+# LIBAVCODEC CHECK--------------------
AC_ARG_WITH(libavcodec,[
- --with-libavcodec Enable support for libavcodec (Default=auto)],[
+ --without-libavcodec disable support for libavcodec (Default=auto)],[
],[
- AC_CHECK_LIB(avcodec, avcodec_find_encoder,[
- with_libavcodec="yes"
- ],[
- with_libavcodec="no"
- ])
+ with_libavcodec="yes"
])
-if test $with_libavcodec = "no" ; then {
- AM_CONDITIONAL(WITH_LIBAVCODEC,false)
-} else {
+
+if test $with_libavcodec != "no" ; then {
+ PKG_CHECK_MODULES(LIBAVCODEC, libavcodec,[with_libavcodec="yes"],[with_libavcodec="no"])
+} ; fi
+if test $with_libavcodec != "no" ; then {
+ PKG_CHECK_MODULES(LIBAVFORMAT, libavformat,[with_libavcodec="yes"],[with_libavcodec="no"])
+} ; fi
+if test $with_libavcodec = "yes" ; then {
+ AC_DEFINE(WITH_LIBAVCODEC,[],[enable libavcodec support])
AM_CONDITIONAL(WITH_LIBAVCODEC,true)
+} else {
+ AM_CONDITIONAL(WITH_LIBAVCODEC,false)
} ; fi
-
-
# FREETYPE2 CHECK--------------------
AC_ARG_WITH(freetype,[
MAINTAINERCLEANFILES=Makefile.in
-INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/modules/mod_libavcodec/libavcodec -I$(top_srcdir)/src/modules/mod_libavcodec/libavformat
+INCLUDES = -I$(top_srcdir)/src
moduledir=@MODULE_DIR@
if WITH_LIBAVCODEC
module_LTLIBRARIES = libmod_libavcodec.la
-
-# Add the filenames to the following line:
libmod_libavcodec_la_SOURCES = main.cpp trgt_av.cpp trgt_av.h mptr.cpp mptr.h
-
-libmod_libavcodec_la_LDFLAGS = -module -no-undefined -lavcodec -lavformat
-libmod_libavcodec_la_CXXFLAGS = @SYNFIG_CFLAGS@
-libmod_libavcodec_la_LIBADD = -L../../synfig -lsynfig @SYNFIG_LIBS@
+libmod_libavcodec_la_LDFLAGS = -module -no-undefined
+libmod_libavcodec_la_CXXFLAGS = @SYNFIG_CFLAGS@ @LIBAVCODEC_CFLAGS@ @LIBAVFORMAT_CFLAGS@
+libmod_libavcodec_la_LIBADD = -L../../synfig -lsynfig @SYNFIG_LIBS@ @LIBAVCODEC_LIBS@ @LIBAVFORMAT_LIBS@
else
endif
-EXTRA_DIST= mod_libavcodec.nsh unmod_libavcodec.nsh libavcodec/ac3.h libavcodec/ac3tab.h libavcodec/avcodec.h libavcodec/bswap.h libavcodec/cabac.h libavcodec/common.h libavcodec/dsputil.h libavcodec/dvdata.h libavcodec/fastmemcpy.h libavcodec/golomb.h libavcodec/h263data.h libavcodec/h264data.h libavcodec/i386/dsputil_mmx_avg.h libavcodec/i386/dsputil_mmx_rnd.h libavcodec/i386/mmx.h libavcodec/imgconvert_template.h libavcodec/indeo3data.h libavcodec/liba52/a52.h libavcodec/liba52/a52_internal.h libavcodec/liba52/a52_util.h libavcodec/liba52/bitstream.h libavcodec/liba52/mm_accel.h libavcodec/liba52/tables.h libavcodec/libpostproc/mangle.h libavcodec/libpostproc/postprocess.h libavcodec/libpostproc/postprocess_internal.h libavcodec/mpeg12data.h libavcodec/mpeg4data.h libavcodec/mpegaudio.h libavcodec/mpegaudiodectab.h libavcodec/mpegaudiotab.h libavcodec/mpegvideo.h libavcodec/msmpeg4data.h libavcodec/oggvorbis.h libavcodec/ra144.h libavcodec/ra288.h libavcodec/simple_idct.h libavcodec/svq1_cb.h libavcodec/svq1_vlc.h libavcodec/vp3data.h libavcodec/wmadata.h libavformat/avformat.h libavformat/avi.h libavformat/avio.h libavformat/barpainet.h libavformat/dv1394.h libavformat/dvcore.h libavformat/framehook.h libavformat/mpegts.h libavformat/os_support.h libavformat/rtp.h libavformat/rtsp.h libavformat/rtspcodes.h
+EXTRA_DIST= mod_libavcodec.nsh unmod_libavcodec.nsh
+++ /dev/null
-/*
- * 4XM codec
- * Copyright (c) 2003 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file 4xm.c
- * 4XM codec.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#define BLOCK_TYPE_VLC_BITS 5
-#define ACDC_VLC_BITS 9
-
-#define CFRAME_BUFFER_COUNT 100
-
-static const uint8_t block_type_tab[4][8][2]={
- { //{8,4,2}x{8,4,2}
- { 0,1}, { 2,2}, { 6,3}, {14,4}, {30,5}, {31,5}, { 0,0}
- },{ //{8,4}x1
- { 0,1}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}, { 0,0}
- },{ //1x{8,4}
- { 0,1}, { 2,2}, { 0,0}, { 6,3}, {14,4}, {15,4}, { 0,0}
- },{ //1x2, 2x1
- { 0,1}, { 0,0}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4}
- }
-};
-
-static const uint8_t size2index[4][4]={
- {-1, 3, 1, 1},
- { 3, 0, 0, 0},
- { 2, 0, 0, 0},
- { 2, 0, 0, 0},
-};
-
-static const int8_t mv[256][2]={
-{ 0, 0},{ 0, -1},{ -1, 0},{ 1, 0},{ 0, 1},{ -1, -1},{ 1, -1},{ -1, 1},
-{ 1, 1},{ 0, -2},{ -2, 0},{ 2, 0},{ 0, 2},{ -1, -2},{ 1, -2},{ -2, -1},
-{ 2, -1},{ -2, 1},{ 2, 1},{ -1, 2},{ 1, 2},{ -2, -2},{ 2, -2},{ -2, 2},
-{ 2, 2},{ 0, -3},{ -3, 0},{ 3, 0},{ 0, 3},{ -1, -3},{ 1, -3},{ -3, -1},
-{ 3, -1},{ -3, 1},{ 3, 1},{ -1, 3},{ 1, 3},{ -2, -3},{ 2, -3},{ -3, -2},
-{ 3, -2},{ -3, 2},{ 3, 2},{ -2, 3},{ 2, 3},{ 0, -4},{ -4, 0},{ 4, 0},
-{ 0, 4},{ -1, -4},{ 1, -4},{ -4, -1},{ 4, -1},{ 4, 1},{ -1, 4},{ 1, 4},
-{ -3, -3},{ -3, 3},{ 3, 3},{ -2, -4},{ -4, -2},{ 4, -2},{ -4, 2},{ -2, 4},
-{ 2, 4},{ -3, -4},{ 3, -4},{ 4, -3},{ -5, 0},{ -4, 3},{ -3, 4},{ 3, 4},
-{ -1, -5},{ -5, -1},{ -5, 1},{ -1, 5},{ -2, -5},{ 2, -5},{ 5, -2},{ 5, 2},
-{ -4, -4},{ -4, 4},{ -3, -5},{ -5, -3},{ -5, 3},{ 3, 5},{ -6, 0},{ 0, 6},
-{ -6, -1},{ -6, 1},{ 1, 6},{ 2, -6},{ -6, 2},{ 2, 6},{ -5, -4},{ 5, 4},
-{ 4, 5},{ -6, -3},{ 6, 3},{ -7, 0},{ -1, -7},{ 5, -5},{ -7, 1},{ -1, 7},
-{ 4, -6},{ 6, 4},{ -2, -7},{ -7, 2},{ -3, -7},{ 7, -3},{ 3, 7},{ 6, -5},
-{ 0, -8},{ -1, -8},{ -7, -4},{ -8, 1},{ 4, 7},{ 2, -8},{ -2, 8},{ 6, 6},
-{ -8, 3},{ 5, -7},{ -5, 7},{ 8, -4},{ 0, -9},{ -9, -1},{ 1, 9},{ 7, -6},
-{ -7, 6},{ -5, -8},{ -5, 8},{ -9, 3},{ 9, -4},{ 7, -7},{ 8, -6},{ 6, 8},
-{ 10, 1},{-10, 2},{ 9, -5},{ 10, -3},{ -8, -7},{-10, -4},{ 6, -9},{-11, 0},
-{ 11, 1},{-11, -2},{ -2, 11},{ 7, -9},{ -7, 9},{ 10, 6},{ -4, 11},{ 8, -9},
-{ 8, 9},{ 5, 11},{ 7,-10},{ 12, -3},{ 11, 6},{ -9, -9},{ 8, 10},{ 5, 12},
-{-11, 7},{ 13, 2},{ 6,-12},{ 10, 9},{-11, 8},{ -7, 12},{ 0, 14},{ 14, -2},
-{ -9, 11},{ -6, 13},{-14, -4},{ -5,-14},{ 5, 14},{-15, -1},{-14, -6},{ 3,-15},
-{ 11,-11},{ -7, 14},{ -5, 15},{ 8,-14},{ 15, 6},{ 3, 16},{ 7,-15},{-16, 5},
-{ 0, 17},{-16, -6},{-10, 14},{-16, 7},{ 12, 13},{-16, 8},{-17, 6},{-18, 3},
-{ -7, 17},{ 15, 11},{ 16, 10},{ 2,-19},{ 3,-19},{-11,-16},{-18, 8},{-19, -6},
-{ 2,-20},{-17,-11},{-10,-18},{ 8, 19},{-21, -1},{-20, 7},{ -4, 21},{ 21, 5},
-{ 15, 16},{ 2,-22},{-10,-20},{-22, 5},{ 20,-11},{ -7,-22},{-12, 20},{ 23, -5},
-{ 13,-20},{ 24, -2},{-15, 19},{-11, 22},{ 16, 19},{ 23,-10},{-18,-18},{ -9,-24},
-{ 24,-10},{ -3, 26},{-23, 13},{-18,-20},{ 17, 21},{ -4, 27},{ 27, 6},{ 1,-28},
-{-11, 26},{-17,-23},{ 7, 28},{ 11,-27},{ 29, 5},{-23,-19},{-28,-11},{-21, 22},
-{-30, 7},{-17, 26},{-27, 16},{ 13, 29},{ 19,-26},{ 10,-31},{-14,-30},{ 20,-27},
-{-29, 18},{-16,-31},{-28,-22},{ 21,-30},{-25, 28},{ 26,-29},{ 25,-32},{-32,-32}
-};
-
-// this is simply the scaled down elementwise product of the standard jpeg quantizer table and the AAN premul table
-static const uint8_t dequant_table[64]={
- 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,
-};
-
-static VLC block_type_vlc[4];
-
-
-typedef struct CFrameBuffer{
- int allocated_size;
- int size;
- int id;
- uint8_t *data;
-}CFrameBuffer;
-
-typedef struct FourXContext{
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame current_picture, last_picture;
- GetBitContext pre_gb; ///< ac/dc prefix
- GetBitContext gb;
- uint8_t *bytestream;
- uint16_t *wordstream;
- int mv[256];
- VLC pre_vlc;
- int last_dc;
- DCTELEM __align8 block[6][64];
- uint8_t *bitstream_buffer;
- int bitstream_buffer_size;
- CFrameBuffer cfrm[CFRAME_BUFFER_COUNT];
-} FourXContext;
-
-
-#define FIX_1_082392200 70936
-#define FIX_1_414213562 92682
-#define FIX_1_847759065 121095
-#define FIX_2_613125930 171254
-
-#define MULTIPLY(var,const) (((var)*(const)) >> 16)
-
-static void idct(DCTELEM block[64]){
- int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int tmp10, tmp11, tmp12, tmp13;
- int z5, z10, z11, z12, z13;
- int i;
- int temp[64];
-
- for(i=0; i<8; i++){
- tmp10 = block[8*0 + i] + block[8*4 + i];
- tmp11 = block[8*0 + i] - block[8*4 + i];
-
- tmp13 = block[8*2 + i] + block[8*6 + i];
- tmp12 = MULTIPLY(block[8*2 + i] - block[8*6 + i], FIX_1_414213562) - tmp13;
-
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
- z13 = block[8*5 + i] + block[8*3 + i];
- z10 = block[8*5 + i] - block[8*3 + i];
- z11 = block[8*1 + i] + block[8*7 + i];
- z12 = block[8*1 + i] - block[8*7 + i];
-
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
-
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
-
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
-
- temp[8*0 + i] = tmp0 + tmp7;
- temp[8*7 + i] = tmp0 - tmp7;
- temp[8*1 + i] = tmp1 + tmp6;
- temp[8*6 + i] = tmp1 - tmp6;
- temp[8*2 + i] = tmp2 + tmp5;
- temp[8*5 + i] = tmp2 - tmp5;
- temp[8*4 + i] = tmp3 + tmp4;
- temp[8*3 + i] = tmp3 - tmp4;
- }
-
- for(i=0; i<8*8; i+=8){
- tmp10 = temp[0 + i] + temp[4 + i];
- tmp11 = temp[0 + i] - temp[4 + i];
-
- tmp13 = temp[2 + i] + temp[6 + i];
- tmp12 = MULTIPLY(temp[2 + i] - temp[6 + i], FIX_1_414213562) - tmp13;
-
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
- z13 = temp[5 + i] + temp[3 + i];
- z10 = temp[5 + i] - temp[3 + i];
- z11 = temp[1 + i] + temp[7 + i];
- z12 = temp[1 + i] - temp[7 + i];
-
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
-
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
-
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
-
- block[0 + i] = (tmp0 + tmp7)>>6;
- block[7 + i] = (tmp0 - tmp7)>>6;
- block[1 + i] = (tmp1 + tmp6)>>6;
- block[6 + i] = (tmp1 - tmp6)>>6;
- block[2 + i] = (tmp2 + tmp5)>>6;
- block[5 + i] = (tmp2 - tmp5)>>6;
- block[4 + i] = (tmp3 + tmp4)>>6;
- block[3 + i] = (tmp3 - tmp4)>>6;
- }
-}
-
-static void init_vlcs(FourXContext *f){
- static int done = 0;
- int i;
-
- if (!done) {
- done = 1;
-
- for(i=0; i<4; i++){
- init_vlc(&block_type_vlc[i], BLOCK_TYPE_VLC_BITS, 7,
- &block_type_tab[i][0][1], 2, 1,
- &block_type_tab[i][0][0], 2, 1);
- }
- }
-}
-
-static void init_mv(FourXContext *f){
- int i;
-
- for(i=0; i<256; i++){
- f->mv[i] = mv[i][0] + mv[i][1]*f->current_picture.linesize[0]/2;
- }
-}
-
-static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){
- int i;
- dc*= 0x10001;
-
- switch(log2w){
- case 0:
- for(i=0; i<h; i++){
- dst[0] = scale*src[0] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 1:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 2:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- case 3:
- for(i=0; i<h; i++){
- ((uint32_t*)dst)[0] = scale*((uint32_t*)src)[0] + dc;
- ((uint32_t*)dst)[1] = scale*((uint32_t*)src)[1] + dc;
- ((uint32_t*)dst)[2] = scale*((uint32_t*)src)[2] + dc;
- ((uint32_t*)dst)[3] = scale*((uint32_t*)src)[3] + dc;
- if(scale) src += stride;
- dst += stride;
- }
- break;
- default: assert(0);
- }
-}
-
-static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){
- const int index= size2index[log2h][log2w];
- const int h= 1<<log2h;
- int code= get_vlc2(&f->gb, block_type_vlc[index].table, BLOCK_TYPE_VLC_BITS, 1);
-
- assert(code>=0 && code<=6);
-
- if(code == 0){
- src += f->mv[ *f->bytestream++ ];
- mcdc(dst, src, log2w, h, stride, 1, 0);
- }else if(code == 1){
- log2h--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (stride<<log2h), src + (stride<<log2h), log2w, log2h, stride);
- }else if(code == 2){
- log2w--;
- decode_p_block(f, dst , src , log2w, log2h, stride);
- decode_p_block(f, dst + (1<<log2w), src + (1<<log2w), log2w, log2h, stride);
- }else if(code == 4){
- src += f->mv[ *f->bytestream++ ];
- mcdc(dst, src, log2w, h, stride, 1, le2me_16(*f->wordstream++));
- }else if(code == 5){
- mcdc(dst, src, log2w, h, stride, 0, le2me_16(*f->wordstream++));
- }else if(code == 6){
- if(log2w){
- dst[0] = le2me_16(*f->wordstream++);
- dst[1] = le2me_16(*f->wordstream++);
- }else{
- dst[0 ] = le2me_16(*f->wordstream++);
- dst[stride] = le2me_16(*f->wordstream++);
- }
- }
-}
-
-static int get32(void *p){
- return le2me_32(*(uint32_t*)p);
-}
-
-static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){
- int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- uint16_t *src= (uint16_t*)f->last_picture.data[0];
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
- const int bitstream_size= get32(buf+8);
- const int bytestream_size= get32(buf+16);
- const int wordstream_size= get32(buf+12);
-
- if(bitstream_size+ bytestream_size+ wordstream_size + 20 != length)
- printf("lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
- bitstream_size+ bytestream_size+ wordstream_size - length);
-
- f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
- f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)(buf + 20), bitstream_size/4);
- init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size);
-
- f->wordstream= (uint16_t*)(buf + 20 + bitstream_size);
- f->bytestream= buf + 20 + bitstream_size + wordstream_size;
-
- init_mv(f);
-
- for(y=0; y<height; y+=8){
- for(x=0; x<width; x+=8){
- decode_p_block(f, dst + x, src + x, 3, 3, stride);
- }
- src += 8*stride;
- dst += 8*stride;
- }
-
- if(bitstream_size != (get_bits_count(&f->gb)+31)/32*4)
- printf(" %d %d %d bytes left\n",
- bitstream_size - (get_bits_count(&f->gb)+31)/32*4,
- bytestream_size - (f->bytestream - (buf + 20 + bitstream_size + wordstream_size)),
- wordstream_size - (((uint8_t*)f->wordstream) - (buf + 20 + bitstream_size))
- );
-
- return 0;
-}
-
-/**
- * decode block and dequantize.
- * Note this is allmost identical to mjpeg
- */
-static int decode_i_block(FourXContext *f, DCTELEM *block){
- int code, i, j, level, val;
-
- /* DC coef */
- val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
- if (val>>4){
- printf("error dc run != 0\n");
- }
-
- if(val)
- val = get_xbits(&f->gb, val);
-
- val = val * dequant_table[0] + f->last_dc;
- f->last_dc =
- block[0] = val;
- /* AC coefs */
- i = 1;
- for(;;) {
- code = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3);
-
- /* EOB */
- if (code == 0)
- break;
- if (code == 0xf0) {
- i += 16;
- } else {
- level = get_xbits(&f->gb, code & 0xf);
- i += code >> 4;
- if (i >= 64) {
- printf("run %d oveflow\n", i);
- return 0;
- }
-
- j= ff_zigzag_direct[i];
- block[j] = level * dequant_table[j];
- i++;
- if (i >= 64)
- break;
- }
- }
-
- return 0;
-}
-
-static inline void idct_put(FourXContext *f, int x, int y){
- DCTELEM (*block)[64]= f->block;
- int stride= f->current_picture.linesize[0]>>1;
- int i;
- uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x;
-
- for(i=0; i<4; i++){
- block[i][0] += 0x80*8*8;
- idct(block[i]);
- }
-
- if(!(f->avctx->flags&CODEC_FLAG_GRAY)){
- for(i=4; i<6; i++) idct(block[i]);
- }
-
- for(y=0; y<8; y++){
- for(x=0; x<8; x++){
- DCTELEM *temp= block[(x>>2) + 2*(y>>2)] + 2*(x&3) + 2*8*(y&3); //FIXME optimize
- int cb= block[4][x + 8*y];
- int cr= block[5][x + 8*y];
- int cg= (cb + cr)>>1;
- int y;
-
- cb+=cb;
-
- y = temp[0];
- dst[0 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[1];
- dst[1 ]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[8];
- dst[ stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- y = temp[9];
- dst[1+stride]= ((y+cb)>>3) + (((y-cg)&0xFC)<<3) + (((y+cr)&0xF8)<<8);
- dst += 2;
- }
- dst += 2*stride - 2*8;
- }
-}
-
-static int decode_i_mb(FourXContext *f){
- int i;
-
- f->dsp.clear_blocks(f->block[0]);
-
- for(i=0; i<6; i++){
- if(decode_i_block(f, f->block[i]) < 0)
- return -1;
- }
-
- return 0;
-}
-
-static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){
- int frequency[512];
- uint8_t flag[512];
- int up[512];
- uint8_t len_tab[257];
- int bits_tab[257];
- int start, end;
- uint8_t *ptr= buf;
- int j;
-
- memset(frequency, 0, sizeof(frequency));
- memset(up, -1, sizeof(up));
-
- start= *ptr++;
- end= *ptr++;
- for(;;){
- int i;
-
- for(i=start; i<=end; i++){
- frequency[i]= *ptr++;
-// printf("%d %d %d\n", start, end, frequency[i]);
- }
- start= *ptr++;
- if(start==0) break;
-
- end= *ptr++;
- }
- frequency[256]=1;
-
- while((ptr - buf)&3) ptr++; // 4byte align
-
-// for(j=0; j<16; j++)
-// printf("%2X", ptr[j]);
-
- for(j=257; j<512; j++){
- int min_freq[2]= {256*256, 256*256};
- int smallest[2]= {0, 0};
- int i;
- for(i=0; i<j; i++){
- if(frequency[i] == 0) continue;
- if(frequency[i] < min_freq[1]){
- if(frequency[i] < min_freq[0]){
- min_freq[1]= min_freq[0]; smallest[1]= smallest[0];
- min_freq[0]= frequency[i];smallest[0]= i;
- }else{
- min_freq[1]= frequency[i];smallest[1]= i;
- }
- }
- }
- if(min_freq[1] == 256*256) break;
-
- frequency[j]= min_freq[0] + min_freq[1];
- flag[ smallest[0] ]= 0;
- flag[ smallest[1] ]= 1;
- up[ smallest[0] ]=
- up[ smallest[1] ]= j;
- frequency[ smallest[0] ]= frequency[ smallest[1] ]= 0;
- }
-
- for(j=0; j<257; j++){
- int node;
- int len=0;
- int bits=0;
-
- for(node= j; up[node] != -1; node= up[node]){
- bits += flag[node]<<len;
- len++;
- if(len > 31) printf("vlc length overflow\n"); //can this happen at all ?
- }
-
- bits_tab[j]= bits;
- len_tab[j]= len;
- }
-
- init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257,
- len_tab , 1, 1,
- bits_tab, 4, 4);
-
- return ptr;
-}
-
-static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){
- int x, y;
- const int width= f->avctx->width;
- const int height= f->avctx->height;
- uint16_t *dst= (uint16_t*)f->current_picture.data[0];
- const int stride= f->current_picture.linesize[0]>>1;
- const int bitstream_size= get32(buf);
- const int token_count __attribute__((unused)) = get32(buf + bitstream_size + 8);
- int prestream_size= 4*get32(buf + bitstream_size + 4);
- uint8_t *prestream= buf + bitstream_size + 12;
-
- if(prestream_size + bitstream_size + 12 != length)
- fprintf(stderr, "size missmatch %d %d %d\n", prestream_size, bitstream_size, length);
-
- prestream= read_huffman_tables(f, prestream);
-
- init_get_bits(&f->gb, buf + 4, 8*bitstream_size);
-
- prestream_size= length + buf - prestream;
-
- f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
- f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)prestream, prestream_size/4);
- init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size);
-
- f->last_dc= 0*128*8*8;
-
- for(y=0; y<height; y+=16){
- for(x=0; x<width; x+=16){
- if(decode_i_mb(f) < 0)
- return -1;
-
- idct_put(f, x, y);
- }
- dst += 16*stride;
- }
-
- if(get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256)
- printf("end missmatch\n");
-
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- FourXContext * const f = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame *p, temp;
- int i, frame_4cc, frame_size;
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0) {
- return 0;
- }
-
- frame_4cc= get32(buf);
- if(buf_size != get32(buf+4)+8){
- fprintf(stderr, "size missmatch %d %d\n", buf_size, get32(buf+4));
- }
-
- if(frame_4cc == ff_get_fourcc("cfrm")){
- int free_index=-1;
- const int data_size= buf_size - 20;
- const int id= get32(buf+12);
- const int whole_size= get32(buf+16);
- CFrameBuffer *cfrm;
-
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id && f->cfrm[i].id < avctx->frame_number)
- printf("lost c frame %d\n", f->cfrm[i].id);
- }
-
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- if(f->cfrm[i].id == id) break;
- if(f->cfrm[i].size == 0 ) free_index= i;
- }
-
- if(i>=CFRAME_BUFFER_COUNT){
- i= free_index;
- f->cfrm[i].id= id;
- }
- cfrm= &f->cfrm[i];
-
- cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(cfrm->data + cfrm->size, buf+20, data_size);
- cfrm->size += data_size;
-
- if(cfrm->size >= whole_size){
- buf= cfrm->data;
- frame_size= cfrm->size;
-
- if(id != avctx->frame_number){
- printf("cframe id missmatch %d %d\n", id, avctx->frame_number);
- }
-
- cfrm->size= cfrm->id= 0;
- frame_4cc= ff_get_fourcc("pfrm");
- }else
- return buf_size;
- }else{
- buf= buf + 12;
- frame_size= buf_size - 12;
- }
-
- temp= f->current_picture;
- f->current_picture= f->last_picture;
- f->last_picture= temp;
-
- p= &f->current_picture;
- avctx->coded_frame= p;
-
- avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 1;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- if(frame_4cc == ff_get_fourcc("ifrm")){
- p->pict_type= I_TYPE;
- if(decode_i_frame(f, buf, frame_size) < 0)
- return -1;
- }else if(frame_4cc == ff_get_fourcc("pfrm")){
- p->pict_type= P_TYPE;
- if(decode_p_frame(f, buf, frame_size) < 0)
- return -1;
- }else if(frame_4cc == ff_get_fourcc("snd_")){
- printf("ignoring snd_ chunk length:%d\n", buf_size);
- }else{
- printf("ignoring unknown chunk length:%d\n", buf_size);
- }
-
-#if 0
-for(i=0; i<20; i++){
- printf("%2X %c ", buf[i], clip(buf[i],16,126));
-}
-#endif
-
- p->key_frame= p->pict_type == I_TYPE;
-
- *picture= *p;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return buf_size;
-}
-
-
-static void common_init(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
-
- dsputil_init(&f->dsp, avctx);
-
- f->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
-
- common_init(avctx);
- init_vlcs(f);
-
- avctx->pix_fmt= PIX_FMT_RGB565;
-
- return 0;
-}
-
-
-static int decode_end(AVCodecContext *avctx){
- FourXContext * const f = avctx->priv_data;
- int i;
-
- av_freep(&f->bitstream_buffer);
- f->bitstream_buffer_size=0;
- for(i=0; i<CFRAME_BUFFER_COUNT; i++){
- av_freep(&f->cfrm[i].data);
- f->cfrm[i].allocated_size= 0;
- }
- free_vlc(&f->pre_vlc);
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec fourxm_decoder = {
- "4xm",
- CODEC_TYPE_VIDEO,
- CODEC_ID_4XM,
- sizeof(FourXContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- /*CODEC_CAP_DR1,*/
-};
-
+++ /dev/null
-# Doxyfile 1.3-rc1
-
-# This file describes the settings to be used by the documentation system
-# doxygen (www.doxygen.org) for a project
-#
-# All text after a hash (#) is considered a comment and will be ignored
-# The format is:
-# TAG = value [value, ...]
-# For lists items can also be appended using:
-# TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (" ")
-
-#---------------------------------------------------------------------------
-# General configuration options
-#---------------------------------------------------------------------------
-
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
-# by quotes) that should identify the project.
-
-PROJECT_NAME = libavcodec
-
-# The PROJECT_NUMBER tag can be used to enter a project or revision number.
-# This could be handy for archiving the generated documentation or
-# if some version control system is used.
-
-PROJECT_NUMBER =
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
-# base path where the generated documentation will be put.
-# If a relative path is entered, it will be relative to the location
-# where doxygen was started. If left blank the current directory will be used.
-
-OUTPUT_DIRECTORY = doxy
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all
-# documentation generated by doxygen is written. Doxygen will use this
-# information to generate all constant output in the proper language.
-# The default language is English, other supported languages are:
-# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch,
-# Finnish, French, German, Greek, Hungarian, Italian, Japanese, Japanese-en
-# (Japanese with english messages), Korean, Norwegian, Polish, Portuguese,
-# Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish and Ukrainian.
-
-OUTPUT_LANGUAGE = English
-
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
-# documentation are documented, even if no documentation was available.
-# Private class members and static file members will be hidden unless
-# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
-
-EXTRACT_ALL = YES
-
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
-# will be included in the documentation.
-
-EXTRACT_PRIVATE = YES
-
-# If the EXTRACT_STATIC tag is set to YES all static members of a file
-# will be included in the documentation.
-
-EXTRACT_STATIC = YES
-
-# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
-# defined locally in source files will be included in the documentation.
-# If set to NO only classes defined in header files are included.
-
-EXTRACT_LOCAL_CLASSES = YES
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
-# undocumented members of documented classes, files or namespaces.
-# If set to NO (the default) these members will be included in the
-# various overviews, but no documentation section is generated.
-# This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_MEMBERS = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
-# undocumented classes that are normally visible in the class hierarchy.
-# If set to NO (the default) these class will be included in the various
-# overviews. This option has no effect if EXTRACT_ALL is enabled.
-
-HIDE_UNDOC_CLASSES = NO
-
-# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
-# friend (class|struct|union) declarations.
-# If set to NO (the default) these declarations will be included in the
-# documentation.
-
-HIDE_FRIEND_COMPOUNDS = NO
-
-# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
-# documentation blocks found inside the body of a function.
-# If set to NO (the default) these blocks will be appended to the
-# function's detailed documentation block.
-
-HIDE_IN_BODY_DOCS = NO
-
-# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
-# include brief member descriptions after the members that are listed in
-# the file and class documentation (similar to JavaDoc).
-# Set to NO to disable this.
-
-BRIEF_MEMBER_DESC = YES
-
-# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
-# the brief description of a member or function before the detailed description.
-# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
-# brief descriptions will be completely suppressed.
-
-REPEAT_BRIEF = YES
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
-# Doxygen will generate a detailed section even if there is only a brief
-# description.
-
-ALWAYS_DETAILED_SEC = NO
-
-# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all inherited
-# members of a class in the documentation of that class as if those members were
-# ordinary class members. Constructors, destructors and assignment operators of
-# the base classes will not be shown.
-
-INLINE_INHERITED_MEMB = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
-# path before files name in the file list and in the header files. If set
-# to NO the shortest path that makes the file name unique will be used.
-
-FULL_PATH_NAMES = YES
-
-# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
-# can be used to strip a user defined part of the path. Stripping is
-# only done if one of the specified strings matches the left-hand part of
-# the path. It is allowed to use relative paths in the argument list.
-
-STRIP_FROM_PATH = .
-
-# The INTERNAL_DOCS tag determines if documentation
-# that is typed after a \internal command is included. If the tag is set
-# to NO (the default) then the documentation will be excluded.
-# Set it to YES to include the internal documentation.
-
-INTERNAL_DOCS = NO
-
-# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
-# file names in lower case letters. If set to YES upper case letters are also
-# allowed. This is useful if you have classes or files whose names only differ
-# in case and if your file system supports case sensitive file names. Windows
-# users are adviced to set this option to NO.
-
-CASE_SENSE_NAMES = YES
-
-# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
-# (but less readable) file names. This can be useful is your file systems
-# doesn't support long names like on DOS, Mac, or CD-ROM.
-
-SHORT_NAMES = NO
-
-# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
-# will show members with their full class and namespace scopes in the
-# documentation. If set to YES the scope will be hidden.
-
-HIDE_SCOPE_NAMES = NO
-
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
-# will generate a verbatim copy of the header file for each class for
-# which an include is specified. Set to NO to disable this.
-
-VERBATIM_HEADERS = YES
-
-# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
-# will put list of the files that are included by a file in the documentation
-# of that file.
-
-SHOW_INCLUDE_FILES = YES
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
-# will interpret the first line (until the first dot) of a JavaDoc-style
-# comment as the brief description. If set to NO, the JavaDoc
-# comments will behave just like the Qt-style comments (thus requiring an
-# explict @brief command for a brief description.
-
-JAVADOC_AUTOBRIEF = YES
-
-# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
-# treat a multi-line C++ special comment block (i.e. a block of //! or ///
-# comments) as a brief description. This used to be the default behaviour.
-# The new default is to treat a multi-line C++ comment block as a detailed
-# description. Set this tag to YES if you prefer the old behaviour instead.
-
-MULTILINE_CPP_IS_BRIEF = NO
-
-# If the DETAILS_AT_TOP tag is set to YES then Doxygen
-# will output the detailed description near the top, like JavaDoc.
-# If set to NO, the detailed description appears after the member
-# documentation.
-
-DETAILS_AT_TOP = NO
-
-# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
-# member inherits the documentation from any documented member that it
-# reimplements.
-
-INHERIT_DOCS = YES
-
-# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
-# is inserted in the documentation for inline members.
-
-INLINE_INFO = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
-# will sort the (detailed) documentation of file and class members
-# alphabetically by member name. If set to NO the members will appear in
-# declaration order.
-
-SORT_MEMBER_DOCS = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
-# tag is set to YES, then doxygen will reuse the documentation of the first
-# member in the group (if any) for the other members of the group. By default
-# all members of a group must be documented explicitly.
-
-DISTRIBUTE_GROUP_DOC = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab.
-# Doxygen uses this value to replace tabs by spaces in code fragments.
-
-TAB_SIZE = 8
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or
-# disable (NO) the todo list. This list is created by putting \todo
-# commands in the documentation.
-
-GENERATE_TODOLIST = YES
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or
-# disable (NO) the test list. This list is created by putting \test
-# commands in the documentation.
-
-GENERATE_TESTLIST = YES
-
-# The GENERATE_BUGLIST tag can be used to enable (YES) or
-# disable (NO) the bug list. This list is created by putting \bug
-# commands in the documentation.
-
-GENERATE_BUGLIST = YES
-
-# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
-# disable (NO) the deprecated list. This list is created by putting
-# \deprecated commands in the documentation.
-
-GENERATE_DEPRECATEDLIST= YES
-
-# This tag can be used to specify a number of aliases that acts
-# as commands in the documentation. An alias has the form "name=value".
-# For example adding "sideeffect=\par Side Effects:\n" will allow you to
-# put the command \sideeffect (or @sideeffect) in the documentation, which
-# will result in a user defined paragraph with heading "Side Effects:".
-# You can put \n's in the value part of an alias to insert newlines.
-
-ALIASES =
-
-# The ENABLED_SECTIONS tag can be used to enable conditional
-# documentation sections, marked by \if sectionname ... \endif.
-
-ENABLED_SECTIONS =
-
-# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
-# the initial value of a variable or define consist of for it to appear in
-# the documentation. If the initializer consists of more lines than specified
-# here it will be hidden. Use a value of 0 to hide initializers completely.
-# The appearance of the initializer of individual variables and defines in the
-# documentation can be controlled using \showinitializer or \hideinitializer
-# command in the documentation regardless of this setting.
-
-MAX_INITIALIZER_LINES = 30
-
-# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
-# only. Doxygen will then generate output that is more tailored for C.
-# For instance some of the names that are used will be different. The list
-# of all members will be omitted, etc.
-
-OPTIMIZE_OUTPUT_FOR_C = YES
-
-# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources
-# only. Doxygen will then generate output that is more tailored for Java.
-# For instance namespaces will be presented as packages, qualified scopes
-# will look different, etc.
-
-OPTIMIZE_OUTPUT_JAVA = NO
-
-# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
-# at the bottom of the documentation of classes and structs. If set to YES the
-# list will mention the files that were used to generate the documentation.
-
-SHOW_USED_FILES = YES
-
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated
-# by doxygen. Possible values are YES and NO. If left blank NO is used.
-
-QUIET = NO
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are
-# generated by doxygen. Possible values are YES and NO. If left blank
-# NO is used.
-
-WARNINGS = YES
-
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
-# automatically be disabled.
-
-WARN_IF_UNDOCUMENTED = YES
-
-# The WARN_FORMAT tag determines the format of the warning messages that
-# doxygen can produce. The string should contain the $file, $line, and $text
-# tags, which will be replaced by the file and line number from which the
-# warning originated and the warning text.
-
-WARN_FORMAT = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning
-# and error messages should be written. If left blank the output is written
-# to stderr.
-
-WARN_LOGFILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag can be used to specify the files and/or directories that contain
-# documented source files. You may enter file names like "myfile.cpp" or
-# directories like "/usr/src/myproject". Separate the files or directories
-# with spaces.
-
-INPUT =
-
-# If the value of the INPUT tag contains directories, you can use the
-# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank the following patterns are tested:
-# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx *.hpp
-# *.h++ *.idl *.odl
-
-FILE_PATTERNS =
-
-# The RECURSIVE tag can be used to turn specify whether or not subdirectories
-# should be searched for input files as well. Possible values are YES and NO.
-# If left blank NO is used.
-
-RECURSIVE = YES
-
-# The EXCLUDE tag can be used to specify files and/or directories that should
-# excluded from the INPUT source files. This way you can easily exclude a
-# subdirectory from a directory tree whose root is specified with the INPUT tag.
-
-EXCLUDE =
-
-# The EXCLUDE_SYMLINKS tag can be used select whether or not files or directories
-# that are symbolic links (a Unix filesystem feature) are excluded from the input.
-
-EXCLUDE_SYMLINKS = NO
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-
-EXCLUDE_PATTERNS =
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or
-# directories that contain example code fragments that are included (see
-# the \include command).
-
-EXAMPLE_PATH =
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
-# and *.h) to filter out the source-files in the directories. If left
-# blank all files are included.
-
-EXAMPLE_PATTERNS =
-
-# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
-# searched for input files to be used with the \include or \dontinclude
-# commands irrespective of the value of the RECURSIVE tag.
-# Possible values are YES and NO. If left blank NO is used.
-
-EXAMPLE_RECURSIVE = NO
-
-# The IMAGE_PATH tag can be used to specify one or more files or
-# directories that contain image that are included in the documentation (see
-# the \image command).
-
-IMAGE_PATH =
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should
-# invoke to filter for each input file. Doxygen will invoke the filter program
-# by executing (via popen()) the command <filter> <input-file>, where <filter>
-# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
-# input file. Doxygen will then use the output that the filter program writes
-# to standard output.
-
-INPUT_FILTER =
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
-# INPUT_FILTER) will be used to filter the input files when producing source
-# files to browse (i.e. when SOURCE_BROWSER is set to YES).
-
-FILTER_SOURCE_FILES = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will
-# be generated. Documented entities will be cross-referenced with these sources.
-
-SOURCE_BROWSER = YES
-
-# Setting the INLINE_SOURCES tag to YES will include the body
-# of functions and classes directly in the documentation.
-
-INLINE_SOURCES = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
-# doxygen to hide any special comment blocks from generated source code
-# fragments. Normal C and C++ comments will always remain visible.
-
-STRIP_CODE_COMMENTS = YES
-
-# If the REFERENCED_BY_RELATION tag is set to YES (the default)
-# then for each documented function all documented
-# functions referencing it will be listed.
-
-REFERENCED_BY_RELATION = YES
-
-# If the REFERENCES_RELATION tag is set to YES (the default)
-# then for each documented function all documented entities
-# called/used by that function will be listed.
-
-REFERENCES_RELATION = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
-# of all compounds will be generated. Enable this if the project
-# contains a lot of classes, structs, unions or interfaces.
-
-ALPHABETICAL_INDEX = YES
-
-# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
-# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
-# in which this list will be split (can be a number in the range [1..20])
-
-COLS_IN_ALPHA_INDEX = 5
-
-# In case all classes in a project start with a common prefix, all
-# classes will be put under the same header in the alphabetical index.
-# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
-# should be ignored while generating the index headers.
-
-IGNORE_PREFIX =
-
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
-# generate HTML output.
-
-GENERATE_HTML = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `html' will be used as the default path.
-
-HTML_OUTPUT = html
-
-# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
-# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
-# doxygen will generate files with .html extension.
-
-HTML_FILE_EXTENSION = .html
-
-# The HTML_HEADER tag can be used to specify a personal HTML header for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard header.
-
-HTML_HEADER =
-
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for
-# each generated HTML page. If it is left blank doxygen will generate a
-# standard footer.
-
-HTML_FOOTER =
-
-# The HTML_STYLESHEET tag can be used to specify a user defined cascading
-# style sheet that is used by each HTML page. It can be used to
-# fine-tune the look of the HTML output. If the tag is left blank doxygen
-# will generate a default style sheet
-
-HTML_STYLESHEET =
-
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
-# files or namespaces will be aligned in HTML using tables. If set to
-# NO a bullet list will be used.
-
-HTML_ALIGN_MEMBERS = YES
-
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files
-# will be generated that can be used as input for tools like the
-# Microsoft HTML help workshop to generate a compressed HTML help file (.chm)
-# of the generated HTML documentation.
-
-GENERATE_HTMLHELP = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
-# be used to specify the file name of the resulting .chm file. You
-# can add a path in front of the file if the result should not be
-# written to the html output dir.
-
-CHM_FILE =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
-# be used to specify the location (absolute path including file name) of
-# the HTML help compiler (hhc.exe). If non empty doxygen will try to run
-# the html help compiler on the generated index.hhp.
-
-HHC_LOCATION =
-
-# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
-# controls if a separate .chi index file is generated (YES) or that
-# it should be included in the master .chm file (NO).
-
-GENERATE_CHI = NO
-
-# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
-# controls whether a binary table of contents is generated (YES) or a
-# normal table of contents (NO) in the .chm file.
-
-BINARY_TOC = NO
-
-# The TOC_EXPAND flag can be set to YES to add extra items for group members
-# to the contents of the Html help documentation and to the tree view.
-
-TOC_EXPAND = NO
-
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
-# top of each HTML page. The value NO (the default) enables the index and
-# the value YES disables it.
-
-DISABLE_INDEX = NO
-
-# This tag can be used to set the number of enum values (range [1..20])
-# that doxygen will group on one line in the generated HTML documentation.
-
-ENUM_VALUES_PER_LINE = 4
-
-# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be
-# generated containing a tree-like index structure (just like the one that
-# is generated for HTML Help). For this to work a browser that supports
-# JavaScript and frames is required (for instance Mozilla, Netscape 4.0+,
-# or Internet explorer 4.0+). Note that for large projects the tree generation
-# can take a very long time. In such cases it is better to disable this feature.
-# Windows users are probably better off using the HTML help feature.
-
-GENERATE_TREEVIEW = NO
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
-# used to set the initial width (in pixels) of the frame in which the tree
-# is shown.
-
-TREEVIEW_WIDTH = 250
-
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
-# generate Latex output.
-
-GENERATE_LATEX = YES
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `latex' will be used as the default path.
-
-LATEX_OUTPUT = latex
-
-# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
-# invoked. If left blank `latex' will be used as the default command name.
-
-LATEX_CMD_NAME = latex
-
-# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
-# generate index for LaTeX. If left blank `makeindex' will be used as the
-# default command name.
-
-MAKEINDEX_CMD_NAME = makeindex
-
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
-# LaTeX documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_LATEX = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used
-# by the printer. Possible values are: a4, a4wide, letter, legal and
-# executive. If left blank a4wide will be used.
-
-PAPER_TYPE = a4wide
-
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
-# packages that should be included in the LaTeX output.
-
-EXTRA_PACKAGES =
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
-# the generated latex document. The header should contain everything until
-# the first chapter. If it is left blank doxygen will generate a
-# standard header. Notice: only use this tag if you know what you are doing!
-
-LATEX_HEADER =
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will
-# contain links (just like the HTML output) instead of page references
-# This makes the output suitable for online browsing using a pdf viewer.
-
-PDF_HYPERLINKS = NO
-
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
-# plain latex in the generated Makefile. Set this option to YES to get a
-# higher quality PDF documentation.
-
-USE_PDFLATEX = NO
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
-# command to the generated LaTeX files. This will instruct LaTeX to keep
-# running if errors occur, instead of asking the user for help.
-# This option is also used when generating formulas in HTML.
-
-LATEX_BATCHMODE = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
-# The RTF output is optimised for Word 97 and may not look very pretty with
-# other RTF readers or editors.
-
-GENERATE_RTF = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `rtf' will be used as the default path.
-
-RTF_OUTPUT = rtf
-
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
-# RTF documents. This may be useful for small projects and may help to
-# save some trees in general.
-
-COMPACT_RTF = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
-# will contain hyperlink fields. The RTF file will
-# contain links (just like the HTML output) instead of page references.
-# This makes the output suitable for online browsing using WORD or other
-# programs which support those fields.
-# Note: wordpad (write) and others do not support links.
-
-RTF_HYPERLINKS = NO
-
-# Load stylesheet definitions from file. Syntax is similar to doxygen's
-# config file, i.e. a series of assigments. You only have to provide
-# replacements, missing definitions are set to their default value.
-
-RTF_STYLESHEET_FILE =
-
-# Set optional variables used in the generation of an rtf document.
-# Syntax is similar to doxygen's config file.
-
-RTF_EXTENSIONS_FILE =
-
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
-# generate man pages
-
-GENERATE_MAN = NO
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put.
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be
-# put in front of it. If left blank `man' will be used as the default path.
-
-MAN_OUTPUT = man
-
-# The MAN_EXTENSION tag determines the extension that is added to
-# the generated man pages (default is the subroutine's section .3)
-
-MAN_EXTENSION = .3
-
-# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
-# then it will generate one additional man file for each entity
-# documented in the real man page(s). These additional files
-# only source the real man page, but without them the man command
-# would be unable to find the correct page. The default is NO.
-
-MAN_LINKS = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES Doxygen will
-# generate an XML file that captures the structure of
-# the code including all documentation. Note that this
-# feature is still experimental and incomplete at the
-# moment.
-
-GENERATE_XML = NO
-
-# The XML_SCHEMA tag can be used to specify an XML schema,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_SCHEMA =
-
-# The XML_DTD tag can be used to specify an XML DTD,
-# which can be used by a validating XML parser to check the
-# syntax of the XML files.
-
-XML_DTD =
-
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
-# generate an AutoGen Definitions (see autogen.sf.net) file
-# that captures the structure of the code including all
-# documentation. Note that this feature is still experimental
-# and incomplete at the moment.
-
-GENERATE_AUTOGEN_DEF = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_PERLMOD tag is set to YES Doxygen will
-# generate a Perl module file that captures the structure of
-# the code including all documentation. Note that this
-# feature is still experimental and incomplete at the
-# moment.
-
-GENERATE_PERLMOD = NO
-
-# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
-# the necessary Makefile rules, Perl scripts and LaTeX code to be able
-# to generate PDF and DVI output from the Perl module output.
-
-PERLMOD_LATEX = NO
-
-# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
-# nicely formatted so it can be parsed by a human reader. This is useful
-# if you want to understand what is going on. On the other hand, if this
-# tag is set to NO the size of the Perl module output will be much smaller
-# and Perl will parse it just the same.
-
-PERLMOD_PRETTY = YES
-
-# The names of the make variables in the generated doxyrules.make file
-# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
-# This is useful so different doxyrules.make files included by the same
-# Makefile don't overwrite each other's variables.
-
-PERLMOD_MAKEVAR_PREFIX =
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
-# evaluate all C-preprocessor directives found in the sources and include
-# files.
-
-ENABLE_PREPROCESSING = YES
-
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
-# names in the source code. If set to NO (the default) only conditional
-# compilation will be performed. Macro expansion can be done in a controlled
-# way by setting EXPAND_ONLY_PREDEF to YES.
-
-MACRO_EXPANSION = YES
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
-# then the macro expansion is limited to the macros specified with the
-# PREDEFINED and EXPAND_AS_PREDEFINED tags.
-
-EXPAND_ONLY_PREDEF = YES
-
-# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
-# in the INCLUDE_PATH (see below) will be search if a #include is found.
-
-SEARCH_INCLUDES = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that
-# contain include files that are not input files but should be processed by
-# the preprocessor.
-
-INCLUDE_PATH =
-
-# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
-# patterns (like *.h and *.hpp) to filter out the header-files in the
-# directories. If left blank, the patterns specified with FILE_PATTERNS will
-# be used.
-
-INCLUDE_FILE_PATTERNS =
-
-# The PREDEFINED tag can be used to specify one or more macro names that
-# are defined before the preprocessor is started (similar to the -D option of
-# gcc). The argument of the tag is a list of macros of the form: name
-# or name=definition (no spaces). If the definition and the = are
-# omitted =1 is assumed.
-
-PREDEFINED = __attribute__(x)="" "RENAME(x)=x ## _TMPL" "DEF(x)=x ## _TMPL" \
- HAVE_BUILTIN_VECTOR HAVE_AV_CONFIG_H HAVE_MMX HAVE_MMX2 HAVE_3DNOW \
- ATTR_ALIGN(x)=""
-
-# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
-# this tag can be used to specify a list of macro names that should be expanded.
-# The macro definition that is found in the sources will be used.
-# Use the PREDEFINED tag if you want to use a different macro definition.
-
-#EXPAND_AS_DEFINED = FF_COMMON_FRAME
-EXPAND_AS_DEFINED = declare_idct(idct, table, idct_row_head, idct_row, idct_row_tail, idct_row_mid)
-
-# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
-# doxygen's preprocessor will remove all function-like macros that are alone
-# on a line, have an all uppercase name, and do not end with a semicolon. Such
-# function macros are typically used for boiler-plate code, and will confuse the
-# parser if not removed.
-
-SKIP_FUNCTION_MACROS = YES
-
-#---------------------------------------------------------------------------
-# Configuration::addtions related to external references
-#---------------------------------------------------------------------------
-
-# The TAGFILES tag can be used to specify one or more tagfiles.
-
-TAGFILES =
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create
-# a tag file that is based on the input files it reads.
-
-GENERATE_TAGFILE =
-
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed
-# in the class index. If set to NO only the inherited external classes
-# will be listed.
-
-ALLEXTERNALS = NO
-
-# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
-# in the modules index. If set to NO, only the current project's groups will
-# be listed.
-
-EXTERNAL_GROUPS = YES
-
-# The PERL_PATH should be the absolute path and name of the perl script
-# interpreter (i.e. the result of `which perl').
-
-PERL_PATH = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
-# generate a inheritance diagram (in Html, RTF and LaTeX) for classes with base or
-# super classes. Setting the tag to NO turns the diagrams off. Note that this
-# option is superceded by the HAVE_DOT option below. This is only a fallback. It is
-# recommended to install and use dot, since it yield more powerful graphs.
-
-CLASS_DIAGRAMS = YES
-
-# If set to YES, the inheritance and collaboration graphs will hide
-# inheritance and usage relations if the target is undocumented
-# or is not a class.
-
-HIDE_UNDOC_RELATIONS = YES
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
-# available from the path. This tool is part of Graphviz, a graph visualization
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section
-# have no effect if this option is set to NO (the default)
-
-HAVE_DOT = NO
-
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect inheritance relations. Setting this tag to YES will force the
-# the CLASS_DIAGRAMS tag to NO.
-
-CLASS_GRAPH = YES
-
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
-# will generate a graph for each documented class showing the direct and
-# indirect implementation dependencies (inheritance, containment, and
-# class references variables) of the class with other documented classes.
-
-COLLABORATION_GRAPH = YES
-
-# If set to YES, the inheritance and collaboration graphs will show the
-# relations between templates and their instances.
-
-TEMPLATE_RELATIONS = YES
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
-# tags are set to YES then doxygen will generate a graph for each documented
-# file showing the direct and indirect include dependencies of the file with
-# other documented files.
-
-INCLUDE_GRAPH = YES
-
-# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
-# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
-# documented header file showing the documented files that directly or
-# indirectly include this file.
-
-INCLUDED_BY_GRAPH = YES
-
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
-# will graphical hierarchy of all classes instead of a textual one.
-
-GRAPHICAL_HIERARCHY = YES
-
-# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
-# generated by dot. Possible values are png, jpg, or gif
-# If left blank png will be used.
-
-DOT_IMAGE_FORMAT = png
-
-# The tag DOT_PATH can be used to specify the path where the dot tool can be
-# found. If left blank, it is assumed the dot tool can be found on the path.
-
-DOT_PATH =
-
-# The DOTFILE_DIRS tag can be used to specify one or more directories that
-# contain dot files that are included in the documentation (see the
-# \dotfile command).
-
-DOTFILE_DIRS =
-
-# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
-
-MAX_DOT_GRAPH_WIDTH = 1024
-
-# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than
-# this value, doxygen will try to truncate the graph, so that it fits within
-# the specified constraint. Beware that most browsers cannot cope with very
-# large images.
-
-MAX_DOT_GRAPH_HEIGHT = 1024
-
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
-# generate a legend page explaining the meaning of the various boxes and
-# arrows in the dot generated graphs.
-
-GENERATE_LEGEND = YES
-
-# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
-# remove the intermedate dot files that are used to generate
-# the various graphs.
-
-DOT_CLEANUP = YES
-
-#---------------------------------------------------------------------------
-# Configuration::addtions related to the search engine
-#---------------------------------------------------------------------------
-
-# The SEARCHENGINE tag specifies whether or not a search engine should be
-# used. If set to NO the values of all tags below this one will be ignored.
-
-SEARCHENGINE = NO
-
-# The CGI_NAME tag should be the name of the CGI script that
-# starts the search engine (doxysearch) with the correct parameters.
-# A script with this name will be generated by doxygen.
-
-CGI_NAME = search.cgi
-
-# The CGI_URL tag should be the absolute URL to the directory where the
-# cgi binaries are located. See the documentation of your http daemon for
-# details.
-
-CGI_URL =
-
-# The DOC_URL tag should be the absolute URL to the directory where the
-# documentation is located. If left blank the absolute path to the
-# documentation, with file:// prepended to it, will be used.
-
-DOC_URL =
-
-# The DOC_ABSPATH tag should be the absolute path to the directory where the
-# documentation is located. If left blank the directory on the local machine
-# will be used.
-
-DOC_ABSPATH =
-
-# The BIN_ABSPATH tag must point to the directory where the doxysearch binary
-# is installed.
-
-BIN_ABSPATH = /usr/local/bin/
-
-# The EXT_DOC_PATHS tag can be used to specify one or more paths to
-# documentation generated for other projects. This allows doxysearch to search
-# the documentation for these projects as well.
-
-EXT_DOC_PATHS =
+++ /dev/null
-#
-# libavcodec Makefile
-# (c) 2000-2003 Fabrice Bellard
-#
-include ../config.mak
-
-VPATH=$(SRC_PATH)/libavcodec
-
-# NOTE: -I.. is needed to include config.h
-CFLAGS= $(OPTFLAGS) -Wall -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
-
-OBJS= common.o utils.o mem.o allcodecs.o \
- mpegvideo.o jrevdct.o jfdctfst.o jfdctint.o\
- mpegaudio.o ac3enc.o mjpeg.o resample.o dsputil.o \
- motion_est.o imgconvert.o imgresample.o \
- mpeg12.o mpegaudiodec.o pcm.o simple_idct.o \
- ratecontrol.o adpcm.o eval.o dv.o error_resilience.o \
- fft.o mdct.o mace.o huffyuv.o cyuv.o opts.o raw.o h264.o golomb.o \
- vp3.o asv1.o 4xm.o cabac.o ffv1.o ra144.o ra288.o vcr1.o cljr.o \
- roqvideo.o dpcm.o interplayvideo.o xan.o
-
-ifeq ($(AMR_NB),yes)
-ifeq ($(AMR_NB_FIXED),yes)
-OBJS+= amr.o
-AMREXTRALIBS+= amr/*.o
-AMRLIBS=amrlibs
-CLEANAMR=cleanamr
-else
-OBJS+= amr.o amr_float/sp_dec.o amr_float/sp_enc.o amr_float/interf_dec.o amr_float/interf_enc.o
-CLEANAMR=cleanamrfloat
-endif
-endif
-
-ASM_OBJS=
-
-# codecs which are patented in some non free countries like the us
-ifeq ($(CONFIG_RISKY),yes)
-OBJS+= h263.o msmpeg4.o h263dec.o svq1.o rv10.o wmadec.o indeo3.o
-endif
-
-ifeq ($(HAVE_XVMC_ACCEL),yes)
-OBJS+= xvmcvideo.o
-endif
-
-# currently using liba52 for ac3 decoding
-ifeq ($(CONFIG_AC3),yes)
-OBJS+= a52dec.o
-
-# using builtin liba52 or runtime linked liba52.so.0
-ifneq ($(CONFIG_A52BIN),yes)
-OBJS+= liba52/bit_allocate.o liba52/bitstream.o liba52/downmix.o \
- liba52/imdct.o liba52/parse.o liba52/crc.o liba52/resample.o
-endif
-endif
-
-ifeq ($(CONFIG_FAAD),yes)
-OBJS+= faad.o
-ifeq ($(CONFIG_FAADBIN),yes)
-# no libs needed
-else
-EXTRALIBS += -lfaad
-endif
-endif
-
-ifeq ($(CONFIG_PP),yes)
-ifeq ($(SHARED_PP),yes)
-EXTRALIBS += -lpostproc
-else
-# LIBS += libpostproc/libpostproc.a ... should be fixed
-OBJS += libpostproc/postprocess.o
-endif
-endif
-
-ifeq ($(CONFIG_MP3LAME),yes)
-OBJS += mp3lameaudio.o
-EXTRALIBS += -lmp3lame
-endif
-
-ifeq ($(CONFIG_VORBIS),yes)
-OBJS += oggvorbis.o
-EXTRALIBS += -lvorbis -lvorbisenc
-endif
-
-ifeq ($(TARGET_GPROF),yes)
-CFLAGS+=-p
-LDFLAGS+=-p
-endif
-
-# i386 mmx specific stuff
-ifeq ($(TARGET_MMX),yes)
-OBJS += i386/fdct_mmx.o i386/cputest.o \
- i386/dsputil_mmx.o i386/mpegvideo_mmx.o \
- i386/idct_mmx.o i386/motion_est_mmx.o \
- i386/simple_idct_mmx.o i386/fft_sse.o
-ifdef TARGET_BUILTIN_VECTOR
-i386/fft_sse.o: CFLAGS+= -msse
-endif
-endif
-
-# armv4l specific stuff
-ifeq ($(TARGET_ARCH_ARMV4L),yes)
-ASM_OBJS += armv4l/jrevdct_arm.o armv4l/simple_idct_arm.o
-OBJS += armv4l/dsputil_arm.o armv4l/mpegvideo_arm.o
-endif
-
-# sun mediaLib specific stuff
-# currently only works when libavcodec is used in mplayer
-ifeq ($(HAVE_MLIB),yes)
-OBJS += mlib/dsputil_mlib.o
-CFLAGS += $(MLIB_INC)
-endif
-
-# alpha specific stuff
-ifeq ($(TARGET_ARCH_ALPHA),yes)
-OBJS += alpha/dsputil_alpha.o alpha/mpegvideo_alpha.o \
- alpha/simple_idct_alpha.o alpha/motion_est_alpha.o
-ASM_OBJS += alpha/dsputil_alpha_asm.o alpha/motion_est_mvi_asm.o
-CFLAGS += -fforce-addr -freduce-all-givs
-endif
-
-ifeq ($(TARGET_ARCH_POWERPC),yes)
-OBJS += ppc/dsputil_ppc.o ppc/mpegvideo_ppc.o
-endif
-
-ifeq ($(TARGET_MMI),yes)
-OBJS += ps2/dsputil_mmi.o ps2/idct_mmi.o ps2/mpegvideo_mmi.o
-endif
-
-ifeq ($(TARGET_ALTIVEC),yes)
-OBJS += ppc/dsputil_altivec.o ppc/mpegvideo_altivec.o ppc/idct_altivec.o \
- ppc/fft_altivec.o ppc/gmc_altivec.o
-endif
-
-ifeq ($(TARGET_ARCH_SH4),yes)
-OBJS+= sh4/idct_sh4.o sh4/dsputil_sh4.o sh4/dsputil_align.o
-endif
-
-
-SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S)
-OBJS := $(OBJS) $(ASM_OBJS)
-
-LIB= $(LIBPREF)avcodec$(LIBSUF)
-ifeq ($(BUILD_SHARED),yes)
-SLIB= $(SLIBPREF)avcodec$(SLIBSUF)
-endif
-TESTS= imgresample-test dct-test motion-test fft-test
-
-all: $(LIB) $(SLIB)
-
-amrlibs:
- $(MAKE) -C amr spclib fipoplib
-
-tests: apiexample cpuid_test $(TESTS)
-
-$(LIB): $(OBJS) $(AMRLIBS)
- rm -f $@
- $(AR) rc $@ $(OBJS) $(AMREXTRALIBS)
- $(RANLIB) $@
-
-$(SLIB): $(OBJS)
-ifeq ($(CONFIG_WIN32),yes)
- $(CC) $(SHFLAGS) -Wl,--output-def,$(@:.dll=.def) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS)
- -lib /machine:i386 /def:$(@:.dll=.def)
-else
- $(CC) $(SHFLAGS) -o $@ $(OBJS) $(EXTRALIBS) $(AMREXTRALIBS)
-endif
-
-dsputil.o: dsputil.c dsputil.h
-
-libpostproc/libpostproc.a:
- $(MAKE) -C libpostproc
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-%.o: %.S
- $(CC) $(CFLAGS) -c -o $@ $<
-
-depend: $(SRCS)
- $(CC) -MM $(CFLAGS) $^ 1>.depend
-
-dep: depend
-
-clean: $(CLEANAMR)
- rm -f *.o *.d *~ .depend $(LIB) $(SLIB) *.so i386/*.o i386/*~ \
- armv4l/*.o armv4l/*~ \
- mlib/*.o mlib/*~ \
- alpha/*.o alpha/*~ \
- ppc/*.o ppc/*~ \
- ps2/*.o ps2/*~ \
- sh4/*.o sh4/*~ \
- liba52/*.o liba52/*~ \
- apiexample $(TESTS)
- $(MAKE) -C libpostproc clean
-
-distclean: clean
- rm -f Makefile.bak .depend
-
-cleanamr:
- $(MAKE) -C amr clean
-
-cleanamrfloat:
- rm -f amr_float/*.o
-
-# api example program
-apiexample: apiexample.c $(LIB)
- $(CC) $(CFLAGS) -o $@ $< $(LIB) $(EXTRALIBS) -lm
-
-# cpuid test
-cpuid_test: i386/cputest.c
- $(CC) $(CFLAGS) -D__TEST__ -o $@ $<
-
-# testing progs
-
-imgresample-test: imgresample.c
- $(CC) $(CFLAGS) -DTEST -o $@ $^ -lm
-
-dct-test: dct-test.o fdctref.o $(LIB)
- $(CC) -o $@ $^ -lm
-
-motion-test: motion_test.o $(LIB)
- $(CC) -o $@ $^ -lm
-
-fft-test: fft-test.o $(LIB)
- $(CC) -o $@ $^ -lm
-
-ifeq ($(BUILD_SHARED),yes)
-install: all install-headers
-ifeq ($(CONFIG_WIN32),yes)
- install -s -m 755 $(SLIB) "$(prefix)"
-else
- install -d $(prefix)/lib
- install -s -m 755 $(SLIB) $(prefix)/lib/libavcodec-$(VERSION).so
- ln -sf libavcodec-$(VERSION).so $(prefix)/lib/libavcodec.so
- ldconfig || true
-endif
-else
-install:
-endif
-
-installlib: all install-headers
- install -m 644 $(LIB) $(prefix)/lib
-
-install-headers:
- mkdir -p "$(prefix)/include/ffmpeg"
- install -m 644 $(SRC_PATH)/libavcodec/avcodec.h $(SRC_PATH)/libavcodec/common.h \
- "$(prefix)/include/ffmpeg"
-
-#
-# include dependency files if they exist
-#
-ifneq ($(wildcard .depend),)
-include .depend
-endif
+++ /dev/null
-EXTRA_DIST= *.nsh
+++ /dev/null
-/*
- * A52 decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file a52dec.c
- * A52 decoder.
- */
-
-#include "avcodec.h"
-#include "liba52/a52.h"
-
-#ifdef CONFIG_A52BIN
-#include <dlfcn.h>
-static const char* liba52name = "liba52.so.0";
-#endif
-
-/**
- * liba52 - Copyright (C) Aaron Holtzman
- * released under the GPL license.
- */
-typedef struct AC3DecodeState {
- uint8_t inbuf[4096]; /* input buffer */
- uint8_t *inbuf_ptr;
- int frame_size;
- int flags;
- int channels;
- a52_state_t* state;
- sample_t* samples;
-
- /*
- * virtual method table
- *
- * using this function table so the liba52 doesn't
- * have to be really linked together with ffmpeg
- * and might be linked in runtime - this allows binary
- * distribution of ffmpeg library which doens't depend
- * on liba52 library - but if user has it installed
- * it will be used - user might install such library
- * separately
- */
- void* handle;
- a52_state_t* (*a52_init)(uint32_t mm_accel);
- sample_t* (*a52_samples)(a52_state_t * state);
- int (*a52_syncinfo)(uint8_t * buf, int * flags,
- int * sample_rate, int * bit_rate);
- int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags,
- sample_t * level, sample_t bias);
- void (*a52_dynrng)(a52_state_t * state,
- sample_t (* call) (sample_t, void *), void * data);
- int (*a52_block)(a52_state_t * state);
- void (*a52_free)(a52_state_t * state);
-
-} AC3DecodeState;
-
-#ifdef CONFIG_A52BIN
-static void* dlsymm(void* handle, const char* symbol)
-{
- void* f = dlsym(handle, symbol);
- if (!f)
- fprintf(stderr, "A52 Decoder - function '%s' can't be resolved\n", symbol);
- return f;
-}
-#endif
-
-static int a52_decode_init(AVCodecContext *avctx)
-{
- AC3DecodeState *s = avctx->priv_data;
-
-#ifdef CONFIG_A52BIN
- s->handle = dlopen(liba52name, RTLD_LAZY);
- if (!s->handle)
- {
- fprintf(stderr, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror());
- return -1;
- }
- s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init");
- s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples");
- s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo");
- s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame");
- s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block");
- s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free");
- if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo
- || !s->a52_frame || !s->a52_block || !s->a52_free)
- {
- dlclose(s->handle);
- return -1;
- }
-#else
- /* static linked version */
- s->handle = 0;
- s->a52_init = a52_init;
- s->a52_samples = a52_samples;
- s->a52_syncinfo = a52_syncinfo;
- s->a52_frame = a52_frame;
- s->a52_block = a52_block;
- s->a52_free = a52_free;
-#endif
- s->state = s->a52_init(0); /* later use CPU flags */
- s->samples = s->a52_samples(s->state);
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
-
- return 0;
-}
-
-/**** the following two functions comes from a52dec */
-static inline int blah (int32_t i)
-{
- if (i > 0x43c07fff)
- return 32767;
- else if (i < 0x43bf8000)
- return -32768;
- return i - 0x43c00000;
-}
-
-static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
-{
- int i, j, c;
- int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format
-
- j = 0;
- nchannels *= 256;
- for (i = 0; i < 256; i++) {
- for (c = 0; c < nchannels; c += 256)
- s16[j++] = blah (f[i + c]);
- }
-}
-
-/**** end */
-
-#define HEADER_SIZE 7
-
-static int a52_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- AC3DecodeState *s = avctx->priv_data;
- uint8_t *buf_ptr;
- int flags, i, len;
- int sample_rate, bit_rate;
- short *out_samples = data;
- float level;
- static const int ac3_channels[8] = {
- 2, 1, 2, 3, 3, 4, 4, 5
- };
-
- *data_size = 0;
- buf_ptr = buf;
- while (buf_size > 0) {
- len = s->inbuf_ptr - s->inbuf;
- if (s->frame_size == 0) {
- /* no header seen : find one. We need at least 7 bytes to parse it */
- len = HEADER_SIZE - len;
- if (len > buf_size)
- len = buf_size;
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
- len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate);
- if (len == 0) {
- /* no sync found : move by one byte (inefficient, but simple!) */
- memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
- s->inbuf_ptr--;
- } else {
- s->frame_size = len;
- /* update codec info */
- avctx->sample_rate = sample_rate;
- s->channels = ac3_channels[s->flags & 7];
- if (s->flags & A52_LFE)
- s->channels++;
- if (avctx->channels == 0)
- /* No specific number of channel requested */
- avctx->channels = s->channels;
- else if (s->channels < avctx->channels) {
- fprintf(stderr, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);
- avctx->channels = s->channels;
- }
- avctx->bit_rate = bit_rate;
- }
- }
- } else if (len < s->frame_size) {
- len = s->frame_size - len;
- if (len > buf_size)
- len = buf_size;
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- } else {
- flags = s->flags;
- if (avctx->channels == 1)
- flags = A52_MONO;
- else if (avctx->channels == 2)
- flags = A52_STEREO;
- else
- flags |= A52_ADJUST_LEVEL;
- level = 1;
- if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) {
- fail:
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- continue;
- }
- for (i = 0; i < 6; i++) {
- if (s->a52_block(s->state))
- goto fail;
- float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels);
- }
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
- break;
- }
- }
- return buf_ptr - buf;
-}
-
-static int a52_decode_end(AVCodecContext *avctx)
-{
- AC3DecodeState *s = avctx->priv_data;
- s->a52_free(s->state);
-#ifdef CONFIG_A52BIN
- dlclose(s->handle);
-#endif
- return 0;
-}
-
-AVCodec ac3_decoder = {
- "ac3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_AC3,
- sizeof(AC3DecodeState),
- a52_decode_init,
- NULL,
- a52_decode_end,
- a52_decode_frame,
-};
+++ /dev/null
-/*
- * Common code between AC3 encoder and decoder
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file ac3.h
- * Common code between AC3 encoder and decoder.
- */
-
-#define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */
-#define AC3_MAX_CHANNELS 6 /* including LFE channel */
-
-#define NB_BLOCKS 6 /* number of PCM blocks inside an AC3 frame */
-#define AC3_FRAME_SIZE (NB_BLOCKS * 256)
-
-/* exponent encoding strategy */
-#define EXP_REUSE 0
-#define EXP_NEW 1
-
-#define EXP_D15 1
-#define EXP_D25 2
-#define EXP_D45 3
-
-typedef struct AC3BitAllocParameters {
- int fscod; /* frequency */
- int halfratecod;
- int sgain, sdecay, fdecay, dbknee, floor;
- int cplfleak, cplsleak;
-} AC3BitAllocParameters;
-
-extern const uint16_t ac3_freqs[3];
-extern const uint16_t ac3_bitratetab[19];
-extern const int16_t ac3_window[256];
-extern const uint8_t sdecaytab[4];
-extern const uint8_t fdecaytab[4];
-extern const uint16_t sgaintab[4];
-extern const uint16_t dbkneetab[4];
-extern const uint16_t floortab[8];
-extern const uint16_t fgaintab[8];
-
-void ac3_common_init(void);
-void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
- int8_t *exp, int start, int end,
- int snroffset, int fgain, int is_lfe,
- int deltbae,int deltnseg,
- uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba);
+++ /dev/null
-/*
- * AC3 decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file ac3dec.c
- * AC3 decoder.
- */
-
-//#define DEBUG
-
-#include "avcodec.h"
-#include "libac3/ac3.h"
-
-/* currently, I use libac3 which is Copyright (C) Aaron Holtzman and
- released under the GPL license. I may reimplement it someday... */
-typedef struct AC3DecodeState {
- uint8_t inbuf[4096]; /* input buffer */
- uint8_t *inbuf_ptr;
- int frame_size;
- int flags;
- int channels;
- ac3_state_t state;
-} AC3DecodeState;
-
-static int ac3_decode_init(AVCodecContext *avctx)
-{
- AC3DecodeState *s = avctx->priv_data;
-
- ac3_init ();
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- return 0;
-}
-
-stream_samples_t samples;
-
-/**** the following two functions comes from ac3dec */
-static inline int blah (int32_t i)
-{
- if (i > 0x43c07fff)
- return 32767;
- else if (i < 0x43bf8000)
- return -32768;
- else
- return i - 0x43c00000;
-}
-
-static inline void float_to_int (float * _f, int16_t * s16, int nchannels)
-{
- int i, j, c;
- int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format
-
- j = 0;
- nchannels *= 256;
- for (i = 0; i < 256; i++) {
- for (c = 0; c < nchannels; c += 256)
- s16[j++] = blah (f[i + c]);
- }
-}
-
-/**** end */
-
-#define HEADER_SIZE 7
-
-static int ac3_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- AC3DecodeState *s = avctx->priv_data;
- uint8_t *buf_ptr;
- int flags, i, len;
- int sample_rate, bit_rate;
- short *out_samples = data;
- float level;
- static const int ac3_channels[8] = {
- 2, 1, 2, 3, 3, 4, 4, 5
- };
-
- *data_size = 0;
- buf_ptr = buf;
- while (buf_size > 0) {
- len = s->inbuf_ptr - s->inbuf;
- if (s->frame_size == 0) {
- /* no header seen : find one. We need at least 7 bytes to parse it */
- len = HEADER_SIZE - len;
- if (len > buf_size)
- len = buf_size;
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) {
- len = ac3_syncinfo (s->inbuf, &s->flags, &sample_rate, &bit_rate);
- if (len == 0) {
- /* no sync found : move by one byte (inefficient, but simple!) */
- memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1);
- s->inbuf_ptr--;
- } else {
- s->frame_size = len;
- /* update codec info */
- avctx->sample_rate = sample_rate;
- s->channels = ac3_channels[s->flags & 7];
- if (s->flags & AC3_LFE)
- s->channels++;
- if (avctx->channels == 0)
- /* No specific number of channel requested */
- avctx->channels = s->channels;
- else if (s->channels < avctx->channels) {
- fprintf(stderr, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len);
- avctx->channels = s->channels;
- }
- avctx->bit_rate = bit_rate;
- }
- }
- } else if (len < s->frame_size) {
- len = s->frame_size - len;
- if (len > buf_size)
- len = buf_size;
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- } else {
- flags = s->flags;
- if (avctx->channels == 1)
- flags = AC3_MONO;
- else if (avctx->channels == 2)
- flags = AC3_STEREO;
- else
- flags |= AC3_ADJUST_LEVEL;
- level = 1;
- if (ac3_frame (&s->state, s->inbuf, &flags, &level, 384)) {
- fail:
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- continue;
- }
- for (i = 0; i < 6; i++) {
- if (ac3_block (&s->state))
- goto fail;
- float_to_int (*samples, out_samples + i * 256 * avctx->channels, avctx->channels);
- }
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- *data_size = 6 * avctx->channels * 256 * sizeof(int16_t);
- break;
- }
- }
- return buf_ptr - buf;
-}
-
-static int ac3_decode_end(AVCodecContext *s)
-{
- return 0;
-}
-
-AVCodec ac3_decoder = {
- "ac3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_AC3,
- sizeof(AC3DecodeState),
- ac3_decode_init,
- NULL,
- ac3_decode_end,
- ac3_decode_frame,
-};
+++ /dev/null
-/*
- * The simplest AC3 encoder
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file ac3enc.c
- * The simplest AC3 encoder.
- */
-//#define DEBUG
-//#define DEBUG_BITALLOC
-#include "avcodec.h"
-
-#include "ac3.h"
-
-typedef struct AC3EncodeContext {
- PutBitContext pb;
- int nb_channels;
- int nb_all_channels;
- int lfe_channel;
- int bit_rate;
- unsigned int sample_rate;
- unsigned int bsid;
- unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
- unsigned int frame_size; /* current frame size in words */
- int halfratecod;
- unsigned int frmsizecod;
- unsigned int fscod; /* frequency */
- unsigned int acmod;
- int lfe;
- unsigned int bsmod;
- short last_samples[AC3_MAX_CHANNELS][256];
- unsigned int chbwcod[AC3_MAX_CHANNELS];
- int nb_coefs[AC3_MAX_CHANNELS];
-
- /* bitrate allocation control */
- int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod;
- AC3BitAllocParameters bit_alloc;
- int csnroffst;
- int fgaincod[AC3_MAX_CHANNELS];
- int fsnroffst[AC3_MAX_CHANNELS];
- /* mantissa encoding */
- int mant1_cnt, mant2_cnt, mant4_cnt;
-} AC3EncodeContext;
-
-#include "ac3tab.h"
-
-#define MDCT_NBITS 9
-#define N (1 << MDCT_NBITS)
-
-/* new exponents are sent if their Norm 1 exceed this number */
-#define EXP_DIFF_THRESHOLD 1000
-
-static void fft_init(int ln);
-static void ac3_crc_init(void);
-
-static inline int16_t fix15(float a)
-{
- int v;
- v = (int)(a * (float)(1 << 15));
- if (v < -32767)
- v = -32767;
- else if (v > 32767)
- v = 32767;
- return v;
-}
-
-static inline int calc_lowcomp1(int a, int b0, int b1)
-{
- if ((b0 + 256) == b1) {
- a = 384 ;
- } else if (b0 > b1) {
- a = a - 64;
- if (a < 0) a=0;
- }
- return a;
-}
-
-static inline int calc_lowcomp(int a, int b0, int b1, int bin)
-{
- if (bin < 7) {
- if ((b0 + 256) == b1) {
- a = 384 ;
- } else if (b0 > b1) {
- a = a - 64;
- if (a < 0) a=0;
- }
- } else if (bin < 20) {
- if ((b0 + 256) == b1) {
- a = 320 ;
- } else if (b0 > b1) {
- a= a - 64;
- if (a < 0) a=0;
- }
- } else {
- a = a - 128;
- if (a < 0) a=0;
- }
- return a;
-}
-
-/* AC3 bit allocation. The algorithm is the one described in the AC3
- spec. */
-void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap,
- int8_t *exp, int start, int end,
- int snroffset, int fgain, int is_lfe,
- int deltbae,int deltnseg,
- uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba)
-{
- int bin,i,j,k,end1,v,v1,bndstrt,bndend,lowcomp,begin;
- int fastleak,slowleak,address,tmp;
- int16_t psd[256]; /* scaled exponents */
- int16_t bndpsd[50]; /* interpolated exponents */
- int16_t excite[50]; /* excitation */
- int16_t mask[50]; /* masking value */
-
- /* exponent mapping to PSD */
- for(bin=start;bin<end;bin++) {
- psd[bin]=(3072 - (exp[bin] << 7));
- }
-
- /* PSD integration */
- j=start;
- k=masktab[start];
- do {
- v=psd[j];
- j++;
- end1=bndtab[k+1];
- if (end1 > end) end1=end;
- for(i=j;i<end1;i++) {
- int c,adr;
- /* logadd */
- v1=psd[j];
- c=v-v1;
- if (c >= 0) {
- adr=c >> 1;
- if (adr > 255) adr=255;
- v=v + latab[adr];
- } else {
- adr=(-c) >> 1;
- if (adr > 255) adr=255;
- v=v1 + latab[adr];
- }
- j++;
- }
- bndpsd[k]=v;
- k++;
- } while (end > bndtab[k]);
-
- /* excitation function */
- bndstrt = masktab[start];
- bndend = masktab[end-1] + 1;
-
- if (bndstrt == 0) {
- lowcomp = 0;
- lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1]) ;
- excite[0] = bndpsd[0] - fgain - lowcomp ;
- lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2]) ;
- excite[1] = bndpsd[1] - fgain - lowcomp ;
- begin = 7 ;
- for (bin = 2; bin < 7; bin++) {
- if (!(is_lfe && bin == 6))
- lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1]) ;
- fastleak = bndpsd[bin] - fgain ;
- slowleak = bndpsd[bin] - s->sgain ;
- excite[bin] = fastleak - lowcomp ;
- if (!(is_lfe && bin == 6)) {
- if (bndpsd[bin] <= bndpsd[bin+1]) {
- begin = bin + 1 ;
- break ;
- }
- }
- }
-
- end1=bndend;
- if (end1 > 22) end1=22;
-
- for (bin = begin; bin < end1; bin++) {
- if (!(is_lfe && bin == 6))
- lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin) ;
-
- fastleak -= s->fdecay ;
- v = bndpsd[bin] - fgain;
- if (fastleak < v) fastleak = v;
-
- slowleak -= s->sdecay ;
- v = bndpsd[bin] - s->sgain;
- if (slowleak < v) slowleak = v;
-
- v=fastleak - lowcomp;
- if (slowleak > v) v=slowleak;
-
- excite[bin] = v;
- }
- begin = 22;
- } else {
- /* coupling channel */
- begin = bndstrt;
-
- fastleak = (s->cplfleak << 8) + 768;
- slowleak = (s->cplsleak << 8) + 768;
- }
-
- for (bin = begin; bin < bndend; bin++) {
- fastleak -= s->fdecay ;
- v = bndpsd[bin] - fgain;
- if (fastleak < v) fastleak = v;
- slowleak -= s->sdecay ;
- v = bndpsd[bin] - s->sgain;
- if (slowleak < v) slowleak = v;
-
- v=fastleak;
- if (slowleak > v) v = slowleak;
- excite[bin] = v;
- }
-
- /* compute masking curve */
-
- for (bin = bndstrt; bin < bndend; bin++) {
- v1 = excite[bin];
- tmp = s->dbknee - bndpsd[bin];
- if (tmp > 0) {
- v1 += tmp >> 2;
- }
- v=hth[bin >> s->halfratecod][s->fscod];
- if (v1 > v) v=v1;
- mask[bin] = v;
- }
-
- /* delta bit allocation */
-
- if (deltbae == 0 || deltbae == 1) {
- int band, seg, delta;
- band = 0 ;
- for (seg = 0; seg < deltnseg; seg++) {
- band += deltoffst[seg] ;
- if (deltba[seg] >= 4) {
- delta = (deltba[seg] - 3) << 7;
- } else {
- delta = (deltba[seg] - 4) << 7;
- }
- for (k = 0; k < deltlen[seg]; k++) {
- mask[band] += delta ;
- band++ ;
- }
- }
- }
-
- /* compute bit allocation */
-
- i = start ;
- j = masktab[start] ;
- do {
- v=mask[j];
- v -= snroffset ;
- v -= s->floor ;
- if (v < 0) v = 0;
- v &= 0x1fe0 ;
- v += s->floor ;
-
- end1=bndtab[j] + bndsz[j];
- if (end1 > end) end1=end;
-
- for (k = i; k < end1; k++) {
- address = (psd[i] - v) >> 5 ;
- if (address < 0) address=0;
- else if (address > 63) address=63;
- bap[i] = baptab[address];
- i++;
- }
- } while (end > bndtab[j++]) ;
-}
-
-typedef struct IComplex {
- short re,im;
-} IComplex;
-
-static void fft_init(int ln)
-{
- int i, j, m, n;
- float alpha;
-
- n = 1 << ln;
-
- for(i=0;i<(n/2);i++) {
- alpha = 2 * M_PI * (float)i / (float)n;
- costab[i] = fix15(cos(alpha));
- sintab[i] = fix15(sin(alpha));
- }
-
- for(i=0;i<n;i++) {
- m=0;
- for(j=0;j<ln;j++) {
- m |= ((i >> j) & 1) << (ln-j-1);
- }
- fft_rev[i]=m;
- }
-}
-
-/* butter fly op */
-#define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
-{\
- int ax, ay, bx, by;\
- bx=pre1;\
- by=pim1;\
- ax=qre1;\
- ay=qim1;\
- pre = (bx + ax) >> 1;\
- pim = (by + ay) >> 1;\
- qre = (bx - ax) >> 1;\
- qim = (by - ay) >> 1;\
-}
-
-#define MUL16(a,b) ((a) * (b))
-
-#define CMUL(pre, pim, are, aim, bre, bim) \
-{\
- pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15;\
- pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15;\
-}
-
-
-/* do a 2^n point complex fft on 2^ln points. */
-static void fft(IComplex *z, int ln)
-{
- int j, l, np, np2;
- int nblocks, nloops;
- register IComplex *p,*q;
- int tmp_re, tmp_im;
-
- np = 1 << ln;
-
- /* reverse */
- for(j=0;j<np;j++) {
- int k;
- IComplex tmp;
- k = fft_rev[j];
- if (k < j) {
- tmp = z[k];
- z[k] = z[j];
- z[j] = tmp;
- }
- }
-
- /* pass 0 */
-
- p=&z[0];
- j=(np >> 1);
- do {
- BF(p[0].re, p[0].im, p[1].re, p[1].im,
- p[0].re, p[0].im, p[1].re, p[1].im);
- p+=2;
- } while (--j != 0);
-
- /* pass 1 */
-
- p=&z[0];
- j=np >> 2;
- do {
- BF(p[0].re, p[0].im, p[2].re, p[2].im,
- p[0].re, p[0].im, p[2].re, p[2].im);
- BF(p[1].re, p[1].im, p[3].re, p[3].im,
- p[1].re, p[1].im, p[3].im, -p[3].re);
- p+=4;
- } while (--j != 0);
-
- /* pass 2 .. ln-1 */
-
- nblocks = np >> 3;
- nloops = 1 << 2;
- np2 = np >> 1;
- do {
- p = z;
- q = z + nloops;
- for (j = 0; j < nblocks; ++j) {
-
- BF(p->re, p->im, q->re, q->im,
- p->re, p->im, q->re, q->im);
-
- p++;
- q++;
- for(l = nblocks; l < np2; l += nblocks) {
- CMUL(tmp_re, tmp_im, costab[l], -sintab[l], q->re, q->im);
- BF(p->re, p->im, q->re, q->im,
- p->re, p->im, tmp_re, tmp_im);
- p++;
- q++;
- }
- p += nloops;
- q += nloops;
- }
- nblocks = nblocks >> 1;
- nloops = nloops << 1;
- } while (nblocks != 0);
-}
-
-/* do a 512 point mdct */
-static void mdct512(int32_t *out, int16_t *in)
-{
- int i, re, im, re1, im1;
- int16_t rot[N];
- IComplex x[N/4];
-
- /* shift to simplify computations */
- for(i=0;i<N/4;i++)
- rot[i] = -in[i + 3*N/4];
- for(i=N/4;i<N;i++)
- rot[i] = in[i - N/4];
-
- /* pre rotation */
- for(i=0;i<N/4;i++) {
- re = ((int)rot[2*i] - (int)rot[N-1-2*i]) >> 1;
- im = -((int)rot[N/2+2*i] - (int)rot[N/2-1-2*i]) >> 1;
- CMUL(x[i].re, x[i].im, re, im, -xcos1[i], xsin1[i]);
- }
-
- fft(x, MDCT_NBITS - 2);
-
- /* post rotation */
- for(i=0;i<N/4;i++) {
- re = x[i].re;
- im = x[i].im;
- CMUL(re1, im1, re, im, xsin1[i], xcos1[i]);
- out[2*i] = im1;
- out[N/2-1-2*i] = re1;
- }
-}
-
-/* XXX: use another norm ? */
-static int calc_exp_diff(uint8_t *exp1, uint8_t *exp2, int n)
-{
- int sum, i;
- sum = 0;
- for(i=0;i<n;i++) {
- sum += abs(exp1[i] - exp2[i]);
- }
- return sum;
-}
-
-static void compute_exp_strategy(uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
- uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
- int ch, int is_lfe)
-{
- int i, j;
- int exp_diff;
-
- /* estimate if the exponent variation & decide if they should be
- reused in the next frame */
- exp_strategy[0][ch] = EXP_NEW;
- for(i=1;i<NB_BLOCKS;i++) {
- exp_diff = calc_exp_diff(exp[i][ch], exp[i-1][ch], N/2);
-#ifdef DEBUG
- printf("exp_diff=%d\n", exp_diff);
-#endif
- if (exp_diff > EXP_DIFF_THRESHOLD)
- exp_strategy[i][ch] = EXP_NEW;
- else
- exp_strategy[i][ch] = EXP_REUSE;
- }
- if (is_lfe)
- return;
-
- /* now select the encoding strategy type : if exponents are often
- recoded, we use a coarse encoding */
- i = 0;
- while (i < NB_BLOCKS) {
- j = i + 1;
- while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE)
- j++;
- switch(j - i) {
- case 1:
- exp_strategy[i][ch] = EXP_D45;
- break;
- case 2:
- case 3:
- exp_strategy[i][ch] = EXP_D25;
- break;
- default:
- exp_strategy[i][ch] = EXP_D15;
- break;
- }
- i = j;
- }
-}
-
-/* set exp[i] to min(exp[i], exp1[i]) */
-static void exponent_min(uint8_t exp[N/2], uint8_t exp1[N/2], int n)
-{
- int i;
-
- for(i=0;i<n;i++) {
- if (exp1[i] < exp[i])
- exp[i] = exp1[i];
- }
-}
-
-/* update the exponents so that they are the ones the decoder will
- decode. Return the number of bits used to code the exponents */
-static int encode_exp(uint8_t encoded_exp[N/2],
- uint8_t exp[N/2],
- int nb_exps,
- int exp_strategy)
-{
- int group_size, nb_groups, i, j, k, recurse, exp_min, delta;
- uint8_t exp1[N/2];
-
- switch(exp_strategy) {
- case EXP_D15:
- group_size = 1;
- break;
- case EXP_D25:
- group_size = 2;
- break;
- default:
- case EXP_D45:
- group_size = 4;
- break;
- }
- nb_groups = ((nb_exps + (group_size * 3) - 4) / (3 * group_size)) * 3;
-
- /* for each group, compute the minimum exponent */
- exp1[0] = exp[0]; /* DC exponent is handled separately */
- k = 1;
- for(i=1;i<=nb_groups;i++) {
- exp_min = exp[k];
- assert(exp_min >= 0 && exp_min <= 24);
- for(j=1;j<group_size;j++) {
- if (exp[k+j] < exp_min)
- exp_min = exp[k+j];
- }
- exp1[i] = exp_min;
- k += group_size;
- }
-
- /* constraint for DC exponent */
- if (exp1[0] > 15)
- exp1[0] = 15;
-
- /* Iterate until the delta constraints between each groups are
- satisfyed. I'm sure it is possible to find a better algorithm,
- but I am lazy */
- do {
- recurse = 0;
- for(i=1;i<=nb_groups;i++) {
- delta = exp1[i] - exp1[i-1];
- if (delta > 2) {
- /* if delta too big, we encode a smaller exponent */
- exp1[i] = exp1[i-1] + 2;
- } else if (delta < -2) {
- /* if delta is too small, we must decrease the previous
- exponent, which means we must recurse */
- recurse = 1;
- exp1[i-1] = exp1[i] + 2;
- }
- }
- } while (recurse);
-
- /* now we have the exponent values the decoder will see */
- encoded_exp[0] = exp1[0];
- k = 1;
- for(i=1;i<=nb_groups;i++) {
- for(j=0;j<group_size;j++) {
- encoded_exp[k+j] = exp1[i];
- }
- k += group_size;
- }
-
-#if defined(DEBUG)
- printf("exponents: strategy=%d\n", exp_strategy);
- for(i=0;i<=nb_groups * group_size;i++) {
- printf("%d ", encoded_exp[i]);
- }
- printf("\n");
-#endif
-
- return 4 + (nb_groups / 3) * 7;
-}
-
-/* return the size in bits taken by the mantissa */
-static int compute_mantissa_size(AC3EncodeContext *s, uint8_t *m, int nb_coefs)
-{
- int bits, mant, i;
-
- bits = 0;
- for(i=0;i<nb_coefs;i++) {
- mant = m[i];
- switch(mant) {
- case 0:
- /* nothing */
- break;
- case 1:
- /* 3 mantissa in 5 bits */
- if (s->mant1_cnt == 0)
- bits += 5;
- if (++s->mant1_cnt == 3)
- s->mant1_cnt = 0;
- break;
- case 2:
- /* 3 mantissa in 7 bits */
- if (s->mant2_cnt == 0)
- bits += 7;
- if (++s->mant2_cnt == 3)
- s->mant2_cnt = 0;
- break;
- case 3:
- bits += 3;
- break;
- case 4:
- /* 2 mantissa in 7 bits */
- if (s->mant4_cnt == 0)
- bits += 7;
- if (++s->mant4_cnt == 2)
- s->mant4_cnt = 0;
- break;
- case 14:
- bits += 14;
- break;
- case 15:
- bits += 16;
- break;
- default:
- bits += mant - 1;
- break;
- }
- }
- return bits;
-}
-
-
-static int bit_alloc(AC3EncodeContext *s,
- uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
- uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
- uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
- int frame_bits, int csnroffst, int fsnroffst)
-{
- int i, ch;
-
- /* compute size */
- for(i=0;i<NB_BLOCKS;i++) {
- s->mant1_cnt = 0;
- s->mant2_cnt = 0;
- s->mant4_cnt = 0;
- for(ch=0;ch<s->nb_all_channels;ch++) {
- ac3_parametric_bit_allocation(&s->bit_alloc,
- bap[i][ch], (int8_t *)encoded_exp[i][ch],
- 0, s->nb_coefs[ch],
- (((csnroffst-15) << 4) +
- fsnroffst) << 2,
- fgaintab[s->fgaincod[ch]],
- ch == s->lfe_channel,
- 2, 0, NULL, NULL, NULL);
- frame_bits += compute_mantissa_size(s, bap[i][ch],
- s->nb_coefs[ch]);
- }
- }
-#if 0
- printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n",
- csnroffst, fsnroffst, frame_bits,
- 16 * s->frame_size - ((frame_bits + 7) & ~7));
-#endif
- return 16 * s->frame_size - frame_bits;
-}
-
-#define SNR_INC1 4
-
-static int compute_bit_allocation(AC3EncodeContext *s,
- uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
- uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
- uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
- int frame_bits)
-{
- int i, ch;
- int csnroffst, fsnroffst;
- uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
- static int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
-
- /* init default parameters */
- s->sdecaycod = 2;
- s->fdecaycod = 1;
- s->sgaincod = 1;
- s->dbkneecod = 2;
- s->floorcod = 4;
- for(ch=0;ch<s->nb_all_channels;ch++)
- s->fgaincod[ch] = 4;
-
- /* compute real values */
- s->bit_alloc.fscod = s->fscod;
- s->bit_alloc.halfratecod = s->halfratecod;
- s->bit_alloc.sdecay = sdecaytab[s->sdecaycod] >> s->halfratecod;
- s->bit_alloc.fdecay = fdecaytab[s->fdecaycod] >> s->halfratecod;
- s->bit_alloc.sgain = sgaintab[s->sgaincod];
- s->bit_alloc.dbknee = dbkneetab[s->dbkneecod];
- s->bit_alloc.floor = floortab[s->floorcod];
-
- /* header size */
- frame_bits += 65;
- // if (s->acmod == 2)
- // frame_bits += 2;
- frame_bits += frame_bits_inc[s->acmod];
-
- /* audio blocks */
- for(i=0;i<NB_BLOCKS;i++) {
- frame_bits += s->nb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
- if (s->acmod == 2)
- frame_bits++; /* rematstr */
- frame_bits += 2 * s->nb_channels; /* chexpstr[2] * c */
- if (s->lfe)
- frame_bits++; /* lfeexpstr */
- for(ch=0;ch<s->nb_channels;ch++) {
- if (exp_strategy[i][ch] != EXP_REUSE)
- frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */
- }
- frame_bits++; /* baie */
- frame_bits++; /* snr */
- frame_bits += 2; /* delta / skip */
- }
- frame_bits++; /* cplinu for block 0 */
- /* bit alloc info */
- /* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */
- /* csnroffset[6] */
- /* (fsnoffset[4] + fgaincod[4]) * c */
- frame_bits += 2*4 + 3 + 6 + s->nb_all_channels * (4 + 3);
-
- /* CRC */
- frame_bits += 16;
-
- /* now the big work begins : do the bit allocation. Modify the snr
- offset until we can pack everything in the requested frame size */
-
- csnroffst = s->csnroffst;
- while (csnroffst >= 0 &&
- bit_alloc(s, bap, encoded_exp, exp_strategy, frame_bits, csnroffst, 0) < 0)
- csnroffst -= SNR_INC1;
- if (csnroffst < 0) {
- fprintf(stderr, "Yack, Error !!!\n");
- return -1;
- }
- while ((csnroffst + SNR_INC1) <= 63 &&
- bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits,
- csnroffst + SNR_INC1, 0) >= 0) {
- csnroffst += SNR_INC1;
- memcpy(bap, bap1, sizeof(bap1));
- }
- while ((csnroffst + 1) <= 63 &&
- bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits, csnroffst + 1, 0) >= 0) {
- csnroffst++;
- memcpy(bap, bap1, sizeof(bap1));
- }
-
- fsnroffst = 0;
- while ((fsnroffst + SNR_INC1) <= 15 &&
- bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits,
- csnroffst, fsnroffst + SNR_INC1) >= 0) {
- fsnroffst += SNR_INC1;
- memcpy(bap, bap1, sizeof(bap1));
- }
- while ((fsnroffst + 1) <= 15 &&
- bit_alloc(s, bap1, encoded_exp, exp_strategy, frame_bits,
- csnroffst, fsnroffst + 1) >= 0) {
- fsnroffst++;
- memcpy(bap, bap1, sizeof(bap1));
- }
-
- s->csnroffst = csnroffst;
- for(ch=0;ch<s->nb_all_channels;ch++)
- s->fsnroffst[ch] = fsnroffst;
-#if defined(DEBUG_BITALLOC)
- {
- int j;
-
- for(i=0;i<6;i++) {
- for(ch=0;ch<s->nb_all_channels;ch++) {
- printf("Block #%d Ch%d:\n", i, ch);
- printf("bap=");
- for(j=0;j<s->nb_coefs[ch];j++) {
- printf("%d ",bap[i][ch][j]);
- }
- printf("\n");
- }
- }
- }
-#endif
- return 0;
-}
-
-void ac3_common_init(void)
-{
- int i, j, k, l, v;
- /* compute bndtab and masktab from bandsz */
- k = 0;
- l = 0;
- for(i=0;i<50;i++) {
- bndtab[i] = l;
- v = bndsz[i];
- for(j=0;j<v;j++) masktab[k++]=i;
- l += v;
- }
- bndtab[50] = 0;
-}
-
-
-static int AC3_encode_init(AVCodecContext *avctx)
-{
- int freq = avctx->sample_rate;
- int bitrate = avctx->bit_rate;
- int channels = avctx->channels;
- AC3EncodeContext *s = avctx->priv_data;
- int i, j, ch;
- float alpha;
- static const uint8_t acmod_defs[6] = {
- 0x01, /* C */
- 0x02, /* L R */
- 0x03, /* L C R */
- 0x06, /* L R SL SR */
- 0x07, /* L C R SL SR */
- 0x07, /* L C R SL SR (+LFE) */
- };
-
- avctx->frame_size = AC3_FRAME_SIZE;
-
- /* number of channels */
- if (channels < 1 || channels > 6)
- return -1;
- s->acmod = acmod_defs[channels - 1];
- s->lfe = (channels == 6) ? 1 : 0;
- s->nb_all_channels = channels;
- s->nb_channels = channels > 5 ? 5 : channels;
- s->lfe_channel = s->lfe ? 5 : -1;
-
- /* frequency */
- for(i=0;i<3;i++) {
- for(j=0;j<3;j++)
- if ((ac3_freqs[j] >> i) == freq)
- goto found;
- }
- return -1;
- found:
- s->sample_rate = freq;
- s->halfratecod = i;
- s->fscod = j;
- s->bsid = 8 + s->halfratecod;
- s->bsmod = 0; /* complete main audio service */
-
- /* bitrate & frame size */
- bitrate /= 1000;
- for(i=0;i<19;i++) {
- if ((ac3_bitratetab[i] >> s->halfratecod) == bitrate)
- break;
- }
- if (i == 19)
- return -1;
- s->bit_rate = bitrate;
- s->frmsizecod = i << 1;
- s->frame_size_min = (bitrate * 1000 * AC3_FRAME_SIZE) / (freq * 16);
- /* for now we do not handle fractional sizes */
- s->frame_size = s->frame_size_min;
-
- /* bit allocation init */
- for(ch=0;ch<s->nb_channels;ch++) {
- /* bandwidth for each channel */
- /* XXX: should compute the bandwidth according to the frame
- size, so that we avoid anoying high freq artefacts */
- s->chbwcod[ch] = 50; /* sample bandwidth as mpeg audio layer 2 table 0 */
- s->nb_coefs[ch] = ((s->chbwcod[ch] + 12) * 3) + 37;
- }
- if (s->lfe) {
- s->nb_coefs[s->lfe_channel] = 7; /* fixed */
- }
- /* initial snr offset */
- s->csnroffst = 40;
-
- ac3_common_init();
-
- /* mdct init */
- fft_init(MDCT_NBITS - 2);
- for(i=0;i<N/4;i++) {
- alpha = 2 * M_PI * (i + 1.0 / 8.0) / (float)N;
- xcos1[i] = fix15(-cos(alpha));
- xsin1[i] = fix15(-sin(alpha));
- }
-
- ac3_crc_init();
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-/* output the AC3 frame header */
-static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
-{
- init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE, NULL, NULL);
-
- put_bits(&s->pb, 16, 0x0b77); /* frame header */
- put_bits(&s->pb, 16, 0); /* crc1: will be filled later */
- put_bits(&s->pb, 2, s->fscod);
- put_bits(&s->pb, 6, s->frmsizecod + (s->frame_size - s->frame_size_min));
- put_bits(&s->pb, 5, s->bsid);
- put_bits(&s->pb, 3, s->bsmod);
- put_bits(&s->pb, 3, s->acmod);
- if ((s->acmod & 0x01) && s->acmod != 0x01)
- put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */
- if (s->acmod & 0x04)
- put_bits(&s->pb, 2, 1); /* XXX -6 dB */
- if (s->acmod == 0x02)
- put_bits(&s->pb, 2, 0); /* surround not indicated */
- put_bits(&s->pb, 1, s->lfe); /* LFE */
- put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */
- put_bits(&s->pb, 1, 0); /* no compression control word */
- put_bits(&s->pb, 1, 0); /* no lang code */
- put_bits(&s->pb, 1, 0); /* no audio production info */
- put_bits(&s->pb, 1, 0); /* no copyright */
- put_bits(&s->pb, 1, 1); /* original bitstream */
- put_bits(&s->pb, 1, 0); /* no time code 1 */
- put_bits(&s->pb, 1, 0); /* no time code 2 */
- put_bits(&s->pb, 1, 0); /* no addtional bit stream info */
-}
-
-/* symetric quantization on 'levels' levels */
-static inline int sym_quant(int c, int e, int levels)
-{
- int v;
-
- if (c >= 0) {
- v = (levels * (c << e)) >> 24;
- v = (v + 1) >> 1;
- v = (levels >> 1) + v;
- } else {
- v = (levels * ((-c) << e)) >> 24;
- v = (v + 1) >> 1;
- v = (levels >> 1) - v;
- }
- assert (v >= 0 && v < levels);
- return v;
-}
-
-/* asymetric quantization on 2^qbits levels */
-static inline int asym_quant(int c, int e, int qbits)
-{
- int lshift, m, v;
-
- lshift = e + qbits - 24;
- if (lshift >= 0)
- v = c << lshift;
- else
- v = c >> (-lshift);
- /* rounding */
- v = (v + 1) >> 1;
- m = (1 << (qbits-1));
- if (v >= m)
- v = m - 1;
- assert(v >= -m);
- return v & ((1 << qbits)-1);
-}
-
-/* Output one audio block. There are NB_BLOCKS audio blocks in one AC3
- frame */
-static void output_audio_block(AC3EncodeContext *s,
- uint8_t exp_strategy[AC3_MAX_CHANNELS],
- uint8_t encoded_exp[AC3_MAX_CHANNELS][N/2],
- uint8_t bap[AC3_MAX_CHANNELS][N/2],
- int32_t mdct_coefs[AC3_MAX_CHANNELS][N/2],
- int8_t global_exp[AC3_MAX_CHANNELS],
- int block_num)
-{
- int ch, nb_groups, group_size, i, baie, rbnd;
- uint8_t *p;
- uint16_t qmant[AC3_MAX_CHANNELS][N/2];
- int exp0, exp1;
- int mant1_cnt, mant2_cnt, mant4_cnt;
- uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr;
- int delta0, delta1, delta2;
-
- for(ch=0;ch<s->nb_channels;ch++)
- put_bits(&s->pb, 1, 0); /* 512 point MDCT */
- for(ch=0;ch<s->nb_channels;ch++)
- put_bits(&s->pb, 1, 1); /* no dither */
- put_bits(&s->pb, 1, 0); /* no dynamic range */
- if (block_num == 0) {
- /* for block 0, even if no coupling, we must say it. This is a
- waste of bit :-) */
- put_bits(&s->pb, 1, 1); /* coupling strategy present */
- put_bits(&s->pb, 1, 0); /* no coupling strategy */
- } else {
- put_bits(&s->pb, 1, 0); /* no new coupling strategy */
- }
-
- if (s->acmod == 2)
- {
- if(block_num==0)
- {
- /* first block must define rematrixing (rematstr) */
- put_bits(&s->pb, 1, 1);
-
- /* dummy rematrixing rematflg(1:4)=0 */
- for (rbnd=0;rbnd<4;rbnd++)
- put_bits(&s->pb, 1, 0);
- }
- else
- {
- /* no matrixing (but should be used in the future) */
- put_bits(&s->pb, 1, 0);
- }
- }
-
-#if defined(DEBUG)
- {
- static int count = 0;
- printf("Block #%d (%d)\n", block_num, count++);
- }
-#endif
- /* exponent strategy */
- for(ch=0;ch<s->nb_channels;ch++) {
- put_bits(&s->pb, 2, exp_strategy[ch]);
- }
-
- if (s->lfe) {
- put_bits(&s->pb, 1, exp_strategy[s->lfe_channel]);
- }
-
- for(ch=0;ch<s->nb_channels;ch++) {
- if (exp_strategy[ch] != EXP_REUSE)
- put_bits(&s->pb, 6, s->chbwcod[ch]);
- }
-
- /* exponents */
- for (ch = 0; ch < s->nb_all_channels; ch++) {
- switch(exp_strategy[ch]) {
- case EXP_REUSE:
- continue;
- case EXP_D15:
- group_size = 1;
- break;
- case EXP_D25:
- group_size = 2;
- break;
- default:
- case EXP_D45:
- group_size = 4;
- break;
- }
- nb_groups = (s->nb_coefs[ch] + (group_size * 3) - 4) / (3 * group_size);
- p = encoded_exp[ch];
-
- /* first exponent */
- exp1 = *p++;
- put_bits(&s->pb, 4, exp1);
-
- /* next ones are delta encoded */
- for(i=0;i<nb_groups;i++) {
- /* merge three delta in one code */
- exp0 = exp1;
- exp1 = p[0];
- p += group_size;
- delta0 = exp1 - exp0 + 2;
-
- exp0 = exp1;
- exp1 = p[0];
- p += group_size;
- delta1 = exp1 - exp0 + 2;
-
- exp0 = exp1;
- exp1 = p[0];
- p += group_size;
- delta2 = exp1 - exp0 + 2;
-
- put_bits(&s->pb, 7, ((delta0 * 5 + delta1) * 5) + delta2);
- }
-
- if (ch != s->lfe_channel)
- put_bits(&s->pb, 2, 0); /* no gain range info */
- }
-
- /* bit allocation info */
- baie = (block_num == 0);
- put_bits(&s->pb, 1, baie);
- if (baie) {
- put_bits(&s->pb, 2, s->sdecaycod);
- put_bits(&s->pb, 2, s->fdecaycod);
- put_bits(&s->pb, 2, s->sgaincod);
- put_bits(&s->pb, 2, s->dbkneecod);
- put_bits(&s->pb, 3, s->floorcod);
- }
-
- /* snr offset */
- put_bits(&s->pb, 1, baie); /* always present with bai */
- if (baie) {
- put_bits(&s->pb, 6, s->csnroffst);
- for(ch=0;ch<s->nb_all_channels;ch++) {
- put_bits(&s->pb, 4, s->fsnroffst[ch]);
- put_bits(&s->pb, 3, s->fgaincod[ch]);
- }
- }
-
- put_bits(&s->pb, 1, 0); /* no delta bit allocation */
- put_bits(&s->pb, 1, 0); /* no data to skip */
-
- /* mantissa encoding : we use two passes to handle the grouping. A
- one pass method may be faster, but it would necessitate to
- modify the output stream. */
-
- /* first pass: quantize */
- mant1_cnt = mant2_cnt = mant4_cnt = 0;
- qmant1_ptr = qmant2_ptr = qmant4_ptr = NULL;
-
- for (ch = 0; ch < s->nb_all_channels; ch++) {
- int b, c, e, v;
-
- for(i=0;i<s->nb_coefs[ch];i++) {
- c = mdct_coefs[ch][i];
- e = encoded_exp[ch][i] - global_exp[ch];
- b = bap[ch][i];
- switch(b) {
- case 0:
- v = 0;
- break;
- case 1:
- v = sym_quant(c, e, 3);
- switch(mant1_cnt) {
- case 0:
- qmant1_ptr = &qmant[ch][i];
- v = 9 * v;
- mant1_cnt = 1;
- break;
- case 1:
- *qmant1_ptr += 3 * v;
- mant1_cnt = 2;
- v = 128;
- break;
- default:
- *qmant1_ptr += v;
- mant1_cnt = 0;
- v = 128;
- break;
- }
- break;
- case 2:
- v = sym_quant(c, e, 5);
- switch(mant2_cnt) {
- case 0:
- qmant2_ptr = &qmant[ch][i];
- v = 25 * v;
- mant2_cnt = 1;
- break;
- case 1:
- *qmant2_ptr += 5 * v;
- mant2_cnt = 2;
- v = 128;
- break;
- default:
- *qmant2_ptr += v;
- mant2_cnt = 0;
- v = 128;
- break;
- }
- break;
- case 3:
- v = sym_quant(c, e, 7);
- break;
- case 4:
- v = sym_quant(c, e, 11);
- switch(mant4_cnt) {
- case 0:
- qmant4_ptr = &qmant[ch][i];
- v = 11 * v;
- mant4_cnt = 1;
- break;
- default:
- *qmant4_ptr += v;
- mant4_cnt = 0;
- v = 128;
- break;
- }
- break;
- case 5:
- v = sym_quant(c, e, 15);
- break;
- case 14:
- v = asym_quant(c, e, 14);
- break;
- case 15:
- v = asym_quant(c, e, 16);
- break;
- default:
- v = asym_quant(c, e, b - 1);
- break;
- }
- qmant[ch][i] = v;
- }
- }
-
- /* second pass : output the values */
- for (ch = 0; ch < s->nb_all_channels; ch++) {
- int b, q;
-
- for(i=0;i<s->nb_coefs[ch];i++) {
- q = qmant[ch][i];
- b = bap[ch][i];
- switch(b) {
- case 0:
- break;
- case 1:
- if (q != 128)
- put_bits(&s->pb, 5, q);
- break;
- case 2:
- if (q != 128)
- put_bits(&s->pb, 7, q);
- break;
- case 3:
- put_bits(&s->pb, 3, q);
- break;
- case 4:
- if (q != 128)
- put_bits(&s->pb, 7, q);
- break;
- case 14:
- put_bits(&s->pb, 14, q);
- break;
- case 15:
- put_bits(&s->pb, 16, q);
- break;
- default:
- put_bits(&s->pb, b - 1, q);
- break;
- }
- }
- }
-}
-
-/* compute the ac3 crc */
-
-#define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
-
-static void ac3_crc_init(void)
-{
- unsigned int c, n, k;
-
- for(n=0;n<256;n++) {
- c = n << 8;
- for (k = 0; k < 8; k++) {
- if (c & (1 << 15))
- c = ((c << 1) & 0xffff) ^ (CRC16_POLY & 0xffff);
- else
- c = c << 1;
- }
- crc_table[n] = c;
- }
-}
-
-static unsigned int ac3_crc(uint8_t *data, int n, unsigned int crc)
-{
- int i;
- for(i=0;i<n;i++) {
- crc = (crc_table[data[i] ^ (crc >> 8)] ^ (crc << 8)) & 0xffff;
- }
- return crc;
-}
-
-static unsigned int mul_poly(unsigned int a, unsigned int b, unsigned int poly)
-{
- unsigned int c;
-
- c = 0;
- while (a) {
- if (a & 1)
- c ^= b;
- a = a >> 1;
- b = b << 1;
- if (b & (1 << 16))
- b ^= poly;
- }
- return c;
-}
-
-static unsigned int pow_poly(unsigned int a, unsigned int n, unsigned int poly)
-{
- unsigned int r;
- r = 1;
- while (n) {
- if (n & 1)
- r = mul_poly(r, a, poly);
- a = mul_poly(a, a, poly);
- n >>= 1;
- }
- return r;
-}
-
-
-/* compute log2(max(abs(tab[]))) */
-static int log2_tab(int16_t *tab, int n)
-{
- int i, v;
-
- v = 0;
- for(i=0;i<n;i++) {
- v |= abs(tab[i]);
- }
- return av_log2(v);
-}
-
-static void lshift_tab(int16_t *tab, int n, int lshift)
-{
- int i;
-
- if (lshift > 0) {
- for(i=0;i<n;i++) {
- tab[i] <<= lshift;
- }
- } else if (lshift < 0) {
- lshift = -lshift;
- for(i=0;i<n;i++) {
- tab[i] >>= lshift;
- }
- }
-}
-
-/* fill the end of the frame and compute the two crcs */
-static int output_frame_end(AC3EncodeContext *s)
-{
- int frame_size, frame_size_58, n, crc1, crc2, crc_inv;
- uint8_t *frame;
-
- frame_size = s->frame_size; /* frame size in words */
- /* align to 8 bits */
- flush_put_bits(&s->pb);
- /* add zero bytes to reach the frame size */
- frame = s->pb.buf;
- n = 2 * s->frame_size - (pbBufPtr(&s->pb) - frame) - 2;
- assert(n >= 0);
- if(n>0)
- memset(pbBufPtr(&s->pb), 0, n);
-
- /* Now we must compute both crcs : this is not so easy for crc1
- because it is at the beginning of the data... */
- frame_size_58 = (frame_size >> 1) + (frame_size >> 3);
- crc1 = ac3_crc(frame + 4, (2 * frame_size_58) - 4, 0);
- /* XXX: could precompute crc_inv */
- crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY);
- crc1 = mul_poly(crc_inv, crc1, CRC16_POLY);
- frame[2] = crc1 >> 8;
- frame[3] = crc1;
-
- crc2 = ac3_crc(frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2, 0);
- frame[2*frame_size - 2] = crc2 >> 8;
- frame[2*frame_size - 1] = crc2;
-
- // printf("n=%d frame_size=%d\n", n, frame_size);
- return frame_size * 2;
-}
-
-static int AC3_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- AC3EncodeContext *s = avctx->priv_data;
- short *samples = data;
- int i, j, k, v, ch;
- int16_t input_samples[N];
- int32_t mdct_coef[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
- uint8_t exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
- uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS];
- uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
- uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
- int8_t exp_samples[NB_BLOCKS][AC3_MAX_CHANNELS];
- int frame_bits;
-
- frame_bits = 0;
- for(ch=0;ch<s->nb_all_channels;ch++) {
- /* fixed mdct to the six sub blocks & exponent computation */
- for(i=0;i<NB_BLOCKS;i++) {
- int16_t *sptr;
- int sinc;
-
- /* compute input samples */
- memcpy(input_samples, s->last_samples[ch], N/2 * sizeof(int16_t));
- sinc = s->nb_all_channels;
- sptr = samples + (sinc * (N/2) * i) + ch;
- for(j=0;j<N/2;j++) {
- v = *sptr;
- input_samples[j + N/2] = v;
- s->last_samples[ch][j] = v;
- sptr += sinc;
- }
-
- /* apply the MDCT window */
- for(j=0;j<N/2;j++) {
- input_samples[j] = MUL16(input_samples[j],
- ac3_window[j]) >> 15;
- input_samples[N-j-1] = MUL16(input_samples[N-j-1],
- ac3_window[j]) >> 15;
- }
-
- /* Normalize the samples to use the maximum available
- precision */
- v = 14 - log2_tab(input_samples, N);
- if (v < 0)
- v = 0;
- exp_samples[i][ch] = v - 8;
- lshift_tab(input_samples, N, v);
-
- /* do the MDCT */
- mdct512(mdct_coef[i][ch], input_samples);
-
- /* compute "exponents". We take into account the
- normalization there */
- for(j=0;j<N/2;j++) {
- int e;
- v = abs(mdct_coef[i][ch][j]);
- if (v == 0)
- e = 24;
- else {
- e = 23 - av_log2(v) + exp_samples[i][ch];
- if (e >= 24) {
- e = 24;
- mdct_coef[i][ch][j] = 0;
- }
- }
- exp[i][ch][j] = e;
- }
- }
-
- compute_exp_strategy(exp_strategy, exp, ch, ch == s->lfe_channel);
-
- /* compute the exponents as the decoder will see them. The
- EXP_REUSE case must be handled carefully : we select the
- min of the exponents */
- i = 0;
- while (i < NB_BLOCKS) {
- j = i + 1;
- while (j < NB_BLOCKS && exp_strategy[j][ch] == EXP_REUSE) {
- exponent_min(exp[i][ch], exp[j][ch], s->nb_coefs[ch]);
- j++;
- }
- frame_bits += encode_exp(encoded_exp[i][ch],
- exp[i][ch], s->nb_coefs[ch],
- exp_strategy[i][ch]);
- /* copy encoded exponents for reuse case */
- for(k=i+1;k<j;k++) {
- memcpy(encoded_exp[k][ch], encoded_exp[i][ch],
- s->nb_coefs[ch] * sizeof(uint8_t));
- }
- i = j;
- }
- }
-
- compute_bit_allocation(s, bap, encoded_exp, exp_strategy, frame_bits);
- /* everything is known... let's output the frame */
- output_frame_header(s, frame);
-
- for(i=0;i<NB_BLOCKS;i++) {
- output_audio_block(s, exp_strategy[i], encoded_exp[i],
- bap[i], mdct_coef[i], exp_samples[i], i);
- }
- return output_frame_end(s);
-}
-
-static int AC3_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
-#if 0
-/*************************************************************************/
-/* TEST */
-
-#define FN (N/4)
-
-void fft_test(void)
-{
- IComplex in[FN], in1[FN];
- int k, n, i;
- float sum_re, sum_im, a;
-
- /* FFT test */
-
- for(i=0;i<FN;i++) {
- in[i].re = random() % 65535 - 32767;
- in[i].im = random() % 65535 - 32767;
- in1[i] = in[i];
- }
- fft(in, 7);
-
- /* do it by hand */
- for(k=0;k<FN;k++) {
- sum_re = 0;
- sum_im = 0;
- for(n=0;n<FN;n++) {
- a = -2 * M_PI * (n * k) / FN;
- sum_re += in1[n].re * cos(a) - in1[n].im * sin(a);
- sum_im += in1[n].re * sin(a) + in1[n].im * cos(a);
- }
- printf("%3d: %6d,%6d %6.0f,%6.0f\n",
- k, in[k].re, in[k].im, sum_re / FN, sum_im / FN);
- }
-}
-
-void mdct_test(void)
-{
- int16_t input[N];
- int32_t output[N/2];
- float input1[N];
- float output1[N/2];
- float s, a, err, e, emax;
- int i, k, n;
-
- for(i=0;i<N;i++) {
- input[i] = (random() % 65535 - 32767) * 9 / 10;
- input1[i] = input[i];
- }
-
- mdct512(output, input);
-
- /* do it by hand */
- for(k=0;k<N/2;k++) {
- s = 0;
- for(n=0;n<N;n++) {
- a = (2*M_PI*(2*n+1+N/2)*(2*k+1) / (4 * N));
- s += input1[n] * cos(a);
- }
- output1[k] = -2 * s / N;
- }
-
- err = 0;
- emax = 0;
- for(i=0;i<N/2;i++) {
- printf("%3d: %7d %7.0f\n", i, output[i], output1[i]);
- e = output[i] - output1[i];
- if (e > emax)
- emax = e;
- err += e * e;
- }
- printf("err2=%f emax=%f\n", err / (N/2), emax);
-}
-
-void test_ac3(void)
-{
- AC3EncodeContext ctx;
- unsigned char frame[AC3_MAX_CODED_FRAME_SIZE];
- short samples[AC3_FRAME_SIZE];
- int ret, i;
-
- AC3_encode_init(&ctx, 44100, 64000, 1);
-
- fft_test();
- mdct_test();
-
- for(i=0;i<AC3_FRAME_SIZE;i++)
- samples[i] = (int)(sin(2*M_PI*i*1000.0/44100) * 10000);
- ret = AC3_encode_frame(&ctx, frame, samples);
- printf("ret=%d\n", ret);
-}
-#endif
-
-AVCodec ac3_encoder = {
- "ac3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_AC3,
- sizeof(AC3EncodeContext),
- AC3_encode_init,
- AC3_encode_frame,
- AC3_encode_close,
- NULL,
-};
+++ /dev/null
-/**
- * @file ac3tab.h
- * tables taken directly from AC3 spec.
- */
-
-/* possible frequencies */
-const uint16_t ac3_freqs[3] = { 48000, 44100, 32000 };
-
-/* possible bitrates */
-const uint16_t ac3_bitratetab[19] = {
- 32, 40, 48, 56, 64, 80, 96, 112, 128,
- 160, 192, 224, 256, 320, 384, 448, 512, 576, 640
-};
-
-/* AC3 MDCT window */
-
-/* MDCT window */
-const int16_t ac3_window[256] = {
- 4, 7, 12, 16, 21, 28, 34, 42,
- 51, 61, 72, 84, 97, 111, 127, 145,
- 164, 184, 207, 231, 257, 285, 315, 347,
- 382, 419, 458, 500, 544, 591, 641, 694,
- 750, 810, 872, 937, 1007, 1079, 1155, 1235,
- 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016,
- 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076,
- 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444,
- 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127,
- 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112,
- 8380, 8652, 8927, 9207, 9491, 9778,10069,10363,
-10660,10960,11264,11570,11879,12190,12504,12820,
-13138,13458,13780,14103,14427,14753,15079,15407,
-15735,16063,16392,16720,17049,17377,17705,18032,
-18358,18683,19007,19330,19651,19970,20287,20602,
-20914,21225,21532,21837,22139,22438,22733,23025,
-23314,23599,23880,24157,24430,24699,24964,25225,
-25481,25732,25979,26221,26459,26691,26919,27142,
-27359,27572,27780,27983,28180,28373,28560,28742,
-28919,29091,29258,29420,29577,29729,29876,30018,
-30155,30288,30415,30538,30657,30771,30880,30985,
-31086,31182,31274,31363,31447,31528,31605,31678,
-31747,31814,31877,31936,31993,32046,32097,32145,
-32190,32232,32272,32310,32345,32378,32409,32438,
-32465,32490,32513,32535,32556,32574,32592,32608,
-32623,32636,32649,32661,32671,32681,32690,32698,
-32705,32712,32718,32724,32729,32733,32737,32741,
-32744,32747,32750,32752,32754,32756,32757,32759,
-32760,32761,32762,32763,32764,32764,32765,32765,
-32766,32766,32766,32766,32767,32767,32767,32767,
-32767,32767,32767,32767,32767,32767,32767,32767,
-32767,32767,32767,32767,32767,32767,32767,32767,
-};
-
-static uint8_t masktab[253];
-
-static const uint8_t latab[260]= {
-0x0040,0x003f,0x003e,0x003d,0x003c,0x003b,0x003a,0x0039,0x0038,0x0037,
-0x0036,0x0035,0x0034,0x0034,0x0033,0x0032,0x0031,0x0030,0x002f,0x002f,
-0x002e,0x002d,0x002c,0x002c,0x002b,0x002a,0x0029,0x0029,0x0028,0x0027,
-0x0026,0x0026,0x0025,0x0024,0x0024,0x0023,0x0023,0x0022,0x0021,0x0021,
-0x0020,0x0020,0x001f,0x001e,0x001e,0x001d,0x001d,0x001c,0x001c,0x001b,
-0x001b,0x001a,0x001a,0x0019,0x0019,0x0018,0x0018,0x0017,0x0017,0x0016,
-0x0016,0x0015,0x0015,0x0015,0x0014,0x0014,0x0013,0x0013,0x0013,0x0012,
-0x0012,0x0012,0x0011,0x0011,0x0011,0x0010,0x0010,0x0010,0x000f,0x000f,
-0x000f,0x000e,0x000e,0x000e,0x000d,0x000d,0x000d,0x000d,0x000c,0x000c,
-0x000c,0x000c,0x000b,0x000b,0x000b,0x000b,0x000a,0x000a,0x000a,0x000a,
-0x000a,0x0009,0x0009,0x0009,0x0009,0x0009,0x0008,0x0008,0x0008,0x0008,
-0x0008,0x0008,0x0007,0x0007,0x0007,0x0007,0x0007,0x0007,0x0006,0x0006,
-0x0006,0x0006,0x0006,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0005,
-0x0005,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004,
-0x0004,0x0004,0x0004,0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003,
-0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002,
-0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,
-0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001,
-0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
-0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
-0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,
-0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
-0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
-0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
-0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
-0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
-};
-
-static const uint16_t hth[50][3]= {
-{ 0x04d0,0x04f0,0x0580 },
-{ 0x04d0,0x04f0,0x0580 },
-{ 0x0440,0x0460,0x04b0 },
-{ 0x0400,0x0410,0x0450 },
-{ 0x03e0,0x03e0,0x0420 },
-{ 0x03c0,0x03d0,0x03f0 },
-{ 0x03b0,0x03c0,0x03e0 },
-{ 0x03b0,0x03b0,0x03d0 },
-{ 0x03a0,0x03b0,0x03c0 },
-{ 0x03a0,0x03a0,0x03b0 },
-{ 0x03a0,0x03a0,0x03b0 },
-{ 0x03a0,0x03a0,0x03b0 },
-{ 0x03a0,0x03a0,0x03a0 },
-{ 0x0390,0x03a0,0x03a0 },
-{ 0x0390,0x0390,0x03a0 },
-{ 0x0390,0x0390,0x03a0 },
-{ 0x0380,0x0390,0x03a0 },
-{ 0x0380,0x0380,0x03a0 },
-{ 0x0370,0x0380,0x03a0 },
-{ 0x0370,0x0380,0x03a0 },
-{ 0x0360,0x0370,0x0390 },
-{ 0x0360,0x0370,0x0390 },
-{ 0x0350,0x0360,0x0390 },
-{ 0x0350,0x0360,0x0390 },
-{ 0x0340,0x0350,0x0380 },
-{ 0x0340,0x0350,0x0380 },
-{ 0x0330,0x0340,0x0380 },
-{ 0x0320,0x0340,0x0370 },
-{ 0x0310,0x0320,0x0360 },
-{ 0x0300,0x0310,0x0350 },
-{ 0x02f0,0x0300,0x0340 },
-{ 0x02f0,0x02f0,0x0330 },
-{ 0x02f0,0x02f0,0x0320 },
-{ 0x02f0,0x02f0,0x0310 },
-{ 0x0300,0x02f0,0x0300 },
-{ 0x0310,0x0300,0x02f0 },
-{ 0x0340,0x0320,0x02f0 },
-{ 0x0390,0x0350,0x02f0 },
-{ 0x03e0,0x0390,0x0300 },
-{ 0x0420,0x03e0,0x0310 },
-{ 0x0460,0x0420,0x0330 },
-{ 0x0490,0x0450,0x0350 },
-{ 0x04a0,0x04a0,0x03c0 },
-{ 0x0460,0x0490,0x0410 },
-{ 0x0440,0x0460,0x0470 },
-{ 0x0440,0x0440,0x04a0 },
-{ 0x0520,0x0480,0x0460 },
-{ 0x0800,0x0630,0x0440 },
-{ 0x0840,0x0840,0x0450 },
-{ 0x0840,0x0840,0x04e0 },
-};
-
-static const uint8_t baptab[64]= {
- 0, 1, 1, 1, 1, 1, 2, 2, 3, 3,
- 3, 4, 4, 5, 5, 6, 6, 6, 6, 7,
- 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
- 9, 10, 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 12, 12, 13, 13, 13, 13, 14, 14, 14,
- 14, 14, 14, 14, 14, 15, 15, 15, 15, 15,
- 15, 15, 15, 15,
-};
-
-const uint8_t sdecaytab[4]={
- 0x0f, 0x11, 0x13, 0x15,
-};
-
-const uint8_t fdecaytab[4]={
- 0x3f, 0x53, 0x67, 0x7b,
-};
-
-const uint16_t sgaintab[4]= {
- 0x540, 0x4d8, 0x478, 0x410,
-};
-
-const uint16_t dbkneetab[4]= {
- 0x000, 0x700, 0x900, 0xb00,
-};
-
-const uint16_t floortab[8]= {
- 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800,
-};
-
-const uint16_t fgaintab[8]= {
- 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400,
-};
-
-static const uint8_t bndsz[50]={
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3,
- 3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24
-};
-
-static uint8_t bndtab[51];
-
-/* fft & mdct sin cos tables */
-static int16_t costab[64];
-static int16_t sintab[64];
-static int16_t fft_rev[512];
-static int16_t xcos1[128];
-static int16_t xsin1[128];
-
-static uint16_t crc_table[256];
+++ /dev/null
-/*
- * ADPCM codecs
- * Copyright (c) 2001-2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avcodec.h"
-
-/**
- * @file adpcm.c
- * ADPCM codecs.
- * First version by Francois Revol revol@free.fr
- * Fringe ADPCM codecs (e.g., DK3 and DK4)
- * by Mike Melanson (melanson@pcisys.net)
- *
- * Features and limitations:
- *
- * Reference documents:
- * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
- * http://www.geocities.com/SiliconValley/8682/aud3.txt
- * http://openquicktime.sourceforge.net/plugins.htm
- * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html
- * http://www.cs.ucla.edu/~leec/mediabench/applications.html
- * SoX source code http://home.sprynet.com/~cbagwell/sox.html
- */
-
-#define BLKSIZE 1024
-
-#define CLAMP_TO_SHORT(value) \
-if (value > 32767) \
- value = 32767; \
-else if (value < -32768) \
- value = -32768; \
-
-/* step_table[] and index_table[] are from the ADPCM reference source */
-/* This is the index table: */
-static const int index_table[16] = {
- -1, -1, -1, -1, 2, 4, 6, 8,
- -1, -1, -1, -1, 2, 4, 6, 8,
-};
-
-/**
- * This is the step table. Note that many programs use slight deviations from
- * this table, but such deviations are negligible:
- */
-static const int step_table[89] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
-};
-
-/* Those are for MS-ADPCM */
-/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */
-static const int AdaptationTable[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 768, 614, 512, 409, 307, 230, 230, 230
-};
-
-static const int AdaptCoeff1[] = {
- 256, 512, 0, 192, 240, 460, 392
-};
-
-static const int AdaptCoeff2[] = {
- 0, -256, 0, 64, 0, -208, -232
-};
-
-/* end of tables */
-
-typedef struct ADPCMChannelStatus {
- int predictor;
- short int step_index;
- int step;
- /* for encoding */
- int prev_sample;
-
- /* MS version */
- short sample1;
- short sample2;
- int coeff1;
- int coeff2;
- int idelta;
-} ADPCMChannelStatus;
-
-typedef struct ADPCMContext {
- int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */
- ADPCMChannelStatus status[2];
- short sample_buffer[32]; /* hold left samples while waiting for right samples */
-} ADPCMContext;
-
-/* XXX: implement encoding */
-
-static int adpcm_encode_init(AVCodecContext *avctx)
-{
- if (avctx->channels > 2)
- return -1; /* only stereo or mono =) */
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT:
- fprintf(stderr, "ADPCM: codec admcp_ima_qt unsupported for encoding !\n");
- avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */
- return -1;
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */
- /* and we have 4 bytes per channel overhead */
- avctx->block_align = BLKSIZE;
- /* seems frame_size isn't taken into account... have to buffer the samples :-( */
- break;
- case CODEC_ID_ADPCM_MS:
- fprintf(stderr, "ADPCM: codec admcp_ms unsupported for encoding !\n");
- return -1;
- break;
- default:
- return -1;
- break;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-static int adpcm_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
-
- return 0;
-}
-
-
-static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample)
-{
- int step_index;
- unsigned char nibble;
-
- int sign = 0; /* sign bit of the nibble (MSB) */
- int delta, predicted_delta;
-
- delta = sample - c->prev_sample;
-
- if (delta < 0) {
- sign = 1;
- delta = -delta;
- }
-
- step_index = c->step_index;
-
- /* nibble = 4 * delta / step_table[step_index]; */
- nibble = (delta << 2) / step_table[step_index];
-
- if (nibble > 7)
- nibble = 7;
-
- step_index += index_table[nibble];
- if (step_index < 0)
- step_index = 0;
- if (step_index > 88)
- step_index = 88;
-
- /* what the decoder will find */
- predicted_delta = ((step_table[step_index] * nibble) / 4) + (step_table[step_index] / 8);
-
- if (sign)
- c->prev_sample -= predicted_delta;
- else
- c->prev_sample += predicted_delta;
-
- CLAMP_TO_SHORT(c->prev_sample);
-
-
- nibble += sign << 3; /* sign * 8 */
-
- /* save back */
- c->step_index = step_index;
-
- return nibble;
-}
-
-static int adpcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- int n;
- short *samples;
- unsigned char *dst;
- ADPCMContext *c = avctx->priv_data;
-
- dst = frame;
- samples = (short *)data;
-/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- n = avctx->frame_size / 8;
- c->status[0].prev_sample = (signed short)samples[0]; /* XXX */
-/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */
- *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */
- *dst++ = (c->status[0].prev_sample >> 8) & 0xFF;
- *dst++ = (unsigned char)c->status[0].step_index;
- *dst++ = 0; /* unknown */
- samples++;
- if (avctx->channels == 2) {
- c->status[1].prev_sample = (signed short)samples[0];
-/* c->status[1].step_index = 0; */
- *dst++ = (c->status[1].prev_sample) & 0xFF;
- *dst++ = (c->status[1].prev_sample >> 8) & 0xFF;
- *dst++ = (unsigned char)c->status[1].step_index;
- *dst++ = 0;
- samples++;
- }
-
- /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */
- for (; n>0; n--) {
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F;
- *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0;
- dst++;
- /* right channel */
- if (avctx->channels == 2) {
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4;
- dst++;
- *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]);
- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4;
- dst++;
- }
- samples += 8 * avctx->channels;
- }
- break;
- default:
- return -1;
- }
- return dst - frame;
-}
-
-static int adpcm_decode_init(AVCodecContext * avctx)
-{
- ADPCMContext *c = avctx->priv_data;
-
- c->channel = 0;
- c->status[0].predictor = c->status[1].predictor = 0;
- c->status[0].step_index = c->status[1].step_index = 0;
- c->status[0].step = c->status[1].step = 0;
-
- switch(avctx->codec->id) {
- default:
- break;
- }
- return 0;
-}
-
-static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble)
-{
- int step_index;
- int predictor;
- int sign, delta, diff, step;
-
- step = step_table[c->step_index];
- step_index = c->step_index + index_table[(unsigned)nibble];
- if (step_index < 0) step_index = 0;
- else if (step_index > 88) step_index = 88;
-
- sign = nibble & 8;
- delta = nibble & 7;
- /* perform direct multiplication instead of series of jumps proposed by
- * the reference ADPCM implementation since modern CPUs can do the mults
- * quickly enough */
- diff = ((2 * delta + 1) * step) >> 3;
- predictor = c->predictor;
- if (sign) predictor -= diff;
- else predictor += diff;
-
- CLAMP_TO_SHORT(predictor);
- c->predictor = predictor;
- c->step_index = step_index;
-
- return (short)predictor;
-}
-
-static inline short adpcm_4xa_expand_nibble(ADPCMChannelStatus *c, char nibble)
-{
- int step_index;
- int predictor;
- int sign, delta, diff, step;
-
- step = step_table[c->step_index];
- step_index = c->step_index + index_table[(unsigned)nibble];
- if (step_index < 0) step_index = 0;
- else if (step_index > 88) step_index = 88;
-
- sign = nibble & 8;
- delta = nibble & 7;
-
- diff = (delta*step + (step>>1))>>3; // difference to code above
-
- predictor = c->predictor;
- if (sign) predictor -= diff;
- else predictor += diff;
-
- CLAMP_TO_SHORT(predictor);
- c->predictor = predictor;
- c->step_index = step_index;
-
- return (short)predictor;
-}
-
-static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble)
-{
- int predictor;
-
- predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256;
- predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
- CLAMP_TO_SHORT(predictor);
-
- c->sample2 = c->sample1;
- c->sample1 = predictor;
- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) / 256;
- if (c->idelta < 16) c->idelta = 16;
-
- return (short)predictor;
-}
-
-/* DK3 ADPCM support macro */
-#define DK3_GET_NEXT_NIBBLE() \
- if (decode_top_nibble_next) \
- { \
- nibble = (last_byte >> 4) & 0x0F; \
- decode_top_nibble_next = 0; \
- } \
- else \
- { \
- last_byte = *src++; \
- if (src >= buf + buf_size) break; \
- nibble = last_byte & 0x0F; \
- decode_top_nibble_next = 1; \
- }
-
-static int adpcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- ADPCMContext *c = avctx->priv_data;
- ADPCMChannelStatus *cs;
- int n, m, channel, i;
- int block_predictor[2];
- short *samples;
- uint8_t *src;
- int st; /* stereo */
-
- /* DK3 ADPCM accounting variables */
- unsigned char last_byte = 0;
- unsigned char nibble;
- int decode_top_nibble_next = 0;
- int diff_channel;
-
- samples = data;
- src = buf;
-
- st = avctx->channels == 2;
-
- switch(avctx->codec->id) {
- case CODEC_ID_ADPCM_IMA_QT:
- n = (buf_size - 2);/* >> 2*avctx->channels;*/
- channel = c->channel;
- cs = &(c->status[channel]);
- /* (pppppp) (piiiiiii) */
-
- /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
- cs->predictor = (*src++) << 8;
- cs->predictor |= (*src & 0x80);
- cs->predictor &= 0xFF80;
-
- /* sign extension */
- if(cs->predictor & 0x8000)
- cs->predictor -= 0x10000;
-
- CLAMP_TO_SHORT(cs->predictor);
-
- cs->step_index = (*src++) & 0x7F;
-
- if (cs->step_index > 88) fprintf(stderr, "ERROR: step_index = %i\n", cs->step_index);
- if (cs->step_index > 88) cs->step_index = 88;
-
- cs->step = step_table[cs->step_index];
-
- if (st && channel)
- samples++;
-
- *samples++ = cs->predictor;
- samples += st;
-
- for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */
- *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F);
- samples += avctx->channels;
- *samples = adpcm_ima_expand_nibble(cs, (src[0] >> 4) & 0x0F);
- samples += avctx->channels;
- src ++;
- }
-
- if(st) { /* handle stereo interlacing */
- c->channel = (channel + 1) % 2; /* we get one packet for left, then one for right data */
- if(channel == 0) { /* wait for the other packet before outputing anything */
- *data_size = 0;
- return src - buf;
- }
- }
- break;
- case CODEC_ID_ADPCM_IMA_WAV:
- if (buf_size > BLKSIZE) {
- if (avctx->block_align != 0)
- buf_size = avctx->block_align;
- else
- buf_size = BLKSIZE;
- }
- // XXX: do as per-channel loop
- cs = &(c->status[0]);
- cs->predictor = (*src++) & 0x0FF;
- cs->predictor |= ((*src++) << 8) & 0x0FF00;
- if(cs->predictor & 0x8000)
- cs->predictor -= 0x10000;
- CLAMP_TO_SHORT(cs->predictor);
-
- // XXX: is this correct ??: *samples++ = cs->predictor;
-
- cs->step_index = *src++;
- if (cs->step_index < 0) cs->step_index = 0;
- if (cs->step_index > 88) cs->step_index = 88;
- if (*src++) fprintf(stderr, "unused byte should be null !!\n"); /* unused */
-
- if (st) {
- cs = &(c->status[1]);
- cs->predictor = (*src++) & 0x0FF;
- cs->predictor |= ((*src++) << 8) & 0x0FF00;
- if(cs->predictor & 0x8000)
- cs->predictor -= 0x10000;
- CLAMP_TO_SHORT(cs->predictor);
-
- // XXX: is this correct ??: *samples++ = cs->predictor;
-
- cs->step_index = *src++;
- if (cs->step_index < 0) cs->step_index = 0;
- if (cs->step_index > 88) cs->step_index = 88;
- src++; /* if != 0 -> out-of-sync */
- }
-
- for(m=4; src < (buf + buf_size);) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] & 0x0F);
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[4] & 0x0F);
- *samples++ = adpcm_ima_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
- if (st) {
- *samples++ = adpcm_ima_expand_nibble(&c->status[1], (src[4] >> 4) & 0x0F);
- if (!--m) {
- m=4;
- src+=4;
- }
- }
- src++;
- }
- break;
- case CODEC_ID_ADPCM_4XM:
- cs = &(c->status[0]);
- c->status[0].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- if(st){
- c->status[1].predictor= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- }
- c->status[0].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- if(st){
- c->status[1].step_index= (int16_t)(src[0] + (src[1]<<8)); src+=2;
- }
-// if (cs->step_index < 0) cs->step_index = 0;
-// if (cs->step_index > 88) cs->step_index = 88;
-
- m= (buf_size - (src - buf))>>st;
-//printf("%d %d %d %d\n", st, m, c->status[0].predictor, c->status[0].step_index);
- //FIXME / XXX decode chanels individual & interleave samples
- for(i=0; i<m; i++) {
- *samples++ = adpcm_4xa_expand_nibble(&c->status[0], src[i] & 0x0F);
- if (st)
- *samples++ = adpcm_4xa_expand_nibble(&c->status[1], src[i+m] & 0x0F);
- *samples++ = adpcm_4xa_expand_nibble(&c->status[0], src[i] >> 4);
- if (st)
- *samples++ = adpcm_4xa_expand_nibble(&c->status[1], src[i+m] >> 4);
- }
-
- src += m<<st;
-
- break;
- case CODEC_ID_ADPCM_MS:
-
- if (buf_size > BLKSIZE) {
- if (avctx->block_align != 0)
- buf_size = avctx->block_align;
- else
- buf_size = BLKSIZE;
- }
- n = buf_size - 7 * avctx->channels;
- if (n < 0)
- return -1;
- block_predictor[0] = (*src++); /* should be bound */
- block_predictor[0] = (block_predictor[0] < 0)?(0):((block_predictor[0] > 7)?(7):(block_predictor[0]));
- block_predictor[1] = 0;
- if (st)
- block_predictor[1] = (*src++);
- block_predictor[1] = (block_predictor[1] < 0)?(0):((block_predictor[1] > 7)?(7):(block_predictor[1]));
- c->status[0].idelta = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (c->status[0].idelta & 0x08000)
- c->status[0].idelta -= 0x10000;
- src+=2;
- if (st)
- c->status[1].idelta = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (st && c->status[1].idelta & 0x08000)
- c->status[1].idelta |= 0xFFFF0000;
- if (st)
- src+=2;
- c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]];
- c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]];
- c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]];
- c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]];
-
- c->status[0].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- if (st) c->status[1].sample1 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (st) src+=2;
- c->status[0].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- src+=2;
- if (st) c->status[1].sample2 = ((*src & 0xFF) | ((src[1] << 8) & 0xFF00));
- if (st) src+=2;
-
- *samples++ = c->status[0].sample1;
- if (st) *samples++ = c->status[1].sample1;
- *samples++ = c->status[0].sample2;
- if (st) *samples++ = c->status[1].sample2;
- for(;n>0;n--) {
- *samples++ = adpcm_ms_expand_nibble(&c->status[0], (src[0] >> 4) & 0x0F);
- *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
- src ++;
- }
- break;
- case CODEC_ID_ADPCM_IMA_DK4:
- if (buf_size > BLKSIZE) {
- if (avctx->block_align != 0)
- buf_size = avctx->block_align;
- else
- buf_size = BLKSIZE;
- }
- c->status[0].predictor = (src[0] | (src[1] << 8));
- c->status[0].step_index = src[2];
- src += 4;
- if(c->status[0].predictor & 0x8000)
- c->status[0].predictor -= 0x10000;
- *samples++ = c->status[0].predictor;
- if (st) {
- c->status[1].predictor = (src[0] | (src[1] << 8));
- c->status[1].step_index = src[2];
- src += 4;
- if(c->status[1].predictor & 0x8000)
- c->status[1].predictor -= 0x10000;
- *samples++ = c->status[1].predictor;
- }
- while (src < buf + buf_size) {
-
- /* take care of the top nibble (always left or mono channel) */
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- (src[0] >> 4) & 0x0F);
-
- /* take care of the bottom nibble, which is right sample for
- * stereo, or another mono sample */
- if (st)
- *samples++ = adpcm_ima_expand_nibble(&c->status[1],
- src[0] & 0x0F);
- else
- *samples++ = adpcm_ima_expand_nibble(&c->status[0],
- src[0] & 0x0F);
-
- src++;
- }
- break;
- case CODEC_ID_ADPCM_IMA_DK3:
- if (buf_size > BLKSIZE) {
- if (avctx->block_align != 0)
- buf_size = avctx->block_align;
- else
- buf_size = BLKSIZE;
- }
- c->status[0].predictor = (src[10] | (src[11] << 8));
- c->status[1].predictor = (src[12] | (src[13] << 8));
- c->status[0].step_index = src[14];
- c->status[1].step_index = src[15];
- /* sign extend the predictors */
- if(c->status[0].predictor & 0x8000)
- c->status[0].predictor -= 0x10000;
- if(c->status[1].predictor & 0x8000)
- c->status[1].predictor -= 0x10000;
- src += 16;
- diff_channel = c->status[1].predictor;
-
- /* the DK3_GET_NEXT_NIBBLE macro issues the break statement when
- * the buffer is consumed */
- while (1) {
-
- /* for this algorithm, c->status[0] is the sum channel and
- * c->status[1] is the diff channel */
-
- /* process the first predictor of the sum channel */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[0], nibble);
-
- /* process the diff channel predictor */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[1], nibble);
-
- /* process the first pair of stereo PCM samples */
- diff_channel = (diff_channel + c->status[1].predictor) / 2;
- *samples++ = c->status[0].predictor + c->status[1].predictor;
- *samples++ = c->status[0].predictor - c->status[1].predictor;
-
- /* process the second predictor of the sum channel */
- DK3_GET_NEXT_NIBBLE();
- adpcm_ima_expand_nibble(&c->status[0], nibble);
-
- /* process the second pair of stereo PCM samples */
- diff_channel = (diff_channel + c->status[1].predictor) / 2;
- *samples++ = c->status[0].predictor + c->status[1].predictor;
- *samples++ = c->status[0].predictor - c->status[1].predictor;
- }
- break;
- default:
- *data_size = 0;
- return -1;
- }
- *data_size = (uint8_t *)samples - (uint8_t *)data;
- return src - buf;
-}
-
-#define ADPCM_CODEC(id, name) \
-AVCodec name ## _encoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_encode_init, \
- adpcm_encode_frame, \
- adpcm_encode_close, \
- NULL, \
-}; \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(ADPCMContext), \
- adpcm_decode_init, \
- NULL, \
- NULL, \
- adpcm_decode_frame, \
-};
-
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
-ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
-ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
-ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
-
-#undef ADPCM_CODEC
+++ /dev/null
-/*
- * Utils for libavcodec
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file allcodecs.c
- * Utils for libavcodec.
- */
-
-#include "avcodec.h"
-
-/* If you do not call this function, then you can select exactly which
- formats you want to support */
-
-/**
- * simple call to register all the codecs.
- */
-void avcodec_register_all(void)
-{
- static int inited = 0;
-
- if (inited != 0)
- return;
- inited = 1;
-
- /* encoders */
-#ifdef CONFIG_ENCODERS
- register_avcodec(&ac3_encoder);
- register_avcodec(&mp2_encoder);
-#ifdef CONFIG_MP3LAME
- register_avcodec(&mp3lame_encoder);
-#endif
-#ifdef CONFIG_VORBIS
- register_avcodec(&oggvorbis_encoder);
- register_avcodec(&oggvorbis_decoder);
-#endif
- register_avcodec(&mpeg1video_encoder);
-// register_avcodec(&h264_encoder);
-#ifdef CONFIG_RISKY
- register_avcodec(&mpeg2video_encoder);
- register_avcodec(&h263_encoder);
- register_avcodec(&h263p_encoder);
- register_avcodec(&flv_encoder);
- register_avcodec(&rv10_encoder);
- register_avcodec(&mpeg4_encoder);
- register_avcodec(&msmpeg4v1_encoder);
- register_avcodec(&msmpeg4v2_encoder);
- register_avcodec(&msmpeg4v3_encoder);
- register_avcodec(&wmv1_encoder);
- register_avcodec(&wmv2_encoder);
-#endif
- register_avcodec(&mjpeg_encoder);
- register_avcodec(&ljpeg_encoder);
- register_avcodec(&huffyuv_encoder);
- register_avcodec(&asv1_encoder);
- register_avcodec(&asv2_encoder);
- register_avcodec(&ffv1_encoder);
-#endif /* CONFIG_ENCODERS */
- register_avcodec(&rawvideo_encoder);
- register_avcodec(&rawvideo_decoder);
-
- /* decoders */
-#ifdef CONFIG_DECODERS
-#ifdef CONFIG_RISKY
- register_avcodec(&h263_decoder);
- register_avcodec(&mpeg4_decoder);
- register_avcodec(&msmpeg4v1_decoder);
- register_avcodec(&msmpeg4v2_decoder);
- register_avcodec(&msmpeg4v3_decoder);
- register_avcodec(&wmv1_decoder);
- register_avcodec(&wmv2_decoder);
- register_avcodec(&h263i_decoder);
- register_avcodec(&flv_decoder);
- register_avcodec(&rv10_decoder);
- register_avcodec(&svq1_decoder);
- register_avcodec(&svq3_decoder);
- register_avcodec(&wmav1_decoder);
- register_avcodec(&wmav2_decoder);
- register_avcodec(&indeo3_decoder);
-#ifdef CONFIG_FAAD
- register_avcodec(&aac_decoder);
- register_avcodec(&mpeg4aac_decoder);
-#endif
-#endif
- register_avcodec(&mpeg1video_decoder);
- register_avcodec(&mpeg2video_decoder);
-#ifdef HAVE_XVMC
- register_avcodec(&mpeg_xvmc_decoder);
-#endif
- register_avcodec(&dvvideo_decoder);
- register_avcodec(&dvaudio_decoder);
- register_avcodec(&mjpeg_decoder);
- register_avcodec(&mjpegb_decoder);
- register_avcodec(&mp2_decoder);
- register_avcodec(&mp3_decoder);
- register_avcodec(&mace3_decoder);
- register_avcodec(&mace6_decoder);
- register_avcodec(&huffyuv_decoder);
- register_avcodec(&ffv1_decoder);
- register_avcodec(&cyuv_decoder);
- register_avcodec(&h264_decoder);
- register_avcodec(&vp3_decoder);
- register_avcodec(&asv1_decoder);
- register_avcodec(&asv2_decoder);
- register_avcodec(&vcr1_decoder);
- register_avcodec(&cljr_decoder);
- register_avcodec(&fourxm_decoder);
- register_avcodec(&mdec_decoder);
- register_avcodec(&roq_decoder);
- register_avcodec(&interplay_video_decoder);
- register_avcodec(&xan_wc3_decoder);
-#ifdef CONFIG_AC3
- register_avcodec(&ac3_decoder);
-#endif
- register_avcodec(&ra_144_decoder);
- register_avcodec(&ra_288_decoder);
- register_avcodec(&roq_dpcm_decoder);
- register_avcodec(&interplay_dpcm_decoder);
- register_avcodec(&xan_dpcm_decoder);
-#endif /* CONFIG_DECODERS */
-
-#ifdef AMR_NB
- register_avcodec(&amr_nb_decoder);
- register_avcodec(&amr_nb_encoder);
-#endif /* AMR_NB */
- /* pcm codecs */
-
-#define PCM_CODEC(id, name) \
- register_avcodec(& name ## _encoder); \
- register_avcodec(& name ## _decoder); \
-
-PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
-PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
-PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
-PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
-PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
-PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
-PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
-PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
-
- /* adpcm codecs */
-PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
-PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
-PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
-
-#undef PCM_CODEC
-}
-
+++ /dev/null
-/*
- * AMR Audio decoder stub
- * Copyright (c) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- /*
- This code implements amr-nb audio encoder/decoder through external reference
- code from www.3gpp.org. The licence of the code from 3gpp is unclear so you
- have to download the code separately. Two versions exists: One fixed-point
- and one with floats. For some reason the float-encoder is significant faster
- atleast on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip at MR102).
-
- The fixed-point (TS26.073) can be downloaded from:
- http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26073-510.zip
- Extract the soure into ffmpeg/libavcodec/amr
- To use the float version run "./configure" with "--enable-amr-nb-fixed"
-
- The float version (default) can be downloaded from:
- http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26104-510.zip
- Extract the soure into ffmpeg/libavcodec/amr_float
-
- The specification for amr-nb can be found in TS 26.071
- (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other
- info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm
-
- In the future support for AMR-WB might also be included here.
- Reference code exist in TS26.173 and TS 26.204.
-
- */
-#define DEBUG
-//#define AMR_NB_FIXED
-#include "../config.h"
-#include "avcodec.h"
-
-#ifdef AMR_NB_FIXED
-
-#define MMS_IO
-
-#include "amr/sp_dec.h"
-#include "amr/d_homing.h"
-#include "amr/typedef.h"
-#include "amr/sp_enc.h"
-#include "amr/sid_sync.h"
-#include "amr/e_homing.h"
-
-#else
-#include "amr_float/interf_dec.h"
-#include "amr_float/interf_enc.h"
-#endif
-
-/* Common code for fixed and float version*/
-typedef struct AMR_bitrates
-{
- int startrate;
- int stoprate;
- enum Mode mode;
-
-} AMR_bitrates;
-
-/* Match desired bitrate with closest one*/
-static enum Mode getBitrateMode(int bitrate)
-{
- /* Adjusted so that all bitrates can be used from commandline where
- only a multiple of 1000 can be specified*/
- AMR_bitrates rates[]={ {0,4999,MR475}, //4
- {5000,5899,MR515},//5
- {5900,6699,MR59},//6
- {6700,7000,MR67},//7
- {7001,7949,MR74},//8
- {7950,9999,MR795},//9
- {10000,11999,MR102},//10
- {12000,64000,MR122},//12
-
- };
- int i;
- for(i=0;i<sizeof(rates);i++)
- {
- if(rates[i].startrate<=bitrate && rates[i].stoprate>=bitrate)
- {
- return(rates[i].mode);
- }
- }
- /*Return highest possible*/
- return(MR122);
-}
-
-#ifdef AMR_NB_FIXED
-/* fixed point version*/
-/* frame size in serial bitstream file (frame type + serial stream + flags) */
-#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5)
-
-typedef struct AMRContext {
- int frameCount;
- Speech_Decode_FrameState *speech_decoder_state;
- enum RXFrameType rx_type;
- enum Mode mode;
- Word16 reset_flag;
- Word16 reset_flag_old;
-
- enum Mode enc_bitrate;
- Speech_Encode_FrameState *enstate;
- sid_syncState *sidstate;
- enum TXFrameType tx_frametype;
-
-
-} AMRContext;
-
-static int amr_nb_decode_init(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- s->frameCount=0;
- s->speech_decoder_state=NULL;
- s->rx_type = (enum RXFrameType)0;
- s->mode= (enum Mode)0;
- s->reset_flag=0;
- s->reset_flag_old=1;
-
- if(Speech_Decode_Frame_init(&s->speech_decoder_state, "Decoder"))
- {
- printf("Speech_Decode_Frame_init error\n");
- return -1;
- }
- return 0;
-}
-
-static int amr_nb_encode_init(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- s->frameCount=0;
- s->speech_decoder_state=NULL;
- s->rx_type = (enum RXFrameType)0;
- s->mode= (enum Mode)0;
- s->reset_flag=0;
- s->reset_flag_old=1;
-
- if(avctx->sample_rate!=8000)
- {
-#ifdef DEBUG
- printf("Only 8000Hz sample rate supported\n");
-#endif
- return -1;
- }
-
- if(avctx->channels!=1)
- {
-#ifdef DEBUG
- printf("Only mono supported\n");
-#endif
- return -1;
- }
-
- avctx->frame_size=160;
- avctx->coded_frame= avcodec_alloc_frame();
-
- if(Speech_Encode_Frame_init(&s->enstate, 0, "encoder") || sid_sync_init (&s->sidstate))
- {
-#ifdef DEBUG
- printf("Speech_Encode_Frame_init error\n");
-#endif
- return -1;
- }
-
- s->enc_bitrate=getBitrateMode(avctx->bit_rate);
-
- return 0;
-}
-
-static int amr_nb_encode_close(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- Speech_Encode_Frame_exit(&s->enstate);
- sid_sync_exit (&s->sidstate);
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
-static int amr_nb_decode_close(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- Speech_Decode_Frame_exit(&s->speech_decoder_state);
- return 0;
-}
-
-static int amr_nb_decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- AMRContext *s = avctx->priv_data;
-
- uint8_t*amrData=buf;
- int offset=0;
-
- UWord8 toc, q, ft;
-
- Word16 serial[SERIAL_FRAMESIZE]; /* coded bits */
- Word16 *synth;
- UWord8 *packed_bits;
- *data_size=0;
-
- static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
- int i;
-
- //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount);
-
- synth=data;
-
-// while(offset<buf_size)
- {
- toc=amrData[offset];
- /* read rest of the frame based on ToC byte */
- q = (toc >> 2) & 0x01;
- ft = (toc >> 3) & 0x0F;
-
- //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]);
-
- offset++;
-
- packed_bits=amrData+offset;
-
- offset+=packed_size[ft];
-
- //Unsort and unpack bits
- s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]);
-
- //We have a new frame
- s->frameCount++;
-
- if (s->rx_type == RX_NO_DATA)
- {
- s->mode = s->speech_decoder_state->prev_mode;
- }
- else {
- s->speech_decoder_state->prev_mode = s->mode;
- }
-
- /* if homed: check if this frame is another homing frame */
- if (s->reset_flag_old == 1)
- {
- /* only check until end of first subframe */
- s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode);
- }
- /* produce encoder homing frame if homed & input=decoder homing frame */
- if ((s->reset_flag != 0) && (s->reset_flag_old != 0))
- {
- for (i = 0; i < L_FRAME; i++)
- {
- synth[i] = EHF_MASK;
- }
- }
- else
- {
- /* decode frame */
- Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth);
- }
-
- //Each AMR-frame results in 160 16-bit samples
- *data_size+=160*2;
- synth+=160;
-
- /* if not homed: check whether current frame is a homing frame */
- if (s->reset_flag_old == 0)
- {
- /* check whole frame */
- s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode);
- }
- /* reset decoder if current frame is a homing frame */
- if (s->reset_flag != 0)
- {
- Speech_Decode_Frame_reset(s->speech_decoder_state);
- }
- s->reset_flag_old = s->reset_flag;
-
- }
- return offset;
-}
-
-
-static int amr_nb_encode_frame(AVCodecContext *avctx,
- unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
-{
- short serial_data[250] = {0};
-
- AMRContext *s = avctx->priv_data;
- int written;
-
- s->reset_flag = encoder_homing_frame_test(data);
-
- Speech_Encode_Frame(s->enstate, s->enc_bitrate, data, &serial_data[1], &s->mode);
-
- /* add frame type and mode */
- sid_sync (s->sidstate, s->mode, &s->tx_frametype);
-
- written = PackBits(s->mode, s->enc_bitrate, s->tx_frametype, &serial_data[1], frame);
-
- if (s->reset_flag != 0)
- {
- Speech_Encode_Frame_reset(s->enstate);
- sid_sync_reset(s->sidstate);
- }
- return written;
-}
-
-
-#else /* Float point version*/
-
-typedef struct AMRContext {
- int frameCount;
- void * decState;
- int *enstate;
- enum Mode enc_bitrate;
-} AMRContext;
-
-static int amr_nb_decode_init(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- s->frameCount=0;
- s->decState=Decoder_Interface_init();
- if(!s->decState)
- {
- printf("Decoder_Interface_init error\r\n");
- return -1;
- }
- return 0;
-}
-
-static int amr_nb_encode_init(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- s->frameCount=0;
-
- if(avctx->sample_rate!=8000)
- {
-#ifdef DEBUG
- printf("Only 8000Hz sample rate supported\n");
-#endif
- return -1;
- }
-
- if(avctx->channels!=1)
- {
-#ifdef DEBUG
- printf("Only mono supported\n");
-#endif
- return -1;
- }
-
- avctx->frame_size=160;
- avctx->coded_frame= avcodec_alloc_frame();
-
- s->enstate=Encoder_Interface_init(0);
- if(!s->enstate)
- {
- printf("Encoder_Interface_init error\n");
- return -1;
- }
-
- s->enc_bitrate=getBitrateMode(avctx->bit_rate);
-
- return 0;
-}
-
-static int amr_nb_decode_close(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- Decoder_Interface_exit(s->decState);
- return 0;
-}
-
-static int amr_nb_encode_close(AVCodecContext * avctx)
-{
- AMRContext *s = avctx->priv_data;
- Encoder_Interface_exit(s->enstate);
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
-static int amr_nb_decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- AMRContext *s = (AMRContext*)avctx->priv_data;
-
- uint8_t*amrData=buf;
- int offset=0;
- static short block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 };
- enum Mode dec_mode;
- int packet_size;
- *data_size=0;
-
- //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount);
-
- while(offset<buf_size)
- {
- dec_mode = (amrData[offset] >> 3) & 0x000F;
- packet_size = block_size[dec_mode];
-
- s->frameCount++;
- //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packet_size,amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]);
- /* call decoder */
- Decoder_Interface_Decode(s->decState, &amrData[offset], data+*data_size, 0);
- *data_size+=160*2;
-
- offset+=packet_size+1;
- }
- return buf_size;
-}
-
-static int amr_nb_encode_frame(AVCodecContext *avctx,
- unsigned char *frame/*out*/, int buf_size, void *data/*in*/)
-{
- AMRContext *s = (AMRContext*)avctx->priv_data;
- int written;
-
- written = Encoder_Interface_Encode(s->enstate,
- s->enc_bitrate,
- data,
- frame,
- 0);
-
- return written;
-}
-
-#endif
-
-AVCodec amr_nb_decoder =
-{
- "amr_nb",
- CODEC_TYPE_AUDIO,
- CODEC_ID_AMR_NB,
- sizeof(AMRContext),
- amr_nb_decode_init,
- NULL,
- amr_nb_decode_close,
- amr_nb_decode_frame,
-};
-
-AVCodec amr_nb_encoder =
-{
- "amr_nb",
- CODEC_TYPE_AUDIO,
- CODEC_ID_AMR_NB,
- sizeof(AMRContext),
- amr_nb_encode_init,
- amr_nb_encode_frame,
- amr_nb_encode_close,
- NULL,
-};
+++ /dev/null
-/**
- * @file apiexample.c
- * avcodec API use example.
- *
- * Note that this library only handles codecs (mpeg, mpeg4, etc...),
- * not file formats (avi, vob, etc...). See library 'libavformat' for the
- * format handling
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#ifdef HAVE_AV_CONFIG_H
-#undef HAVE_AV_CONFIG_H
-#endif
-
-#include "avcodec.h"
-
-#define INBUF_SIZE 4096
-
-/*
- * Audio encoding example
- */
-void audio_encode_example(const char *filename)
-{
- AVCodec *codec;
- AVCodecContext *c= NULL;
- int frame_size, i, j, out_size, outbuf_size;
- FILE *f;
- short *samples;
- float t, tincr;
- uint8_t *outbuf;
-
- printf("Audio encoding\n");
-
- /* find the MP2 encoder */
- codec = avcodec_find_encoder(CODEC_ID_MP2);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
- c= avcodec_alloc_context();
-
- /* put sample parameters */
- c->bit_rate = 64000;
- c->sample_rate = 44100;
- c->channels = 2;
-
- /* open it */
- if (avcodec_open(c, codec) < 0) {
- fprintf(stderr, "could not open codec\n");
- exit(1);
- }
-
- /* the codec gives us the frame size, in samples */
- frame_size = c->frame_size;
- samples = malloc(frame_size * 2 * c->channels);
- outbuf_size = 10000;
- outbuf = malloc(outbuf_size);
-
- f = fopen(filename, "w");
- if (!f) {
- fprintf(stderr, "could not open %s\n", filename);
- exit(1);
- }
-
- /* encode a single tone sound */
- t = 0;
- tincr = 2 * M_PI * 440.0 / c->sample_rate;
- for(i=0;i<200;i++) {
- for(j=0;j<frame_size;j++) {
- samples[2*j] = (int)(sin(t) * 10000);
- samples[2*j+1] = samples[2*j];
- t += tincr;
- }
- /* encode the samples */
- out_size = avcodec_encode_audio(c, outbuf, outbuf_size, samples);
- fwrite(outbuf, 1, out_size, f);
- }
- fclose(f);
- free(outbuf);
- free(samples);
-
- avcodec_close(c);
- free(c);
-}
-
-/*
- * Audio decoding.
- */
-void audio_decode_example(const char *outfilename, const char *filename)
-{
- AVCodec *codec;
- AVCodecContext *c= NULL;
- int out_size, size, len;
- FILE *f, *outfile;
- uint8_t *outbuf;
- uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
-
- printf("Audio decoding\n");
-
- /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
- memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
-
- /* find the mpeg audio decoder */
- codec = avcodec_find_decoder(CODEC_ID_MP2);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
- c= avcodec_alloc_context();
-
- /* open it */
- if (avcodec_open(c, codec) < 0) {
- fprintf(stderr, "could not open codec\n");
- exit(1);
- }
-
- outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
-
- f = fopen(filename, "r");
- if (!f) {
- fprintf(stderr, "could not open %s\n", filename);
- exit(1);
- }
- outfile = fopen(outfilename, "w");
- if (!outfile) {
- free(c);
- exit(1);
- }
-
- /* decode until eof */
- inbuf_ptr = inbuf;
- for(;;) {
- size = fread(inbuf, 1, INBUF_SIZE, f);
- if (size == 0)
- break;
-
- inbuf_ptr = inbuf;
- while (size > 0) {
- len = avcodec_decode_audio(c, (short *)outbuf, &out_size,
- inbuf_ptr, size);
- if (len < 0) {
- fprintf(stderr, "Error while decoding\n");
- exit(1);
- }
- if (out_size > 0) {
- /* if a frame has been decoded, output it */
- fwrite(outbuf, 1, out_size, outfile);
- }
- size -= len;
- inbuf_ptr += len;
- }
- }
-
- fclose(outfile);
- fclose(f);
- free(outbuf);
-
- avcodec_close(c);
- free(c);
-}
-
-/*
- * Video encoding example
- */
-void video_encode_example(const char *filename)
-{
- AVCodec *codec;
- AVCodecContext *c= NULL;
- int i, out_size, size, x, y, outbuf_size;
- FILE *f;
- AVFrame *picture;
- uint8_t *outbuf, *picture_buf;
-
- printf("Video encoding\n");
-
- /* find the mpeg1 video encoder */
- codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
- c= avcodec_alloc_context();
- picture= avcodec_alloc_frame();
-
- /* put sample parameters */
- c->bit_rate = 400000;
- /* resolution must be a multiple of two */
- c->width = 352;
- c->height = 288;
- /* frames per second */
- c->frame_rate = 25;
- c->frame_rate_base= 1;
- c->gop_size = 10; /* emit one intra frame every ten frames */
- c->max_b_frames=1;
-
- /* open it */
- if (avcodec_open(c, codec) < 0) {
- fprintf(stderr, "could not open codec\n");
- exit(1);
- }
-
- /* the codec gives us the frame size, in samples */
-
- f = fopen(filename, "w");
- if (!f) {
- fprintf(stderr, "could not open %s\n", filename);
- exit(1);
- }
-
- /* alloc image and output buffer */
- outbuf_size = 100000;
- outbuf = malloc(outbuf_size);
- size = c->width * c->height;
- picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
-
- picture->data[0] = picture_buf;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size / 4;
- picture->linesize[0] = c->width;
- picture->linesize[1] = c->width / 2;
- picture->linesize[2] = c->width / 2;
-
- /* encode 1 second of video */
- for(i=0;i<25;i++) {
- fflush(stdout);
- /* prepare a dummy image */
- /* Y */
- for(y=0;y<c->height;y++) {
- for(x=0;x<c->width;x++) {
- picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3;
- }
- }
-
- /* Cb and Cr */
- for(y=0;y<c->height/2;y++) {
- for(x=0;x<c->width/2;x++) {
- picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2;
- picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5;
- }
- }
-
- /* encode the image */
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
- printf("encoding frame %3d (size=%5d)\n", i, out_size);
- fwrite(outbuf, 1, out_size, f);
- }
-
- /* get the delayed frames */
- for(; out_size; i++) {
- fflush(stdout);
-
- out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL);
- printf("write frame %3d (size=%5d)\n", i, out_size);
- fwrite(outbuf, 1, out_size, f);
- }
-
- /* add sequence end code to have a real mpeg file */
- outbuf[0] = 0x00;
- outbuf[1] = 0x00;
- outbuf[2] = 0x01;
- outbuf[3] = 0xb7;
- fwrite(outbuf, 1, 4, f);
- fclose(f);
- free(picture_buf);
- free(outbuf);
-
- avcodec_close(c);
- free(c);
- free(picture);
- printf("\n");
-}
-
-/*
- * Video decoding example
- */
-
-void pgm_save(unsigned char *buf,int wrap, int xsize,int ysize,char *filename)
-{
- FILE *f;
- int i;
-
- f=fopen(filename,"w");
- fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255);
- for(i=0;i<ysize;i++)
- fwrite(buf + i * wrap,1,xsize,f);
- fclose(f);
-}
-
-void video_decode_example(const char *outfilename, const char *filename)
-{
- AVCodec *codec;
- AVCodecContext *c= NULL;
- int frame, size, got_picture, len;
- FILE *f;
- AVFrame *picture;
- uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
- char buf[1024];
-
- /* set end of buffer to 0 (this ensures that no overreading happens for damaged mpeg streams) */
- memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
-
- printf("Video decoding\n");
-
- /* find the mpeg1 video decoder */
- codec = avcodec_find_decoder(CODEC_ID_MPEG1VIDEO);
- if (!codec) {
- fprintf(stderr, "codec not found\n");
- exit(1);
- }
-
- c= avcodec_alloc_context();
- picture= avcodec_alloc_frame();
-
- if(codec->capabilities&CODEC_CAP_TRUNCATED)
- c->flags|= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
-
- /* for some codecs, such as msmpeg4 and mpeg4, width and height
- MUST be initialized there because these info are not available
- in the bitstream */
-
- /* open it */
- if (avcodec_open(c, codec) < 0) {
- fprintf(stderr, "could not open codec\n");
- exit(1);
- }
-
- /* the codec gives us the frame size, in samples */
-
- f = fopen(filename, "r");
- if (!f) {
- fprintf(stderr, "could not open %s\n", filename);
- exit(1);
- }
-
- frame = 0;
- for(;;) {
- size = fread(inbuf, 1, INBUF_SIZE, f);
- if (size == 0)
- break;
-
- /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio)
- and this is the only method to use them because you cannot
- know the compressed data size before analysing it.
-
- BUT some other codecs (msmpeg4, mpeg4) are inherently frame
- based, so you must call them with all the data for one
- frame exactly. You must also initialize 'width' and
- 'height' before initializing them. */
-
- /* NOTE2: some codecs allow the raw parameters (frame size,
- sample rate) to be changed at any frame. We handle this, so
- you should also take care of it */
-
- /* here, we use a stream based decoder (mpeg1video), so we
- feed decoder and see if it could decode a frame */
- inbuf_ptr = inbuf;
- while (size > 0) {
- len = avcodec_decode_video(c, picture, &got_picture,
- inbuf_ptr, size);
- if (len < 0) {
- fprintf(stderr, "Error while decoding frame %d\n", frame);
- exit(1);
- }
- if (got_picture) {
- printf("saving frame %3d\n", frame);
- fflush(stdout);
-
- /* the picture is allocated by the decoder. no need to
- free it */
- snprintf(buf, sizeof(buf), outfilename, frame);
- pgm_save(picture->data[0], picture->linesize[0],
- c->width, c->height, buf);
- frame++;
- }
- size -= len;
- inbuf_ptr += len;
- }
- }
-
- /* some codecs, such as MPEG, transmit the I and P frame with a
- latency of one frame. You must do the following to have a
- chance to get the last frame of the video */
- len = avcodec_decode_video(c, picture, &got_picture,
- NULL, 0);
- if (got_picture) {
- printf("saving last frame %3d\n", frame);
- fflush(stdout);
-
- /* the picture is allocated by the decoder. no need to
- free it */
- snprintf(buf, sizeof(buf), outfilename, frame);
- pgm_save(picture->data[0], picture->linesize[0],
- c->width, c->height, buf);
- frame++;
- }
-
- fclose(f);
-
- avcodec_close(c);
- free(c);
- free(picture);
- printf("\n");
-}
-
-// simple example how the options could be used
-int options_example(int argc, char* argv[])
-{
- AVCodec* codec = avcodec_find_encoder_by_name((argc > 1) ? argv[2] : "mpeg4");
- const AVOption* c;
- AVCodecContext* avctx;
- char* def = av_malloc(5000);
- const char* col = "";
- int i = 0;
-
- if (!codec)
- return -1;
- c = codec->options;
- avctx = avcodec_alloc_context();
- *def = 0;
-
- if (c) {
- const AVOption *stack[FF_OPT_MAX_DEPTH];
- int depth = 0;
- for (;;) {
- if (!c->name) {
- if (c->help) {
- stack[depth++] = c;
- c = (const AVOption*)c->help;
- } else {
- if (depth == 0)
- break; // finished
- c = stack[--depth];
- c++;
- }
- } else {
- int t = c->type & FF_OPT_TYPE_MASK;
- printf("Config %s %s\n",
- t == FF_OPT_TYPE_BOOL ? "bool " :
- t == FF_OPT_TYPE_DOUBLE ? "double " :
- t == FF_OPT_TYPE_INT ? "integer" :
- t == FF_OPT_TYPE_STRING ? "string " :
- "unknown??", c->name);
- switch (t) {
- case FF_OPT_TYPE_BOOL:
- i += sprintf(def + i, "%s%s=%s",
- col, c->name,
- c->defval != 0. ? "on" : "off");
- break;
- case FF_OPT_TYPE_DOUBLE:
- i += sprintf(def + i, "%s%s=%f",
- col, c->name, c->defval);
- break;
- case FF_OPT_TYPE_INT:
- i += sprintf(def + i, "%s%s=%d",
- col, c->name, (int) c->defval);
- break;
- case FF_OPT_TYPE_STRING:
- if (c->defstr) {
- char* d = av_strdup(c->defstr);
- char* f = strchr(d, ',');
- if (f)
- *f = 0;
- i += sprintf(def + i, "%s%s=%s",
- col, c->name, d);
- av_free(d);
- }
- break;
- }
- col = ":";
- c++;
- }
- }
- }
- printf("Default Options: %s\n", def);
- av_free(def);
- return 0;
-}
-
-
-int main(int argc, char **argv)
-{
- const char *filename;
-
- /* must be called before using avcodec lib */
- avcodec_init();
-
- /* register all the codecs (you can also register only the codec
- you wish to have smaller code */
- avcodec_register_all();
-
-#ifdef OPT_TEST
- options_example(argc, argv);
-#else
- if (argc <= 1) {
- audio_encode_example("/tmp/test.mp2");
- audio_decode_example("/tmp/test.sw", "/tmp/test.mp2");
-
- video_encode_example("/tmp/test.mpg");
- filename = "/tmp/test.mpg";
- } else {
- filename = argv[1];
- }
-
- // audio_decode_example("/tmp/test.sw", filename);
- video_decode_example("/tmp/test%d.pgm", filename);
-#endif
-
- return 0;
-}
+++ /dev/null
-/*
- * ASUS V1/V2 codec
- * Copyright (c) 2003 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file asv1.c
- * ASUS V1/V2 codec.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#define VLC_BITS 6
-#define ASV2_LEVEL_VLC_BITS 10
-
-typedef struct ASV1Context{
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame picture;
- PutBitContext pb;
- GetBitContext gb;
- ScanTable scantable;
- int inv_qscale;
- int mb_width;
- int mb_height;
- int mb_width2;
- int mb_height2;
- DCTELEM __align8 block[6][64];
- uint16_t __align8 intra_matrix[64];
- int __align8 q_intra_matrix[64];
- uint8_t *bitstream_buffer;
- int bitstream_buffer_size;
-} ASV1Context;
-
-static const uint8_t scantab[64]={
- 0x00,0x08,0x01,0x09,0x10,0x18,0x11,0x19,
- 0x02,0x0A,0x03,0x0B,0x12,0x1A,0x13,0x1B,
- 0x04,0x0C,0x05,0x0D,0x20,0x28,0x21,0x29,
- 0x06,0x0E,0x07,0x0F,0x14,0x1C,0x15,0x1D,
- 0x22,0x2A,0x23,0x2B,0x30,0x38,0x31,0x39,
- 0x16,0x1E,0x17,0x1F,0x24,0x2C,0x25,0x2D,
- 0x32,0x3A,0x33,0x3B,0x26,0x2E,0x27,0x2F,
- 0x34,0x3C,0x35,0x3D,0x36,0x3E,0x37,0x3F,
-};
-
-
-static const uint8_t reverse[256]={
-0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
-0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
-0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
-0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
-0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
-0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
-0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
-0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
-0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
-0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
-0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
-0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
-0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
-0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
-0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
-0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
-};
-
-static const uint8_t ccp_tab[17][2]={
- {0x2,2}, {0x7,5}, {0xB,5}, {0x3,5},
- {0xD,5}, {0x5,5}, {0x9,5}, {0x1,5},
- {0xE,5}, {0x6,5}, {0xA,5}, {0x2,5},
- {0xC,5}, {0x4,5}, {0x8,5}, {0x3,2},
- {0xF,5}, //EOB
-};
-
-static const uint8_t level_tab[7][2]={
- {3,4}, {3,3}, {3,2}, {0,3}, {2,2}, {2,3}, {2,4}
-};
-
-static const uint8_t dc_ccp_tab[8][2]={
- {0x1,2}, {0xD,4}, {0xF,4}, {0xC,4},
- {0x5,3}, {0xE,4}, {0x4,3}, {0x0,2},
-};
-
-static const uint8_t ac_ccp_tab[16][2]={
- {0x00,2}, {0x3B,6}, {0x0A,4}, {0x3A,6},
- {0x02,3}, {0x39,6}, {0x3C,6}, {0x38,6},
- {0x03,3}, {0x3D,6}, {0x08,4}, {0x1F,5},
- {0x09,4}, {0x0B,4}, {0x0D,4}, {0x0C,4},
-};
-
-static const uint8_t asv2_level_tab[63][2]={
- {0x3F,10},{0x2F,10},{0x37,10},{0x27,10},{0x3B,10},{0x2B,10},{0x33,10},{0x23,10},
- {0x3D,10},{0x2D,10},{0x35,10},{0x25,10},{0x39,10},{0x29,10},{0x31,10},{0x21,10},
- {0x1F, 8},{0x17, 8},{0x1B, 8},{0x13, 8},{0x1D, 8},{0x15, 8},{0x19, 8},{0x11, 8},
- {0x0F, 6},{0x0B, 6},{0x0D, 6},{0x09, 6},
- {0x07, 4},{0x05, 4},
- {0x03, 2},
- {0x00, 5},
- {0x02, 2},
- {0x04, 4},{0x06, 4},
- {0x08, 6},{0x0C, 6},{0x0A, 6},{0x0E, 6},
- {0x10, 8},{0x18, 8},{0x14, 8},{0x1C, 8},{0x12, 8},{0x1A, 8},{0x16, 8},{0x1E, 8},
- {0x20,10},{0x30,10},{0x28,10},{0x38,10},{0x24,10},{0x34,10},{0x2C,10},{0x3C,10},
- {0x22,10},{0x32,10},{0x2A,10},{0x3A,10},{0x26,10},{0x36,10},{0x2E,10},{0x3E,10},
-};
-
-
-static VLC ccp_vlc;
-static VLC level_vlc;
-static VLC dc_ccp_vlc;
-static VLC ac_ccp_vlc;
-static VLC asv2_level_vlc;
-
-static void init_vlcs(ASV1Context *a){
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- init_vlc(&ccp_vlc, VLC_BITS, 17,
- &ccp_tab[0][1], 2, 1,
- &ccp_tab[0][0], 2, 1);
- init_vlc(&dc_ccp_vlc, VLC_BITS, 8,
- &dc_ccp_tab[0][1], 2, 1,
- &dc_ccp_tab[0][0], 2, 1);
- init_vlc(&ac_ccp_vlc, VLC_BITS, 16,
- &ac_ccp_tab[0][1], 2, 1,
- &ac_ccp_tab[0][0], 2, 1);
- init_vlc(&level_vlc, VLC_BITS, 7,
- &level_tab[0][1], 2, 1,
- &level_tab[0][0], 2, 1);
- init_vlc(&asv2_level_vlc, ASV2_LEVEL_VLC_BITS, 63,
- &asv2_level_tab[0][1], 2, 1,
- &asv2_level_tab[0][0], 2, 1);
- }
-}
-
-//FIXME write a reversed bitstream reader to avoid the double reverse
-static inline int asv2_get_bits(GetBitContext *gb, int n){
- return reverse[ get_bits(gb, n) << (8-n) ];
-}
-
-static inline void asv2_put_bits(PutBitContext *pb, int n, int v){
- put_bits(pb, n, reverse[ v << (8-n) ]);
-}
-
-static inline int asv1_get_level(GetBitContext *gb){
- int code= get_vlc2(gb, level_vlc.table, VLC_BITS, 1);
-
- if(code==3) return get_sbits(gb, 8);
- else return code - 3;
-}
-
-static inline int asv2_get_level(GetBitContext *gb){
- int code= get_vlc2(gb, asv2_level_vlc.table, ASV2_LEVEL_VLC_BITS, 1);
-
- if(code==31) return (int8_t)asv2_get_bits(gb, 8);
- else return code - 31;
-}
-
-static inline void asv1_put_level(PutBitContext *pb, int level){
- unsigned int index= level + 3;
-
- if(index <= 6) put_bits(pb, level_tab[index][1], level_tab[index][0]);
- else{
- put_bits(pb, level_tab[3][1], level_tab[3][0]);
- put_bits(pb, 8, level&0xFF);
- }
-}
-
-static inline void asv2_put_level(PutBitContext *pb, int level){
- unsigned int index= level + 31;
-
- if(index <= 62) put_bits(pb, asv2_level_tab[index][1], asv2_level_tab[index][0]);
- else{
- put_bits(pb, asv2_level_tab[31][1], asv2_level_tab[31][0]);
- asv2_put_bits(pb, 8, level&0xFF);
- }
-}
-
-static inline int asv1_decode_block(ASV1Context *a, DCTELEM block[64]){
- int i;
-
- block[0]= 8*get_bits(&a->gb, 8);
-
- for(i=0; i<11; i++){
- const int ccp= get_vlc2(&a->gb, ccp_vlc.table, VLC_BITS, 1);
-
- if(ccp){
- if(ccp == 16) break;
- if(ccp < 0 || i>=10){
- printf("coded coeff pattern damaged\n");
- return -1;
- }
-
- if(ccp&8) block[a->scantable.permutated[4*i+0]]= (asv1_get_level(&a->gb) * a->intra_matrix[4*i+0])>>4;
- if(ccp&4) block[a->scantable.permutated[4*i+1]]= (asv1_get_level(&a->gb) * a->intra_matrix[4*i+1])>>4;
- if(ccp&2) block[a->scantable.permutated[4*i+2]]= (asv1_get_level(&a->gb) * a->intra_matrix[4*i+2])>>4;
- if(ccp&1) block[a->scantable.permutated[4*i+3]]= (asv1_get_level(&a->gb) * a->intra_matrix[4*i+3])>>4;
- }
- }
-
- return 0;
-}
-
-static inline int asv2_decode_block(ASV1Context *a, DCTELEM block[64]){
- int i, count, ccp;
-
- count= asv2_get_bits(&a->gb, 4);
-
- block[0]= 8*asv2_get_bits(&a->gb, 8);
-
- ccp= get_vlc2(&a->gb, dc_ccp_vlc.table, VLC_BITS, 1);
- if(ccp){
- if(ccp&4) block[a->scantable.permutated[1]]= (asv2_get_level(&a->gb) * a->intra_matrix[1])>>4;
- if(ccp&2) block[a->scantable.permutated[2]]= (asv2_get_level(&a->gb) * a->intra_matrix[2])>>4;
- if(ccp&1) block[a->scantable.permutated[3]]= (asv2_get_level(&a->gb) * a->intra_matrix[3])>>4;
- }
-
- for(i=1; i<count+1; i++){
- const int ccp= get_vlc2(&a->gb, ac_ccp_vlc.table, VLC_BITS, 1);
-
- if(ccp){
- if(ccp&8) block[a->scantable.permutated[4*i+0]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+0])>>4;
- if(ccp&4) block[a->scantable.permutated[4*i+1]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+1])>>4;
- if(ccp&2) block[a->scantable.permutated[4*i+2]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+2])>>4;
- if(ccp&1) block[a->scantable.permutated[4*i+3]]= (asv2_get_level(&a->gb) * a->intra_matrix[4*i+3])>>4;
- }
- }
-
- return 0;
-}
-
-static inline void asv1_encode_block(ASV1Context *a, DCTELEM block[64]){
- int i;
- int nc_count=0;
-
- put_bits(&a->pb, 8, (block[0] + 32)>>6);
- block[0]= 0;
-
- for(i=0; i<10; i++){
- const int index= scantab[4*i];
- int ccp=0;
-
- if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8;
- if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4;
- if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2;
- if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1;
-
- if(ccp){
- for(;nc_count; nc_count--)
- put_bits(&a->pb, ccp_tab[0][1], ccp_tab[0][0]);
-
- put_bits(&a->pb, ccp_tab[ccp][1], ccp_tab[ccp][0]);
-
- if(ccp&8) asv1_put_level(&a->pb, block[index + 0]);
- if(ccp&4) asv1_put_level(&a->pb, block[index + 8]);
- if(ccp&2) asv1_put_level(&a->pb, block[index + 1]);
- if(ccp&1) asv1_put_level(&a->pb, block[index + 9]);
- }else{
- nc_count++;
- }
- }
- put_bits(&a->pb, ccp_tab[16][1], ccp_tab[16][0]);
-}
-
-static inline void asv2_encode_block(ASV1Context *a, DCTELEM block[64]){
- int i;
- int count=0;
-
- for(count=63; count>3; count--){
- const int index= scantab[count];
-
- if( (block[index]*a->q_intra_matrix[index] + (1<<15))>>16 )
- break;
- }
-
- count >>= 2;
-
- asv2_put_bits(&a->pb, 4, count);
- asv2_put_bits(&a->pb, 8, (block[0] + 32)>>6);
- block[0]= 0;
-
- for(i=0; i<=count; i++){
- const int index= scantab[4*i];
- int ccp=0;
-
- if( (block[index + 0] = (block[index + 0]*a->q_intra_matrix[index + 0] + (1<<15))>>16) ) ccp |= 8;
- if( (block[index + 8] = (block[index + 8]*a->q_intra_matrix[index + 8] + (1<<15))>>16) ) ccp |= 4;
- if( (block[index + 1] = (block[index + 1]*a->q_intra_matrix[index + 1] + (1<<15))>>16) ) ccp |= 2;
- if( (block[index + 9] = (block[index + 9]*a->q_intra_matrix[index + 9] + (1<<15))>>16) ) ccp |= 1;
-
- if(i) put_bits(&a->pb, ac_ccp_tab[ccp][1], ac_ccp_tab[ccp][0]);
- else put_bits(&a->pb, dc_ccp_tab[ccp][1], dc_ccp_tab[ccp][0]);
-
- if(ccp){
- if(ccp&8) asv2_put_level(&a->pb, block[index + 0]);
- if(ccp&4) asv2_put_level(&a->pb, block[index + 8]);
- if(ccp&2) asv2_put_level(&a->pb, block[index + 1]);
- if(ccp&1) asv2_put_level(&a->pb, block[index + 9]);
- }
- }
-}
-
-static inline int decode_mb(ASV1Context *a, DCTELEM block[6][64]){
- int i;
-
- a->dsp.clear_blocks(block[0]);
-
- if(a->avctx->codec_id == CODEC_ID_ASV1){
- for(i=0; i<6; i++){
- if( asv1_decode_block(a, block[i]) < 0)
- return -1;
- }
- }else{
- for(i=0; i<6; i++){
- if( asv2_decode_block(a, block[i]) < 0)
- return -1;
- }
- }
- return 0;
-}
-
-static inline void encode_mb(ASV1Context *a, DCTELEM block[6][64]){
- int i;
-
- if(a->avctx->codec_id == CODEC_ID_ASV1){
- for(i=0; i<6; i++)
- asv1_encode_block(a, block[i]);
- }else{
- for(i=0; i<6; i++)
- asv2_encode_block(a, block[i]);
- }
-}
-
-static inline void idct_put(ASV1Context *a, int mb_x, int mb_y){
- DCTELEM (*block)[64]= a->block;
- int linesize= a->picture.linesize[0];
-
- uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
- uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
- uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
-
- a->dsp.idct_put(dest_y , linesize, block[0]);
- a->dsp.idct_put(dest_y + 8, linesize, block[1]);
- a->dsp.idct_put(dest_y + 8*linesize , linesize, block[2]);
- a->dsp.idct_put(dest_y + 8*linesize + 8, linesize, block[3]);
-
- if(!(a->avctx->flags&CODEC_FLAG_GRAY)){
- a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]);
- a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]);
- }
-}
-
-static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){
- DCTELEM (*block)[64]= a->block;
- int linesize= a->picture.linesize[0];
- int i;
-
- uint8_t *ptr_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
- uint8_t *ptr_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
- uint8_t *ptr_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
-
- a->dsp.get_pixels(block[0], ptr_y , linesize);
- a->dsp.get_pixels(block[1], ptr_y + 8, linesize);
- a->dsp.get_pixels(block[2], ptr_y + 8*linesize , linesize);
- a->dsp.get_pixels(block[3], ptr_y + 8*linesize + 8, linesize);
- for(i=0; i<4; i++)
- a->dsp.fdct(block[i]);
-
- if(!(a->avctx->flags&CODEC_FLAG_GRAY)){
- a->dsp.get_pixels(block[4], ptr_cb, a->picture.linesize[1]);
- a->dsp.get_pixels(block[5], ptr_cr, a->picture.linesize[2]);
- for(i=4; i<6; i++)
- a->dsp.fdct(block[i]);
- }
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- ASV1Context * const a = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int mb_x, mb_y;
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
-
- if(avctx->codec_id == CODEC_ID_ASV1)
- a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (uint32_t*)buf, buf_size/4);
- else{
- int i;
- for(i=0; i<buf_size; i++)
- a->bitstream_buffer[i]= reverse[ buf[i] ];
- }
-
- init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8);
-
- for(mb_y=0; mb_y<a->mb_height2; mb_y++){
- for(mb_x=0; mb_x<a->mb_width2; mb_x++){
- if( decode_mb(a, a->block) <0)
- return -1;
-
- idct_put(a, mb_x, mb_y);
- }
- }
-
- if(a->mb_width2 != a->mb_width){
- mb_x= a->mb_width2;
- for(mb_y=0; mb_y<a->mb_height2; mb_y++){
- if( decode_mb(a, a->block) <0)
- return -1;
-
- idct_put(a, mb_x, mb_y);
- }
- }
-
- if(a->mb_height2 != a->mb_height){
- mb_y= a->mb_height2;
- for(mb_x=0; mb_x<a->mb_width; mb_x++){
- if( decode_mb(a, a->block) <0)
- return -1;
-
- idct_put(a, mb_x, mb_y);
- }
- }
-#if 0
-int i;
-printf("%d %d\n", 8*buf_size, get_bits_count(&a->gb));
-for(i=get_bits_count(&a->gb); i<8*buf_size; i++){
- printf("%d", get_bits1(&a->gb));
-}
-
-for(i=0; i<s->avctx->extradata_size; i++){
- printf("%c\n", ((uint8_t*)s->avctx->extradata)[i]);
-}
-#endif
-
- *picture= *(AVFrame*)&a->picture;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return (get_bits_count(&a->gb)+31)/32*4;
-}
-
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- ASV1Context * const a = avctx->priv_data;
- AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int size;
- int mb_x, mb_y;
-
- init_put_bits(&a->pb, buf, buf_size, NULL, NULL);
-
- *p = *pict;
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- for(mb_y=0; mb_y<a->mb_height2; mb_y++){
- for(mb_x=0; mb_x<a->mb_width2; mb_x++){
- dct_get(a, mb_x, mb_y);
- encode_mb(a, a->block);
- }
- }
-
- if(a->mb_width2 != a->mb_width){
- mb_x= a->mb_width2;
- for(mb_y=0; mb_y<a->mb_height2; mb_y++){
- dct_get(a, mb_x, mb_y);
- encode_mb(a, a->block);
- }
- }
-
- if(a->mb_height2 != a->mb_height){
- mb_y= a->mb_height2;
- for(mb_x=0; mb_x<a->mb_width; mb_x++){
- dct_get(a, mb_x, mb_y);
- encode_mb(a, a->block);
- }
- }
- emms_c();
-
- align_put_bits(&a->pb);
- while(get_bit_count(&a->pb)&31)
- put_bits(&a->pb, 8, 0);
-
- size= get_bit_count(&a->pb)/32;
-
- if(avctx->codec_id == CODEC_ID_ASV1)
- a->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
- else{
- int i;
- for(i=0; i<4*size; i++)
- buf[i]= reverse[ buf[i] ];
- }
-
- return size*4;
-}
-
-static void common_init(AVCodecContext *avctx){
- ASV1Context * const a = avctx->priv_data;
-
- dsputil_init(&a->dsp, avctx);
-
- a->mb_width = (avctx->width + 15) / 16;
- a->mb_height = (avctx->height + 15) / 16;
- a->mb_width2 = (avctx->width + 0) / 16;
- a->mb_height2 = (avctx->height + 0) / 16;
-
- avctx->coded_frame= (AVFrame*)&a->picture;
- a->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
- ASV1Context * const a = avctx->priv_data;
- AVFrame *p= (AVFrame*)&a->picture;
- int i;
- const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
-
- common_init(avctx);
- init_vlcs(a);
- ff_init_scantable(a->dsp.idct_permutation, &a->scantable, scantab);
-
- a->inv_qscale= ((uint8_t*)avctx->extradata)[0];
- if(a->inv_qscale == 0){
- printf("illegal qscale 0\n");
- if(avctx->codec_id == CODEC_ID_ASV1)
- a->inv_qscale= 6;
- else
- a->inv_qscale= 10;
- }
-
- for(i=0; i<64; i++){
- int index= scantab[i];
-
- a->intra_matrix[i]= 64*scale*ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
- }
-
- p->qstride= a->mb_width;
- p->qscale_table= av_mallocz( p->qstride * a->mb_height);
- p->quality= (32*scale + a->inv_qscale/2)/a->inv_qscale;
- memset(p->qscale_table, p->quality, p->qstride*a->mb_height);
-
- return 0;
-}
-
-static int encode_init(AVCodecContext *avctx){
- ASV1Context * const a = avctx->priv_data;
- int i;
- const int scale= avctx->codec_id == CODEC_ID_ASV1 ? 1 : 2;
-
- common_init(avctx);
-
- if(avctx->global_quality == 0) avctx->global_quality= 4*FF_QUALITY_SCALE;
-
- a->inv_qscale= (32*scale*FF_QUALITY_SCALE + avctx->global_quality/2) / avctx->global_quality;
-
- avctx->extradata= av_mallocz(8);
- avctx->extradata_size=8;
- ((uint32_t*)avctx->extradata)[0]= le2me_32(a->inv_qscale);
- ((uint32_t*)avctx->extradata)[1]= le2me_32(ff_get_fourcc("ASUS"));
-
- for(i=0; i<64; i++){
- int q= 32*scale*ff_mpeg1_default_intra_matrix[i];
- a->q_intra_matrix[i]= ((a->inv_qscale<<16) + q/2) / q;
- }
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
- ASV1Context * const a = avctx->priv_data;
-
- av_freep(&a->bitstream_buffer);
- av_freep(&a->picture.qscale_table);
- a->bitstream_buffer_size=0;
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec asv1_decoder = {
- "asv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ASV1,
- sizeof(ASV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
-AVCodec asv2_decoder = {
- "asv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ASV2,
- sizeof(ASV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec asv1_encoder = {
- "asv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ASV1,
- sizeof(ASV1Context),
- encode_init,
- encode_frame,
- //encode_end,
-};
-
-AVCodec asv2_encoder = {
- "asv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ASV2,
- sizeof(ASV1Context),
- encode_init,
- encode_frame,
- //encode_end,
-};
-
-#endif //CONFIG_ENCODERS
+++ /dev/null
-/**
- * @file avcodec.c
- * avcodec.
- */
-
-#include "errno.h"
-#include "avcodec.h"
-
-#ifndef MKTAG
-#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
-#endif
-
-// private structure used to hide all internal memory allocations
-// and structures used for de/encoding - end user should
-// never see any complicated structure
-typedef struct private_handle
-{
- AVCodec* avcodec;
- AVCodecContext avcontext;
- struct private_handle* next;
- struct private_handle* prev;
-} private_handle_t;
-
-static private_handle_t* handle_first = 0;
-
-static AVCodec* avcodec_find_by_fcc(uint32_t fcc)
-{
- // translation table
- static const struct fcc_to_avcodecid {
- enum CodecID codec;
- uint32_t list[4]; // maybe we could map more fcc to same codec
- } lc[] = {
- { CODEC_ID_H263, { MKTAG('U', '2', '6', '3'), 0 } },
- { CODEC_ID_H263I, { MKTAG('I', '2', '6', '3'), 0 } },
- { CODEC_ID_MSMPEG4V3, { MKTAG('D', 'I', 'V', '3'), 0 } },
- { CODEC_ID_MPEG4, { MKTAG('D', 'I', 'V', 'X'), MKTAG('D', 'X', '5', '0'), 0 } },
- { CODEC_ID_MSMPEG4V2, { MKTAG('M', 'P', '4', '2'), 0 } },
- { CODEC_ID_MJPEG, { MKTAG('M', 'J', 'P', 'G'), 0 } },
- { CODEC_ID_MPEG1VIDEO, { MKTAG('P', 'I', 'M', '1'), 0 } },
- { CODEC_ID_AC3, { 0x2000, 0 } },
- { CODEC_ID_MP2, { 0x50, 0x55, 0 } },
- { CODEC_ID_FLV1, { MKTAG('F', 'L', 'V', '1'), 0 } },
-
- { CODEC_ID_NONE, {0}}
- };
- const struct fcc_to_avcodecid* c;
-
- for (c = lc; c->codec != CODEC_ID_NONE; c++)
- {
- int i = 0;
- while (c->list[i] != 0)
- if (c->list[i++] == fcc)
- return avcodec_find_decoder(c->codec);
- }
-
- return NULL;
-}
-
-static private_handle_t* create_handle(void)
-{
- private_handle_t* t = av_malloc(sizeof(private_handle_t));
- if (!t)
- return NULL;
- memset(t, 0, sizeof(*t));
-
- // register and fill
- if (!handle_first)
- {
- avcodec_init();
- avcodec_register_all();
- handle_first = t;
- }
- else
- {
- t->prev = handle_first->next;
- handle_first->next = t;
- t->next = handle_first;
- }
-
- return t;
-}
-
-static void destroy_handle(private_handle_t* handle)
-{
- if (handle)
- {
- if (handle->avcodec)
- {
- avcodec_close(&handle->avcontext);
- }
- av_free(handle);
-
- // count referencies
- }
-}
-
-int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout)
-{
- AVCodecContext* ctx = handle;
- switch (cmd)
- {
- case AVC_OPEN_BY_NAME:
- {
- // pin char* codec name
- private_handle_t* h = create_handle();
- (private_handle_t**)pout = h;
- if (!h)
- return -ENOMEM;
- if (!h->avcodec)
- {
- destroy_handle(h);
- (private_handle_t**)pout = NULL;
- return -1;// better error
- }
- return 0;
- }
- case AVC_OPEN_BY_CODEC_ID:
- {
- // pin uint32_t codec fourcc
- private_handle_t* h = create_handle();
- (private_handle_t**)pout = h;
- if (!h)
- return -ENOMEM;
-
- if (!h->avcodec)
- {
- destroy_handle(h);
- (private_handle_t**)pout = NULL;
- return -1;// better error
- }
- return 0;
- }
- case AVC_OPEN_BY_FOURCC:
- {
- // pin uint32_t codec fourcc
- private_handle_t* h = create_handle();
- (private_handle_t**)pout = h;
- if (!h)
- return -ENOMEM;
- h->avcodec = avcodec_find_by_fcc((uint32_t) pin);
- if (!h->avcodec)
- {
- destroy_handle(h);
- (private_handle_t**)pout = NULL;
- return -1;// better error
- }
- return 0;
- }
- case AVC_CLOSE:
- // uninit part
- // eventually close all allocated space if this was last
- // instance
- destroy_handle(handle);
- break;
-
- case AVC_FLUSH:
- break;
-
- case AVC_DECODE:
- break;
-
- case AVC_ENCODE:
- break;
-
- case AVC_GET_VERSION:
- (int*) pout = 500;
- default:
- return -1;
-
- }
- return 0;
-}
+++ /dev/null
-#ifndef AVCODEC_H
-#define AVCODEC_H
-
-/**
- * @file avcodec.h
- * external api header.
- */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "common.h"
-
-#define FFMPEG_VERSION_INT 0x000408
-#define FFMPEG_VERSION "0.4.8"
-#define LIBAVCODEC_BUILD 4680
-
-#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
-#define LIBAVCODEC_VERSION FFMPEG_VERSION
-
-#define AV_STRINGIFY(s) AV_TOSTRING(s)
-#define AV_TOSTRING(s) #s
-#define LIBAVCODEC_IDENT "FFmpeg" LIBAVCODEC_VERSION "b" AV_STRINGIFY(LIBAVCODEC_BUILD)
-
-enum CodecID {
- CODEC_ID_NONE,
- CODEC_ID_MPEG1VIDEO,
- CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */
- CODEC_ID_MPEG2VIDEO_XVMC,
- CODEC_ID_H263,
- CODEC_ID_RV10,
- CODEC_ID_MP2,
- CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
- CODEC_ID_VORBIS,
- CODEC_ID_AC3,
- CODEC_ID_MJPEG,
- CODEC_ID_MJPEGB,
- CODEC_ID_LJPEG,
- CODEC_ID_MPEG4,
- CODEC_ID_RAWVIDEO,
- CODEC_ID_MSMPEG4V1,
- CODEC_ID_MSMPEG4V2,
- CODEC_ID_MSMPEG4V3,
- CODEC_ID_WMV1,
- CODEC_ID_WMV2,
- CODEC_ID_H263P,
- CODEC_ID_H263I,
- CODEC_ID_FLV1,
- CODEC_ID_SVQ1,
- CODEC_ID_SVQ3,
- CODEC_ID_DVVIDEO,
- CODEC_ID_DVAUDIO,
- CODEC_ID_WMAV1,
- CODEC_ID_WMAV2,
- CODEC_ID_MACE3,
- CODEC_ID_MACE6,
- CODEC_ID_HUFFYUV,
- CODEC_ID_CYUV,
- CODEC_ID_H264,
- CODEC_ID_INDEO3,
- CODEC_ID_VP3,
- CODEC_ID_AAC,
- CODEC_ID_MPEG4AAC,
- CODEC_ID_ASV1,
- CODEC_ID_ASV2,
- CODEC_ID_FFV1,
- CODEC_ID_4XM,
- CODEC_ID_VCR1,
- CODEC_ID_CLJR,
- CODEC_ID_MDEC,
- CODEC_ID_ROQ,
- CODEC_ID_INTERPLAY_VIDEO,
- CODEC_ID_XAN_WC3,
- CODEC_ID_XAN_WC4,
-
- /* various pcm "codecs" */
- CODEC_ID_PCM_S16LE,
- CODEC_ID_PCM_S16BE,
- CODEC_ID_PCM_U16LE,
- CODEC_ID_PCM_U16BE,
- CODEC_ID_PCM_S8,
- CODEC_ID_PCM_U8,
- CODEC_ID_PCM_MULAW,
- CODEC_ID_PCM_ALAW,
-
- /* various adpcm codecs */
- CODEC_ID_ADPCM_IMA_QT,
- CODEC_ID_ADPCM_IMA_WAV,
- CODEC_ID_ADPCM_IMA_DK3,
- CODEC_ID_ADPCM_IMA_DK4,
- CODEC_ID_ADPCM_MS,
- CODEC_ID_ADPCM_4XM,
-
- /* AMR */
- CODEC_ID_AMR_NB,
- /* RealAudio codecs*/
- CODEC_ID_RA_144,
- CODEC_ID_RA_288,
-
- /* various DPCM codecs */
- CODEC_ID_ROQ_DPCM,
- CODEC_ID_INTERPLAY_DPCM,
- CODEC_ID_XAN_DPCM
-};
-
-/* CODEC_ID_MP3LAME is absolete */
-#define CODEC_ID_MP3LAME CODEC_ID_MP3
-
-enum CodecType {
- CODEC_TYPE_UNKNOWN = -1,
- CODEC_TYPE_VIDEO,
- CODEC_TYPE_AUDIO
-};
-
-/**
- * Pixel format. Notes:
- *
- * PIX_FMT_RGBA32 is handled in an endian-specific manner. A RGBA
- * color is put together as:
- * (A << 24) | (R << 16) | (G << 8) | B
- * This is stored as BGRA on little endian CPU architectures and ARGB on
- * big endian CPUs.
- *
- * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized
- * image data is stored in AVFrame.data[0]. The palette is transported in
- * AVFrame.data[1] and, is 1024 bytes long (256 4-byte entries) and is
- * formatted the same as in PIX_FMT_RGBA32 described above (i.e., it is
- * also endian-specific).
- */
-enum PixelFormat {
- PIX_FMT_YUV420P, ///< Planar YUV 4:2:0 (1 Cr & Cb sample per 2x2 Y samples)
- PIX_FMT_YUV422,
- PIX_FMT_RGB24, ///< Packed pixel, 3 bytes per pixel, RGBRGB...
- PIX_FMT_BGR24, ///< Packed pixel, 3 bytes per pixel, BGRBGR...
- PIX_FMT_YUV422P, ///< Planar YUV 4:2:2 (1 Cr & Cb sample per 2x1 Y samples)
- PIX_FMT_YUV444P, ///< Planar YUV 4:4:4 (1 Cr & Cb sample per 1x1 Y samples)
- PIX_FMT_RGBA32, ///< Packed pixel, 4 bytes per pixel, BGRABGRA..., stored in cpu endianness
- PIX_FMT_YUV410P, ///< Planar YUV 4:1:0 (1 Cr & Cb sample per 4x4 Y samples)
- PIX_FMT_YUV411P, ///< Planar YUV 4:1:1 (1 Cr & Cb sample per 4x1 Y samples)
- PIX_FMT_RGB565, ///< always stored in cpu endianness
- PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
- PIX_FMT_GRAY8,
- PIX_FMT_MONOWHITE, ///< 0 is white
- PIX_FMT_MONOBLACK, ///< 0 is black
- PIX_FMT_PAL8, ///< 8 bit with RGBA palette
- PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0 full scale (jpeg)
- PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2 full scale (jpeg)
- PIX_FMT_YUVJ444P, ///< Planar YUV 4:4:4 full scale (jpeg)
- PIX_FMT_XVMC_MPEG2_MC,///< XVideo Motion Acceleration via common packet passing(xvmc_render.h)
- PIX_FMT_XVMC_MPEG2_IDCT,
- PIX_FMT_NB
-};
-
-/* currently unused, may be used if 24/32 bits samples ever supported */
-enum SampleFormat {
- SAMPLE_FMT_S16 = 0 ///< signed 16 bits
-};
-
-/* in bytes */
-#define AVCODEC_MAX_AUDIO_FRAME_SIZE 131072
-
-/**
- * Required number of additionally allocated bytes at the end of the input bitstream for decoding.
- * this is mainly needed because some optimized bitstream readers read
- * 32 or 64 bit at once and could read over the end<br>
- * Note, if the first 23 bits of the additional bytes are not 0 then damaged
- * MPEG bitstreams could cause overread and segfault
- */
-#define FF_INPUT_BUFFER_PADDING_SIZE 8
-
-/* motion estimation type, EPZS by default */
-enum Motion_Est_ID {
- ME_ZERO = 1,
- ME_FULL,
- ME_LOG,
- ME_PHODS,
- ME_EPZS,
- ME_X1
-};
-
-typedef struct RcOverride{
- int start_frame;
- int end_frame;
- int qscale; // if this is 0 then quality_factor will be used instead
- float quality_factor;
-} RcOverride;
-
-/* only for ME compatiblity with old apps */
-extern int motion_estimation_method;
-
-/* ME algos sorted by quality */
-static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
- ME_X1, ME_EPZS, ME_FULL };
-
-
-#define FF_MAX_B_FRAMES 8
-
-/* encoding support
- these flags can be passed in AVCodecContext.flags before initing
- Note: note not everything is supported yet
-*/
-
-#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale
-#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed
-#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC
-#define CODEC_FLAG_GMC 0x0020 ///< use GMC
-#define CODEC_FLAG_PART 0x0080 ///< use data partitioning
-/* parent program gurantees that the input for b-frame containing streams is not written to
- for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */
-#define CODEC_FLAG_INPUT_PRESERVED 0x0100
-#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode
-#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode
-#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg)
-#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale
-#define CODEC_FLAG_EMU_EDGE 0x4000///< dont draw edges
-#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding
-#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead
- of only at frame boundaries */
-#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization
-#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct
-#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay
-#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan
-#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization
-#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe
-#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct)
-/* Fx : Flag for h263+ extra options */
-#define CODEC_FLAG_H263P_AIC 0x01000000 ///< Advanced intra coding
-#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector
-/* For advanced prediction mode, we reuse the 4MV flag */
-/* Unsupported options :
- * Syntax Arithmetic coding (SAC)
- * Deblocking filter internal loop
- * Slice structured
- * Reference Picture Selection
- * Independant Segment Decoding
- * Alternative Inter * VLC
- * Modified Quantization */
-/* /Fx */
-/* codec capabilities */
-
-#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback
-/**
- * Codec uses get_buffer() for allocating buffers.
- * direct rendering method 1
- */
-#define CODEC_CAP_DR1 0x0002
-/* if 'parse_only' field is true, then avcodec_parse_frame() can be
- used */
-#define CODEC_CAP_PARSE_ONLY 0x0004
-#define CODEC_CAP_TRUNCATED 0x0008
-
-#define FF_COMMON_FRAME \
- /**\
- * pointer to the picture planes.\
- * this might be different from the first allocated byte\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *data[4];\
- int linesize[4];\
- /**\
- * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\
- * this isnt used by lavc unless the default get/release_buffer() is used\
- * - encoding: \
- * - decoding: \
- */\
- uint8_t *base[4];\
- /**\
- * 1 -> keyframe, 0-> not\
- * - encoding: set by lavc\
- * - decoding: set by lavc\
- */\
- int key_frame;\
-\
- /**\
- * picture type of the frame, see ?_TYPE below.\
- * - encoding: set by lavc for coded_picture (and set by user for input)\
- * - decoding: set by lavc\
- */\
- int pict_type;\
-\
- /**\
- * presentation timestamp in micro seconds (time when frame should be shown to user)\
- * if 0 then the frame_rate will be used as reference\
- * - encoding: MUST be set by user\
- * - decoding: set by lavc\
- */\
- int64_t pts;\
-\
- /**\
- * picture number in bitstream order.\
- * - encoding: set by\
- * - decoding: set by lavc\
- */\
- int coded_picture_number;\
- /**\
- * picture number in display order.\
- * - encoding: set by\
- * - decoding: set by lavc\
- */\
- int display_picture_number;\
-\
- /**\
- * quality (between 1 (good) and 31 (bad)) \
- * - encoding: set by lavc for coded_picture (and set by user for input)\
- * - decoding: set by lavc\
- */\
- float quality; \
-\
- /**\
- * buffer age (1->was last buffer and dint change, 2->..., ...).\
- * set to something large if the buffer has not been used yet \
- * - encoding: unused\
- * - decoding: MUST be set by get_buffer()\
- */\
- int age;\
-\
- /**\
- * is this picture used as reference\
- * - encoding: unused\
- * - decoding: set by lavc (before get_buffer() call))\
- */\
- int reference;\
-\
- /**\
- * QP table\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int8_t *qscale_table;\
- /**\
- * QP store stride\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int qstride;\
-\
- /**\
- * mbskip_table[mb]>=1 if MB didnt change\
- * stride= mb_width = (width+15)>>4\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- uint8_t *mbskip_table;\
-\
- /**\
- * for some private data of the user\
- * - encoding: unused\
- * - decoding: set by user\
- */\
- void *opaque;\
-\
- /**\
- * error\
- * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\
- * - decoding: unused\
- */\
- uint64_t error[4];\
-\
- /**\
- * type of the buffer (to keep track of who has to dealloc data[*])\
- * - encoding: set by the one who allocs it\
- * - decoding: set by the one who allocs it\
- * Note: user allocated (direct rendering) & internal buffers can not coexist currently\
- */\
- int type;\
- \
- /**\
- * when decoding, this signal how much the picture must be delayed.\
- * extra_delay = repeat_pict / (2*fps)\
- * - encoding: unused\
- * - decoding: set by lavc\
- */\
- int repeat_pict;\
- \
- /**\
- * \
- */\
- int qscale_type;\
-
-#define FF_QSCALE_TYPE_MPEG1 0
-#define FF_QSCALE_TYPE_MPEG2 1
-
-#define FF_BUFFER_TYPE_INTERNAL 1
-#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user)
-#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc image (data/base)
-#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, dont dealloc anything
-
-
-#define FF_I_TYPE 1 // Intra
-#define FF_P_TYPE 2 // Predicted
-#define FF_B_TYPE 3 // Bi-dir predicted
-#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4
-#define FF_SI_TYPE 5
-#define FF_SP_TYPE 6
-
-/**
- * Audio Video Frame.
- */
-typedef struct AVFrame {
- FF_COMMON_FRAME
-} AVFrame;
-
-#define DEFAULT_FRAME_RATE_BASE 1001000
-
-/**
- * main external api structure.
- */
-typedef struct AVCodecContext {
- /**
- * the average bitrate.
- * - encoding: set by user. unused for constant quantizer encoding
- * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
- */
- int bit_rate;
-
- /**
- * number of bits the bitstream is allowed to diverge from the reference.
- * the reference can be CBR (for CBR pass1) or VBR (for pass2)
- * - encoding: set by user. unused for constant quantizer encoding
- * - decoding: unused
- */
- int bit_rate_tolerance;
-
- /**
- * CODEC_FLAG_*.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int flags;
-
- /**
- * some codecs needs additionnal format info. It is stored here
- * - encoding: set by user.
- * - decoding: set by lavc. (FIXME is this ok?)
- */
- int sub_id;
-
- /**
- * motion estimation algorithm used for video coding.
- * - encoding: MUST be set by user.
- * - decoding: unused
- */
- int me_method;
-
- /**
- * some codecs need / can use extra-data like huffman tables.
- * mjpeg: huffman tables
- * rv10: additional flags
- * mpeg4: global headers (they can be in the bitstream or here)
- * - encoding: set/allocated/freed by lavc.
- * - decoding: set/allocated/freed by user.
- */
- void *extradata;
- int extradata_size;
-
- /* video only */
- /**
- * frames per sec multiplied by frame_rate_base.
- * for variable fps this is the precission, so if the timestamps
- * can be specified in msec precssion then this is 1000*frame_rate_base
- * - encoding: MUST be set by user
- * - decoding: set by lavc. 0 or the frame_rate if available
- */
- int frame_rate;
-
- /**
- * width / height.
- * - encoding: MUST be set by user.
- * - decoding: set by user, some codecs might override / change it during playback
- */
- int width, height;
-
-#define FF_ASPECT_SQUARE 1
-#define FF_ASPECT_4_3_625 2
-#define FF_ASPECT_4_3_525 3
-#define FF_ASPECT_16_9_625 4
-#define FF_ASPECT_16_9_525 5
-#define FF_ASPECT_EXTENDED 15
-
- /**
- * the number of pictures in a group of pitures, or 0 for intra_only.
- * - encoding: set by user.
- * - decoding: unused
- */
- int gop_size;
-
- /**
- * pixel format, see PIX_FMT_xxx.
- * - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt
- * conversion is in order. This only works for
- * codecs with one supported pix_fmt, we should
- * do something for a generic case as well.
- * - decoding: set by lavc.
- */
- enum PixelFormat pix_fmt;
-
- /**
- * Frame rate emulation. If not zero lower layer (i.e. format handler)
- * has to read frames at native frame rate.
- * - encoding: set by user.
- * - decoding: unused.
- */
- int rate_emu;
-
- /**
- * if non NULL, 'draw_horiz_band' is called by the libavcodec
- * decoder to draw an horizontal band. It improve cache usage. Not
- * all codecs can do that. You must check the codec capabilities
- * before
- * - encoding: unused
- * - decoding: set by user.
- * @param height the height of the slice
- * @param y the y position of the slice
- * @param type 1->top field, 2->bottom field, 3->frame
- * @param offset offset into the AVFrame.data from which the slice should be read
- */
- void (*draw_horiz_band)(struct AVCodecContext *s,
- AVFrame *src, int offset[4],
- int y, int type, int height);
-
- /* audio only */
- int sample_rate; ///< samples per sec
- int channels;
- int sample_fmt; ///< sample format, currenly unused
-
- /* the following data should not be initialized */
- int frame_size; ///< in samples, initialized when calling 'init'
- int frame_number; ///< audio or video frame number
- int real_pict_num; ///< returns the real picture number of previous encoded frame
-
- /**
- * number of frames the decoded output will be delayed relative to
- * the encoded input.
- * - encoding: set by lavc.
- * - decoding: unused
- */
- int delay;
-
- /* - encoding parameters */
- float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
- float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
-
- /**
- * minimum quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int qmin;
-
- /**
- * maximum quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int qmax;
-
- /**
- * maximum quantizer difference etween frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- int max_qdiff;
-
- /**
- * maximum number of b frames between non b frames.
- * note: the output will be delayed by max_b_frames+1 relative to the input
- * - encoding: set by user.
- * - decoding: unused
- */
- int max_b_frames;
-
- /**
- * qscale factor between ip and b frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- float b_quant_factor;
-
- /** obsolete FIXME remove */
- int rc_strategy;
- int b_frame_strategy;
-
- /**
- * hurry up amount.
- * - encoding: unused
- * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header
- */
- int hurry_up;
-
- struct AVCodec *codec;
-
- void *priv_data;
-
- /* The following data is for RTP friendly coding */
- /* By now only H.263/H.263+/MPEG4 coder honours this */
- int rtp_mode; /* 1 for activate RTP friendly-mode */
- /* highers numbers represent more error-prone */
- /* enviroments, by now just "1" exist */
-
- int rtp_payload_size; /* The size of the RTP payload, the coder will */
- /* do it's best to deliver a chunk with size */
- /* below rtp_payload_size, the chunk will start */
- /* with a start code on some codecs like H.263 */
- /* This doesn't take account of any particular */
- /* headers inside the transmited RTP payload */
-
-
- /* The RTP callcack: This function is called */
- /* every time the encoder as a packet to send */
- /* Depends on the encoder if the data starts */
- /* with a Start Code (it should) H.263 does */
- void (*rtp_callback)(void *data, int size, int packet_number);
-
- /* statistics, used for 2-pass encoding */
- int mv_bits;
- int header_bits;
- int i_tex_bits;
- int p_tex_bits;
- int i_count;
- int p_count;
- int skip_count;
- int misc_bits;
-
- /**
- * number of bits used for the previously encoded frame.
- * - encoding: set by lavc
- * - decoding: unused
- */
- int frame_bits;
-
- /**
- * private data of the user, can be used to carry app specific stuff.
- * - encoding: set by user
- * - decoding: set by user
- */
- void *opaque;
-
- char codec_name[32];
- enum CodecType codec_type; /* see CODEC_TYPE_xxx */
- enum CodecID codec_id; /* see CODEC_ID_xxx */
-
- /**
- * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
- * this is used to workaround some encoder bugs
- * - encoding: set by user, if not then the default based on codec_id will be used
- * - decoding: set by user, will be converted to upper case by lavc during init
- */
- unsigned int codec_tag;
-
- /**
- * workaround bugs in encoders which sometimes cannot be detected automatically.
- * - encoding: unused
- * - decoding: set by user
- */
- int workaround_bugs;
-#define FF_BUG_AUTODETECT 1 ///< autodetection
-#define FF_BUG_OLD_MSMPEG4 2
-#define FF_BUG_XVID_ILACE 4
-#define FF_BUG_UMP4 8
-#define FF_BUG_NO_PADDING 16
-#define FF_BUG_AC_VLC 32
-#define FF_BUG_QPEL_CHROMA 64
-#define FF_BUG_STD_QPEL 128
-#define FF_BUG_QPEL_CHROMA2 256
-#define FF_BUG_DIRECT_BLOCKSIZE 512
-#define FF_BUG_EDGE 1024
-//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100%
-
- /**
- * luma single coeff elimination threshold.
- * - encoding: set by user
- * - decoding: unused
- */
- int luma_elim_threshold;
-
- /**
- * chroma single coeff elimination threshold.
- * - encoding: set by user
- * - decoding: unused
- */
- int chroma_elim_threshold;
-
- /**
- * strictly follow the std (MPEG4, ...).
- * - encoding: set by user
- * - decoding: unused
- */
- int strict_std_compliance;
-
- /**
- * qscale offset between ip and b frames.
- * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
- * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
- * - encoding: set by user.
- * - decoding: unused
- */
- float b_quant_offset;
-
- /**
- * error resilience higher values will detect more errors but may missdetect
- * some more or less valid parts as errors.
- * - encoding: unused
- * - decoding: set by user
- */
- int error_resilience;
-#define FF_ER_CAREFULL 1
-#define FF_ER_COMPLIANT 2
-#define FF_ER_AGGRESSIVE 3
-#define FF_ER_VERY_AGGRESSIVE 4
-
- /**
- * called at the beginning of each frame to get a buffer for it.
- * if pic.reference is set then the frame will be read later by lavc
- * width and height should be rounded up to the next multiple of 16
- * - encoding: unused
- * - decoding: set by lavc, user can override
- */
- int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic);
-
- /**
- * called to release buffers which where allocated with get_buffer.
- * a released buffer can be reused in get_buffer()
- * pic.data[*] must be set to NULL
- * - encoding: unused
- * - decoding: set by lavc, user can override
- */
- void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic);
-
- /**
- * is 1 if the decoded stream contains b frames, 0 otherwise.
- * - encoding: unused
- * - decoding: set by lavc
- */
- int has_b_frames;
-
- int block_align; ///< used by some WAV based audio codecs
-
- int parse_only; /* - decoding only: if true, only parsing is done
- (function avcodec_parse_frame()). The frame
- data is returned. Only MPEG codecs support this now. */
-
- /**
- * 0-> h263 quant 1-> mpeg quant.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mpeg_quant;
-
- /**
- * pass1 encoding statistics output buffer.
- * - encoding: set by lavc
- * - decoding: unused
- */
- char *stats_out;
-
- /**
- * pass2 encoding statistics input buffer.
- * concatenated stuff from stats_out of pass1 should be placed here
- * - encoding: allocated/set/freed by user
- * - decoding: unused
- */
- char *stats_in;
-
- /**
- * ratecontrol qmin qmax limiting method.
- * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax
- * - encoding: set by user.
- * - decoding: unused
- */
- float rc_qsquish;
-
- float rc_qmod_amp;
- int rc_qmod_freq;
-
- /**
- * ratecontrol override, see RcOverride.
- * - encoding: allocated/set/freed by user.
- * - decoding: unused
- */
- RcOverride *rc_override;
- int rc_override_count;
-
- /**
- * rate control equation.
- * - encoding: set by user
- * - decoding: unused
- */
- char *rc_eq;
-
- /**
- * maximum bitrate.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_max_rate;
-
- /**
- * minimum bitrate.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_min_rate;
-
- /**
- * decoder bitstream buffer size.
- * - encoding: set by user.
- * - decoding: unused
- */
- int rc_buffer_size;
- float rc_buffer_aggressivity;
-
- /**
- * qscale factor between p and i frames.
- * - encoding: set by user.
- * - decoding: unused
- */
- float i_quant_factor;
-
- /**
- * qscale offset between p and i frames.
- * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset)
- * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset)
- * - encoding: set by user.
- * - decoding: unused
- */
- float i_quant_offset;
-
- /**
- * initial complexity for pass1 ratecontrol.
- * - encoding: set by user.
- * - decoding: unused
- */
- float rc_initial_cplx;
-
- /**
- * dct algorithm, see FF_DCT_* below.
- * - encoding: set by user
- * - decoding: unused
- */
- int dct_algo;
-#define FF_DCT_AUTO 0
-#define FF_DCT_FASTINT 1
-#define FF_DCT_INT 2
-#define FF_DCT_MMX 3
-#define FF_DCT_MLIB 4
-#define FF_DCT_ALTIVEC 5
-
- /**
- * luminance masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float lumi_masking;
-
- /**
- * temporary complexity masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float temporal_cplx_masking;
-
- /**
- * spatial complexity masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float spatial_cplx_masking;
-
- /**
- * p block masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float p_masking;
-
- /**
- * darkness masking (0-> disabled).
- * - encoding: set by user
- * - decoding: unused
- */
- float dark_masking;
-
-
- /* for binary compatibility */
- int unused;
-
- /**
- * idct algorithm, see FF_IDCT_* below.
- * - encoding: set by user
- * - decoding: set by user
- */
- int idct_algo;
-#define FF_IDCT_AUTO 0
-#define FF_IDCT_INT 1
-#define FF_IDCT_SIMPLE 2
-#define FF_IDCT_SIMPLEMMX 3
-#define FF_IDCT_LIBMPEG2MMX 4
-#define FF_IDCT_PS2 5
-#define FF_IDCT_MLIB 6
-#define FF_IDCT_ARM 7
-#define FF_IDCT_ALTIVEC 8
-#define FF_IDCT_SH4 9
-#define FF_IDCT_SIMPLEARM 10
-
- /**
- * slice count.
- * - encoding: set by lavc
- * - decoding: set by user (or 0)
- */
- int slice_count;
- /**
- * slice offsets in the frame in bytes.
- * - encoding: set/allocated by lavc
- * - decoding: set/allocated by user (or NULL)
- */
- int *slice_offset;
-
- /**
- * error concealment flags.
- * - encoding: unused
- * - decoding: set by user
- */
- int error_concealment;
-#define FF_EC_GUESS_MVS 1
-#define FF_EC_DEBLOCK 2
-
- /**
- * dsp_mask could be add used to disable unwanted CPU features
- * CPU features (i.e. MMX, SSE. ...)
- *
- * with FORCE flag you may instead enable given CPU features
- * (Dangerous: usable in case of misdetection, improper usage however will
- * result into program crash)
- */
- unsigned dsp_mask;
-#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */
- /* lower 16 bits - CPU features */
-#ifdef HAVE_MMX
-#define FF_MM_MMX 0x0001 /* standard MMX */
-#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */
-#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
-#define FF_MM_SSE 0x0008 /* SSE functions */
-#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */
-#endif /* HAVE_MMX */
-
- /**
- * bits per sample/pixel from the demuxer (needed for huffyuv).
- * - encoding: set by lavc
- * - decoding: set by user
- */
- int bits_per_sample;
-
- /**
- * prediction method (needed for huffyuv).
- * - encoding: set by user
- * - decoding: unused
- */
- int prediction_method;
-#define FF_PRED_LEFT 0
-#define FF_PRED_PLANE 1
-#define FF_PRED_MEDIAN 2
-
- /**
- * aspect ratio (0 if unknown).
- * - encoding: set by user.
- * - decoding: set by lavc.
- */
- float aspect_ratio;
-
- /**
- * the picture in the bitstream.
- * - encoding: set by lavc
- * - decoding: set by lavc
- */
- AVFrame *coded_frame;
-
- /**
- * debug.
- * - encoding: set by user.
- * - decoding: set by user.
- */
- int debug;
-#define FF_DEBUG_PICT_INFO 1
-#define FF_DEBUG_RC 2
-#define FF_DEBUG_BITSTREAM 4
-#define FF_DEBUG_MB_TYPE 8
-#define FF_DEBUG_QP 16
-#define FF_DEBUG_MV 32
-#define FF_DEBUG_VIS_MV 0x00000040
-#define FF_DEBUG_SKIP 0x00000080
-#define FF_DEBUG_STARTCODE 0x00000100
-#define FF_DEBUG_PTS 0x00000200
-#define FF_DEBUG_ER 0x00000400
-#define FF_DEBUG_MMCO 0x00000800
-#define FF_DEBUG_BUGS 0x00001000
-
- /**
- * error.
- * - encoding: set by lavc if flags&CODEC_FLAG_PSNR
- * - decoding: unused
- */
- uint64_t error[4];
-
- /**
- * minimum MB quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_qmin;
-
- /**
- * maximum MB quantizer.
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_qmax;
-
- /**
- * motion estimation compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_cmp;
- /**
- * subpixel motion estimation compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_sub_cmp;
- /**
- * macroblock compare function (not supported yet).
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_cmp;
-#define FF_CMP_SAD 0
-#define FF_CMP_SSE 1
-#define FF_CMP_SATD 2
-#define FF_CMP_DCT 3
-#define FF_CMP_PSNR 4
-#define FF_CMP_BIT 5
-#define FF_CMP_RD 6
-#define FF_CMP_ZERO 7
-#define FF_CMP_CHROMA 256
-
- /**
- * ME diamond size & shape.
- * - encoding: set by user.
- * - decoding: unused
- */
- int dia_size;
-
- /**
- * amount of previous MV predictors (2a+1 x 2a+1 square).
- * - encoding: set by user.
- * - decoding: unused
- */
- int last_predictor_count;
-
- /**
- * pre pass for motion estimation.
- * - encoding: set by user.
- * - decoding: unused
- */
- int pre_me;
-
- /**
- * motion estimation pre pass compare function.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_pre_cmp;
-
- /**
- * ME pre pass diamond size & shape.
- * - encoding: set by user.
- * - decoding: unused
- */
- int pre_dia_size;
-
- /**
- * subpel ME quality.
- * - encoding: set by user.
- * - decoding: unused
- */
- int me_subpel_quality;
-
- /**
- * callback to negotiate the pixelFormat.
- * @param fmt is the list of formats which are supported by the codec,
- * its terminated by -1 as 0 is a valid format, the formats are ordered by quality
- * the first is allways the native one
- * @return the choosen format
- * - encoding: unused
- * - decoding: set by user, if not set then the native format will always be choosen
- */
- enum PixelFormat (*get_format)(struct AVCodecContext *s, enum PixelFormat * fmt);
-
- /**
- * DTG active format information (additionnal aspect ratio
- * information only used in DVB MPEG2 transport streams). 0 if
- * not set.
- *
- * - encoding: unused.
- * - decoding: set by decoder
- */
- int dtg_active_format;
-#define FF_DTG_AFD_SAME 8
-#define FF_DTG_AFD_4_3 9
-#define FF_DTG_AFD_16_9 10
-#define FF_DTG_AFD_14_9 11
-#define FF_DTG_AFD_4_3_SP_14_9 13
-#define FF_DTG_AFD_16_9_SP_14_9 14
-#define FF_DTG_AFD_SP_4_3 15
-
- /**
- * Maximum motion estimation search range in subpel units.
- * if 0 then no limit
- *
- * - encoding: set by user.
- * - decoding: unused.
- */
- int me_range;
-
- /**
- * frame_rate_base.
- * for variable fps this is 1
- * - encoding: set by user.
- * - decoding: set by lavc.
- * @todo move this after frame_rate
- */
-
- int frame_rate_base;
- /**
- * intra quantizer bias.
- * - encoding: set by user.
- * - decoding: unused
- */
- int intra_quant_bias;
-#define FF_DEFAULT_QUANT_BIAS 999999
-
- /**
- * inter quantizer bias.
- * - encoding: set by user.
- * - decoding: unused
- */
- int inter_quant_bias;
-
- /**
- * color table ID.
- * - encoding: unused.
- * - decoding: which clrtable should be used for 8bit RGB images
- * table have to be stored somewhere FIXME
- */
- int color_table_id;
-
- /**
- * internal_buffer count.
- * Dont touch, used by lavc default_get_buffer()
- */
- int internal_buffer_count;
-
- /**
- * internal_buffers.
- * Dont touch, used by lavc default_get_buffer()
- */
- void *internal_buffer;
-
-#define FF_QUALITY_SCALE 256
- /**
- * global quality for codecs which cannot change it per frame.
- * this should be proportional to MPEG1/2/4 qscale.
- * - encoding: set by user.
- * - decoding: unused
- */
- int global_quality;
-
-#define FF_CODER_TYPE_VLC 0
-#define FF_CODER_TYPE_AC 1
- /**
- * coder type
- * - encoding: set by user.
- * - decoding: unused
- */
- int coder_type;
-
- /**
- * context model
- * - encoding: set by user.
- * - decoding: unused
- */
- int context_model;
-
- /**
- * slice flags
- * - encoding: unused
- * - decoding: set by user.
- */
- int slice_flags;
-#define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display
-#define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics)
-#define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1)
-
- /**
- * XVideo Motion Acceleration
- * - encoding: forbidden
- * - decoding: set by decoder
- */
- int xvmc_acceleration;
-
- /**
- * macroblock decision mode
- * - encoding: set by user.
- * - decoding: unused
- */
- int mb_decision;
-#define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp
-#define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits
-#define FF_MB_DECISION_RD 2 ///< rate distoration
-
- /**
- * custom intra quantization matrix
- * - encoding: set by user, can be NULL
- * - decoding: set by lavc
- */
- uint16_t *intra_matrix;
-
- /**
- * custom inter quantization matrix
- * - encoding: set by user, can be NULL
- * - decoding: set by lavc
- */
- uint16_t *inter_matrix;
-
- /**
- * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
- * this is used to workaround some encoder bugs
- * - encoding: unused
- * - decoding: set by user, will be converted to upper case by lavc during init
- */
- unsigned int stream_codec_tag;
-
- /**
- * scene change detection threshold.
- * 0 is default, larger means fewer detected scene changes
- * - encoding: set by user.
- * - decoding: unused
- */
- int scenechange_threshold;
-} AVCodecContext;
-
-
-/**
- * AVOption.
- */
-typedef struct AVOption {
- /** options' name */
- const char *name; /* if name is NULL, it indicates a link to next */
- /** short English text help or const struct AVOption* subpointer */
- const char *help; // const struct AVOption* sub;
- /** offset to context structure where the parsed value should be stored */
- int offset;
- /** options' type */
- int type;
-#define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
-#define FF_OPT_TYPE_DOUBLE 2 ///< double
-#define FF_OPT_TYPE_INT 3 ///< integer
-#define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
-#define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
-//#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
-#define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
-#define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
- /** min value (min == max -> no limits) */
- double min;
- /** maximum value for double/int */
- double max;
- /** default boo [0,1]l/double/int value */
- double defval;
- /**
- * default string value (with optional semicolon delimited extra option-list
- * i.e. option1;option2;option3
- * defval might select other then first argument as default
- */
- const char *defstr;
-#define FF_OPT_MAX_DEPTH 10
-} AVOption;
-
-/**
- * Parse option(s) and sets fields in passed structure
- * @param strct structure where the parsed results will be written
- * @param list list with AVOptions
- * @param opts string with options for parsing
- */
-int avoption_parse(void* strct, const AVOption* list, const char* opts);
-
-
-/**
- * AVCodec.
- */
-typedef struct AVCodec {
- const char *name;
- enum CodecType type;
- int id;
- int priv_data_size;
- int (*init)(AVCodecContext *);
- int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data);
- int (*close)(AVCodecContext *);
- int (*decode)(AVCodecContext *, void *outdata, int *outdata_size,
- uint8_t *buf, int buf_size);
- int capabilities;
- const AVOption *options;
- struct AVCodec *next;
- void (*flush)(AVCodecContext *);
-} AVCodec;
-
-/**
- * four components are given, that's all.
- * the last component is alpha
- */
-typedef struct AVPicture {
- uint8_t *data[4];
- int linesize[4]; ///< number of bytes per line
-} AVPicture;
-
-/**
- * AVPaletteControl
- * This structure defines a method for communicating palette changes
- * between and demuxer and a decoder.
- */
-typedef struct AVPaletteControl {
-
- /* demuxer sets this to 1 to indicate the palette has changed;
- * decoder resets to 0 */
- int palette_changed;
-
- /* 256 3-byte RGB palette entries; the components should be
- * formatted in the buffer as "RGBRGB..." and should be scaled to
- * 8 bits if they originally represented 6-bit VGA palette
- * components */
- unsigned char palette[256 * 3];
-
-} AVPaletteControl;
-
-extern AVCodec ac3_encoder;
-extern AVCodec mp2_encoder;
-extern AVCodec mp3lame_encoder;
-extern AVCodec oggvorbis_encoder;
-extern AVCodec mpeg1video_encoder;
-extern AVCodec mpeg2video_encoder;
-extern AVCodec h263_encoder;
-extern AVCodec h263p_encoder;
-extern AVCodec flv_encoder;
-extern AVCodec rv10_encoder;
-extern AVCodec mjpeg_encoder;
-extern AVCodec ljpeg_encoder;
-extern AVCodec mpeg4_encoder;
-extern AVCodec msmpeg4v1_encoder;
-extern AVCodec msmpeg4v2_encoder;
-extern AVCodec msmpeg4v3_encoder;
-extern AVCodec wmv1_encoder;
-extern AVCodec wmv2_encoder;
-extern AVCodec huffyuv_encoder;
-extern AVCodec h264_encoder;
-extern AVCodec asv1_encoder;
-extern AVCodec asv2_encoder;
-extern AVCodec vcr1_encoder;
-extern AVCodec ffv1_encoder;
-extern AVCodec mdec_encoder;
-
-extern AVCodec h263_decoder;
-extern AVCodec mpeg4_decoder;
-extern AVCodec msmpeg4v1_decoder;
-extern AVCodec msmpeg4v2_decoder;
-extern AVCodec msmpeg4v3_decoder;
-extern AVCodec wmv1_decoder;
-extern AVCodec wmv2_decoder;
-extern AVCodec mpeg1video_decoder;
-extern AVCodec mpeg2video_decoder;
-extern AVCodec mpeg_xvmc_decoder;
-extern AVCodec h263i_decoder;
-extern AVCodec flv_decoder;
-extern AVCodec rv10_decoder;
-extern AVCodec svq1_decoder;
-extern AVCodec svq3_decoder;
-extern AVCodec dvvideo_decoder;
-extern AVCodec dvaudio_decoder;
-extern AVCodec wmav1_decoder;
-extern AVCodec wmav2_decoder;
-extern AVCodec mjpeg_decoder;
-extern AVCodec mjpegb_decoder;
-extern AVCodec mp2_decoder;
-extern AVCodec mp3_decoder;
-extern AVCodec mace3_decoder;
-extern AVCodec mace6_decoder;
-extern AVCodec huffyuv_decoder;
-extern AVCodec oggvorbis_decoder;
-extern AVCodec cyuv_decoder;
-extern AVCodec h264_decoder;
-extern AVCodec indeo3_decoder;
-extern AVCodec vp3_decoder;
-extern AVCodec amr_nb_decoder;
-extern AVCodec amr_nb_encoder;
-extern AVCodec aac_decoder;
-extern AVCodec mpeg4aac_decoder;
-extern AVCodec asv1_decoder;
-extern AVCodec asv2_decoder;
-extern AVCodec vcr1_decoder;
-extern AVCodec cljr_decoder;
-extern AVCodec ffv1_decoder;
-extern AVCodec fourxm_decoder;
-extern AVCodec mdec_decoder;
-extern AVCodec roq_decoder;
-extern AVCodec interplay_video_decoder;
-extern AVCodec xan_wc3_decoder;
-extern AVCodec ra_144_decoder;
-extern AVCodec ra_288_decoder;
-extern AVCodec roq_dpcm_decoder;
-extern AVCodec interplay_dpcm_decoder;
-extern AVCodec xan_dpcm_decoder;
-
-/* pcm codecs */
-#define PCM_CODEC(id, name) \
-extern AVCodec name ## _decoder; \
-extern AVCodec name ## _encoder
-
-PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
-PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
-PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
-PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
-PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
-PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
-PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
-PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
-
-/* adpcm codecs */
-
-PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3);
-PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4);
-PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms);
-PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm);
-
-#undef PCM_CODEC
-
-/* dummy raw video codec */
-extern AVCodec rawvideo_encoder;
-extern AVCodec rawvideo_decoder;
-
-/* the following codecs use external GPL libs */
-extern AVCodec ac3_decoder;
-
-/* resample.c */
-
-struct ReSampleContext;
-
-typedef struct ReSampleContext ReSampleContext;
-
-ReSampleContext *audio_resample_init(int output_channels, int input_channels,
- int output_rate, int input_rate);
-int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples);
-void audio_resample_close(ReSampleContext *s);
-
-/* YUV420 format is assumed ! */
-
-struct ImgReSampleContext;
-
-typedef struct ImgReSampleContext ImgReSampleContext;
-
-ImgReSampleContext *img_resample_init(int output_width, int output_height,
- int input_width, int input_height);
-
-ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
- int iwidth, int iheight,
- int topBand, int bottomBand,
- int leftBand, int rightBand);
-
-void img_resample(ImgReSampleContext *s,
- AVPicture *output, AVPicture *input);
-
-void img_resample_close(ImgReSampleContext *s);
-
-int avpicture_fill(AVPicture *picture, uint8_t *ptr,
- int pix_fmt, int width, int height);
-int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
- unsigned char *dest, int dest_size);
-int avpicture_get_size(int pix_fmt, int width, int height);
-void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift);
-const char *avcodec_get_pix_fmt_name(int pix_fmt);
-enum PixelFormat avcodec_get_pix_fmt(const char* name);
-
-#define FF_LOSS_RESOLUTION 0x0001 /* loss due to resolution change */
-#define FF_LOSS_DEPTH 0x0002 /* loss due to color depth change */
-#define FF_LOSS_COLORSPACE 0x0004 /* loss due to color space conversion */
-#define FF_LOSS_ALPHA 0x0008 /* loss of alpha bits */
-#define FF_LOSS_COLORQUANT 0x0010 /* loss due to color quantization */
-#define FF_LOSS_CHROMA 0x0020 /* loss of chroma (e.g. rgb to gray conversion) */
-
-int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
- int has_alpha);
-int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
- int has_alpha, int *loss_ptr);
-
-#define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */
-#define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */
-int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height);
-
-/* convert among pixel formats */
-int img_convert(AVPicture *dst, int dst_pix_fmt,
- AVPicture *src, int pix_fmt,
- int width, int height);
-
-/* deinterlace a picture */
-int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
- int pix_fmt, int width, int height);
-
-/* external high level API */
-
-extern AVCodec *first_avcodec;
-
-/* returns LIBAVCODEC_VERSION_INT constant */
-unsigned avcodec_version(void);
-/* returns LIBAVCODEC_BUILD constant */
-unsigned avcodec_build(void);
-void avcodec_init(void);
-
-void register_avcodec(AVCodec *format);
-AVCodec *avcodec_find_encoder(enum CodecID id);
-AVCodec *avcodec_find_encoder_by_name(const char *name);
-AVCodec *avcodec_find_decoder(enum CodecID id);
-AVCodec *avcodec_find_decoder_by_name(const char *name);
-void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode);
-
-void avcodec_get_context_defaults(AVCodecContext *s);
-AVCodecContext *avcodec_alloc_context(void);
-AVFrame *avcodec_alloc_frame(void);
-
-int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
-void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
-void avcodec_default_free_buffers(AVCodecContext *s);
-
-/**
- * opens / inits the AVCodecContext.
- * not thread save!
- */
-int avcodec_open(AVCodecContext *avctx, AVCodec *codec);
-
-int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
- int *got_picture_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata,
- int *data_size_ptr,
- uint8_t *buf, int buf_size);
-int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const short *samples);
-int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVFrame *pict);
-
-int avcodec_close(AVCodecContext *avctx);
-
-void avcodec_register_all(void);
-
-void avcodec_flush_buffers(AVCodecContext *avctx);
-
-/* misc usefull functions */
-
-/**
- * returns a single letter to describe the picture type
- */
-char av_get_pict_type_char(int pict_type);
-
-/**
- * reduce a fraction.
- * this is usefull for framerate calculations
- * @param max the maximum allowed for dst_nom & dst_den
- * @return 1 if exact, 0 otherwise
- */
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
-
-/**
- * rescale a 64bit integer.
- * a simple a*b/c isnt possible as it can overflow
- */
-int64_t av_rescale(int64_t a, int b, int c);
-
-
-/**
- * Interface for 0.5.0 version
- *
- * do not even think about it's usage for this moment
- */
-
-typedef struct {
- /// compressed size used from given memory buffer
- int size;
- /// I/P/B frame type
- int frame_type;
-} avc_enc_result_t;
-
-/**
- * Commands
- * order can't be changed - once it was defined
- */
-typedef enum {
- // general commands
- AVC_OPEN_BY_NAME = 0xACA000,
- AVC_OPEN_BY_CODEC_ID,
- AVC_OPEN_BY_FOURCC,
- AVC_CLOSE,
-
- AVC_FLUSH,
- // pin - struct { uint8_t* src, uint_t src_size }
- // pout - struct { AVPicture* img, consumed_bytes,
- AVC_DECODE,
- // pin - struct { AVPicture* img, uint8_t* dest, uint_t dest_size }
- // pout - uint_t used_from_dest_size
- AVC_ENCODE,
-
- // query/get video commands
- AVC_GET_VERSION = 0xACB000,
- AVC_GET_WIDTH,
- AVC_GET_HEIGHT,
- AVC_GET_DELAY,
- AVC_GET_QUANT_TABLE,
- // ...
-
- // query/get audio commands
- AVC_GET_FRAME_SIZE = 0xABC000,
-
- // maybe define some simple structure which
- // might be passed to the user - but they can't
- // contain any codec specific parts and these
- // calls are usualy necessary only few times
-
- // set video commands
- AVC_SET_WIDTH = 0xACD000,
- AVC_SET_HEIGHT,
-
- // set video encoding commands
- AVC_SET_FRAME_RATE = 0xACD800,
- AVC_SET_QUALITY,
- AVC_SET_HURRY_UP,
-
- // set audio commands
- AVC_SET_SAMPLE_RATE = 0xACE000,
- AVC_SET_CHANNELS
-
-} avc_cmd_t;
-
-/**
- * \param handle allocated private structure by libavcodec
- * for initialization pass NULL - will be returned pout
- * user is supposed to know nothing about its structure
- * \param cmd type of operation to be performed
- * \param pint input parameter
- * \param pout output parameter
- *
- * \returns command status - eventually for query command it might return
- * integer resulting value
- */
-int avcodec(void* handle, avc_cmd_t cmd, void* pin, void* pout);
-
-/* memory */
-void *av_malloc(unsigned int size);
-void *av_mallocz(unsigned int size);
-void *av_realloc(void *ptr, unsigned int size);
-void av_free(void *ptr);
-char *av_strdup(const char *s);
-void __av_freep(void **ptr);
-#define av_freep(p) __av_freep((void **)(p))
-void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size);
-/* for static data only */
-/* call av_free_static to release all staticaly allocated tables */
-void av_free_static(void);
-void *__av_mallocz_static(void** location, unsigned int size);
-#define av_mallocz_static(p, s) __av_mallocz_static((void **)(p), s)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AVCODEC_H */
+++ /dev/null
-/**
- * @file bswap.h
- * byte swap.
- */
-
-#ifndef __BSWAP_H__
-#define __BSWAP_H__
-
-#ifdef HAVE_BYTESWAP_H
-#include <byteswap.h>
-#else
-
-#ifdef ARCH_X86
-static inline unsigned short ByteSwap16(unsigned short x)
-{
- __asm("xchgb %b0,%h0" :
- "=q" (x) :
- "0" (x));
- return x;
-}
-#define bswap_16(x) ByteSwap16(x)
-
-static inline unsigned int ByteSwap32(unsigned int x)
-{
-#if __CPU__ > 386
- __asm("bswap %0":
- "=r" (x) :
-#else
- __asm("xchgb %b0,%h0\n"
- " rorl $16,%0\n"
- " xchgb %b0,%h0":
- "=q" (x) :
-#endif
- "0" (x));
- return x;
-}
-#define bswap_32(x) ByteSwap32(x)
-
-static inline unsigned long long int ByteSwap64(unsigned long long int x)
-{
- register union { __extension__ uint64_t __ll;
- uint32_t __l[2]; } __x;
- asm("xchgl %0,%1":
- "=r"(__x.__l[0]),"=r"(__x.__l[1]):
- "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
- return __x.__ll;
-}
-#define bswap_64(x) ByteSwap64(x)
-
-#elif defined(ARCH_SH4)
-
-static inline uint16_t ByteSwap16(uint16_t x) {
- __asm__("swap.b %0,%0":"=r"(x):"0"(x));
- return x;
-}
-
-static inline uint32_t ByteSwap32(uint32_t x) {
- __asm__(
- "swap.b %0,%0\n"
- "swap.w %0,%0\n"
- "swap.b %0,%0\n"
- :"=r"(x):"0"(x));
- return x;
-}
-
-#define bswap_16(x) ByteSwap16(x)
-#define bswap_32(x) ByteSwap32(x)
-
-static inline uint64_t ByteSwap64(uint64_t x)
-{
- union {
- uint64_t ll;
- struct {
- uint32_t l,h;
- } l;
- } r;
- r.l.l = bswap_32 (x);
- r.l.h = bswap_32 (x>>32);
- return r.ll;
-}
-#define bswap_64(x) ByteSwap64(x)
-
-#else
-
-#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
-
-
-// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
-#define bswap_32(x) \
- ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
-
-static inline uint64_t ByteSwap64(uint64_t x)
-{
- union {
- uint64_t ll;
- uint32_t l[2];
- } w, r;
- w.ll = x;
- r.l[0] = bswap_32 (w.l[1]);
- r.l[1] = bswap_32 (w.l[0]);
- return r.ll;
-}
-#define bswap_64(x) ByteSwap64(x)
-
-#endif /* !ARCH_X86 */
-
-#endif /* !HAVE_BYTESWAP_H */
-
-// be2me ... BigEndian to MachineEndian
-// le2me ... LittleEndian to MachineEndian
-
-#ifdef WORDS_BIGENDIAN
-#define be2me_16(x) (x)
-#define be2me_32(x) (x)
-#define be2me_64(x) (x)
-#define le2me_16(x) bswap_16(x)
-#define le2me_32(x) bswap_32(x)
-#define le2me_64(x) bswap_64(x)
-#else
-#define be2me_16(x) bswap_16(x)
-#define be2me_32(x) bswap_32(x)
-#define be2me_64(x) bswap_64(x)
-#define le2me_16(x) (x)
-#define le2me_32(x) (x)
-#define le2me_64(x) (x)
-#endif
-
-#endif /* __BSWAP_H__ */
+++ /dev/null
-/*
- * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file cabac.c
- * Context Adaptive Binary Arithmetic Coder.
- */
-
-#include <string.h>
-
-#include "common.h"
-#include "cabac.h"
-
-const uint8_t ff_h264_lps_range[64][4]= {
-{128,176,208,240}, {128,167,197,227}, {128,158,187,216}, {123,150,178,205},
-{116,142,169,195}, {111,135,160,185}, {105,128,152,175}, {100,122,144,166},
-{ 95,116,137,158}, { 90,110,130,150}, { 85,104,123,142}, { 81, 99,117,135},
-{ 77, 94,111,128}, { 73, 89,105,122}, { 69, 85,100,116}, { 66, 80, 95,110},
-{ 62, 76, 90,104}, { 59, 72, 86, 99}, { 56, 69, 81, 94}, { 53, 65, 77, 89},
-{ 51, 62, 73, 85}, { 48, 59, 69, 80}, { 46, 56, 66, 76}, { 43, 53, 63, 72},
-{ 41, 50, 59, 69}, { 39, 48, 56, 65}, { 37, 45, 54, 62}, { 35, 43, 51, 59},
-{ 33, 41, 48, 56}, { 32, 39, 46, 53}, { 30, 37, 43, 50}, { 29, 35, 41, 48},
-{ 27, 33, 39, 45}, { 26, 31, 37, 43}, { 24, 30, 35, 41}, { 23, 28, 33, 39},
-{ 22, 27, 32, 37}, { 21, 26, 30, 35}, { 20, 24, 29, 33}, { 19, 23, 27, 31},
-{ 18, 22, 26, 30}, { 17, 21, 25, 28}, { 16, 20, 23, 27}, { 15, 19, 22, 25},
-{ 14, 18, 21, 24}, { 14, 17, 20, 23}, { 13, 16, 19, 22}, { 12, 15, 18, 21},
-{ 12, 14, 17, 20}, { 11, 14, 16, 19}, { 11, 13, 15, 18}, { 10, 12, 15, 17},
-{ 10, 12, 14, 16}, { 9, 11, 13, 15}, { 9, 11, 12, 14}, { 8, 10, 12, 14},
-{ 8, 9, 11, 13}, { 7, 9, 11, 12}, { 7, 9, 10, 12}, { 7, 8, 10, 11},
-{ 6, 8, 9, 11}, { 6, 7, 9, 10}, { 6, 7, 8, 9}, { 2, 2, 2, 2},
-};
-
-const uint8_t ff_h264_mps_state[64]= {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9,10,11,12,13,14,15,16,
- 17,18,19,20,21,22,23,24,
- 25,26,27,28,29,30,31,32,
- 33,34,35,36,37,38,39,40,
- 41,42,43,44,45,46,47,48,
- 49,50,51,52,53,54,55,56,
- 57,58,59,60,61,62,62,63,
-};
-
-const uint8_t ff_h264_lps_state[64]= {
- 0, 0, 1, 2, 2, 4, 4, 5,
- 6, 7, 8, 9, 9,11,11,12,
- 13,13,15,15,16,16,18,18,
- 19,19,21,21,22,22,23,24,
- 24,25,26,26,27,27,28,29,
- 29,30,30,30,31,32,32,33,
- 33,33,34,34,35,35,35,36,
- 36,36,37,37,37,38,38,63,
-};
-
-/**
- *
- * @param buf_size size of buf in bits
- */
-void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size){
- init_put_bits(&c->pb, buf, buf_size, NULL, NULL);
-
- c->low= 0;
- c->range= 0x1FE;
- c->outstanding_count= 0;
-#ifdef STRICT_LIMITS
- c->sym_count =0;
-#endif
-
- c->pb.bit_left++; //avoids firstBitFlag
-}
-
-/**
- *
- * @param buf_size size of buf in bits
- */
-void ff_init_cabac_decoder(CABACContext *c, uint8_t *buf, int buf_size){
- c->bytestream_start=
- c->bytestream= buf;
-
- c->low= *c->bytestream++;
- c->low= (c->low<<9) + ((*c->bytestream++)<<1);
- c->range= 0x1FE00;
- c->bits_left= 7;
-}
-
-void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4],
- uint8_t const *mps_state, uint8_t const *lps_state, int state_count){
- int i, j;
-
- for(i=0; i<state_count; i++){
- for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save
- c->lps_range[2*i+0][j]=
- c->lps_range[2*i+1][j]= lps_range[i][j];
- }
-
- c->mps_state[2*i+0]= 2*mps_state[i];
- c->mps_state[2*i+1]= 2*mps_state[i]+1;
-
- if(lps_state[i]){
- c->lps_state[2*i+0]= 2*lps_state[i];
- c->lps_state[2*i+1]= 2*lps_state[i]+1;
- }else{
- c->lps_state[2*i+0]= 1;
- c->lps_state[2*i+1]= 0;
- }
- }
-}
-
-#if 0 //selftest
-#define SIZE 10240
-int main(){
- CABACContext c;
- uint8_t b[9*SIZE];
- uint8_t r[9*SIZE];
- int i;
- uint8_t state[10]= {0};
-
- ff_init_cabac_encoder(&c, b, SIZE);
- ff_init_cabac_states(&c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
-
- for(i=0; i<SIZE; i++){
- r[i]= random()%7;
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- put_cabac_bypass(&c, r[i]&1);
-STOP_TIMER("put_cabac_bypass")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- put_cabac(&c, state, r[i]&1);
-STOP_TIMER("put_cabac")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- put_cabac_u(&c, state, r[i], 6, 3, i&1);
-STOP_TIMER("put_cabac_u")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- put_cabac_ueg(&c, state, r[i], 3, 0, 1, 2);
-STOP_TIMER("put_cabac_ueg")
- }
-
- put_cabac_terminate(&c, 1);
-
- ff_init_cabac_decoder(&c, b, SIZE);
-
- memset(state, 0, sizeof(state));
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- if( (r[i]&1) != get_cabac_bypass(&c) )
- printf("CABAC bypass failure at %d\n", i);
-STOP_TIMER("get_cabac_bypass")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- if( (r[i]&1) != get_cabac(&c, state) )
- printf("CABAC failure at %d\n", i);
-STOP_TIMER("get_cabac")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- if( r[i] != get_cabac_u(&c, state, (i&1) ? 6 : 7, 3, i&1) )
- printf("CABAC unary (truncated) binarization failure at %d\n", i);
-STOP_TIMER("get_cabac_u")
- }
-
- for(i=0; i<SIZE; i++){
-START_TIMER
- if( r[i] != get_cabac_ueg(&c, state, 3, 0, 1, 2))
- printf("CABAC unary (truncated) binarization failure at %d\n", i);
-STOP_TIMER("get_cabac_ueg")
- }
-
- if(!get_cabac_terminate(&c))
- printf("where's the Terminator?\n");
-
- return 0;
-}
-
-#endif
+++ /dev/null
-/*
- * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file cabac.h
- * Context Adaptive Binary Arithmetic Coder.
- */
-
-
-#undef NDEBUG
-#include <assert.h>
-
-typedef struct CABACContext{
- int low;
- int range;
- int outstanding_count;
-#ifdef STRICT_LIMITS
- int symCount;
-#endif
- uint8_t lps_range[2*64][4]; ///< rangeTabLPS
- uint8_t lps_state[2*64]; ///< transIdxLPS
- uint8_t mps_state[2*64]; ///< transIdxMPS
- uint8_t *bytestream_start;
- uint8_t *bytestream;
- int bits_left; ///<
- PutBitContext pb;
-}CABACContext;
-
-extern const uint8_t ff_h264_lps_range[64][4];
-extern const uint8_t ff_h264_mps_state[64];
-extern const uint8_t ff_h264_lps_state[64];
-
-void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
-void ff_init_cabac_decoder(CABACContext *c, uint8_t *buf, int buf_size);
-void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4],
- uint8_t const *mps_state, uint8_t const *lps_state, int state_count);
-
-
-static inline void put_cabac_bit(CABACContext *c, int b){
- put_bits(&c->pb, 1, b);
- for(;c->outstanding_count; c->outstanding_count--){
- put_bits(&c->pb, 1, 1-b);
- }
-}
-
-static inline void renorm_cabac_encoder(CABACContext *c){
- while(c->range < 0x100){
- //FIXME optimize
- if(c->low<0x100){
- put_cabac_bit(c, 0);
- }else if(c->low<0x200){
- c->outstanding_count++;
- c->low -= 0x100;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x200;
- }
-
- c->range+= c->range;
- c->low += c->low;
- }
-}
-
-static inline void put_cabac(CABACContext *c, uint8_t * const state, int bit){
- int RangeLPS= c->lps_range[*state][((c->range)>>6)&3];
-
- if(bit == ((*state)&1)){
- c->range -= RangeLPS;
- *state= c->mps_state[*state];
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- *state= c->lps_state[*state];
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-static inline void put_cabac_static(CABACContext *c, int RangeLPS, int bit){
- assert(c->range > RangeLPS);
-
- if(!bit){
- c->range -= RangeLPS;
- }else{
- c->low += c->range - RangeLPS;
- c->range = RangeLPS;
- }
-
- renorm_cabac_encoder(c);
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- * @param bit 0 -> write zero bit, !=0 write one bit
- */
-static inline void put_cabac_bypass(CABACContext *c, int bit){
- c->low += c->low;
-
- if(bit){
- c->low += c->range;
- }
-//FIXME optimize
- if(c->low<0x200){
- put_cabac_bit(c, 0);
- }else if(c->low<0x400){
- c->outstanding_count++;
- c->low -= 0x200;
- }else{
- put_cabac_bit(c, 1);
- c->low -= 0x400;
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-}
-
-/**
- *
- * @return the number of bytes written
- */
-static inline int put_cabac_terminate(CABACContext *c, int bit){
- c->range -= 2;
-
- if(!bit){
- renorm_cabac_encoder(c);
- }else{
- c->low += c->range;
- c->range= 2;
-
- renorm_cabac_encoder(c);
-
- assert(c->low <= 0x1FF);
- put_cabac_bit(c, c->low>>9);
- put_bits(&c->pb, 2, ((c->low>>7)&3)|1);
-
- flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong
- }
-
-#ifdef STRICT_LIMITS
- c->symCount++;
-#endif
-
- return (get_bit_count(&c->pb)+7)>>3;
-}
-
-/**
- * put (truncated) unary binarization.
- */
-static inline void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){
- int i;
-
- assert(v <= max);
-
-#if 1
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
- if(truncated==0 || v<max)
- put_cabac(c, state, 0);
-#else
- if(v <= max_index){
- for(i=0; i<v; i++){
- put_cabac(c, state+i, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+i, 0);
- }else{
- for(i=0; i<=max_index; i++){
- put_cabac(c, state+i, 1);
- }
- for(; i<v; i++){
- put_cabac(c, state+max_index, 1);
- }
- if(truncated==0 || v<max)
- put_cabac(c, state+max_index, 0);
- }
-#endif
-}
-
-/**
- * put unary exp golomb k-th order binarization.
- */
-static inline void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int is_signed, int k, int max_index){
- int i;
-
- if(v==0)
- put_cabac(c, state, 0);
- else{
- const int sign= v < 0;
-
- if(is_signed) v= ABS(v);
-
- if(v<max){
- for(i=0; i<v; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- put_cabac(c, state, 0);
- }else{
- int m= 1<<k;
-
- for(i=0; i<max; i++){
- put_cabac(c, state, 1);
- if(i < max_index) state++;
- }
-
- v -= max;
- while(v >= m){ //FIXME optimize
- put_cabac_bypass(c, 1);
- v-= m;
- m+= m;
- }
- put_cabac_bypass(c, 0);
- while(m>>=1){
- put_cabac_bypass(c, v&m);
- }
- }
-
- if(is_signed)
- put_cabac_bypass(c, sign);
- }
-}
-
-static inline void renorm_cabac_decoder(CABACContext *c){
- while(c->range < 0x10000){
- c->range+= c->range;
- c->low+= c->low;
- if(--c->bits_left == 0){
- c->low+= *c->bytestream++;
- c->bits_left= 8;
- }
- }
-}
-
-static inline int get_cabac(CABACContext *c, uint8_t * const state){
- int RangeLPS= c->lps_range[*state][((c->range)>>14)&3]<<8;
- int bit;
-
- c->range -= RangeLPS;
- if(c->low < c->range){
- bit= (*state)&1;
- *state= c->mps_state[*state];
- }else{
- bit= ((*state)&1)^1;
- c->low -= c->range;
- c->range = RangeLPS;
- *state= c->lps_state[*state];
- }
- renorm_cabac_decoder(c);
-
- return bit;
-}
-
-static inline int get_cabac_static(CABACContext *c, int RangeLPS){
- int bit;
-
- c->range -= RangeLPS;
- if(c->low < c->range){
- bit= 0;
- }else{
- bit= 1;
- c->low -= c->range;
- c->range = RangeLPS;
- }
- renorm_cabac_decoder(c);
-
- return bit;
-}
-
-static inline int get_cabac_bypass(CABACContext *c){
- c->low += c->low;
-
- if(--c->bits_left == 0){
- c->low+= *c->bytestream++;
- c->bits_left= 8;
- }
-
- if(c->low < c->range){
- return 0;
- }else{
- c->low -= c->range;
- return 1;
- }
-}
-
-/**
- *
- * @return the number of bytes read or 0 if no end
- */
-static inline int get_cabac_terminate(CABACContext *c){
- c->range -= 2<<8;
- if(c->low < c->range){
- renorm_cabac_decoder(c);
- return 0;
- }else{
- return c->bytestream - c->bytestream_start;
- }
-}
-
-/**
- * get (truncated) unnary binarization.
- */
-static inline int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){
- int i;
-
- for(i=0; i<max; i++){
- if(get_cabac(c, state)==0)
- return i;
-
- if(i< max_index) state++;
- }
-
- return truncated ? max : -1;
-}
-
-/**
- * get unary exp golomb k-th order binarization.
- */
-static inline int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signed, int k, int max_index){
- int i, v;
- int m= 1<<k;
-
- if(get_cabac(c, state)==0)
- return 0;
-
- if(0 < max_index) state++;
-
- for(i=1; i<max; i++){
- if(get_cabac(c, state)==0){
- if(is_signed && get_cabac_bypass(c)){
- return -i;
- }else
- return i;
- }
-
- if(i < max_index) state++;
- }
-
- while(get_cabac_bypass(c)){
- i+= m;
- m+= m;
- }
-
- v=0;
- while(m>>=1){
- v+= v + get_cabac_bypass(c);
- }
- i += v;
-
- if(is_signed && get_cabac_bypass(c)){
- return -i;
- }else
- return i;
-}
+++ /dev/null
-/*
- * Cirrus Logic AccuPak (CLJR) codec
- * Copyright (c) 2003 Alex Beregszaszi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file cljr.c
- * Cirrus Logic AccuPak codec.
- */
-
-#include "avcodec.h"
-#include "mpegvideo.h"
-
-typedef struct CLJRContext{
- AVCodecContext *avctx;
- AVFrame picture;
- int delta[16];
- int offset[4];
- GetBitContext gb;
-} CLJRContext;
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- CLJRContext * const a = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int x, y;
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- init_get_bits(&a->gb, buf, buf_size);
-
- for(y=0; y<avctx->height; y++){
- uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
- uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ];
- uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ];
- for(x=0; x<avctx->width; x+=4){
- luma[3] = get_bits(&a->gb, 5) << 3;
- luma[2] = get_bits(&a->gb, 5) << 3;
- luma[1] = get_bits(&a->gb, 5) << 3;
- luma[0] = get_bits(&a->gb, 5) << 3;
- luma+= 4;
- *(cb++) = get_bits(&a->gb, 6) << 2;
- *(cr++) = get_bits(&a->gb, 6) << 2;
- }
- }
-
- *picture= *(AVFrame*)&a->picture;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return buf_size;
-}
-
-#if 0
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- CLJRContext * const a = avctx->priv_data;
- AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int size;
- int mb_x, mb_y;
-
- *p = *pict;
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- emms_c();
-
- align_put_bits(&a->pb);
- while(get_bit_count(&a->pb)&31)
- put_bits(&a->pb, 8, 0);
-
- size= get_bit_count(&a->pb)/32;
-
- return size*4;
-}
-#endif
-
-static void common_init(AVCodecContext *avctx){
- CLJRContext * const a = avctx->priv_data;
-
- avctx->coded_frame= (AVFrame*)&a->picture;
- a->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
-
- common_init(avctx);
-
- avctx->pix_fmt= PIX_FMT_YUV411P;
-
- return 0;
-}
-
-static int encode_init(AVCodecContext *avctx){
-
- common_init(avctx);
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec cljr_decoder = {
- "cljr",
- CODEC_TYPE_VIDEO,
- CODEC_ID_CLJR,
- sizeof(CLJRContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-#if 0
-#ifdef CONFIG_ENCODERS
-
-AVCodec cljr_encoder = {
- "cljr",
- CODEC_TYPE_VIDEO,
- CODEC_ID_cljr,
- sizeof(CLJRContext),
- encode_init,
- encode_frame,
- //encode_end,
-};
-
-#endif //CONFIG_ENCODERS
-#endif
+++ /dev/null
-/*
- * Common bit i/o utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file common.c
- * common internal api.
- */
-
-#include "avcodec.h"
-
-const uint8_t ff_sqrt_tab[128]={
- 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11
-};
-
-const uint8_t ff_log2_tab[256]={
- 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
-};
-
-void init_put_bits(PutBitContext *s,
- uint8_t *buffer, int buffer_size,
- void *opaque,
- void (*write_data)(void *, uint8_t *, int))
-{
- s->buf = buffer;
- s->buf_end = s->buf + buffer_size;
- s->data_out_size = 0;
- if(write_data!=NULL)
- {
- fprintf(stderr, "write Data callback is not supported\n");
- }
-#ifdef ALT_BITSTREAM_WRITER
- s->index=0;
- ((uint32_t*)(s->buf))[0]=0;
-// memset(buffer, 0, buffer_size);
-#else
- s->buf_ptr = s->buf;
- s->bit_left=32;
- s->bit_buf=0;
-#endif
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* return the number of bits output */
-int64_t get_bit_count(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- return s->data_out_size * 8 + s->index;
-#else
- return (s->buf_ptr - s->buf + s->data_out_size) * 8 + 32 - (int64_t)s->bit_left;
-#endif
-}
-
-void align_put_bits(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- put_bits(s,( - s->index) & 7,0);
-#else
- put_bits(s,s->bit_left & 7,0);
-#endif
-}
-
-#endif //CONFIG_ENCODERS
-
-/* pad the end of the output stream with zeros */
-void flush_put_bits(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- align_put_bits(s);
-#else
- s->bit_buf<<= s->bit_left;
- while (s->bit_left < 32) {
- /* XXX: should test end of buffer */
- *s->buf_ptr++=s->bit_buf >> 24;
- s->bit_buf<<=8;
- s->bit_left+=8;
- }
- s->bit_left=32;
- s->bit_buf=0;
-#endif
-}
-
-#ifdef CONFIG_ENCODERS
-
-void put_string(PutBitContext * pbc, char *s)
-{
- while(*s){
- put_bits(pbc, 8, *s);
- s++;
- }
- put_bits(pbc, 8, 0);
-}
-
-/* bit input functions */
-
-#endif //CONFIG_ENCODERS
-
-/**
- * init GetBitContext.
- * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
- * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
- * @param bit_size the size of the buffer in bits
- */
-void init_get_bits(GetBitContext *s,
- const uint8_t *buffer, int bit_size)
-{
- const int buffer_size= (bit_size+7)>>3;
-
- s->buffer= buffer;
- s->size_in_bits= bit_size;
- s->buffer_end= buffer + buffer_size;
-#ifdef ALT_BITSTREAM_READER
- s->index=0;
-#elif defined LIBMPEG2_BITSTREAM_READER
-#ifdef LIBMPEG2_BITSTREAM_READER_HACK
- if ((int)buffer&1) {
- /* word alignment */
- s->cache = (*buffer++)<<24;
- s->buffer_ptr = buffer;
- s->bit_count = 16-8;
- } else
-#endif
- {
- s->buffer_ptr = buffer;
- s->bit_count = 16;
- s->cache = 0;
- }
-#elif defined A32_BITSTREAM_READER
- s->buffer_ptr = (uint32_t*)buffer;
- s->bit_count = 32;
- s->cache0 = 0;
- s->cache1 = 0;
-#endif
- {
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- UPDATE_CACHE(re, s)
- CLOSE_READER(re, s)
- }
-#ifdef A32_BITSTREAM_READER
- s->cache1 = 0;
-#endif
-}
-
-/**
- * reads 0-32 bits.
- */
-unsigned int get_bits_long(GetBitContext *s, int n){
- if(n<=17) return get_bits(s, n);
- else{
- int ret= get_bits(s, 16) << (n-16);
- return ret | get_bits(s, n-16);
- }
-}
-
-/**
- * shows 0-32 bits.
- */
-unsigned int show_bits_long(GetBitContext *s, int n){
- if(n<=17) return show_bits(s, n);
- else{
- GetBitContext gb= *s;
- int ret= get_bits_long(s, n);
- *s= gb;
- return ret;
- }
-}
-
-void align_get_bits(GetBitContext *s)
-{
- int n= (-get_bits_count(s)) & 7;
- if(n) skip_bits(s, n);
-}
-
-int check_marker(GetBitContext *s, const char *msg)
-{
- int bit= get_bits1(s);
- if(!bit) printf("Marker bit missing %s\n", msg);
-
- return bit;
-}
-
-/* VLC decoding */
-
-//#define DEBUG_VLC
-
-#define GET_DATA(v, table, i, wrap, size) \
-{\
- const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
- switch(size) {\
- case 1:\
- v = *(const uint8_t *)ptr;\
- break;\
- case 2:\
- v = *(const uint16_t *)ptr;\
- break;\
- default:\
- v = *(const uint32_t *)ptr;\
- break;\
- }\
-}
-
-
-static int alloc_table(VLC *vlc, int size)
-{
- int index;
- index = vlc->table_size;
- vlc->table_size += size;
- if (vlc->table_size > vlc->table_allocated) {
- vlc->table_allocated += (1 << vlc->bits);
- vlc->table = av_realloc(vlc->table,
- sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
- if (!vlc->table)
- return -1;
- }
- return index;
-}
-
-static int build_table(VLC *vlc, int table_nb_bits,
- int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size,
- uint32_t code_prefix, int n_prefix)
-{
- int i, j, k, n, table_size, table_index, nb, n1, index;
- uint32_t code;
- VLC_TYPE (*table)[2];
-
- table_size = 1 << table_nb_bits;
- table_index = alloc_table(vlc, table_size);
-#ifdef DEBUG_VLC
- printf("new table index=%d size=%d code_prefix=%x n=%d\n",
- table_index, table_size, code_prefix, n_prefix);
-#endif
- if (table_index < 0)
- return -1;
- table = &vlc->table[table_index];
-
- for(i=0;i<table_size;i++) {
- table[i][1] = 0; //bits
- table[i][0] = -1; //codes
- }
-
- /* first pass: map codes and compute auxillary table sizes */
- for(i=0;i<nb_codes;i++) {
- GET_DATA(n, bits, i, bits_wrap, bits_size);
- GET_DATA(code, codes, i, codes_wrap, codes_size);
- /* we accept tables with holes */
- if (n <= 0)
- continue;
-#if defined(DEBUG_VLC) && 0
- printf("i=%d n=%d code=0x%x\n", i, n, code);
-#endif
- /* if code matches the prefix, it is in the table */
- n -= n_prefix;
- if (n > 0 && (code >> n) == code_prefix) {
- if (n <= table_nb_bits) {
- /* no need to add another table */
- j = (code << (table_nb_bits - n)) & (table_size - 1);
- nb = 1 << (table_nb_bits - n);
- for(k=0;k<nb;k++) {
-#ifdef DEBUG_VLC
- printf("%4x: code=%d n=%d\n",
- j, i, n);
-#endif
- if (table[j][1] /*bits*/ != 0) {
- fprintf(stderr, "incorrect codes\n");
- av_abort();
- }
- table[j][1] = n; //bits
- table[j][0] = i; //code
- j++;
- }
- } else {
- n -= table_nb_bits;
- j = (code >> n) & ((1 << table_nb_bits) - 1);
-#ifdef DEBUG_VLC
- printf("%4x: n=%d (subtable)\n",
- j, n);
-#endif
- /* compute table size */
- n1 = -table[j][1]; //bits
- if (n > n1)
- n1 = n;
- table[j][1] = -n1; //bits
- }
- }
- }
-
- /* second pass : fill auxillary tables recursively */
- for(i=0;i<table_size;i++) {
- n = table[i][1]; //bits
- if (n < 0) {
- n = -n;
- if (n > table_nb_bits) {
- n = table_nb_bits;
- table[i][1] = -n; //bits
- }
- index = build_table(vlc, n, nb_codes,
- bits, bits_wrap, bits_size,
- codes, codes_wrap, codes_size,
- (code_prefix << table_nb_bits) | i,
- n_prefix + table_nb_bits);
- if (index < 0)
- return -1;
- /* note: realloc has been done, so reload tables */
- table = &vlc->table[table_index];
- table[i][0] = index; //code
- }
- }
- return table_index;
-}
-
-
-/* Build VLC decoding tables suitable for use with get_vlc().
-
- 'nb_bits' set thee decoding table size (2^nb_bits) entries. The
- bigger it is, the faster is the decoding. But it should not be too
- big to save memory and L1 cache. '9' is a good compromise.
-
- 'nb_codes' : number of vlcs codes
-
- 'bits' : table which gives the size (in bits) of each vlc code.
-
- 'codes' : table which gives the bit pattern of of each vlc code.
-
- 'xxx_wrap' : give the number of bytes between each entry of the
- 'bits' or 'codes' tables.
-
- 'xxx_size' : gives the number of bytes of each entry of the 'bits'
- or 'codes' tables.
-
- 'wrap' and 'size' allows to use any memory configuration and types
- (byte/word/long) to store the 'bits' and 'codes' tables.
-*/
-int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size)
-{
- vlc->bits = nb_bits;
- vlc->table = NULL;
- vlc->table_allocated = 0;
- vlc->table_size = 0;
-#ifdef DEBUG_VLC
- printf("build table nb_codes=%d\n", nb_codes);
-#endif
-
- if (build_table(vlc, nb_bits, nb_codes,
- bits, bits_wrap, bits_size,
- codes, codes_wrap, codes_size,
- 0, 0) < 0) {
- av_free(vlc->table);
- return -1;
- }
- return 0;
-}
-
-
-void free_vlc(VLC *vlc)
-{
- av_free(vlc->table);
-}
-
-int64_t ff_gcd(int64_t a, int64_t b){
- if(b) return ff_gcd(b, a%b);
- else return a;
-}
-
-void ff_float2fraction(int *nom_arg, int *denom_arg, double f, int max){
- double best_diff=1E10, diff;
- int best_denom=1, best_nom=1;
- int nom, denom, gcd;
-
- //brute force here, perhaps we should try continued fractions if we need large max ...
- for(denom=1; denom<=max; denom++){
- nom= (int)(f*denom + 0.5);
- if(nom<=0 || nom>max) continue;
-
- diff= ABS( f - (double)nom / (double)denom );
- if(diff < best_diff){
- best_diff= diff;
- best_nom= nom;
- best_denom= denom;
- }
- }
-
- gcd= ff_gcd(best_nom, best_denom);
- best_nom /= gcd;
- best_denom /= gcd;
-
- *nom_arg= best_nom;
- *denom_arg= best_denom;
-}
+++ /dev/null
-/**
- * @file common.h
- * common internal api header.
- */
-
-#ifndef COMMON_H
-#define COMMON_H
-
-#if defined(WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
-# define CONFIG_WIN32
-#endif
-
-//#define ALT_BITSTREAM_WRITER
-//#define ALIGNED_BITSTREAM_WRITER
-
-#define ALT_BITSTREAM_READER
-//#define LIBMPEG2_BITSTREAM_READER
-//#define A32_BITSTREAM_READER
-#define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
-
-#ifdef HAVE_AV_CONFIG_H
-/* only include the following when compiling package */
-# include "config.h"
-
-# include <stdlib.h>
-# include <stdio.h>
-# include <string.h>
-# include <ctype.h>
-# ifndef __BEOS__
-# include <errno.h>
-# else
-# include "berrno.h"
-# endif
-# include <math.h>
-
-# ifndef ENODATA
-# define ENODATA 61
-# endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#include <stddef.h>
-#ifndef offsetof
-# define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F))
-#endif
-
-#define AVOPTION_CODEC_BOOL(name, help, field) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_BOOL }
-#define AVOPTION_CODEC_DOUBLE(name, help, field, minv, maxv, defval) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_DOUBLE, minv, maxv, defval }
-#define AVOPTION_CODEC_FLAG(name, help, field, flag, defval) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_FLAG, flag, 0, defval }
-#define AVOPTION_CODEC_INT(name, help, field, minv, maxv, defval) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_INT, minv, maxv, defval }
-#define AVOPTION_CODEC_STRING(name, help, field, str, val) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_STRING, .defval = val, .defstr = str }
-#define AVOPTION_CODEC_RCOVERRIDE(name, help, field) \
- { name, help, offsetof(AVCodecContext, field), FF_OPT_TYPE_RCOVERRIDE, .defval = 0, .defstr = NULL }
-#define AVOPTION_SUB(ptr) { .name = NULL, .help = (const char*)ptr }
-#define AVOPTION_END() AVOPTION_SUB(NULL)
-
-struct AVOption;
-#ifdef HAVE_MMX
-extern const struct AVOption avoptions_common[3 + 5];
-#else
-extern const struct AVOption avoptions_common[3];
-#endif
-extern const struct AVOption avoptions_workaround_bug[11];
-
-#endif /* HAVE_AV_CONFIG_H */
-
-/* Suppress restrict if it was not defined in config.h. */
-#ifndef restrict
-# define restrict
-#endif
-
-#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
-# define always_inline __attribute__((always_inline)) inline
-#else
-# define always_inline inline
-#endif
-
-#ifdef CONFIG_WIN32
-
-/* windows */
-
-typedef unsigned short uint16_t;
-typedef signed short int16_t;
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-typedef unsigned __int64 uint64_t;
-typedef signed char int8_t;
-typedef signed int int32_t;
-typedef signed __int64 int64_t;
-
-# ifndef __MINGW32__
-# define int64_t_C(c) (c ## i64)
-# define uint64_t_C(c) (c ## i64)
-
-# define inline __inline
-
-# else
-# define int64_t_C(c) (c ## LL)
-# define uint64_t_C(c) (c ## ULL)
-# endif /* __MINGW32__ */
-
-# ifdef _DEBUG
-# define DEBUG
-# endif
-
-# define snprintf _snprintf
-# define vsnprintf _vsnprintf
-
-/* CONFIG_WIN32 end */
-#elif defined (CONFIG_OS2)
-/* OS/2 EMX */
-
-#include <inttypes.h>
-
-#ifndef int64_t_C
-#define int64_t_C(c) (c ## LL)
-#define uint64_t_C(c) (c ## ULL)
-#endif
-
-#ifdef HAVE_AV_CONFIG_H
-
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-
-#include <float.h>
-
-#endif /* HAVE_AV_CONFIG_H */
-
-/* CONFIG_OS2 end */
-#else
-
-/* unix */
-
-#include <inttypes.h>
-
-#ifndef int64_t_C
-#define int64_t_C(c) (c ## LL)
-#define uint64_t_C(c) (c ## ULL)
-#endif
-
-#ifdef HAVE_AV_CONFIG_H
-
-# ifdef USE_FASTMEMCPY
-# include "fastmemcpy.h"
-# endif
-# endif /* HAVE_AV_CONFIG_H */
-
-#endif /* !CONFIG_WIN32 && !CONFIG_OS2 */
-
-#ifdef HAVE_AV_CONFIG_H
-
-# include "bswap.h"
-
-# if defined(__MINGW32__) || defined(__CYGWIN__) || \
- defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__))
-# define MANGLE(a) "_" #a
-# else
-# define MANGLE(a) #a
-# endif
-
-/* debug stuff */
-
-# ifndef DEBUG
-# define NDEBUG
-# endif
-# include <assert.h>
-
-/* dprintf macros */
-# if defined(CONFIG_WIN32) && !defined(__MINGW32__)
-
-inline void dprintf(const char* fmt,...) {}
-
-# else
-
-# ifdef DEBUG
-# define dprintf(fmt,args...) printf(fmt, ## args)
-# else
-# define dprintf(fmt,args...)
-# endif
-
-# endif /* !CONFIG_WIN32 */
-
-# define av_abort() do { fprintf(stderr, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
-
-//rounded divison & shift
-#define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b))
-/* assume b>0 */
-#define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
-#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
-
-#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
-#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
-
-extern const uint32_t inverse[256];
-
-#ifdef ARCH_X86
-# define FASTDIV(a,b) \
- ({\
- int ret,dmy;\
- asm volatile(\
- "mull %3"\
- :"=d"(ret),"=a"(dmy)\
- :"1"(a),"g"(inverse[b])\
- );\
- ret;\
- })
-#elif defined(CONFIG_FASTDIV)
-# define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*inverse[b])>>32))
-#else
-# define FASTDIV(a,b) ((a)/(b))
-#endif
-
-#ifdef ARCH_X86
-// avoid +32 for shift optimization (gcc should do that ...)
-static inline int32_t NEG_SSR32( int32_t a, int8_t s){
- asm ("sarl %1, %0\n\t"
- : "+r" (a)
- : "ic" ((uint8_t)(-s))
- );
- return a;
-}
-static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
- asm ("shrl %1, %0\n\t"
- : "+r" (a)
- : "ic" ((uint8_t)(-s))
- );
- return a;
-}
-#else
-# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
-# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
-#endif
-
-/* bit output */
-
-struct PutBitContext;
-
-typedef void (*WriteDataFunc)(void *, uint8_t *, int);
-
-typedef struct PutBitContext {
-#ifdef ALT_BITSTREAM_WRITER
- uint8_t *buf, *buf_end;
- int index;
-#else
- uint32_t bit_buf;
- int bit_left;
- uint8_t *buf, *buf_ptr, *buf_end;
-#endif
- int64_t data_out_size; /* in bytes */
-} PutBitContext;
-
-void init_put_bits(PutBitContext *s,
- uint8_t *buffer, int buffer_size,
- void *opaque,
- void (*write_data)(void *, uint8_t *, int));
-
-int64_t get_bit_count(PutBitContext *s); /* XXX: change function name */
-void align_put_bits(PutBitContext *s);
-void flush_put_bits(PutBitContext *s);
-void put_string(PutBitContext * pbc, char *s);
-
-/* bit input */
-
-typedef struct GetBitContext {
- const uint8_t *buffer, *buffer_end;
-#ifdef ALT_BITSTREAM_READER
- int index;
-#elif defined LIBMPEG2_BITSTREAM_READER
- uint8_t *buffer_ptr;
- uint32_t cache;
- int bit_count;
-#elif defined A32_BITSTREAM_READER
- uint32_t *buffer_ptr;
- uint32_t cache0;
- uint32_t cache1;
- int bit_count;
-#endif
- int size_in_bits;
-} GetBitContext;
-
-static inline int get_bits_count(GetBitContext *s);
-
-#define VLC_TYPE int16_t
-
-typedef struct VLC {
- int bits;
- VLC_TYPE (*table)[2]; ///< code, bits
- int table_size, table_allocated;
-} VLC;
-
-typedef struct RL_VLC_ELEM {
- int16_t level;
- int8_t len;
- uint8_t run;
-} RL_VLC_ELEM;
-
-#ifdef ARCH_SPARC64
-#define UNALIGNED_STORES_ARE_BAD
-#endif
-
-/* used to avoid missaligned exceptions on some archs (alpha, ...) */
-#ifdef ARCH_X86
-# define unaligned32(a) (*(uint32_t*)(a))
-#else
-# ifdef __GNUC__
-static inline uint32_t unaligned32(const void *v) {
- struct Unaligned {
- uint32_t i;
- } __attribute__((packed));
-
- return ((const struct Unaligned *) v)->i;
-}
-# elif defined(__DECC)
-static inline uint32_t unaligned32(const void *v) {
- return *(const __unaligned uint32_t *) v;
-}
-# else
-static inline uint32_t unaligned32(const void *v) {
- return *(const uint32_t *) v;
-}
-# endif
-#endif //!ARCH_X86
-
-#ifndef ALT_BITSTREAM_WRITER
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
-{
- unsigned int bit_buf;
- int bit_left;
-
-#ifdef STATS
- st_out_bit_counts[st_current_index] += n;
-#endif
- // printf("put_bits=%d %x\n", n, value);
- assert(n == 32 || value < (1U << n));
-
- bit_buf = s->bit_buf;
- bit_left = s->bit_left;
-
- // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
- /* XXX: optimize */
- if (n < bit_left) {
- bit_buf = (bit_buf<<n) | value;
- bit_left-=n;
- } else {
- bit_buf<<=bit_left;
- bit_buf |= value >> (n - bit_left);
-#ifdef UNALIGNED_STORES_ARE_BAD
- if (3 & (int) s->buf_ptr) {
- s->buf_ptr[0] = bit_buf >> 24;
- s->buf_ptr[1] = bit_buf >> 16;
- s->buf_ptr[2] = bit_buf >> 8;
- s->buf_ptr[3] = bit_buf ;
- } else
-#endif
- *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
- //printf("bitbuf = %08x\n", bit_buf);
- s->buf_ptr+=4;
- bit_left+=32 - n;
- bit_buf = value;
- }
-
- s->bit_buf = bit_buf;
- s->bit_left = bit_left;
-}
-#endif
-
-
-#ifdef ALT_BITSTREAM_WRITER
-static inline void put_bits(PutBitContext *s, int n, unsigned int value)
-{
-# ifdef ALIGNED_BITSTREAM_WRITER
-# ifdef ARCH_X86
- asm volatile(
- "movl %0, %%ecx \n\t"
- "xorl %%eax, %%eax \n\t"
- "shrdl %%cl, %1, %%eax \n\t"
- "shrl %%cl, %1 \n\t"
- "movl %0, %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "andl $0xFFFFFFFC, %%ecx \n\t"
- "bswapl %1 \n\t"
- "orl %1, (%2, %%ecx) \n\t"
- "bswapl %%eax \n\t"
- "addl %3, %0 \n\t"
- "movl %%eax, 4(%2, %%ecx) \n\t"
- : "=&r" (s->index), "=&r" (value)
- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
- : "%eax", "%ecx"
- );
-# else
- int index= s->index;
- uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
-
- value<<= 32-n;
-
- ptr[0] |= be2me_32(value>>(index&31));
- ptr[1] = be2me_32(value<<(32-(index&31)));
-//if(n>24) printf("%d %d\n", n, value);
- index+= n;
- s->index= index;
-# endif
-# else //ALIGNED_BITSTREAM_WRITER
-# ifdef ARCH_X86
- asm volatile(
- "movl $7, %%ecx \n\t"
- "andl %0, %%ecx \n\t"
- "addl %3, %%ecx \n\t"
- "negl %%ecx \n\t"
- "shll %%cl, %1 \n\t"
- "bswapl %1 \n\t"
- "movl %0, %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "orl %1, (%%ecx, %2) \n\t"
- "addl %3, %0 \n\t"
- "movl $0, 4(%%ecx, %2) \n\t"
- : "=&r" (s->index), "=&r" (value)
- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
- : "%ecx"
- );
-# else
- int index= s->index;
- uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
-
- ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
- ptr[1] = 0;
-//if(n>24) printf("%d %d\n", n, value);
- index+= n;
- s->index= index;
-# endif
-# endif //!ALIGNED_BITSTREAM_WRITER
-}
-#endif
-
-
-static inline uint8_t* pbBufPtr(PutBitContext *s)
-{
-#ifdef ALT_BITSTREAM_WRITER
- return s->buf + (s->index>>3);
-#else
- return s->buf_ptr;
-#endif
-}
-
-/* Bitstream reader API docs:
-name
- abritary name which is used as prefix for the internal variables
-
-gb
- getbitcontext
-
-OPEN_READER(name, gb)
- loads gb into local variables
-
-CLOSE_READER(name, gb)
- stores local vars in gb
-
-UPDATE_CACHE(name, gb)
- refills the internal cache from the bitstream
- after this call at least MIN_CACHE_BITS will be available,
-
-GET_CACHE(name, gb)
- will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
-
-SHOW_UBITS(name, gb, num)
- will return the nest num bits
-
-SHOW_SBITS(name, gb, num)
- will return the nest num bits and do sign extension
-
-SKIP_BITS(name, gb, num)
- will skip over the next num bits
- note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER
-
-SKIP_CACHE(name, gb, num)
- will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
-
-SKIP_COUNTER(name, gb, num)
- will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
-
-LAST_SKIP_CACHE(name, gb, num)
- will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
-
-LAST_SKIP_BITS(name, gb, num)
- is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER
-
-for examples see get_bits, show_bits, skip_bits, get_vlc
-*/
-
-static inline int unaligned32_be(const void *v)
-{
-#ifdef CONFIG_ALIGN
- const uint8_t *p=v;
- return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
-#else
- return be2me_32( unaligned32(v)); //original
-#endif
-}
-
-#ifdef ALT_BITSTREAM_READER
-# define MIN_CACHE_BITS 25
-
-# define OPEN_READER(name, gb)\
- int name##_index= (gb)->index;\
- int name##_cache= 0;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->index= name##_index;\
-
-# define UPDATE_CACHE(name, gb)\
- name##_cache= unaligned32_be( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
-
-# define SKIP_CACHE(name, gb, num)\
- name##_cache <<= (num);\
-
-// FIXME name?
-# define SKIP_COUNTER(name, gb, num)\
- name##_index += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) ;
-
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache, num)
-
-# define GET_CACHE(name, gb)\
- ((uint32_t)name##_cache)
-
-static inline int get_bits_count(GetBitContext *s){
- return s->index;
-}
-#elif defined LIBMPEG2_BITSTREAM_READER
-//libmpeg2 like reader
-
-# define MIN_CACHE_BITS 17
-
-# define OPEN_READER(name, gb)\
- int name##_bit_count=(gb)->bit_count;\
- int name##_cache= (gb)->cache;\
- uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->bit_count= name##_bit_count;\
- (gb)->cache= name##_cache;\
- (gb)->buffer_ptr= name##_buffer_ptr;\
-
-#ifdef LIBMPEG2_BITSTREAM_READER_HACK
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count >= 0){\
- name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
- ((uint16_t*)name##_buffer_ptr)++;\
- name##_bit_count-= 16;\
- }\
-
-#else
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count >= 0){\
- name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
- name##_buffer_ptr+=2;\
- name##_bit_count-= 16;\
- }\
-
-#endif
-
-# define SKIP_CACHE(name, gb, num)\
- name##_cache <<= (num);\
-
-# define SKIP_COUNTER(name, gb, num)\
- name##_bit_count += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
-
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache, num)
-
-# define GET_CACHE(name, gb)\
- ((uint32_t)name##_cache)
-
-static inline int get_bits_count(GetBitContext *s){
- return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
-}
-
-#elif defined A32_BITSTREAM_READER
-
-# define MIN_CACHE_BITS 32
-
-# define OPEN_READER(name, gb)\
- int name##_bit_count=(gb)->bit_count;\
- uint32_t name##_cache0= (gb)->cache0;\
- uint32_t name##_cache1= (gb)->cache1;\
- uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
-
-# define CLOSE_READER(name, gb)\
- (gb)->bit_count= name##_bit_count;\
- (gb)->cache0= name##_cache0;\
- (gb)->cache1= name##_cache1;\
- (gb)->buffer_ptr= name##_buffer_ptr;\
-
-# define UPDATE_CACHE(name, gb)\
- if(name##_bit_count > 0){\
- const uint32_t next= be2me_32( *name##_buffer_ptr );\
- name##_cache0 |= NEG_USR32(next,name##_bit_count);\
- name##_cache1 |= next<<name##_bit_count;\
- name##_buffer_ptr++;\
- name##_bit_count-= 32;\
- }\
-
-#ifdef ARCH_X86
-# define SKIP_CACHE(name, gb, num)\
- asm(\
- "shldl %2, %1, %0 \n\t"\
- "shll %2, %1 \n\t"\
- : "+r" (name##_cache0), "+r" (name##_cache1)\
- : "Ic" ((uint8_t)num)\
- );
-#else
-# define SKIP_CACHE(name, gb, num)\
- name##_cache0 <<= (num);\
- name##_cache0 |= NEG_USR32(name##_cache1,num);\
- name##_cache1 <<= (num);
-#endif
-
-# define SKIP_COUNTER(name, gb, num)\
- name##_bit_count += (num);\
-
-# define SKIP_BITS(name, gb, num)\
- {\
- SKIP_CACHE(name, gb, num)\
- SKIP_COUNTER(name, gb, num)\
- }\
-
-# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
-# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
-
-# define SHOW_UBITS(name, gb, num)\
- NEG_USR32(name##_cache0, num)
-
-# define SHOW_SBITS(name, gb, num)\
- NEG_SSR32(name##_cache0, num)
-
-# define GET_CACHE(name, gb)\
- (name##_cache0)
-
-static inline int get_bits_count(GetBitContext *s){
- return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
-}
-
-#endif
-
-/**
- * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
- * if MSB not set it is negative
- * @param n length in bits
- * @author BERO
- */
-static inline int get_xbits(GetBitContext *s, int n){
- register int tmp;
- register int32_t cache;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- cache = GET_CACHE(re,s);
- if ((int32_t)cache<0) { //MSB=1
- tmp = NEG_USR32(cache,n);
- } else {
- // tmp = (-1<<n) | NEG_USR32(cache,n) + 1; mpeg12.c algo
- // tmp = - (NEG_USR32(cache,n) ^ ((1 << n) - 1)); h263.c algo
- tmp = - NEG_USR32(~cache,n);
- }
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return tmp;
-}
-
-static inline int get_sbits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_SBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return tmp;
-}
-
-/**
- * reads 0-17 bits.
- * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
- */
-static inline unsigned int get_bits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_UBITS(re, s, n);
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
- return tmp;
-}
-
-unsigned int get_bits_long(GetBitContext *s, int n);
-
-/**
- * shows 0-17 bits.
- * Note, the alt bitstream reader can read upto 25 bits, but the libmpeg2 reader cant
- */
-static inline unsigned int show_bits(GetBitContext *s, int n){
- register int tmp;
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- tmp= SHOW_UBITS(re, s, n);
-// CLOSE_READER(re, s)
- return tmp;
-}
-
-unsigned int show_bits_long(GetBitContext *s, int n);
-
-static inline void skip_bits(GetBitContext *s, int n){
- //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
- LAST_SKIP_BITS(re, s, n)
- CLOSE_READER(re, s)
-}
-
-static inline unsigned int get_bits1(GetBitContext *s){
-#ifdef ALT_BITSTREAM_READER
- int index= s->index;
- uint8_t result= s->buffer[ index>>3 ];
- result<<= (index&0x07);
- result>>= 8 - 1;
- index++;
- s->index= index;
-
- return result;
-#else
- return get_bits(s, 1);
-#endif
-}
-
-static inline unsigned int show_bits1(GetBitContext *s){
- return show_bits(s, 1);
-}
-
-static inline void skip_bits1(GetBitContext *s){
- skip_bits(s, 1);
-}
-
-void init_get_bits(GetBitContext *s,
- const uint8_t *buffer, int buffer_size);
-
-int check_marker(GetBitContext *s, const char *msg);
-void align_get_bits(GetBitContext *s);
-int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size);
-void free_vlc(VLC *vlc);
-
-/**
- *
- * if the vlc code is invalid and max_depth=1 than no bits will be removed
- * if the vlc code is invalid and max_depth>1 than the number of bits removed
- * is undefined
- */
-#define GET_VLC(code, name, gb, table, bits, max_depth)\
-{\
- int n, index, nb_bits;\
-\
- index= SHOW_UBITS(name, gb, bits);\
- code = table[index][0];\
- n = table[index][1];\
-\
- if(max_depth > 1 && n < 0){\
- LAST_SKIP_BITS(name, gb, bits)\
- UPDATE_CACHE(name, gb)\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + code;\
- code = table[index][0];\
- n = table[index][1];\
- if(max_depth > 2 && n < 0){\
- LAST_SKIP_BITS(name, gb, nb_bits)\
- UPDATE_CACHE(name, gb)\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + code;\
- code = table[index][0];\
- n = table[index][1];\
- }\
- }\
- SKIP_BITS(name, gb, n)\
-}
-
-#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\
-{\
- int n, index, nb_bits;\
-\
- index= SHOW_UBITS(name, gb, bits);\
- level = table[index].level;\
- n = table[index].len;\
-\
- if(max_depth > 1 && n < 0){\
- LAST_SKIP_BITS(name, gb, bits)\
- UPDATE_CACHE(name, gb)\
-\
- nb_bits = -n;\
-\
- index= SHOW_UBITS(name, gb, nb_bits) + level;\
- level = table[index].level;\
- n = table[index].len;\
- }\
- run= table[index].run;\
- SKIP_BITS(name, gb, n)\
-}
-
-// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly
-static inline int get_vlc(GetBitContext *s, VLC *vlc)
-{
- int code;
- VLC_TYPE (*table)[2]= vlc->table;
-
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
-
- GET_VLC(code, re, s, table, vlc->bits, 3)
-
- CLOSE_READER(re, s)
- return code;
-}
-
-/**
- * parses a vlc code, faster then get_vlc()
- * @param bits is the number of bits which will be read at once, must be
- * identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be readed to completly
- * read the longest vlc code
- * = (max_vlc_length + bits - 1) / bits
- */
-static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
- int bits, int max_depth)
-{
- int code;
-
- OPEN_READER(re, s)
- UPDATE_CACHE(re, s)
-
- GET_VLC(code, re, s, table, bits, max_depth)
-
- CLOSE_READER(re, s)
- return code;
-}
-
-//#define TRACE
-
-#ifdef TRACE
-
-static inline void print_bin(int bits, int n){
- int i;
-
- for(i=n-1; i>=0; i--){
- printf("%d", (bits>>i)&1);
- }
- for(i=n; i<24; i++)
- printf(" ");
-}
-
-static inline int get_bits_trace(GetBitContext *s, int n, char *file, char *func, int line){
- int r= get_bits(s, n);
-
- print_bin(r, n);
- printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
- return r;
-}
-static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, char *func, int line){
- int show= show_bits(s, 24);
- int pos= get_bits_count(s);
- int r= get_vlc2(s, table, bits, max_depth);
- int len= get_bits_count(s) - pos;
- int bits2= show>>(24-len);
-
- print_bin(bits2, len);
-
- printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
- return r;
-}
-static inline int get_xbits_trace(GetBitContext *s, int n, char *file, char *func, int line){
- int show= show_bits(s, n);
- int r= get_xbits(s, n);
-
- print_bin(show, n);
- printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
- return r;
-}
-
-#define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-
-#define tprintf printf
-
-#else //TRACE
-#define tprintf(_arg...) {}
-#endif
-
-/* define it to include statistics code (useful only for optimizing
- codec efficiency */
-//#define STATS
-
-#ifdef STATS
-
-enum {
- ST_UNKNOWN,
- ST_DC,
- ST_INTRA_AC,
- ST_INTER_AC,
- ST_INTRA_MB,
- ST_INTER_MB,
- ST_MV,
- ST_NB,
-};
-
-extern int st_current_index;
-extern unsigned int st_bit_counts[ST_NB];
-extern unsigned int st_out_bit_counts[ST_NB];
-
-void print_stats(void);
-#endif
-
-/* misc math functions */
-extern const uint8_t ff_log2_tab[256];
-
-static inline int av_log2(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xffff0000) {
- v >>= 16;
- n += 16;
- }
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
-static inline int av_log2_16bit(unsigned int v)
-{
- int n;
-
- n = 0;
- if (v & 0xff00) {
- v >>= 8;
- n += 8;
- }
- n += ff_log2_tab[v];
-
- return n;
-}
-
-
-/* median of 3 */
-static inline int mid_pred(int a, int b, int c)
-{
- int vmin, vmax;
- vmax = vmin = a;
- if (b < vmin)
- vmin = b;
- else
- vmax = b;
-
- if (c < vmin)
- vmin = c;
- else if (c > vmax)
- vmax = c;
-
- return a + b + c - vmin - vmax;
-}
-
-static inline int clip(int a, int amin, int amax)
-{
- if (a < amin)
- return amin;
- else if (a > amax)
- return amax;
- else
- return a;
-}
-
-/* math */
-extern const uint8_t ff_sqrt_tab[128];
-
-int64_t ff_gcd(int64_t a, int64_t b);
-
-static inline int ff_sqrt(int a)
-{
- int ret=0;
- int s;
- int ret_sq=0;
-
- if(a<128) return ff_sqrt_tab[a];
-
- for(s=15; s>=0; s--){
- int b= ret_sq + (1<<(s*2)) + (ret<<s)*2;
- if(b<=a){
- ret_sq=b;
- ret+= 1<<s;
- }
- }
- return ret;
-}
-
-/**
- * converts fourcc string to int
- */
-static inline int ff_get_fourcc(const char *s){
- assert( strlen(s)==4 );
-
- return (s[0]) + (s[1]<<8) + (s[2]<<16) + (s[3]<<24);
-}
-
-#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
-#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
-
-
-void ff_float2fraction(int *nom_arg, int *denom_arg, double f, int max);
-
-
-#ifdef ARCH_X86
-#define MASK_ABS(mask, level)\
- asm volatile(\
- "cdq \n\t"\
- "xorl %1, %0 \n\t"\
- "subl %1, %0 \n\t"\
- : "+a" (level), "=&d" (mask)\
- );
-#else
-#define MASK_ABS(mask, level)\
- mask= level>>31;\
- level= (level^mask)-mask;
-#endif
-
-
-#if __CPU__ >= 686 && !defined(RUNTIME_CPUDETECT)
-#define COPY3_IF_LT(x,y,a,b,c,d)\
-asm volatile (\
- "cmpl %0, %3 \n\t"\
- "cmovl %3, %0 \n\t"\
- "cmovl %4, %1 \n\t"\
- "cmovl %5, %2 \n\t"\
- : "+r" (x), "+r" (a), "+r" (c)\
- : "r" (y), "r" (b), "r" (d)\
-);
-#else
-#define COPY3_IF_LT(x,y,a,b,c,d)\
-if((y)<(x)){\
- (x)=(y);\
- (a)=(b);\
- (c)=(d);\
-}
-#endif
-
-#ifdef ARCH_X86
-static inline long long rdtsc()
-{
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
- return l;
-}
-
-#define START_TIMER \
-static uint64_t tsum=0;\
-static int tcount=0;\
-static int tskip_count=0;\
-uint64_t tend;\
-uint64_t tstart= rdtsc();\
-
-#define STOP_TIMER(id) \
-tend= rdtsc();\
-if(tcount<2 || tend - tstart < 4*tsum/tcount){\
- tsum+= tend - tstart;\
- tcount++;\
-}else\
- tskip_count++;\
-if(256*256*256*64%(tcount+tskip_count)==0){\
- fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
-}
-#endif
-
-#define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)
-
-/* avoid usage of various functions */
-#define malloc please_use_av_malloc
-#define free please_use_av_free
-#define realloc please_use_av_realloc
-
-#define CHECKED_ALLOCZ(p, size)\
-{\
- p= av_mallocz(size);\
- if(p==NULL && (size)!=0){\
- perror("malloc");\
- goto fail;\
- }\
-}
-
-#endif /* HAVE_AV_CONFIG_H */
-
-#endif /* COMMON_H */
+++ /dev/null
-/*
- *
- * Copyright (C) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Creative YUV (CYUV) Video Decoder
- * by Mike Melanson (melanson@pcisys.net)
- * based on "Creative YUV (CYUV) stream format for AVI":
- * http://www.csse.monash.edu.au/~timf/videocodec/cyuv.txt
- *
- */
-
-/**
- * @file cyuv.c
- * Creative YUV (CYUV) Video Decoder.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-
-typedef struct CyuvDecodeContext {
- AVCodecContext *avctx;
- int width, height;
- AVFrame frame;
-} CyuvDecodeContext;
-
-static int cyuv_decode_init(AVCodecContext *avctx)
-{
- CyuvDecodeContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->width = avctx->width;
- s->height = avctx->height;
- avctx->pix_fmt = PIX_FMT_YUV411P;
- avctx->has_b_frames = 0;
-
- return 0;
-}
-
-static int cyuv_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- CyuvDecodeContext *s=avctx->priv_data;
-
- unsigned char *y_plane;
- unsigned char *u_plane;
- unsigned char *v_plane;
- int y_ptr;
- int u_ptr;
- int v_ptr;
-
- /* prediction error tables (make it clear that they are signed values) */
- signed char *y_table = buf + 0;
- signed char *u_table = buf + 16;
- signed char *v_table = buf + 32;
-
- unsigned char y_pred, u_pred, v_pred;
- int stream_ptr;
- unsigned char cur_byte;
- int pixel_groups;
-
- *data_size = 0;
-
- /* sanity check the buffer size: A buffer has 3x16-bytes tables
- * followed by (height) lines each with 3 bytes to represent groups
- * of 4 pixels. Thus, the total size of the buffer ought to be:
- * (3 * 16) + height * (width * 3 / 4) */
- if (buf_size != 48 + s->height * (s->width * 3 / 4)) {
- printf ("ffmpeg: cyuv: got a buffer with %d bytes when %d were expected\n",
- buf_size,
- 48 + s->height * (s->width * 3 / 4));
- return -1;
- }
-
- /* pixel data starts 48 bytes in, after 3x16-byte tables */
- stream_ptr = 48;
-
- if(s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- s->frame.reference = 0;
- if(avctx->get_buffer(avctx, &s->frame) < 0) {
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- y_plane = s->frame.data[0];
- u_plane = s->frame.data[1];
- v_plane = s->frame.data[2];
-
- /* iterate through each line in the height */
- for (y_ptr = 0, u_ptr = 0, v_ptr = 0;
- y_ptr < (s->height * s->frame.linesize[0]);
- y_ptr += s->frame.linesize[0] - s->width,
- u_ptr += s->frame.linesize[1] - s->width / 4,
- v_ptr += s->frame.linesize[2] - s->width / 4) {
-
- /* reset predictors */
- cur_byte = buf[stream_ptr++];
- u_plane[u_ptr++] = u_pred = cur_byte & 0xF0;
- y_plane[y_ptr++] = y_pred = (cur_byte & 0x0F) << 4;
-
- cur_byte = buf[stream_ptr++];
- v_plane[v_ptr++] = v_pred = cur_byte & 0xF0;
- y_pred += y_table[cur_byte & 0x0F];
- y_plane[y_ptr++] = y_pred;
-
- cur_byte = buf[stream_ptr++];
- y_pred += y_table[cur_byte & 0x0F];
- y_plane[y_ptr++] = y_pred;
- y_pred += y_table[(cur_byte & 0xF0) >> 4];
- y_plane[y_ptr++] = y_pred;
-
- /* iterate through the remaining pixel groups (4 pixels/group) */
- pixel_groups = s->width / 4 - 1;
- while (pixel_groups--) {
-
- cur_byte = buf[stream_ptr++];
- u_pred += u_table[(cur_byte & 0xF0) >> 4];
- u_plane[u_ptr++] = u_pred;
- y_pred += y_table[cur_byte & 0x0F];
- y_plane[y_ptr++] = y_pred;
-
- cur_byte = buf[stream_ptr++];
- v_pred += v_table[(cur_byte & 0xF0) >> 4];
- v_plane[v_ptr++] = v_pred;
- y_pred += y_table[cur_byte & 0x0F];
- y_plane[y_ptr++] = y_pred;
-
- cur_byte = buf[stream_ptr++];
- y_pred += y_table[cur_byte & 0x0F];
- y_plane[y_ptr++] = y_pred;
- y_pred += y_table[(cur_byte & 0xF0) >> 4];
- y_plane[y_ptr++] = y_pred;
-
- }
- }
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data= s->frame;
-
- return buf_size;
-}
-
-static int cyuv_decode_end(AVCodecContext *avctx)
-{
-/* CyuvDecodeContext *s = avctx->priv_data;*/
-
- return 0;
-}
-
-AVCodec cyuv_decoder = {
- "cyuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_CYUV,
- sizeof(CyuvDecodeContext),
- cyuv_decode_init,
- NULL,
- cyuv_decode_end,
- cyuv_decode_frame,
- 0,
- NULL
-};
-
+++ /dev/null
-/**
- * @file dct-test.c
- * DCT test. (c) 2001 Fabrice Bellard.
- * Started from sample code by Juan J. Sierralta P.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
-
-#include "dsputil.h"
-
-#include "i386/mmx.h"
-#include "simple_idct.h"
-
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-/* reference fdct/idct */
-extern void fdct(DCTELEM *block);
-extern void idct(DCTELEM *block);
-extern void init_fdct();
-
-extern void j_rev_dct(DCTELEM *data);
-extern void ff_mmx_idct(DCTELEM *data);
-extern void ff_mmxext_idct(DCTELEM *data);
-
-extern void odivx_idct_c (short *block);
-
-#define AANSCALE_BITS 12
-static const unsigned short aanscales[64] = {
- /* precomputed values scaled up by 14 bits */
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
- 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
- 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
- 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
- 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
-};
-
-uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
-
-int64_t gettime(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-#define NB_ITS 20000
-#define NB_ITS_SPEED 50000
-
-static short idct_mmx_perm[64];
-
-static short idct_simple_mmx_perm[64]={
- 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
- 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
- 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
- 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
- 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
- 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
- 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
- 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
-};
-
-void idct_mmx_init(void)
-{
- int i;
-
- /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */
- for (i = 0; i < 64; i++) {
- idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
-// idct_simple_mmx_perm[i] = simple_block_permute_op(i);
- }
-}
-
-static DCTELEM block[64] __attribute__ ((aligned (8)));
-static DCTELEM block1[64] __attribute__ ((aligned (8)));
-static DCTELEM block_org[64] __attribute__ ((aligned (8)));
-
-void dct_error(const char *name, int is_idct,
- void (*fdct_func)(DCTELEM *block),
- void (*fdct_ref)(DCTELEM *block), int test)
-{
- int it, i, scale;
- int err_inf, v;
- int64_t err2, ti, ti1, it1;
- int64_t sysErr[64], sysErrMax=0;
- int maxout=0;
- int blockSumErrMax=0, blockSumErr;
-
- srandom(0);
-
- err_inf = 0;
- err2 = 0;
- for(i=0; i<64; i++) sysErr[i]=0;
- for(it=0;it<NB_ITS;it++) {
- for(i=0;i<64;i++)
- block1[i] = 0;
- switch(test){
- case 0:
- for(i=0;i<64;i++)
- block1[i] = (random() % 512) -256;
- if (is_idct){
- fdct(block1);
-
- for(i=0;i<64;i++)
- block1[i]>>=3;
- }
- break;
- case 1:{
- int num= (random()%10)+1;
- for(i=0;i<num;i++)
- block1[random()%64] = (random() % 512) -256;
- }break;
- case 2:
- block1[0]= (random()%4096)-2048;
- block1[63]= (block1[0]&1)^1;
- break;
- }
-
-#if 0 // simulate mismatch control
-{ int sum=0;
- for(i=0;i<64;i++)
- sum+=block1[i];
-
- if((sum&1)==0) block1[63]^=1;
-}
-#endif
-
- for(i=0; i<64; i++)
- block_org[i]= block1[i];
-
- if (fdct_func == ff_mmx_idct ||
- fdct_func == j_rev_dct || fdct_func == ff_mmxext_idct) {
- for(i=0;i<64;i++)
- block[idct_mmx_perm[i]] = block1[i];
- } else if(fdct_func == ff_simple_idct_mmx ) {
- for(i=0;i<64;i++)
- block[idct_simple_mmx_perm[i]] = block1[i];
-
- } else {
- for(i=0; i<64; i++)
- block[i]= block1[i];
- }
-#if 0 // simulate mismatch control for tested IDCT but not the ref
-{ int sum=0;
- for(i=0;i<64;i++)
- sum+=block[i];
-
- if((sum&1)==0) block[63]^=1;
-}
-#endif
-
- fdct_func(block);
- emms(); /* for ff_mmx_idct */
-
- if (fdct_func == fdct_ifast) {
- for(i=0; i<64; i++) {
- scale = 8*(1 << (AANSCALE_BITS + 11)) / aanscales[i];
- block[i] = (block[i] * scale /*+ (1<<(AANSCALE_BITS-1))*/) >> AANSCALE_BITS;
- }
- }
-
- fdct_ref(block1);
-
- blockSumErr=0;
- for(i=0;i<64;i++) {
- v = abs(block[i] - block1[i]);
- if (v > err_inf)
- err_inf = v;
- err2 += v * v;
- sysErr[i] += block[i] - block1[i];
- blockSumErr += v;
- if( abs(block[i])>maxout) maxout=abs(block[i]);
- }
- if(blockSumErrMax < blockSumErr) blockSumErrMax= blockSumErr;
-#if 0 // print different matrix pairs
- if(blockSumErr){
- printf("\n");
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%4d ", block_org[i]);
- }
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%4d ", block[i] - block1[i]);
- }
- }
-#endif
- }
- for(i=0; i<64; i++) sysErrMax= MAX(sysErrMax, ABS(sysErr[i]));
-
-#if 1 // dump systematic errors
- for(i=0; i<64; i++){
- if(i%8==0) printf("\n");
- printf("%5d ", (int)sysErr[i]);
- }
- printf("\n");
-#endif
-
- printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n",
- is_idct ? "IDCT" : "DCT",
- name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax);
-#if 1 //Speed test
- /* speed test */
- for(i=0;i<64;i++)
- block1[i] = 0;
- switch(test){
- case 0:
- for(i=0;i<64;i++)
- block1[i] = (random() % 512) -256;
- if (is_idct){
- fdct(block1);
-
- for(i=0;i<64;i++)
- block1[i]>>=3;
- }
- break;
- case 1:{
- case 2:
- block1[0] = (random() % 512) -256;
- block1[1] = (random() % 512) -256;
- block1[2] = (random() % 512) -256;
- block1[3] = (random() % 512) -256;
- }break;
- }
-
- if (fdct_func == ff_mmx_idct ||
- fdct_func == j_rev_dct || fdct_func == ff_mmxext_idct) {
- for(i=0;i<64;i++)
- block[idct_mmx_perm[i]] = block1[i];
- } else if(fdct_func == ff_simple_idct_mmx ) {
- for(i=0;i<64;i++)
- block[idct_simple_mmx_perm[i]] = block1[i];
- } else {
- for(i=0; i<64; i++)
- block[i]= block1[i];
- }
-
- ti = gettime();
- it1 = 0;
- do {
- for(it=0;it<NB_ITS_SPEED;it++) {
- for(i=0; i<64; i++)
- block[i]= block1[i];
-// memcpy(block, block1, sizeof(DCTELEM) * 64);
-// dont memcpy especially not fastmemcpy because it does movntq !!!
- fdct_func(block);
- }
- it1 += NB_ITS_SPEED;
- ti1 = gettime() - ti;
- } while (ti1 < 1000000);
- emms();
-
- printf("%s %s: %0.1f kdct/s\n",
- is_idct ? "IDCT" : "DCT",
- name, (double)it1 * 1000.0 / (double)ti1);
-#endif
-}
-
-static uint8_t img_dest[64] __attribute__ ((aligned (8)));
-static uint8_t img_dest1[64] __attribute__ ((aligned (8)));
-
-void idct248_ref(uint8_t *dest, int linesize, int16_t *block)
-{
- static int init;
- static double c8[8][8];
- static double c4[4][4];
- double block1[64], block2[64], block3[64];
- double s, sum, v;
- int i, j, k;
-
- if (!init) {
- init = 1;
-
- for(i=0;i<8;i++) {
- sum = 0;
- for(j=0;j<8;j++) {
- s = (i==0) ? sqrt(1.0/8.0) : sqrt(1.0/4.0);
- c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0);
- sum += c8[i][j] * c8[i][j];
- }
- }
-
- for(i=0;i<4;i++) {
- sum = 0;
- for(j=0;j<4;j++) {
- s = (i==0) ? sqrt(1.0/4.0) : sqrt(1.0/2.0);
- c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0);
- sum += c4[i][j] * c4[i][j];
- }
- }
- }
-
- /* butterfly */
- s = 0.5 * sqrt(2.0);
- for(i=0;i<4;i++) {
- for(j=0;j<8;j++) {
- block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * s;
- block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * s;
- }
- }
-
- /* idct8 on lines */
- for(i=0;i<8;i++) {
- for(j=0;j<8;j++) {
- sum = 0;
- for(k=0;k<8;k++)
- sum += c8[k][j] * block1[8*i+k];
- block2[8*i+j] = sum;
- }
- }
-
- /* idct4 */
- for(i=0;i<8;i++) {
- for(j=0;j<4;j++) {
- /* top */
- sum = 0;
- for(k=0;k<4;k++)
- sum += c4[k][j] * block2[8*(2*k)+i];
- block3[8*(2*j)+i] = sum;
-
- /* bottom */
- sum = 0;
- for(k=0;k<4;k++)
- sum += c4[k][j] * block2[8*(2*k+1)+i];
- block3[8*(2*j+1)+i] = sum;
- }
- }
-
- /* clamp and store the result */
- for(i=0;i<8;i++) {
- for(j=0;j<8;j++) {
- v = block3[8*i+j];
- if (v < 0)
- v = 0;
- else if (v > 255)
- v = 255;
- dest[i * linesize + j] = (int)rint(v);
- }
- }
-}
-
-void idct248_error(const char *name,
- void (*idct248_put)(uint8_t *dest, int line_size, int16_t *block))
-{
- int it, i, it1, ti, ti1, err_max, v;
-
- srandom(0);
-
- /* just one test to see if code is correct (precision is less
- important here) */
- err_max = 0;
- for(it=0;it<NB_ITS;it++) {
-
- /* XXX: use forward transform to generate values */
- for(i=0;i<64;i++)
- block1[i] = (random() % 256) - 128;
- block1[0] += 1024;
-
- for(i=0; i<64; i++)
- block[i]= block1[i];
- idct248_ref(img_dest1, 8, block);
-
- for(i=0; i<64; i++)
- block[i]= block1[i];
- idct248_put(img_dest, 8, block);
-
- for(i=0;i<64;i++) {
- v = abs((int)img_dest[i] - (int)img_dest1[i]);
- if (v == 255)
- printf("%d %d\n", img_dest[i], img_dest1[i]);
- if (v > err_max)
- err_max = v;
- }
-#if 0
- printf("ref=\n");
- for(i=0;i<8;i++) {
- int j;
- for(j=0;j<8;j++) {
- printf(" %3d", img_dest1[i*8+j]);
- }
- printf("\n");
- }
-
- printf("out=\n");
- for(i=0;i<8;i++) {
- int j;
- for(j=0;j<8;j++) {
- printf(" %3d", img_dest[i*8+j]);
- }
- printf("\n");
- }
-#endif
- }
- printf("%s %s: err_inf=%d\n",
- 1 ? "IDCT248" : "DCT248",
- name, err_max);
-
- ti = gettime();
- it1 = 0;
- do {
- for(it=0;it<NB_ITS_SPEED;it++) {
- for(i=0; i<64; i++)
- block[i]= block1[i];
-// memcpy(block, block1, sizeof(DCTELEM) * 64);
-// dont memcpy especially not fastmemcpy because it does movntq !!!
- idct248_put(img_dest, 8, block);
- }
- it1 += NB_ITS_SPEED;
- ti1 = gettime() - ti;
- } while (ti1 < 1000000);
- emms();
-
- printf("%s %s: %0.1f kdct/s\n",
- 1 ? "IDCT248" : "DCT248",
- name, (double)it1 * 1000.0 / (double)ti1);
-}
-
-void help(void)
-{
- printf("dct-test [-i] [<test-number>]\n"
- "test-number 0 -> test with random matrixes\n"
- " 1 -> test with random sparse matrixes\n"
- " 2 -> do 3. test from mpeg4 std\n"
- "-i test IDCT implementations\n"
- "-4 test IDCT248 implementations\n");
- exit(1);
-}
-
-int main(int argc, char **argv)
-{
- int test_idct = 0, test_248_dct = 0;
- int c,i;
- int test=1;
-
- init_fdct();
- idct_mmx_init();
-
- for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
- for(i=0;i<MAX_NEG_CROP;i++) {
- cropTbl[i] = 0;
- cropTbl[i + MAX_NEG_CROP + 256] = 255;
- }
-
- for(;;) {
- c = getopt(argc, argv, "ih4");
- if (c == -1)
- break;
- switch(c) {
- case 'i':
- test_idct = 1;
- break;
- case '4':
- test_248_dct = 1;
- break;
- default :
- case 'h':
- help();
- break;
- }
- }
-
- if(optind <argc) test= atoi(argv[optind]);
-
- printf("ffmpeg DCT/IDCT test\n");
-
- if (test_248_dct) {
- idct248_error("SIMPLE-C", simple_idct248_put);
- } else {
- if (!test_idct) {
- dct_error("REF-DBL", 0, fdct, fdct, test); /* only to verify code ! */
- dct_error("IJG-AAN-INT", 0, fdct_ifast, fdct, test);
- dct_error("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, test);
- dct_error("MMX", 0, ff_fdct_mmx, fdct, test);
- } else {
- dct_error("REF-DBL", 1, idct, idct, test);
- dct_error("INT", 1, j_rev_dct, idct, test);
- dct_error("LIBMPEG2-MMX", 1, ff_mmx_idct, idct, test);
- dct_error("LIBMPEG2-MMXEXT", 1, ff_mmxext_idct, idct, test);
- dct_error("SIMPLE-C", 1, simple_idct, idct, test);
- dct_error("SIMPLE-MMX", 1, ff_simple_idct_mmx, idct, test);
- // dct_error("ODIVX-C", 1, odivx_idct_c, idct);
- //printf(" test against odivx idct\n");
- // dct_error("REF", 1, idct, odivx_idct_c);
- // dct_error("INT", 1, j_rev_dct, odivx_idct_c);
- // dct_error("MMX", 1, ff_mmx_idct, odivx_idct_c);
- // dct_error("MMXEXT", 1, ff_mmxext_idct, odivx_idct_c);
- // dct_error("SIMPLE-C", 1, simple_idct, odivx_idct_c);
- // dct_error("SIMPLE-MMX", 1, ff_simple_idct_mmx, odivx_idct_c);
- // dct_error("ODIVX-C", 1, odivx_idct_c, odivx_idct_c);
- }
- }
- return 0;
-}
+++ /dev/null
-/*
- * Assorted DPCM codecs
- * Copyright (c) 2003 The ffmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file: dpcm.c
- * Assorted DPCM (differential pulse code modulation) audio codecs
- * by Mike Melanson (melanson@pcisys.net)
- * Xan DPCM decoder by Mario Brito (mbrito@student.dei.uc.pt)
- * for more information on the specific data formats, visit:
- * http://www.pcisys.net/~melanson/codecs/simpleaudio.html
- *
- * Note about using the Xan DPCM decoder: Xan DPCM is used in AVI files
- * found in the Wing Commander IV computer game. These AVI files contain
- * WAVEFORMAT headers which report the audio format as 0x01: raw PCM.
- * Clearly incorrect. To detect Xan DPCM, you will probably have to
- * special-case your AVI demuxer to use Xan DPCM if the file uses 'Xxan'
- * (Xan video) for its video codec. Alternately, such AVI files also contain
- * the fourcc 'Axan' in the 'auds' chunk of the AVI header.
- */
-
-#include "avcodec.h"
-
-typedef struct DPCMContext {
- int channels;
- short roq_square_array[256];
-} DPCMContext;
-
-#define SATURATE_S16(x) if (x < -32768) x = -32768; \
- else if (x > 32767) x = 32767;
-#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000;
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-static int interplay_delta_table[] = {
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 47, 51, 56, 61,
- 66, 72, 79, 86, 94, 102, 112, 122,
- 133, 145, 158, 173, 189, 206, 225, 245,
- 267, 292, 318, 348, 379, 414, 452, 493,
- 538, 587, 640, 699, 763, 832, 908, 991,
- 1081, 1180, 1288, 1405, 1534, 1673, 1826, 1993,
- 2175, 2373, 2590, 2826, 3084, 3365, 3672, 4008,
- 4373, 4772, 5208, 5683, 6202, 6767, 7385, 8059,
- 8794, 9597, 10472, 11428, 12471, 13609, 14851, 16206,
- 17685, 19298, 21060, 22981, 25078, 27367, 29864, 32589,
- -29973, -26728, -23186, -19322, -15105, -10503, -5481, -1,
- 1, 1, 5481, 10503, 15105, 19322, 23186, 26728,
- 29973, -32589, -29864, -27367, -25078, -22981, -21060, -19298,
- -17685, -16206, -14851, -13609, -12471, -11428, -10472, -9597,
- -8794, -8059, -7385, -6767, -6202, -5683, -5208, -4772,
- -4373, -4008, -3672, -3365, -3084, -2826, -2590, -2373,
- -2175, -1993, -1826, -1673, -1534, -1405, -1288, -1180,
- -1081, -991, -908, -832, -763, -699, -640, -587,
- -538, -493, -452, -414, -379, -348, -318, -292,
- -267, -245, -225, -206, -189, -173, -158, -145,
- -133, -122, -112, -102, -94, -86, -79, -72,
- -66, -61, -56, -51, -47, -43, -42, -41,
- -40, -39, -38, -37, -36, -35, -34, -33,
- -32, -31, -30, -29, -28, -27, -26, -25,
- -24, -23, -22, -21, -20, -19, -18, -17,
- -16, -15, -14, -13, -12, -11, -10, -9,
- -8, -7, -6, -5, -4, -3, -2, -1
-
-};
-
-static int dpcm_decode_init(AVCodecContext *avctx)
-{
- DPCMContext *s = avctx->priv_data;
- int i;
- short square;
-
- s->channels = avctx->channels;
-
- switch(avctx->codec->id) {
-
- case CODEC_ID_ROQ_DPCM:
- /* initialize square table */
- for (i = 0; i < 128; i++) {
- square = i * i;
- s->roq_square_array[i] = square;
- s->roq_square_array[i + 128] = -square;
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-static int dpcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- DPCMContext *s = avctx->priv_data;
- int in, out = 0;
- int predictor[2];
- int channel_number = 0;
- short *output_samples = data;
- int shift[2];
- unsigned char byte;
- short diff;
-
- switch(avctx->codec->id) {
-
- case CODEC_ID_ROQ_DPCM:
- if (s->channels == 1)
- predictor[0] = LE_16(&buf[6]);
- else {
- predictor[0] = buf[7] << 8;
- predictor[1] = buf[6] << 8;
- }
- SE_16BIT(predictor[0]);
- SE_16BIT(predictor[1]);
-
- /* decode the samples */
- for (in = 8, out = 0; in < buf_size; in++, out++) {
- predictor[channel_number] += s->roq_square_array[buf[in]];
- SATURATE_S16(predictor[channel_number]);
- output_samples[out] = predictor[channel_number];
-
- /* toggle channel */
- channel_number ^= s->channels - 1;
- }
- break;
-
- case CODEC_ID_INTERPLAY_DPCM:
- in = 6; /* skip over the stream mask and stream length */
- predictor[0] = LE_16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[0])
- output_samples[out++] = predictor[0];
- if (s->channels == 2) {
- predictor[1] = LE_16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[1])
- output_samples[out++] = predictor[1];
- }
-
- while (in < buf_size) {
- predictor[channel_number] += interplay_delta_table[buf[in++]];
- SATURATE_S16(predictor[channel_number]);
- output_samples[out++] = predictor[channel_number];
-
- /* toggle channel */
- channel_number ^= s->channels - 1;
- }
-
- break;
-
- case CODEC_ID_XAN_DPCM:
- in = 0;
- shift[0] = shift[1] = 4;
- predictor[0] = LE_16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[0]);
- if (s->channels == 2) {
- predictor[1] = LE_16(&buf[in]);
- in += 2;
- SE_16BIT(predictor[1]);
- }
-
- while (in < buf_size) {
- byte = buf[in++];
- diff = (byte & 0xFC) << 8;
- if ((byte & 0x03) == 3)
- shift[channel_number]++;
- else
- shift[channel_number] -= (2 * (byte & 3));
- /* saturate the shifter to a lower limit of 0 */
- if (shift[channel_number] < 0)
- shift[channel_number] = 0;
-
- diff >>= shift[channel_number];
- predictor[channel_number] += diff;
-
- SATURATE_S16(predictor[channel_number]);
- output_samples[out++] = predictor[channel_number];
-
- /* toggle channel */
- channel_number ^= s->channels - 1;
- }
- break;
- }
-
- *data_size = out * sizeof(short);
- return buf_size;
-}
-
-AVCodec roq_dpcm_decoder = {
- "roq_dpcm",
- CODEC_TYPE_AUDIO,
- CODEC_ID_ROQ_DPCM,
- sizeof(DPCMContext),
- dpcm_decode_init,
- NULL,
- NULL,
- dpcm_decode_frame,
-};
-
-AVCodec interplay_dpcm_decoder = {
- "interplay_dpcm",
- CODEC_TYPE_AUDIO,
- CODEC_ID_INTERPLAY_DPCM,
- sizeof(DPCMContext),
- dpcm_decode_init,
- NULL,
- NULL,
- dpcm_decode_frame,
-};
-
-AVCodec xan_dpcm_decoder = {
- "xan_dpcm",
- CODEC_TYPE_AUDIO,
- CODEC_ID_XAN_DPCM,
- sizeof(DPCMContext),
- dpcm_decode_init,
- NULL,
- NULL,
- dpcm_decode_frame,
-};
+++ /dev/null
-/*
- * DSP utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file dsputil.c
- * DSP utils
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "simple_idct.h"
-
-
-uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
-uint32_t squareTbl[512];
-
-const uint8_t ff_zigzag_direct[64] = {
- 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
-};
-
-/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
-uint16_t __align8 inv_zigzag_direct16[64];
-
-const uint8_t ff_alternate_horizontal_scan[64] = {
- 0, 1, 2, 3, 8, 9, 16, 17,
- 10, 11, 4, 5, 6, 7, 15, 14,
- 13, 12, 19, 18, 24, 25, 32, 33,
- 26, 27, 20, 21, 22, 23, 28, 29,
- 30, 31, 34, 35, 40, 41, 48, 49,
- 42, 43, 36, 37, 38, 39, 44, 45,
- 46, 47, 50, 51, 56, 57, 58, 59,
- 52, 53, 54, 55, 60, 61, 62, 63,
-};
-
-const uint8_t ff_alternate_vertical_scan[64] = {
- 0, 8, 16, 24, 1, 9, 2, 10,
- 17, 25, 32, 40, 48, 56, 57, 49,
- 41, 33, 26, 18, 3, 11, 4, 12,
- 19, 27, 34, 42, 50, 58, 35, 43,
- 51, 59, 20, 28, 5, 13, 6, 14,
- 21, 29, 36, 44, 52, 60, 37, 45,
- 53, 61, 22, 30, 7, 15, 23, 31,
- 38, 46, 54, 62, 39, 47, 55, 63,
-};
-
-/* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */
-const uint32_t inverse[256]={
- 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757,
- 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154,
- 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709,
- 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333,
- 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367,
- 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283,
- 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315,
- 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085,
- 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498,
- 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675,
- 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441,
- 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183,
- 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712,
- 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400,
- 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163,
- 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641,
- 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573,
- 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737,
- 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493,
- 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373,
- 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368,
- 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671,
- 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767,
- 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740,
- 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751,
- 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635,
- 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593,
- 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944,
- 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933,
- 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575,
- 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532,
- 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010,
-};
-
-/* Input permutation for the simple_idct_mmx */
-static const uint8_t simple_mmx_permutation[64]={
- 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D,
- 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D,
- 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D,
- 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F,
- 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F,
- 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D,
- 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F,
- 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F,
-};
-
-static int pix_sum_c(uint8_t * pix, int line_size)
-{
- int s, i, j;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
- s += pix[0];
- s += pix[1];
- s += pix[2];
- s += pix[3];
- s += pix[4];
- s += pix[5];
- s += pix[6];
- s += pix[7];
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-
-static int pix_norm1_c(uint8_t * pix, int line_size)
-{
- int s, i, j;
- uint32_t *sq = squareTbl + 256;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
-#if 0
- s += sq[pix[0]];
- s += sq[pix[1]];
- s += sq[pix[2]];
- s += sq[pix[3]];
- s += sq[pix[4]];
- s += sq[pix[5]];
- s += sq[pix[6]];
- s += sq[pix[7]];
-#else
-#if LONG_MAX > 2147483647
- register uint64_t x=*(uint64_t*)pix;
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
- s += sq[(x>>32)&0xff];
- s += sq[(x>>40)&0xff];
- s += sq[(x>>48)&0xff];
- s += sq[(x>>56)&0xff];
-#else
- register uint32_t x=*(uint32_t*)pix;
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
- x=*(uint32_t*)(pix+4);
- s += sq[x&0xff];
- s += sq[(x>>8)&0xff];
- s += sq[(x>>16)&0xff];
- s += sq[(x>>24)&0xff];
-#endif
-#endif
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-
-static void bswap_buf(uint32_t *dst, uint32_t *src, int w){
- int i;
-
- for(i=0; i+8<=w; i+=8){
- dst[i+0]= bswap_32(src[i+0]);
- dst[i+1]= bswap_32(src[i+1]);
- dst[i+2]= bswap_32(src[i+2]);
- dst[i+3]= bswap_32(src[i+3]);
- dst[i+4]= bswap_32(src[i+4]);
- dst[i+5]= bswap_32(src[i+5]);
- dst[i+6]= bswap_32(src[i+6]);
- dst[i+7]= bswap_32(src[i+7]);
- }
- for(;i<w; i++){
- dst[i+0]= bswap_32(src[i+0]);
- }
-}
-
-static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size)
-{
- int s, i;
- uint32_t *sq = squareTbl + 256;
-
- s = 0;
- for (i = 0; i < 8; i++) {
- s += sq[pix1[0] - pix2[0]];
- s += sq[pix1[1] - pix2[1]];
- s += sq[pix1[2] - pix2[2]];
- s += sq[pix1[3] - pix2[3]];
- s += sq[pix1[4] - pix2[4]];
- s += sq[pix1[5] - pix2[5]];
- s += sq[pix1[6] - pix2[6]];
- s += sq[pix1[7] - pix2[7]];
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
- uint32_t *sq = squareTbl + 256;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- s += sq[pix1[ 0] - pix2[ 0]];
- s += sq[pix1[ 1] - pix2[ 1]];
- s += sq[pix1[ 2] - pix2[ 2]];
- s += sq[pix1[ 3] - pix2[ 3]];
- s += sq[pix1[ 4] - pix2[ 4]];
- s += sq[pix1[ 5] - pix2[ 5]];
- s += sq[pix1[ 6] - pix2[ 6]];
- s += sq[pix1[ 7] - pix2[ 7]];
- s += sq[pix1[ 8] - pix2[ 8]];
- s += sq[pix1[ 9] - pix2[ 9]];
- s += sq[pix1[10] - pix2[10]];
- s += sq[pix1[11] - pix2[11]];
- s += sq[pix1[12] - pix2[12]];
- s += sq[pix1[13] - pix2[13]];
- s += sq[pix1[14] - pix2[14]];
- s += sq[pix1[15] - pix2[15]];
-
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
-{
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- block[0] = pixels[0];
- block[1] = pixels[1];
- block[2] = pixels[2];
- block[3] = pixels[3];
- block[4] = pixels[4];
- block[5] = pixels[5];
- block[6] = pixels[6];
- block[7] = pixels[7];
- pixels += line_size;
- block += 8;
- }
-}
-
-static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1,
- const uint8_t *s2, int stride){
- int i;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- block[0] = s1[0] - s2[0];
- block[1] = s1[1] - s2[1];
- block[2] = s1[2] - s2[2];
- block[3] = s1[3] - s2[3];
- block[4] = s1[4] - s2[4];
- block[5] = s1[5] - s2[5];
- block[6] = s1[6] - s2[6];
- block[7] = s1[7] - s2[7];
- s1 += stride;
- s2 += stride;
- block += 8;
- }
-}
-
-
-static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- pixels[0] = cm[block[0]];
- pixels[1] = cm[block[1]];
- pixels[2] = cm[block[2]];
- pixels[3] = cm[block[3]];
- pixels[4] = cm[block[4]];
- pixels[5] = cm[block[5]];
- pixels[6] = cm[block[6]];
- pixels[7] = cm[block[7]];
-
- pixels += line_size;
- block += 8;
- }
-}
-
-static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels,
- int line_size)
-{
- int i;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- /* read the pixels */
- for(i=0;i<8;i++) {
- pixels[0] = cm[pixels[0] + block[0]];
- pixels[1] = cm[pixels[1] + block[1]];
- pixels[2] = cm[pixels[2] + block[2]];
- pixels[3] = cm[pixels[3] + block[3]];
- pixels[4] = cm[pixels[4] + block[4]];
- pixels[5] = cm[pixels[5] + block[5]];
- pixels[6] = cm[pixels[6] + block[6]];
- pixels[7] = cm[pixels[7] + block[7]];
- pixels += line_size;
- block += 8;
- }
-}
-#if 0
-
-#define PIXOP2(OPNAME, OP) \
-static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint64_t*)block), LD64(pixels));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+line_size);\
- OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- for(i=0; i<h; i++){\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+line_size);\
- OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= LD64(pixels );\
- uint64_t b= LD64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD64(pixels );\
- b= LD64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0202020202020202ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint64_t a= LD64(pixels );\
- const uint64_t b= LD64(pixels+1);\
- uint64_t l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- uint64_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint64_t a= LD64(pixels );\
- uint64_t b= LD64(pixels+1);\
- l1= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL);\
- h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD64(pixels );\
- b= LD64(pixels+1);\
- l0= (a&0x0303030303030303ULL)\
- + (b&0x0303030303030303ULL)\
- + 0x0101010101010101ULL;\
- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\
- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\
- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8)
-
-#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) )
-#else // 64 bit variant
-
-#define PIXOP2(OPNAME, OP) \
-static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint16_t*)(block )), LD16(pixels ));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint32_t*)(block )), LD32(pixels ));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- int i;\
- for(i=0; i<h; i++){\
- OP(*((uint32_t*)(block )), LD32(pixels ));\
- OP(*((uint32_t*)(block+4)), LD32(pixels+4));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_c(block, pixels, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD32(&src1[i*src_stride1 ]);\
- b= LD32(&src2[i*src_stride2 ]);\
- OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a,b;\
- a= LD16(&src1[i*src_stride1 ]);\
- b= LD16(&src2[i*src_stride2 ]);\
- OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
- OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \
- int src_stride1, int src_stride2, int h){\
- OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\
- OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a, b, c, d, l0, l1, h0, h1;\
- a= LD32(&src1[i*src_stride1]);\
- b= LD32(&src2[i*src_stride2]);\
- c= LD32(&src3[i*src_stride3]);\
- d= LD32(&src4[i*src_stride4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- c= LD32(&src3[i*src_stride3+4]);\
- d= LD32(&src4[i*src_stride4+4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- int i;\
- for(i=0; i<h; i++){\
- uint32_t a, b, c, d, l0, l1, h0, h1;\
- a= LD32(&src1[i*src_stride1]);\
- b= LD32(&src2[i*src_stride2]);\
- c= LD32(&src3[i*src_stride3]);\
- d= LD32(&src4[i*src_stride4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- a= LD32(&src1[i*src_stride1+4]);\
- b= LD32(&src2[i*src_stride2+4]);\
- c= LD32(&src3[i*src_stride3+4]);\
- d= LD32(&src4[i*src_stride4+4]);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- l1= (c&0x03030303UL)\
- + (d&0x03030303UL);\
- h1= ((c&0xFCFCFCFCUL)>>2)\
- + ((d&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- }\
-}\
-static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
- OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
-}\
-static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\
- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\
- OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
- OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\
-}\
-\
-static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i, a0, b0, a1, b1;\
- a0= pixels[0];\
- b0= pixels[1] + 2;\
- a0 += b0;\
- b0 += pixels[2];\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- a1= pixels[0];\
- b1= pixels[1];\
- a1 += b1;\
- b1 += pixels[2];\
-\
- block[0]= (a1+a0)>>2; /* FIXME non put */\
- block[1]= (b1+b0)>>2;\
-\
- pixels+=line_size;\
- block +=line_size;\
-\
- a0= pixels[0];\
- b0= pixels[1] + 2;\
- a0 += b0;\
- b0 += pixels[2];\
-\
- block[0]= (a1+a0)>>2;\
- block[1]= (b1+b0)>>2;\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
-}\
-\
-static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int j;\
- for(j=0; j<2; j++){\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x02020202UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
- pixels+=4-line_size*(h+1);\
- block +=4-line_size*h;\
- }\
-}\
-\
-static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\
-{\
- int j;\
- for(j=0; j<2; j++){\
- int i;\
- const uint32_t a= LD32(pixels );\
- const uint32_t b= LD32(pixels+1);\
- uint32_t l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- uint32_t l1,h1;\
-\
- pixels+=line_size;\
- for(i=0; i<h; i+=2){\
- uint32_t a= LD32(pixels );\
- uint32_t b= LD32(pixels+1);\
- l1= (a&0x03030303UL)\
- + (b&0x03030303UL);\
- h1= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- a= LD32(pixels );\
- b= LD32(pixels+1);\
- l0= (a&0x03030303UL)\
- + (b&0x03030303UL)\
- + 0x01010101UL;\
- h0= ((a&0xFCFCFCFCUL)>>2)\
- + ((b&0xFCFCFCFCUL)>>2);\
- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\
- pixels+=line_size;\
- block +=line_size;\
- }\
- pixels+=4-line_size*(h+1);\
- block +=4-line_size*h;\
- }\
-}\
-\
-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\
-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\
-
-#define op_avg(a, b) a = rnd_avg32(a, b)
-#endif
-#define op_put(a, b) a = b
-
-PIXOP2(avg, op_avg)
-PIXOP2(put, op_put)
-#undef op_avg
-#undef op_put
-
-#define avg2(a,b) ((a+b+1)>>1)
-#define avg4(a,b,c,d) ((a+b+c+d+2)>>2)
-
-
-static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder)
-{
- const int A=(16-x16)*(16-y16);
- const int B=( x16)*(16-y16);
- const int C=(16-x16)*( y16);
- const int D=( x16)*( y16);
- int i;
-
- for(i=0; i<h; i++)
- {
- dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8;
- dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8;
- dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8;
- dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8;
- dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8;
- dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8;
- dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8;
- dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8;
- dst+= stride;
- src+= stride;
- }
-}
-
-static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy,
- int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
-{
- int y, vx, vy;
- const int s= 1<<shift;
-
- width--;
- height--;
-
- for(y=0; y<h; y++){
- int x;
-
- vx= ox;
- vy= oy;
- for(x=0; x<8; x++){ //XXX FIXME optimize
- int src_x, src_y, frac_x, frac_y, index;
-
- src_x= vx>>16;
- src_y= vy>>16;
- frac_x= src_x&(s-1);
- frac_y= src_y&(s-1);
- src_x>>=shift;
- src_y>>=shift;
-
- if((unsigned)src_x < width){
- if((unsigned)src_y < height){
- index= src_x + src_y*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
- + src[index +1]* frac_x )*(s-frac_y)
- + ( src[index+stride ]*(s-frac_x)
- + src[index+stride+1]* frac_x )* frac_y
- + r)>>(shift*2);
- }else{
- index= src_x + clip(src_y, 0, height)*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_x)
- + src[index +1]* frac_x )*s
- + r)>>(shift*2);
- }
- }else{
- if((unsigned)src_y < height){
- index= clip(src_x, 0, width) + src_y*stride;
- dst[y*stride + x]= ( ( src[index ]*(s-frac_y)
- + src[index+stride ]* frac_y )*s
- + r)>>(shift*2);
- }else{
- index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride;
- dst[y*stride + x]= src[index ];
- }
- }
-
- vx+= dxx;
- vy+= dyx;
- }
- ox += dxy;
- oy += dyy;
- }
-}
-
-static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- switch(width){
- case 2: put_pixels2_c (dst, src, stride, height); break;
- case 4: put_pixels4_c (dst, src, stride, height); break;
- case 8: put_pixels8_c (dst, src, stride, height); break;
- case 16:put_pixels16_c(dst, src, stride, height); break;
- }
-}
-
-static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- switch(width){
- case 2: avg_pixels2_c (dst, src, stride, height); break;
- case 4: avg_pixels4_c (dst, src, stride, height); break;
- case 8: avg_pixels8_c (dst, src, stride, height); break;
- case 16:avg_pixels16_c(dst, src, stride, height); break;
- }
-}
-
-static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-
-static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){
- int i,j;
- for (i=0; i < height; i++) {
- for (j=0; j < width; j++) {
- dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1;
- }
- src += stride;
- dst += stride;
- }
-}
-#if 0
-#define TPEL_WIDTH(width)\
-static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\
-static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\
- void put_tpel_pixels_mc22_c(dst, src, stride, width, height);}
-#endif
-
-#define H264_CHROMA_MC(OPNAME, OP)\
-static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- dst+= stride;\
- src+= stride;\
- }\
-}\
-\
-static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
- OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
- dst+= stride;\
- src+= stride;\
- }\
-}\
-\
-static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\
- const int A=(8-x)*(8-y);\
- const int B=( x)*(8-y);\
- const int C=(8-x)*( y);\
- const int D=( x)*( y);\
- int i;\
- \
- assert(x<8 && y<8 && x>=0 && y>=0);\
-\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\
- OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\
- OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\
- OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\
- OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\
- OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\
- OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\
- OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\
- dst+= stride;\
- src+= stride;\
- }\
-}
-
-#define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1)
-#define op_put(a, b) a = (((b) + 32)>>6)
-
-H264_CHROMA_MC(put_ , op_put)
-H264_CHROMA_MC(avg_ , op_avg)
-#undef op_avg
-#undef op_put
-
-static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- ST32(dst+8 , LD32(src+8 ));
- ST32(dst+12, LD32(src+12));
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- ST32(dst+8 , LD32(src+8 ));
- ST32(dst+12, LD32(src+12));
- dst[16]= src[16];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h)
-{
- int i;
- for(i=0; i<h; i++)
- {
- ST32(dst , LD32(src ));
- ST32(dst+4 , LD32(src+4 ));
- dst[8]= src[8];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-
-#define QPEL_MC(r, OPNAME, RND, OP) \
-static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\
- OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\
- OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\
- OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\
- OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=8;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int src0= src[0*srcStride];\
- const int src1= src[1*srcStride];\
- const int src2= src[2*srcStride];\
- const int src3= src[3*srcStride];\
- const int src4= src[4*srcStride];\
- const int src5= src[5*srcStride];\
- const int src6= src[6*srcStride];\
- const int src7= src[7*srcStride];\
- const int src8= src[8*srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\
- OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\
- OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\
- OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\
- OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- \
- for(i=0; i<h; i++)\
- {\
- OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\
- OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\
- OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\
- OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\
- OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\
- OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\
- OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\
- OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\
- OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\
- OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\
- OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\
- OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\
- OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\
- OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\
- OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\
- OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- const int w=16;\
- for(i=0; i<w; i++)\
- {\
- const int src0= src[0*srcStride];\
- const int src1= src[1*srcStride];\
- const int src2= src[2*srcStride];\
- const int src3= src[3*srcStride];\
- const int src4= src[4*srcStride];\
- const int src5= src[5*srcStride];\
- const int src6= src[6*srcStride];\
- const int src7= src[7*srcStride];\
- const int src8= src[8*srcStride];\
- const int src9= src[9*srcStride];\
- const int src10= src[10*srcStride];\
- const int src11= src[11*srcStride];\
- const int src12= src[12*srcStride];\
- const int src13= src[13*srcStride];\
- const int src14= src[14*srcStride];\
- const int src15= src[15*srcStride];\
- const int src16= src[16*srcStride];\
- OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\
- OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\
- OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\
- OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\
- OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\
- OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\
- OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\
- OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\
- OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\
- OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\
- OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\
- OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\
- OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\
- OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\
- OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\
- OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels8_c(dst, src, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t half[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
- OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- copy_block9(full, src, 16, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\
-}\
-\
-static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t half[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\
- OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- uint8_t halfHV[64];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- uint8_t halfV[64];\
- uint8_t halfHV[64];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\
- put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[16*9];\
- uint8_t halfH[72];\
- copy_block9(full, src, 16, stride, 9);\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\
- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[72];\
- put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels16_c(dst, src, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t half[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
- OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- copy_block17(full, src, 24, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\
-}\
-\
-static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t half[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\
- OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- uint8_t halfHV[256];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}\
-void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- uint8_t halfV[256];\
- uint8_t halfHV[256];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\
- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[24*17];\
- uint8_t halfH[272];\
- copy_block17(full, src, 24, stride, 17);\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\
- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t halfH[272];\
- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\
-}
-
-#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
-#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1)
-#define op_put(a, b) a = cm[((b) + 16)>>5]
-#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5]
-
-QPEL_MC(0, put_ , _ , op_put)
-QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
-QPEL_MC(0, avg_ , _ , op_avg)
-//QPEL_MC(1, avg_no_rnd , _ , op_avg)
-#undef op_avg
-#undef op_avg_no_rnd
-#undef op_put
-#undef op_put_no_rnd
-
-#if 1
-#define H264_LOWPASS(OPNAME, OP, OP2) \
-static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int h=4;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=4;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int srcB= src[-2*srcStride];\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- const int src5= src[5 *srcStride];\
- const int src6= src[6 *srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- const int h=4;\
- const int w=4;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- src -= 2*srcStride;\
- for(i=0; i<h+5; i++)\
- {\
- tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\
- tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\
- tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\
- tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\
- tmp+=tmpStride;\
- src+=srcStride;\
- }\
- tmp -= tmpStride*(h+5-2);\
- for(i=0; i<w; i++)\
- {\
- const int tmpB= tmp[-2*tmpStride];\
- const int tmpA= tmp[-1*tmpStride];\
- const int tmp0= tmp[0 *tmpStride];\
- const int tmp1= tmp[1 *tmpStride];\
- const int tmp2= tmp[2 *tmpStride];\
- const int tmp3= tmp[3 *tmpStride];\
- const int tmp4= tmp[4 *tmpStride];\
- const int tmp5= tmp[5 *tmpStride];\
- const int tmp6= tmp[6 *tmpStride];\
- OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
- OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
- OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
- OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
- dst++;\
- tmp++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int h=8;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<h; i++)\
- {\
- OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\
- OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\
- OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\
- OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\
- OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\
- OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\
- OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\
- OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- const int w=8;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- for(i=0; i<w; i++)\
- {\
- const int srcB= src[-2*srcStride];\
- const int srcA= src[-1*srcStride];\
- const int src0= src[0 *srcStride];\
- const int src1= src[1 *srcStride];\
- const int src2= src[2 *srcStride];\
- const int src3= src[3 *srcStride];\
- const int src4= src[4 *srcStride];\
- const int src5= src[5 *srcStride];\
- const int src6= src[6 *srcStride];\
- const int src7= src[7 *srcStride];\
- const int src8= src[8 *srcStride];\
- const int src9= src[9 *srcStride];\
- const int src10=src[10*srcStride];\
- OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
- OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
- OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\
- OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\
- OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\
- OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\
- OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\
- OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\
- dst++;\
- src++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- const int h=8;\
- const int w=8;\
- uint8_t *cm = cropTbl + MAX_NEG_CROP;\
- int i;\
- src -= 2*srcStride;\
- for(i=0; i<h+5; i++)\
- {\
- tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\
- tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\
- tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\
- tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\
- tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\
- tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\
- tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\
- tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\
- tmp+=tmpStride;\
- src+=srcStride;\
- }\
- tmp -= tmpStride*(h+5-2);\
- for(i=0; i<w; i++)\
- {\
- const int tmpB= tmp[-2*tmpStride];\
- const int tmpA= tmp[-1*tmpStride];\
- const int tmp0= tmp[0 *tmpStride];\
- const int tmp1= tmp[1 *tmpStride];\
- const int tmp2= tmp[2 *tmpStride];\
- const int tmp3= tmp[3 *tmpStride];\
- const int tmp4= tmp[4 *tmpStride];\
- const int tmp5= tmp[5 *tmpStride];\
- const int tmp6= tmp[6 *tmpStride];\
- const int tmp7= tmp[7 *tmpStride];\
- const int tmp8= tmp[8 *tmpStride];\
- const int tmp9= tmp[9 *tmpStride];\
- const int tmp10=tmp[10*tmpStride];\
- OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
- OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
- OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\
- OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\
- OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\
- OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\
- OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\
- OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\
- dst++;\
- tmp++;\
- }\
-}\
-\
-static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\
-}\
-\
-static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
- src += 8*srcStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\
- OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\
-}\
-\
-static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
- OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
- OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
- src += 8*srcStride;\
- tmp += 8*tmpStride;\
- dst += 8*dstStride;\
- OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\
- OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\
-}\
-
-#define H264_MC(OPNAME, SIZE) \
-static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t half[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t half[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t half[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfH[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfV[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-\
-static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\
- uint8_t full[SIZE*(SIZE+5)];\
- uint8_t * const full_mid= full + SIZE*2;\
- int16_t tmp[SIZE*(SIZE+5)];\
- uint8_t halfV[SIZE*SIZE];\
- uint8_t halfHV[SIZE*SIZE];\
- copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\
- put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\
- put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\
- OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\
-}\
-
-#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1)
-//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7)
-#define op_put(a, b) a = cm[((b) + 16)>>5]
-#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1)
-#define op2_put(a, b) a = cm[((b) + 512)>>10]
-
-H264_LOWPASS(put_ , op_put, op2_put)
-H264_LOWPASS(avg_ , op_avg, op2_avg)
-H264_MC(put_, 4)
-H264_MC(put_, 8)
-H264_MC(put_, 16)
-H264_MC(avg_, 4)
-H264_MC(avg_, 8)
-H264_MC(avg_, 16)
-
-#undef op_avg
-#undef op_put
-#undef op2_avg
-#undef op2_put
-#endif
-
-static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- int i;
-
- for(i=0; i<h; i++){
- dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4];
- dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4];
- dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4];
- dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4];
- dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4];
- dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4];
- dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4];
- dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4];
- dst+=dstStride;
- src+=srcStride;
- }
-}
-
-static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- int i;
-
- for(i=0; i<w; i++){
- const int src_1= src[ -srcStride];
- const int src0 = src[0 ];
- const int src1 = src[ srcStride];
- const int src2 = src[2*srcStride];
- const int src3 = src[3*srcStride];
- const int src4 = src[4*srcStride];
- const int src5 = src[5*srcStride];
- const int src6 = src[6*srcStride];
- const int src7 = src[7*srcStride];
- const int src8 = src[8*srcStride];
- const int src9 = src[9*srcStride];
- dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4];
- dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4];
- dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4];
- dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4];
- dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4];
- dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4];
- dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4];
- dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4];
- src++;
- dst++;
- }
-}
-
-static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){
- put_pixels8_c(dst, src, stride, 8);
-}
-
-static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t half[64];
- wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
- put_pixels8_l2(dst, src, half, stride, stride, 8, 8);
-}
-
-static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){
- wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8);
-}
-
-static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t half[64];
- wmv2_mspel8_h_lowpass(half, src, 8, stride, 8);
- put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8);
-}
-
-static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){
- wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8);
-}
-
-static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- uint8_t halfV[64];
- uint8_t halfHV[64];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8);
- wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
-}
-static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- uint8_t halfV[64];
- uint8_t halfHV[64];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8);
- wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8);
- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);
-}
-static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){
- uint8_t halfH[88];
- wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11);
- wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8);
-}
-
-
-static inline int pix_abs16x16_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<16;i++) {
- s += abs(pix1[0] - pix2[0]);
- s += abs(pix1[1] - pix2[1]);
- s += abs(pix1[2] - pix2[2]);
- s += abs(pix1[3] - pix2[3]);
- s += abs(pix1[4] - pix2[4]);
- s += abs(pix1[5] - pix2[5]);
- s += abs(pix1[6] - pix2[6]);
- s += abs(pix1[7] - pix2[7]);
- s += abs(pix1[8] - pix2[8]);
- s += abs(pix1[9] - pix2[9]);
- s += abs(pix1[10] - pix2[10]);
- s += abs(pix1[11] - pix2[11]);
- s += abs(pix1[12] - pix2[12]);
- s += abs(pix1[13] - pix2[13]);
- s += abs(pix1[14] - pix2[14]);
- s += abs(pix1[15] - pix2[15]);
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs16x16_x2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<16;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
- s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
- s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
- s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
- s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
- s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
- s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
- s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
- s += abs(pix1[8] - avg2(pix2[8], pix2[9]));
- s += abs(pix1[9] - avg2(pix2[9], pix2[10]));
- s += abs(pix1[10] - avg2(pix2[10], pix2[11]));
- s += abs(pix1[11] - avg2(pix2[11], pix2[12]));
- s += abs(pix1[12] - avg2(pix2[12], pix2[13]));
- s += abs(pix1[13] - avg2(pix2[13], pix2[14]));
- s += abs(pix1[14] - avg2(pix2[14], pix2[15]));
- s += abs(pix1[15] - avg2(pix2[15], pix2[16]));
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs16x16_y2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<16;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
- s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
- s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
- s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
- s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
- s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
- s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
- s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
- s += abs(pix1[8] - avg2(pix2[8], pix3[8]));
- s += abs(pix1[9] - avg2(pix2[9], pix3[9]));
- s += abs(pix1[10] - avg2(pix2[10], pix3[10]));
- s += abs(pix1[11] - avg2(pix2[11], pix3[11]));
- s += abs(pix1[12] - avg2(pix2[12], pix3[12]));
- s += abs(pix1[13] - avg2(pix2[13], pix3[13]));
- s += abs(pix1[14] - avg2(pix2[14], pix3[14]));
- s += abs(pix1[15] - avg2(pix2[15], pix3[15]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int pix_abs16x16_xy2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<16;i++) {
- s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
- s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
- s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
- s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
- s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
- s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
- s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
- s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
- s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9]));
- s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10]));
- s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11]));
- s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12]));
- s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13]));
- s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14]));
- s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15]));
- s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static inline int pix_abs8x8_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<8;i++) {
- s += abs(pix1[0] - pix2[0]);
- s += abs(pix1[1] - pix2[1]);
- s += abs(pix1[2] - pix2[2]);
- s += abs(pix1[3] - pix2[3]);
- s += abs(pix1[4] - pix2[4]);
- s += abs(pix1[5] - pix2[5]);
- s += abs(pix1[6] - pix2[6]);
- s += abs(pix1[7] - pix2[7]);
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs8x8_x2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
-
- s = 0;
- for(i=0;i<8;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix2[1]));
- s += abs(pix1[1] - avg2(pix2[1], pix2[2]));
- s += abs(pix1[2] - avg2(pix2[2], pix2[3]));
- s += abs(pix1[3] - avg2(pix2[3], pix2[4]));
- s += abs(pix1[4] - avg2(pix2[4], pix2[5]));
- s += abs(pix1[5] - avg2(pix2[5], pix2[6]));
- s += abs(pix1[6] - avg2(pix2[6], pix2[7]));
- s += abs(pix1[7] - avg2(pix2[7], pix2[8]));
- pix1 += line_size;
- pix2 += line_size;
- }
- return s;
-}
-
-static int pix_abs8x8_y2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<8;i++) {
- s += abs(pix1[0] - avg2(pix2[0], pix3[0]));
- s += abs(pix1[1] - avg2(pix2[1], pix3[1]));
- s += abs(pix1[2] - avg2(pix2[2], pix3[2]));
- s += abs(pix1[3] - avg2(pix2[3], pix3[3]));
- s += abs(pix1[4] - avg2(pix2[4], pix3[4]));
- s += abs(pix1[5] - avg2(pix2[5], pix3[5]));
- s += abs(pix1[6] - avg2(pix2[6], pix3[6]));
- s += abs(pix1[7] - avg2(pix2[7], pix3[7]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int pix_abs8x8_xy2_c(uint8_t *pix1, uint8_t *pix2, int line_size)
-{
- int s, i;
- uint8_t *pix3 = pix2 + line_size;
-
- s = 0;
- for(i=0;i<8;i++) {
- s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1]));
- s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2]));
- s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3]));
- s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4]));
- s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5]));
- s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6]));
- s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7]));
- s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8]));
- pix1 += line_size;
- pix2 += line_size;
- pix3 += line_size;
- }
- return s;
-}
-
-static int sad16x16_c(void *s, uint8_t *a, uint8_t *b, int stride){
- return pix_abs16x16_c(a,b,stride);
-}
-
-static int sad8x8_c(void *s, uint8_t *a, uint8_t *b, int stride){
- return pix_abs8x8_c(a,b,stride);
-}
-
-/**
- * permutes an 8x8 block.
- * @param block the block which will be permuted according to the given permutation vector
- * @param permutation the permutation vector
- * @param last the last non zero coefficient in scantable order, used to speed the permutation up
- * @param scantable the used scantable, this is only used to speed the permutation up, the block is not
- * (inverse) permutated to scantable order!
- */
-void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last)
-{
- int i;
- DCTELEM temp[64];
-
- if(last<=0) return;
- //if(permutation[1]==1) return; //FIXME its ok but not clean and might fail for some perms
-
- for(i=0; i<=last; i++){
- const int j= scantable[i];
- temp[j]= block[j];
- block[j]=0;
- }
-
- for(i=0; i<=last; i++){
- const int j= scantable[i];
- const int perm_j= permutation[j];
- block[perm_j]= temp[j];
- }
-}
-
-/**
- * memset(blocks, 0, sizeof(DCTELEM)*6*64)
- */
-static void clear_blocks_c(DCTELEM *blocks)
-{
- memset(blocks, 0, sizeof(DCTELEM)*6*64);
-}
-
-static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){
- int i;
- for(i=0; i+7<w; i+=8){
- dst[i+0] += src[i+0];
- dst[i+1] += src[i+1];
- dst[i+2] += src[i+2];
- dst[i+3] += src[i+3];
- dst[i+4] += src[i+4];
- dst[i+5] += src[i+5];
- dst[i+6] += src[i+6];
- dst[i+7] += src[i+7];
- }
- for(; i<w; i++)
- dst[i+0] += src[i+0];
-}
-
-static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- int i;
- for(i=0; i+7<w; i+=8){
- dst[i+0] = src1[i+0]-src2[i+0];
- dst[i+1] = src1[i+1]-src2[i+1];
- dst[i+2] = src1[i+2]-src2[i+2];
- dst[i+3] = src1[i+3]-src2[i+3];
- dst[i+4] = src1[i+4]-src2[i+4];
- dst[i+5] = src1[i+5]-src2[i+5];
- dst[i+6] = src1[i+6]-src2[i+6];
- dst[i+7] = src1[i+7]-src2[i+7];
- }
- for(; i<w; i++)
- dst[i+0] = src1[i+0]-src2[i+0];
-}
-
-#define BUTTERFLY2(o1,o2,i1,i2) \
-o1= (i1)+(i2);\
-o2= (i1)-(i2);
-
-#define BUTTERFLY1(x,y) \
-{\
- int a,b;\
- a= x;\
- b= y;\
- x= a+b;\
- y= a-b;\
-}
-
-#define BUTTERFLYA(x,y) (ABS((x)+(y)) + ABS((x)-(y)))
-
-static int hadamard8_diff_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride){
- int i;
- int temp[64];
- int sum=0;
-
- for(i=0; i<8; i++){
- //FIXME try pointer walks
- BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]);
- BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]);
- BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]);
- BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
- BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
- BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
- }
-
- for(i=0; i<8; i++){
- BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
- BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
- BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
-
- BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
- BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
- BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
-
- sum +=
- BUTTERFLYA(temp[8*0+i], temp[8*4+i])
- +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
- +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
- +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
- }
-#if 0
-static int maxi=0;
-if(sum>maxi){
- maxi=sum;
- printf("MAX:%d\n", maxi);
-}
-#endif
- return sum;
-}
-
-static int hadamard8_abs_c(uint8_t *src, int stride, int mean){
- int i;
- int temp[64];
- int sum=0;
-//FIXME OOOPS ignore 0 term instead of mean mess
- for(i=0; i<8; i++){
- //FIXME try pointer walks
- BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-mean,src[stride*i+1]-mean);
- BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-mean,src[stride*i+3]-mean);
- BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-mean,src[stride*i+5]-mean);
- BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-mean,src[stride*i+7]-mean);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+2]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+3]);
- BUTTERFLY1(temp[8*i+4], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+5], temp[8*i+7]);
-
- BUTTERFLY1(temp[8*i+0], temp[8*i+4]);
- BUTTERFLY1(temp[8*i+1], temp[8*i+5]);
- BUTTERFLY1(temp[8*i+2], temp[8*i+6]);
- BUTTERFLY1(temp[8*i+3], temp[8*i+7]);
- }
-
- for(i=0; i<8; i++){
- BUTTERFLY1(temp[8*0+i], temp[8*1+i]);
- BUTTERFLY1(temp[8*2+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*5+i]);
- BUTTERFLY1(temp[8*6+i], temp[8*7+i]);
-
- BUTTERFLY1(temp[8*0+i], temp[8*2+i]);
- BUTTERFLY1(temp[8*1+i], temp[8*3+i]);
- BUTTERFLY1(temp[8*4+i], temp[8*6+i]);
- BUTTERFLY1(temp[8*5+i], temp[8*7+i]);
-
- sum +=
- BUTTERFLYA(temp[8*0+i], temp[8*4+i])
- +BUTTERFLYA(temp[8*1+i], temp[8*5+i])
- +BUTTERFLYA(temp[8*2+i], temp[8*6+i])
- +BUTTERFLYA(temp[8*3+i], temp[8*7+i]);
- }
-
- return sum;
-}
-
-static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
- MpegEncContext * const s= (MpegEncContext *)c;
- uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- int sum=0, i;
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
- s->dsp.fdct(temp);
-
- for(i=0; i<64; i++)
- sum+= ABS(temp[i]);
-
- return sum;
-}
-
-void simple_idct(DCTELEM *block); //FIXME
-
-static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
- MpegEncContext * const s= (MpegEncContext *)c;
- uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64*2/8];
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64;
- int sum=0, i;
-
- s->mb_intra=0;
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- memcpy(bak, temp, 64*sizeof(DCTELEM));
-
- s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
- s->dct_unquantize(s, temp, 0, s->qscale);
- simple_idct(temp); //FIXME
-
- for(i=0; i<64; i++)
- sum+= (temp[i]-bak[i])*(temp[i]-bak[i]);
-
- return sum;
-}
-
-static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
- MpegEncContext * const s= (MpegEncContext *)c;
- const uint8_t *scantable= s->intra_scantable.permutated;
- uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
- uint64_t __align8 aligned_bak[stride];
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- uint8_t * const bak= (uint8_t*)aligned_bak;
- int i, last, run, bits, level, distoration, start_i;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
-
- for(i=0; i<8; i++){
- ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0];
- ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1];
- }
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
-
- bits=0;
-
- if (s->mb_intra) {
- start_i = 1;
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
- } else {
- start_i = 0;
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
-
- if(last>=start_i){
- run=0;
- for(i=start_i; i<last; i++){
- int j= scantable[i];
- level= temp[j];
-
- if(level){
- level+=64;
- if((level&(~127)) == 0){
- bits+= length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- run=0;
- }else
- run++;
- }
- i= scantable[last];
-
- level= temp[i] + 64;
-
- assert(level - 64);
-
- if((level&(~127)) == 0){
- bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
-
- }
-
- if(last>=0){
- s->dct_unquantize(s, temp, 0, s->qscale);
- }
-
- s->dsp.idct_add(bak, stride, temp);
-
- distoration= s->dsp.sse[1](NULL, bak, src1, stride);
-
- return distoration + ((bits*s->qscale*s->qscale*109 + 64)>>7);
-}
-
-static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride){
- MpegEncContext * const s= (MpegEncContext *)c;
- const uint8_t *scantable= s->intra_scantable.permutated;
- uint64_t __align8 aligned_temp[sizeof(DCTELEM)*64/8];
- DCTELEM * const temp= (DCTELEM*)aligned_temp;
- int i, last, run, bits, level, start_i;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
-
- s->dsp.diff_pixels(temp, src1, src2, stride);
-
- s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i);
-
- bits=0;
-
- if (s->mb_intra) {
- start_i = 1;
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma
- } else {
- start_i = 0;
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
-
- if(last>=start_i){
- run=0;
- for(i=start_i; i<last; i++){
- int j= scantable[i];
- level= temp[j];
-
- if(level){
- level+=64;
- if((level&(~127)) == 0){
- bits+= length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- run=0;
- }else
- run++;
- }
- i= scantable[last];
-
- level= temp[i] + 64;
-
- assert(level - 64);
-
- if((level&(~127)) == 0){
- bits+= last_length[UNI_AC_ENC_INDEX(run, level)];
- }else
- bits+= esc_length;
- }
-
- return bits;
-}
-
-
-WARPER88_1616(hadamard8_diff_c, hadamard8_diff16_c)
-WARPER88_1616(dct_sad8x8_c, dct_sad16x16_c)
-WARPER88_1616(quant_psnr8x8_c, quant_psnr16x16_c)
-WARPER88_1616(rd8x8_c, rd16x16_c)
-WARPER88_1616(bit8x8_c, bit16x16_c)
-
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- put_pixels_clamped_c(block, dest, line_size);
-}
-static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- j_rev_dct (block);
- add_pixels_clamped_c(block, dest, line_size);
-}
-
-/* init static data */
-void dsputil_static_init(void)
-{
- int i;
-
- for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i;
- for(i=0;i<MAX_NEG_CROP;i++) {
- cropTbl[i] = 0;
- cropTbl[i + MAX_NEG_CROP + 256] = 255;
- }
-
- for(i=0;i<512;i++) {
- squareTbl[i] = (i - 256) * (i - 256);
- }
-
- for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
-}
-
-
-void dsputil_init(DSPContext* c, AVCodecContext *avctx)
-{
- int i;
-
-#ifdef CONFIG_ENCODERS
- if(avctx->dct_algo==FF_DCT_FASTINT)
- c->fdct = fdct_ifast;
- else
- c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
-#endif //CONFIG_ENCODERS
-
- if(avctx->idct_algo==FF_IDCT_INT){
- c->idct_put= ff_jref_idct_put;
- c->idct_add= ff_jref_idct_add;
- c->idct = j_rev_dct;
- c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
- }else{ //accurate/default
- c->idct_put= simple_idct_put;
- c->idct_add= simple_idct_add;
- c->idct = simple_idct;
- c->idct_permutation_type= FF_NO_IDCT_PERM;
- }
-
- c->get_pixels = get_pixels_c;
- c->diff_pixels = diff_pixels_c;
- c->put_pixels_clamped = put_pixels_clamped_c;
- c->add_pixels_clamped = add_pixels_clamped_c;
- c->gmc1 = gmc1_c;
- c->gmc = gmc_c;
- c->clear_blocks = clear_blocks_c;
- c->pix_sum = pix_sum_c;
- c->pix_norm1 = pix_norm1_c;
- c->sse[0]= sse16_c;
- c->sse[1]= sse8_c;
-
- /* TODO [0] 16 [1] 8 */
- c->pix_abs16x16 = pix_abs16x16_c;
- c->pix_abs16x16_x2 = pix_abs16x16_x2_c;
- c->pix_abs16x16_y2 = pix_abs16x16_y2_c;
- c->pix_abs16x16_xy2 = pix_abs16x16_xy2_c;
- c->pix_abs8x8 = pix_abs8x8_c;
- c->pix_abs8x8_x2 = pix_abs8x8_x2_c;
- c->pix_abs8x8_y2 = pix_abs8x8_y2_c;
- c->pix_abs8x8_xy2 = pix_abs8x8_xy2_c;
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \
- c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \
- c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \
- c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c
-
- dspfunc(put, 0, 16);
- dspfunc(put_no_rnd, 0, 16);
- dspfunc(put, 1, 8);
- dspfunc(put_no_rnd, 1, 8);
- dspfunc(put, 2, 4);
- dspfunc(put, 3, 2);
-
- dspfunc(avg, 0, 16);
- dspfunc(avg_no_rnd, 0, 16);
- dspfunc(avg, 1, 8);
- dspfunc(avg_no_rnd, 1, 8);
- dspfunc(avg, 2, 4);
- dspfunc(avg, 3, 2);
-#undef dspfunc
-
- c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;
- c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;
- c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;
- c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;
- c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;
- c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;
- c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;
- c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;
- c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;
-
- c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;
- c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;
- c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;
- c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;
- c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;
- c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;
- c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;
- c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;
- c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;
-
-#define dspfunc(PFX, IDX, NUM) \
- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \
- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \
- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \
- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \
- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \
- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \
- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \
- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \
- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \
- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \
- c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
- c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
- c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
- c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
- c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
- c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
-
- dspfunc(put_qpel, 0, 16);
- dspfunc(put_no_rnd_qpel, 0, 16);
-
- dspfunc(avg_qpel, 0, 16);
- /* dspfunc(avg_no_rnd_qpel, 0, 16); */
-
- dspfunc(put_qpel, 1, 8);
- dspfunc(put_no_rnd_qpel, 1, 8);
-
- dspfunc(avg_qpel, 1, 8);
- /* dspfunc(avg_no_rnd_qpel, 1, 8); */
-
- dspfunc(put_h264_qpel, 0, 16);
- dspfunc(put_h264_qpel, 1, 8);
- dspfunc(put_h264_qpel, 2, 4);
- dspfunc(avg_h264_qpel, 0, 16);
- dspfunc(avg_h264_qpel, 1, 8);
- dspfunc(avg_h264_qpel, 2, 4);
-
-#undef dspfunc
- c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;
- c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;
- c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;
- c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;
- c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;
- c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;
-
- c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;
- c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;
- c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;
- c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;
- c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;
- c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;
- c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;
- c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;
-
- c->hadamard8_diff[0]= hadamard8_diff16_c;
- c->hadamard8_diff[1]= hadamard8_diff_c;
- c->hadamard8_abs = hadamard8_abs_c;
-
- c->dct_sad[0]= dct_sad16x16_c;
- c->dct_sad[1]= dct_sad8x8_c;
-
- c->sad[0]= sad16x16_c;
- c->sad[1]= sad8x8_c;
-
- c->quant_psnr[0]= quant_psnr16x16_c;
- c->quant_psnr[1]= quant_psnr8x8_c;
-
- c->rd[0]= rd16x16_c;
- c->rd[1]= rd8x8_c;
-
- c->bit[0]= bit16x16_c;
- c->bit[1]= bit8x8_c;
-
- c->add_bytes= add_bytes_c;
- c->diff_bytes= diff_bytes_c;
- c->bswap_buf= bswap_buf;
-
-#ifdef HAVE_MMX
- dsputil_init_mmx(c, avctx);
-#endif
-#ifdef ARCH_ARMV4L
- dsputil_init_armv4l(c, avctx);
-#endif
-#ifdef HAVE_MLIB
- dsputil_init_mlib(c, avctx);
-#endif
-#ifdef ARCH_ALPHA
- dsputil_init_alpha(c, avctx);
-#endif
-#ifdef ARCH_POWERPC
- dsputil_init_ppc(c, avctx);
-#endif
-#ifdef HAVE_MMI
- dsputil_init_mmi(c, avctx);
-#endif
-#ifdef ARCH_SH4
- dsputil_init_sh4(c,avctx);
-#endif
-
- switch(c->idct_permutation_type){
- case FF_NO_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= i;
- break;
- case FF_LIBMPEG2_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);
- break;
- case FF_SIMPLE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= simple_mmx_permutation[i];
- break;
- case FF_TRANSPOSE_IDCT_PERM:
- for(i=0; i<64; i++)
- c->idct_permutation[i]= ((i&7)<<3) | (i>>3);
- break;
- default:
- fprintf(stderr, "Internal error, IDCT permutation not set\n");
- }
-}
-
+++ /dev/null
-/*
- * DSP utils
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file dsputil.h
- * DSP utils.
- * note, many functions in here may use MMX which trashes the FPU state, it is
- * absolutely necessary to call emms_c() between dsp & float/double code
- */
-
-#ifndef DSPUTIL_H
-#define DSPUTIL_H
-
-#include "common.h"
-#include "avcodec.h"
-
-
-//#define DEBUG
-/* dct code */
-typedef short DCTELEM;
-
-void fdct_ifast (DCTELEM *data);
-void ff_jpeg_fdct_islow (DCTELEM *data);
-
-void j_rev_dct (DCTELEM *data);
-
-void ff_fdct_mmx(DCTELEM *block);
-
-/* encoding scans */
-extern const uint8_t ff_alternate_horizontal_scan[64];
-extern const uint8_t ff_alternate_vertical_scan[64];
-extern const uint8_t ff_zigzag_direct[64];
-
-/* pixel operations */
-#define MAX_NEG_CROP 384
-
-/* temporary */
-extern uint32_t squareTbl[512];
-extern uint8_t cropTbl[256 + 2 * MAX_NEG_CROP];
-
-
-/* minimum alignment rules ;)
-if u notice errors in the align stuff, need more alignment for some asm code for some cpu
-or need to use a function with less aligned data then send a mail to the ffmpeg-dev list, ...
-
-!warning these alignments might not match reallity, (missing attribute((align)) stuff somewhere possible)
-i (michael) didnt check them, these are just the alignents which i think could be reached easily ...
-
-!future video codecs might need functions with less strict alignment
-*/
-
-/*
-void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size);
-void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride);
-void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
-void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size);
-void clear_blocks_c(DCTELEM *blocks);
-*/
-
-/* add and put pixel (decoding) */
-// blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16
-typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h);
-typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h);
-typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
-typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y);
-
-#define DEF_OLD_QPEL(name)\
-void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
-void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\
-void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);
-
-DEF_OLD_QPEL(qpel16_mc11_old_c)
-DEF_OLD_QPEL(qpel16_mc31_old_c)
-DEF_OLD_QPEL(qpel16_mc12_old_c)
-DEF_OLD_QPEL(qpel16_mc32_old_c)
-DEF_OLD_QPEL(qpel16_mc13_old_c)
-DEF_OLD_QPEL(qpel16_mc33_old_c)
-DEF_OLD_QPEL(qpel8_mc11_old_c)
-DEF_OLD_QPEL(qpel8_mc31_old_c)
-DEF_OLD_QPEL(qpel8_mc12_old_c)
-DEF_OLD_QPEL(qpel8_mc32_old_c)
-DEF_OLD_QPEL(qpel8_mc13_old_c)
-DEF_OLD_QPEL(qpel8_mc33_old_c)
-
-#define CALL_2X_PIXELS(a, b, n)\
-static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\
- b(block , pixels , line_size, h);\
- b(block+n, pixels+n, line_size, h);\
-}
-
-/* motion estimation */
-
-typedef int (*op_pixels_abs_func)(uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size)/* __attribute__ ((const))*/;
-
-typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size)/* __attribute__ ((const))*/;
-
-
-/**
- * DSPContext.
- */
-typedef struct DSPContext {
- /* pixel ops : interface with DCT */
- void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size);
- void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride);
- void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
- void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size);
- /**
- * translational global motion compensation.
- */
- void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder);
- /**
- * global motion compensation.
- */
- void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy,
- int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height);
- void (*clear_blocks)(DCTELEM *blocks/*align 16*/);
- int (*pix_sum)(uint8_t * pix, int line_size);
- int (*pix_norm1)(uint8_t * pix, int line_size);
- me_cmp_func sad[2]; /* identical to pix_absAxA except additional void * */
- me_cmp_func sse[2];
- me_cmp_func hadamard8_diff[2];
- me_cmp_func dct_sad[2];
- me_cmp_func quant_psnr[2];
- me_cmp_func bit[2];
- me_cmp_func rd[2];
- int (*hadamard8_abs )(uint8_t *src, int stride, int mean);
-
- me_cmp_func me_pre_cmp[11];
- me_cmp_func me_cmp[11];
- me_cmp_func me_sub_cmp[11];
- me_cmp_func mb_cmp[11];
-
- /* maybe create an array for 16/8/4/2 functions */
- /**
- * Halfpel motion compensation with rounding (a+b+1)>>1.
- * this is an array[4][4] of motion compensation funcions for 4
- * horizontal blocksizes (2,4,8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func put_pixels_tab[4][4];
-
- /**
- * Halfpel motion compensation with rounding (a+b+1)>>1.
- * This is an array[4][4] of motion compensation functions for 4
- * horizontal blocksizes (2,4,8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination into which the result is averaged (a+b+1)>>1
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func avg_pixels_tab[4][4];
-
- /**
- * Halfpel motion compensation with no rounding (a+b)>>1.
- * this is an array[2][4] of motion compensation funcions for 2
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func put_no_rnd_pixels_tab[2][4];
-
- /**
- * Halfpel motion compensation with no rounding (a+b)>>1.
- * this is an array[2][4] of motion compensation funcions for 2
- * horizontal blocksizes (8,16) and the 4 halfpel positions<br>
- * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ]
- * @param block destination into which the result is averaged (a+b)>>1
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- op_pixels_func avg_no_rnd_pixels_tab[2][4];
-
- /**
- * Thirdpel motion compensation with rounding (a+b+1)>>1.
- * this is an array[12] of motion compensation funcions for the 9 thirdpel positions<br>
- * *pixels_tab[ xthirdpel + 4*ythirdpel ]
- * @param block destination where the result is stored
- * @param pixels source
- * @param line_size number of bytes in a horizontal line of block
- * @param h height
- */
- tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
- tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width?
-
- qpel_mc_func put_qpel_pixels_tab[2][16];
- qpel_mc_func avg_qpel_pixels_tab[2][16];
- qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16];
- qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16];
- qpel_mc_func put_mspel_pixels_tab[8];
-
- /**
- * h264 Chram MC
- */
- h264_chroma_mc_func put_h264_chroma_pixels_tab[3];
- h264_chroma_mc_func avg_h264_chroma_pixels_tab[3];
-
- qpel_mc_func put_h264_qpel_pixels_tab[3][16];
- qpel_mc_func avg_h264_qpel_pixels_tab[3][16];
-
- op_pixels_abs_func pix_abs16x16;
- op_pixels_abs_func pix_abs16x16_x2;
- op_pixels_abs_func pix_abs16x16_y2;
- op_pixels_abs_func pix_abs16x16_xy2;
- op_pixels_abs_func pix_abs8x8;
- op_pixels_abs_func pix_abs8x8_x2;
- op_pixels_abs_func pix_abs8x8_y2;
- op_pixels_abs_func pix_abs8x8_xy2;
-
- /* huffyuv specific */
- void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w);
- void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w);
- void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w);
-
- /* (I)DCT */
- void (*fdct)(DCTELEM *block/* align 16*/);
-
- /* IDCT really*/
- void (*idct)(DCTELEM *block/* align 16*/);
-
- /**
- * block -> idct -> clip to unsigned 8 bit -> dest.
- * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...)
- * @param line_size size in bytes of a horizotal line of dest
- */
- void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- /**
- * block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
- * @param line_size size in bytes of a horizotal line of dest
- */
- void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- /**
- * idct input permutation.
- * several optimized IDCTs need a permutated input (relative to the normal order of the reference
- * IDCT)
- * this permutation must be performed before the idct_put/add, note, normally this can be merged
- * with the zigzag/alternate scan<br>
- * an example to avoid confusion:
- * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...)
- * - (x -> referece dct -> reference idct -> x)
- * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x)
- * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...)
- */
- uint8_t idct_permutation[64];
- int idct_permutation_type;
-#define FF_NO_IDCT_PERM 1
-#define FF_LIBMPEG2_IDCT_PERM 2
-#define FF_SIMPLE_IDCT_PERM 3
-#define FF_TRANSPOSE_IDCT_PERM 4
-
-} DSPContext;
-
-void dsputil_static_init(void);
-void dsputil_init(DSPContext* p, AVCodecContext *avctx);
-
-/**
- * permute block according to permuatation.
- * @param last last non zero element in scantable order
- */
-void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last);
-
-#define BYTE_VEC32(c) ((c)*0x01010101UL)
-
-static inline uint32_t rnd_avg32(uint32_t a, uint32_t b)
-{
- return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
-}
-
-static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b)
-{
- return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1);
-}
-
-/**
- * Empty mmx state.
- * this must be called between any dsp function and float/double code.
- * for example sin(); dsp->idct_put(); emms_c(); cos()
- */
-#define emms_c()
-
-/* should be defined by architectures supporting
- one or more MultiMedia extension */
-int mm_support(void);
-
-#if defined(HAVE_MMX)
-
-#undef emms_c
-
-#define MM_MMX 0x0001 /* standard MMX */
-#define MM_3DNOW 0x0004 /* AMD 3DNOW */
-#define MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */
-#define MM_SSE 0x0008 /* SSE functions */
-#define MM_SSE2 0x0010 /* PIV SSE2 functions */
-
-extern int mm_flags;
-
-void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
-void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
-
-static inline void emms(void)
-{
- __asm __volatile ("emms;":::"memory");
-}
-
-
-#define emms_c() \
-{\
- if (mm_flags & MM_MMX)\
- emms();\
-}
-
-#define __align8 __attribute__ ((aligned (8)))
-
-void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx);
-void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_ARMV4L)
-
-/* This is to use 4 bytes read to the IDCT pointers for some 'zero'
- line ptimizations */
-#define __align8 __attribute__ ((aligned (4)))
-
-void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(HAVE_MLIB)
-
-/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */
-#define __align8 __attribute__ ((aligned (8)))
-
-void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_ALPHA)
-
-#define __align8 __attribute__ ((aligned (8)))
-
-void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_POWERPC)
-
-#define MM_ALTIVEC 0x0001 /* standard AltiVec */
-
-extern int mm_flags;
-
-#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN)
-#include <altivec.h>
-#endif
-
-#define __align8 __attribute__ ((aligned (16)))
-
-void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(HAVE_MMI)
-
-#define __align8 __attribute__ ((aligned (16)))
-
-void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx);
-
-#elif defined(ARCH_SH4)
-
-#define __align8 __attribute__ ((aligned (8)))
-
-void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx);
-
-#else
-
-#define __align8
-
-#endif
-
-#ifdef __GNUC__
-
-struct unaligned_64 { uint64_t l; } __attribute__((packed));
-struct unaligned_32 { uint32_t l; } __attribute__((packed));
-struct unaligned_16 { uint16_t l; } __attribute__((packed));
-
-#define LD16(a) (((const struct unaligned_16 *) (a))->l)
-#define LD32(a) (((const struct unaligned_32 *) (a))->l)
-#define LD64(a) (((const struct unaligned_64 *) (a))->l)
-
-#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b)
-
-#else /* __GNUC__ */
-
-#define LD16(a) (*((uint16_t*)(a)))
-#define LD32(a) (*((uint32_t*)(a)))
-#define LD64(a) (*((uint64_t*)(a)))
-
-#define ST32(a, b) *((uint32_t*)(a)) = (b)
-
-#endif /* !__GNUC__ */
-
-/* PSNR */
-void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3],
- int orig_linesize[3], int coded_linesize,
- AVCodecContext *avctx);
-
-/* FFT computation */
-
-/* NOTE: soon integer code will be added, so you must use the
- FFTSample type */
-typedef float FFTSample;
-
-typedef struct FFTComplex {
- FFTSample re, im;
-} FFTComplex;
-
-typedef struct FFTContext {
- int nbits;
- int inverse;
- uint16_t *revtab;
- FFTComplex *exptab;
- FFTComplex *exptab1; /* only used by SSE code */
- void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
-} FFTContext;
-
-int fft_init(FFTContext *s, int nbits, int inverse);
-void fft_permute(FFTContext *s, FFTComplex *z);
-void fft_calc_c(FFTContext *s, FFTComplex *z);
-void fft_calc_sse(FFTContext *s, FFTComplex *z);
-void fft_calc_altivec(FFTContext *s, FFTComplex *z);
-
-static inline void fft_calc(FFTContext *s, FFTComplex *z)
-{
- s->fft_calc(s, z);
-}
-void fft_end(FFTContext *s);
-
-/* MDCT computation */
-
-typedef struct MDCTContext {
- int n; /* size of MDCT (i.e. number of input data * 2) */
- int nbits; /* n = 2^nbits */
- /* pre/post rotation tables */
- FFTSample *tcos;
- FFTSample *tsin;
- FFTContext fft;
-} MDCTContext;
-
-int ff_mdct_init(MDCTContext *s, int nbits, int inverse);
-void ff_imdct_calc(MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp);
-void ff_mdct_calc(MDCTContext *s, FFTSample *out,
- const FFTSample *input, FFTSample *tmp);
-void ff_mdct_end(MDCTContext *s);
-
-#define WARPER88_1616(name8, name16)\
-static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride){\
- return name8(s, dst , src , stride)\
- +name8(s, dst+8 , src+8 , stride)\
- +name8(s, dst +8*stride, src +8*stride, stride)\
- +name8(s, dst+8+8*stride, src+8+8*stride, stride);\
-}
-
-#ifndef HAVE_LRINTF
-/* XXX: add ISOC specific test to avoid specific BSD testing. */
-/* better than nothing implementation. */
-/* btw, rintf() is existing on fbsd too -- alex */
-static inline long int lrintf(float x)
-{
-#ifdef CONFIG_WIN32
- /* XXX: incorrect, but make it compile */
- return (int)(x);
-#else
- return (int)(rint(x));
-#endif
-}
-#endif
-
-#if defined(CONFIG_OS2) || defined(CONFIG_SUNOS)
-static inline float floorf(float f) {
- return floor(f);
-}
-#endif
-
-#endif
+++ /dev/null
-/*
- * DV decoder
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file dv.c
- * DV decoder.
- */
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "simple_idct.h"
-
-#define NTSC_FRAME_SIZE 120000
-#define PAL_FRAME_SIZE 144000
-
-#define TEX_VLC_BITS 9
-
-typedef struct DVVideoDecodeContext {
- AVCodecContext *avctx;
- GetBitContext gb;
- VLC *vlc;
- int sampling_411; /* 0 = 420, 1 = 411 */
- int width, height;
- uint8_t *current_picture[3]; /* picture structure */
- AVFrame picture;
- int linesize[3];
- DCTELEM block[5*6][64] __align8;
- uint8_t dv_zigzag[2][64];
- uint8_t idct_permutation[64];
- /* XXX: move it to static storage ? */
- uint8_t dv_shift[2][22][64];
- void (*idct_put[2])(uint8_t *dest, int line_size, DCTELEM *block);
-} DVVideoDecodeContext;
-
-#include "dvdata.h"
-
-static VLC dv_vlc;
-/* XXX: also include quantization */
-static RL_VLC_ELEM *dv_rl_vlc[1];
-
-static void dv_build_unquantize_tables(DVVideoDecodeContext *s)
-{
- int i, q, j;
-
- /* NOTE: max left shift is 6 */
- for(q = 0; q < 22; q++) {
- /* 88 unquant */
- for(i = 1; i < 64; i++) {
- /* 88 table */
- j = s->idct_permutation[i];
- s->dv_shift[0][q][j] =
- dv_quant_shifts[q][dv_88_areas[i]] + 1;
- }
-
- /* 248 unquant */
- for(i = 1; i < 64; i++) {
- /* 248 table */
- s->dv_shift[1][q][i] =
- dv_quant_shifts[q][dv_248_areas[i]] + 1;
- }
- }
-}
-
-static int dvvideo_decode_init(AVCodecContext *avctx)
-{
- DVVideoDecodeContext *s = avctx->priv_data;
- MpegEncContext s2;
- static int done=0;
-
- if (!done) {
- int i;
-
- done = 1;
-
- /* NOTE: as a trick, we use the fact the no codes are unused
- to accelerate the parsing of partial codes */
- init_vlc(&dv_vlc, TEX_VLC_BITS, NB_DV_VLC,
- dv_vlc_len, 1, 1, dv_vlc_bits, 2, 2);
-
- dv_rl_vlc[0] = av_malloc(dv_vlc.table_size * sizeof(RL_VLC_ELEM));
- for(i = 0; i < dv_vlc.table_size; i++){
- int code= dv_vlc.table[i][0];
- int len = dv_vlc.table[i][1];
- int level, run;
-
- if(len<0){ //more bits needed
- run= 0;
- level= code;
- } else if (code == (NB_DV_VLC - 1)) {
- /* EOB */
- run = 0;
- level = 256;
- } else {
- run= dv_vlc_run[code] + 1;
- level= dv_vlc_level[code];
- }
- dv_rl_vlc[0][i].len = len;
- dv_rl_vlc[0][i].level = level;
- dv_rl_vlc[0][i].run = run;
- }
- }
-
- /* ugly way to get the idct & scantable */
- /* XXX: fix it */
- memset(&s2, 0, sizeof(MpegEncContext));
- s2.avctx = avctx;
- dsputil_init(&s2.dsp, avctx);
- if (DCT_common_init(&s2) < 0)
- return -1;
-
- s->idct_put[0] = s2.dsp.idct_put;
- memcpy(s->idct_permutation, s2.dsp.idct_permutation, 64);
- memcpy(s->dv_zigzag[0], s2.intra_scantable.permutated, 64);
-
- /* XXX: use MMX also for idct248 */
- s->idct_put[1] = simple_idct248_put;
- memcpy(s->dv_zigzag[1], dv_248_zigzag, 64);
-
- /* XXX: do it only for constant case */
- dv_build_unquantize_tables(s);
-
- return 0;
-}
-
-//#define VLC_DEBUG
-
-typedef struct BlockInfo {
- const uint8_t *shift_table;
- const uint8_t *scan_table;
- uint8_t pos; /* position in block */
- uint8_t eob_reached; /* true if EOB has been reached */
- uint8_t dct_mode;
- uint8_t partial_bit_count;
- uint16_t partial_bit_buffer;
- int shift_offset;
-} BlockInfo;
-
-/* block size in bits */
-static const uint16_t block_sizes[6] = {
- 112, 112, 112, 112, 80, 80
-};
-
-#ifndef ALT_BITSTREAM_READER
-#warning only works with ALT_BITSTREAM_READER
-#endif
-
-/* decode ac coefs */
-static void dv_decode_ac(DVVideoDecodeContext *s,
- BlockInfo *mb, DCTELEM *block, int last_index)
-{
- int last_re_index;
- int shift_offset = mb->shift_offset;
- const uint8_t *scan_table = mb->scan_table;
- const uint8_t *shift_table = mb->shift_table;
- int pos = mb->pos;
- int level, pos1, sign, run;
- int partial_bit_count;
-#ifndef ALT_BITSTREAM_READER //FIXME
- int re_index=0;
- int re1_index=0;
-#endif
- OPEN_READER(re, &s->gb);
-
-#ifdef VLC_DEBUG
- printf("start\n");
-#endif
-
- /* if we must parse a partial vlc, we do it here */
- partial_bit_count = mb->partial_bit_count;
- if (partial_bit_count > 0) {
- uint8_t buf[4];
- uint32_t v;
- int l, l1;
- GetBitContext gb1;
-
- /* build the dummy bit buffer */
- l = 16 - partial_bit_count;
- UPDATE_CACHE(re, &s->gb);
-#ifdef VLC_DEBUG
- printf("show=%04x\n", SHOW_UBITS(re, &s->gb, 16));
-#endif
- v = (mb->partial_bit_buffer << l) | SHOW_UBITS(re, &s->gb, l);
- buf[0] = v >> 8;
- buf[1] = v;
-#ifdef VLC_DEBUG
- printf("v=%04x cnt=%d %04x\n",
- v, partial_bit_count, (mb->partial_bit_buffer << l));
-#endif
- /* try to read the codeword */
- init_get_bits(&gb1, buf, 4*8);
- {
- OPEN_READER(re1, &gb1);
- UPDATE_CACHE(re1, &gb1);
- GET_RL_VLC(level, run, re1, &gb1, dv_rl_vlc[0],
- TEX_VLC_BITS, 2);
- l = re1_index;
- CLOSE_READER(re1, &gb1);
- }
-#ifdef VLC_DEBUG
- printf("****run=%d level=%d size=%d\n", run, level, l);
-#endif
- /* compute codeword length */
- l1 = (level != 256 && level != 0);
- /* if too long, we cannot parse */
- l -= partial_bit_count;
- if ((re_index + l + l1) > last_index)
- return;
- /* skip read bits */
- last_re_index = 0; /* avoid warning */
- re_index += l;
- /* by definition, if we can read the vlc, all partial bits
- will be read (otherwise we could have read the vlc before) */
- mb->partial_bit_count = 0;
- UPDATE_CACHE(re, &s->gb);
- goto handle_vlc;
- }
-
- /* get the AC coefficients until last_index is reached */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
-#ifdef VLC_DEBUG
- printf("%2d: bits=%04x index=%d\n",
- pos, SHOW_UBITS(re, &s->gb, 16), re_index);
-#endif
- last_re_index = re_index;
- GET_RL_VLC(level, run, re, &s->gb, dv_rl_vlc[0],
- TEX_VLC_BITS, 2);
- handle_vlc:
-#ifdef VLC_DEBUG
- printf("run=%d level=%d\n", run, level);
-#endif
- if (level == 256) {
- if (re_index > last_index) {
- cannot_read:
- /* put position before read code */
- re_index = last_re_index;
- mb->eob_reached = 0;
- break;
- }
- /* EOB */
- mb->eob_reached = 1;
- break;
- } else if (level != 0) {
- if ((re_index + 1) > last_index)
- goto cannot_read;
- sign = SHOW_SBITS(re, &s->gb, 1);
- level = (level ^ sign) - sign;
- LAST_SKIP_BITS(re, &s->gb, 1);
- pos += run;
- /* error */
- if (pos >= 64) {
- goto read_error;
- }
- pos1 = scan_table[pos];
- level = level << (shift_table[pos1] + shift_offset);
- block[pos1] = level;
- // printf("run=%d level=%d shift=%d\n", run, level, shift_table[pos1]);
- } else {
- if (re_index > last_index)
- goto cannot_read;
- /* level is zero: means run without coding. No
- sign is coded */
- pos += run;
- /* error */
- if (pos >= 64) {
- read_error:
-#if defined(VLC_DEBUG) || 1
- fprintf(stderr, "error pos=%d\n", pos);
-#endif
- /* for errors, we consider the eob is reached */
- mb->eob_reached = 1;
- break;
- }
- }
- }
- CLOSE_READER(re, &s->gb);
- mb->pos = pos;
-}
-
-static inline void bit_copy(PutBitContext *pb, GetBitContext *gb, int bits_left)
-{
- while (bits_left >= 16) {
- put_bits(pb, 16, get_bits(gb, 16));
- bits_left -= 16;
- }
- if (bits_left > 0) {
- put_bits(pb, bits_left, get_bits(gb, bits_left));
- }
-}
-
-/* mb_x and mb_y are in units of 8 pixels */
-static inline void dv_decode_video_segment(DVVideoDecodeContext *s,
- uint8_t *buf_ptr1,
- const uint16_t *mb_pos_ptr)
-{
- int quant, dc, dct_mode, class1, j;
- int mb_index, mb_x, mb_y, v, last_index;
- DCTELEM *block, *block1;
- int c_offset, bits_left;
- uint8_t *y_ptr;
- BlockInfo mb_data[5 * 6], *mb, *mb1;
- void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block);
- uint8_t *buf_ptr;
- PutBitContext pb, vs_pb;
- uint8_t mb_bit_buffer[80 + 4]; /* allow some slack */
- int mb_bit_count;
- uint8_t vs_bit_buffer[5 * 80 + 4]; /* allow some slack */
- int vs_bit_count;
-
- memset(s->block, 0, sizeof(s->block));
-
- /* pass 1 : read DC and AC coefficients in blocks */
- buf_ptr = buf_ptr1;
- block1 = &s->block[0][0];
- mb1 = mb_data;
- init_put_bits(&vs_pb, vs_bit_buffer, 5 * 80, NULL, NULL);
- vs_bit_count = 0;
- for(mb_index = 0; mb_index < 5; mb_index++) {
- /* skip header */
- quant = buf_ptr[3] & 0x0f;
- buf_ptr += 4;
- init_put_bits(&pb, mb_bit_buffer, 80, NULL, NULL);
- mb_bit_count = 0;
- mb = mb1;
- block = block1;
- for(j = 0;j < 6; j++) {
- /* NOTE: size is not important here */
- init_get_bits(&s->gb, buf_ptr, 14*8);
-
- /* get the dc */
- dc = get_bits(&s->gb, 9);
- dc = (dc << (32 - 9)) >> (32 - 9);
- dct_mode = get_bits1(&s->gb);
- mb->dct_mode = dct_mode;
- mb->scan_table = s->dv_zigzag[dct_mode];
- class1 = get_bits(&s->gb, 2);
- mb->shift_offset = (class1 == 3);
- mb->shift_table = s->dv_shift[dct_mode]
- [quant + dv_quant_offset[class1]];
- dc = dc << 2;
- /* convert to unsigned because 128 is not added in the
- standard IDCT */
- dc += 1024;
- block[0] = dc;
- last_index = block_sizes[j];
- buf_ptr += last_index >> 3;
- mb->pos = 0;
- mb->partial_bit_count = 0;
-
- dv_decode_ac(s, mb, block, last_index);
-
- /* write the remaining bits in a new buffer only if the
- block is finished */
- bits_left = last_index - get_bits_count(&s->gb);
- if (mb->eob_reached) {
- mb->partial_bit_count = 0;
- mb_bit_count += bits_left;
- bit_copy(&pb, &s->gb, bits_left);
- } else {
- /* should be < 16 bits otherwise a codeword could have
- been parsed */
- mb->partial_bit_count = bits_left;
- mb->partial_bit_buffer = get_bits(&s->gb, bits_left);
- }
- block += 64;
- mb++;
- }
-
- flush_put_bits(&pb);
-
- /* pass 2 : we can do it just after */
-#ifdef VLC_DEBUG
- printf("***pass 2 size=%d\n", mb_bit_count);
-#endif
- block = block1;
- mb = mb1;
- init_get_bits(&s->gb, mb_bit_buffer, 80*8);
- for(j = 0;j < 6; j++) {
- if (!mb->eob_reached && get_bits_count(&s->gb) < mb_bit_count) {
- dv_decode_ac(s, mb, block, mb_bit_count);
- /* if still not finished, no need to parse other blocks */
- if (!mb->eob_reached) {
- /* we could not parse the current AC coefficient,
- so we add the remaining bytes */
- bits_left = mb_bit_count - get_bits_count(&s->gb);
- if (bits_left > 0) {
- mb->partial_bit_count += bits_left;
- mb->partial_bit_buffer =
- (mb->partial_bit_buffer << bits_left) |
- get_bits(&s->gb, bits_left);
- }
- goto next_mb;
- }
- }
- block += 64;
- mb++;
- }
- /* all blocks are finished, so the extra bytes can be used at
- the video segment level */
- bits_left = mb_bit_count - get_bits_count(&s->gb);
- vs_bit_count += bits_left;
- bit_copy(&vs_pb, &s->gb, bits_left);
- next_mb:
- mb1 += 6;
- block1 += 6 * 64;
- }
-
- /* we need a pass other the whole video segment */
- flush_put_bits(&vs_pb);
-
-#ifdef VLC_DEBUG
- printf("***pass 3 size=%d\n", vs_bit_count);
-#endif
- block = &s->block[0][0];
- mb = mb_data;
- init_get_bits(&s->gb, vs_bit_buffer, 5 * 80*8);
- for(mb_index = 0; mb_index < 5; mb_index++) {
- for(j = 0;j < 6; j++) {
- if (!mb->eob_reached) {
-#ifdef VLC_DEBUG
- printf("start %d:%d\n", mb_index, j);
-#endif
- dv_decode_ac(s, mb, block, vs_bit_count);
- }
- block += 64;
- mb++;
- }
- }
-
- /* compute idct and place blocks */
- block = &s->block[0][0];
- mb = mb_data;
- for(mb_index = 0; mb_index < 5; mb_index++) {
- v = *mb_pos_ptr++;
- mb_x = v & 0xff;
- mb_y = v >> 8;
- y_ptr = s->current_picture[0] + (mb_y * s->linesize[0] * 8) + (mb_x * 8);
- if (s->sampling_411)
- c_offset = (mb_y * s->linesize[1] * 8) + ((mb_x >> 2) * 8);
- else
- c_offset = ((mb_y >> 1) * s->linesize[1] * 8) + ((mb_x >> 1) * 8);
- for(j = 0;j < 6; j++) {
- idct_put = s->idct_put[mb->dct_mode];
- if (j < 4) {
- if (s->sampling_411 && mb_x < (704 / 8)) {
- /* NOTE: at end of line, the macroblock is handled as 420 */
- idct_put(y_ptr + (j * 8), s->linesize[0], block);
- } else {
- idct_put(y_ptr + ((j & 1) * 8) + ((j >> 1) * 8 * s->linesize[0]),
- s->linesize[0], block);
- }
- } else {
- if (s->sampling_411 && mb_x >= (704 / 8)) {
- uint8_t pixels[64], *c_ptr, *c_ptr1, *ptr;
- int y, linesize;
- /* NOTE: at end of line, the macroblock is handled as 420 */
- idct_put(pixels, 8, block);
- linesize = s->linesize[6 - j];
- c_ptr = s->current_picture[6 - j] + c_offset;
- ptr = pixels;
- for(y = 0;y < 8; y++) {
- /* convert to 411P */
- c_ptr1 = c_ptr + 8*linesize;
- c_ptr[0]= ptr[0]; c_ptr1[0]= ptr[4];
- c_ptr[1]= ptr[1]; c_ptr1[1]= ptr[5];
- c_ptr[2]= ptr[2]; c_ptr1[2]= ptr[6];
- c_ptr[3]= ptr[3]; c_ptr1[3]= ptr[7];
- c_ptr += linesize;
- ptr += 8;
- }
- } else {
- /* don't ask me why they inverted Cb and Cr ! */
- idct_put(s->current_picture[6 - j] + c_offset,
- s->linesize[6 - j], block);
- }
- }
- block += 64;
- mb++;
- }
- }
-}
-
-
-/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
- 144000 bytes for PAL) */
-static int dvvideo_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- DVVideoDecodeContext *s = avctx->priv_data;
- int sct, dsf, apt, ds, nb_dif_segs, vs, width, height, i, packet_size;
- uint8_t *buf_ptr;
- const uint16_t *mb_pos_ptr;
-
- /* parse id */
- init_get_bits(&s->gb, buf, buf_size*8);
- sct = get_bits(&s->gb, 3);
- if (sct != 0)
- return -1;
- skip_bits(&s->gb, 5);
- get_bits(&s->gb, 4); /* dsn (sequence number */
- get_bits(&s->gb, 1); /* fsc (channel number) */
- skip_bits(&s->gb, 3);
- get_bits(&s->gb, 8); /* dbn (diff block number 0-134) */
-
- dsf = get_bits(&s->gb, 1); /* 0 = NTSC 1 = PAL */
- if (get_bits(&s->gb, 1) != 0)
- return -1;
- skip_bits(&s->gb, 11);
- apt = get_bits(&s->gb, 3); /* apt */
-
- get_bits(&s->gb, 1); /* tf1 */
- skip_bits(&s->gb, 4);
- get_bits(&s->gb, 3); /* ap1 */
-
- get_bits(&s->gb, 1); /* tf2 */
- skip_bits(&s->gb, 4);
- get_bits(&s->gb, 3); /* ap2 */
-
- get_bits(&s->gb, 1); /* tf3 */
- skip_bits(&s->gb, 4);
- get_bits(&s->gb, 3); /* ap3 */
-
- /* init size */
- width = 720;
- if (dsf) {
- avctx->frame_rate = 25;
- avctx->frame_rate_base = 1;
- packet_size = PAL_FRAME_SIZE;
- height = 576;
- nb_dif_segs = 12;
- } else {
- avctx->frame_rate = 30000;
- avctx->frame_rate_base = 1001;
- packet_size = NTSC_FRAME_SIZE;
- height = 480;
- nb_dif_segs = 10;
- }
- /* NOTE: we only accept several full frames */
- if (buf_size < packet_size)
- return -1;
-
- /* NTSC[dsf == 0] is always 720x480, 4:1:1
- * PAL[dsf == 1] is always 720x576, 4:2:0 for IEC 68134[apt == 0]
- * but for the SMPTE 314M[apt == 1] it is 720x576, 4:1:1
- */
- s->sampling_411 = !dsf || apt;
- if (s->sampling_411) {
- mb_pos_ptr = dsf ? dv_place_411P : dv_place_411;
- avctx->pix_fmt = PIX_FMT_YUV411P;
- } else {
- mb_pos_ptr = dv_place_420;
- avctx->pix_fmt = PIX_FMT_YUV420P;
- }
-
- avctx->width = width;
- avctx->height = height;
-
- /* Once again, this is pretty complicated by the fact that the same
- * field is used differently by IEC 68134[apt == 0] and
- * SMPTE 314M[apt == 1].
- */
- if (buf[VAUX_TC61_OFFSET] == 0x61 &&
- ((apt == 0 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x07) ||
- (apt == 1 && (buf[VAUX_TC61_OFFSET + 2] & 0x07) == 0x02)))
- avctx->aspect_ratio = 16.0 / 9.0;
- else
- avctx->aspect_ratio = 4.0 / 3.0;
-
- if(s->picture.data[0])
- avctx->release_buffer(avctx, &s->picture);
-
- s->picture.reference= 0;
- if(avctx->get_buffer(avctx, &s->picture) < 0) {
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- for(i=0;i<3;i++) {
- s->current_picture[i] = s->picture.data[i];
- s->linesize[i] = s->picture.linesize[i];
- if (!s->current_picture[i])
- return -1;
- }
- s->width = width;
- s->height = height;
-
- /* for each DIF segment */
- buf_ptr = buf;
- for (ds = 0; ds < nb_dif_segs; ds++) {
- buf_ptr += 6 * 80; /* skip DIF segment header */
-
- for(vs = 0; vs < 27; vs++) {
- if ((vs % 3) == 0) {
- /* skip audio block */
- buf_ptr += 80;
- }
- dv_decode_video_segment(s, buf_ptr, mb_pos_ptr);
- buf_ptr += 5 * 80;
- mb_pos_ptr += 5;
- }
- }
-
- emms_c();
-
- /* return image */
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data= s->picture;
-
- return packet_size;
-}
-
-static int dvvideo_decode_end(AVCodecContext *avctx)
-{
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec dvvideo_decoder = {
- "dvvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_DVVIDEO,
- sizeof(DVVideoDecodeContext),
- dvvideo_decode_init,
- NULL,
- dvvideo_decode_end,
- dvvideo_decode_frame,
- CODEC_CAP_DR1,
- NULL
-};
-
-typedef struct DVAudioDecodeContext {
- AVCodecContext *avctx;
- GetBitContext gb;
-} DVAudioDecodeContext;
-
-static int dvaudio_decode_init(AVCodecContext *avctx)
-{
- // DVAudioDecodeContext *s = avctx->priv_data;
- return 0;
-}
-
-static uint16_t dv_audio_12to16(uint16_t sample)
-{
- uint16_t shift, result;
-
- sample = (sample < 0x800) ? sample : sample | 0xf000;
- shift = (sample & 0xf00) >> 8;
-
- if (shift < 0x2 || shift > 0xd) {
- result = sample;
- } else if (shift < 0x8) {
- shift--;
- result = (sample - (256 * shift)) << shift;
- } else {
- shift = 0xe - shift;
- result = ((sample + ((256 * shift) + 1)) << shift) - 1;
- }
-
- return result;
-}
-
-/* NOTE: exactly one frame must be given (120000 bytes for NTSC,
- 144000 bytes for PAL)
-
- There's a couple of assumptions being made here:
- 1. By default we silence erroneous (0x8000/16bit 0x800/12bit)
- audio samples. We can pass them upwards when ffmpeg will be ready
- to deal with them.
- 2. We don't do software emphasis.
- 3. Audio is always returned as 16bit linear samples: 12bit
- nonlinear samples are converted into 16bit linear ones.
-*/
-static int dvaudio_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- DVVideoDecodeContext *s = avctx->priv_data;
- const uint16_t (*unshuffle)[9];
- int smpls, freq, quant, sys, stride, difseg, ad, dp, nb_dif_segs, i;
- uint16_t lc, rc;
- uint8_t *buf_ptr;
-
- /* parse id */
- init_get_bits(&s->gb, &buf[AAUX_AS_OFFSET], 5*8);
- i = get_bits(&s->gb, 8);
- if (i != 0x50) { /* No audio ? */
- *data_size = 0;
- return buf_size;
- }
-
- get_bits(&s->gb, 1); /* 0 - locked audio, 1 - unlocked audio */
- skip_bits(&s->gb, 1);
- smpls = get_bits(&s->gb, 6); /* samples in this frame - min. samples */
-
- skip_bits(&s->gb, 8);
-
- skip_bits(&s->gb, 2);
- sys = get_bits(&s->gb, 1); /* 0 - 60 fields, 1 = 50 fields */
- skip_bits(&s->gb, 5);
-
- get_bits(&s->gb, 1); /* 0 - emphasis on, 1 - emphasis off */
- get_bits(&s->gb, 1); /* 0 - reserved, 1 - emphasis time constant 50/15us */
- freq = get_bits(&s->gb, 3); /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
- quant = get_bits(&s->gb, 3); /* 0 - 16bit linear, 1 - 12bit nonlinear */
-
- if (quant > 1)
- return -1; /* Unsupported quantization */
-
- avctx->sample_rate = dv_audio_frequency[freq];
- avctx->channels = 2;
- avctx->bit_rate = avctx->channels * avctx->sample_rate * 16;
- // What about:
- // avctx->frame_size =
-
- *data_size = (dv_audio_min_samples[sys][freq] + smpls) *
- avctx->channels * 2;
-
- if (sys) {
- nb_dif_segs = 12;
- stride = 108;
- unshuffle = dv_place_audio50;
- } else {
- nb_dif_segs = 10;
- stride = 90;
- unshuffle = dv_place_audio60;
- }
-
- /* for each DIF segment */
- buf_ptr = buf;
- for (difseg = 0; difseg < nb_dif_segs; difseg++) {
- buf_ptr += 6 * 80; /* skip DIF segment header */
- for (ad = 0; ad < 9; ad++) {
-
- for (dp = 8; dp < 80; dp+=2) {
- if (quant == 0) { /* 16bit quantization */
- i = unshuffle[difseg][ad] + (dp - 8)/2 * stride;
- ((short *)data)[i] = (buf_ptr[dp] << 8) | buf_ptr[dp+1];
- if (((unsigned short *)data)[i] == 0x8000)
- ((short *)data)[i] = 0;
- } else { /* 12bit quantization */
- if (difseg >= nb_dif_segs/2)
- goto out; /* We're not doing 4ch at this time */
-
- lc = ((uint16_t)buf_ptr[dp] << 4) |
- ((uint16_t)buf_ptr[dp+2] >> 4);
- rc = ((uint16_t)buf_ptr[dp+1] << 4) |
- ((uint16_t)buf_ptr[dp+2] & 0x0f);
- lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
- rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
-
- i = unshuffle[difseg][ad] + (dp - 8)/3 * stride;
- ((short *)data)[i] = lc;
- i = unshuffle[difseg+nb_dif_segs/2][ad] + (dp - 8)/3 * stride;
- ((short *)data)[i] = rc;
- ++dp;
- }
- }
-
- buf_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
- }
- }
-
-out:
- return buf_size;
-}
-
-static int dvaudio_decode_end(AVCodecContext *avctx)
-{
- // DVAudioDecodeContext *s = avctx->priv_data;
- return 0;
-}
-
-AVCodec dvaudio_decoder = {
- "dvaudio",
- CODEC_TYPE_AUDIO,
- CODEC_ID_DVAUDIO,
- sizeof(DVAudioDecodeContext),
- dvaudio_decode_init,
- NULL,
- dvaudio_decode_end,
- dvaudio_decode_frame,
- 0,
- NULL
-};
+++ /dev/null
-/*
- * Constants for DV codec
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file dvdata.h
- * Constants for DV codec.
- */
-
-#define NB_DV_VLC 409
-#define AAUX_AS_OFFSET (80*6 + 80*16*3 + 3)
-#define AAUX_ASC_OFFSET (80*6 + 80*16*4 + 3)
-#define VAUX_TC61_OFFSET (80*5 + 48 + 5)
-
-static const uint16_t dv_vlc_bits[409] = {
- 0x0000, 0x0002, 0x0007, 0x0008, 0x0009, 0x0014, 0x0015, 0x0016,
- 0x0017, 0x0030, 0x0031, 0x0032, 0x0033, 0x0068, 0x0069, 0x006a,
- 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, 0x00e0, 0x00e1, 0x00e2,
- 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea,
- 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, 0x01e0, 0x01e1, 0x01e2,
- 0x01e3, 0x01e4, 0x01e5, 0x01e6, 0x01e7, 0x01e8, 0x01e9, 0x01ea,
- 0x01eb, 0x01ec, 0x01ed, 0x01ee, 0x01ef, 0x03e0, 0x03e1, 0x03e2,
- 0x03e3, 0x03e4, 0x03e5, 0x03e6, 0x07ce, 0x07cf, 0x07d0, 0x07d1,
- 0x07d2, 0x07d3, 0x07d4, 0x07d5, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
- 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
- 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
- 0x1f80, 0x1f81, 0x1f82, 0x1f83, 0x1f84, 0x1f85, 0x1f86, 0x1f87,
- 0x1f88, 0x1f89, 0x1f8a, 0x1f8b, 0x1f8c, 0x1f8d, 0x1f8e, 0x1f8f,
- 0x1f90, 0x1f91, 0x1f92, 0x1f93, 0x1f94, 0x1f95, 0x1f96, 0x1f97,
- 0x1f98, 0x1f99, 0x1f9a, 0x1f9b, 0x1f9c, 0x1f9d, 0x1f9e, 0x1f9f,
- 0x1fa0, 0x1fa1, 0x1fa2, 0x1fa3, 0x1fa4, 0x1fa5, 0x1fa6, 0x1fa7,
- 0x1fa8, 0x1fa9, 0x1faa, 0x1fab, 0x1fac, 0x1fad, 0x1fae, 0x1faf,
- 0x1fb0, 0x1fb1, 0x1fb2, 0x1fb3, 0x1fb4, 0x1fb5, 0x1fb6, 0x1fb7,
- 0x1fb8, 0x1fb9, 0x1fba, 0x1fbb, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf,
- 0x7f00, 0x7f01, 0x7f02, 0x7f03, 0x7f04, 0x7f05, 0x7f06, 0x7f07,
- 0x7f08, 0x7f09, 0x7f0a, 0x7f0b, 0x7f0c, 0x7f0d, 0x7f0e, 0x7f0f,
- 0x7f10, 0x7f11, 0x7f12, 0x7f13, 0x7f14, 0x7f15, 0x7f16, 0x7f17,
- 0x7f18, 0x7f19, 0x7f1a, 0x7f1b, 0x7f1c, 0x7f1d, 0x7f1e, 0x7f1f,
- 0x7f20, 0x7f21, 0x7f22, 0x7f23, 0x7f24, 0x7f25, 0x7f26, 0x7f27,
- 0x7f28, 0x7f29, 0x7f2a, 0x7f2b, 0x7f2c, 0x7f2d, 0x7f2e, 0x7f2f,
- 0x7f30, 0x7f31, 0x7f32, 0x7f33, 0x7f34, 0x7f35, 0x7f36, 0x7f37,
- 0x7f38, 0x7f39, 0x7f3a, 0x7f3b, 0x7f3c, 0x7f3d, 0x7f3e, 0x7f3f,
- 0x7f40, 0x7f41, 0x7f42, 0x7f43, 0x7f44, 0x7f45, 0x7f46, 0x7f47,
- 0x7f48, 0x7f49, 0x7f4a, 0x7f4b, 0x7f4c, 0x7f4d, 0x7f4e, 0x7f4f,
- 0x7f50, 0x7f51, 0x7f52, 0x7f53, 0x7f54, 0x7f55, 0x7f56, 0x7f57,
- 0x7f58, 0x7f59, 0x7f5a, 0x7f5b, 0x7f5c, 0x7f5d, 0x7f5e, 0x7f5f,
- 0x7f60, 0x7f61, 0x7f62, 0x7f63, 0x7f64, 0x7f65, 0x7f66, 0x7f67,
- 0x7f68, 0x7f69, 0x7f6a, 0x7f6b, 0x7f6c, 0x7f6d, 0x7f6e, 0x7f6f,
- 0x7f70, 0x7f71, 0x7f72, 0x7f73, 0x7f74, 0x7f75, 0x7f76, 0x7f77,
- 0x7f78, 0x7f79, 0x7f7a, 0x7f7b, 0x7f7c, 0x7f7d, 0x7f7e, 0x7f7f,
- 0x7f80, 0x7f81, 0x7f82, 0x7f83, 0x7f84, 0x7f85, 0x7f86, 0x7f87,
- 0x7f88, 0x7f89, 0x7f8a, 0x7f8b, 0x7f8c, 0x7f8d, 0x7f8e, 0x7f8f,
- 0x7f90, 0x7f91, 0x7f92, 0x7f93, 0x7f94, 0x7f95, 0x7f96, 0x7f97,
- 0x7f98, 0x7f99, 0x7f9a, 0x7f9b, 0x7f9c, 0x7f9d, 0x7f9e, 0x7f9f,
- 0x7fa0, 0x7fa1, 0x7fa2, 0x7fa3, 0x7fa4, 0x7fa5, 0x7fa6, 0x7fa7,
- 0x7fa8, 0x7fa9, 0x7faa, 0x7fab, 0x7fac, 0x7fad, 0x7fae, 0x7faf,
- 0x7fb0, 0x7fb1, 0x7fb2, 0x7fb3, 0x7fb4, 0x7fb5, 0x7fb6, 0x7fb7,
- 0x7fb8, 0x7fb9, 0x7fba, 0x7fbb, 0x7fbc, 0x7fbd, 0x7fbe, 0x7fbf,
- 0x7fc0, 0x7fc1, 0x7fc2, 0x7fc3, 0x7fc4, 0x7fc5, 0x7fc6, 0x7fc7,
- 0x7fc8, 0x7fc9, 0x7fca, 0x7fcb, 0x7fcc, 0x7fcd, 0x7fce, 0x7fcf,
- 0x7fd0, 0x7fd1, 0x7fd2, 0x7fd3, 0x7fd4, 0x7fd5, 0x7fd6, 0x7fd7,
- 0x7fd8, 0x7fd9, 0x7fda, 0x7fdb, 0x7fdc, 0x7fdd, 0x7fde, 0x7fdf,
- 0x7fe0, 0x7fe1, 0x7fe2, 0x7fe3, 0x7fe4, 0x7fe5, 0x7fe6, 0x7fe7,
- 0x7fe8, 0x7fe9, 0x7fea, 0x7feb, 0x7fec, 0x7fed, 0x7fee, 0x7fef,
- 0x7ff0, 0x7ff1, 0x7ff2, 0x7ff3, 0x7ff4, 0x7ff5, 0x7ff6, 0x7ff7,
- 0x7ff8, 0x7ff9, 0x7ffa, 0x7ffb, 0x7ffc, 0x7ffd, 0x7ffe, 0x7fff,
- 0x0006,
-};
-
-static const uint8_t dv_vlc_len[409] = {
- 2, 3, 4, 4, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 7, 7,
- 7, 7, 7, 7, 7, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 10, 11, 11, 11, 11,
- 11, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 4,
-};
-
-static const uint8_t dv_vlc_run[409] = {
- 0, 0, 1, 0, 0, 2, 1, 0,
- 0, 3, 4, 0, 0, 5, 6, 2,
- 1, 1, 0, 0, 0, 7, 8, 9,
- 10, 3, 4, 2, 1, 1, 1, 0,
- 0, 0, 0, 0, 0, 11, 12, 13,
- 14, 5, 6, 3, 4, 2, 2, 1,
- 0, 0, 0, 0, 0, 5, 3, 3,
- 2, 1, 1, 1, 0, 1, 6, 4,
- 3, 1, 1, 1, 2, 3, 4, 5,
- 7, 8, 9, 10, 7, 8, 4, 3,
- 2, 2, 2, 2, 2, 1, 1, 1,
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55,
- 56, 57, 58, 59, 60, 61, 62, 63,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0,
-};
-
-static const uint8_t dv_vlc_level[409] = {
- 1, 2, 1, 3, 4, 1, 2, 5,
- 6, 1, 1, 7, 8, 1, 1, 2,
- 3, 4, 9, 10, 11, 1, 1, 1,
- 1, 2, 2, 3, 5, 6, 7, 12,
- 13, 14, 15, 16, 17, 1, 1, 1,
- 1, 2, 2, 3, 3, 4, 5, 8,
- 18, 19, 20, 21, 22, 3, 4, 5,
- 6, 9, 10, 11, 0, 0, 3, 4,
- 6, 12, 13, 14, 0, 0, 0, 0,
- 2, 2, 2, 2, 3, 3, 5, 7,
- 7, 8, 9, 10, 11, 15, 16, 17,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55,
- 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71,
- 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87,
- 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103,
- 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135,
- 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151,
- 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 161, 162, 163, 164, 165, 166, 167,
- 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183,
- 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 195, 196, 197, 198, 199,
- 200, 201, 202, 203, 204, 205, 206, 207,
- 208, 209, 210, 211, 212, 213, 214, 215,
- 216, 217, 218, 219, 220, 221, 222, 223,
- 224, 225, 226, 227, 228, 229, 230, 231,
- 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247,
- 248, 249, 250, 251, 252, 253, 254, 255,
- 0,
-};
-
-/* Specific zigzag scan for 248 idct. NOTE that unlike the
- specification, we interleave the fields */
-static const uint8_t dv_248_zigzag[64] = {
- 0, 8, 1, 9, 16, 24, 2, 10,
- 17, 25, 32, 40, 48, 56, 33, 41,
- 18, 26, 3, 11, 4, 12, 19, 27,
- 34, 42, 49, 57, 50, 58, 35, 43,
- 20, 28, 5, 13, 6, 14, 21, 29,
- 36, 44, 51, 59, 52, 60, 37, 45,
- 22, 30, 7, 15, 23, 31, 38, 46,
- 53, 61, 54, 62, 39, 47, 55, 63,
-};
-
-/* unquant tables (not used directly) */
-static const uint8_t dv_88_areas[64] = {
- 0,0,0,1,1,1,2,2,
- 0,0,1,1,1,2,2,2,
- 0,1,1,1,2,2,2,3,
- 1,1,1,2,2,2,3,3,
- 1,1,2,2,2,3,3,3,
- 1,2,2,2,3,3,3,3,
- 2,2,2,3,3,3,3,3,
- 2,2,3,3,3,3,3,3,
-};
-
-static const uint8_t dv_248_areas[64] = {
- 0,0,1,1,1,2,2,3,
- 0,0,1,1,2,2,2,3,
- 0,1,1,2,2,2,3,3,
- 0,1,1,2,2,2,3,3,
- 1,1,2,2,2,3,3,3,
- 1,1,2,2,2,3,3,3,
- 1,2,2,2,3,3,3,3,
- 1,2,2,3,3,3,3,3,
-};
-
-static uint8_t dv_quant_shifts[22][4] = {
- { 3,3,4,4 },
- { 3,3,4,4 },
- { 2,3,3,4 },
- { 2,3,3,4 },
- { 2,2,3,3 },
- { 2,2,3,3 },
- { 1,2,2,3 },
- { 1,2,2,3 },
- { 1,1,2,2 },
- { 1,1,2,2 },
- { 0,1,1,2 },
- { 0,1,1,2 },
- { 0,0,1,1 },
- { 0,0,1,1 },
- { 0,0,0,1 },
- { 0,0,0,0 },
- { 0,0,0,0 },
- { 0,0,0,0 },
- { 0,0,0,0 },
- { 0,0,0,0 },
- { 0,0,0,0 },
- { 0,0,0,0 },
-};
-
-static const uint8_t dv_quant_offset[4] = { 6, 3, 0, 1 };
-
-/* NOTE: I prefer hardcoding the positionning of dv blocks, it is
- simpler :-) */
-
-static const uint16_t dv_place_420[1620] = {
- 0x0c24, 0x2412, 0x3036, 0x0000, 0x1848,
- 0x0e24, 0x2612, 0x3236, 0x0200, 0x1a48,
- 0x1024, 0x2812, 0x3436, 0x0400, 0x1c48,
- 0x1026, 0x2814, 0x3438, 0x0402, 0x1c4a,
- 0x0e26, 0x2614, 0x3238, 0x0202, 0x1a4a,
- 0x0c26, 0x2414, 0x3038, 0x0002, 0x184a,
- 0x0c28, 0x2416, 0x303a, 0x0004, 0x184c,
- 0x0e28, 0x2616, 0x323a, 0x0204, 0x1a4c,
- 0x1028, 0x2816, 0x343a, 0x0404, 0x1c4c,
- 0x102a, 0x2818, 0x343c, 0x0406, 0x1c4e,
- 0x0e2a, 0x2618, 0x323c, 0x0206, 0x1a4e,
- 0x0c2a, 0x2418, 0x303c, 0x0006, 0x184e,
- 0x0c2c, 0x241a, 0x303e, 0x0008, 0x1850,
- 0x0e2c, 0x261a, 0x323e, 0x0208, 0x1a50,
- 0x102c, 0x281a, 0x343e, 0x0408, 0x1c50,
- 0x102e, 0x281c, 0x3440, 0x040a, 0x1c52,
- 0x0e2e, 0x261c, 0x3240, 0x020a, 0x1a52,
- 0x0c2e, 0x241c, 0x3040, 0x000a, 0x1852,
- 0x0c30, 0x241e, 0x3042, 0x000c, 0x1854,
- 0x0e30, 0x261e, 0x3242, 0x020c, 0x1a54,
- 0x1030, 0x281e, 0x3442, 0x040c, 0x1c54,
- 0x1032, 0x2820, 0x3444, 0x040e, 0x1c56,
- 0x0e32, 0x2620, 0x3244, 0x020e, 0x1a56,
- 0x0c32, 0x2420, 0x3044, 0x000e, 0x1856,
- 0x0c34, 0x2422, 0x3046, 0x0010, 0x1858,
- 0x0e34, 0x2622, 0x3246, 0x0210, 0x1a58,
- 0x1034, 0x2822, 0x3446, 0x0410, 0x1c58,
- 0x1224, 0x2a12, 0x3636, 0x0600, 0x1e48,
- 0x1424, 0x2c12, 0x3836, 0x0800, 0x2048,
- 0x1624, 0x2e12, 0x3a36, 0x0a00, 0x2248,
- 0x1626, 0x2e14, 0x3a38, 0x0a02, 0x224a,
- 0x1426, 0x2c14, 0x3838, 0x0802, 0x204a,
- 0x1226, 0x2a14, 0x3638, 0x0602, 0x1e4a,
- 0x1228, 0x2a16, 0x363a, 0x0604, 0x1e4c,
- 0x1428, 0x2c16, 0x383a, 0x0804, 0x204c,
- 0x1628, 0x2e16, 0x3a3a, 0x0a04, 0x224c,
- 0x162a, 0x2e18, 0x3a3c, 0x0a06, 0x224e,
- 0x142a, 0x2c18, 0x383c, 0x0806, 0x204e,
- 0x122a, 0x2a18, 0x363c, 0x0606, 0x1e4e,
- 0x122c, 0x2a1a, 0x363e, 0x0608, 0x1e50,
- 0x142c, 0x2c1a, 0x383e, 0x0808, 0x2050,
- 0x162c, 0x2e1a, 0x3a3e, 0x0a08, 0x2250,
- 0x162e, 0x2e1c, 0x3a40, 0x0a0a, 0x2252,
- 0x142e, 0x2c1c, 0x3840, 0x080a, 0x2052,
- 0x122e, 0x2a1c, 0x3640, 0x060a, 0x1e52,
- 0x1230, 0x2a1e, 0x3642, 0x060c, 0x1e54,
- 0x1430, 0x2c1e, 0x3842, 0x080c, 0x2054,
- 0x1630, 0x2e1e, 0x3a42, 0x0a0c, 0x2254,
- 0x1632, 0x2e20, 0x3a44, 0x0a0e, 0x2256,
- 0x1432, 0x2c20, 0x3844, 0x080e, 0x2056,
- 0x1232, 0x2a20, 0x3644, 0x060e, 0x1e56,
- 0x1234, 0x2a22, 0x3646, 0x0610, 0x1e58,
- 0x1434, 0x2c22, 0x3846, 0x0810, 0x2058,
- 0x1634, 0x2e22, 0x3a46, 0x0a10, 0x2258,
- 0x1824, 0x3012, 0x3c36, 0x0c00, 0x2448,
- 0x1a24, 0x3212, 0x3e36, 0x0e00, 0x2648,
- 0x1c24, 0x3412, 0x4036, 0x1000, 0x2848,
- 0x1c26, 0x3414, 0x4038, 0x1002, 0x284a,
- 0x1a26, 0x3214, 0x3e38, 0x0e02, 0x264a,
- 0x1826, 0x3014, 0x3c38, 0x0c02, 0x244a,
- 0x1828, 0x3016, 0x3c3a, 0x0c04, 0x244c,
- 0x1a28, 0x3216, 0x3e3a, 0x0e04, 0x264c,
- 0x1c28, 0x3416, 0x403a, 0x1004, 0x284c,
- 0x1c2a, 0x3418, 0x403c, 0x1006, 0x284e,
- 0x1a2a, 0x3218, 0x3e3c, 0x0e06, 0x264e,
- 0x182a, 0x3018, 0x3c3c, 0x0c06, 0x244e,
- 0x182c, 0x301a, 0x3c3e, 0x0c08, 0x2450,
- 0x1a2c, 0x321a, 0x3e3e, 0x0e08, 0x2650,
- 0x1c2c, 0x341a, 0x403e, 0x1008, 0x2850,
- 0x1c2e, 0x341c, 0x4040, 0x100a, 0x2852,
- 0x1a2e, 0x321c, 0x3e40, 0x0e0a, 0x2652,
- 0x182e, 0x301c, 0x3c40, 0x0c0a, 0x2452,
- 0x1830, 0x301e, 0x3c42, 0x0c0c, 0x2454,
- 0x1a30, 0x321e, 0x3e42, 0x0e0c, 0x2654,
- 0x1c30, 0x341e, 0x4042, 0x100c, 0x2854,
- 0x1c32, 0x3420, 0x4044, 0x100e, 0x2856,
- 0x1a32, 0x3220, 0x3e44, 0x0e0e, 0x2656,
- 0x1832, 0x3020, 0x3c44, 0x0c0e, 0x2456,
- 0x1834, 0x3022, 0x3c46, 0x0c10, 0x2458,
- 0x1a34, 0x3222, 0x3e46, 0x0e10, 0x2658,
- 0x1c34, 0x3422, 0x4046, 0x1010, 0x2858,
- 0x1e24, 0x3612, 0x4236, 0x1200, 0x2a48,
- 0x2024, 0x3812, 0x4436, 0x1400, 0x2c48,
- 0x2224, 0x3a12, 0x4636, 0x1600, 0x2e48,
- 0x2226, 0x3a14, 0x4638, 0x1602, 0x2e4a,
- 0x2026, 0x3814, 0x4438, 0x1402, 0x2c4a,
- 0x1e26, 0x3614, 0x4238, 0x1202, 0x2a4a,
- 0x1e28, 0x3616, 0x423a, 0x1204, 0x2a4c,
- 0x2028, 0x3816, 0x443a, 0x1404, 0x2c4c,
- 0x2228, 0x3a16, 0x463a, 0x1604, 0x2e4c,
- 0x222a, 0x3a18, 0x463c, 0x1606, 0x2e4e,
- 0x202a, 0x3818, 0x443c, 0x1406, 0x2c4e,
- 0x1e2a, 0x3618, 0x423c, 0x1206, 0x2a4e,
- 0x1e2c, 0x361a, 0x423e, 0x1208, 0x2a50,
- 0x202c, 0x381a, 0x443e, 0x1408, 0x2c50,
- 0x222c, 0x3a1a, 0x463e, 0x1608, 0x2e50,
- 0x222e, 0x3a1c, 0x4640, 0x160a, 0x2e52,
- 0x202e, 0x381c, 0x4440, 0x140a, 0x2c52,
- 0x1e2e, 0x361c, 0x4240, 0x120a, 0x2a52,
- 0x1e30, 0x361e, 0x4242, 0x120c, 0x2a54,
- 0x2030, 0x381e, 0x4442, 0x140c, 0x2c54,
- 0x2230, 0x3a1e, 0x4642, 0x160c, 0x2e54,
- 0x2232, 0x3a20, 0x4644, 0x160e, 0x2e56,
- 0x2032, 0x3820, 0x4444, 0x140e, 0x2c56,
- 0x1e32, 0x3620, 0x4244, 0x120e, 0x2a56,
- 0x1e34, 0x3622, 0x4246, 0x1210, 0x2a58,
- 0x2034, 0x3822, 0x4446, 0x1410, 0x2c58,
- 0x2234, 0x3a22, 0x4646, 0x1610, 0x2e58,
- 0x2424, 0x3c12, 0x0036, 0x1800, 0x3048,
- 0x2624, 0x3e12, 0x0236, 0x1a00, 0x3248,
- 0x2824, 0x4012, 0x0436, 0x1c00, 0x3448,
- 0x2826, 0x4014, 0x0438, 0x1c02, 0x344a,
- 0x2626, 0x3e14, 0x0238, 0x1a02, 0x324a,
- 0x2426, 0x3c14, 0x0038, 0x1802, 0x304a,
- 0x2428, 0x3c16, 0x003a, 0x1804, 0x304c,
- 0x2628, 0x3e16, 0x023a, 0x1a04, 0x324c,
- 0x2828, 0x4016, 0x043a, 0x1c04, 0x344c,
- 0x282a, 0x4018, 0x043c, 0x1c06, 0x344e,
- 0x262a, 0x3e18, 0x023c, 0x1a06, 0x324e,
- 0x242a, 0x3c18, 0x003c, 0x1806, 0x304e,
- 0x242c, 0x3c1a, 0x003e, 0x1808, 0x3050,
- 0x262c, 0x3e1a, 0x023e, 0x1a08, 0x3250,
- 0x282c, 0x401a, 0x043e, 0x1c08, 0x3450,
- 0x282e, 0x401c, 0x0440, 0x1c0a, 0x3452,
- 0x262e, 0x3e1c, 0x0240, 0x1a0a, 0x3252,
- 0x242e, 0x3c1c, 0x0040, 0x180a, 0x3052,
- 0x2430, 0x3c1e, 0x0042, 0x180c, 0x3054,
- 0x2630, 0x3e1e, 0x0242, 0x1a0c, 0x3254,
- 0x2830, 0x401e, 0x0442, 0x1c0c, 0x3454,
- 0x2832, 0x4020, 0x0444, 0x1c0e, 0x3456,
- 0x2632, 0x3e20, 0x0244, 0x1a0e, 0x3256,
- 0x2432, 0x3c20, 0x0044, 0x180e, 0x3056,
- 0x2434, 0x3c22, 0x0046, 0x1810, 0x3058,
- 0x2634, 0x3e22, 0x0246, 0x1a10, 0x3258,
- 0x2834, 0x4022, 0x0446, 0x1c10, 0x3458,
- 0x2a24, 0x4212, 0x0636, 0x1e00, 0x3648,
- 0x2c24, 0x4412, 0x0836, 0x2000, 0x3848,
- 0x2e24, 0x4612, 0x0a36, 0x2200, 0x3a48,
- 0x2e26, 0x4614, 0x0a38, 0x2202, 0x3a4a,
- 0x2c26, 0x4414, 0x0838, 0x2002, 0x384a,
- 0x2a26, 0x4214, 0x0638, 0x1e02, 0x364a,
- 0x2a28, 0x4216, 0x063a, 0x1e04, 0x364c,
- 0x2c28, 0x4416, 0x083a, 0x2004, 0x384c,
- 0x2e28, 0x4616, 0x0a3a, 0x2204, 0x3a4c,
- 0x2e2a, 0x4618, 0x0a3c, 0x2206, 0x3a4e,
- 0x2c2a, 0x4418, 0x083c, 0x2006, 0x384e,
- 0x2a2a, 0x4218, 0x063c, 0x1e06, 0x364e,
- 0x2a2c, 0x421a, 0x063e, 0x1e08, 0x3650,
- 0x2c2c, 0x441a, 0x083e, 0x2008, 0x3850,
- 0x2e2c, 0x461a, 0x0a3e, 0x2208, 0x3a50,
- 0x2e2e, 0x461c, 0x0a40, 0x220a, 0x3a52,
- 0x2c2e, 0x441c, 0x0840, 0x200a, 0x3852,
- 0x2a2e, 0x421c, 0x0640, 0x1e0a, 0x3652,
- 0x2a30, 0x421e, 0x0642, 0x1e0c, 0x3654,
- 0x2c30, 0x441e, 0x0842, 0x200c, 0x3854,
- 0x2e30, 0x461e, 0x0a42, 0x220c, 0x3a54,
- 0x2e32, 0x4620, 0x0a44, 0x220e, 0x3a56,
- 0x2c32, 0x4420, 0x0844, 0x200e, 0x3856,
- 0x2a32, 0x4220, 0x0644, 0x1e0e, 0x3656,
- 0x2a34, 0x4222, 0x0646, 0x1e10, 0x3658,
- 0x2c34, 0x4422, 0x0846, 0x2010, 0x3858,
- 0x2e34, 0x4622, 0x0a46, 0x2210, 0x3a58,
- 0x3024, 0x0012, 0x0c36, 0x2400, 0x3c48,
- 0x3224, 0x0212, 0x0e36, 0x2600, 0x3e48,
- 0x3424, 0x0412, 0x1036, 0x2800, 0x4048,
- 0x3426, 0x0414, 0x1038, 0x2802, 0x404a,
- 0x3226, 0x0214, 0x0e38, 0x2602, 0x3e4a,
- 0x3026, 0x0014, 0x0c38, 0x2402, 0x3c4a,
- 0x3028, 0x0016, 0x0c3a, 0x2404, 0x3c4c,
- 0x3228, 0x0216, 0x0e3a, 0x2604, 0x3e4c,
- 0x3428, 0x0416, 0x103a, 0x2804, 0x404c,
- 0x342a, 0x0418, 0x103c, 0x2806, 0x404e,
- 0x322a, 0x0218, 0x0e3c, 0x2606, 0x3e4e,
- 0x302a, 0x0018, 0x0c3c, 0x2406, 0x3c4e,
- 0x302c, 0x001a, 0x0c3e, 0x2408, 0x3c50,
- 0x322c, 0x021a, 0x0e3e, 0x2608, 0x3e50,
- 0x342c, 0x041a, 0x103e, 0x2808, 0x4050,
- 0x342e, 0x041c, 0x1040, 0x280a, 0x4052,
- 0x322e, 0x021c, 0x0e40, 0x260a, 0x3e52,
- 0x302e, 0x001c, 0x0c40, 0x240a, 0x3c52,
- 0x3030, 0x001e, 0x0c42, 0x240c, 0x3c54,
- 0x3230, 0x021e, 0x0e42, 0x260c, 0x3e54,
- 0x3430, 0x041e, 0x1042, 0x280c, 0x4054,
- 0x3432, 0x0420, 0x1044, 0x280e, 0x4056,
- 0x3232, 0x0220, 0x0e44, 0x260e, 0x3e56,
- 0x3032, 0x0020, 0x0c44, 0x240e, 0x3c56,
- 0x3034, 0x0022, 0x0c46, 0x2410, 0x3c58,
- 0x3234, 0x0222, 0x0e46, 0x2610, 0x3e58,
- 0x3434, 0x0422, 0x1046, 0x2810, 0x4058,
- 0x3624, 0x0612, 0x1236, 0x2a00, 0x4248,
- 0x3824, 0x0812, 0x1436, 0x2c00, 0x4448,
- 0x3a24, 0x0a12, 0x1636, 0x2e00, 0x4648,
- 0x3a26, 0x0a14, 0x1638, 0x2e02, 0x464a,
- 0x3826, 0x0814, 0x1438, 0x2c02, 0x444a,
- 0x3626, 0x0614, 0x1238, 0x2a02, 0x424a,
- 0x3628, 0x0616, 0x123a, 0x2a04, 0x424c,
- 0x3828, 0x0816, 0x143a, 0x2c04, 0x444c,
- 0x3a28, 0x0a16, 0x163a, 0x2e04, 0x464c,
- 0x3a2a, 0x0a18, 0x163c, 0x2e06, 0x464e,
- 0x382a, 0x0818, 0x143c, 0x2c06, 0x444e,
- 0x362a, 0x0618, 0x123c, 0x2a06, 0x424e,
- 0x362c, 0x061a, 0x123e, 0x2a08, 0x4250,
- 0x382c, 0x081a, 0x143e, 0x2c08, 0x4450,
- 0x3a2c, 0x0a1a, 0x163e, 0x2e08, 0x4650,
- 0x3a2e, 0x0a1c, 0x1640, 0x2e0a, 0x4652,
- 0x382e, 0x081c, 0x1440, 0x2c0a, 0x4452,
- 0x362e, 0x061c, 0x1240, 0x2a0a, 0x4252,
- 0x3630, 0x061e, 0x1242, 0x2a0c, 0x4254,
- 0x3830, 0x081e, 0x1442, 0x2c0c, 0x4454,
- 0x3a30, 0x0a1e, 0x1642, 0x2e0c, 0x4654,
- 0x3a32, 0x0a20, 0x1644, 0x2e0e, 0x4656,
- 0x3832, 0x0820, 0x1444, 0x2c0e, 0x4456,
- 0x3632, 0x0620, 0x1244, 0x2a0e, 0x4256,
- 0x3634, 0x0622, 0x1246, 0x2a10, 0x4258,
- 0x3834, 0x0822, 0x1446, 0x2c10, 0x4458,
- 0x3a34, 0x0a22, 0x1646, 0x2e10, 0x4658,
- 0x3c24, 0x0c12, 0x1836, 0x3000, 0x0048,
- 0x3e24, 0x0e12, 0x1a36, 0x3200, 0x0248,
- 0x4024, 0x1012, 0x1c36, 0x3400, 0x0448,
- 0x4026, 0x1014, 0x1c38, 0x3402, 0x044a,
- 0x3e26, 0x0e14, 0x1a38, 0x3202, 0x024a,
- 0x3c26, 0x0c14, 0x1838, 0x3002, 0x004a,
- 0x3c28, 0x0c16, 0x183a, 0x3004, 0x004c,
- 0x3e28, 0x0e16, 0x1a3a, 0x3204, 0x024c,
- 0x4028, 0x1016, 0x1c3a, 0x3404, 0x044c,
- 0x402a, 0x1018, 0x1c3c, 0x3406, 0x044e,
- 0x3e2a, 0x0e18, 0x1a3c, 0x3206, 0x024e,
- 0x3c2a, 0x0c18, 0x183c, 0x3006, 0x004e,
- 0x3c2c, 0x0c1a, 0x183e, 0x3008, 0x0050,
- 0x3e2c, 0x0e1a, 0x1a3e, 0x3208, 0x0250,
- 0x402c, 0x101a, 0x1c3e, 0x3408, 0x0450,
- 0x402e, 0x101c, 0x1c40, 0x340a, 0x0452,
- 0x3e2e, 0x0e1c, 0x1a40, 0x320a, 0x0252,
- 0x3c2e, 0x0c1c, 0x1840, 0x300a, 0x0052,
- 0x3c30, 0x0c1e, 0x1842, 0x300c, 0x0054,
- 0x3e30, 0x0e1e, 0x1a42, 0x320c, 0x0254,
- 0x4030, 0x101e, 0x1c42, 0x340c, 0x0454,
- 0x4032, 0x1020, 0x1c44, 0x340e, 0x0456,
- 0x3e32, 0x0e20, 0x1a44, 0x320e, 0x0256,
- 0x3c32, 0x0c20, 0x1844, 0x300e, 0x0056,
- 0x3c34, 0x0c22, 0x1846, 0x3010, 0x0058,
- 0x3e34, 0x0e22, 0x1a46, 0x3210, 0x0258,
- 0x4034, 0x1022, 0x1c46, 0x3410, 0x0458,
- 0x4224, 0x1212, 0x1e36, 0x3600, 0x0648,
- 0x4424, 0x1412, 0x2036, 0x3800, 0x0848,
- 0x4624, 0x1612, 0x2236, 0x3a00, 0x0a48,
- 0x4626, 0x1614, 0x2238, 0x3a02, 0x0a4a,
- 0x4426, 0x1414, 0x2038, 0x3802, 0x084a,
- 0x4226, 0x1214, 0x1e38, 0x3602, 0x064a,
- 0x4228, 0x1216, 0x1e3a, 0x3604, 0x064c,
- 0x4428, 0x1416, 0x203a, 0x3804, 0x084c,
- 0x4628, 0x1616, 0x223a, 0x3a04, 0x0a4c,
- 0x462a, 0x1618, 0x223c, 0x3a06, 0x0a4e,
- 0x442a, 0x1418, 0x203c, 0x3806, 0x084e,
- 0x422a, 0x1218, 0x1e3c, 0x3606, 0x064e,
- 0x422c, 0x121a, 0x1e3e, 0x3608, 0x0650,
- 0x442c, 0x141a, 0x203e, 0x3808, 0x0850,
- 0x462c, 0x161a, 0x223e, 0x3a08, 0x0a50,
- 0x462e, 0x161c, 0x2240, 0x3a0a, 0x0a52,
- 0x442e, 0x141c, 0x2040, 0x380a, 0x0852,
- 0x422e, 0x121c, 0x1e40, 0x360a, 0x0652,
- 0x4230, 0x121e, 0x1e42, 0x360c, 0x0654,
- 0x4430, 0x141e, 0x2042, 0x380c, 0x0854,
- 0x4630, 0x161e, 0x2242, 0x3a0c, 0x0a54,
- 0x4632, 0x1620, 0x2244, 0x3a0e, 0x0a56,
- 0x4432, 0x1420, 0x2044, 0x380e, 0x0856,
- 0x4232, 0x1220, 0x1e44, 0x360e, 0x0656,
- 0x4234, 0x1222, 0x1e46, 0x3610, 0x0658,
- 0x4434, 0x1422, 0x2046, 0x3810, 0x0858,
- 0x4634, 0x1622, 0x2246, 0x3a10, 0x0a58,
- 0x0024, 0x1812, 0x2436, 0x3c00, 0x0c48,
- 0x0224, 0x1a12, 0x2636, 0x3e00, 0x0e48,
- 0x0424, 0x1c12, 0x2836, 0x4000, 0x1048,
- 0x0426, 0x1c14, 0x2838, 0x4002, 0x104a,
- 0x0226, 0x1a14, 0x2638, 0x3e02, 0x0e4a,
- 0x0026, 0x1814, 0x2438, 0x3c02, 0x0c4a,
- 0x0028, 0x1816, 0x243a, 0x3c04, 0x0c4c,
- 0x0228, 0x1a16, 0x263a, 0x3e04, 0x0e4c,
- 0x0428, 0x1c16, 0x283a, 0x4004, 0x104c,
- 0x042a, 0x1c18, 0x283c, 0x4006, 0x104e,
- 0x022a, 0x1a18, 0x263c, 0x3e06, 0x0e4e,
- 0x002a, 0x1818, 0x243c, 0x3c06, 0x0c4e,
- 0x002c, 0x181a, 0x243e, 0x3c08, 0x0c50,
- 0x022c, 0x1a1a, 0x263e, 0x3e08, 0x0e50,
- 0x042c, 0x1c1a, 0x283e, 0x4008, 0x1050,
- 0x042e, 0x1c1c, 0x2840, 0x400a, 0x1052,
- 0x022e, 0x1a1c, 0x2640, 0x3e0a, 0x0e52,
- 0x002e, 0x181c, 0x2440, 0x3c0a, 0x0c52,
- 0x0030, 0x181e, 0x2442, 0x3c0c, 0x0c54,
- 0x0230, 0x1a1e, 0x2642, 0x3e0c, 0x0e54,
- 0x0430, 0x1c1e, 0x2842, 0x400c, 0x1054,
- 0x0432, 0x1c20, 0x2844, 0x400e, 0x1056,
- 0x0232, 0x1a20, 0x2644, 0x3e0e, 0x0e56,
- 0x0032, 0x1820, 0x2444, 0x3c0e, 0x0c56,
- 0x0034, 0x1822, 0x2446, 0x3c10, 0x0c58,
- 0x0234, 0x1a22, 0x2646, 0x3e10, 0x0e58,
- 0x0434, 0x1c22, 0x2846, 0x4010, 0x1058,
- 0x0624, 0x1e12, 0x2a36, 0x4200, 0x1248,
- 0x0824, 0x2012, 0x2c36, 0x4400, 0x1448,
- 0x0a24, 0x2212, 0x2e36, 0x4600, 0x1648,
- 0x0a26, 0x2214, 0x2e38, 0x4602, 0x164a,
- 0x0826, 0x2014, 0x2c38, 0x4402, 0x144a,
- 0x0626, 0x1e14, 0x2a38, 0x4202, 0x124a,
- 0x0628, 0x1e16, 0x2a3a, 0x4204, 0x124c,
- 0x0828, 0x2016, 0x2c3a, 0x4404, 0x144c,
- 0x0a28, 0x2216, 0x2e3a, 0x4604, 0x164c,
- 0x0a2a, 0x2218, 0x2e3c, 0x4606, 0x164e,
- 0x082a, 0x2018, 0x2c3c, 0x4406, 0x144e,
- 0x062a, 0x1e18, 0x2a3c, 0x4206, 0x124e,
- 0x062c, 0x1e1a, 0x2a3e, 0x4208, 0x1250,
- 0x082c, 0x201a, 0x2c3e, 0x4408, 0x1450,
- 0x0a2c, 0x221a, 0x2e3e, 0x4608, 0x1650,
- 0x0a2e, 0x221c, 0x2e40, 0x460a, 0x1652,
- 0x082e, 0x201c, 0x2c40, 0x440a, 0x1452,
- 0x062e, 0x1e1c, 0x2a40, 0x420a, 0x1252,
- 0x0630, 0x1e1e, 0x2a42, 0x420c, 0x1254,
- 0x0830, 0x201e, 0x2c42, 0x440c, 0x1454,
- 0x0a30, 0x221e, 0x2e42, 0x460c, 0x1654,
- 0x0a32, 0x2220, 0x2e44, 0x460e, 0x1656,
- 0x0832, 0x2020, 0x2c44, 0x440e, 0x1456,
- 0x0632, 0x1e20, 0x2a44, 0x420e, 0x1256,
- 0x0634, 0x1e22, 0x2a46, 0x4210, 0x1258,
- 0x0834, 0x2022, 0x2c46, 0x4410, 0x1458,
- 0x0a34, 0x2222, 0x2e46, 0x4610, 0x1658,
-};
-
-static const uint16_t dv_place_411P[1620] = {
- 0x0c24, 0x2710, 0x3334, 0x0000, 0x1848,
- 0x0d24, 0x2810, 0x3434, 0x0100, 0x1948,
- 0x0e24, 0x2910, 0x3534, 0x0200, 0x1a48,
- 0x0f24, 0x2914, 0x3538, 0x0300, 0x1b48,
- 0x1024, 0x2814, 0x3438, 0x0400, 0x1c48,
- 0x1124, 0x2714, 0x3338, 0x0500, 0x1d48,
- 0x1128, 0x2614, 0x3238, 0x0504, 0x1d4c,
- 0x1028, 0x2514, 0x3138, 0x0404, 0x1c4c,
- 0x0f28, 0x2414, 0x3038, 0x0304, 0x1b4c,
- 0x0e28, 0x2418, 0x303c, 0x0204, 0x1a4c,
- 0x0d28, 0x2518, 0x313c, 0x0104, 0x194c,
- 0x0c28, 0x2618, 0x323c, 0x0004, 0x184c,
- 0x0c2c, 0x2718, 0x333c, 0x0008, 0x1850,
- 0x0d2c, 0x2818, 0x343c, 0x0108, 0x1950,
- 0x0e2c, 0x2918, 0x353c, 0x0208, 0x1a50,
- 0x0f2c, 0x291c, 0x3540, 0x0308, 0x1b50,
- 0x102c, 0x281c, 0x3440, 0x0408, 0x1c50,
- 0x112c, 0x271c, 0x3340, 0x0508, 0x1d50,
- 0x1130, 0x261c, 0x3240, 0x050c, 0x1d54,
- 0x1030, 0x251c, 0x3140, 0x040c, 0x1c54,
- 0x0f30, 0x241c, 0x3040, 0x030c, 0x1b54,
- 0x0e30, 0x2420, 0x3044, 0x020c, 0x1a54,
- 0x0d30, 0x2520, 0x3144, 0x010c, 0x1954,
- 0x0c30, 0x2620, 0x3244, 0x000c, 0x1854,
- 0x0c34, 0x2720, 0x3344, 0x0010, 0x1858,
- 0x0d34, 0x2820, 0x3444, 0x0110, 0x1a58,
- 0x0e34, 0x2920, 0x3544, 0x0210, 0x1c58,
- 0x1224, 0x2d10, 0x3934, 0x0600, 0x1e48,
- 0x1324, 0x2e10, 0x3a34, 0x0700, 0x1f48,
- 0x1424, 0x2f10, 0x3b34, 0x0800, 0x2048,
- 0x1524, 0x2f14, 0x3b38, 0x0900, 0x2148,
- 0x1624, 0x2e14, 0x3a38, 0x0a00, 0x2248,
- 0x1724, 0x2d14, 0x3938, 0x0b00, 0x2348,
- 0x1728, 0x2c14, 0x3838, 0x0b04, 0x234c,
- 0x1628, 0x2b14, 0x3738, 0x0a04, 0x224c,
- 0x1528, 0x2a14, 0x3638, 0x0904, 0x214c,
- 0x1428, 0x2a18, 0x363c, 0x0804, 0x204c,
- 0x1328, 0x2b18, 0x373c, 0x0704, 0x1f4c,
- 0x1228, 0x2c18, 0x383c, 0x0604, 0x1e4c,
- 0x122c, 0x2d18, 0x393c, 0x0608, 0x1e50,
- 0x132c, 0x2e18, 0x3a3c, 0x0708, 0x1f50,
- 0x142c, 0x2f18, 0x3b3c, 0x0808, 0x2050,
- 0x152c, 0x2f1c, 0x3b40, 0x0908, 0x2150,
- 0x162c, 0x2e1c, 0x3a40, 0x0a08, 0x2250,
- 0x172c, 0x2d1c, 0x3940, 0x0b08, 0x2350,
- 0x1730, 0x2c1c, 0x3840, 0x0b0c, 0x2354,
- 0x1630, 0x2b1c, 0x3740, 0x0a0c, 0x2254,
- 0x1530, 0x2a1c, 0x3640, 0x090c, 0x2154,
- 0x1430, 0x2a20, 0x3644, 0x080c, 0x2054,
- 0x1330, 0x2b20, 0x3744, 0x070c, 0x1f54,
- 0x1230, 0x2c20, 0x3844, 0x060c, 0x1e54,
- 0x1234, 0x2d20, 0x3944, 0x0610, 0x1e58,
- 0x1334, 0x2e20, 0x3a44, 0x0710, 0x2058,
- 0x1434, 0x2f20, 0x3b44, 0x0810, 0x2258,
- 0x1824, 0x3310, 0x3f34, 0x0c00, 0x2448,
- 0x1924, 0x3410, 0x4034, 0x0d00, 0x2548,
- 0x1a24, 0x3510, 0x4134, 0x0e00, 0x2648,
- 0x1b24, 0x3514, 0x4138, 0x0f00, 0x2748,
- 0x1c24, 0x3414, 0x4038, 0x1000, 0x2848,
- 0x1d24, 0x3314, 0x3f38, 0x1100, 0x2948,
- 0x1d28, 0x3214, 0x3e38, 0x1104, 0x294c,
- 0x1c28, 0x3114, 0x3d38, 0x1004, 0x284c,
- 0x1b28, 0x3014, 0x3c38, 0x0f04, 0x274c,
- 0x1a28, 0x3018, 0x3c3c, 0x0e04, 0x264c,
- 0x1928, 0x3118, 0x3d3c, 0x0d04, 0x254c,
- 0x1828, 0x3218, 0x3e3c, 0x0c04, 0x244c,
- 0x182c, 0x3318, 0x3f3c, 0x0c08, 0x2450,
- 0x192c, 0x3418, 0x403c, 0x0d08, 0x2550,
- 0x1a2c, 0x3518, 0x413c, 0x0e08, 0x2650,
- 0x1b2c, 0x351c, 0x4140, 0x0f08, 0x2750,
- 0x1c2c, 0x341c, 0x4040, 0x1008, 0x2850,
- 0x1d2c, 0x331c, 0x3f40, 0x1108, 0x2950,
- 0x1d30, 0x321c, 0x3e40, 0x110c, 0x2954,
- 0x1c30, 0x311c, 0x3d40, 0x100c, 0x2854,
- 0x1b30, 0x301c, 0x3c40, 0x0f0c, 0x2754,
- 0x1a30, 0x3020, 0x3c44, 0x0e0c, 0x2654,
- 0x1930, 0x3120, 0x3d44, 0x0d0c, 0x2554,
- 0x1830, 0x3220, 0x3e44, 0x0c0c, 0x2454,
- 0x1834, 0x3320, 0x3f44, 0x0c10, 0x2458,
- 0x1934, 0x3420, 0x4044, 0x0d10, 0x2658,
- 0x1a34, 0x3520, 0x4144, 0x0e10, 0x2858,
- 0x1e24, 0x3910, 0x4534, 0x1200, 0x2a48,
- 0x1f24, 0x3a10, 0x4634, 0x1300, 0x2b48,
- 0x2024, 0x3b10, 0x4734, 0x1400, 0x2c48,
- 0x2124, 0x3b14, 0x4738, 0x1500, 0x2d48,
- 0x2224, 0x3a14, 0x4638, 0x1600, 0x2e48,
- 0x2324, 0x3914, 0x4538, 0x1700, 0x2f48,
- 0x2328, 0x3814, 0x4438, 0x1704, 0x2f4c,
- 0x2228, 0x3714, 0x4338, 0x1604, 0x2e4c,
- 0x2128, 0x3614, 0x4238, 0x1504, 0x2d4c,
- 0x2028, 0x3618, 0x423c, 0x1404, 0x2c4c,
- 0x1f28, 0x3718, 0x433c, 0x1304, 0x2b4c,
- 0x1e28, 0x3818, 0x443c, 0x1204, 0x2a4c,
- 0x1e2c, 0x3918, 0x453c, 0x1208, 0x2a50,
- 0x1f2c, 0x3a18, 0x463c, 0x1308, 0x2b50,
- 0x202c, 0x3b18, 0x473c, 0x1408, 0x2c50,
- 0x212c, 0x3b1c, 0x4740, 0x1508, 0x2d50,
- 0x222c, 0x3a1c, 0x4640, 0x1608, 0x2e50,
- 0x232c, 0x391c, 0x4540, 0x1708, 0x2f50,
- 0x2330, 0x381c, 0x4440, 0x170c, 0x2f54,
- 0x2230, 0x371c, 0x4340, 0x160c, 0x2e54,
- 0x2130, 0x361c, 0x4240, 0x150c, 0x2d54,
- 0x2030, 0x3620, 0x4244, 0x140c, 0x2c54,
- 0x1f30, 0x3720, 0x4344, 0x130c, 0x2b54,
- 0x1e30, 0x3820, 0x4444, 0x120c, 0x2a54,
- 0x1e34, 0x3920, 0x4544, 0x1210, 0x2a58,
- 0x1f34, 0x3a20, 0x4644, 0x1310, 0x2c58,
- 0x2034, 0x3b20, 0x4744, 0x1410, 0x2e58,
- 0x2424, 0x3f10, 0x0334, 0x1800, 0x3048,
- 0x2524, 0x4010, 0x0434, 0x1900, 0x3148,
- 0x2624, 0x4110, 0x0534, 0x1a00, 0x3248,
- 0x2724, 0x4114, 0x0538, 0x1b00, 0x3348,
- 0x2824, 0x4014, 0x0438, 0x1c00, 0x3448,
- 0x2924, 0x3f14, 0x0338, 0x1d00, 0x3548,
- 0x2928, 0x3e14, 0x0238, 0x1d04, 0x354c,
- 0x2828, 0x3d14, 0x0138, 0x1c04, 0x344c,
- 0x2728, 0x3c14, 0x0038, 0x1b04, 0x334c,
- 0x2628, 0x3c18, 0x003c, 0x1a04, 0x324c,
- 0x2528, 0x3d18, 0x013c, 0x1904, 0x314c,
- 0x2428, 0x3e18, 0x023c, 0x1804, 0x304c,
- 0x242c, 0x3f18, 0x033c, 0x1808, 0x3050,
- 0x252c, 0x4018, 0x043c, 0x1908, 0x3150,
- 0x262c, 0x4118, 0x053c, 0x1a08, 0x3250,
- 0x272c, 0x411c, 0x0540, 0x1b08, 0x3350,
- 0x282c, 0x401c, 0x0440, 0x1c08, 0x3450,
- 0x292c, 0x3f1c, 0x0340, 0x1d08, 0x3550,
- 0x2930, 0x3e1c, 0x0240, 0x1d0c, 0x3554,
- 0x2830, 0x3d1c, 0x0140, 0x1c0c, 0x3454,
- 0x2730, 0x3c1c, 0x0040, 0x1b0c, 0x3354,
- 0x2630, 0x3c20, 0x0044, 0x1a0c, 0x3254,
- 0x2530, 0x3d20, 0x0144, 0x190c, 0x3154,
- 0x2430, 0x3e20, 0x0244, 0x180c, 0x3054,
- 0x2434, 0x3f20, 0x0344, 0x1810, 0x3058,
- 0x2534, 0x4020, 0x0444, 0x1910, 0x3258,
- 0x2634, 0x4120, 0x0544, 0x1a10, 0x3458,
- 0x2a24, 0x4510, 0x0934, 0x1e00, 0x3648,
- 0x2b24, 0x4610, 0x0a34, 0x1f00, 0x3748,
- 0x2c24, 0x4710, 0x0b34, 0x2000, 0x3848,
- 0x2d24, 0x4714, 0x0b38, 0x2100, 0x3948,
- 0x2e24, 0x4614, 0x0a38, 0x2200, 0x3a48,
- 0x2f24, 0x4514, 0x0938, 0x2300, 0x3b48,
- 0x2f28, 0x4414, 0x0838, 0x2304, 0x3b4c,
- 0x2e28, 0x4314, 0x0738, 0x2204, 0x3a4c,
- 0x2d28, 0x4214, 0x0638, 0x2104, 0x394c,
- 0x2c28, 0x4218, 0x063c, 0x2004, 0x384c,
- 0x2b28, 0x4318, 0x073c, 0x1f04, 0x374c,
- 0x2a28, 0x4418, 0x083c, 0x1e04, 0x364c,
- 0x2a2c, 0x4518, 0x093c, 0x1e08, 0x3650,
- 0x2b2c, 0x4618, 0x0a3c, 0x1f08, 0x3750,
- 0x2c2c, 0x4718, 0x0b3c, 0x2008, 0x3850,
- 0x2d2c, 0x471c, 0x0b40, 0x2108, 0x3950,
- 0x2e2c, 0x461c, 0x0a40, 0x2208, 0x3a50,
- 0x2f2c, 0x451c, 0x0940, 0x2308, 0x3b50,
- 0x2f30, 0x441c, 0x0840, 0x230c, 0x3b54,
- 0x2e30, 0x431c, 0x0740, 0x220c, 0x3a54,
- 0x2d30, 0x421c, 0x0640, 0x210c, 0x3954,
- 0x2c30, 0x4220, 0x0644, 0x200c, 0x3854,
- 0x2b30, 0x4320, 0x0744, 0x1f0c, 0x3754,
- 0x2a30, 0x4420, 0x0844, 0x1e0c, 0x3654,
- 0x2a34, 0x4520, 0x0944, 0x1e10, 0x3658,
- 0x2b34, 0x4620, 0x0a44, 0x1f10, 0x3858,
- 0x2c34, 0x4720, 0x0b44, 0x2010, 0x3a58,
- 0x3024, 0x0310, 0x0f34, 0x2400, 0x3c48,
- 0x3124, 0x0410, 0x1034, 0x2500, 0x3d48,
- 0x3224, 0x0510, 0x1134, 0x2600, 0x3e48,
- 0x3324, 0x0514, 0x1138, 0x2700, 0x3f48,
- 0x3424, 0x0414, 0x1038, 0x2800, 0x4048,
- 0x3524, 0x0314, 0x0f38, 0x2900, 0x4148,
- 0x3528, 0x0214, 0x0e38, 0x2904, 0x414c,
- 0x3428, 0x0114, 0x0d38, 0x2804, 0x404c,
- 0x3328, 0x0014, 0x0c38, 0x2704, 0x3f4c,
- 0x3228, 0x0018, 0x0c3c, 0x2604, 0x3e4c,
- 0x3128, 0x0118, 0x0d3c, 0x2504, 0x3d4c,
- 0x3028, 0x0218, 0x0e3c, 0x2404, 0x3c4c,
- 0x302c, 0x0318, 0x0f3c, 0x2408, 0x3c50,
- 0x312c, 0x0418, 0x103c, 0x2508, 0x3d50,
- 0x322c, 0x0518, 0x113c, 0x2608, 0x3e50,
- 0x332c, 0x051c, 0x1140, 0x2708, 0x3f50,
- 0x342c, 0x041c, 0x1040, 0x2808, 0x4050,
- 0x352c, 0x031c, 0x0f40, 0x2908, 0x4150,
- 0x3530, 0x021c, 0x0e40, 0x290c, 0x4154,
- 0x3430, 0x011c, 0x0d40, 0x280c, 0x4054,
- 0x3330, 0x001c, 0x0c40, 0x270c, 0x3f54,
- 0x3230, 0x0020, 0x0c44, 0x260c, 0x3e54,
- 0x3130, 0x0120, 0x0d44, 0x250c, 0x3d54,
- 0x3030, 0x0220, 0x0e44, 0x240c, 0x3c54,
- 0x3034, 0x0320, 0x0f44, 0x2410, 0x3c58,
- 0x3134, 0x0420, 0x1044, 0x2510, 0x3e58,
- 0x3234, 0x0520, 0x1144, 0x2610, 0x4058,
- 0x3624, 0x0910, 0x1534, 0x2a00, 0x4248,
- 0x3724, 0x0a10, 0x1634, 0x2b00, 0x4348,
- 0x3824, 0x0b10, 0x1734, 0x2c00, 0x4448,
- 0x3924, 0x0b14, 0x1738, 0x2d00, 0x4548,
- 0x3a24, 0x0a14, 0x1638, 0x2e00, 0x4648,
- 0x3b24, 0x0914, 0x1538, 0x2f00, 0x4748,
- 0x3b28, 0x0814, 0x1438, 0x2f04, 0x474c,
- 0x3a28, 0x0714, 0x1338, 0x2e04, 0x464c,
- 0x3928, 0x0614, 0x1238, 0x2d04, 0x454c,
- 0x3828, 0x0618, 0x123c, 0x2c04, 0x444c,
- 0x3728, 0x0718, 0x133c, 0x2b04, 0x434c,
- 0x3628, 0x0818, 0x143c, 0x2a04, 0x424c,
- 0x362c, 0x0918, 0x153c, 0x2a08, 0x4250,
- 0x372c, 0x0a18, 0x163c, 0x2b08, 0x4350,
- 0x382c, 0x0b18, 0x173c, 0x2c08, 0x4450,
- 0x392c, 0x0b1c, 0x1740, 0x2d08, 0x4550,
- 0x3a2c, 0x0a1c, 0x1640, 0x2e08, 0x4650,
- 0x3b2c, 0x091c, 0x1540, 0x2f08, 0x4750,
- 0x3b30, 0x081c, 0x1440, 0x2f0c, 0x4754,
- 0x3a30, 0x071c, 0x1340, 0x2e0c, 0x4654,
- 0x3930, 0x061c, 0x1240, 0x2d0c, 0x4554,
- 0x3830, 0x0620, 0x1244, 0x2c0c, 0x4454,
- 0x3730, 0x0720, 0x1344, 0x2b0c, 0x4354,
- 0x3630, 0x0820, 0x1444, 0x2a0c, 0x4254,
- 0x3634, 0x0920, 0x1544, 0x2a10, 0x4258,
- 0x3734, 0x0a20, 0x1644, 0x2b10, 0x4458,
- 0x3834, 0x0b20, 0x1744, 0x2c10, 0x4658,
- 0x3c24, 0x0f10, 0x1b34, 0x3000, 0x0048,
- 0x3d24, 0x1010, 0x1c34, 0x3100, 0x0148,
- 0x3e24, 0x1110, 0x1d34, 0x3200, 0x0248,
- 0x3f24, 0x1114, 0x1d38, 0x3300, 0x0348,
- 0x4024, 0x1014, 0x1c38, 0x3400, 0x0448,
- 0x4124, 0x0f14, 0x1b38, 0x3500, 0x0548,
- 0x4128, 0x0e14, 0x1a38, 0x3504, 0x054c,
- 0x4028, 0x0d14, 0x1938, 0x3404, 0x044c,
- 0x3f28, 0x0c14, 0x1838, 0x3304, 0x034c,
- 0x3e28, 0x0c18, 0x183c, 0x3204, 0x024c,
- 0x3d28, 0x0d18, 0x193c, 0x3104, 0x014c,
- 0x3c28, 0x0e18, 0x1a3c, 0x3004, 0x004c,
- 0x3c2c, 0x0f18, 0x1b3c, 0x3008, 0x0050,
- 0x3d2c, 0x1018, 0x1c3c, 0x3108, 0x0150,
- 0x3e2c, 0x1118, 0x1d3c, 0x3208, 0x0250,
- 0x3f2c, 0x111c, 0x1d40, 0x3308, 0x0350,
- 0x402c, 0x101c, 0x1c40, 0x3408, 0x0450,
- 0x412c, 0x0f1c, 0x1b40, 0x3508, 0x0550,
- 0x4130, 0x0e1c, 0x1a40, 0x350c, 0x0554,
- 0x4030, 0x0d1c, 0x1940, 0x340c, 0x0454,
- 0x3f30, 0x0c1c, 0x1840, 0x330c, 0x0354,
- 0x3e30, 0x0c20, 0x1844, 0x320c, 0x0254,
- 0x3d30, 0x0d20, 0x1944, 0x310c, 0x0154,
- 0x3c30, 0x0e20, 0x1a44, 0x300c, 0x0054,
- 0x3c34, 0x0f20, 0x1b44, 0x3010, 0x0058,
- 0x3d34, 0x1020, 0x1c44, 0x3110, 0x0258,
- 0x3e34, 0x1120, 0x1d44, 0x3210, 0x0458,
- 0x4224, 0x1510, 0x2134, 0x3600, 0x0648,
- 0x4324, 0x1610, 0x2234, 0x3700, 0x0748,
- 0x4424, 0x1710, 0x2334, 0x3800, 0x0848,
- 0x4524, 0x1714, 0x2338, 0x3900, 0x0948,
- 0x4624, 0x1614, 0x2238, 0x3a00, 0x0a48,
- 0x4724, 0x1514, 0x2138, 0x3b00, 0x0b48,
- 0x4728, 0x1414, 0x2038, 0x3b04, 0x0b4c,
- 0x4628, 0x1314, 0x1f38, 0x3a04, 0x0a4c,
- 0x4528, 0x1214, 0x1e38, 0x3904, 0x094c,
- 0x4428, 0x1218, 0x1e3c, 0x3804, 0x084c,
- 0x4328, 0x1318, 0x1f3c, 0x3704, 0x074c,
- 0x4228, 0x1418, 0x203c, 0x3604, 0x064c,
- 0x422c, 0x1518, 0x213c, 0x3608, 0x0650,
- 0x432c, 0x1618, 0x223c, 0x3708, 0x0750,
- 0x442c, 0x1718, 0x233c, 0x3808, 0x0850,
- 0x452c, 0x171c, 0x2340, 0x3908, 0x0950,
- 0x462c, 0x161c, 0x2240, 0x3a08, 0x0a50,
- 0x472c, 0x151c, 0x2140, 0x3b08, 0x0b50,
- 0x4730, 0x141c, 0x2040, 0x3b0c, 0x0b54,
- 0x4630, 0x131c, 0x1f40, 0x3a0c, 0x0a54,
- 0x4530, 0x121c, 0x1e40, 0x390c, 0x0954,
- 0x4430, 0x1220, 0x1e44, 0x380c, 0x0854,
- 0x4330, 0x1320, 0x1f44, 0x370c, 0x0754,
- 0x4230, 0x1420, 0x2044, 0x360c, 0x0654,
- 0x4234, 0x1520, 0x2144, 0x3610, 0x0658,
- 0x4334, 0x1620, 0x2244, 0x3710, 0x0858,
- 0x4434, 0x1720, 0x2344, 0x3810, 0x0a58,
- 0x0024, 0x1b10, 0x2734, 0x3c00, 0x0c48,
- 0x0124, 0x1c10, 0x2834, 0x3d00, 0x0d48,
- 0x0224, 0x1d10, 0x2934, 0x3e00, 0x0e48,
- 0x0324, 0x1d14, 0x2938, 0x3f00, 0x0f48,
- 0x0424, 0x1c14, 0x2838, 0x4000, 0x1048,
- 0x0524, 0x1b14, 0x2738, 0x4100, 0x1148,
- 0x0528, 0x1a14, 0x2638, 0x4104, 0x114c,
- 0x0428, 0x1914, 0x2538, 0x4004, 0x104c,
- 0x0328, 0x1814, 0x2438, 0x3f04, 0x0f4c,
- 0x0228, 0x1818, 0x243c, 0x3e04, 0x0e4c,
- 0x0128, 0x1918, 0x253c, 0x3d04, 0x0d4c,
- 0x0028, 0x1a18, 0x263c, 0x3c04, 0x0c4c,
- 0x002c, 0x1b18, 0x273c, 0x3c08, 0x0c50,
- 0x012c, 0x1c18, 0x283c, 0x3d08, 0x0d50,
- 0x022c, 0x1d18, 0x293c, 0x3e08, 0x0e50,
- 0x032c, 0x1d1c, 0x2940, 0x3f08, 0x0f50,
- 0x042c, 0x1c1c, 0x2840, 0x4008, 0x1050,
- 0x052c, 0x1b1c, 0x2740, 0x4108, 0x1150,
- 0x0530, 0x1a1c, 0x2640, 0x410c, 0x1154,
- 0x0430, 0x191c, 0x2540, 0x400c, 0x1054,
- 0x0330, 0x181c, 0x2440, 0x3f0c, 0x0f54,
- 0x0230, 0x1820, 0x2444, 0x3e0c, 0x0e54,
- 0x0130, 0x1920, 0x2544, 0x3d0c, 0x0d54,
- 0x0030, 0x1a20, 0x2644, 0x3c0c, 0x0c54,
- 0x0034, 0x1b20, 0x2744, 0x3c10, 0x0c58,
- 0x0134, 0x1c20, 0x2844, 0x3d10, 0x0e58,
- 0x0234, 0x1d20, 0x2944, 0x3e10, 0x1058,
- 0x0624, 0x2110, 0x2d34, 0x4200, 0x1248,
- 0x0724, 0x2210, 0x2e34, 0x4300, 0x1348,
- 0x0824, 0x2310, 0x2f34, 0x4400, 0x1448,
- 0x0924, 0x2314, 0x2f38, 0x4500, 0x1548,
- 0x0a24, 0x2214, 0x2e38, 0x4600, 0x1648,
- 0x0b24, 0x2114, 0x2d38, 0x4700, 0x1748,
- 0x0b28, 0x2014, 0x2c38, 0x4704, 0x174c,
- 0x0a28, 0x1f14, 0x2b38, 0x4604, 0x164c,
- 0x0928, 0x1e14, 0x2a38, 0x4504, 0x154c,
- 0x0828, 0x1e18, 0x2a3c, 0x4404, 0x144c,
- 0x0728, 0x1f18, 0x2b3c, 0x4304, 0x134c,
- 0x0628, 0x2018, 0x2c3c, 0x4204, 0x124c,
- 0x062c, 0x2118, 0x2d3c, 0x4208, 0x1250,
- 0x072c, 0x2218, 0x2e3c, 0x4308, 0x1350,
- 0x082c, 0x2318, 0x2f3c, 0x4408, 0x1450,
- 0x092c, 0x231c, 0x2f40, 0x4508, 0x1550,
- 0x0a2c, 0x221c, 0x2e40, 0x4608, 0x1650,
- 0x0b2c, 0x211c, 0x2d40, 0x4708, 0x1750,
- 0x0b30, 0x201c, 0x2c40, 0x470c, 0x1754,
- 0x0a30, 0x1f1c, 0x2b40, 0x460c, 0x1654,
- 0x0930, 0x1e1c, 0x2a40, 0x450c, 0x1554,
- 0x0830, 0x1e20, 0x2a44, 0x440c, 0x1454,
- 0x0730, 0x1f20, 0x2b44, 0x430c, 0x1354,
- 0x0630, 0x2020, 0x2c44, 0x420c, 0x1254,
- 0x0634, 0x2120, 0x2d44, 0x4210, 0x1258,
- 0x0734, 0x2220, 0x2e44, 0x4310, 0x1458,
- 0x0834, 0x2320, 0x2f44, 0x4410, 0x1658,
-};
-
-static const uint16_t dv_place_411[1350] = {
- 0x0c24, 0x2710, 0x3334, 0x0000, 0x1848,
- 0x0d24, 0x2810, 0x3434, 0x0100, 0x1948,
- 0x0e24, 0x2910, 0x3534, 0x0200, 0x1a48,
- 0x0f24, 0x2914, 0x3538, 0x0300, 0x1b48,
- 0x1024, 0x2814, 0x3438, 0x0400, 0x1c48,
- 0x1124, 0x2714, 0x3338, 0x0500, 0x1d48,
- 0x1128, 0x2614, 0x3238, 0x0504, 0x1d4c,
- 0x1028, 0x2514, 0x3138, 0x0404, 0x1c4c,
- 0x0f28, 0x2414, 0x3038, 0x0304, 0x1b4c,
- 0x0e28, 0x2418, 0x303c, 0x0204, 0x1a4c,
- 0x0d28, 0x2518, 0x313c, 0x0104, 0x194c,
- 0x0c28, 0x2618, 0x323c, 0x0004, 0x184c,
- 0x0c2c, 0x2718, 0x333c, 0x0008, 0x1850,
- 0x0d2c, 0x2818, 0x343c, 0x0108, 0x1950,
- 0x0e2c, 0x2918, 0x353c, 0x0208, 0x1a50,
- 0x0f2c, 0x291c, 0x3540, 0x0308, 0x1b50,
- 0x102c, 0x281c, 0x3440, 0x0408, 0x1c50,
- 0x112c, 0x271c, 0x3340, 0x0508, 0x1d50,
- 0x1130, 0x261c, 0x3240, 0x050c, 0x1d54,
- 0x1030, 0x251c, 0x3140, 0x040c, 0x1c54,
- 0x0f30, 0x241c, 0x3040, 0x030c, 0x1b54,
- 0x0e30, 0x2420, 0x3044, 0x020c, 0x1a54,
- 0x0d30, 0x2520, 0x3144, 0x010c, 0x1954,
- 0x0c30, 0x2620, 0x3244, 0x000c, 0x1854,
- 0x0c34, 0x2720, 0x3344, 0x0010, 0x1858,
- 0x0d34, 0x2820, 0x3444, 0x0110, 0x1a58,
- 0x0e34, 0x2920, 0x3544, 0x0210, 0x1c58,
- 0x1224, 0x2d10, 0x3934, 0x0600, 0x1e48,
- 0x1324, 0x2e10, 0x3a34, 0x0700, 0x1f48,
- 0x1424, 0x2f10, 0x3b34, 0x0800, 0x2048,
- 0x1524, 0x2f14, 0x3b38, 0x0900, 0x2148,
- 0x1624, 0x2e14, 0x3a38, 0x0a00, 0x2248,
- 0x1724, 0x2d14, 0x3938, 0x0b00, 0x2348,
- 0x1728, 0x2c14, 0x3838, 0x0b04, 0x234c,
- 0x1628, 0x2b14, 0x3738, 0x0a04, 0x224c,
- 0x1528, 0x2a14, 0x3638, 0x0904, 0x214c,
- 0x1428, 0x2a18, 0x363c, 0x0804, 0x204c,
- 0x1328, 0x2b18, 0x373c, 0x0704, 0x1f4c,
- 0x1228, 0x2c18, 0x383c, 0x0604, 0x1e4c,
- 0x122c, 0x2d18, 0x393c, 0x0608, 0x1e50,
- 0x132c, 0x2e18, 0x3a3c, 0x0708, 0x1f50,
- 0x142c, 0x2f18, 0x3b3c, 0x0808, 0x2050,
- 0x152c, 0x2f1c, 0x3b40, 0x0908, 0x2150,
- 0x162c, 0x2e1c, 0x3a40, 0x0a08, 0x2250,
- 0x172c, 0x2d1c, 0x3940, 0x0b08, 0x2350,
- 0x1730, 0x2c1c, 0x3840, 0x0b0c, 0x2354,
- 0x1630, 0x2b1c, 0x3740, 0x0a0c, 0x2254,
- 0x1530, 0x2a1c, 0x3640, 0x090c, 0x2154,
- 0x1430, 0x2a20, 0x3644, 0x080c, 0x2054,
- 0x1330, 0x2b20, 0x3744, 0x070c, 0x1f54,
- 0x1230, 0x2c20, 0x3844, 0x060c, 0x1e54,
- 0x1234, 0x2d20, 0x3944, 0x0610, 0x1e58,
- 0x1334, 0x2e20, 0x3a44, 0x0710, 0x2058,
- 0x1434, 0x2f20, 0x3b44, 0x0810, 0x2258,
- 0x1824, 0x3310, 0x0334, 0x0c00, 0x2448,
- 0x1924, 0x3410, 0x0434, 0x0d00, 0x2548,
- 0x1a24, 0x3510, 0x0534, 0x0e00, 0x2648,
- 0x1b24, 0x3514, 0x0538, 0x0f00, 0x2748,
- 0x1c24, 0x3414, 0x0438, 0x1000, 0x2848,
- 0x1d24, 0x3314, 0x0338, 0x1100, 0x2948,
- 0x1d28, 0x3214, 0x0238, 0x1104, 0x294c,
- 0x1c28, 0x3114, 0x0138, 0x1004, 0x284c,
- 0x1b28, 0x3014, 0x0038, 0x0f04, 0x274c,
- 0x1a28, 0x3018, 0x003c, 0x0e04, 0x264c,
- 0x1928, 0x3118, 0x013c, 0x0d04, 0x254c,
- 0x1828, 0x3218, 0x023c, 0x0c04, 0x244c,
- 0x182c, 0x3318, 0x033c, 0x0c08, 0x2450,
- 0x192c, 0x3418, 0x043c, 0x0d08, 0x2550,
- 0x1a2c, 0x3518, 0x053c, 0x0e08, 0x2650,
- 0x1b2c, 0x351c, 0x0540, 0x0f08, 0x2750,
- 0x1c2c, 0x341c, 0x0440, 0x1008, 0x2850,
- 0x1d2c, 0x331c, 0x0340, 0x1108, 0x2950,
- 0x1d30, 0x321c, 0x0240, 0x110c, 0x2954,
- 0x1c30, 0x311c, 0x0140, 0x100c, 0x2854,
- 0x1b30, 0x301c, 0x0040, 0x0f0c, 0x2754,
- 0x1a30, 0x3020, 0x0044, 0x0e0c, 0x2654,
- 0x1930, 0x3120, 0x0144, 0x0d0c, 0x2554,
- 0x1830, 0x3220, 0x0244, 0x0c0c, 0x2454,
- 0x1834, 0x3320, 0x0344, 0x0c10, 0x2458,
- 0x1934, 0x3420, 0x0444, 0x0d10, 0x2658,
- 0x1a34, 0x3520, 0x0544, 0x0e10, 0x2858,
- 0x1e24, 0x3910, 0x0934, 0x1200, 0x2a48,
- 0x1f24, 0x3a10, 0x0a34, 0x1300, 0x2b48,
- 0x2024, 0x3b10, 0x0b34, 0x1400, 0x2c48,
- 0x2124, 0x3b14, 0x0b38, 0x1500, 0x2d48,
- 0x2224, 0x3a14, 0x0a38, 0x1600, 0x2e48,
- 0x2324, 0x3914, 0x0938, 0x1700, 0x2f48,
- 0x2328, 0x3814, 0x0838, 0x1704, 0x2f4c,
- 0x2228, 0x3714, 0x0738, 0x1604, 0x2e4c,
- 0x2128, 0x3614, 0x0638, 0x1504, 0x2d4c,
- 0x2028, 0x3618, 0x063c, 0x1404, 0x2c4c,
- 0x1f28, 0x3718, 0x073c, 0x1304, 0x2b4c,
- 0x1e28, 0x3818, 0x083c, 0x1204, 0x2a4c,
- 0x1e2c, 0x3918, 0x093c, 0x1208, 0x2a50,
- 0x1f2c, 0x3a18, 0x0a3c, 0x1308, 0x2b50,
- 0x202c, 0x3b18, 0x0b3c, 0x1408, 0x2c50,
- 0x212c, 0x3b1c, 0x0b40, 0x1508, 0x2d50,
- 0x222c, 0x3a1c, 0x0a40, 0x1608, 0x2e50,
- 0x232c, 0x391c, 0x0940, 0x1708, 0x2f50,
- 0x2330, 0x381c, 0x0840, 0x170c, 0x2f54,
- 0x2230, 0x371c, 0x0740, 0x160c, 0x2e54,
- 0x2130, 0x361c, 0x0640, 0x150c, 0x2d54,
- 0x2030, 0x3620, 0x0644, 0x140c, 0x2c54,
- 0x1f30, 0x3720, 0x0744, 0x130c, 0x2b54,
- 0x1e30, 0x3820, 0x0844, 0x120c, 0x2a54,
- 0x1e34, 0x3920, 0x0944, 0x1210, 0x2a58,
- 0x1f34, 0x3a20, 0x0a44, 0x1310, 0x2c58,
- 0x2034, 0x3b20, 0x0b44, 0x1410, 0x2e58,
- 0x2424, 0x0310, 0x0f34, 0x1800, 0x3048,
- 0x2524, 0x0410, 0x1034, 0x1900, 0x3148,
- 0x2624, 0x0510, 0x1134, 0x1a00, 0x3248,
- 0x2724, 0x0514, 0x1138, 0x1b00, 0x3348,
- 0x2824, 0x0414, 0x1038, 0x1c00, 0x3448,
- 0x2924, 0x0314, 0x0f38, 0x1d00, 0x3548,
- 0x2928, 0x0214, 0x0e38, 0x1d04, 0x354c,
- 0x2828, 0x0114, 0x0d38, 0x1c04, 0x344c,
- 0x2728, 0x0014, 0x0c38, 0x1b04, 0x334c,
- 0x2628, 0x0018, 0x0c3c, 0x1a04, 0x324c,
- 0x2528, 0x0118, 0x0d3c, 0x1904, 0x314c,
- 0x2428, 0x0218, 0x0e3c, 0x1804, 0x304c,
- 0x242c, 0x0318, 0x0f3c, 0x1808, 0x3050,
- 0x252c, 0x0418, 0x103c, 0x1908, 0x3150,
- 0x262c, 0x0518, 0x113c, 0x1a08, 0x3250,
- 0x272c, 0x051c, 0x1140, 0x1b08, 0x3350,
- 0x282c, 0x041c, 0x1040, 0x1c08, 0x3450,
- 0x292c, 0x031c, 0x0f40, 0x1d08, 0x3550,
- 0x2930, 0x021c, 0x0e40, 0x1d0c, 0x3554,
- 0x2830, 0x011c, 0x0d40, 0x1c0c, 0x3454,
- 0x2730, 0x001c, 0x0c40, 0x1b0c, 0x3354,
- 0x2630, 0x0020, 0x0c44, 0x1a0c, 0x3254,
- 0x2530, 0x0120, 0x0d44, 0x190c, 0x3154,
- 0x2430, 0x0220, 0x0e44, 0x180c, 0x3054,
- 0x2434, 0x0320, 0x0f44, 0x1810, 0x3058,
- 0x2534, 0x0420, 0x1044, 0x1910, 0x3258,
- 0x2634, 0x0520, 0x1144, 0x1a10, 0x3458,
- 0x2a24, 0x0910, 0x1534, 0x1e00, 0x3648,
- 0x2b24, 0x0a10, 0x1634, 0x1f00, 0x3748,
- 0x2c24, 0x0b10, 0x1734, 0x2000, 0x3848,
- 0x2d24, 0x0b14, 0x1738, 0x2100, 0x3948,
- 0x2e24, 0x0a14, 0x1638, 0x2200, 0x3a48,
- 0x2f24, 0x0914, 0x1538, 0x2300, 0x3b48,
- 0x2f28, 0x0814, 0x1438, 0x2304, 0x3b4c,
- 0x2e28, 0x0714, 0x1338, 0x2204, 0x3a4c,
- 0x2d28, 0x0614, 0x1238, 0x2104, 0x394c,
- 0x2c28, 0x0618, 0x123c, 0x2004, 0x384c,
- 0x2b28, 0x0718, 0x133c, 0x1f04, 0x374c,
- 0x2a28, 0x0818, 0x143c, 0x1e04, 0x364c,
- 0x2a2c, 0x0918, 0x153c, 0x1e08, 0x3650,
- 0x2b2c, 0x0a18, 0x163c, 0x1f08, 0x3750,
- 0x2c2c, 0x0b18, 0x173c, 0x2008, 0x3850,
- 0x2d2c, 0x0b1c, 0x1740, 0x2108, 0x3950,
- 0x2e2c, 0x0a1c, 0x1640, 0x2208, 0x3a50,
- 0x2f2c, 0x091c, 0x1540, 0x2308, 0x3b50,
- 0x2f30, 0x081c, 0x1440, 0x230c, 0x3b54,
- 0x2e30, 0x071c, 0x1340, 0x220c, 0x3a54,
- 0x2d30, 0x061c, 0x1240, 0x210c, 0x3954,
- 0x2c30, 0x0620, 0x1244, 0x200c, 0x3854,
- 0x2b30, 0x0720, 0x1344, 0x1f0c, 0x3754,
- 0x2a30, 0x0820, 0x1444, 0x1e0c, 0x3654,
- 0x2a34, 0x0920, 0x1544, 0x1e10, 0x3658,
- 0x2b34, 0x0a20, 0x1644, 0x1f10, 0x3858,
- 0x2c34, 0x0b20, 0x1744, 0x2010, 0x3a58,
- 0x3024, 0x0f10, 0x1b34, 0x2400, 0x0048,
- 0x3124, 0x1010, 0x1c34, 0x2500, 0x0148,
- 0x3224, 0x1110, 0x1d34, 0x2600, 0x0248,
- 0x3324, 0x1114, 0x1d38, 0x2700, 0x0348,
- 0x3424, 0x1014, 0x1c38, 0x2800, 0x0448,
- 0x3524, 0x0f14, 0x1b38, 0x2900, 0x0548,
- 0x3528, 0x0e14, 0x1a38, 0x2904, 0x054c,
- 0x3428, 0x0d14, 0x1938, 0x2804, 0x044c,
- 0x3328, 0x0c14, 0x1838, 0x2704, 0x034c,
- 0x3228, 0x0c18, 0x183c, 0x2604, 0x024c,
- 0x3128, 0x0d18, 0x193c, 0x2504, 0x014c,
- 0x3028, 0x0e18, 0x1a3c, 0x2404, 0x004c,
- 0x302c, 0x0f18, 0x1b3c, 0x2408, 0x0050,
- 0x312c, 0x1018, 0x1c3c, 0x2508, 0x0150,
- 0x322c, 0x1118, 0x1d3c, 0x2608, 0x0250,
- 0x332c, 0x111c, 0x1d40, 0x2708, 0x0350,
- 0x342c, 0x101c, 0x1c40, 0x2808, 0x0450,
- 0x352c, 0x0f1c, 0x1b40, 0x2908, 0x0550,
- 0x3530, 0x0e1c, 0x1a40, 0x290c, 0x0554,
- 0x3430, 0x0d1c, 0x1940, 0x280c, 0x0454,
- 0x3330, 0x0c1c, 0x1840, 0x270c, 0x0354,
- 0x3230, 0x0c20, 0x1844, 0x260c, 0x0254,
- 0x3130, 0x0d20, 0x1944, 0x250c, 0x0154,
- 0x3030, 0x0e20, 0x1a44, 0x240c, 0x0054,
- 0x3034, 0x0f20, 0x1b44, 0x2410, 0x0058,
- 0x3134, 0x1020, 0x1c44, 0x2510, 0x0258,
- 0x3234, 0x1120, 0x1d44, 0x2610, 0x0458,
- 0x3624, 0x1510, 0x2134, 0x2a00, 0x0648,
- 0x3724, 0x1610, 0x2234, 0x2b00, 0x0748,
- 0x3824, 0x1710, 0x2334, 0x2c00, 0x0848,
- 0x3924, 0x1714, 0x2338, 0x2d00, 0x0948,
- 0x3a24, 0x1614, 0x2238, 0x2e00, 0x0a48,
- 0x3b24, 0x1514, 0x2138, 0x2f00, 0x0b48,
- 0x3b28, 0x1414, 0x2038, 0x2f04, 0x0b4c,
- 0x3a28, 0x1314, 0x1f38, 0x2e04, 0x0a4c,
- 0x3928, 0x1214, 0x1e38, 0x2d04, 0x094c,
- 0x3828, 0x1218, 0x1e3c, 0x2c04, 0x084c,
- 0x3728, 0x1318, 0x1f3c, 0x2b04, 0x074c,
- 0x3628, 0x1418, 0x203c, 0x2a04, 0x064c,
- 0x362c, 0x1518, 0x213c, 0x2a08, 0x0650,
- 0x372c, 0x1618, 0x223c, 0x2b08, 0x0750,
- 0x382c, 0x1718, 0x233c, 0x2c08, 0x0850,
- 0x392c, 0x171c, 0x2340, 0x2d08, 0x0950,
- 0x3a2c, 0x161c, 0x2240, 0x2e08, 0x0a50,
- 0x3b2c, 0x151c, 0x2140, 0x2f08, 0x0b50,
- 0x3b30, 0x141c, 0x2040, 0x2f0c, 0x0b54,
- 0x3a30, 0x131c, 0x1f40, 0x2e0c, 0x0a54,
- 0x3930, 0x121c, 0x1e40, 0x2d0c, 0x0954,
- 0x3830, 0x1220, 0x1e44, 0x2c0c, 0x0854,
- 0x3730, 0x1320, 0x1f44, 0x2b0c, 0x0754,
- 0x3630, 0x1420, 0x2044, 0x2a0c, 0x0654,
- 0x3634, 0x1520, 0x2144, 0x2a10, 0x0658,
- 0x3734, 0x1620, 0x2244, 0x2b10, 0x0858,
- 0x3834, 0x1720, 0x2344, 0x2c10, 0x0a58,
- 0x0024, 0x1b10, 0x2734, 0x3000, 0x0c48,
- 0x0124, 0x1c10, 0x2834, 0x3100, 0x0d48,
- 0x0224, 0x1d10, 0x2934, 0x3200, 0x0e48,
- 0x0324, 0x1d14, 0x2938, 0x3300, 0x0f48,
- 0x0424, 0x1c14, 0x2838, 0x3400, 0x1048,
- 0x0524, 0x1b14, 0x2738, 0x3500, 0x1148,
- 0x0528, 0x1a14, 0x2638, 0x3504, 0x114c,
- 0x0428, 0x1914, 0x2538, 0x3404, 0x104c,
- 0x0328, 0x1814, 0x2438, 0x3304, 0x0f4c,
- 0x0228, 0x1818, 0x243c, 0x3204, 0x0e4c,
- 0x0128, 0x1918, 0x253c, 0x3104, 0x0d4c,
- 0x0028, 0x1a18, 0x263c, 0x3004, 0x0c4c,
- 0x002c, 0x1b18, 0x273c, 0x3008, 0x0c50,
- 0x012c, 0x1c18, 0x283c, 0x3108, 0x0d50,
- 0x022c, 0x1d18, 0x293c, 0x3208, 0x0e50,
- 0x032c, 0x1d1c, 0x2940, 0x3308, 0x0f50,
- 0x042c, 0x1c1c, 0x2840, 0x3408, 0x1050,
- 0x052c, 0x1b1c, 0x2740, 0x3508, 0x1150,
- 0x0530, 0x1a1c, 0x2640, 0x350c, 0x1154,
- 0x0430, 0x191c, 0x2540, 0x340c, 0x1054,
- 0x0330, 0x181c, 0x2440, 0x330c, 0x0f54,
- 0x0230, 0x1820, 0x2444, 0x320c, 0x0e54,
- 0x0130, 0x1920, 0x2544, 0x310c, 0x0d54,
- 0x0030, 0x1a20, 0x2644, 0x300c, 0x0c54,
- 0x0034, 0x1b20, 0x2744, 0x3010, 0x0c58,
- 0x0134, 0x1c20, 0x2844, 0x3110, 0x0e58,
- 0x0234, 0x1d20, 0x2944, 0x3210, 0x1058,
- 0x0624, 0x2110, 0x2d34, 0x3600, 0x1248,
- 0x0724, 0x2210, 0x2e34, 0x3700, 0x1348,
- 0x0824, 0x2310, 0x2f34, 0x3800, 0x1448,
- 0x0924, 0x2314, 0x2f38, 0x3900, 0x1548,
- 0x0a24, 0x2214, 0x2e38, 0x3a00, 0x1648,
- 0x0b24, 0x2114, 0x2d38, 0x3b00, 0x1748,
- 0x0b28, 0x2014, 0x2c38, 0x3b04, 0x174c,
- 0x0a28, 0x1f14, 0x2b38, 0x3a04, 0x164c,
- 0x0928, 0x1e14, 0x2a38, 0x3904, 0x154c,
- 0x0828, 0x1e18, 0x2a3c, 0x3804, 0x144c,
- 0x0728, 0x1f18, 0x2b3c, 0x3704, 0x134c,
- 0x0628, 0x2018, 0x2c3c, 0x3604, 0x124c,
- 0x062c, 0x2118, 0x2d3c, 0x3608, 0x1250,
- 0x072c, 0x2218, 0x2e3c, 0x3708, 0x1350,
- 0x082c, 0x2318, 0x2f3c, 0x3808, 0x1450,
- 0x092c, 0x231c, 0x2f40, 0x3908, 0x1550,
- 0x0a2c, 0x221c, 0x2e40, 0x3a08, 0x1650,
- 0x0b2c, 0x211c, 0x2d40, 0x3b08, 0x1750,
- 0x0b30, 0x201c, 0x2c40, 0x3b0c, 0x1754,
- 0x0a30, 0x1f1c, 0x2b40, 0x3a0c, 0x1654,
- 0x0930, 0x1e1c, 0x2a40, 0x390c, 0x1554,
- 0x0830, 0x1e20, 0x2a44, 0x380c, 0x1454,
- 0x0730, 0x1f20, 0x2b44, 0x370c, 0x1354,
- 0x0630, 0x2020, 0x2c44, 0x360c, 0x1254,
- 0x0634, 0x2120, 0x2d44, 0x3610, 0x1258,
- 0x0734, 0x2220, 0x2e44, 0x3710, 0x1458,
- 0x0834, 0x2320, 0x2f44, 0x3810, 0x1658,
-};
-
-static const uint16_t dv_place_audio60[10][9] = {
- { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
- { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
- { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
- { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
- { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
-
- { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
- { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
- { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
- { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
- { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
-};
-
-static const uint16_t dv_place_audio50[12][9] = {
- { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
- { 6, 42, 78, 32, 68, 104, 22, 58, 94},
- { 12, 48, 84, 2, 38, 74, 28, 64, 100},
- { 18, 54, 90, 8, 44, 80, 34, 70, 106},
- { 24, 60, 96, 14, 50, 86, 4, 40, 76},
- { 30, 66, 102, 20, 56, 92, 10, 46, 82},
-
- { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
- { 7, 43, 79, 33, 69, 105, 23, 59, 95},
- { 13, 49, 85, 3, 39, 75, 29, 65, 101},
- { 19, 55, 91, 9, 45, 81, 35, 71, 107},
- { 25, 61, 97, 15, 51, 87, 5, 41, 77},
- { 31, 67, 103, 21, 57, 93, 11, 47, 83},
-};
-
-static const int dv_audio_frequency[3] = {
- 48000, 44100, 32000,
-};
-
-static const int dv_audio_min_samples[2][3] = {
- { 1580, 1452, 1053 }, /* 60 fields */
- { 1896, 1742, 1264 }, /* 50 fileds */
-};
+++ /dev/null
-/*
- * Error resilience / concealment
- *
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file error_resilience.c
- * Error resilience / concealment.
- */
-
-#include <limits.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "common.h"
-
-static void decode_mb(MpegEncContext *s){
- s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;
- s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
- s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
-
- MPV_decode_mb(s, s->block);
-}
-
-/**
- * replaces the current MB with a flat dc only version.
- */
-static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
-{
- int dc, dcu, dcv, y, i;
- for(i=0; i<4; i++){
- dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)];
- if(dc<0) dc=0;
- else if(dc>2040) dc=2040;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
- }
- }
- }
- dcu = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
- dcv = s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
- if (dcu<0 ) dcu=0;
- else if(dcu>2040) dcu=2040;
- if (dcv<0 ) dcv=0;
- else if(dcv>2040) dcv=2040;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dest_cb[x + y*(s->uvlinesize)]= dcu/8;
- dest_cr[x + y*(s->uvlinesize)]= dcv/8;
- }
- }
-}
-
-static void filter181(int16_t *data, int width, int height, int stride){
- int x,y;
-
- /* horizontal filter */
- for(y=1; y<height-1; y++){
- int prev_dc= data[0 + y*stride];
-
- for(x=1; x<width-1; x++){
- int dc;
-
- dc= - prev_dc
- + data[x + y*stride]*8
- - data[x + 1 + y*stride];
- dc= (dc*10923 + 32768)>>16;
- prev_dc= data[x + y*stride];
- data[x + y*stride]= dc;
- }
- }
-
- /* vertical filter */
- for(x=1; x<width-1; x++){
- int prev_dc= data[x];
-
- for(y=1; y<height-1; y++){
- int dc;
-
- dc= - prev_dc
- + data[x + y *stride]*8
- - data[x + (y+1)*stride];
- dc= (dc*10923 + 32768)>>16;
- prev_dc= data[x + y*stride];
- data[x + y*stride]= dc;
- }
- }
-}
-
-/**
- * guess the dc of blocks which dont have a undamaged dc
- * @param w width in 8 pixel blocks
- * @param h height in 8 pixel blocks
- */
-static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
- int b_x, b_y;
-
- for(b_y=0; b_y<h; b_y++){
- for(b_x=0; b_x<w; b_x++){
- int color[4]={1024,1024,1024,1024};
- int distance[4]={9999,9999,9999,9999};
- int mb_index, error, j;
- int64_t guess, weight_sum;
-
- mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
-
- error= s->error_status_table[mb_index];
-
- if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
- if(!(error&DC_ERROR)) continue; //dc-ok
-
- /* right block */
- for(j=b_x+1; j<w; j++){
- int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[0]= dc[j + b_y*stride];
- distance[0]= j-b_x;
- break;
- }
- }
-
- /* left block */
- for(j=b_x-1; j>=0; j--){
- int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[1]= dc[j + b_y*stride];
- distance[1]= b_x-j;
- break;
- }
- }
-
- /* bottom block */
- for(j=b_y+1; j<h; j++){
- int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[2]= dc[b_x + j*stride];
- distance[2]= j-b_y;
- break;
- }
- }
-
- /* top block */
- for(j=b_y-1; j>=0; j--){
- int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
- int error_j= s->error_status_table[mb_index_j];
- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
- if(intra_j==0 || !(error_j&DC_ERROR)){
- color[3]= dc[b_x + j*stride];
- distance[3]= b_y-j;
- break;
- }
- }
-
- weight_sum=0;
- guess=0;
- for(j=0; j<4; j++){
- int64_t weight= 256*256*256*16/distance[j];
- guess+= weight*(int64_t)color[j];
- weight_sum+= weight;
- }
- guess= (guess + weight_sum/2) / weight_sum;
-
- dc[b_x + b_y*stride]= guess;
- }
- }
-}
-
-/**
- * simple horizontal deblocking filter used for error resilience
- * @param w width in 8 pixel blocks
- * @param h height in 8 pixel blocks
- */
-static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
- int b_x, b_y;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- for(b_y=0; b_y<h; b_y++){
- for(b_x=0; b_x<w-1; b_x++){
- int y;
- int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
- int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
- int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
- int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
- int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int offset= b_x*8 + b_y*stride*8;
- int16_t *left_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))];
- int16_t *right_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))];
-
- if(!(left_damage||right_damage)) continue; // both undamaged
-
- if( (!left_intra) && (!right_intra)
- && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue;
-
- for(y=0; y<8; y++){
- int a,b,c,d;
-
- a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
- b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
- c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
-
- d= ABS(b) - ((ABS(a) + ABS(c) + 1)>>1);
- d= FFMAX(d, 0);
- if(b<0) d= -d;
-
- if(d==0) continue;
-
- if(!(left_damage && right_damage))
- d= d*16/9;
-
- if(left_damage){
- dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
- dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
- dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
- dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
- }
- if(right_damage){
- dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
- dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
- dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
- dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
- }
- }
- }
- }
-}
-
-/**
- * simple vertical deblocking filter used for error resilience
- * @param w width in 8 pixel blocks
- * @param h height in 8 pixel blocks
- */
-static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
- int b_x, b_y;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- for(b_y=0; b_y<h-1; b_y++){
- for(b_x=0; b_x<w; b_x++){
- int x;
- int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
- int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
- int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
- int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
- int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
- int offset= b_x*8 + b_y*stride*8;
- int16_t *top_mv= s->motion_val[s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
- int16_t *bottom_mv= s->motion_val[s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
-
- if(!(top_damage||bottom_damage)) continue; // both undamaged
-
- if( (!top_intra) && (!bottom_intra)
- && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue;
-
- for(x=0; x<8; x++){
- int a,b,c,d;
-
- a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
- b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
- c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
-
- d= ABS(b) - ((ABS(a) + ABS(c)+1)>>1);
- d= FFMAX(d, 0);
- if(b<0) d= -d;
-
- if(d==0) continue;
-
- if(!(top_damage && bottom_damage))
- d= d*16/9;
-
- if(top_damage){
- dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)];
- dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)];
- dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)];
- dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)];
- }
- if(bottom_damage){
- dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)];
- dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)];
- dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
- dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
- }
- }
- }
- }
-}
-
-static void guess_mv(MpegEncContext *s){
- uint8_t fixed[s->mb_stride * s->mb_height];
-#define MV_FROZEN 3
-#define MV_CHANGED 2
-#define MV_UNCHANGED 1
- const int mb_stride = s->mb_stride;
- const int mb_width = s->mb_width;
- const int mb_height= s->mb_height;
- int i, depth, num_avail;
- int mb_x, mb_y;
-
- num_avail=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[ i ];
- int f=0;
- int error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
- if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
-
- fixed[mb_xy]= f;
- if(f==MV_FROZEN)
- num_avail++;
- }
-
- if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y*s->mb_stride;
-
- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
- if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skiped=0;
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- s->mv[0][0][0]= 0;
- s->mv[0][0][1]= 0;
- decode_mb(s);
- }
- }
- return;
- }
-
- for(depth=0;; depth++){
- int changed, pass, none_left;
-
- none_left=1;
- changed=1;
- for(pass=0; (changed || pass<2) && pass<10; pass++){
- int mb_x, mb_y;
-int score_sum=0;
-
- changed=0;
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y*s->mb_stride;
- int mv_predictor[8][2]={{0}};
- int pred_count=0;
- int j;
- int best_score=256*256*256*64;
- int best_pred=0;
- const int mot_stride= mb_width*2+2;
- const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride;
- int prev_x= s->motion_val[mot_index][0];
- int prev_y= s->motion_val[mot_index][1];
-
- if((mb_x^mb_y^pass)&1) continue;
-
- if(fixed[mb_xy]==MV_FROZEN) continue;
- assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
- assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
-
- j=0;
- if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
- if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;
- if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
- if(j==0) continue;
-
- j=0;
- if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;
- if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;
- if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
- if(j==0 && pass>1) continue;
-
- none_left=0;
-
- if(mb_x>0 && fixed[mb_xy-1]){
- mv_predictor[pred_count][0]= s->motion_val[mot_index - 2][0];
- mv_predictor[pred_count][1]= s->motion_val[mot_index - 2][1];
- pred_count++;
- }
- if(mb_x+1<mb_width && fixed[mb_xy+1]){
- mv_predictor[pred_count][0]= s->motion_val[mot_index + 2][0];
- mv_predictor[pred_count][1]= s->motion_val[mot_index + 2][1];
- pred_count++;
- }
- if(mb_y>0 && fixed[mb_xy-mb_stride]){
- mv_predictor[pred_count][0]= s->motion_val[mot_index - mot_stride*2][0];
- mv_predictor[pred_count][1]= s->motion_val[mot_index - mot_stride*2][1];
- pred_count++;
- }
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
- mv_predictor[pred_count][0]= s->motion_val[mot_index + mot_stride*2][0];
- mv_predictor[pred_count][1]= s->motion_val[mot_index + mot_stride*2][1];
- pred_count++;
- }
- if(pred_count==0) continue;
-
- if(pred_count>1){
- int sum_x=0, sum_y=0;
- int max_x, max_y, min_x, min_y;
-
- for(j=0; j<pred_count; j++){
- sum_x+= mv_predictor[j][0];
- sum_y+= mv_predictor[j][1];
- }
-
- /* mean */
- mv_predictor[pred_count][0] = sum_x/j;
- mv_predictor[pred_count][1] = sum_y/j;
-
- /* median */
- if(pred_count>=3){
- min_y= min_x= 99999;
- max_y= max_x=-99999;
- }else{
- min_x=min_y=max_x=max_y=0;
- }
- for(j=0; j<pred_count; j++){
- max_x= FFMAX(max_x, mv_predictor[j][0]);
- max_y= FFMAX(max_y, mv_predictor[j][1]);
- min_x= FFMIN(min_x, mv_predictor[j][0]);
- min_y= FFMIN(min_y, mv_predictor[j][1]);
- }
- mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
- mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
-
- if(pred_count==4){
- mv_predictor[pred_count+1][0] /= 2;
- mv_predictor[pred_count+1][1] /= 2;
- }
- pred_count+=2;
- }
-
- /* zero MV */
- pred_count++;
-
- /* last MV */
- mv_predictor[pred_count][0]= s->motion_val[mot_index][0];
- mv_predictor[pred_count][1]= s->motion_val[mot_index][1];
- pred_count++;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skiped=0;
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
-
- for(j=0; j<pred_count; j++){
- int score=0;
- uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
-
- s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
- s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
-
- decode_mb(s);
-
- if(mb_x>0 && fixed[mb_xy-1]){
- int k;
- for(k=0; k<16; k++)
- score += ABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
- }
- if(mb_x+1<mb_width && fixed[mb_xy+1]){
- int k;
- for(k=0; k<16; k++)
- score += ABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
- }
- if(mb_y>0 && fixed[mb_xy-mb_stride]){
- int k;
- for(k=0; k<16; k++)
- score += ABS(src[k-s->linesize ]-src[k ]);
- }
- if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
- int k;
- for(k=0; k<16; k++)
- score += ABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
- }
-
- if(score <= best_score){ // <= will favor the last MV
- best_score= score;
- best_pred= j;
- }
- }
-score_sum+= best_score;
-//FIXME no need to set s->motion_val[mot_index][0] explicit
- s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];
- s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];
-
- decode_mb(s);
-
-
- if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
- fixed[mb_xy]=MV_CHANGED;
- changed++;
- }else
- fixed[mb_xy]=MV_UNCHANGED;
- }
- }
-
-// printf(".%d/%d", changed, score_sum); fflush(stdout);
- }
-
- if(none_left)
- return;
-
- for(i=0; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
- if(fixed[mb_xy])
- fixed[mb_xy]=MV_FROZEN;
- }
-// printf(":"); fflush(stdout);
- }
-}
-
-static int is_intra_more_likely(MpegEncContext *s){
- int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
-
- if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
-
- undamaged_count=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- const int error= s->error_status_table[mb_xy];
- if(!((error&DC_ERROR) && (error&MV_ERROR)))
- undamaged_count++;
- }
-
- if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
-
- skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs
- is_intra_likely=0;
-
- j=0;
- for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
- for(mb_x= 0; mb_x<s->mb_width; mb_x++){
- int error;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
-
- error= s->error_status_table[mb_xy];
- if((error&DC_ERROR) && (error&MV_ERROR))
- continue; //skip damaged
-
- j++;
- if((j%skip_amount) != 0) continue; //skip a few to speed things up
-
- if(s->pict_type==I_TYPE){
- uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
-
- is_intra_likely += s->dsp.pix_abs16x16(last_mb_ptr, mb_ptr , s->linesize);
- is_intra_likely -= s->dsp.pix_abs16x16(last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize);
- }else{
- if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
- is_intra_likely++;
- else
- is_intra_likely--;
- }
- }
- }
-//printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
- return is_intra_likely > 0;
-}
-
-void ff_er_frame_start(MpegEncContext *s){
- if(!s->error_resilience) return;
-
- memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
- s->error_count= 3*s->mb_num;
-}
-
-/**
- * adds a slice.
- * @param endx x component of the last macroblock, can be -1 for the last of the previous line
- * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
- * error of the same type occured
- */
-void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
- const int start_i= clip(startx + starty * s->mb_width , 0, s->mb_num-1);
- const int end_i = clip(endx + endy * s->mb_width , 0, s->mb_num);
- const int start_xy= s->mb_index2xy[start_i];
- const int end_xy = s->mb_index2xy[end_i];
- int mask= -1;
-
- if(!s->error_resilience) return;
-
- mask &= ~VP_START;
- if(status & (AC_ERROR|AC_END)){
- mask &= ~(AC_ERROR|AC_END);
- s->error_count -= end_i - start_i + 1;
- }
- if(status & (DC_ERROR|DC_END)){
- mask &= ~(DC_ERROR|DC_END);
- s->error_count -= end_i - start_i + 1;
- }
- if(status & (MV_ERROR|MV_END)){
- mask &= ~(MV_ERROR|MV_END);
- s->error_count -= end_i - start_i + 1;
- }
-
- if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
-
- if(mask == ~0x7F){
- memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
- }else{
- int i;
- for(i=start_xy; i<end_xy; i++){
- s->error_status_table[ i ] &= mask;
- }
- }
-
- if(end_i == s->mb_num)
- s->error_count= INT_MAX;
- else{
- s->error_status_table[end_xy] &= mask;
- s->error_status_table[end_xy] |= status;
- }
-
- s->error_status_table[start_xy] |= VP_START;
-
- if(start_xy > 0){
- int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
-
- prev_status &= ~ VP_START;
- if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
- }
-}
-
-void ff_er_frame_end(MpegEncContext *s){
- int i, mb_x, mb_y, error, error_type;
- int distance;
- int threshold_part[4]= {100,100,100};
- int threshold= 50;
- int is_intra_likely;
-
- if(!s->error_resilience || s->error_count==0) return;
-
- fprintf(stderr, "concealing errors\n");
-
- if(s->motion_val == NULL){
- int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
-
- fprintf(stderr, "Warning MVs not available\n");
-
- s->motion_val= av_mallocz(size * 2 * sizeof(int16_t));
- }
-
- if(s->avctx->debug&FF_DEBUG_ER){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
-
- printf("%2X ", status);
- }
- printf("\n");
- }
- }
-
-#if 1
- /* handle overlapping slices */
- for(error_type=1; error_type<=3; error_type++){
- int end_ok=0;
-
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(error&(1<<error_type))
- end_ok=1;
- if(error&(8<<error_type))
- end_ok=1;
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= 1<<error_type;
-
- if(error&VP_START)
- end_ok=0;
- }
- }
-#endif
-#if 1
- /* handle slices with partitions of different length */
- if(s->partitioned_frame){
- int end_ok=0;
-
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(error&AC_END)
- end_ok=0;
- if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
- end_ok=1;
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= AC_ERROR;
-
- if(error&VP_START)
- end_ok=0;
- }
- }
-#endif
- /* handle missing slices */
- if(s->error_resilience>=4){
- int end_ok=1;
-
- for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
- const int mb_xy= s->mb_index2xy[i];
- int error1= s->error_status_table[mb_xy ];
- int error2= s->error_status_table[s->mb_index2xy[i+1]];
-
- if(error1&VP_START)
- end_ok=1;
-
- if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
- && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
- && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited
- end_ok=0;
- }
-
- if(!end_ok)
- s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
- }
- }
-
-#if 1
- /* backward mark errors */
- distance=9999999;
- for(error_type=1; error_type<=3; error_type++){
- for(i=s->mb_num-1; i>=0; i--){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(!s->mbskip_table[mb_xy]) //FIXME partition specific
- distance++;
- if(error&(1<<error_type))
- distance= 0;
-
- if(s->partitioned_frame){
- if(distance < threshold_part[error_type-1])
- s->error_status_table[mb_xy]|= 1<<error_type;
- }else{
- if(distance < threshold)
- s->error_status_table[mb_xy]|= 1<<error_type;
- }
-
- if(error&VP_START)
- distance= 9999999;
- }
- }
-#endif
-
- /* forward mark errors */
- error=0;
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- int old_error= s->error_status_table[mb_xy];
-
- if(old_error&VP_START)
- error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
- else{
- error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
- s->error_status_table[mb_xy]|= error;
- }
- }
-#if 1
- /* handle not partitioned case */
- if(!s->partitioned_frame){
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- error= s->error_status_table[mb_xy];
- if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
- error|= AC_ERROR|DC_ERROR|MV_ERROR;
- s->error_status_table[mb_xy]= error;
- }
- }
-#endif
- is_intra_likely= is_intra_more_likely(s);
-
- /* set unknown mb-type to most likely */
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- error= s->error_status_table[mb_xy];
- if(!((error&DC_ERROR) && (error&MV_ERROR)))
- continue;
-
- if(is_intra_likely)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
- else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
- }
-
- /* handle inter blocks with damaged AC */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type)) continue; //intra
- if(error&MV_ERROR) continue; //inter with damaged MV
- if(!(error&AC_ERROR)) continue; //undamaged inter
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra=0;
- s->mb_skiped=0;
- if(IS_8X8(mb_type)){
- int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
- int j;
- s->mv_type = MV_TYPE_8X8;
- for(j=0; j<4; j++){
- s->mv[0][j][0] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0];
- s->mv[0][j][1] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1];
- }
- }else{
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0];
- s->mv[0][0][1] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1];
- }
-
- s->dsp.clear_blocks(s->block[0]);
-
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- decode_mb(s);
- }
- }
-
- /* guess MVs */
- if(s->pict_type==B_TYPE){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type)) continue;
- if(!(error&MV_ERROR)) continue; //inter with undamaged MV
- if(!(error&AC_ERROR)) continue; //undamaged inter
-
- s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
- s->mb_intra=0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_skiped=0;
-
- if(s->pp_time){
- int time_pp= s->pp_time;
- int time_pb= s->pb_time;
-
- s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp;
- s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp;
- s->mv[1][0][0] = s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][0][1] = s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
- }else{
- s->mv[0][0][0]= 0;
- s->mv[0][0][1]= 0;
- s->mv[1][0][0]= 0;
- s->mv[1][0][1]= 0;
- }
-
- s->dsp.clear_blocks(s->block[0]);
- s->mb_x= mb_x;
- s->mb_y= mb_y;
- decode_mb(s);
- }
- }
- }else
- guess_mv(s);
-
-#ifdef HAVE_XVMC
- /* the filters below are not XvMC compatible, skip them */
- if(s->avctx->xvmc_acceleration) goto ec_clean;
-#endif
- /* fill DC for inter blocks */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- int dc, dcu, dcv, y, n;
- int16_t *dc_ptr;
- uint8_t *dest_y, *dest_cb, *dest_cr;
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- error= s->error_status_table[mb_xy];
-
- if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
-// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
-
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
-
- dc_ptr= &s->dc_val[0][mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2)];
- for(n=0; n<4; n++){
- dc=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
- }
- }
- dc_ptr[(n&1) + (n>>1)*(s->mb_width*2+2)]= (dc+4)>>3;
- }
-
- dcu=dcv=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- dcu+=dest_cb[x + y*(s->uvlinesize)];
- dcv+=dest_cr[x + y*(s->uvlinesize)];
- }
- }
- s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcu+4)>>3;
- s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcv+4)>>3;
- }
- }
-#if 1
- /* guess DC for damaged blocks */
- guess_dc(s, s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2, 1);
- guess_dc(s, s->dc_val[1] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0);
- guess_dc(s, s->dc_val[2] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0);
-#endif
- /* filter luma DC */
- filter181(s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2);
-
-#if 1
- /* render DC only intra */
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- uint8_t *dest_y, *dest_cb, *dest_cr;
- const int mb_xy= mb_x + mb_y * s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- error= s->error_status_table[mb_xy];
-
- if(IS_INTER(mb_type)) continue;
- if(!(error&AC_ERROR)) continue; //undamaged
-
- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
-
- put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
- }
- }
-#endif
-
- if(s->avctx->error_concealment&FF_EC_DEBLOCK){
- /* filter horizontal block boundaries */
- h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
-
- /* filter vertical block boundaries */
- v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
- v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
- v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
- }
-
-#ifdef HAVE_XVMC
-ec_clean:
-#endif
- /* clean a few tables */
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- int error= s->error_status_table[mb_xy];
-
- if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
- s->mbskip_table[mb_xy]=0;
- }
- s->mbintra_table[mb_xy]=1;
- }
-}
+++ /dev/null
-/*
- * simple arithmetic expression evaluator
- *
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file eval.c
- * simple arithmetic expression evaluator.
- *
- * see http://joe.hotchkiss.com/programming/eval/eval.html
- */
-
-#include "avcodec.h"
-#include "mpegvideo.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#ifndef NAN
- #define NAN 0
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-#define STACK_SIZE 100
-
-typedef struct Parser{
- double stack[STACK_SIZE];
- int stack_index;
- char *s;
- double *const_value;
- const char **const_name; // NULL terminated
- double (**func1)(void *, double a); // NULL terminated
- const char **func1_name; // NULL terminated
- double (**func2)(void *, double a, double b); // NULL terminated
- char **func2_name; // NULL terminated
- void *opaque;
-} Parser;
-
-static void evalExpression(Parser *p);
-
-static void push(Parser *p, double d){
- if(p->stack_index+1>= STACK_SIZE){
- fprintf(stderr, "stack overflow in the parser\n");
- return;
- }
- p->stack[ p->stack_index++ ]= d;
-//printf("push %f\n", d); fflush(stdout);
-}
-
-static double pop(Parser *p){
- if(p->stack_index<=0){
- fprintf(stderr, "stack underflow in the parser\n");
- return NAN;
- }
-//printf("pop\n"); fflush(stdout);
- return p->stack[ --p->stack_index ];
-}
-
-static int strmatch(const char *s, const char *prefix){
- int i;
- for(i=0; prefix[i]; i++){
- if(prefix[i] != s[i]) return 0;
- }
- return 1;
-}
-
-static void evalPrimary(Parser *p){
- double d, d2=NAN;
- char *next= p->s;
- int i;
-
- /* number */
- d= strtod(p->s, &next);
- if(next != p->s){
- push(p, d);
- p->s= next;
- return;
- }
-
- /* named constants */
- for(i=0; p->const_name[i]; i++){
- if(strmatch(p->s, p->const_name[i])){
- push(p, p->const_value[i]);
- p->s+= strlen(p->const_name[i]);
- return;
- }
- }
-
- p->s= strchr(p->s, '(');
- if(p->s==NULL){
- fprintf(stderr, "Parser: missing ( in \"%s\"\n", next);
- return;
- }
- p->s++; // "("
- evalExpression(p);
- d= pop(p);
- p->s++; // ")" or ","
- if(p->s[-1]== ','){
- evalExpression(p);
- d2= pop(p);
- p->s++; // ")"
- }
-
- if( strmatch(next, "sinh" ) ) d= sinh(d);
- else if( strmatch(next, "cosh" ) ) d= cosh(d);
- else if( strmatch(next, "tanh" ) ) d= tanh(d);
- else if( strmatch(next, "sin" ) ) d= sin(d);
- else if( strmatch(next, "cos" ) ) d= cos(d);
- else if( strmatch(next, "tan" ) ) d= tan(d);
- else if( strmatch(next, "exp" ) ) d= exp(d);
- else if( strmatch(next, "log" ) ) d= log(d);
- else if( strmatch(next, "squish") ) d= 1/(1+exp(4*d));
- else if( strmatch(next, "gauss" ) ) d= exp(-d*d/2)/sqrt(2*M_PI);
- else if( strmatch(next, "abs" ) ) d= fabs(d);
- else if( strmatch(next, "max" ) ) d= d > d2 ? d : d2;
- else if( strmatch(next, "min" ) ) d= d < d2 ? d : d2;
- else if( strmatch(next, "gt" ) ) d= d > d2 ? 1.0 : 0.0;
- else if( strmatch(next, "lt" ) ) d= d > d2 ? 0.0 : 1.0;
- else if( strmatch(next, "eq" ) ) d= d == d2 ? 1.0 : 0.0;
-// else if( strmatch(next, "l1" ) ) d= 1 + d2*(d - 1);
-// else if( strmatch(next, "sq01" ) ) d= (d >= 0.0 && d <=1.0) ? 1.0 : 0.0;
- else{
- int error=1;
- for(i=0; p->func1_name && p->func1_name[i]; i++){
- if(strmatch(next, p->func1_name[i])){
- d= p->func1[i](p->opaque, d);
- error=0;
- break;
- }
- }
-
- for(i=0; p->func2_name && p->func2_name[i]; i++){
- if(strmatch(next, p->func2_name[i])){
- d= p->func2[i](p->opaque, d, d2);
- error=0;
- break;
- }
- }
-
- if(error){
- fprintf(stderr, "Parser: unknown function in \"%s\"\n", next);
- return;
- }
- }
-
- if(p->s[-1]!= ')'){
- fprintf(stderr, "Parser: missing ) in \"%s\"\n", next);
- return;
- }
- push(p, d);
-}
-
-static void evalPow(Parser *p){
- int neg= 0;
- if(p->s[0]=='+') p->s++;
-
- if(p->s[0]=='-'){
- neg= 1;
- p->s++;
- }
-
- if(p->s[0]=='('){
- p->s++;;
- evalExpression(p);
-
- if(p->s[0]!=')')
- fprintf(stderr, "Parser: missing )\n");
- p->s++;
- }else{
- evalPrimary(p);
- }
-
- if(neg) push(p, -pop(p));
-}
-
-static void evalFactor(Parser *p){
- evalPow(p);
- while(p->s[0]=='^'){
- double d;
-
- p->s++;
- evalPow(p);
- d= pop(p);
- push(p, pow(pop(p), d));
- }
-}
-
-static void evalTerm(Parser *p){
- evalFactor(p);
- while(p->s[0]=='*' || p->s[0]=='/'){
- int inv= p->s[0]=='/';
- double d;
-
- p->s++;
- evalFactor(p);
- d= pop(p);
- if(inv) d= 1.0/d;
- push(p, d * pop(p));
- }
-}
-
-static void evalExpression(Parser *p){
- evalTerm(p);
- while(p->s[0]=='+' || p->s[0]=='-'){
- int sign= p->s[0]=='-';
- double d;
-
- p->s++;
- evalTerm(p);
- d= pop(p);
- if(sign) d= -d;
- push(p, d + pop(p));
- }
-}
-
-double ff_eval(char *s, double *const_value, const char **const_name,
- double (**func1)(void *, double), const char **func1_name,
- double (**func2)(void *, double, double), char **func2_name,
- void *opaque){
- Parser p;
-
- p.stack_index=0;
- p.s= s;
- p.const_value= const_value;
- p.const_name = const_name;
- p.func1 = func1;
- p.func1_name = func1_name;
- p.func2 = func2;
- p.func2_name = func2_name;
- p.opaque = opaque;
-
- evalExpression(&p);
- return pop(&p);
-}
+++ /dev/null
-/*
- * Faad decoder
- * Copyright (c) 2003 Zdenek Kabelac.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file faad.c
- * AAC decoder.
- *
- * still a bit unfinished - but it plays something
- */
-
-#include "avcodec.h"
-#include "faad.h"
-
-/*
- * when CONFIG_FAADBIN is defined the libfaad will be opened at runtime
- */
-//#undef CONFIG_FAADBIN
-//#define CONFIG_FAADBIN
-
-#ifdef CONFIG_FAADBIN
-#include <dlfcn.h>
-static const char* libfaadname = "libfaad.so.0";
-#else
-#define dlopen(a)
-#define dlclose(a)
-#endif
-
-typedef struct {
- void* handle; /* dlopen handle */
- void* faac_handle; /* FAAD library handle */
- int frame_size;
- int sample_size;
- int flags;
-
- /* faad calls */
- faacDecHandle FAADAPI (*faacDecOpen)(void);
- faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder);
- unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder,
- faacDecConfigurationPtr config);
- long FAADAPI (*faacDecInit)(faacDecHandle hDecoder,
- unsigned char *buffer,
- unsigned long *samplerate,
- unsigned char *channels);
- char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer,
- unsigned long SizeOfDecoderSpecificInfo,
- unsigned long *samplerate, unsigned char *channels);
- void FAADAPI (*faacDecClose)(faacDecHandle hDecoder);
- void* FAADAPI (*faacDecDecode)(faacDecHandle hDecoder,
- faacDecFrameInfo *hInfo,
- unsigned char *buffer);
- unsigned char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode);
-} FAACContext;
-
-static const unsigned long faac_srates[] =
-{
- 96000, 88200, 64000, 48000, 44100, 32000,
- 24000, 22050, 16000, 12000, 11025, 8000
-};
-
-static int faac_init_mp4(AVCodecContext *avctx)
-{
- FAACContext *s = (FAACContext *) avctx->priv_data;
- unsigned long samplerate;
- unsigned char channels;
- int r = 0;
-
- if (avctx->extradata)
- r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata,
- avctx->extradata_size,
- &samplerate, &channels);
- // else r = s->faacDecInit(s->faac_handle ... );
-
- if (r < 0)
- fprintf(stderr, "faacDecInit2 failed r:%d sr:%ld ch:%d s:%d\n",
- r, samplerate, channels, avctx->extradata_size);
-
- return r;
-}
-
-static int faac_init_aac(AVCodecContext *avctx)
-{
- FAACContext *s = (FAACContext *) avctx->priv_data;
- return 0;
-}
-
-static int faac_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- FAACContext *s = (FAACContext *) avctx->priv_data;
- faacDecFrameInfo frame_info;
- void* out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf);
- //printf("DECODE FRAME %d, %d, %d - %p\n", buf_size, frame_info.samples, frame_info.bytesconsumed, out);
-
- if (frame_info.error > 0) {
- fprintf(stderr, "faac: frame decodinf failed: %s\n",
- s->faacDecGetErrorMessage(frame_info.error));
- return 0;
- }
-
- frame_info.samples *= s->sample_size;
- memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one
-
- if (data_size)
- *data_size = frame_info.samples;
-
- return (buf_size < (int)frame_info.bytesconsumed)
- ? buf_size : (int)frame_info.bytesconsumed;
-}
-
-static int faac_decode_end(AVCodecContext *avctx)
-{
- FAACContext *s = (FAACContext *) avctx->priv_data;
-
- if (s->faacDecClose)
- s->faacDecClose(s->faac_handle);
-
- dlclose(s->handle);
- return 0;
-}
-
-static int faac_decode_init(AVCodecContext *avctx)
-{
- FAACContext *s = (FAACContext *) avctx->priv_data;
- faacDecConfigurationPtr faac_cfg;
-
-#ifdef CONFIG_FAADBIN
- const char* err = 0;
-
- s->handle = dlopen(libfaadname, RTLD_LAZY);
- if (!s->handle)
- {
- fprintf(stderr, "FAAD library: %s could not be opened! \n%s\n",
- libfaadname, dlerror());
- return -1;
- }
-#define dfaac(a, b) \
- do { static const char* n = "faacDec" #a; \
- if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0)
- for(;;) {
-#else /* !CONFIG_FAADBIN */
-#define dfaac(a, b) s->faacDec ## a = faacDec ## a
-#endif /* CONFIG_FAADBIN */
-
- // resolve all needed function calls
- dfaac(Open, (faacDecHandle FAADAPI (*)(void)));
- dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr
- FAADAPI (*)(faacDecHandle)));
- dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle,
- faacDecConfigurationPtr)));
-
- dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*,
- unsigned long*, unsigned char*)));
- dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*,
- unsigned long, unsigned long*,
- unsigned char*)));
- dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder)));
- dfaac(Decode, (void* FAADAPI (*)(faacDecHandle, faacDecFrameInfo*,
- unsigned char*)));
-
- dfaac(GetErrorMessage, (unsigned char* FAADAPI (*)(unsigned char)));
-#undef dfacc
-
-#ifdef CONFIG_FAADBIN
- break;
- }
- if (err) {
- dlclose(s->handle);
- fprintf(stderr, "FAAD library: cannot resolve %s in %s!\n",
- err, libfaadname);
- return -1;
- }
-#endif
-
- s->faac_handle = s->faacDecOpen();
- if (!s->faac_handle) {
- fprintf(stderr, "FAAD library: cannot create handler!\n");
- faac_decode_end(avctx);
- return -1;
- }
-
-
- faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle);
-
- if (faac_cfg) {
- switch (avctx->bits_per_sample) {
- case 8: fprintf(stderr, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break;
- default:
- case 16:
- faac_cfg->outputFormat = FAAD_FMT_16BIT;
- s->sample_size = 2;
- break;
- case 24:
- faac_cfg->outputFormat = FAAD_FMT_24BIT;
- s->sample_size = 3;
- break;
- case 32:
- faac_cfg->outputFormat = FAAD_FMT_32BIT;
- s->sample_size = 4;
- break;
- }
-
- faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate;
- faac_cfg->defObjectType = LC;
- }
-
- s->faacDecSetConfiguration(s->faac_handle, faac_cfg);
-
- faac_init_mp4(avctx);
-
- return 0;
-}
-
-#define AAC_CODEC(id, name) \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(FAACContext), \
- faac_decode_init, \
- NULL, \
- faac_decode_end, \
- faac_decode_frame, \
-}
-
-// FIXME - raw AAC files - maybe just one entry will be enough
-AAC_CODEC(CODEC_ID_AAC, aac);
-// If it's mp4 file - usually embeded into Qt Mov
-AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac);
-
-#undef AAC_CODEC
+++ /dev/null
-#include "../libvo/fastmemcpy.h"
+++ /dev/null
-/**
- * @file fdctref.c
- * forward discrete cosine transform, double precision.
- */
-
-/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
-
-/*
- * Disclaimer of Warranty
- *
- * These software programs are available to the user without any license fee or
- * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims
- * any and all warranties, whether express, implied, or statuary, including any
- * implied warranties or merchantability or of fitness for a particular
- * purpose. In no event shall the copyright-holder be liable for any
- * incidental, punitive, or consequential damages of any kind whatsoever
- * arising from the use of these programs.
- *
- * This disclaimer of warranty extends to the user of these programs and user's
- * customers, employees, agents, transferees, successors, and assigns.
- *
- * The MPEG Software Simulation Group does not represent or warrant that the
- * programs furnished hereunder are free of infringement of any third-party
- * patents.
- *
- * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
- * are subject to royalty fees to patent holders. Many of these patents are
- * general enough such that they are unavoidable regardless of implementation
- * design.
- *
- */
-
-#include <math.h>
-
-#ifndef PI
-# ifdef M_PI
-# define PI M_PI
-# else
-# define PI 3.14159265358979323846
-# endif
-#endif
-
-/* global declarations */
-void init_fdct (void);
-void fdct (short *block);
-
-/* private data */
-static double c[8][8]; /* transform coefficients */
-
-void init_fdct()
-{
- int i, j;
- double s;
-
- for (i=0; i<8; i++)
- {
- s = (i==0) ? sqrt(0.125) : 0.5;
-
- for (j=0; j<8; j++)
- c[i][j] = s * cos((PI/8.0)*i*(j+0.5));
- }
-}
-
-void fdct(block)
-short *block;
-{
- register int i, j;
- double s;
- double tmp[64];
-
- for(i = 0; i < 8; i++)
- for(j = 0; j < 8; j++)
- {
- s = 0.0;
-
-/*
- * for(k = 0; k < 8; k++)
- * s += c[j][k] * block[8 * i + k];
- */
- s += c[j][0] * block[8 * i + 0];
- s += c[j][1] * block[8 * i + 1];
- s += c[j][2] * block[8 * i + 2];
- s += c[j][3] * block[8 * i + 3];
- s += c[j][4] * block[8 * i + 4];
- s += c[j][5] * block[8 * i + 5];
- s += c[j][6] * block[8 * i + 6];
- s += c[j][7] * block[8 * i + 7];
-
- tmp[8 * i + j] = s;
- }
-
- for(j = 0; j < 8; j++)
- for(i = 0; i < 8; i++)
- {
- s = 0.0;
-
-/*
- * for(k = 0; k < 8; k++)
- * s += c[i][k] * tmp[8 * k + j];
- */
- s += c[i][0] * tmp[8 * 0 + j];
- s += c[i][1] * tmp[8 * 1 + j];
- s += c[i][2] * tmp[8 * 2 + j];
- s += c[i][3] * tmp[8 * 3 + j];
- s += c[i][4] * tmp[8 * 4 + j];
- s += c[i][5] * tmp[8 * 5 + j];
- s += c[i][6] * tmp[8 * 6 + j];
- s += c[i][7] * tmp[8 * 7 + j];
- s*=8.0;
-
- block[8 * i + j] = (short)floor(s + 0.499999);
-/*
- * reason for adding 0.499999 instead of 0.5:
- * s is quite often x.5 (at least for i and/or j = 0 or 4)
- * and setting the rounding threshold exactly to 0.5 leads to an
- * extremely high arithmetic implementation dependency of the result;
- * s being between x.5 and x.500001 (which is now incorrectly rounded
- * downwards instead of upwards) is assumed to occur less often
- * (if at all)
- */
- }
-}
-
-/* perform IDCT matrix multiply for 8x8 coefficient block */
-
-void idct(block)
-short *block;
-{
- int i, j, k, v;
- double partial_product;
- double tmp[64];
-
- for (i=0; i<8; i++)
- for (j=0; j<8; j++)
- {
- partial_product = 0.0;
-
- for (k=0; k<8; k++)
- partial_product+= c[k][j]*block[8*i+k];
-
- tmp[8*i+j] = partial_product;
- }
-
- /* Transpose operation is integrated into address mapping by switching
- loop order of i and j */
-
- for (j=0; j<8; j++)
- for (i=0; i<8; i++)
- {
- partial_product = 0.0;
-
- for (k=0; k<8; k++)
- partial_product+= c[k][i]*tmp[8*k+j];
-
- v = (int) floor(partial_product+0.5);
- block[8*i+j] = v;
- }
-}
+++ /dev/null
-/**
- * @file fft-test.c
- * FFT and MDCT tests.
- */
-
-#include "dsputil.h"
-#include <math.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-int mm_flags;
-
-/* reference fft */
-
-#define MUL16(a,b) ((a) * (b))
-
-#define CMAC(pre, pim, are, aim, bre, bim) \
-{\
- pre += (MUL16(are, bre) - MUL16(aim, bim));\
- pim += (MUL16(are, bim) + MUL16(bre, aim));\
-}
-
-FFTComplex *exptab;
-
-void fft_ref_init(int nbits, int inverse)
-{
- int n, i;
- float c1, s1, alpha;
-
- n = 1 << nbits;
- exptab = av_malloc((n / 2) * sizeof(FFTComplex));
-
- for(i=0;i<(n/2);i++) {
- alpha = 2 * M_PI * (float)i / (float)n;
- c1 = cos(alpha);
- s1 = sin(alpha);
- if (!inverse)
- s1 = -s1;
- exptab[i].re = c1;
- exptab[i].im = s1;
- }
-}
-
-void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits)
-{
- int n, i, j, k, n2;
- float tmp_re, tmp_im, s, c;
- FFTComplex *q;
-
- n = 1 << nbits;
- n2 = n >> 1;
- for(i=0;i<n;i++) {
- tmp_re = 0;
- tmp_im = 0;
- q = tab;
- for(j=0;j<n;j++) {
- k = (i * j) & (n - 1);
- if (k >= n2) {
- c = -exptab[k - n2].re;
- s = -exptab[k - n2].im;
- } else {
- c = exptab[k].re;
- s = exptab[k].im;
- }
- CMAC(tmp_re, tmp_im, c, s, q->re, q->im);
- q++;
- }
- tabr[i].re = tmp_re;
- tabr[i].im = tmp_im;
- }
-}
-
-void imdct_ref(float *out, float *in, int n)
-{
- int k, i, a;
- float sum, f;
-
- for(i=0;i<n;i++) {
- sum = 0;
- for(k=0;k<n/2;k++) {
- a = (2 * i + 1 + (n / 2)) * (2 * k + 1);
- f = cos(M_PI * a / (double)(2 * n));
- sum += f * in[k];
- }
- out[i] = -sum;
- }
-}
-
-/* NOTE: no normalisation by 1 / N is done */
-void mdct_ref(float *output, float *input, int n)
-{
- int k, i;
- float a, s;
-
- /* do it by hand */
- for(k=0;k<n/2;k++) {
- s = 0;
- for(i=0;i<n;i++) {
- a = (2*M_PI*(2*i+1+n/2)*(2*k+1) / (4 * n));
- s += input[i] * cos(a);
- }
- output[k] = s;
- }
-}
-
-
-float frandom(void)
-{
- return (float)((random() & 0xffff) - 32768) / 32768.0;
-}
-
-int64_t gettime(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-void check_diff(float *tab1, float *tab2, int n)
-{
- int i;
-
- for(i=0;i<n;i++) {
- if (fabsf(tab1[i] - tab2[i]) >= 1e-3) {
- printf("ERROR %d: %f %f\n",
- i, tab1[i], tab2[i]);
- }
- }
-}
-
-
-void help(void)
-{
- printf("usage: fft-test [-h] [-s] [-i] [-n b]\n"
- "-h print this help\n"
- "-s speed test\n"
- "-m (I)MDCT test\n"
- "-i inverse transform test\n"
- "-n b set the transform size to 2^b\n"
- );
- exit(1);
-}
-
-
-
-int main(int argc, char **argv)
-{
- FFTComplex *tab, *tab1, *tab_ref;
- FFTSample *tabtmp, *tab2;
- int it, i, c;
- int do_speed = 0;
- int do_mdct = 0;
- int do_inverse = 0;
- FFTContext s1, *s = &s1;
- MDCTContext m1, *m = &m1;
- int fft_nbits, fft_size;
-
- mm_flags = 0;
- fft_nbits = 9;
- for(;;) {
- c = getopt(argc, argv, "hsimn:");
- if (c == -1)
- break;
- switch(c) {
- case 'h':
- help();
- break;
- case 's':
- do_speed = 1;
- break;
- case 'i':
- do_inverse = 1;
- break;
- case 'm':
- do_mdct = 1;
- break;
- case 'n':
- fft_nbits = atoi(optarg);
- break;
- }
- }
-
- fft_size = 1 << fft_nbits;
- tab = av_malloc(fft_size * sizeof(FFTComplex));
- tab1 = av_malloc(fft_size * sizeof(FFTComplex));
- tab_ref = av_malloc(fft_size * sizeof(FFTComplex));
- tabtmp = av_malloc(fft_size / 2 * sizeof(FFTSample));
- tab2 = av_malloc(fft_size * sizeof(FFTSample));
-
- if (do_mdct) {
- if (do_inverse)
- printf("IMDCT");
- else
- printf("MDCT");
- ff_mdct_init(m, fft_nbits, do_inverse);
- } else {
- if (do_inverse)
- printf("IFFT");
- else
- printf("FFT");
- fft_init(s, fft_nbits, do_inverse);
- fft_ref_init(fft_nbits, do_inverse);
- }
- printf(" %d test\n", fft_size);
-
- /* generate random data */
-
- for(i=0;i<fft_size;i++) {
- tab1[i].re = frandom();
- tab1[i].im = frandom();
- }
-
- /* checking result */
- printf("Checking...\n");
-
- if (do_mdct) {
- if (do_inverse) {
- imdct_ref((float *)tab_ref, (float *)tab1, fft_size);
- ff_imdct_calc(m, tab2, (float *)tab1, tabtmp);
- check_diff((float *)tab_ref, tab2, fft_size);
- } else {
- mdct_ref((float *)tab_ref, (float *)tab1, fft_size);
-
- ff_mdct_calc(m, tab2, (float *)tab1, tabtmp);
-
- check_diff((float *)tab_ref, tab2, fft_size / 2);
- }
- } else {
- memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
- fft_permute(s, tab);
- fft_calc(s, tab);
-
- fft_ref(tab_ref, tab1, fft_nbits);
- check_diff((float *)tab_ref, (float *)tab, fft_size * 2);
- }
-
- /* do a speed test */
-
- if (do_speed) {
- int64_t time_start, duration;
- int nb_its;
-
- printf("Speed test...\n");
- /* we measure during about 1 seconds */
- nb_its = 1;
- for(;;) {
- time_start = gettime();
- for(it=0;it<nb_its;it++) {
- if (do_mdct) {
- if (do_inverse) {
- ff_imdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
- } else {
- ff_mdct_calc(m, (float *)tab, (float *)tab1, tabtmp);
- }
- } else {
- memcpy(tab, tab1, fft_size * sizeof(FFTComplex));
- fft_calc(s, tab);
- }
- }
- duration = gettime() - time_start;
- if (duration >= 1000000)
- break;
- nb_its *= 2;
- }
- printf("time: %0.1f us/transform [total time=%0.2f s its=%d]\n",
- (double)duration / nb_its,
- (double)duration / 1000000.0,
- nb_its);
- }
-
- if (do_mdct) {
- ff_mdct_end(m);
- } else {
- fft_end(s);
- }
- return 0;
-}
+++ /dev/null
-/*
- * FFT/IFFT transforms
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file fft.c
- * FFT/IFFT transforms.
- */
-
-#include "dsputil.h"
-
-/**
- * The size of the FFT is 2^nbits. If inverse is TRUE, inverse FFT is
- * done
- */
-int fft_init(FFTContext *s, int nbits, int inverse)
-{
- int i, j, m, n;
- float alpha, c1, s1, s2;
-
- s->nbits = nbits;
- n = 1 << nbits;
-
- s->exptab = av_malloc((n / 2) * sizeof(FFTComplex));
- if (!s->exptab)
- goto fail;
- s->revtab = av_malloc(n * sizeof(uint16_t));
- if (!s->revtab)
- goto fail;
- s->inverse = inverse;
-
- s2 = inverse ? 1.0 : -1.0;
-
- for(i=0;i<(n/2);i++) {
- alpha = 2 * M_PI * (float)i / (float)n;
- c1 = cos(alpha);
- s1 = sin(alpha) * s2;
- s->exptab[i].re = c1;
- s->exptab[i].im = s1;
- }
- s->fft_calc = fft_calc_c;
- s->exptab1 = NULL;
-
- /* compute constant table for HAVE_SSE version */
-#if (defined(HAVE_MMX) && defined(HAVE_BUILTIN_VECTOR)) || defined(HAVE_ALTIVEC)
- {
- int has_vectors = 0;
-
-#if defined(HAVE_MMX)
- has_vectors = mm_support() & MM_SSE;
-#endif
-#if defined(HAVE_ALTIVEC) && !defined(ALTIVEC_USE_REFERENCE_C_CODE)
- has_vectors = mm_support() & MM_ALTIVEC;
-#endif
- if (has_vectors) {
- int np, nblocks, np2, l;
- FFTComplex *q;
-
- np = 1 << nbits;
- nblocks = np >> 3;
- np2 = np >> 1;
- s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex));
- if (!s->exptab1)
- goto fail;
- q = s->exptab1;
- do {
- for(l = 0; l < np2; l += 2 * nblocks) {
- *q++ = s->exptab[l];
- *q++ = s->exptab[l + nblocks];
-
- q->re = -s->exptab[l].im;
- q->im = s->exptab[l].re;
- q++;
- q->re = -s->exptab[l + nblocks].im;
- q->im = s->exptab[l + nblocks].re;
- q++;
- }
- nblocks = nblocks >> 1;
- } while (nblocks != 0);
- av_freep(&s->exptab);
-#if defined(HAVE_MMX)
- s->fft_calc = fft_calc_sse;
-#else
- s->fft_calc = fft_calc_altivec;
-#endif
- }
- }
-#endif
-
- /* compute bit reverse table */
-
- for(i=0;i<n;i++) {
- m=0;
- for(j=0;j<nbits;j++) {
- m |= ((i >> j) & 1) << (nbits-j-1);
- }
- s->revtab[i]=m;
- }
- return 0;
- fail:
- av_freep(&s->revtab);
- av_freep(&s->exptab);
- av_freep(&s->exptab1);
- return -1;
-}
-
-/* butter fly op */
-#define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \
-{\
- FFTSample ax, ay, bx, by;\
- bx=pre1;\
- by=pim1;\
- ax=qre1;\
- ay=qim1;\
- pre = (bx + ax);\
- pim = (by + ay);\
- qre = (bx - ax);\
- qim = (by - ay);\
-}
-
-#define MUL16(a,b) ((a) * (b))
-
-#define CMUL(pre, pim, are, aim, bre, bim) \
-{\
- pre = (MUL16(are, bre) - MUL16(aim, bim));\
- pim = (MUL16(are, bim) + MUL16(bre, aim));\
-}
-
-/**
- * Do a complex FFT with the parameters defined in fft_init(). The
- * input data must be permuted before with s->revtab table. No
- * 1.0/sqrt(n) normalization is done.
- */
-void fft_calc_c(FFTContext *s, FFTComplex *z)
-{
- int ln = s->nbits;
- int j, np, np2;
- int nblocks, nloops;
- register FFTComplex *p, *q;
- FFTComplex *exptab = s->exptab;
- int l;
- FFTSample tmp_re, tmp_im;
-
- np = 1 << ln;
-
- /* pass 0 */
-
- p=&z[0];
- j=(np >> 1);
- do {
- BF(p[0].re, p[0].im, p[1].re, p[1].im,
- p[0].re, p[0].im, p[1].re, p[1].im);
- p+=2;
- } while (--j != 0);
-
- /* pass 1 */
-
-
- p=&z[0];
- j=np >> 2;
- if (s->inverse) {
- do {
- BF(p[0].re, p[0].im, p[2].re, p[2].im,
- p[0].re, p[0].im, p[2].re, p[2].im);
- BF(p[1].re, p[1].im, p[3].re, p[3].im,
- p[1].re, p[1].im, -p[3].im, p[3].re);
- p+=4;
- } while (--j != 0);
- } else {
- do {
- BF(p[0].re, p[0].im, p[2].re, p[2].im,
- p[0].re, p[0].im, p[2].re, p[2].im);
- BF(p[1].re, p[1].im, p[3].re, p[3].im,
- p[1].re, p[1].im, p[3].im, -p[3].re);
- p+=4;
- } while (--j != 0);
- }
- /* pass 2 .. ln-1 */
-
- nblocks = np >> 3;
- nloops = 1 << 2;
- np2 = np >> 1;
- do {
- p = z;
- q = z + nloops;
- for (j = 0; j < nblocks; ++j) {
- BF(p->re, p->im, q->re, q->im,
- p->re, p->im, q->re, q->im);
-
- p++;
- q++;
- for(l = nblocks; l < np2; l += nblocks) {
- CMUL(tmp_re, tmp_im, exptab[l].re, exptab[l].im, q->re, q->im);
- BF(p->re, p->im, q->re, q->im,
- p->re, p->im, tmp_re, tmp_im);
- p++;
- q++;
- }
-
- p += nloops;
- q += nloops;
- }
- nblocks = nblocks >> 1;
- nloops = nloops << 1;
- } while (nblocks != 0);
-}
-
-/**
- * Do the permutation needed BEFORE calling fft_calc()
- */
-void fft_permute(FFTContext *s, FFTComplex *z)
-{
- int j, k, np;
- FFTComplex tmp;
- const uint16_t *revtab = s->revtab;
-
- /* reverse */
- np = 1 << s->nbits;
- for(j=0;j<np;j++) {
- k = revtab[j];
- if (k < j) {
- tmp = z[k];
- z[k] = z[j];
- z[j] = tmp;
- }
- }
-}
-
-void fft_end(FFTContext *s)
-{
- av_freep(&s->revtab);
- av_freep(&s->exptab);
- av_freep(&s->exptab1);
-}
-
+++ /dev/null
-/*
- * FFV1 codec for libavcodec
- *
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file ffv1.c
- * FF Video Codec 1 (a experimental lossless codec)
- */
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "cabac.h"
-#include "golomb.h"
-
-#define MAX_PLANES 4
-#define CONTEXT_SIZE 32
-
-static const int8_t quant3[256]={
- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0,
-};
-static const int8_t quant5[256]={
- 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,-1,
-};
-static const int8_t quant7[256]={
- 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,
-};
-static const int8_t quant9[256]={
- 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,
--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1,
-};
-static const int8_t quant11[256]={
- 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,
--4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1,
-};
-static const int8_t quant13[256]={
- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,
--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,
--4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1,
-};
-
-static const uint8_t log2_run[32]={
- 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
- 4, 4, 5, 5, 6, 6, 7, 7,
- 8, 9,10,11,12,13,14,15,
-};
-
-typedef struct VlcState{
- int16_t drift;
- uint16_t error_sum;
- int8_t bias;
- uint8_t count;
-} VlcState;
-
-typedef struct PlaneContext{
- int context_count;
- uint8_t (*state)[CONTEXT_SIZE];
- VlcState *vlc_state;
- uint8_t interlace_bit_state[2];
-} PlaneContext;
-
-typedef struct FFV1Context{
- AVCodecContext *avctx;
- CABACContext c;
- GetBitContext gb;
- PutBitContext pb;
- int version;
- int width, height;
- int chroma_h_shift, chroma_v_shift;
- int flags;
- int picture_number;
- AVFrame picture;
- int plane_count;
- int ac; ///< 1-> CABAC 0-> golomb rice
- PlaneContext plane[MAX_PLANES];
- int16_t quant_table[5][256];
-
- DSPContext dsp;
-}FFV1Context;
-
-static inline int predict(uint8_t *src, uint8_t *last){
- const int LT= last[-1];
- const int T= last[ 0];
- const int L = src[-1];
-
- return mid_pred(L, L + T - LT, T);
-}
-
-static inline int get_context(FFV1Context *f, uint8_t *src, uint8_t *last, uint8_t *last2){
- const int LT= last[-1];
- const int T= last[ 0];
- const int RT= last[ 1];
- const int L = src[-1];
-
- if(f->quant_table[3][127]){
- const int TT= last2[0];
- const int LL= src[-2];
- return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF]
- +f->quant_table[3][(LL-L) & 0xFF] + f->quant_table[4][(TT-T) & 0xFF];
- }else
- return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF];
-}
-
-/**
- * put
- */
-static inline void put_symbol(CABACContext *c, uint8_t *state, int v, int is_signed, int max_exp){
- int i;
-
- if(v){
- const int a= ABS(v);
- const int e= av_log2(a);
-
- put_cabac(c, state+0, 0);
-
- for(i=0; i<e; i++){
- put_cabac(c, state+1+i, 1); //1..8
- }
-
- if(e<max_exp){
- put_cabac(c, state+1+i, 0); //1..8
-
- for(i=e-1; i>=0; i--){
- put_cabac(c, state+16+e+i, (a>>i)&1); //17..29
- }
- if(is_signed)
- put_cabac(c, state+9 + e, v < 0); //9..16
- }
- }else{
- put_cabac(c, state+0, 1);
- }
-}
-
-static inline int get_symbol(CABACContext *c, uint8_t *state, int is_signed, int max_exp){
- if(get_cabac(c, state+0))
- return 0;
- else{
- int i, e;
-
- for(e=0; e<max_exp; e++){
- int a= 1<<e;
-
- if(get_cabac(c, state + 1 + e)==0){ // 1..8
- for(i=e-1; i>=0; i--){
- a += get_cabac(c, state+16+e+i)<<i; //17..29
- }
-
- if(is_signed && get_cabac(c, state+9 + e)) //9..16
- return -a;
- else
- return a;
- }
- }
- return -(1<<e);
- }
-}
-
-static inline void update_vlc_state(VlcState * const state, const int v){
- int drift= state->drift;
- int count= state->count;
- state->error_sum += ABS(v);
- drift += v;
-
- if(count == 128){ //FIXME variable
- count >>= 1;
- drift >>= 1;
- state->error_sum >>= 1;
- }
- count++;
-
- if(drift <= -count){
- if(state->bias > -128) state->bias--;
-
- drift += count;
- if(drift <= -count)
- drift= -count + 1;
- }else if(drift > 0){
- if(state->bias < 127) state->bias++;
-
- drift -= count;
- if(drift > 0)
- drift= 0;
- }
-
- state->drift= drift;
- state->count= count;
-}
-
-static inline void put_vlc_symbol(PutBitContext *pb, VlcState * const state, int v){
- int i, k, code;
-//printf("final: %d ", v);
- v = (int8_t)(v - state->bias);
-
- i= state->count;
- k=0;
- while(i < state->error_sum){ //FIXME optimize
- k++;
- i += i;
- }
-
- assert(k<=8);
-
-#if 0 // JPEG LS
- if(k==0 && 2*state->drift <= - state->count) code= v ^ (-1);
- else code= v;
-#else
- code= v ^ ((2*state->drift + state->count)>>31);
-#endif
-
- code = -2*code-1;
- code^= (code>>31);
-//printf("v:%d/%d bias:%d error:%d drift:%d count:%d k:%d\n", v, code, state->bias, state->error_sum, state->drift, state->count, k);
- set_ur_golomb(pb, code, k, 12, 8);
-
- update_vlc_state(state, v);
-}
-
-static inline int get_vlc_symbol(GetBitContext *gb, VlcState * const state){
- int k, i, v, ret;
-
- i= state->count;
- k=0;
- while(i < state->error_sum){ //FIXME optimize
- k++;
- i += i;
- }
-
- assert(k<=8);
-
- v= get_ur_golomb(gb, k, 12, 8);
-//printf("v:%d bias:%d error:%d drift:%d count:%d k:%d", v, state->bias, state->error_sum, state->drift, state->count, k);
-
- v++;
- if(v&1) v= (v>>1);
- else v= -(v>>1);
-
-#if 0 // JPEG LS
- if(k==0 && 2*state->drift <= - state->count) v ^= (-1);
-#else
- v ^= ((2*state->drift + state->count)>>31);
-#endif
-
- ret= (int8_t)(v + state->bias);
-
- update_vlc_state(state, v);
-//printf("final: %d\n", ret);
- return ret;
-}
-
-
-
-static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
- PlaneContext * const p= &s->plane[plane_index];
- CABACContext * const c= &s->c;
- int x,y;
- uint8_t sample_buffer[2][w+6];
- uint8_t *sample[2]= {sample_buffer[0]+3, sample_buffer[1]+3};
- int run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- uint8_t *temp= sample[0]; //FIXME try a normal buffer
- int run_count=0;
- int run_mode=0;
-
- sample[0]= sample[1];
- sample[1]= temp;
-
- sample[1][-1]= sample[0][0 ];
- sample[0][ w]= sample[0][w-1];
-
- for(x=0; x<w; x++){
- uint8_t *temp_src= src + x + stride*y;
- int diff, context;
-
- context= get_context(s, sample[1]+x, sample[0]+x, sample[1]+x);
- diff= temp_src[0] - predict(sample[1]+x, sample[0]+x);
-
- if(context < 0){
- context = -context;
- diff= -diff;
- }
-
- diff= (int8_t)diff;
-
- if(s->ac){
- put_symbol(c, p->state[context], diff, 1, 7);
- }else{
- if(context == 0) run_mode=1;
-
- if(run_mode){
-
- if(diff){
- while(run_count >= 1<<log2_run[run_index]){
- run_count -= 1<<log2_run[run_index];
- run_index++;
- put_bits(&s->pb, 1, 1);
- }
-
- put_bits(&s->pb, 1 + log2_run[run_index], run_count);
- if(run_index) run_index--;
- run_count=0;
- run_mode=0;
- if(diff>0) diff--;
- }else{
- run_count++;
- }
- }
-
-// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, (int)get_bit_count(&s->pb));
-
- if(run_mode == 0)
- put_vlc_symbol(&s->pb, &p->vlc_state[context], diff);
- }
-
- sample[1][x]= temp_src[0];
- }
- if(run_mode){
- while(run_count >= 1<<log2_run[run_index]){
- run_count -= 1<<log2_run[run_index];
- run_index++;
- put_bits(&s->pb, 1, 1);
- }
-
- if(run_count)
- put_bits(&s->pb, 1, 1);
- }
- }
-}
-
-static void write_quant_table(CABACContext *c, int16_t *quant_table){
- int last=0;
- int i;
- uint8_t state[CONTEXT_SIZE]={0};
-
- for(i=1; i<128 ; i++){
- if(quant_table[i] != quant_table[i-1]){
- put_symbol(c, state, i-last-1, 0, 7);
- last= i;
- }
- }
- put_symbol(c, state, i-last-1, 0, 7);
-}
-
-static void write_header(FFV1Context *f){
- uint8_t state[CONTEXT_SIZE]={0};
- int i;
- CABACContext * const c= &f->c;
-
- put_symbol(c, state, f->version, 0, 7);
- put_symbol(c, state, f->avctx->coder_type, 0, 7);
- put_symbol(c, state, 0, 0, 7); //YUV cs type
- put_cabac(c, state, 1); //chroma planes
- put_symbol(c, state, f->chroma_h_shift, 0, 7);
- put_symbol(c, state, f->chroma_v_shift, 0, 7);
- put_cabac(c, state, 0); //no transparency plane
-
- for(i=0; i<5; i++)
- write_quant_table(c, f->quant_table[i]);
-}
-
-static int common_init(AVCodecContext *avctx){
- FFV1Context *s = avctx->priv_data;
- int width, height;
-
- s->avctx= avctx;
- s->flags= avctx->flags;
-
- dsputil_init(&s->dsp, avctx);
-
- width= s->width= avctx->width;
- height= s->height= avctx->height;
-
- assert(width && height);
-
- return 0;
-}
-
-static int encode_init(AVCodecContext *avctx)
-{
- FFV1Context *s = avctx->priv_data;
- int i;
-
- common_init(avctx);
-
- s->version=0;
- s->ac= avctx->coder_type;
-
- s->plane_count=2;
- for(i=0; i<256; i++){
- s->quant_table[0][i]= quant11[i];
- s->quant_table[1][i]= 11*quant11[i];
- if(avctx->context_model==0){
- s->quant_table[2][i]= 11*11*quant11[i];
- s->quant_table[3][i]=
- s->quant_table[4][i]=0;
- }else{
- s->quant_table[2][i]= 11*11*quant5 [i];
- s->quant_table[3][i]= 5*11*11*quant5 [i];
- s->quant_table[4][i]= 5*5*11*11*quant5 [i];
- }
- }
-
- for(i=0; i<s->plane_count; i++){
- PlaneContext * const p= &s->plane[i];
-
- if(avctx->context_model==0){
- p->context_count= (11*11*11+1)/2;
- }else{
- p->context_count= (11*11*5*5*5+1)/2;
- }
-
- if(s->ac){
- if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
- }else{
- if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
- }
- }
-
- avctx->coded_frame= &s->picture;
- switch(avctx->pix_fmt){
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV411P:
- case PIX_FMT_YUV410P:
- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift);
- break;
- default:
- fprintf(stderr, "format not supported\n");
- return -1;
- }
-
-
- s->picture_number=0;
-
- return 0;
-}
-
-
-static void clear_state(FFV1Context *f){
- int i, j;
-
- for(i=0; i<f->plane_count; i++){
- PlaneContext *p= &f->plane[i];
-
- p->interlace_bit_state[0]= 0;
- p->interlace_bit_state[1]= 0;
-
- for(j=0; j<p->context_count; j++){
- if(f->ac){
- memset(p->state[j], 0, sizeof(uint8_t)*CONTEXT_SIZE);
- p->state[j][7] = 2*62;
- }else{
- p->vlc_state[j].drift= 0;
- p->vlc_state[j].error_sum= 4; //FFMAX((RANGE + 32)/64, 2);
- p->vlc_state[j].bias= 0;
- p->vlc_state[j].count= 1;
- }
- }
- }
-}
-
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- FFV1Context *f = avctx->priv_data;
- CABACContext * const c= &f->c;
- AVFrame *pict = data;
- const int width= f->width;
- const int height= f->height;
- AVFrame * const p= &f->picture;
- int used_count= 0;
-
- if(avctx->strict_std_compliance >= 0){
- printf("this codec is under development, files encoded with it wont be decodeable with future versions!!!\n"
- "use vstrict=-1 to use it anyway\n");
- return -1;
- }
-
- ff_init_cabac_encoder(c, buf, buf_size);
- ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
-
- if(avctx->gop_size==0 || f->picture_number % avctx->gop_size == 0){
- put_cabac_bypass(c, 1);
- p->key_frame= 1;
- write_header(f);
- clear_state(f);
- }else{
- put_cabac_bypass(c, 0);
- p->key_frame= 0;
- }
-
- if(!f->ac){
- used_count += put_cabac_terminate(c, 1);
-//printf("pos=%d\n", used_count);
- init_put_bits(&f->pb, buf + used_count, buf_size - used_count, NULL, NULL);
- }
-
- if(1){
- const int chroma_width = -((-width )>>f->chroma_h_shift);
- const int chroma_height= -((-height)>>f->chroma_v_shift);
-
- encode_plane(f, p->data[0], width, height, p->linesize[0], 0);
-
- encode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
- encode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
- }
- emms_c();
-
- f->picture_number++;
-
- if(f->ac){
- return put_cabac_terminate(c, 1);
- }else{
- flush_put_bits(&f->pb); //nicer padding FIXME
- return used_count + (get_bit_count(&f->pb)+7)/8;
- }
-}
-
-static void common_end(FFV1Context *s){
- int i;
-
- for(i=0; i<s->plane_count; i++){
- PlaneContext *p= &s->plane[i];
-
- av_freep(&p->state);
- }
-}
-
-static int encode_end(AVCodecContext *avctx)
-{
- FFV1Context *s = avctx->priv_data;
-
- common_end(s);
-
- return 0;
-}
-
-static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){
- PlaneContext * const p= &s->plane[plane_index];
- CABACContext * const c= &s->c;
- int x,y;
- uint8_t sample_buffer[2][w+6];
- uint8_t *sample[2]= {sample_buffer[0]+3, sample_buffer[1]+3};
- int run_index=0;
-
- memset(sample_buffer, 0, sizeof(sample_buffer));
-
- for(y=0; y<h; y++){
- uint8_t *temp= sample[0]; //FIXME try a normal buffer
- int run_count=0;
- int run_mode=0;
-
- sample[0]= sample[1];
- sample[1]= temp;
-
- sample[1][-1]= sample[0][0 ];
- sample[0][ w]= sample[0][w-1];
-
- for(x=0; x<w; x++){
- uint8_t *temp_src= src + x + stride*y;
- int diff, context, sign;
-
- context= get_context(s, sample[1] + x, sample[0] + x, sample[1] + x);
- if(context < 0){
- context= -context;
- sign=1;
- }else
- sign=0;
-
-
- if(s->ac)
- diff= get_symbol(c, p->state[context], 1, 7);
- else{
- if(context == 0 && run_mode==0) run_mode=1;
-
- if(run_mode){
- if(run_count==0 && run_mode==1){
- if(get_bits1(&s->gb)){
- run_count = 1<<log2_run[run_index];
- if(x + run_count <= w) run_index++;
- }else{
- if(log2_run[run_index]) run_count = get_bits(&s->gb, log2_run[run_index]);
- else run_count=0;
- if(run_index) run_index--;
- run_mode=2;
- }
- }
- run_count--;
- if(run_count < 0){
- run_mode=0;
- run_count=0;
- diff= get_vlc_symbol(&s->gb, &p->vlc_state[context]);
- if(diff>=0) diff++;
- }else
- diff=0;
- }else
- diff= get_vlc_symbol(&s->gb, &p->vlc_state[context]);
-
-// printf("count:%d index:%d, mode:%d, x:%d y:%d pos:%d\n", run_count, run_index, run_mode, x, y, get_bits_count(&s->gb));
- }
-
- if(sign) diff= (int8_t)(-diff); //FIXME remove cast
-
- sample[1][x]=
- temp_src[0] = predict(sample[1] + x, sample[0] + x) + diff;
-
- assert(diff>= -128 && diff <= 127);
- }
- }
-}
-
-static int read_quant_table(CABACContext *c, int16_t *quant_table, int scale){
- int v;
- int i=0;
- uint8_t state[CONTEXT_SIZE]={0};
-
- for(v=0; i<128 ; v++){
- int len= get_symbol(c, state, 0, 7) + 1;
-
- if(len + i > 128) return -1;
-
- while(len--){
- quant_table[i] = scale*v;
- i++;
-//printf("%2d ",v);
-//if(i%16==0) printf("\n");
- }
- }
-
- for(i=1; i<128; i++){
- quant_table[256-i]= -quant_table[i];
- }
- quant_table[128]= -quant_table[127];
-
- return 2*v - 1;
-}
-
-static int read_header(FFV1Context *f){
- uint8_t state[CONTEXT_SIZE]={0};
- int i, context_count;
- CABACContext * const c= &f->c;
-
- f->version= get_symbol(c, state, 0, 7);
- f->ac= f->avctx->coder_type= get_symbol(c, state, 0, 7);
- get_symbol(c, state, 0, 7); //YUV cs type
- get_cabac(c, state); //no chroma = false
- f->chroma_h_shift= get_symbol(c, state, 0, 7);
- f->chroma_v_shift= get_symbol(c, state, 0, 7);
- get_cabac(c, state); //transparency plane
- f->plane_count= 2;
-
- switch(16*f->chroma_h_shift + f->chroma_v_shift){
- case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P; break;
- case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P; break;
- case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P; break;
- case 0x20: f->avctx->pix_fmt= PIX_FMT_YUV411P; break;
- case 0x33: f->avctx->pix_fmt= PIX_FMT_YUV410P; break;
- default:
- fprintf(stderr, "format not supported\n");
- return -1;
- }
-//printf("%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift,f->avctx->pix_fmt);
-
- context_count=1;
- for(i=0; i<5; i++){
- context_count*= read_quant_table(c, f->quant_table[i], context_count);
- if(context_count < 0){
- printf("read_quant_table error\n");
- return -1;
- }
- }
- context_count= (context_count+1)/2;
-
- for(i=0; i<f->plane_count; i++){
- PlaneContext * const p= &f->plane[i];
-
- p->context_count= context_count;
-
- if(f->ac){
- if(!p->state) p->state= av_malloc(CONTEXT_SIZE*p->context_count*sizeof(uint8_t));
- }else{
- if(!p->vlc_state) p->vlc_state= av_malloc(p->context_count*sizeof(VlcState));
- }
- }
-
- return 0;
-}
-
-static int decode_init(AVCodecContext *avctx)
-{
-// FFV1Context *s = avctx->priv_data;
-
- common_init(avctx);
-
-#if 0
- switch(s->bitstream_bpp){
- case 12:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- case 16:
- avctx->pix_fmt = PIX_FMT_YUV422P;
- break;
- case 24:
- case 32:
- if(s->bgr32){
- avctx->pix_fmt = PIX_FMT_RGBA32;
- }else{
- avctx->pix_fmt = PIX_FMT_BGR24;
- }
- break;
- default:
- assert(0);
- }
-#endif
-
- return 0;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
- FFV1Context *f = avctx->priv_data;
- CABACContext * const c= &f->c;
- const int width= f->width;
- const int height= f->height;
- AVFrame * const p= &f->picture;
- int bytes_read;
-
- AVFrame *picture = data;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
- ff_init_cabac_decoder(c, buf, buf_size);
- ff_init_cabac_states(c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64);
-
- p->pict_type= FF_I_TYPE; //FIXME I vs. P
- if(get_cabac_bypass(c)){
- p->key_frame= 1;
- read_header(f);
- clear_state(f);
- }else{
- p->key_frame= 0;
- }
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- if(avctx->debug&FF_DEBUG_PICT_INFO)
- printf("keyframe:%d coder:%d\n", p->key_frame, f->ac);
-
- if(!f->ac){
- bytes_read = get_cabac_terminate(c);
- if(bytes_read ==0) printf("error at end of AC stream\n");
-//printf("pos=%d\n", bytes_read);
- init_get_bits(&f->gb, buf + bytes_read, buf_size - bytes_read);
- } else {
- bytes_read = 0; /* avoid warning */
- }
-
- if(1){
- const int chroma_width = -((-width )>>f->chroma_h_shift);
- const int chroma_height= -((-height)>>f->chroma_v_shift);
- decode_plane(f, p->data[0], width, height, p->linesize[0], 0);
-
- decode_plane(f, p->data[1], chroma_width, chroma_height, p->linesize[1], 1);
- decode_plane(f, p->data[2], chroma_width, chroma_height, p->linesize[2], 1);
- }
-
- emms_c();
-
- f->picture_number++;
-
- *picture= *p;
-
- avctx->release_buffer(avctx, p); //FIXME
-
- *data_size = sizeof(AVFrame);
-
- if(f->ac){
- bytes_read= get_cabac_terminate(c);
- if(bytes_read ==0) printf("error at end of frame\n");
- }else{
- bytes_read+= (get_bits_count(&f->gb)+7)/8;
- }
-
- return bytes_read;
-}
-
-static int decode_end(AVCodecContext *avctx)
-{
- FFV1Context *s = avctx->priv_data;
- int i;
-
- if(avctx->get_buffer == avcodec_default_get_buffer){
- for(i=0; i<4; i++){
- av_freep(&s->picture.base[i]);
- s->picture.data[i]= NULL;
- }
- av_freep(&s->picture.opaque);
- }
-
- return 0;
-}
-
-AVCodec ffv1_decoder = {
- "ffv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FFV1,
- sizeof(FFV1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec ffv1_encoder = {
- "ffv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FFV1,
- sizeof(FFV1Context),
- encode_init,
- encode_frame,
- encode_end,
-};
-#endif
+++ /dev/null
-/*
- * exp golomb vlc stuff
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file golomb.c
- * @brief
- * exp golomb vlc stuff
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include <inttypes.h>
-
-const uint8_t ff_golomb_vlc_len[512]={
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
-7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
-5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
-5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
-};
-
-const uint8_t ff_ue_golomb_vlc_code[512]={
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
- 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-const int8_t ff_se_golomb_vlc_code[512]={
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, -8, 9, -9, 10,-10, 11,-11, 12,-12, 13,-13, 14,-14, 15,-15,
- 4, 4, 4, 4, -4, -4, -4, -4, 5, 5, 5, 5, -5, -5, -5, -5, 6, 6, 6, 6, -6, -6, -6, -6, 7, 7, 7, 7, -7, -7, -7, -7,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-
-const uint8_t ff_ue_golomb_len[256]={
- 1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
-11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,13,
-13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
-13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,15,
-15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
-15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
-15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
-15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,
-};
-
-const uint8_t ff_interleaved_golomb_vlc_len[256]={
-9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
-9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
-9,9,7,7,9,9,7,7,5,5,5,5,5,5,5,5,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-};
-
-const uint8_t ff_interleaved_ue_golomb_vlc_code[256]={
- 15,16,7, 7, 17,18,8, 8, 3, 3, 3, 3, 3, 3, 3, 3,
- 19,20,9, 9, 21,22,10,10,4, 4, 4, 4, 4, 4, 4, 4,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 23,24,11,11,25,26,12,12,5, 5, 5, 5, 5, 5, 5, 5,
- 27,28,13,13,29,30,14,14,6, 6, 6, 6, 6, 6, 6, 6,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-const int8_t ff_interleaved_se_golomb_vlc_code[256]={
- 8, -8, 4, 4, 9, -9, -4, -4, 2, 2, 2, 2, 2, 2, 2, 2,
- 10,-10, 5, 5, 11,-11, -5, -5, -2, -2, -2, -2, -2, -2, -2, -2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 12,-12, 6, 6, 13,-13, -6, -6, 3, 3, 3, 3, 3, 3, 3, 3,
- 14,-14, 7, 7, 15,-15, -7, -7, -3, -3, -3, -3, -3, -3, -3, -3,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
+++ /dev/null
-/*
- * exp golomb vlc stuff
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file golomb.h
- * @brief
- * exp golomb vlc stuff
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#define INVALID_VLC 0x80000000
-
-extern const uint8_t ff_golomb_vlc_len[512];
-extern const uint8_t ff_ue_golomb_vlc_code[512];
-extern const int8_t ff_se_golomb_vlc_code[512];
-extern const uint8_t ff_ue_golomb_len[256];
-
-extern const uint8_t ff_interleaved_golomb_vlc_len[256];
-extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256];
-extern const int8_t ff_interleaved_se_golomb_vlc_code[256];
-
-
- /**
- * read unsigned exp golomb code.
- */
-static inline int get_ue_golomb(GetBitContext *gb){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- if(buf >= (1<<27)){
- buf >>= 32 - 9;
- LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
- CLOSE_READER(re, gb);
-
- return ff_ue_golomb_vlc_code[buf];
- }else{
- log= 2*av_log2(buf) - 31;
- buf>>= log;
- buf--;
- LAST_SKIP_BITS(re, gb, 32 - log);
- CLOSE_READER(re, gb);
-
- return buf;
- }
-}
-
-static inline int svq3_get_ue_golomb(GetBitContext *gb){
- uint32_t buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- if(buf&0xAA800000){
- buf >>= 32 - 8;
- LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
- CLOSE_READER(re, gb);
-
- return ff_interleaved_ue_golomb_vlc_code[buf];
- }else{
- buf|=1;
- if((buf & 0xAAAAAAAA) == 0)
- return INVALID_VLC;
-
- for(log=31; (buf & 0x80000000) == 0; log--){
- buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
- }
-
- LAST_SKIP_BITS(re, gb, 63 - 2*log);
- CLOSE_READER(re, gb);
-
- return ((buf << log) >> log) - 1;
- }
-}
-
-/**
- * read unsigned truncated exp golomb code.
- */
-static inline int get_te0_golomb(GetBitContext *gb, int range){
- assert(range >= 1);
-
- if(range==1) return 0;
- else if(range==2) return get_bits1(gb)^1;
- else return get_ue_golomb(gb);
-}
-
-/**
- * read unsigned truncated exp golomb code.
- */
-static inline int get_te_golomb(GetBitContext *gb, int range){
- assert(range >= 1);
-
- if(range==2) return get_bits1(gb)^1;
- else return get_ue_golomb(gb);
-}
-
-
-/**
- * read signed exp golomb code.
- */
-static inline int get_se_golomb(GetBitContext *gb){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- if(buf >= (1<<27)){
- buf >>= 32 - 9;
- LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
- CLOSE_READER(re, gb);
-
- return ff_se_golomb_vlc_code[buf];
- }else{
- log= 2*av_log2(buf) - 31;
- buf>>= log;
-
- LAST_SKIP_BITS(re, gb, 32 - log);
- CLOSE_READER(re, gb);
-
- if(buf&1) buf= -(buf>>1);
- else buf= (buf>>1);
-
- return buf;
- }
-}
-
-static inline int svq3_get_se_golomb(GetBitContext *gb){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- if(buf&0xAA800000){
- buf >>= 32 - 8;
- LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
- CLOSE_READER(re, gb);
-
- return ff_interleaved_se_golomb_vlc_code[buf];
- }else{
- buf |=1;
- if((buf & 0xAAAAAAAA) == 0)
- return INVALID_VLC;
-
- for(log=31; (buf & 0x80000000) == 0; log--){
- buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
- }
-
- LAST_SKIP_BITS(re, gb, 63 - 2*log);
- CLOSE_READER(re, gb);
-
- return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1;
- }
-}
-
-/**
- * read unsigned golomb rice code (ffv1).
- */
-static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- log= av_log2(buf);
-
- if(log > 31-limit){
- buf >>= log - k;
- buf += (30-log)<<k;
- LAST_SKIP_BITS(re, gb, 32 + k - log);
- CLOSE_READER(re, gb);
-
- return buf;
- }else{
- buf >>= 32 - limit - esc_len;
- LAST_SKIP_BITS(re, gb, esc_len + limit);
- CLOSE_READER(re, gb);
-
- return buf + limit - 1;
- }
-}
-
-/**
- * read unsigned golomb rice code (jpegls).
- */
-static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- log= av_log2(buf);
-
- if(log > 31-11){
- buf >>= log - k;
- buf += (30-log)<<k;
- LAST_SKIP_BITS(re, gb, 32 + k - log);
- CLOSE_READER(re, gb);
-
- return buf;
- }else{
- int i;
- for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){
- LAST_SKIP_BITS(re, gb, 1);
- UPDATE_CACHE(re, gb);
- }
- SKIP_BITS(re, gb, 1);
-
- if(i < limit - 1){
- if(k){
- buf = SHOW_UBITS(re, gb, k);
- LAST_SKIP_BITS(re, gb, k);
- }else{
- buf=0;
- }
-
- CLOSE_READER(re, gb);
- return buf + (i<<k);
- }else if(i == limit - 1){
- buf = SHOW_UBITS(re, gb, esc_len);
- LAST_SKIP_BITS(re, gb, esc_len);
- CLOSE_READER(re, gb);
-
- return buf + 1;
- }else
- return -1;
- }
-}
-
-#ifdef TRACE
-
-static inline int get_ue(GetBitContext *s, char *file, char *func, int line){
- int show= show_bits(s, 24);
- int pos= get_bits_count(s);
- int i= get_ue_golomb(s);
- int len= get_bits_count(s) - pos;
- int bits= show>>(24-len);
-
- print_bin(bits, len);
-
- printf("%5d %2d %3d ue @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
-
- return i;
-}
-
-static inline int get_se(GetBitContext *s, char *file, char *func, int line){
- int show= show_bits(s, 24);
- int pos= get_bits_count(s);
- int i= get_se_golomb(s);
- int len= get_bits_count(s) - pos;
- int bits= show>>(24-len);
-
- print_bin(bits, len);
-
- printf("%5d %2d %3d se @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
-
- return i;
-}
-
-static inline int get_te(GetBitContext *s, int r, char *file, char *func, int line){
- int show= show_bits(s, 24);
- int pos= get_bits_count(s);
- int i= get_te0_golomb(s, r);
- int len= get_bits_count(s) - pos;
- int bits= show>>(24-len);
-
- print_bin(bits, len);
-
- printf("%5d %2d %3d te @%5d in %s %s:%d\n", bits, len, i, pos, file, func, line);
-
- return i;
-}
-
-#define get_ue_golomb(a) get_ue(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_se_golomb(a) get_se(a, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_te_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-#define get_te0_golomb(a, r) get_te(a, r, __FILE__, __PRETTY_FUNCTION__, __LINE__)
-
-#endif
-
-/**
- * write unsigned exp golomb code.
- */
-static inline void set_ue_golomb(PutBitContext *pb, int i){
- int e;
-
- assert(i>=0);
-
-#if 0
- if(i=0){
- put_bits(pb, 1, 1);
- return;
- }
-#endif
- if(i<256)
- put_bits(pb, ff_ue_golomb_len[i], i+1);
- else{
- e= av_log2(i+1);
-
- put_bits(pb, 2*e+1, i+1);
- }
-}
-
-/**
- * write truncated unsigned exp golomb code.
- */
-static inline void set_te_golomb(PutBitContext *pb, int i, int range){
- assert(range >= 1);
- assert(i<=range);
-
- if(range==2) put_bits(pb, 1, i^1);
- else set_ue_golomb(pb, i);
-}
-
-/**
- * write signed exp golomb code.
- */
-static inline void set_se_golomb(PutBitContext *pb, int i){
-#if 0
- if(i<=0) i= -2*i;
- else i= 2*i-1;
-#elif 1
- i= 2*i-1;
- if(i<0) i^= -1; //FIXME check if gcc does the right thing
-#else
- i= 2*i-1;
- i^= (i>>31);
-#endif
- set_ue_golomb(pb, i);
-}
-
-/**
- * write unsigned golomb rice code (ffv1).
- */
-static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit, int esc_len){
- int e;
-
- assert(i>=0);
-
- e= i>>k;
- if(e<limit){
- put_bits(pb, e + k + 1, (1<<k) + (i&((1<<k)-1)));
- }else{
- put_bits(pb, limit + esc_len, i - limit + 1);
- }
-}
-
-/**
- * write unsigned golomb rice code (jpegls).
- */
-static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k, int limit, int esc_len){
- int e;
-
- assert(i>=0);
-
- e= (i>>k) + 1;
- if(e<limit){
- put_bits(pb, e, 1);
- if(k)
- put_bits(pb, k, i&((1<<k)-1));
- }else{
- put_bits(pb, limit , 1);
- put_bits(pb, esc_len, i - 1);
- }
-}
+++ /dev/null
-/*
- * H263/MPEG4 backend for ffmpeg encoder and decoder
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * H263+ support.
- * Copyright (c) 2001 Juan J. Sierralta P.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * ac prediction encoding, b-frame support, error resilience, optimizations,
- * qpel decoding, gmc decoding, interlaced decoding,
- * by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file h263.c
- * h263/mpeg4 codec.
- */
-
-//#define DEBUG
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "h263data.h"
-#include "mpeg4data.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#define INTRA_MCBPC_VLC_BITS 6
-#define INTER_MCBPC_VLC_BITS 7
-#define CBPY_VLC_BITS 6
-#define MV_VLC_BITS 9
-#define DC_VLC_BITS 9
-#define SPRITE_TRAJ_VLC_BITS 6
-#define MB_TYPE_B_VLC_BITS 4
-#define TEX_VLC_BITS 9
-
-#ifdef CONFIG_ENCODERS
-static void h263_encode_block(MpegEncContext * s, DCTELEM * block,
- int n);
-static void h263_encode_motion(MpegEncContext * s, int val, int fcode);
-static void h263p_encode_umotion(MpegEncContext * s, int val);
-static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block,
- int n, int dc, uint8_t *scan_table,
- PutBitContext *dc_pb, PutBitContext *ac_pb);
-#endif
-
-static int h263_decode_motion(MpegEncContext * s, int pred, int fcode);
-static int h263p_decode_umotion(MpegEncContext * s, int pred);
-static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded);
-static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
-static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, int intra, int rvlc);
-static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr);
-#ifdef CONFIG_ENCODERS
-static void mpeg4_inv_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
- int dir);
-static void mpeg4_encode_visual_object_header(MpegEncContext * s);
-static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number);
-#endif //CONFIG_ENCODERS
-static void mpeg4_decode_sprite_trajectory(MpegEncContext * s);
-static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr, int *dir_ptr);
-
-#ifdef CONFIG_ENCODERS
-static uint8_t uni_DCtab_lum_len[512];
-static uint8_t uni_DCtab_chrom_len[512];
-static uint16_t uni_DCtab_lum_bits[512];
-static uint16_t uni_DCtab_chrom_bits[512];
-
-static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL;
-static uint8_t fcode_tab[MAX_MV*2+1];
-static uint8_t umv_fcode_tab[MAX_MV*2+1];
-
-static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2];
-static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2];
-static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2];
-static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2];
-//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
-//#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
-#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
-
-/* mpeg4
-inter
-max level: 24/6
-max run: 53/63
-
-intra
-max level: 53/16
-max run: 29/41
-*/
-#endif
-
-#if 0 //3IV1 is quite rare and tis slows things down a tiny bit
-#define IS_3IV1 s->avctx->codec_tag == ff_get_fourcc("3IV1")
-#else
-#define IS_3IV1 0
-#endif
-
-int h263_get_picture_format(int width, int height)
-{
- int format;
-
- if (width == 128 && height == 96)
- format = 1;
- else if (width == 176 && height == 144)
- format = 2;
- else if (width == 352 && height == 288)
- format = 3;
- else if (width == 704 && height == 576)
- format = 4;
- else if (width == 1408 && height == 1152)
- format = 5;
- else
- format = 7;
- return format;
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void float_aspect_to_info(MpegEncContext * s, float aspect){
- int i;
-
- aspect*= s->height/(double)s->width;
-//printf("%f\n", aspect);
-
- if(aspect==0) aspect= 1.0;
-
- ff_float2fraction(&s->aspected_width, &s->aspected_height, aspect, 255);
-
-//printf("%d %d\n", s->aspected_width, s->aspected_height);
- for(i=1; i<6; i++){
- if(s->aspected_width == pixel_aspect[i][0] && s->aspected_height== pixel_aspect[i][1]){
- s->aspect_ratio_info=i;
- return;
- }
- }
-
- s->aspect_ratio_info= FF_ASPECT_EXTENDED;
-}
-
-void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- int format;
-
- align_put_bits(&s->pb);
-
- put_bits(&s->pb, 17, 1);
- put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
- put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->frame_rate_base) /
- s->avctx->frame_rate) & 0xff); /* TemporalReference */
- if (s->width == 352 && s->height == 288)
- format = 2;
- else if (s->width == 176 && s->height == 144)
- format = 3;
- else if (s->width == 128 && s->height == 96)
- format = 4;
- else if (s->width == 320 && s->height == 240)
- format = 5;
- else if (s->width == 160 && s->height == 120)
- format = 6;
- else if (s->width <= 255 && s->height <= 255)
- format = 0; /* use 1 byte width & height */
- else
- format = 1; /* use 2 bytes width & height */
- put_bits(&s->pb, 3, format); /* PictureSize */
- if (format == 0) {
- put_bits(&s->pb, 8, s->width);
- put_bits(&s->pb, 8, s->height);
- } else if (format == 1) {
- put_bits(&s->pb, 16, s->width);
- put_bits(&s->pb, 16, s->height);
- }
- put_bits(&s->pb, 2, s->pict_type == P_TYPE); /* PictureType */
- put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */
- put_bits(&s->pb, 5, s->qscale); /* Quantizer */
- put_bits(&s->pb, 1, 0); /* ExtraInformation */
-
- if(s->h263_aic){
- s->y_dc_scale_table=
- s->c_dc_scale_table= h263_aic_dc_scale_table;
- }else{
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- }
-}
-
-void h263_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- int format;
-
- align_put_bits(&s->pb);
-
- /* Update the pointer to last GOB */
- s->ptr_lastgob = pbBufPtr(&s->pb);
- s->gob_number = 0;
-
- put_bits(&s->pb, 22, 0x20); /* PSC */
- put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->frame_rate_base) /
- s->avctx->frame_rate) & 0xff);
-
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 1, 0); /* h263 id */
- put_bits(&s->pb, 1, 0); /* split screen off */
- put_bits(&s->pb, 1, 0); /* camera off */
- put_bits(&s->pb, 1, 0); /* freeze picture release off */
-
- format = h263_get_picture_format(s->width, s->height);
- if (!s->h263_plus) {
- /* H.263v1 */
- put_bits(&s->pb, 3, format);
- put_bits(&s->pb, 1, (s->pict_type == P_TYPE));
- /* By now UMV IS DISABLED ON H.263v1, since the restrictions
- of H.263v1 UMV implies to check the predicted MV after
- calculation of the current MB to see if we're on the limits */
- put_bits(&s->pb, 1, 0); /* unrestricted motion vector: off */
- put_bits(&s->pb, 1, 0); /* SAC: off */
- put_bits(&s->pb, 1, 0); /* advanced prediction mode: off */
- put_bits(&s->pb, 1, 0); /* not PB frame */
- put_bits(&s->pb, 5, s->qscale);
- put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
- } else {
- /* H.263v2 */
- /* H.263 Plus PTYPE */
- put_bits(&s->pb, 3, 7);
- put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */
- if (format == 7)
- put_bits(&s->pb,3,6); /* Custom Source Format */
- else
- put_bits(&s->pb, 3, format);
-
- put_bits(&s->pb,1,0); /* Custom PCF: off */
- s->umvplus = s->unrestricted_mv;
- put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */
- put_bits(&s->pb,1,0); /* SAC: off */
- put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */
- put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
- put_bits(&s->pb,1,0); /* Deblocking Filter: off */
- put_bits(&s->pb,1,0); /* Slice Structured: off */
- put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
- put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
- put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */
- put_bits(&s->pb,1,0); /* Modified Quantization: off */
- put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
- put_bits(&s->pb,3,0); /* Reserved */
-
- put_bits(&s->pb, 3, s->pict_type == P_TYPE);
-
- put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */
- put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */
- put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */
- put_bits(&s->pb,2,0); /* Reserved */
- put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
-
- /* This should be here if PLUSPTYPE */
- put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
-
- if (format == 7) {
- /* Custom Picture Format (CPFMT) */
- float_aspect_to_info(s, s->avctx->aspect_ratio);
-
- put_bits(&s->pb,4,s->aspect_ratio_info);
- put_bits(&s->pb,9,(s->width >> 2) - 1);
- put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
- put_bits(&s->pb,9,(s->height >> 2));
- if (s->aspect_ratio_info == FF_ASPECT_EXTENDED)
- {
- put_bits(&s->pb, 8, s->aspected_width);
- put_bits(&s->pb, 8, s->aspected_height);
- }
- }
-
- /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
- if (s->umvplus)
-// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
- put_bits(&s->pb,2,1); /* unlimited */
-
- put_bits(&s->pb, 5, s->qscale);
- }
-
- put_bits(&s->pb, 1, 0); /* no PEI */
-
- if(s->h263_aic){
- s->y_dc_scale_table=
- s->c_dc_scale_table= h263_aic_dc_scale_table;
- }else{
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- }
-}
-
-/**
- * Encodes a group of blocks header.
- */
-int h263_encode_gob_header(MpegEncContext * s, int mb_line)
-{
- align_put_bits(&s->pb);
- flush_put_bits(&s->pb);
- /* Call the RTP callback to send the last GOB */
- if (s->rtp_callback) {
- int pdif = pbBufPtr(&s->pb) - s->ptr_lastgob;
- s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number);
- }
- put_bits(&s->pb, 17, 1); /* GBSC */
- s->gob_number = mb_line / s->gob_index;
- put_bits(&s->pb, 5, s->gob_number); /* GN */
- put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */
- put_bits(&s->pb, 5, s->qscale); /* GQUANT */
- //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif);
- return 0;
-}
-
-static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6])
-{
- int score0=0, score1=0;
- int i, n;
- int8_t * const qscale_table= s->current_picture.qscale_table;
-
- for(n=0; n<6; n++){
- int16_t *ac_val, *ac_val1;
-
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val1= ac_val;
- if(dir[n]){
- const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
- /* top prediction */
- ac_val-= s->block_wrap[n]*16;
- if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
- /* same qscale */
- for(i=1; i<8; i++){
- const int level= block[n][s->dsp.idct_permutation[i ]];
- score0+= ABS(level);
- score1+= ABS(level - ac_val[i+8]);
- ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
- ac_val1[i+8]= level;
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1; i<8; i++){
- const int level= block[n][s->dsp.idct_permutation[i ]];
- score0+= ABS(level);
- score1+= ABS(level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale));
- ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
- ac_val1[i+8]= level;
- }
- }
- }else{
- const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
- /* left prediction */
- ac_val-= 16;
- if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
- /* same qscale */
- for(i=1; i<8; i++){
- const int level= block[n][s->dsp.idct_permutation[i<<3]];
- score0+= ABS(level);
- score1+= ABS(level - ac_val[i]);
- ac_val1[i ]= level;
- ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1; i<8; i++){
- const int level= block[n][s->dsp.idct_permutation[i<<3]];
- score0+= ABS(level);
- score1+= ABS(level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale));
- ac_val1[i ]= level;
- ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
- }
- }
- }
- }
-
- return score0 > score1 ? 1 : 0;
-}
-
-/**
- * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2)
- */
-void ff_clean_h263_qscales(MpegEncContext *s){
- int i;
- int8_t * const qscale_table= s->current_picture.qscale_table;
-
- for(i=1; i<s->mb_num; i++){
- if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2)
- qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2;
- }
- for(i=s->mb_num-2; i>=0; i--){
- if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2)
- qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2;
- }
-}
-
-/**
- * modify mb_type & qscale so that encoding is acually possible in mpeg4
- */
-void ff_clean_mpeg4_qscales(MpegEncContext *s){
- int i;
- int8_t * const qscale_table= s->current_picture.qscale_table;
-
- ff_clean_h263_qscales(s);
-
- for(i=1; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
-
- if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&MB_TYPE_INTER4V)){
- s->mb_type[mb_xy]&= ~MB_TYPE_INTER4V;
- s->mb_type[mb_xy]|= MB_TYPE_INTER;
- }
- }
-
- if(s->pict_type== B_TYPE){
- int odd=0;
- /* ok, come on, this isnt funny anymore, theres more code for handling this mpeg4 mess than
- for the actual adaptive quantization */
-
- for(i=0; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
- odd += qscale_table[mb_xy]&1;
- }
-
- if(2*odd > s->mb_num) odd=1;
- else odd=0;
-
- for(i=0; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
- if((qscale_table[mb_xy]&1) != odd)
- qscale_table[mb_xy]++;
- if(qscale_table[mb_xy] > 31)
- qscale_table[mb_xy]= 31;
- }
-
- for(i=1; i<s->mb_num; i++){
- int mb_xy= s->mb_index2xy[i];
- if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&MB_TYPE_DIRECT)){
- s->mb_type[mb_xy]&= ~MB_TYPE_DIRECT;
- s->mb_type[mb_xy]|= MB_TYPE_BIDIR;
- }
- }
- }
-}
-
-#endif //CONFIG_ENCODERS
-/**
- *
- * @return the mb_type
- */
-int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
- const int mb_index= s->mb_x + s->mb_y*s->mb_stride;
- const int colocated_mb_type= s->next_picture.mb_type[mb_index]; //FIXME or next?
- int xy= s->block_index[0];
- uint16_t time_pp= s->pp_time;
- uint16_t time_pb= s->pb_time;
- int i;
-
- //FIXME avoid divides
-
- if(IS_8X8(colocated_mb_type)){
- s->mv_type = MV_TYPE_8X8;
- for(i=0; i<4; i++){
- xy= s->block_index[i];
- s->mv[0][i][0] = s->motion_val[xy][0]*time_pb/time_pp + mx;
- s->mv[0][i][1] = s->motion_val[xy][1]*time_pb/time_pp + my;
- s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->motion_val[xy][0]
- : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][i][1] = my ? s->mv[0][i][1] - s->motion_val[xy][1]
- : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
- }
- return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
- } else if(IS_INTERLACED(colocated_mb_type)){
- s->mv_type = MV_TYPE_FIELD;
- for(i=0; i<2; i++){
- if(s->top_field_first){
- time_pp= s->pp_field_time - s->field_select_table[mb_index][i] + i;
- time_pb= s->pb_field_time - s->field_select_table[mb_index][i] + i;
- }else{
- time_pp= s->pp_field_time + s->field_select_table[mb_index][i] - i;
- time_pb= s->pb_field_time + s->field_select_table[mb_index][i] - i;
- }
- s->mv[0][i][0] = s->field_mv_table[mb_index][i][0]*time_pb/time_pp + mx;
- s->mv[0][i][1] = s->field_mv_table[mb_index][i][1]*time_pb/time_pp + my;
- s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->field_mv_table[mb_index][i][0]
- : s->field_mv_table[mb_index][i][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][i][1] = my ? s->mv[0][i][1] - s->field_mv_table[mb_index][i][1]
- : s->field_mv_table[mb_index][i][1]*(time_pb - time_pp)/time_pp;
- }
- return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
- }else{
- s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->motion_val[xy][0]*time_pb/time_pp + mx;
- s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->motion_val[xy][1]*time_pb/time_pp + my;
- s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0]
- : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
- s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1]
- : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
- if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
- s->mv_type= MV_TYPE_16X16;
- else
- s->mv_type= MV_TYPE_8X8;
- return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line
- }
-}
-
-void ff_h263_update_motion_val(MpegEncContext * s){
- const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
- //FIXME a lot of thet is only needed for !low_delay
- const int wrap = s->block_wrap[0];
- const int xy = s->block_index[0];
-
- s->current_picture.mbskip_table[mb_xy]= s->mb_skiped;
-
- if(s->mv_type != MV_TYPE_8X8){
- int motion_x, motion_y;
- if (s->mb_intra) {
- motion_x = 0;
- motion_y = 0;
- } else if (s->mv_type == MV_TYPE_16X16) {
- motion_x = s->mv[0][0][0];
- motion_y = s->mv[0][0][1];
- } else /*if (s->mv_type == MV_TYPE_FIELD)*/ {
- int i;
- motion_x = s->mv[0][0][0] + s->mv[0][1][0];
- motion_y = s->mv[0][0][1] + s->mv[0][1][1];
- motion_x = (motion_x>>1) | (motion_x&1);
- for(i=0; i<2; i++){
- s->field_mv_table[mb_xy][i][0]= s->mv[0][i][0];
- s->field_mv_table[mb_xy][i][1]= s->mv[0][i][1];
- s->field_select_table[mb_xy][i]= s->field_select[0][i];
- }
- }
-
- /* no update if 8X8 because it has been done during parsing */
- s->motion_val[xy][0] = motion_x;
- s->motion_val[xy][1] = motion_y;
- s->motion_val[xy + 1][0] = motion_x;
- s->motion_val[xy + 1][1] = motion_y;
- s->motion_val[xy + wrap][0] = motion_x;
- s->motion_val[xy + wrap][1] = motion_y;
- s->motion_val[xy + 1 + wrap][0] = motion_x;
- s->motion_val[xy + 1 + wrap][1] = motion_y;
- }
-
- if(s->encoding){ //FIXME encoding MUST be cleaned up
- if (s->mv_type == MV_TYPE_8X8)
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8;
- else
- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-void mpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int cbpc, cbpy, pred_x, pred_y;
- PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
- PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=B_TYPE ? &s->tex_pb : &s->pb;
- PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=I_TYPE ? &s->pb2 : &s->pb;
- const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
- const int dquant_code[5]= {1,0,9,2,3};
-
- // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
- if (!s->mb_intra) {
- /* compute cbp */
- int i, cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
-
- if(s->pict_type==B_TYPE){
- static const int mb_type_table[8]= {-1, 2, 3, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
- int mb_type= mb_type_table[s->mv_dir];
-
- if(s->mb_x==0){
- s->last_mv[0][0][0]=
- s->last_mv[0][0][1]=
- s->last_mv[1][0][0]=
- s->last_mv[1][0][1]= 0;
- }
-
- assert(s->dquant>=-2 && s->dquant<=2);
- assert((s->dquant&1)==0);
- assert(mb_type>=0);
-
- /* nothing to do if this MB was skiped in the next P Frame */
- if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ...
- s->skip_count++;
- s->mv[0][0][0]=
- s->mv[0][0][1]=
- s->mv[1][0][0]=
- s->mv[1][0][1]= 0;
- s->mv_dir= MV_DIR_FORWARD; //doesnt matter
- s->qscale -= s->dquant;
-// s->mb_skiped=1;
-
- return;
- }
-
- if ((cbp | motion_x | motion_y | mb_type) ==0) {
- /* direct MB with MV={0,0} */
- assert(s->dquant==0);
-
- put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */
-
- if(interleaved_stats){
- s->misc_bits++;
- s->last_bits++;
- }
- s->skip_count++;
- return;
- }
-
- put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
- put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge
- put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we dont need it :)
- if(cbp) put_bits(&s->pb, 6, cbp);
-
- if(cbp && mb_type){
- if(s->dquant)
- put_bits(&s->pb, 2, (s->dquant>>2)+3);
- else
- put_bits(&s->pb, 1, 0);
- }else
- s->qscale -= s->dquant;
-
- if(!s->progressive_sequence){
- if(cbp)
- put_bits(&s->pb, 1, s->interlaced_dct);
- if(mb_type) // not diect mode
- put_bits(&s->pb, 1, 0); // no interlaced ME yet
- }
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
-
- switch(mb_type)
- {
- case 0: /* direct */
- h263_encode_motion(s, motion_x, 1);
- h263_encode_motion(s, motion_y, 1);
- s->b_count++;
- s->f_count++;
- break;
- case 1: /* bidir */
- h263_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
- h263_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
- h263_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
- h263_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
- s->last_mv[0][0][0]= s->mv[0][0][0];
- s->last_mv[0][0][1]= s->mv[0][0][1];
- s->last_mv[1][0][0]= s->mv[1][0][0];
- s->last_mv[1][0][1]= s->mv[1][0][1];
- s->b_count++;
- s->f_count++;
- break;
- case 2: /* backward */
- h263_encode_motion(s, motion_x - s->last_mv[1][0][0], s->b_code);
- h263_encode_motion(s, motion_y - s->last_mv[1][0][1], s->b_code);
- s->last_mv[1][0][0]= motion_x;
- s->last_mv[1][0][1]= motion_y;
- s->b_count++;
- break;
- case 3: /* forward */
- h263_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code);
- h263_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code);
- s->last_mv[0][0][0]= motion_x;
- s->last_mv[0][0][1]= motion_y;
- s->f_count++;
- break;
- default:
- printf("unknown mb type\n");
- return;
- }
-
- if(interleaved_stats){
- s->mv_bits+= get_bits_diff(s);
- }
-
- /* encode each block */
- for (i = 0; i < 6; i++) {
- mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, NULL, &s->pb);
- }
-
- if(interleaved_stats){
- s->p_tex_bits+= get_bits_diff(s);
- }
- }else{ /* s->pict_type==B_TYPE */
- if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) {
- /* check if the B frames can skip it too, as we must skip it if we skip here
- why didnt they just compress the skip-mb bits instead of reusing them ?! */
- if(s->max_b_frames>0){
- int i;
- int x,y, offset;
- uint8_t *p_pic;
-
- x= s->mb_x*16;
- y= s->mb_y*16;
- if(x+16 > s->width) x= s->width-16;
- if(y+16 > s->height) y= s->height-16;
-
- offset= x + y*s->linesize;
- p_pic= s->new_picture.data[0] + offset;
-
- s->mb_skiped=1;
- for(i=0; i<s->max_b_frames; i++){
- uint8_t *b_pic;
- int diff;
- Picture *pic= s->reordered_input_picture[i+1];
-
- if(pic==NULL || pic->pict_type!=B_TYPE) break;
-
- b_pic= pic->data[0] + offset + 16; //FIXME +16
- diff= s->dsp.pix_abs16x16(p_pic, b_pic, s->linesize);
- if(diff>s->qscale*70){ //FIXME check that 70 is optimal
- s->mb_skiped=0;
- break;
- }
- }
- }else
- s->mb_skiped=1;
-
- if(s->mb_skiped==1){
- /* skip macroblock */
- put_bits(&s->pb, 1, 1);
-
- if(interleaved_stats){
- s->misc_bits++;
- s->last_bits++;
- }
- s->skip_count++;
-
- return;
- }
- }
-
- put_bits(&s->pb, 1, 0); /* mb coded */
- if(s->mv_type==MV_TYPE_16X16){
- cbpc = cbp & 3;
- if(s->dquant) cbpc+= 8;
- put_bits(&s->pb,
- inter_MCBPC_bits[cbpc],
- inter_MCBPC_code[cbpc]);
-
- cbpy = cbp >> 2;
- cbpy ^= 0xf;
- put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
- if(s->dquant)
- put_bits(pb2, 2, dquant_code[s->dquant+2]);
-
- if(!s->progressive_sequence){
- if(cbp)
- put_bits(pb2, 1, s->interlaced_dct);
- put_bits(pb2, 1, 0); // no interlaced ME yet
- }
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
-
- /* motion vectors: 16x16 mode */
- h263_pred_motion(s, 0, &pred_x, &pred_y);
-
- h263_encode_motion(s, motion_x - pred_x, s->f_code);
- h263_encode_motion(s, motion_y - pred_y, s->f_code);
- }else{
- cbpc = (cbp & 3)+16;
- put_bits(&s->pb,
- inter_MCBPC_bits[cbpc],
- inter_MCBPC_code[cbpc]);
- cbpy = cbp >> 2;
- cbpy ^= 0xf;
- put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
-
- if(!s->progressive_sequence){
- if(cbp)
- put_bits(pb2, 1, s->interlaced_dct);
- }
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
-
- for(i=0; i<4; i++){
- /* motion vectors: 8x8 mode*/
- h263_pred_motion(s, i, &pred_x, &pred_y);
-
- h263_encode_motion(s, s->motion_val[ s->block_index[i] ][0] - pred_x, s->f_code);
- h263_encode_motion(s, s->motion_val[ s->block_index[i] ][1] - pred_y, s->f_code);
- }
- }
-
- if(interleaved_stats){
- s->mv_bits+= get_bits_diff(s);
- }
-
- /* encode each block */
- for (i = 0; i < 6; i++) {
- mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, NULL, tex_pb);
- }
-
- if(interleaved_stats){
- s->p_tex_bits+= get_bits_diff(s);
- }
- s->f_count++;
- }
- } else {
- int cbp;
- int dc_diff[6]; //dc values with the dc prediction subtracted
- int dir[6]; //prediction direction
- int zigzag_last_index[6];
- uint8_t *scan_table[6];
- int i;
-
- for(i=0; i<6; i++){
- const int level= block[i][0];
- uint16_t *dc_ptr;
-
- dc_diff[i]= level - ff_mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]);
- if (i < 4) {
- *dc_ptr = level * s->y_dc_scale;
- } else {
- *dc_ptr = level * s->c_dc_scale;
- }
- }
-
- s->ac_pred= decide_ac_pred(s, block, dir);
-
- if(s->ac_pred){
- for(i=0; i<6; i++){
- uint8_t *st;
- int last_index;
-
- mpeg4_inv_pred_ac(s, block[i], i, dir[i]);
- if (dir[i]==0) st = s->intra_v_scantable.permutated; /* left */
- else st = s->intra_h_scantable.permutated; /* top */
-
- for(last_index=63; last_index>=0; last_index--) //FIXME optimize
- if(block[i][st[last_index]]) break;
- zigzag_last_index[i]= s->block_last_index[i];
- s->block_last_index[i]= last_index;
- scan_table[i]= st;
- }
- }else{
- for(i=0; i<6; i++)
- scan_table[i]= s->intra_scantable.permutated;
- }
-
- /* compute cbp */
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 1)
- cbp |= 1 << (5 - i);
- }
-
- cbpc = cbp & 3;
- if (s->pict_type == I_TYPE) {
- if(s->dquant) cbpc+=4;
- put_bits(&s->pb,
- intra_MCBPC_bits[cbpc],
- intra_MCBPC_code[cbpc]);
- } else {
- if(s->dquant) cbpc+=8;
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- inter_MCBPC_bits[cbpc + 4],
- inter_MCBPC_code[cbpc + 4]);
- }
- put_bits(pb2, 1, s->ac_pred);
- cbpy = cbp >> 2;
- put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
- if(s->dquant)
- put_bits(dc_pb, 2, dquant_code[s->dquant+2]);
-
- if(!s->progressive_sequence){
- put_bits(dc_pb, 1, s->interlaced_dct);
- }
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
-
- /* encode each block */
- for (i = 0; i < 6; i++) {
- mpeg4_encode_block(s, block[i], i, dc_diff[i], scan_table[i], dc_pb, tex_pb);
- }
-
- if(interleaved_stats){
- s->i_tex_bits+= get_bits_diff(s);
- }
- s->i_count++;
-
- /* restore ac coeffs & last_index stuff if we messed them up with the prediction */
- if(s->ac_pred){
- for(i=0; i<6; i++){
- int j;
- int16_t *ac_val;
-
- ac_val = s->ac_val[0][0] + s->block_index[i] * 16;
-
- if(dir[i]){
- for(j=1; j<8; j++)
- block[i][s->dsp.idct_permutation[j ]]= ac_val[j+8];
- }else{
- for(j=1; j<8; j++)
- block[i][s->dsp.idct_permutation[j<<3]]= ac_val[j ];
- }
- s->block_last_index[i]= zigzag_last_index[i];
- }
- }
- }
-}
-
-void h263_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int cbpc, cbpy, i, cbp, pred_x, pred_y;
- int16_t pred_dc;
- int16_t rec_intradc[6];
- uint16_t *dc_ptr[6];
- const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);
- const int dquant_code[5]= {1,0,9,2,3};
-
- //printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
- if (!s->mb_intra) {
- /* compute cbp */
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- if ((cbp | motion_x | motion_y | s->dquant) == 0) {
- /* skip macroblock */
- put_bits(&s->pb, 1, 1);
- if(interleaved_stats){
- s->misc_bits++;
- s->last_bits++;
- }
- return;
- }
- put_bits(&s->pb, 1, 0); /* mb coded */
- cbpc = cbp & 3;
- if(s->dquant) cbpc+= 8;
- put_bits(&s->pb,
- inter_MCBPC_bits[cbpc],
- inter_MCBPC_code[cbpc]);
- cbpy = cbp >> 2;
- cbpy ^= 0xf;
- put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
- if(s->dquant)
- put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
-
- /* motion vectors: 16x16 mode only now */
- h263_pred_motion(s, 0, &pred_x, &pred_y);
-
- if (!s->umvplus) {
- h263_encode_motion(s, motion_x - pred_x, s->f_code);
- h263_encode_motion(s, motion_y - pred_y, s->f_code);
- }
- else {
- h263p_encode_umotion(s, motion_x - pred_x);
- h263p_encode_umotion(s, motion_y - pred_y);
- if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
- /* To prevent Start Code emulation */
- put_bits(&s->pb,1,1);
- }
-
- if(interleaved_stats){
- s->mv_bits+= get_bits_diff(s);
- }
- } else {
- int li = s->h263_aic ? 0 : 1;
-
- cbp = 0;
- for(i=0; i<6; i++) {
- /* Predict DC */
- if (s->h263_aic && s->mb_intra) {
- int16_t level = block[i][0];
-
- pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
- level -= pred_dc;
- /* Quant */
- if (level < 0)
- level = (level + (s->qscale >> 1))/(s->y_dc_scale);
- else
- level = (level - (s->qscale >> 1))/(s->y_dc_scale);
-
- /* AIC can change CBP */
- if (level == 0 && s->block_last_index[i] == 0)
- s->block_last_index[i] = -1;
- else if (level < -127)
- level = -127;
- else if (level > 127)
- level = 127;
-
- block[i][0] = level;
- /* Reconstruction */
- rec_intradc[i] = (s->y_dc_scale*level) + pred_dc;
- /* Oddify */
- rec_intradc[i] |= 1;
- //if ((rec_intradc[i] % 2) == 0)
- // rec_intradc[i]++;
- /* Clipping */
- if (rec_intradc[i] < 0)
- rec_intradc[i] = 0;
- else if (rec_intradc[i] > 2047)
- rec_intradc[i] = 2047;
-
- /* Update AC/DC tables */
- *dc_ptr[i] = rec_intradc[i];
- }
- /* compute cbp */
- if (s->block_last_index[i] >= li)
- cbp |= 1 << (5 - i);
- }
-
- cbpc = cbp & 3;
- if (s->pict_type == I_TYPE) {
- if(s->dquant) cbpc+=4;
- put_bits(&s->pb,
- intra_MCBPC_bits[cbpc],
- intra_MCBPC_code[cbpc]);
- } else {
- if(s->dquant) cbpc+=8;
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- inter_MCBPC_bits[cbpc + 4],
- inter_MCBPC_code[cbpc + 4]);
- }
- if (s->h263_aic) {
- /* XXX: currently, we do not try to use ac prediction */
- put_bits(&s->pb, 1, 0); /* no AC prediction */
- }
- cbpy = cbp >> 2;
- put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
- if(s->dquant)
- put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
-
- if(interleaved_stats){
- s->misc_bits+= get_bits_diff(s);
- }
- }
-
- for(i=0; i<6; i++) {
- /* encode each block */
- h263_encode_block(s, block[i], i);
-
- /* Update INTRADC for decoding */
- if (s->h263_aic && s->mb_intra) {
- block[i][0] = rec_intradc[i];
-
- }
- }
-
- if(interleaved_stats){
- if (!s->mb_intra) {
- s->p_tex_bits+= get_bits_diff(s);
- s->f_count++;
- }else{
- s->i_tex_bits+= get_bits_diff(s);
- s->i_count++;
- }
- }
-}
-#endif
-
-static int h263_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr)
-{
- int x, y, wrap, a, c, pred_dc, scale;
- int16_t *dc_val, *ac_val;
-
- /* find prediction */
- if (n < 4) {
- x = 2 * s->mb_x + 1 + (n & 1);
- y = 2 * s->mb_y + 1 + ((n & 2) >> 1);
- wrap = s->mb_width * 2 + 2;
- dc_val = s->dc_val[0];
- ac_val = s->ac_val[0][0];
- scale = s->y_dc_scale;
- } else {
- x = s->mb_x + 1;
- y = s->mb_y + 1;
- wrap = s->mb_width + 2;
- dc_val = s->dc_val[n - 4 + 1];
- ac_val = s->ac_val[n - 4 + 1][0];
- scale = s->c_dc_scale;
- }
- /* B C
- * A X
- */
- a = dc_val[(x - 1) + (y) * wrap];
- c = dc_val[(x) + (y - 1) * wrap];
-
- /* No prediction outside GOB boundary */
- if (s->first_slice_line && ((n < 2) || (n > 3)))
- c = 1024;
- pred_dc = 1024;
- /* just DC prediction */
- if (a != 1024 && c != 1024)
- pred_dc = (a + c) >> 1;
- else if (a != 1024)
- pred_dc = a;
- else
- pred_dc = c;
-
- /* we assume pred is positive */
- //pred_dc = (pred_dc + (scale >> 1)) / scale;
- *dc_val_ptr = &dc_val[x + y * wrap];
- return pred_dc;
-}
-
-static void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n)
-{
- int x, y, wrap, a, c, pred_dc, scale, i;
- int16_t *dc_val, *ac_val, *ac_val1;
-
- /* find prediction */
- if (n < 4) {
- x = 2 * s->mb_x + 1 + (n & 1);
- y = 2 * s->mb_y + 1 + ((n & 2) >> 1);
- wrap = s->mb_width * 2 + 2;
- dc_val = s->dc_val[0];
- ac_val = s->ac_val[0][0];
- scale = s->y_dc_scale;
- } else {
- x = s->mb_x + 1;
- y = s->mb_y + 1;
- wrap = s->mb_width + 2;
- dc_val = s->dc_val[n - 4 + 1];
- ac_val = s->ac_val[n - 4 + 1][0];
- scale = s->c_dc_scale;
- }
-
- ac_val += ((y) * wrap + (x)) * 16;
- ac_val1 = ac_val;
-
- /* B C
- * A X
- */
- a = dc_val[(x - 1) + (y) * wrap];
- c = dc_val[(x) + (y - 1) * wrap];
-
- /* No prediction outside GOB boundary */
- if (s->first_slice_line && ((n < 2) || (n > 3)))
- c = 1024;
- pred_dc = 1024;
- if (s->ac_pred) {
- if (s->h263_aic_dir) {
- /* left prediction */
- if (a != 1024) {
- ac_val -= 16;
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
- }
- pred_dc = a;
- }
- } else {
- /* top prediction */
- if (c != 1024) {
- ac_val -= 16 * wrap;
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i ]] += ac_val[i + 8];
- }
- pred_dc = c;
- }
- }
- } else {
- /* just DC prediction */
- if (a != 1024 && c != 1024)
- pred_dc = (a + c) >> 1;
- else if (a != 1024)
- pred_dc = a;
- else
- pred_dc = c;
- }
-
- /* we assume pred is positive */
- block[0]=block[0]*scale + pred_dc;
-
- if (block[0] < 0)
- block[0] = 0;
- else if (!(block[0] & 1))
- block[0]++;
-
- /* Update AC/DC tables */
- dc_val[(x) + (y) * wrap] = block[0];
-
- /* left copy */
- for(i=1;i<8;i++)
- ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]];
- /* top copy */
- for(i=1;i<8;i++)
- ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]];
-}
-
-int16_t *h263_pred_motion(MpegEncContext * s, int block,
- int *px, int *py)
-{
- int xy, wrap;
- int16_t *A, *B, *C, *mot_val;
- static const int off[4]= {2, 1, 1, -1};
-
- wrap = s->block_wrap[0];
- xy = s->block_index[block];
-
- mot_val = s->motion_val[xy];
-
- A = s->motion_val[xy - 1];
- /* special case for first (slice) line */
- if (s->first_slice_line && block<3) {
- // we cant just change some MVs to simulate that as we need them for the B frames (and ME)
- // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
- if(block==0){ //most common case
- if(s->mb_x == s->resync_mb_x){ //rare
- *px= *py = 0;
- }else if(s->mb_x + 1 == s->resync_mb_x){ //rare
- C = s->motion_val[xy + off[block] - wrap];
- if(s->mb_x==0){
- *px = C[0];
- *py = C[1];
- }else{
- *px = mid_pred(A[0], 0, C[0]);
- *py = mid_pred(A[1], 0, C[1]);
- }
- }else{
- *px = A[0];
- *py = A[1];
- }
- }else if(block==1){
- if(s->mb_x + 1 == s->resync_mb_x){ //rare
- C = s->motion_val[xy + off[block] - wrap];
- *px = mid_pred(A[0], 0, C[0]);
- *py = mid_pred(A[1], 0, C[1]);
- }else{
- *px = A[0];
- *py = A[1];
- }
- }else{ /* block==2*/
- B = s->motion_val[xy - wrap];
- C = s->motion_val[xy + off[block] - wrap];
- if(s->mb_x == s->resync_mb_x) //rare
- A[0]=A[1]=0;
-
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- } else {
- B = s->motion_val[xy - wrap];
- C = s->motion_val[xy + off[block] - wrap];
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- return mot_val;
-}
-
-#ifdef CONFIG_ENCODERS
-static void h263_encode_motion(MpegEncContext * s, int val, int f_code)
-{
- int range, l, bit_size, sign, code, bits;
-
- if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(&s->pb, mvtab[code][1], mvtab[code][0]);
- } else {
- bit_size = f_code - 1;
- range = 1 << bit_size;
- /* modulo encoding */
- l = range * 32;
-#if 1
- val+= l;
- val&= 2*l-1;
- val-= l;
- sign = val>>31;
- val= (val^sign)-sign;
- sign&=1;
-#else
- if (val < -l) {
- val += 2*l;
- } else if (val >= l) {
- val -= 2*l;
- }
-
- assert(val>=-l && val<l);
-
- if (val >= 0) {
- sign = 0;
- } else {
- val = -val;
- sign = 1;
- }
-#endif
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
-
- put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign);
- if (bit_size > 0) {
- put_bits(&s->pb, bit_size, bits);
- }
- }
-
-}
-
-/* Encode MV differences on H.263+ with Unrestricted MV mode */
-static void h263p_encode_umotion(MpegEncContext * s, int val)
-{
- short sval = 0;
- short i = 0;
- short n_bits = 0;
- short temp_val;
- int code = 0;
- int tcode;
-
- if ( val == 0)
- put_bits(&s->pb, 1, 1);
- else if (val == 1)
- put_bits(&s->pb, 3, 0);
- else if (val == -1)
- put_bits(&s->pb, 3, 2);
- else {
-
- sval = ((val < 0) ? (short)(-val):(short)val);
- temp_val = sval;
-
- while (temp_val != 0) {
- temp_val = temp_val >> 1;
- n_bits++;
- }
-
- i = n_bits - 1;
- while (i > 0) {
- tcode = (sval & (1 << (i-1))) >> (i-1);
- tcode = (tcode << 1) | 1;
- code = (code << 2) | tcode;
- i--;
- }
- code = ((code << 1) | (val < 0)) << 1;
- put_bits(&s->pb, (2*n_bits)+1, code);
- //printf("\nVal = %d\tCode = %d", sval, code);
- }
-}
-
-static void init_mv_penalty_and_fcode(MpegEncContext *s)
-{
- int f_code;
- int mv;
-
- if(mv_penalty==NULL)
- mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
-
- for(f_code=1; f_code<=MAX_FCODE; f_code++){
- for(mv=-MAX_MV; mv<=MAX_MV; mv++){
- int len;
-
- if(mv==0) len= mvtab[0][1];
- else{
- int val, bit_size, range, code;
-
- bit_size = s->f_code - 1;
- range = 1 << bit_size;
-
- val=mv;
- if (val < 0)
- val = -val;
- val--;
- code = (val >> bit_size) + 1;
- if(code<33){
- len= mvtab[code][1] + 1 + bit_size;
- }else{
- len= mvtab[32][1] + 2 + bit_size;
- }
- }
-
- mv_penalty[f_code][mv+MAX_MV]= len;
- }
- }
-
- for(f_code=MAX_FCODE; f_code>0; f_code--){
- for(mv=-(16<<f_code); mv<(16<<f_code); mv++){
- fcode_tab[mv+MAX_MV]= f_code;
- }
- }
-
- for(mv=0; mv<MAX_MV*2+1; mv++){
- umv_fcode_tab[mv]= 1;
- }
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-static void init_uni_dc_tab(void)
-{
- int level, uni_code, uni_len;
-
- for(level=-256; level<256; level++){
- int size, v, l;
- /* find number of bits */
- size = 0;
- v = abs(level);
- while (v) {
- v >>= 1;
- size++;
- }
-
- if (level < 0)
- l= (-level) ^ ((1 << size) - 1);
- else
- l= level;
-
- /* luminance */
- uni_code= DCtab_lum[size][0];
- uni_len = DCtab_lum[size][1];
-
- if (size > 0) {
- uni_code<<=size; uni_code|=l;
- uni_len+=size;
- if (size > 8){
- uni_code<<=1; uni_code|=1;
- uni_len++;
- }
- }
- uni_DCtab_lum_bits[level+256]= uni_code;
- uni_DCtab_lum_len [level+256]= uni_len;
-
- /* chrominance */
- uni_code= DCtab_chrom[size][0];
- uni_len = DCtab_chrom[size][1];
-
- if (size > 0) {
- uni_code<<=size; uni_code|=l;
- uni_len+=size;
- if (size > 8){
- uni_code<<=1; uni_code|=1;
- uni_len++;
- }
- }
- uni_DCtab_chrom_bits[level+256]= uni_code;
- uni_DCtab_chrom_len [level+256]= uni_len;
-
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-#ifdef CONFIG_ENCODERS
-static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){
- int slevel, run, last;
-
- assert(MAX_LEVEL >= 64);
- assert(MAX_RUN >= 63);
-
- for(slevel=-64; slevel<64; slevel++){
- if(slevel==0) continue;
- for(run=0; run<64; run++){
- for(last=0; last<=1; last++){
- const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
- int level= slevel < 0 ? -slevel : slevel;
- int sign= slevel < 0 ? 1 : 0;
- int bits, len, code;
- int level1, run1;
-
- len_tab[index]= 100;
-
- /* ESC0 */
- code= get_rl_index(rl, last, run, level);
- bits= rl->table_vlc[code][0];
- len= rl->table_vlc[code][1];
- bits=bits*2+sign; len++;
-
- if(code!=rl->n && len < len_tab[index]){
- bits_tab[index]= bits;
- len_tab [index]= len;
- }
-#if 1
- /* ESC1 */
- bits= rl->table_vlc[rl->n][0];
- len= rl->table_vlc[rl->n][1];
- bits=bits*2; len++; //esc1
- level1= level - rl->max_level[last][run];
- if(level1>0){
- code= get_rl_index(rl, last, run, level1);
- bits<<= rl->table_vlc[code][1];
- len += rl->table_vlc[code][1];
- bits += rl->table_vlc[code][0];
- bits=bits*2+sign; len++;
-
- if(code!=rl->n && len < len_tab[index]){
- bits_tab[index]= bits;
- len_tab [index]= len;
- }
- }
-#endif
-#if 1
- /* ESC2 */
- bits= rl->table_vlc[rl->n][0];
- len= rl->table_vlc[rl->n][1];
- bits=bits*4+2; len+=2; //esc2
- run1 = run - rl->max_run[last][level] - 1;
- if(run1>=0){
- code= get_rl_index(rl, last, run1, level);
- bits<<= rl->table_vlc[code][1];
- len += rl->table_vlc[code][1];
- bits += rl->table_vlc[code][0];
- bits=bits*2+sign; len++;
-
- if(code!=rl->n && len < len_tab[index]){
- bits_tab[index]= bits;
- len_tab [index]= len;
- }
- }
-#endif
- /* ESC3 */
- bits= rl->table_vlc[rl->n][0];
- len = rl->table_vlc[rl->n][1];
- bits=bits*4+3; len+=2; //esc3
- bits=bits*2+last; len++;
- bits=bits*64+run; len+=6;
- bits=bits*2+1; len++; //marker
- bits=bits*4096+(slevel&0xfff); len+=12;
- bits=bits*2+1; len++; //marker
-
- if(len < len_tab[index]){
- bits_tab[index]= bits;
- len_tab [index]= len;
- }
- }
- }
- }
-}
-
-void h263_encode_init(MpegEncContext *s)
-{
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- init_uni_dc_tab();
-
- init_rl(&rl_inter);
- init_rl(&rl_intra);
- init_rl(&rl_intra_aic);
-
- init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len);
- init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len);
-
- init_mv_penalty_and_fcode(s);
- }
- s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p
-
- // use fcodes >1 only for mpeg4 & h263 & h263p FIXME
- switch(s->codec_id){
- case CODEC_ID_MPEG4:
- s->fcode_tab= fcode_tab;
- s->min_qcoeff= -2048;
- s->max_qcoeff= 2047;
- s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len;
- s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64;
- s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len;
- s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64;
- s->luma_dc_vlc_length= uni_DCtab_lum_len;
- s->chroma_dc_vlc_length= uni_DCtab_chrom_len;
- s->ac_esc_length= 7+2+1+6+1+12+1;
-
- if(s->flags & CODEC_FLAG_GLOBAL_HEADER){
-
- s->avctx->extradata= av_malloc(1024);
- init_put_bits(&s->pb, s->avctx->extradata, 1024, NULL, NULL);
-
- mpeg4_encode_visual_object_header(s);
- mpeg4_encode_vol_header(s, 0, 0);
-
-// ff_mpeg4_stuffing(&s->pb); ?
- flush_put_bits(&s->pb);
- s->avctx->extradata_size= (get_bit_count(&s->pb)+7)>>3;
- }
-
- break;
- case CODEC_ID_H263P:
- s->fcode_tab= umv_fcode_tab;
- s->min_qcoeff= -127;
- s->max_qcoeff= 127;
- break;
- //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later
- case CODEC_ID_FLV1:
- if (s->h263_flv > 1) {
- s->min_qcoeff= -1023;
- s->max_qcoeff= 1023;
- } else {
- s->min_qcoeff= -127;
- s->max_qcoeff= 127;
- }
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- break;
- default: //nothing needed default table allready set in mpegvideo.c
- s->min_qcoeff= -127;
- s->max_qcoeff= 127;
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- }
-}
-
-/**
- * encodes a 8x8 block.
- * @param block the 8x8 block
- * @param n block index (0-3 are luma, 4-5 are chroma)
- */
-static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
-{
- int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
- RLTable *rl;
-
- rl = &rl_inter;
- if (s->mb_intra && !s->h263_aic) {
- /* DC coef */
- level = block[0];
- /* 255 cannot be represented, so we clamp */
- if (level > 254) {
- level = 254;
- block[0] = 254;
- }
- /* 0 cannot be represented also */
- else if (level < 1) {
- level = 1;
- block[0] = 1;
- }
- if (level == 128) //FIXME check rv10
- put_bits(&s->pb, 8, 0xff);
- else
- put_bits(&s->pb, 8, level & 0xff);
- i = 1;
- } else {
- i = 0;
- if (s->h263_aic && s->mb_intra)
- rl = &rl_intra_aic;
- }
-
- /* AC coefs */
- last_index = s->block_last_index[n];
- last_non_zero = i - 1;
- for (; i <= last_index; i++) {
- j = s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- run = i - last_non_zero - 1;
- last = (i == last_index);
- sign = 0;
- slevel = level;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
- code = get_rl_index(rl, last, run, level);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- if(s->h263_flv <= 1){
- put_bits(&s->pb, 1, last);
- put_bits(&s->pb, 6, run);
-
- assert(slevel != 0);
-
- if(slevel < 128 && slevel > -128)
- put_bits(&s->pb, 8, slevel & 0xff);
- else{
- put_bits(&s->pb, 8, 128);
- put_bits(&s->pb, 5, slevel & 0x1f);
- put_bits(&s->pb, 6, (slevel>>5)&0x3f);
- }
- }else{
- if(slevel < 64 && slevel > -64) {
- /* 7-bit level */
- put_bits(&s->pb, 1, 0);
- put_bits(&s->pb, 1, last);
- put_bits(&s->pb, 6, run);
-
- put_bits(&s->pb, 7, slevel & 0x7f);
- } else {
- /* 11-bit level */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 1, last);
- put_bits(&s->pb, 6, run);
-
- put_bits(&s->pb, 11, slevel & 0x7ff);
- }
- }
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-}
-#endif
-
-#ifdef CONFIG_ENCODERS
-
-/***************************************************/
-/**
- * add mpeg4 stuffing bits (01...1)
- */
-void ff_mpeg4_stuffing(PutBitContext * pbc)
-{
- int length;
- put_bits(pbc, 1, 0);
- length= (-get_bit_count(pbc))&7;
- if(length) put_bits(pbc, length, (1<<length)-1);
-}
-
-/* must be called before writing the header */
-void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){
- int time_div, time_mod;
-
- if(s->current_picture.pts)
- s->time= (s->current_picture.pts*s->time_increment_resolution + 500*1000)/(1000*1000);
- else
- s->time= av_rescale(picture_number*(int64_t)s->avctx->frame_rate_base, s->time_increment_resolution, s->avctx->frame_rate);
- time_div= s->time/s->time_increment_resolution;
- time_mod= s->time%s->time_increment_resolution;
-
- if(s->pict_type==B_TYPE){
- s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
- }else{
- s->last_time_base= s->time_base;
- s->time_base= time_div;
- s->pp_time= s->time - s->last_non_b_time;
- s->last_non_b_time= s->time;
- }
-}
-
-static void mpeg4_encode_gop_header(MpegEncContext * s){
- int hours, minutes, seconds;
-
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, GOP_STARTCODE);
-
- seconds= s->time/s->time_increment_resolution;
- minutes= seconds/60; seconds %= 60;
- hours= minutes/60; minutes %= 60;
- hours%=24;
-
- put_bits(&s->pb, 5, hours);
- put_bits(&s->pb, 6, minutes);
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 6, seconds);
-
- put_bits(&s->pb, 1, 0); //closed gov == NO
- put_bits(&s->pb, 1, 0); //broken link == NO
-
- ff_mpeg4_stuffing(&s->pb);
-}
-
-static void mpeg4_encode_visual_object_header(MpegEncContext * s){
- int profile_and_level_indication;
- int vo_ver_id;
-
- if(s->max_b_frames || s->quarter_sample){
- profile_and_level_indication= 0xF1; // adv simple level 1
- vo_ver_id= 5;
- }else{
- profile_and_level_indication= 0x01; // simple level 1
- vo_ver_id= 1;
- }
- //FIXME levels
-
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, VOS_STARTCODE);
-
- put_bits(&s->pb, 8, profile_and_level_indication);
-
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
-
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 4, vo_ver_id);
- put_bits(&s->pb, 3, 1); //priority
-
- put_bits(&s->pb, 4, 1); //visual obj type== video obj
-
- put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME
-
- ff_mpeg4_stuffing(&s->pb);
-}
-
-static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number)
-{
- int vo_ver_id;
-
- if(s->max_b_frames || s->quarter_sample){
- vo_ver_id= 5;
- s->vo_type= ADV_SIMPLE_VO_TYPE;
- }else{
- vo_ver_id= 1;
- s->vo_type= SIMPLE_VO_TYPE;
- }
-
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */
-
- put_bits(&s->pb, 1, 0); /* random access vol */
- put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
- put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
- put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
- put_bits(&s->pb, 3, 1); /* is obj layer priority */
-
- float_aspect_to_info(s, s->avctx->aspect_ratio);
-
- put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */
- if (s->aspect_ratio_info == FF_ASPECT_EXTENDED)
- {
- put_bits(&s->pb, 8, s->aspected_width);
- put_bits(&s->pb, 8, s->aspected_height);
- }
-
- if(s->low_delay){
- put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
- put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
- put_bits(&s->pb, 1, s->low_delay);
- put_bits(&s->pb, 1, 0); /* vbv parameters= no */
- }else{
- put_bits(&s->pb, 1, 0); /* vol control parameters= no */
- }
-
- put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
- put_bits(&s->pb, 1, 1); /* marker bit */
-
- put_bits(&s->pb, 16, s->time_increment_resolution);
- if (s->time_increment_bits < 1)
- s->time_increment_bits = 1;
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 13, s->width); /* vol width */
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 13, s->height); /* vol height */
- put_bits(&s->pb, 1, 1); /* marker bit */
- put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
- put_bits(&s->pb, 1, 1); /* obmc disable */
- if (vo_ver_id == 1) {
- put_bits(&s->pb, 1, s->vol_sprite_usage=0); /* sprite enable */
- }else{
- put_bits(&s->pb, 2, s->vol_sprite_usage=0); /* sprite enable */
- }
-
- s->quant_precision=5;
- put_bits(&s->pb, 1, 0); /* not 8 bit == false */
- put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
-
- if(s->mpeg_quant){
- ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
- ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
- }
-
- if (vo_ver_id != 1)
- put_bits(&s->pb, 1, s->quarter_sample);
- put_bits(&s->pb, 1, 1); /* complexity estimation disable */
- s->resync_marker= s->rtp_mode;
- put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */
- put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
- if(s->data_partitioning){
- put_bits(&s->pb, 1, 0); /* no rvlc */
- }
-
- if (vo_ver_id != 1){
- put_bits(&s->pb, 1, 0); /* newpred */
- put_bits(&s->pb, 1, 0); /* reduced res vop */
- }
- put_bits(&s->pb, 1, 0); /* scalability */
-
- ff_mpeg4_stuffing(&s->pb);
-
- /* user data */
- if(!(s->flags & CODEC_FLAG_BITEXACT)){
- put_bits(&s->pb, 16, 0);
- put_bits(&s->pb, 16, 0x1B2); /* user_data */
- put_string(&s->pb, LIBAVCODEC_IDENT);
- ff_mpeg4_stuffing(&s->pb);
- }
-}
-
-/* write mpeg4 VOP header */
-void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- int time_incr;
- int time_div, time_mod;
-
- if(s->pict_type==I_TYPE){
- if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){
- if(s->strict_std_compliance < 2) //HACK, the reference sw is buggy
- mpeg4_encode_visual_object_header(s);
- if(s->strict_std_compliance < 2 || picture_number==0) //HACK, the reference sw is buggy
- mpeg4_encode_vol_header(s, 0, 0);
- }
- mpeg4_encode_gop_header(s);
- }
-
- s->partitioned_frame= s->data_partitioning && s->pict_type!=B_TYPE;
-
-//printf("num:%d rate:%d base:%d\n", s->picture_number, s->frame_rate, FRAME_RATE_BASE);
-
- put_bits(&s->pb, 16, 0); /* vop header */
- put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
- put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
-
- time_div= s->time/s->time_increment_resolution;
- time_mod= s->time%s->time_increment_resolution;
- time_incr= time_div - s->last_time_base;
- while(time_incr--)
- put_bits(&s->pb, 1, 1);
-
- put_bits(&s->pb, 1, 0);
-
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 1, 1); /* vop coded */
- if ( s->pict_type == P_TYPE
- || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) {
- put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
- }
- put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
- if(!s->progressive_sequence){
- put_bits(&s->pb, 1, s->top_field_first);
- put_bits(&s->pb, 1, s->alternate_scan);
- }
- //FIXME sprite stuff
-
- put_bits(&s->pb, 5, s->qscale);
-
- if (s->pict_type != I_TYPE)
- put_bits(&s->pb, 3, s->f_code); /* fcode_for */
- if (s->pict_type == B_TYPE)
- put_bits(&s->pb, 3, s->b_code); /* fcode_back */
- // printf("****frame %d\n", picture_number);
-
- s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support
- s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
-}
-
-#endif //CONFIG_ENCODERS
-
-/**
- * change qscale by given dquant and update qscale dependant variables.
- */
-static void change_qscale(MpegEncContext * s, int dquant)
-{
- s->qscale += dquant;
-
- if (s->qscale < 1)
- s->qscale = 1;
- else if (s->qscale > 31)
- s->qscale = 31;
-
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
-}
-
-/**
- * predicts the dc.
- * @param n block index (0-3 are luma, 4-5 are chroma)
- * @param dc_val_ptr a pointer to the dc_val entry for the current MB will be stored here
- * @param dir_ptr pointer to an integer where the prediction direction will be stored
- * @return the quantized predicted dc
- */
-static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, uint16_t **dc_val_ptr, int *dir_ptr)
-{
- int a, b, c, wrap, pred, scale;
- uint16_t *dc_val;
-
- /* find prediction */
- if (n < 4) {
- scale = s->y_dc_scale;
- } else {
- scale = s->c_dc_scale;
- }
- if(IS_3IV1)
- scale= 8;
-
- wrap= s->block_wrap[n];
- dc_val = s->dc_val[0] + s->block_index[n];
-
- /* B C
- * A X
- */
- a = dc_val[ - 1];
- b = dc_val[ - 1 - wrap];
- c = dc_val[ - wrap];
-
- /* outside slice handling (we cant do that by memset as we need the dc for error resilience) */
- if(s->first_slice_line && n!=3){
- if(n!=2) b=c= 1024;
- if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024;
- }
- if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){
- if(n==0 || n==4 || n==5)
- b=1024;
- }
-
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1; /* top */
- } else {
- pred = a;
- *dir_ptr = 0; /* left */
- }
- /* we assume pred is positive */
- pred = FASTDIV((pred + (scale >> 1)), scale);
-
- /* prepare address for prediction update */
- *dc_val_ptr = &dc_val[0];
-
- return pred;
-}
-
-/**
- * predicts the ac.
- * @param n block index (0-3 are luma, 4-5 are chroma)
- * @param dir the ac prediction direction
- */
-void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
- int dir)
-{
- int i;
- int16_t *ac_val, *ac_val1;
- int8_t * const qscale_table= s->current_picture.qscale_table;
-
- /* find prediction */
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
- ac_val1 = ac_val;
- if (s->ac_pred) {
- if (dir == 0) {
- const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
- /* left prediction */
- ac_val -= 16;
-
- if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
- /* same qscale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
- }
- }
- } else {
- const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
- /* top prediction */
- ac_val -= 16 * s->block_wrap[n];
-
- if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
- /* same qscale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i]] += ac_val[i + 8];
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
- }
- }
- }
- }
- /* left copy */
- for(i=1;i<8;i++)
- ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]];
-
- /* top copy */
- for(i=1;i<8;i++)
- ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]];
-
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void mpeg4_inv_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
- int dir)
-{
- int i;
- int16_t *ac_val;
- int8_t * const qscale_table= s->current_picture.qscale_table;
-
- /* find prediction */
- ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
-
- if (dir == 0) {
- const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
- /* left prediction */
- ac_val -= 16;
- if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
- /* same qscale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] -= ac_val[i];
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i<<3]] -= ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
- }
- }
- } else {
- const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
- /* top prediction */
- ac_val -= 16 * s->block_wrap[n];
- if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
- /* same qscale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i]] -= ac_val[i + 8];
- }
- }else{
- /* different qscale, we must rescale */
- for(i=1;i<8;i++) {
- block[s->dsp.idct_permutation[i]] -= ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
- }
- }
- }
-}
-
-/**
- * encodes the dc value.
- * @param n block index (0-3 are luma, 4-5 are chroma)
- */
-static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n)
-{
-#if 1
-// if(level<-255 || level>255) printf("dc overflow\n");
- level+=256;
- if (n < 4) {
- /* luminance */
- put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
- } else {
- /* chrominance */
- put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]);
- }
-#else
- int size, v;
- /* find number of bits */
- size = 0;
- v = abs(level);
- while (v) {
- v >>= 1;
- size++;
- }
-
- if (n < 4) {
- /* luminance */
- put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]);
- } else {
- /* chrominance */
- put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]);
- }
-
- /* encode remaining bits */
- if (size > 0) {
- if (level < 0)
- level = (-level) ^ ((1 << size) - 1);
- put_bits(&s->pb, size, level);
- if (size > 8)
- put_bits(&s->pb, 1, 1);
- }
-#endif
-}
-
-/**
- * encodes a 8x8 block
- * @param n block index (0-3 are luma, 4-5 are chroma)
- */
-static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
- uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
-{
- int i, last_non_zero;
-#if 0 //variables for the outcommented version
- int code, sign, last;
-#endif
- const RLTable *rl;
- uint32_t *bits_tab;
- uint8_t *len_tab;
- const int last_index = s->block_last_index[n];
-
- if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
- /* mpeg4 based DC predictor */
- mpeg4_encode_dc(dc_pb, intra_dc, n);
- if(last_index<1) return;
- i = 1;
- rl = &rl_intra;
- bits_tab= uni_mpeg4_intra_rl_bits;
- len_tab = uni_mpeg4_intra_rl_len;
- } else {
- if(last_index<0) return;
- i = 0;
- rl = &rl_inter;
- bits_tab= uni_mpeg4_inter_rl_bits;
- len_tab = uni_mpeg4_inter_rl_len;
- }
-
- /* AC coefs */
- last_non_zero = i - 1;
-#if 1
- for (; i < last_index; i++) {
- int level = block[ scan_table[i] ];
- if (level) {
- int run = i - last_non_zero - 1;
- level+=64;
- if((level&(~127)) == 0){
- const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
- put_bits(ac_pb, len_tab[index], bits_tab[index]);
- }else{ //ESC3
- put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
- }
- last_non_zero = i;
- }
- }
- /*if(i<=last_index)*/{
- int level = block[ scan_table[i] ];
- int run = i - last_non_zero - 1;
- level+=64;
- if((level&(~127)) == 0){
- const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
- put_bits(ac_pb, len_tab[index], bits_tab[index]);
- }else{ //ESC3
- put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
- }
- }
-#else
- for (; i <= last_index; i++) {
- const int slevel = block[ scan_table[i] ];
- if (slevel) {
- int level;
- int run = i - last_non_zero - 1;
- last = (i == last_index);
- sign = 0;
- level = slevel;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
- code = get_rl_index(rl, last, run, level);
- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- int level1, run1;
- level1 = level - rl->max_level[last][run];
- if (level1 < 1)
- goto esc2;
- code = get_rl_index(rl, last, run, level1);
- if (code == rl->n) {
- esc2:
- put_bits(ac_pb, 1, 1);
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - 1;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- put_bits(ac_pb, 1, 1);
- put_bits(ac_pb, 1, last);
- put_bits(ac_pb, 6, run);
- put_bits(ac_pb, 1, 1);
- put_bits(ac_pb, 12, slevel & 0xfff);
- put_bits(ac_pb, 1, 1);
- } else {
- /* second escape */
- put_bits(ac_pb, 1, 0);
- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(ac_pb, 1, sign);
- }
- } else {
- /* first escape */
- put_bits(ac_pb, 1, 0);
- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(ac_pb, 1, sign);
- }
- } else {
- put_bits(ac_pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-#endif
-}
-
-static inline int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc,
- uint8_t *scan_table)
-{
- int i, last_non_zero;
- const RLTable *rl;
- uint8_t *len_tab;
- const int last_index = s->block_last_index[n];
- int len=0;
-
- if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
- /* mpeg4 based DC predictor */
- //mpeg4_encode_dc(dc_pb, intra_dc, n); //FIXME
- if(last_index<1) return len;
- i = 1;
- rl = &rl_intra;
- len_tab = uni_mpeg4_intra_rl_len;
- } else {
- if(last_index<0) return 0;
- i = 0;
- rl = &rl_inter;
- len_tab = uni_mpeg4_inter_rl_len;
- }
-
- /* AC coefs */
- last_non_zero = i - 1;
- for (; i < last_index; i++) {
- int level = block[ scan_table[i] ];
- if (level) {
- int run = i - last_non_zero - 1;
- level+=64;
- if((level&(~127)) == 0){
- const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
- len += len_tab[index];
- }else{ //ESC3
- len += 7+2+1+6+1+12+1;
- }
- last_non_zero = i;
- }
- }
- /*if(i<=last_index)*/{
- int level = block[ scan_table[i] ];
- int run = i - last_non_zero - 1;
- level+=64;
- if((level&(~127)) == 0){
- const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
- len += len_tab[index];
- }else{ //ESC3
- len += 7+2+1+6+1+12+1;
- }
- }
-
- return len;
-}
-
-#endif
-
-
-/***********************************************/
-/* decoding */
-
-static VLC intra_MCBPC_vlc;
-static VLC inter_MCBPC_vlc;
-static VLC cbpy_vlc;
-static VLC mv_vlc;
-static VLC dc_lum, dc_chrom;
-static VLC sprite_trajectory;
-static VLC mb_type_b_vlc;
-
-void init_vlc_rl(RLTable *rl)
-{
- int i, q;
-
- init_vlc(&rl->vlc, 9, rl->n + 1,
- &rl->table_vlc[0][1], 4, 2,
- &rl->table_vlc[0][0], 4, 2);
-
-
- for(q=0; q<32; q++){
- int qmul= q*2;
- int qadd= (q-1)|1;
-
- if(q==0){
- qmul=1;
- qadd=0;
- }
-
- rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 66;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 66;
- level= 0;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code] * qmul + qadd;
- if(code >= rl->last) run+=192;
- }
- }
- rl->rl_vlc[q][i].len= len;
- rl->rl_vlc[q][i].level= level;
- rl->rl_vlc[q][i].run= run;
- }
- }
-}
-
-/* init vlcs */
-
-/* XXX: find a better solution to handle static init */
-void h263_decode_init_vlc(MpegEncContext *s)
-{
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
- intra_MCBPC_bits, 1, 1,
- intra_MCBPC_code, 1, 1);
- init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
- inter_MCBPC_bits, 1, 1,
- inter_MCBPC_code, 1, 1);
- init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
- &cbpy_tab[0][1], 2, 1,
- &cbpy_tab[0][0], 2, 1);
- init_vlc(&mv_vlc, MV_VLC_BITS, 33,
- &mvtab[0][1], 2, 1,
- &mvtab[0][0], 2, 1);
- init_rl(&rl_inter);
- init_rl(&rl_intra);
- init_rl(&rvlc_rl_inter);
- init_rl(&rvlc_rl_intra);
- init_rl(&rl_intra_aic);
- init_vlc_rl(&rl_inter);
- init_vlc_rl(&rl_intra);
- init_vlc_rl(&rvlc_rl_inter);
- init_vlc_rl(&rvlc_rl_intra);
- init_vlc_rl(&rl_intra_aic);
- init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
- &DCtab_lum[0][1], 2, 1,
- &DCtab_lum[0][0], 2, 1);
- init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
- &DCtab_chrom[0][1], 2, 1,
- &DCtab_chrom[0][0], 2, 1);
- init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
- &sprite_trajectory_tab[0][1], 4, 2,
- &sprite_trajectory_tab[0][0], 4, 2);
- init_vlc(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
- &mb_type_b_tab[0][1], 2, 1,
- &mb_type_b_tab[0][0], 2, 1);
- }
-}
-
-/**
- * Get the GOB height based on picture height.
- */
-int ff_h263_get_gob_height(MpegEncContext *s){
- if (s->height <= 400)
- return 1;
- else if (s->height <= 800)
- return 2;
- else
- return 4;
-}
-
-/**
- * decodes the group of blocks header.
- * @return <0 if an error occured
- */
-static int h263_decode_gob_header(MpegEncContext *s)
-{
- unsigned int val, gfid;
- int left;
-
- /* Check for GOB Start Code */
- val = show_bits(&s->gb, 16);
- if(val)
- return -1;
-
- /* We have a GBSC probably with GSTUFF */
- skip_bits(&s->gb, 16); /* Drop the zeros */
- left= s->gb.size_in_bits - get_bits_count(&s->gb);
- //MN: we must check the bits left or we might end in a infinite loop (or segfault)
- for(;left>13; left--){
- if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
- }
- if(left<=13)
- return -1;
-
-#ifdef DEBUG
- fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x);
-#endif
- s->gob_number = get_bits(&s->gb, 5); /* GN */
- gfid = get_bits(&s->gb, 2); /* GFID */
- s->qscale = get_bits(&s->gb, 5); /* GQUANT */
- if(s->qscale==0)
- return -1;
- s->mb_x= 0;
- s->mb_y= s->gob_index* s->gob_number;
- if(s->mb_y >= s->mb_height)
- return -1;
-#ifdef DEBUG
- fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale);
-#endif
- return 0;
-}
-
-static inline void memsetw(short *tab, int val, int n)
-{
- int i;
- for(i=0;i<n;i++)
- tab[i] = val;
-}
-
-#ifdef CONFIG_ENCODERS
-
-void ff_mpeg4_init_partitions(MpegEncContext *s)
-{
- init_put_bits(&s->tex_pb, s->tex_pb_buffer, PB_BUFFER_SIZE, NULL, NULL);
- init_put_bits(&s->pb2 , s->pb2_buffer , PB_BUFFER_SIZE, NULL, NULL);
-}
-
-void ff_mpeg4_merge_partitions(MpegEncContext *s)
-{
- const int pb2_len = get_bit_count(&s->pb2 );
- const int tex_pb_len= get_bit_count(&s->tex_pb);
- const int bits= get_bit_count(&s->pb);
-
- if(s->pict_type==I_TYPE){
- put_bits(&s->pb, 19, DC_MARKER);
- s->misc_bits+=19 + pb2_len + bits - s->last_bits;
- s->i_tex_bits+= tex_pb_len;
- }else{
- put_bits(&s->pb, 17, MOTION_MARKER);
- s->misc_bits+=17 + pb2_len;
- s->mv_bits+= bits - s->last_bits;
- s->p_tex_bits+= tex_pb_len;
- }
-
- flush_put_bits(&s->pb2);
- flush_put_bits(&s->tex_pb);
-
- ff_copy_bits(&s->pb, s->pb2_buffer , pb2_len);
- ff_copy_bits(&s->pb, s->tex_pb_buffer, tex_pb_len);
- s->last_bits= get_bit_count(&s->pb);
-}
-
-#endif //CONFIG_ENCODERS
-
-int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){
- switch(s->pict_type){
- case I_TYPE:
- return 16;
- case P_TYPE:
- case S_TYPE:
- return s->f_code+15;
- case B_TYPE:
- return FFMAX(FFMAX(s->f_code, s->b_code)+15, 17);
- default:
- return -1;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
-{
- int mb_num_bits= av_log2(s->mb_num - 1) + 1;
-
- ff_mpeg4_stuffing(&s->pb);
- put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0);
- put_bits(&s->pb, 1, 1);
-
- put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width);
- put_bits(&s->pb, s->quant_precision, s->qscale);
- put_bits(&s->pb, 1, 0); /* no HEC */
-}
-
-#endif //CONFIG_ENCODERS
-
-/**
- * check if the next stuff is a resync marker or the end.
- * @return 0 if not
- */
-static inline int mpeg4_is_resync(MpegEncContext *s){
- const int bits_count= get_bits_count(&s->gb);
-
- if(s->workaround_bugs&FF_BUG_NO_PADDING){
- return 0;
- }
-
- if(bits_count + 8 >= s->gb.size_in_bits){
- int v= show_bits(&s->gb, 8);
- v|= 0x7F >> (7-(bits_count&7));
-
- if(v==0x7F)
- return 1;
- }else{
- if(show_bits(&s->gb, 16) == ff_mpeg4_resync_prefix[bits_count&7]){
- int len;
- GetBitContext gb= s->gb;
-
- skip_bits(&s->gb, 1);
- align_get_bits(&s->gb);
-
- for(len=0; len<32; len++){
- if(get_bits1(&s->gb)) break;
- }
-
- s->gb= gb;
-
- if(len>=ff_mpeg4_get_video_packet_prefix_length(s))
- return 1;
- }
- }
- return 0;
-}
-
-/**
- * decodes the next video packet.
- * @return <0 if something went wrong
- */
-static int mpeg4_decode_video_packet_header(MpegEncContext *s)
-{
- int mb_num_bits= av_log2(s->mb_num - 1) + 1;
- int header_extension=0, mb_num, len;
-
- /* is there enough space left for a video packet + header */
- if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;
-
- for(len=0; len<32; len++){
- if(get_bits1(&s->gb)) break;
- }
-
- if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){
- printf("marker does not match f_code\n");
- return -1;
- }
-
- if(s->shape != RECT_SHAPE){
- header_extension= get_bits1(&s->gb);
- //FIXME more stuff here
- }
-
- mb_num= get_bits(&s->gb, mb_num_bits);
- if(mb_num>=s->mb_num){
- fprintf(stderr, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
- return -1;
- }
- if(s->pict_type == B_TYPE){
- while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++;
- if(mb_num >= s->mb_num) return -1; // slice contains just skiped MBs which where allready decoded
- }
-
- s->mb_x= mb_num % s->mb_width;
- s->mb_y= mb_num / s->mb_width;
-
- if(s->shape != BIN_ONLY_SHAPE){
- int qscale= get_bits(&s->gb, s->quant_precision);
- if(qscale)
- s->qscale= qscale;
- }
-
- if(s->shape == RECT_SHAPE){
- header_extension= get_bits1(&s->gb);
- }
- if(header_extension){
- int time_increment;
- int time_incr=0;
-
- while (get_bits1(&s->gb) != 0)
- time_incr++;
-
- check_marker(&s->gb, "before time_increment in video packed header");
- time_increment= get_bits(&s->gb, s->time_increment_bits);
- check_marker(&s->gb, "before vop_coding_type in video packed header");
-
- skip_bits(&s->gb, 2); /* vop coding type */
- //FIXME not rect stuff here
-
- if(s->shape != BIN_ONLY_SHAPE){
- skip_bits(&s->gb, 3); /* intra dc vlc threshold */
-//FIXME dont just ignore everything
- if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
- mpeg4_decode_sprite_trajectory(s);
- fprintf(stderr, "untested\n");
- }
-
- //FIXME reduced res stuff here
-
- if (s->pict_type != I_TYPE) {
- int f_code = get_bits(&s->gb, 3); /* fcode_for */
- if(f_code==0){
- printf("Error, video packet header damaged (f_code=0)\n");
- }
- }
- if (s->pict_type == B_TYPE) {
- int b_code = get_bits(&s->gb, 3);
- if(b_code==0){
- printf("Error, video packet header damaged (b_code=0)\n");
- }
- }
- }
- }
- //FIXME new-pred stuff
-
-//printf("parse ok %d %d %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width, get_bits_count(gb), get_bits_count(&s->gb));
-
- return 0;
-}
-
-void ff_mpeg4_clean_buffers(MpegEncContext *s)
-{
- int c_wrap, c_xy, l_wrap, l_xy;
-
- l_wrap= s->block_wrap[0];
- l_xy= s->mb_y*l_wrap*2 + s->mb_x*2;
- c_wrap= s->block_wrap[4];
- c_xy= s->mb_y*c_wrap + s->mb_x;
-
-#if 0
- /* clean DC */
- memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1);
- memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1);
- memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1);
-#endif
-
- /* clean AC */
- memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t));
- memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t));
- memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t));
-
- /* clean MV */
- // we cant clear the MVs as they might be needed by a b frame
-// memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(int16_t));
-// memset(s->motion_val, 0, 2*sizeof(int16_t)*(2 + s->mb_width*2)*(2 + s->mb_height*2));
- s->last_mv[0][0][0]=
- s->last_mv[0][0][1]=
- s->last_mv[1][0][0]=
- s->last_mv[1][0][1]= 0;
-}
-
-/**
- * decodes the group of blocks / video packet header.
- * @return <0 if no resync found
- */
-int ff_h263_resync(MpegEncContext *s){
- int left, ret;
-
- if(s->codec_id==CODEC_ID_MPEG4)
- skip_bits1(&s->gb);
-
- align_get_bits(&s->gb);
-
- if(show_bits(&s->gb, 16)==0){
- if(s->codec_id==CODEC_ID_MPEG4)
- ret= mpeg4_decode_video_packet_header(s);
- else
- ret= h263_decode_gob_header(s);
- if(ret>=0)
- return 0;
- }
- //ok, its not where its supposed to be ...
- s->gb= s->last_resync_gb;
- align_get_bits(&s->gb);
- left= s->gb.size_in_bits - get_bits_count(&s->gb);
-
- for(;left>16+1+5+5; left-=8){
- if(show_bits(&s->gb, 16)==0){
- GetBitContext bak= s->gb;
-
- if(s->codec_id==CODEC_ID_MPEG4)
- ret= mpeg4_decode_video_packet_header(s);
- else
- ret= h263_decode_gob_header(s);
- if(ret>=0)
- return 0;
-
- s->gb= bak;
- }
- skip_bits(&s->gb, 8);
- }
-
- return -1;
-}
-
-/**
- * gets the average motion vector for a GMC MB.
- * @param n either 0 for the x component or 1 for y
- * @returns the average MV for a GMC MB
- */
-static inline int get_amv(MpegEncContext *s, int n){
- int x, y, mb_v, sum, dx, dy, shift;
- int len = 1 << (s->f_code + 4);
- const int a= s->sprite_warping_accuracy;
-
- if(s->real_sprite_warping_points==1){
- if(s->divx_version==500 && s->divx_build==413)
- sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample));
- else
- sum= RSHIFT(s->sprite_offset[0][n]<<s->quarter_sample, a);
- }else{
- dx= s->sprite_delta[n][0];
- dy= s->sprite_delta[n][1];
- shift= s->sprite_shift[0];
- if(n) dy -= 1<<(shift + a + 1);
- else dx -= 1<<(shift + a + 1);
- mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16;
-
- sum=0;
- for(y=0; y<16; y++){
- int v;
-
- v= mb_v + dy*y;
- //XXX FIXME optimize
- for(x=0; x<16; x++){
- sum+= v>>shift;
- v+= dx;
- }
- }
- sum= RSHIFT(sum, a+8-s->quarter_sample);
- }
-
- if (sum < -len) sum= -len;
- else if (sum >= len) sum= len-1;
-
- return sum;
-}
-
-/**
- * decodes first partition.
- * @return number of MBs decoded or <0 if an error occured
- */
-static int mpeg4_decode_partition_a(MpegEncContext *s){
- int mb_num;
- static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
-
- /* decode first partition */
- mb_num=0;
- s->first_slice_line=1;
- for(; s->mb_y<s->mb_height; s->mb_y++){
- ff_init_block_index(s);
- for(; s->mb_x<s->mb_width; s->mb_x++){
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
- int cbpc;
- int dir=0;
-
- mb_num++;
- ff_update_block_index(s);
- if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
- s->first_slice_line=0;
-
- if(s->pict_type==I_TYPE){
- int i;
-
- if(show_bits_long(&s->gb, 19)==DC_MARKER){
- return mb_num-1;
- }
-
- do{
- cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
- if (cbpc < 0){
- fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }while(cbpc == 8);
-
- s->cbp_table[xy]= cbpc & 3;
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
- s->mb_intra = 1;
-
- if(cbpc & 4) {
- change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
- }
- s->current_picture.qscale_table[xy]= s->qscale;
-
- s->mbintra_table[xy]= 1;
- for(i=0; i<6; i++){
- int dc_pred_dir;
- int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
- if(dc < 0){
- fprintf(stderr, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- dir<<=1;
- if(dc_pred_dir) dir|=1;
- }
- s->pred_dir_table[xy]= dir;
- }else{ /* P/S_TYPE */
- int mx, my, pred_x, pred_y, bits;
- int16_t * const mot_val= s->motion_val[s->block_index[0]];
- const int stride= s->block_wrap[0]*2;
-
-// do{ //FIXME
- bits= show_bits(&s->gb, 17);
- if(bits==MOTION_MARKER){
- return mb_num-1;
- }
- skip_bits1(&s->gb);
- if(bits&0x10000){
- /* skip mb */
- if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
- mx= get_amv(s, 0);
- my= get_amv(s, 1);
- }else{
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- mx=my=0;
- }
- mot_val[0 ]= mot_val[2 ]=
- mot_val[0+stride]= mot_val[2+stride]= mx;
- mot_val[1 ]= mot_val[3 ]=
- mot_val[1+stride]= mot_val[3+stride]= my;
-
- if(s->mbintra_table[xy])
- ff_clean_intra_table_entries(s);
- continue;
- }
-
- cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
- if (cbpc < 0){
- fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-// }while(cbpc == 20);
-
- s->cbp_table[xy]= cbpc&(8+3); //8 is dquant
-
- s->mb_intra = ((cbpc & 4) != 0);
-
- if(s->mb_intra){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
- s->mbintra_table[xy]= 1;
- mot_val[0 ]= mot_val[2 ]=
- mot_val[0+stride]= mot_val[2+stride]= 0;
- mot_val[1 ]= mot_val[3 ]=
- mot_val[1+stride]= mot_val[3+stride]= 0;
- }else{
- if(s->mbintra_table[xy])
- ff_clean_intra_table_entries(s);
-
- if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
- s->mcsel= get_bits1(&s->gb);
- else s->mcsel= 0;
-
- if ((cbpc & 16) == 0) {
- /* 16x16 motion prediction */
-
- h263_pred_motion(s, 0, &pred_x, &pred_y);
- if(!s->mcsel){
- mx = h263_decode_motion(s, pred_x, s->f_code);
- if (mx >= 0xffff)
- return -1;
-
- my = h263_decode_motion(s, pred_y, s->f_code);
- if (my >= 0xffff)
- return -1;
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
- } else {
- mx = get_amv(s, 0);
- my = get_amv(s, 1);
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
- }
-
- mot_val[0 ]= mot_val[2 ] =
- mot_val[0+stride]= mot_val[2+stride]= mx;
- mot_val[1 ]= mot_val[3 ]=
- mot_val[1+stride]= mot_val[3+stride]= my;
- } else {
- int i;
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
- for(i=0;i<4;i++) {
- int16_t *mot_val= h263_pred_motion(s, i, &pred_x, &pred_y);
- mx = h263_decode_motion(s, pred_x, s->f_code);
- if (mx >= 0xffff)
- return -1;
-
- my = h263_decode_motion(s, pred_y, s->f_code);
- if (my >= 0xffff)
- return -1;
- mot_val[0] = mx;
- mot_val[1] = my;
- }
- }
- }
- }
- }
- s->mb_x= 0;
- }
-
- return mb_num;
-}
-
-/**
- * decode second partition.
- * @return <0 if an error occured
- */
-static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
- int mb_num=0;
- static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
-
- s->mb_x= s->resync_mb_x;
- s->first_slice_line=1;
- for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){
- ff_init_block_index(s);
- for(; mb_num < mb_count && s->mb_x<s->mb_width; s->mb_x++){
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
-
- mb_num++;
- ff_update_block_index(s);
- if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
- s->first_slice_line=0;
-
- if(s->pict_type==I_TYPE){
- int ac_pred= get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
- if(cbpy<0){
- fprintf(stderr, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- s->cbp_table[xy]|= cbpy<<2;
- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
- }else{ /* P || S_TYPE */
- if(IS_INTRA(s->current_picture.mb_type[xy])){
- int dir=0,i;
- int ac_pred = get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
-
- if(cbpy<0){
- fprintf(stderr, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if(s->cbp_table[xy] & 8) {
- change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
- }
- s->current_picture.qscale_table[xy]= s->qscale;
-
- for(i=0; i<6; i++){
- int dc_pred_dir;
- int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
- if(dc < 0){
- fprintf(stderr, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- dir<<=1;
- if(dc_pred_dir) dir|=1;
- }
- s->cbp_table[xy]&= 3; //remove dquant
- s->cbp_table[xy]|= cbpy<<2;
- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
- s->pred_dir_table[xy]= dir;
- }else if(IS_SKIP(s->current_picture.mb_type[xy])){
- s->current_picture.qscale_table[xy]= s->qscale;
- s->cbp_table[xy]= 0;
- }else{
- int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
-
- if(cbpy<0){
- fprintf(stderr, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if(s->cbp_table[xy] & 8) {
- change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
- }
- s->current_picture.qscale_table[xy]= s->qscale;
-
- s->cbp_table[xy]&= 3; //remove dquant
- s->cbp_table[xy]|= (cbpy^0xf)<<2;
- }
- }
- }
- if(mb_num >= mb_count) return 0;
- s->mb_x= 0;
- }
- return 0;
-}
-
-/**
- * decodes the first & second partition
- * @return <0 if error (and sets error type in the error_status_table)
- */
-int ff_mpeg4_decode_partitions(MpegEncContext *s)
-{
- int mb_num;
- const int part_a_error= s->pict_type==I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR;
- const int part_a_end = s->pict_type==I_TYPE ? (DC_END |MV_END) : MV_END;
-
- mb_num= mpeg4_decode_partition_a(s);
- if(mb_num<0){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
- return -1;
- }
-
- if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){
- fprintf(stderr, "slice below monitor ...\n");
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
- return -1;
- }
-
- s->mb_num_left= mb_num;
-
- if(s->pict_type==I_TYPE){
- if(get_bits_long(&s->gb, 19)!=DC_MARKER){
- fprintf(stderr, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }else{
- if(get_bits(&s->gb, 17)!=MOTION_MARKER){
- fprintf(stderr, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end);
-
- if( mpeg4_decode_partition_b(s, mb_num) < 0){
- if(s->pict_type==P_TYPE)
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR);
- return -1;
- }else{
- if(s->pict_type==P_TYPE)
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END);
- }
-
- return 0;
-}
-
-/**
- * decode partition C of one MB.
- * @return <0 if an error occured
- */
-static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- int cbp, mb_type;
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
-
- mb_type= s->current_picture.mb_type[xy];
- cbp = s->cbp_table[xy];
-
- if(s->current_picture.qscale_table[xy] != s->qscale){
- s->qscale= s->current_picture.qscale_table[xy];
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
- }
-
- if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
- int i;
- for(i=0; i<4; i++){
- s->mv[0][i][0] = s->motion_val[ s->block_index[i] ][0];
- s->mv[0][i][1] = s->motion_val[ s->block_index[i] ][1];
- }
- s->mb_intra = IS_INTRA(mb_type);
-
- if (IS_SKIP(mb_type)) {
- /* skip mb */
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
- s->mcsel=1;
- s->mb_skiped = 0;
- }else{
- s->mcsel=0;
- s->mb_skiped = 1;
- }
- }else if(s->mb_intra){
- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
- }else if(!s->mb_intra){
-// s->mcsel= 0; //FIXME do we need to init that
-
- s->mv_dir = MV_DIR_FORWARD;
- if (IS_8X8(mb_type)) {
- s->mv_type = MV_TYPE_8X8;
- } else {
- s->mv_type = MV_TYPE_16X16;
- }
- }
- } else { /* I-Frame */
- s->mb_intra = 1;
- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
- }
-
- if (!IS_SKIP(mb_type)) {
- int i;
- /* decode each block */
- for (i = 0; i < 6; i++) {
- if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){
- fprintf(stderr, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra);
- return -1;
- }
- cbp+=cbp;
- }
- }
-
- /* per-MB end of slice check */
-
- if(--s->mb_num_left <= 0){
-//printf("%06X %d\n", show_bits(&s->gb, 24), s->gb.size_in_bits - get_bits_count(&s->gb));
- if(mpeg4_is_resync(s))
- return SLICE_END;
- else
- return SLICE_NOEND;
- }else{
- if(mpeg4_is_resync(s)){
- const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
- if(s->cbp_table[xy+delta])
- return SLICE_END;
- }
- return SLICE_OK;
- }
-}
-
-int ff_h263_decode_mb(MpegEncContext *s,
- DCTELEM block[6][64])
-{
- int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
- int16_t *mot_val;
- static int8_t quant_tab[4] = { -1, -2, 1, 2 };
- const int xy= s->mb_x + s->mb_y * s->mb_stride;
-
- if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
- do{
- if (get_bits1(&s->gb)) {
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
- s->mcsel=1;
- s->mv[0][0][0]= get_amv(s, 0);
- s->mv[0][0][1]= get_amv(s, 1);
-
- s->mb_skiped = 0;
- }else{
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- s->mcsel=0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skiped = 1;
- }
- goto end;
- }
- cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
- //fprintf(stderr, "\tCBPC: %d", cbpc);
- if (cbpc < 0){
- fprintf(stderr, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }while(cbpc == 20);
-
- dquant = cbpc & 8;
- s->mb_intra = ((cbpc & 4) != 0);
- if (s->mb_intra) goto intra;
-
- if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
- s->mcsel= get_bits1(&s->gb);
- else s->mcsel= 0;
- cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
- cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2);
- if (dquant) {
- change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
- }
- if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE)))
- s->interlaced_dct= get_bits1(&s->gb);
-
- s->mv_dir = MV_DIR_FORWARD;
- if ((cbpc & 16) == 0) {
- if(s->mcsel){
- s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
- /* 16x16 global motion prediction */
- s->mv_type = MV_TYPE_16X16;
- mx= get_amv(s, 0);
- my= get_amv(s, 1);
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
- }else if((!s->progressive_sequence) && get_bits1(&s->gb)){
- s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED;
- /* 16x8 field motion prediction */
- s->mv_type= MV_TYPE_FIELD;
-
- s->field_select[0][0]= get_bits1(&s->gb);
- s->field_select[0][1]= get_bits1(&s->gb);
-
- h263_pred_motion(s, 0, &pred_x, &pred_y);
-
- for(i=0; i<2; i++){
- mx = h263_decode_motion(s, pred_x, s->f_code);
- if (mx >= 0xffff)
- return -1;
-
- my = h263_decode_motion(s, pred_y/2, s->f_code);
- if (my >= 0xffff)
- return -1;
-
- s->mv[0][i][0] = mx;
- s->mv[0][i][1] = my;
- }
- }else{
- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
- /* 16x16 motion prediction */
- s->mv_type = MV_TYPE_16X16;
- h263_pred_motion(s, 0, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
- else
- mx = h263_decode_motion(s, pred_x, s->f_code);
-
- if (mx >= 0xffff)
- return -1;
-
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
- else
- my = h263_decode_motion(s, pred_y, s->f_code);
-
- if (my >= 0xffff)
- return -1;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
-
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
- }
- } else {
- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
- s->mv_type = MV_TYPE_8X8;
- for(i=0;i<4;i++) {
- mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
- else
- mx = h263_decode_motion(s, pred_x, s->f_code);
- if (mx >= 0xffff)
- return -1;
-
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
- else
- my = h263_decode_motion(s, pred_y, s->f_code);
- if (my >= 0xffff)
- return -1;
- s->mv[0][i][0] = mx;
- s->mv[0][i][1] = my;
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
- mot_val[0] = mx;
- mot_val[1] = my;
- }
- }
- } else if(s->pict_type==B_TYPE) {
- int modb1; // first bit of modb
- int modb2; // second bit of modb
- int mb_type;
-
- s->mb_intra = 0; //B-frames never contain intra blocks
- s->mcsel=0; // ... true gmc blocks
-
- if(s->mb_x==0){
- for(i=0; i<2; i++){
- s->last_mv[i][0][0]=
- s->last_mv[i][0][1]=
- s->last_mv[i][1][0]=
- s->last_mv[i][1][1]= 0;
- }
- }
-
- /* if we skipped it in the future P Frame than skip it now too */
- s->mb_skiped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
-
- if(s->mb_skiped){
- /* skip mb */
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mv[1][0][0] = 0;
- s->mv[1][0][1] = 0;
- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- goto end;
- }
-
- modb1= get_bits1(&s->gb);
- if(modb1){
- mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded
- cbp=0;
- }else{
- modb2= get_bits1(&s->gb);
- mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);
- if(mb_type<0){
- printf("illegal MB_type\n");
- return -1;
- }
- mb_type= mb_type_b_map[ mb_type ];
- if(modb2) cbp= 0;
- else cbp= get_bits(&s->gb, 6);
-
- if ((!IS_DIRECT(mb_type)) && cbp) {
- if(get_bits1(&s->gb)){
- change_qscale(s, get_bits1(&s->gb)*4 - 2);
- }
- }
-
- if(!s->progressive_sequence){
- if(cbp)
- s->interlaced_dct= get_bits1(&s->gb);
-
- if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- mb_type &= ~MB_TYPE_16x16;
-
- if(USES_LIST(mb_type, 0)){
- s->field_select[0][0]= get_bits1(&s->gb);
- s->field_select[0][1]= get_bits1(&s->gb);
- }
- if(USES_LIST(mb_type, 1)){
- s->field_select[1][0]= get_bits1(&s->gb);
- s->field_select[1][1]= get_bits1(&s->gb);
- }
- }
- }
-
- s->mv_dir = 0;
- if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){
- s->mv_type= MV_TYPE_16X16;
-
- if(USES_LIST(mb_type, 0)){
- s->mv_dir = MV_DIR_FORWARD;
-
- mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
- my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);
- s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx;
- s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my;
- }
-
- if(USES_LIST(mb_type, 1)){
- s->mv_dir |= MV_DIR_BACKWARD;
-
- mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);
- my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);
- s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx;
- s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my;
- }
- }else if(!IS_DIRECT(mb_type)){
- s->mv_type= MV_TYPE_FIELD;
-
- if(USES_LIST(mb_type, 0)){
- s->mv_dir = MV_DIR_FORWARD;
-
- for(i=0; i<2; i++){
- mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code);
- my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code);
- s->last_mv[0][i][0]= s->mv[0][i][0] = mx;
- s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2;
- }
- }
-
- if(USES_LIST(mb_type, 1)){
- s->mv_dir |= MV_DIR_BACKWARD;
-
- for(i=0; i<2; i++){
- mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code);
- my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code);
- s->last_mv[1][i][0]= s->mv[1][i][0] = mx;
- s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2;
- }
- }
- }
- }
-
- if(IS_DIRECT(mb_type)){
- if(IS_SKIP(mb_type))
- mx=my=0;
- else{
- mx = h263_decode_motion(s, 0, 1);
- my = h263_decode_motion(s, 0, 1);
- }
-
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
- }
- s->current_picture.mb_type[xy]= mb_type;
- } else { /* I-Frame */
- do{
- cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
- if (cbpc < 0){
- fprintf(stderr, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }while(cbpc == 8);
-
- dquant = cbpc & 4;
- s->mb_intra = 1;
-intra:
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
- if (s->h263_pred || s->h263_aic) {
- s->ac_pred = get_bits1(&s->gb);
- if(s->ac_pred){
- s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
-
- if (s->h263_aic)
- s->h263_aic_dir = get_bits1(&s->gb);
- }
- }else
- s->ac_pred = 0;
-
- cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
- if(cbpy<0){
- fprintf(stderr, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- cbp = (cbpc & 3) | (cbpy << 2);
- if (dquant) {
- change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
- }
-
- if(!s->progressive_sequence)
- s->interlaced_dct= get_bits1(&s->gb);
-
- /* decode each block */
- if (s->h263_pred) {
- for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0)
- return -1;
- cbp+=cbp;
- }
- } else {
- for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, block[i], i, cbp&32) < 0)
- return -1;
- cbp+=cbp;
- }
- }
- goto end;
- }
-
- /* decode each block */
- if (s->h263_pred) {
- for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0)
- return -1;
- cbp+=cbp;
- }
- } else {
- for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, block[i], i, cbp&32) < 0)
- return -1;
- cbp+=cbp;
- }
- }
-end:
-
- /* per-MB end of slice check */
- if(s->codec_id==CODEC_ID_MPEG4){
- if(mpeg4_is_resync(s)){
- const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
- if(s->pict_type==B_TYPE && s->next_picture.mbskip_table[xy + delta])
- return SLICE_OK;
- return SLICE_END;
- }
- }else{
- int v= show_bits(&s->gb, 16);
-
- if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){
- v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits;
- }
-
- if(v==0)
- return SLICE_END;
- }
-
- return SLICE_OK;
-}
-
-static int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
-{
- int code, val, sign, shift, l;
- code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
-
- if (code == 0)
- return pred;
- if (code < 0)
- return 0xffff;
-
- sign = get_bits1(&s->gb);
- shift = f_code - 1;
- val = code;
- if (shift) {
- val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
- val++;
- }
- if (sign)
- val = -val;
- val += pred;
-
- /* modulo decoding */
- if (!s->h263_long_vectors) {
- l = 1 << (f_code + 4);
- val = ((val + l)&(l*2-1)) - l;
- } else {
- /* horrible h263 long vector mode */
- if (pred < -31 && val < -63)
- val += 64;
- if (pred > 32 && val > 63)
- val -= 64;
-
- }
- return val;
-}
-
-/* Decodes RVLC of H.263+ UMV */
-static int h263p_decode_umotion(MpegEncContext * s, int pred)
-{
- int code = 0, sign;
-
- if (get_bits1(&s->gb)) /* Motion difference = 0 */
- return pred;
-
- code = 2 + get_bits1(&s->gb);
-
- while (get_bits1(&s->gb))
- {
- code <<= 1;
- code += get_bits1(&s->gb);
- }
- sign = code & 1;
- code >>= 1;
-
- code = (sign) ? (pred - code) : (pred + code);
-#ifdef DEBUG
- fprintf(stderr,"H.263+ UMV Motion = %d\n", code);
-#endif
- return code;
-
-}
-
-static int h263_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded)
-{
- int code, level, i, j, last, run;
- RLTable *rl = &rl_inter;
- const uint8_t *scan_table;
-
- scan_table = s->intra_scantable.permutated;
- if (s->h263_aic && s->mb_intra) {
- rl = &rl_intra_aic;
- i = 0;
- if (s->ac_pred) {
- if (s->h263_aic_dir)
- scan_table = s->intra_v_scantable.permutated; /* left */
- else
- scan_table = s->intra_h_scantable.permutated; /* top */
- }
- } else if (s->mb_intra) {
- /* DC coef */
- if(s->h263_rv10){
- if (s->rv10_version == 3 && s->pict_type == I_TYPE) {
- int component, diff;
- component = (n <= 3 ? 0 : n - 4 + 1);
- level = s->last_dc[component];
- if (s->rv10_first_dc_coded[component]) {
- diff = rv_decode_dc(s, n);
- if (diff == 0xffff)
- return -1;
- level += diff;
- level = level & 0xff; /* handle wrap round */
- s->last_dc[component] = level;
- } else {
- s->rv10_first_dc_coded[component] = 1;
- }
- } else {
- level = get_bits(&s->gb, 8);
- }
- }else{
- level = get_bits(&s->gb, 8);
- if((level&0x7F) == 0){
- fprintf(stderr, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
- return -1;
- }
- if (level == 255)
- level = 128;
- }
- block[0] = level;
- i = 1;
- } else {
- i = 0;
- }
- if (!coded) {
- if (s->mb_intra && s->h263_aic)
- goto not_coded;
- s->block_last_index[n] = i - 1;
- return 0;
- }
-
- for(;;) {
- code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
- if (code < 0){
- fprintf(stderr, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
- return -1;
- }
- if (code == rl->n) {
- /* escape */
- if (s->h263_flv > 1) {
- int is11 = get_bits1(&s->gb);
- last = get_bits1(&s->gb);
- run = get_bits(&s->gb, 6);
- if(is11){
- level = get_sbits(&s->gb, 11);
- } else {
- level = get_sbits(&s->gb, 7);
- }
- } else {
- last = get_bits1(&s->gb);
- run = get_bits(&s->gb, 6);
- level = (int8_t)get_bits(&s->gb, 8);
- if(level == -128){
- if (s->h263_rv10) {
- /* XXX: should patch encoder too */
- level = get_sbits(&s->gb, 12);
- }else{
- level = get_bits(&s->gb, 5);
- level |= get_sbits(&s->gb, 6)<<5;
- }
- }
- }
- } else {
- run = rl->table_run[code];
- level = rl->table_level[code];
- last = code >= rl->last;
- if (get_bits1(&s->gb))
- level = -level;
- }
- i += run;
- if (i >= 64){
- fprintf(stderr, "run overflow at %dx%d\n", s->mb_x, s->mb_y);
- return -1;
- }
- j = scan_table[i];
- block[j] = level;
- if (last)
- break;
- i++;
- }
-not_coded:
- if (s->mb_intra && s->h263_aic) {
- h263_pred_acdc(s, block, n);
- i = 63;
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-/**
- * decodes the dc value.
- * @param n block index (0-3 are luma, 4-5 are chroma)
- * @param dir_ptr the prediction direction will be stored here
- * @return the quantized dc
- */
-static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
-{
- int level, pred, code;
- uint16_t *dc_val;
-
- if (n < 4)
- code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1);
- else
- code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1);
- if (code < 0 || code > 9 /* && s->nbit<9 */){
- fprintf(stderr, "illegal dc vlc\n");
- return -1;
- }
- if (code == 0) {
- level = 0;
- } else {
- if(IS_3IV1){
- if(code==1)
- level= 2*get_bits1(&s->gb)-1;
- else{
- if(get_bits1(&s->gb))
- level = get_bits(&s->gb, code-1) + (1<<(code-1));
- else
- level = -get_bits(&s->gb, code-1) - (1<<(code-1));
- }
- }else{
- level = get_xbits(&s->gb, code);
- }
-
- if (code > 8){
- if(get_bits1(&s->gb)==0){ /* marker */
- if(s->error_resilience>=2){
- fprintf(stderr, "dc marker bit missing\n");
- return -1;
- }
- }
- }
- }
- pred = ff_mpeg4_pred_dc(s, n, &dc_val, dir_ptr);
- level += pred;
- if (level < 0){
- if(s->error_resilience>=3){
- fprintf(stderr, "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
- return -1;
- }
- level = 0;
- }
- if (n < 4) {
- *dc_val = level * s->y_dc_scale;
- } else {
- *dc_val = level * s->c_dc_scale;
- }
- if(IS_3IV1)
- *dc_val = level * 8;
-
- if(s->error_resilience>=3){
- if(*dc_val > 2048 + s->y_dc_scale + s->c_dc_scale){
- fprintf(stderr, "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
- return level;
-}
-
-/**
- * decodes a block.
- * @return <0 if an error occured
- */
-static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, int intra, int rvlc)
-{
- int level, i, last, run;
- int dc_pred_dir;
- RLTable * rl;
- RL_VLC_ELEM * rl_vlc;
- const uint8_t * scan_table;
- int qmul, qadd;
-
- //Note intra & rvlc should be optimized away if this is inlined
-
- if(intra) {
- /* DC coef */
- if(s->partitioned_frame){
- level = s->dc_val[0][ s->block_index[n] ];
- if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);
- else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale);
- dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;
- }else{
- level = mpeg4_decode_dc(s, n, &dc_pred_dir);
- if (level < 0)
- return -1;
- }
- block[0] = level;
- i = 0;
- if (!coded)
- goto not_coded;
-
- if(rvlc){
- rl = &rvlc_rl_intra;
- rl_vlc = rvlc_rl_intra.rl_vlc[0];
- }else{
- rl = &rl_intra;
- rl_vlc = rl_intra.rl_vlc[0];
- }
- if (s->ac_pred) {
- if (dc_pred_dir == 0)
- scan_table = s->intra_v_scantable.permutated; /* left */
- else
- scan_table = s->intra_h_scantable.permutated; /* top */
- } else {
- scan_table = s->intra_scantable.permutated;
- }
- qmul=1;
- qadd=0;
- } else {
- i = -1;
- if (!coded) {
- s->block_last_index[n] = i;
- return 0;
- }
- if(rvlc) rl = &rvlc_rl_inter;
- else rl = &rl_inter;
-
- scan_table = s->intra_scantable.permutated;
-
- if(s->mpeg_quant){
- qmul=1;
- qadd=0;
- if(rvlc){
- rl_vlc = rvlc_rl_inter.rl_vlc[0];
- }else{
- rl_vlc = rl_inter.rl_vlc[0];
- }
- }else{
- qmul = s->qscale << 1;
- qadd = (s->qscale - 1) | 1;
- if(rvlc){
- rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale];
- }else{
- rl_vlc = rl_inter.rl_vlc[s->qscale];
- }
- }
- }
- {
- OPEN_READER(re, &s->gb);
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- if (level==0) {
- /* escape */
- if(rvlc){
- if(SHOW_UBITS(re, &s->gb, 1)==0){
- fprintf(stderr, "1. marker bit missing in rvlc esc\n");
- return -1;
- }; SKIP_CACHE(re, &s->gb, 1);
-
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
- run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
- SKIP_COUNTER(re, &s->gb, 1+1+6);
- UPDATE_CACHE(re, &s->gb);
-
- if(SHOW_UBITS(re, &s->gb, 1)==0){
- fprintf(stderr, "2. marker bit missing in rvlc esc\n");
- return -1;
- }; SKIP_CACHE(re, &s->gb, 1);
-
- level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11);
-
- if(SHOW_UBITS(re, &s->gb, 5)!=0x10){
- fprintf(stderr, "reverse esc missing\n");
- return -1;
- }; SKIP_CACHE(re, &s->gb, 5);
-
- level= level * qmul + qadd;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1);
- SKIP_COUNTER(re, &s->gb, 1+11+5+1);
-
- i+= run + 1;
- if(last) i+=192;
- }else{
- int cache;
- cache= GET_CACHE(re, &s->gb);
-
- if(IS_3IV1)
- cache ^= 0xC0000000;
-
- if (cache&0x80000000) {
- if (cache&0x40000000) {
- /* third escape */
- SKIP_CACHE(re, &s->gb, 2);
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
- run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
- SKIP_COUNTER(re, &s->gb, 2+1+6);
- UPDATE_CACHE(re, &s->gb);
-
- if(IS_3IV1){
- level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12);
- }else{
- if(SHOW_UBITS(re, &s->gb, 1)==0){
- fprintf(stderr, "1. marker bit missing in 3. esc\n");
- return -1;
- }; SKIP_CACHE(re, &s->gb, 1);
-
- level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12);
-
- if(SHOW_UBITS(re, &s->gb, 1)==0){
- fprintf(stderr, "2. marker bit missing in 3. esc\n");
- return -1;
- }; LAST_SKIP_CACHE(re, &s->gb, 1);
-
- SKIP_COUNTER(re, &s->gb, 1+12+1);
- }
-
- if(level*s->qscale>1024 || level*s->qscale<-1024){
- fprintf(stderr, "|level| overflow in 3. esc, qp=%d\n", s->qscale);
- return -1;
- }
-#if 1
- {
- const int abs_level= ABS(level);
- if(abs_level<=MAX_LEVEL && run<=MAX_RUN && !(s->workaround_bugs&FF_BUG_AC_VLC)){
- const int run1= run - rl->max_run[last][abs_level] - 1;
- if(abs_level <= rl->max_level[last][run]){
- fprintf(stderr, "illegal 3. esc, vlc encoding possible\n");
- return -1;
- }
- if(s->error_resilience > FF_ER_COMPLIANT){
- if(abs_level <= rl->max_level[last][run]*2){
- fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n");
- return -1;
- }
- if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
- fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n");
- return -1;
- }
- }
- }
- }
-#endif
- if (level>0) level= level * qmul + qadd;
- else level= level * qmul - qadd;
-
- i+= run + 1;
- if(last) i+=192;
- } else {
- /* second escape */
-#if MIN_CACHE_BITS < 20
- LAST_SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
-#else
- SKIP_BITS(re, &s->gb, 2);
-#endif
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- }
- } else {
- /* first escape */
-#if MIN_CACHE_BITS < 19
- LAST_SKIP_BITS(re, &s->gb, 1);
- UPDATE_CACHE(re, &s->gb);
-#else
- SKIP_BITS(re, &s->gb, 1);
-#endif
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- i+= run;
- level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- }
- }
- } else {
- i+= run;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- }
- if (i > 62){
- i-= 192;
- if(i&(~63)){
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- block[scan_table[i]] = level;
- break;
- }
-
- block[scan_table[i]] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- not_coded:
- if (s->mb_intra) {
- mpeg4_pred_ac(s, block, n, dc_pred_dir);
- if (s->ac_pred) {
- i = 63; /* XXX: not optimal */
- }
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-/* most is hardcoded. should extend to handle all h263 streams */
-int h263_decode_picture_header(MpegEncContext *s)
-{
- int format, width, height, i;
- uint32_t startcode;
-
- align_get_bits(&s->gb);
-
- startcode= get_bits(&s->gb, 22-8);
-
- for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=8) {
- startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
-
- if(startcode == 0x20)
- break;
- }
-
- if (startcode != 0x20) {
- fprintf(stderr, "Bad picture start code\n");
- return -1;
- }
- /* temporal reference */
- s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
-
- /* PTYPE starts here */
- if (get_bits1(&s->gb) != 1) {
- /* marker */
- fprintf(stderr, "Bad marker\n");
- return -1;
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Bad H263 id\n");
- return -1; /* h263 id */
- }
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
-
- /* Reset GOB number */
- s->gob_number = 0;
-
- format = get_bits(&s->gb, 3);
- /*
- 0 forbidden
- 1 sub-QCIF
- 10 QCIF
- 7 extended PTYPE (PLUSPTYPE)
- */
-
- if (format != 7 && format != 6) {
- s->h263_plus = 0;
- /* H.263v1 */
- width = h263_format[format][0];
- height = h263_format[format][1];
- if (!width)
- return -1;
-
- s->pict_type = I_TYPE + get_bits1(&s->gb);
-
- s->unrestricted_mv = get_bits1(&s->gb);
- s->h263_long_vectors = s->unrestricted_mv;
-
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "H263 SAC not supported\n");
- return -1; /* SAC: off */
- }
- if (get_bits1(&s->gb) != 0) {
- s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */
- }
-
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "H263 PB frame not supported\n");
- return -1; /* not PB frame */
- }
- s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
-
- s->width = width;
- s->height = height;
- } else {
- int ufep;
-
- /* H.263v2 */
- s->h263_plus = 1;
- ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
-
- /* ufep other than 0 and 1 are reserved */
- if (ufep == 1) {
- /* OPPTYPE */
- format = get_bits(&s->gb, 3);
- dprintf("ufep=1, format: %d\n", format);
- skip_bits(&s->gb,1); /* Custom PCF */
- s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */
- skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */
- if (get_bits1(&s->gb) != 0) {
- s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */
- }
- if (get_bits1(&s->gb) != 0) { /* Advanced Intra Coding (AIC) */
- s->h263_aic = 1;
- }
-
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Deblocking Filter not supported\n");
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Slice Structured not supported\n");
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Reference Picture Selection not supported\n");
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Independent Segment Decoding not supported\n");
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Alternative Inter VLC not supported\n");
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Modified Quantization not supported\n");
- }
-
- skip_bits(&s->gb, 1); /* Prevent start code emulation */
-
- skip_bits(&s->gb, 3); /* Reserved */
- } else if (ufep != 0) {
- fprintf(stderr, "Bad UFEP type (%d)\n", ufep);
- return -1;
- }
-
- /* MPPTYPE */
- s->pict_type = get_bits(&s->gb, 3) + I_TYPE;
- dprintf("pict_type: %d\n", s->pict_type);
- if (s->pict_type != I_TYPE &&
- s->pict_type != P_TYPE)
- return -1;
- skip_bits(&s->gb, 2);
- s->no_rounding = get_bits1(&s->gb);
- dprintf("RTYPE: %d\n", s->no_rounding);
- skip_bits(&s->gb, 4);
-
- /* Get the picture dimensions */
- if (ufep) {
- if (format == 6) {
- /* Custom Picture Format (CPFMT) */
- s->aspect_ratio_info = get_bits(&s->gb, 4);
- dprintf("aspect: %d\n", s->aspect_ratio_info);
- /* aspect ratios:
- 0 - forbidden
- 1 - 1:1
- 2 - 12:11 (CIF 4:3)
- 3 - 10:11 (525-type 4:3)
- 4 - 16:11 (CIF 16:9)
- 5 - 40:33 (525-type 16:9)
- 6-14 - reserved
- */
- width = (get_bits(&s->gb, 9) + 1) * 4;
- skip_bits1(&s->gb);
- height = get_bits(&s->gb, 9) * 4;
- dprintf("\nH.263+ Custom picture: %dx%d\n",width,height);
- if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
- /* aspected dimensions */
- s->aspected_width = get_bits(&s->gb, 8);
- s->aspected_height = get_bits(&s->gb, 8);
- }else{
- s->aspected_width = pixel_aspect[s->aspect_ratio_info][0];
- s->aspected_height= pixel_aspect[s->aspect_ratio_info][1];
- }
- } else {
- width = h263_format[format][0];
- height = h263_format[format][1];
- }
- if ((width == 0) || (height == 0))
- return -1;
- s->width = width;
- s->height = height;
- if (s->umvplus) {
- if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
- skip_bits1(&s->gb);
- }
- }
-
- s->qscale = get_bits(&s->gb, 5);
- }
- /* PEI */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
- s->f_code = 1;
-
- if(s->h263_aic){
- s->y_dc_scale_table=
- s->c_dc_scale_table= h263_aic_dc_scale_table;
- }else{
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- }
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("qp:%d %c size:%d rnd:%d %s %s %s %s\n",
- s->qscale, av_get_pict_type_char(s->pict_type),
- s->gb.size_in_bits, 1-s->no_rounding,
- s->mv_type == MV_TYPE_8X8 ? "ADV" : "",
- s->umvplus ? "UMV" : "",
- s->h263_long_vectors ? "LONG" : "",
- s->h263_plus ? "+" : ""
- );
- }
-
-
- return 0;
-}
-
-static void mpeg4_decode_sprite_trajectory(MpegEncContext * s)
-{
- int i;
- int a= 2<<s->sprite_warping_accuracy;
- int rho= 3-s->sprite_warping_accuracy;
- int r=16/a;
- const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes
- int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
- int sprite_ref[4][2];
- int virtual_ref[2][2];
- int w2, h2, w3, h3;
- int alpha=0, beta=0;
- int w= s->width;
- int h= s->height;
- int min_ab;
-
- for(i=0; i<s->num_sprite_warping_points; i++){
- int length;
- int x=0, y=0;
-
- length= get_vlc(&s->gb, &sprite_trajectory);
- if(length){
- x= get_xbits(&s->gb, length);
- }
- if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(&s->gb); /* marker bit */
-
- length= get_vlc(&s->gb, &sprite_trajectory);
- if(length){
- y=get_xbits(&s->gb, length);
- }
- skip_bits1(&s->gb); /* marker bit */
-//printf("%d %d %d %d\n", x, y, i, s->sprite_warping_accuracy);
- d[i][0]= x;
- d[i][1]= y;
- }
-
- while((1<<alpha)<w) alpha++;
- while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h'
- w2= 1<<alpha;
- h2= 1<<beta;
-
-// Note, the 4th point isnt used for GMC
- if(s->divx_version==500 && s->divx_build==413){
- sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
- sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
- sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
- sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
- sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
- sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
- } else {
- sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
- sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
- sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
- sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
- sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
- sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
- }
-/* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]);
- sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */
-
-// this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...)
-// perhaps it should be reordered to be more readable ...
-// the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides
-// so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form
- virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
- + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w);
- virtual_ref[0][1]= 16*vop_ref[0][1]
- + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w);
- virtual_ref[1][0]= 16*vop_ref[0][0]
- + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h);
- virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
- + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h);
-
- switch(s->num_sprite_warping_points)
- {
- case 0:
- s->sprite_offset[0][0]= 0;
- s->sprite_offset[0][1]= 0;
- s->sprite_offset[1][0]= 0;
- s->sprite_offset[1][1]= 0;
- s->sprite_delta[0][0]= a;
- s->sprite_delta[0][1]= 0;
- s->sprite_delta[1][0]= 0;
- s->sprite_delta[1][1]= a;
- s->sprite_shift[0]= 0;
- s->sprite_shift[1]= 0;
- break;
- case 1: //GMC only
- s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0];
- s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1];
- s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
- s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
- s->sprite_delta[0][0]= a;
- s->sprite_delta[0][1]= 0;
- s->sprite_delta[1][0]= 0;
- s->sprite_delta[1][1]= a;
- s->sprite_shift[0]= 0;
- s->sprite_shift[1]= 0;
- break;
- case 2:
- s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho))
- + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
- + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
- + (1<<(alpha+rho-1));
- s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho))
- + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
- + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
- + (1<<(alpha+rho-1));
- s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
- +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
- +2*w2*r*sprite_ref[0][0]
- - 16*w2
- + (1<<(alpha+rho+1)));
- s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
- +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
- +2*w2*r*sprite_ref[0][1]
- - 16*w2
- + (1<<(alpha+rho+1)));
- s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
- s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
- s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
- s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
-
- s->sprite_shift[0]= alpha+rho;
- s->sprite_shift[1]= alpha+rho+2;
- break;
- case 3:
- min_ab= FFMIN(alpha, beta);
- w3= w2>>min_ab;
- h3= h2>>min_ab;
- s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
- + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
- + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
- + (1<<(alpha+beta+rho-min_ab-1));
- s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
- + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
- + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
- + (1<<(alpha+beta+rho-min_ab-1));
- s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
- + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
- + 2*w2*h3*r*sprite_ref[0][0]
- - 16*w2*h3
- + (1<<(alpha+beta+rho-min_ab+1));
- s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
- + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
- + 2*w2*h3*r*sprite_ref[0][1]
- - 16*w2*h3
- + (1<<(alpha+beta+rho-min_ab+1));
- s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
- s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
- s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
- s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
-
- s->sprite_shift[0]= alpha + beta + rho - min_ab;
- s->sprite_shift[1]= alpha + beta + rho - min_ab + 2;
- break;
- }
- /* try to simplify the situation */
- if( s->sprite_delta[0][0] == a<<s->sprite_shift[0]
- && s->sprite_delta[0][1] == 0
- && s->sprite_delta[1][0] == 0
- && s->sprite_delta[1][1] == a<<s->sprite_shift[0])
- {
- s->sprite_offset[0][0]>>=s->sprite_shift[0];
- s->sprite_offset[0][1]>>=s->sprite_shift[0];
- s->sprite_offset[1][0]>>=s->sprite_shift[1];
- s->sprite_offset[1][1]>>=s->sprite_shift[1];
- s->sprite_delta[0][0]= a;
- s->sprite_delta[0][1]= 0;
- s->sprite_delta[1][0]= 0;
- s->sprite_delta[1][1]= a;
- s->sprite_shift[0]= 0;
- s->sprite_shift[1]= 0;
- s->real_sprite_warping_points=1;
- }
- else{
- int shift_y= 16 - s->sprite_shift[0];
- int shift_c= 16 - s->sprite_shift[1];
-//printf("shifts %d %d\n", shift_y, shift_c);
- for(i=0; i<2; i++){
- s->sprite_offset[0][i]<<= shift_y;
- s->sprite_offset[1][i]<<= shift_c;
- s->sprite_delta[0][i]<<= shift_y;
- s->sprite_delta[1][i]<<= shift_y;
- s->sprite_shift[i]= 16;
- }
- s->real_sprite_warping_points= s->num_sprite_warping_points;
- }
-#if 0
-printf("vop:%d:%d %d:%d %d:%d, sprite:%d:%d %d:%d %d:%d, virtual: %d:%d %d:%d\n",
- vop_ref[0][0], vop_ref[0][1],
- vop_ref[1][0], vop_ref[1][1],
- vop_ref[2][0], vop_ref[2][1],
- sprite_ref[0][0], sprite_ref[0][1],
- sprite_ref[1][0], sprite_ref[1][1],
- sprite_ref[2][0], sprite_ref[2][1],
- virtual_ref[0][0], virtual_ref[0][1],
- virtual_ref[1][0], virtual_ref[1][1]
- );
-
-printf("offset: %d:%d , delta: %d %d %d %d, shift %d\n",
- s->sprite_offset[0][0], s->sprite_offset[0][1],
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- s->sprite_shift[0]
- );
-#endif
-}
-
-static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){
- int hours, minutes, seconds;
-
- hours= get_bits(gb, 5);
- minutes= get_bits(gb, 6);
- skip_bits1(gb);
- seconds= get_bits(gb, 6);
-
- s->time_base= seconds + 60*(minutes + 60*hours);
-
- skip_bits1(gb);
- skip_bits1(gb);
-
- return 0;
-}
-
-static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
- int width, height, vo_ver_id;
-
- /* vol header */
- skip_bits(gb, 1); /* random access */
- s->vo_type= get_bits(gb, 8);
- if (get_bits1(gb) != 0) { /* is_ol_id */
- vo_ver_id = get_bits(gb, 4); /* vo_ver_id */
- skip_bits(gb, 3); /* vo_priority */
- } else {
- vo_ver_id = 1;
- }
-//printf("vo type:%d\n",s->vo_type);
- s->aspect_ratio_info= get_bits(gb, 4);
- if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){
- s->aspected_width = get_bits(gb, 8); // par_width
- s->aspected_height = get_bits(gb, 8); // par_height
- }else{
- s->aspected_width = pixel_aspect[s->aspect_ratio_info][0];
- s->aspected_height= pixel_aspect[s->aspect_ratio_info][1];
- }
-
- if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */
- int chroma_format= get_bits(gb, 2);
- if(chroma_format!=1){
- printf("illegal chroma format\n");
- }
- s->low_delay= get_bits1(gb);
- if(get_bits1(gb)){ /* vbv parameters */
- get_bits(gb, 15); /* first_half_bitrate */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* latter_half_bitrate */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* first_half_vbv_buffer_size */
- skip_bits1(gb); /* marker */
- get_bits(gb, 3); /* latter_half_vbv_buffer_size */
- get_bits(gb, 11); /* first_half_vbv_occupancy */
- skip_bits1(gb); /* marker */
- get_bits(gb, 15); /* latter_half_vbv_occupancy */
- skip_bits1(gb); /* marker */
- }
- }else{
- // set low delay flag only once so the smart? low delay detection wont be overriden
- if(s->picture_number==0)
- s->low_delay=0;
- }
-
- s->shape = get_bits(gb, 2); /* vol shape */
- if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n");
- if(s->shape == GRAY_SHAPE && vo_ver_id != 1){
- printf("Gray shape not supported\n");
- skip_bits(gb, 4); //video_object_layer_shape_extension
- }
-
- check_marker(gb, "before time_increment_resolution");
-
- s->time_increment_resolution = get_bits(gb, 16);
-
- s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1;
- if (s->time_increment_bits < 1)
- s->time_increment_bits = 1;
-
- check_marker(gb, "before fixed_vop_rate");
-
- if (get_bits1(gb) != 0) { /* fixed_vop_rate */
- skip_bits(gb, s->time_increment_bits);
- }
-
- if (s->shape != BIN_ONLY_SHAPE) {
- if (s->shape == RECT_SHAPE) {
- skip_bits1(gb); /* marker */
- width = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- height = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- if(width && height){ /* they should be non zero but who knows ... */
- s->width = width;
- s->height = height;
-// printf("width/height: %d %d\n", width, height);
- }
- }
-
- s->progressive_sequence= get_bits1(gb)^1;
- if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
- printf("OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */
- if (vo_ver_id == 1) {
- s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */
- } else {
- s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */
- }
- if(s->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n");
- if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){
- if(s->vol_sprite_usage==STATIC_SPRITE){
- s->sprite_width = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- s->sprite_height= get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- s->sprite_left = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- s->sprite_top = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- }
- s->num_sprite_warping_points= get_bits(gb, 6);
- s->sprite_warping_accuracy = get_bits(gb, 2);
- s->sprite_brightness_change= get_bits1(gb);
- if(s->vol_sprite_usage==STATIC_SPRITE)
- s->low_latency_sprite= get_bits1(gb);
- }
- // FIXME sadct disable bit if verid!=1 && shape not rect
-
- if (get_bits1(gb) == 1) { /* not_8_bit */
- s->quant_precision = get_bits(gb, 4); /* quant_precision */
- if(get_bits(gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */
- if(s->quant_precision!=5) printf("quant precission %d\n", s->quant_precision);
- } else {
- s->quant_precision = 5;
- }
-
- // FIXME a bunch of grayscale shape things
-
- if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */
- int i, v;
-
- /* load default matrixes */
- for(i=0; i<64; i++){
- int j= s->dsp.idct_permutation[i];
- v= ff_mpeg4_default_intra_matrix[i];
- s->intra_matrix[j]= v;
- s->chroma_intra_matrix[j]= v;
-
- v= ff_mpeg4_default_non_intra_matrix[i];
- s->inter_matrix[j]= v;
- s->chroma_inter_matrix[j]= v;
- }
-
- /* load custom intra matrix */
- if(get_bits1(gb)){
- int last=0;
- for(i=0; i<64; i++){
- int j;
- v= get_bits(gb, 8);
- if(v==0) break;
-
- last= v;
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->intra_matrix[j]= v;
- s->chroma_intra_matrix[j]= v;
- }
-
- /* replicate last value */
- for(; i<64; i++){
- int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->intra_matrix[j]= last;
- s->chroma_intra_matrix[j]= last;
- }
- }
-
- /* load custom non intra matrix */
- if(get_bits1(gb)){
- int last=0;
- for(i=0; i<64; i++){
- int j;
- v= get_bits(gb, 8);
- if(v==0) break;
-
- last= v;
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->inter_matrix[j]= v;
- s->chroma_inter_matrix[j]= v;
- }
-
- /* replicate last value */
- for(; i<64; i++){
- int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->inter_matrix[j]= last;
- s->chroma_inter_matrix[j]= last;
- }
- }
-
- // FIXME a bunch of grayscale shape things
- }
-
- if(vo_ver_id != 1)
- s->quarter_sample= get_bits1(gb);
- else s->quarter_sample=0;
-
- if(!get_bits1(gb)) printf("Complexity estimation not supported\n");
-
- s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */
-
- s->data_partitioning= get_bits1(gb);
- if(s->data_partitioning){
- s->rvlc= get_bits1(gb);
- }
-
- if(vo_ver_id != 1) {
- s->new_pred= get_bits1(gb);
- if(s->new_pred){
- printf("new pred not supported\n");
- skip_bits(gb, 2); /* requested upstream message type */
- skip_bits1(gb); /* newpred segment type */
- }
- s->reduced_res_vop= get_bits1(gb);
- if(s->reduced_res_vop) printf("reduced resolution VOP not supported\n");
- }
- else{
- s->new_pred=0;
- s->reduced_res_vop= 0;
- }
-
- s->scalability= get_bits1(gb);
-
- if (s->scalability) {
- GetBitContext bak= *gb;
- int ref_layer_id;
- int ref_layer_sampling_dir;
- int h_sampling_factor_n;
- int h_sampling_factor_m;
- int v_sampling_factor_n;
- int v_sampling_factor_m;
-
- s->hierachy_type= get_bits1(gb);
- ref_layer_id= get_bits(gb, 4);
- ref_layer_sampling_dir= get_bits1(gb);
- h_sampling_factor_n= get_bits(gb, 5);
- h_sampling_factor_m= get_bits(gb, 5);
- v_sampling_factor_n= get_bits(gb, 5);
- v_sampling_factor_m= get_bits(gb, 5);
- s->enhancement_type= get_bits1(gb);
-
- if( h_sampling_factor_n==0 || h_sampling_factor_m==0
- || v_sampling_factor_n==0 || v_sampling_factor_m==0){
-
-// fprintf(stderr, "illegal scalability header (VERY broken encoder), trying to workaround\n");
- s->scalability=0;
-
- *gb= bak;
- }else
- printf("scalability not supported\n");
-
- // bin shape stuff FIXME
- }
- }
- return 0;
-}
-
-/**
- * decodes the user data stuff in the header.
- * allso inits divx/xvid/lavc_version/build
- */
-static int decode_user_data(MpegEncContext *s, GetBitContext *gb){
- char buf[256];
- int i;
- int e;
- int ver, build, ver2, ver3;
- char last;
-
- buf[0]= show_bits(gb, 8);
- for(i=1; i<256; i++){
- buf[i]= show_bits(gb, 16)&0xFF;
- if(buf[i]==0) break;
- skip_bits(gb, 8);
- }
- buf[255]=0;
-
- /* divx detection */
- e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last);
- if(e<2)
- e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last);
- if(e>=2){
- s->divx_version= ver;
- s->divx_build= build;
- s->divx_packed= e==3 && last=='p';
- }
-
- /* ffmpeg detection */
- e=sscanf(buf, "FFmpeg%d.%d.%db%d", &ver, &ver2, &ver3, &build);
- if(e!=4)
- e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
- if(e!=4){
- if(strcmp(buf, "ffmpeg")==0){
- s->ffmpeg_version= 0x000406;
- s->lavc_build= 4600;
- }
- }
- if(e==4){
- s->ffmpeg_version= ver*256*256 + ver2*256 + ver3;
- s->lavc_build= build;
- }
-
- /* xvid detection */
- e=sscanf(buf, "XviD%d", &build);
- if(e==1){
- s->xvid_build= build;
- }
-
-//printf("User Data: %s\n", buf);
- return 0;
-}
-
-static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
- int time_incr, time_increment;
-
- s->pict_type = get_bits(gb, 2) + I_TYPE; /* pict type: I = 0 , P = 1 */
- if(s->pict_type==B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){
- printf("low_delay flag set, but shouldnt, clearing it\n");
- s->low_delay=0;
- }
-
- s->partitioned_frame= s->data_partitioning && s->pict_type!=B_TYPE;
- if(s->partitioned_frame)
- s->decode_mb= mpeg4_decode_partitioned_mb;
- else
- s->decode_mb= ff_h263_decode_mb;
-
- if(s->time_increment_resolution==0){
- s->time_increment_resolution=1;
-// fprintf(stderr, "time_increment_resolution is illegal\n");
- }
- time_incr=0;
- while (get_bits1(gb) != 0)
- time_incr++;
-
- check_marker(gb, "before time_increment");
-
- if(s->time_increment_bits==0){
- printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n");
-
- for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){
- if(show_bits(gb, s->time_increment_bits+1)&1) break;
- }
-
- printf("my guess is %d bits ;)\n",s->time_increment_bits);
- }
-
- if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further
- else time_increment= get_bits(gb, s->time_increment_bits);
-
-// printf("%d %X\n", s->time_increment_bits, time_increment);
-//printf(" type:%d modulo_time_base:%d increment:%d\n", s->pict_type, time_incr, time_increment);
- if(s->pict_type!=B_TYPE){
- s->last_time_base= s->time_base;
- s->time_base+= time_incr;
- s->time= s->time_base*s->time_increment_resolution + time_increment;
- if(s->workaround_bugs&FF_BUG_UMP4){
- if(s->time < s->last_non_b_time){
-// fprintf(stderr, "header is not mpeg4 compatible, broken encoder, trying to workaround\n");
- s->time_base++;
- s->time+= s->time_increment_resolution;
- }
- }
- s->pp_time= s->time - s->last_non_b_time;
- s->last_non_b_time= s->time;
- }else{
- s->time= (s->last_time_base + time_incr)*s->time_increment_resolution + time_increment;
- s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
- if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){
-// printf("messed up order, seeking?, skiping current b frame\n");
- return FRAME_SKIPED;
- }
-
- if(s->t_frame==0) s->t_frame= s->time - s->last_time_base;
- if(s->t_frame==0) s->t_frame=1; // 1/0 protection
-//printf("%Ld %Ld %d %d\n", s->last_non_b_time, s->time, s->pp_time, s->t_frame); fflush(stdout);
- s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame)
- - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
- s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame)
- - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
- }
-
- s->current_picture.pts= s->time*1000LL*1000LL / s->time_increment_resolution;
- if(s->avctx->debug&FF_DEBUG_PTS)
- printf("MPEG4 PTS: %f\n", s->current_picture.pts/(1000.0*1000.0));
-
- check_marker(gb, "before vop_coded");
-
- /* vop coded */
- if (get_bits1(gb) != 1){
- printf("vop not coded\n");
- return FRAME_SKIPED;
- }
-//printf("time %d %d %d || %Ld %Ld %Ld\n", s->time_increment_bits, s->time_increment_resolution, s->time_base,
-//s->time, s->last_non_b_time, s->last_non_b_time - s->pp_time);
- if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE
- || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) {
- /* rounding type for motion estimation */
- s->no_rounding = get_bits1(gb);
- } else {
- s->no_rounding = 0;
- }
-//FIXME reduced res stuff
-
- if (s->shape != RECT_SHAPE) {
- if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) {
- int width, height, hor_spat_ref, ver_spat_ref;
-
- width = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- height = get_bits(gb, 13);
- skip_bits1(gb); /* marker */
- hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */
- skip_bits1(gb); /* marker */
- ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */
- }
- skip_bits1(gb); /* change_CR_disable */
-
- if (get_bits1(gb) != 0) {
- skip_bits(gb, 8); /* constant_alpha_value */
- }
- }
-//FIXME complexity estimation stuff
-
- if (s->shape != BIN_ONLY_SHAPE) {
- int t;
- t=get_bits(gb, 3); /* intra dc VLC threshold */
-//printf("threshold %d\n", t);
- if(!s->progressive_sequence){
- s->top_field_first= get_bits1(gb);
- s->alternate_scan= get_bits1(gb);
- }else
- s->alternate_scan= 0;
- }
-
- if(s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
- } else{
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
- }
-
- if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){
- mpeg4_decode_sprite_trajectory(s);
- if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n");
- if(s->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n");
- }
-
- if (s->shape != BIN_ONLY_SHAPE) {
- s->qscale = get_bits(gb, s->quant_precision);
- if(s->qscale==0){
- printf("Error, header damaged or not MPEG4 header (qscale=0)\n");
- return -1; // makes no sense to continue, as there is nothing left from the image then
- }
-
- if (s->pict_type != I_TYPE) {
- s->f_code = get_bits(gb, 3); /* fcode_for */
- if(s->f_code==0){
- printf("Error, header damaged or not MPEG4 header (f_code=0)\n");
- return -1; // makes no sense to continue, as the MV decoding will break very quickly
- }
- }else
- s->f_code=1;
-
- if (s->pict_type == B_TYPE) {
- s->b_code = get_bits(gb, 3);
- }else
- s->b_code=1;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s\n",
- s->qscale, s->f_code, s->b_code,
- s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
- gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first,
- s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points,
- s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ");
- }
-
- if(!s->scalability){
- if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) {
- skip_bits1(gb); // vop shape coding type
- }
- }else{
- if(s->enhancement_type){
- int load_backward_shape= get_bits1(gb);
- if(load_backward_shape){
- printf("load backward shape isnt supported\n");
- }
- }
- skip_bits(gb, 2); //ref_select_code
- }
- }
- /* detect buggy encoders which dont set the low_delay flag (divx4/xvid/opendivx)*/
- // note we cannot detect divx5 without b-frames easyly (allthough its buggy too)
- if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==0 && s->picture_number==0){
- printf("looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
- s->low_delay=1;
- }
-
- s->picture_number++; // better than pic number==0 allways ;)
-
- s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support
- s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
-
- if(s->workaround_bugs&FF_BUG_EDGE){
- s->h_edge_pos= s->width;
- s->v_edge_pos= s->height;
- }
- return 0;
-}
-
-/**
- * decode mpeg4 headers
- * @return <0 if no VOP found (or a damaged one)
- * FRAME_SKIPPED if a not coded VOP is found
- * 0 if a VOP is found
- */
-int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
-{
- int startcode, v;
-
- /* search next start code */
- align_get_bits(gb);
- startcode = 0xff;
- for(;;) {
- v = get_bits(gb, 8);
- startcode = ((startcode << 8) | v) & 0xffffffff;
-
- if(get_bits_count(gb) >= gb->size_in_bits){
- if(gb->size_in_bits==8 && s->divx_version){
- printf("frame skip %d\n", gb->size_in_bits);
- return FRAME_SKIPED; //divx bug
- }else
- return -1; //end of stream
- }
-
- if((startcode&0xFFFFFF00) != 0x100)
- continue; //no startcode
-
- if(s->avctx->debug&FF_DEBUG_STARTCODE){
- printf("startcode: %3X ", startcode);
- if (startcode<=0x11F) printf("Video Object Start");
- else if(startcode<=0x12F) printf("Video Object Layer Start");
- else if(startcode<=0x13F) printf("Reserved");
- else if(startcode<=0x15F) printf("FGS bp start");
- else if(startcode<=0x1AF) printf("Reserved");
- else if(startcode==0x1B0) printf("Visual Object Seq Start");
- else if(startcode==0x1B1) printf("Visual Object Seq End");
- else if(startcode==0x1B2) printf("User Data");
- else if(startcode==0x1B3) printf("Group of VOP start");
- else if(startcode==0x1B4) printf("Video Session Error");
- else if(startcode==0x1B5) printf("Visual Object Start");
- else if(startcode==0x1B6) printf("Video Object Plane start");
- else if(startcode==0x1B7) printf("slice start");
- else if(startcode==0x1B8) printf("extension start");
- else if(startcode==0x1B9) printf("fgs start");
- else if(startcode==0x1BA) printf("FBA Object start");
- else if(startcode==0x1BB) printf("FBA Object Plane start");
- else if(startcode==0x1BC) printf("Mesh Object start");
- else if(startcode==0x1BD) printf("Mesh Object Plane start");
- else if(startcode==0x1BE) printf("Still Textutre Object start");
- else if(startcode==0x1BF) printf("Textutre Spatial Layer start");
- else if(startcode==0x1C0) printf("Textutre SNR Layer start");
- else if(startcode==0x1C1) printf("Textutre Tile start");
- else if(startcode==0x1C2) printf("Textutre Shape Layer start");
- else if(startcode==0x1C3) printf("stuffing start");
- else if(startcode<=0x1C5) printf("reserved");
- else if(startcode<=0x1FF) printf("System start");
- printf(" at %d\n", get_bits_count(gb));
- }
-
- switch(startcode){
- case 0x120:
- if(decode_vol_header(s, gb) < 0)
- return -1;
- break;
- case USER_DATA_STARTCODE:
- decode_user_data(s, gb);
- break;
- case GOP_STARTCODE:
- mpeg4_decode_gop_header(s, gb);
- break;
- case VOP_STARTCODE:
- return decode_vop_header(s, gb);
- default:
- break;
- }
-
- align_get_bits(gb);
- startcode = 0xff;
- }
-}
-
-/* don't understand why they choose a different header ! */
-int intel_h263_decode_picture_header(MpegEncContext *s)
-{
- int format;
-
- /* picture header */
- if (get_bits_long(&s->gb, 22) != 0x20) {
- fprintf(stderr, "Bad picture start code\n");
- return -1;
- }
- s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
-
- if (get_bits1(&s->gb) != 1) {
- fprintf(stderr, "Bad marker\n");
- return -1; /* marker */
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Bad H263 id\n");
- return -1; /* h263 id */
- }
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
-
- format = get_bits(&s->gb, 3);
- if (format != 7) {
- fprintf(stderr, "Intel H263 free format not supported\n");
- return -1;
- }
- s->h263_plus = 0;
-
- s->pict_type = I_TYPE + get_bits1(&s->gb);
-
- s->unrestricted_mv = get_bits1(&s->gb);
- s->h263_long_vectors = s->unrestricted_mv;
-
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "SAC not supported\n");
- return -1; /* SAC: off */
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "Advanced Prediction Mode not supported\n");
- return -1; /* advanced prediction mode: off */
- }
- if (get_bits1(&s->gb) != 0) {
- fprintf(stderr, "PB frame mode no supported\n");
- return -1; /* PB frame mode */
- }
-
- /* skip unknown header garbage */
- skip_bits(&s->gb, 41);
-
- s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
-
- /* PEI */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
- s->f_code = 1;
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
-
- return 0;
-}
-
-int flv_h263_decode_picture_header(MpegEncContext *s)
-{
- int format, width, height;
-
- /* picture header */
- if (get_bits_long(&s->gb, 17) != 1) {
- fprintf(stderr, "Bad picture start code\n");
- return -1;
- }
- format = get_bits(&s->gb, 5);
- if (format != 0 && format != 1) {
- fprintf(stderr, "Bad picture format\n");
- return -1;
- }
- s->h263_flv = format+1;
- s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
- format = get_bits(&s->gb, 3);
- switch (format) {
- case 0:
- width = get_bits(&s->gb, 8);
- height = get_bits(&s->gb, 8);
- break;
- case 1:
- width = get_bits(&s->gb, 16);
- height = get_bits(&s->gb, 16);
- break;
- case 2:
- width = 352;
- height = 288;
- break;
- case 3:
- width = 176;
- height = 144;
- break;
- case 4:
- width = 128;
- height = 96;
- break;
- case 5:
- width = 320;
- height = 240;
- break;
- case 6:
- width = 160;
- height = 120;
- break;
- default:
- width = height = 0;
- break;
- }
- if ((width == 0) || (height == 0))
- return -1;
- s->width = width;
- s->height = height;
-
- s->pict_type = I_TYPE + get_bits(&s->gb, 2);
- if (s->pict_type > P_TYPE)
- s->pict_type = P_TYPE;
- skip_bits1(&s->gb); /* deblocking flag */
- s->qscale = get_bits(&s->gb, 5);
-
- s->h263_plus = 0;
-
- s->unrestricted_mv = 1;
- s->h263_long_vectors = 0;
-
- /* PEI */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
- s->f_code = 1;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO){
- printf("%c esc_type:%d, qp:%d num:%d\n",
- av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number);
- }
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
-
- return 0;
-}
+++ /dev/null
-/**
- * @file h263data.h
- * H.263 tables.
- */
-
-
-/* intra MCBPC, mb_type = (intra), then (intraq) */
-const uint8_t intra_MCBPC_code[9] = { 1, 1, 2, 3, 1, 1, 2, 3, 1 };
-const uint8_t intra_MCBPC_bits[9] = { 1, 3, 3, 3, 4, 6, 6, 6, 9 };
-
-/* inter MCBPC, mb_type = (inter), (intra), (interq), (intraq), (inter4v) */
-/* Changed the tables for interq and inter4v+q, following the standard ** Juanjo ** */
-const uint8_t inter_MCBPC_code[28] = {
- 1, 3, 2, 5,
- 3, 4, 3, 3,
- 3, 7, 6, 5,
- 4, 4, 3, 2,
- 2, 5, 4, 5,
- 1, 0, 0, 0, /* Stuffing */
- 2, 12, 14, 15,
-};
-const uint8_t inter_MCBPC_bits[28] = {
- 1, 4, 4, 6, /* inter */
- 5, 8, 8, 7, /* intra */
- 3, 7, 7, 9, /* interQ */
- 6, 9, 9, 9, /* intraQ */
- 3, 7, 7, 8, /* inter4 */
- 9, 0, 0, 0, /* Stuffing */
- 11, 13, 13, 13,/* inter4Q*/
-};
-
-const uint8_t cbpy_tab[16][2] =
-{
- {3,4}, {5,5}, {4,5}, {9,4}, {3,5}, {7,4}, {2,6}, {11,4},
- {2,5}, {3,6}, {5,4}, {10,4}, {4,4}, {8,4}, {6,4}, {3,2}
-};
-
-const uint8_t mvtab[33][2] =
-{
- {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7},
- {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10},
- {12,10}, {11,10}, {10,10}, {9,10}, {8,10}, {7,10}, {6,10}, {5,10},
- {4,10}, {7,11}, {6,11}, {5,11}, {4,11}, {3,11}, {2,11}, {3,12},
- {2,12}
-};
-
-/* third non intra table */
-const uint16_t inter_vlc[103][2] = {
-{ 0x2, 2 },{ 0xf, 4 },{ 0x15, 6 },{ 0x17, 7 },
-{ 0x1f, 8 },{ 0x25, 9 },{ 0x24, 9 },{ 0x21, 10 },
-{ 0x20, 10 },{ 0x7, 11 },{ 0x6, 11 },{ 0x20, 11 },
-{ 0x6, 3 },{ 0x14, 6 },{ 0x1e, 8 },{ 0xf, 10 },
-{ 0x21, 11 },{ 0x50, 12 },{ 0xe, 4 },{ 0x1d, 8 },
-{ 0xe, 10 },{ 0x51, 12 },{ 0xd, 5 },{ 0x23, 9 },
-{ 0xd, 10 },{ 0xc, 5 },{ 0x22, 9 },{ 0x52, 12 },
-{ 0xb, 5 },{ 0xc, 10 },{ 0x53, 12 },{ 0x13, 6 },
-{ 0xb, 10 },{ 0x54, 12 },{ 0x12, 6 },{ 0xa, 10 },
-{ 0x11, 6 },{ 0x9, 10 },{ 0x10, 6 },{ 0x8, 10 },
-{ 0x16, 7 },{ 0x55, 12 },{ 0x15, 7 },{ 0x14, 7 },
-{ 0x1c, 8 },{ 0x1b, 8 },{ 0x21, 9 },{ 0x20, 9 },
-{ 0x1f, 9 },{ 0x1e, 9 },{ 0x1d, 9 },{ 0x1c, 9 },
-{ 0x1b, 9 },{ 0x1a, 9 },{ 0x22, 11 },{ 0x23, 11 },
-{ 0x56, 12 },{ 0x57, 12 },{ 0x7, 4 },{ 0x19, 9 },
-{ 0x5, 11 },{ 0xf, 6 },{ 0x4, 11 },{ 0xe, 6 },
-{ 0xd, 6 },{ 0xc, 6 },{ 0x13, 7 },{ 0x12, 7 },
-{ 0x11, 7 },{ 0x10, 7 },{ 0x1a, 8 },{ 0x19, 8 },
-{ 0x18, 8 },{ 0x17, 8 },{ 0x16, 8 },{ 0x15, 8 },
-{ 0x14, 8 },{ 0x13, 8 },{ 0x18, 9 },{ 0x17, 9 },
-{ 0x16, 9 },{ 0x15, 9 },{ 0x14, 9 },{ 0x13, 9 },
-{ 0x12, 9 },{ 0x11, 9 },{ 0x7, 10 },{ 0x6, 10 },
-{ 0x5, 10 },{ 0x4, 10 },{ 0x24, 11 },{ 0x25, 11 },
-{ 0x26, 11 },{ 0x27, 11 },{ 0x58, 12 },{ 0x59, 12 },
-{ 0x5a, 12 },{ 0x5b, 12 },{ 0x5c, 12 },{ 0x5d, 12 },
-{ 0x5e, 12 },{ 0x5f, 12 },{ 0x3, 7 },
-};
-
-const int8_t inter_level[102] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 1, 2, 3, 4,
- 5, 6, 1, 2, 3, 4, 1, 2,
- 3, 1, 2, 3, 1, 2, 3, 1,
- 2, 3, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 2, 3, 1, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
-};
-
-const int8_t inter_run[102] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 1, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 3, 3,
- 3, 4, 4, 4, 5, 5, 5, 6,
- 6, 6, 7, 7, 8, 8, 9, 9,
- 10, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 0, 0, 0, 1, 1, 2,
- 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 16, 17, 18,
- 19, 20, 21, 22, 23, 24, 25, 26,
- 27, 28, 29, 30, 31, 32, 33, 34,
- 35, 36, 37, 38, 39, 40,
-};
-
-static RLTable rl_inter = {
- 102,
- 58,
- inter_vlc,
- inter_run,
- inter_level,
-};
-
-const uint16_t intra_vlc_aic[103][2] = {
-{ 0x2, 2 }, { 0x6, 3 }, { 0xe, 4 }, { 0xc, 5 },
-{ 0xd, 5 }, { 0x10, 6 }, { 0x11, 6 }, { 0x12, 6 },
-{ 0x16, 7 }, { 0x1b, 8 }, { 0x20, 9 }, { 0x21, 9 },
-{ 0x1a, 9 }, { 0x1b, 9 }, { 0x1c, 9 }, { 0x1d, 9 },
-{ 0x1e, 9 }, { 0x1f, 9 }, { 0x23, 11 }, { 0x22, 11 },
-{ 0x57, 12 }, { 0x56, 12 }, { 0x55, 12 }, { 0x54, 12 },
-{ 0x53, 12 }, { 0xf, 4 }, { 0x14, 6 }, { 0x14, 7 },
-{ 0x1e, 8 }, { 0xf, 10 }, { 0x21, 11 }, { 0x50, 12 },
-{ 0xb, 5 }, { 0x15, 7 }, { 0xe, 10 }, { 0x9, 10 },
-{ 0x15, 6 }, { 0x1d, 8 }, { 0xd, 10 }, { 0x51, 12 },
-{ 0x13, 6 }, { 0x23, 9 }, { 0x7, 11 }, { 0x17, 7 },
-{ 0x22, 9 }, { 0x52, 12 }, { 0x1c, 8 }, { 0xc, 10 },
-{ 0x1f, 8 }, { 0xb, 10 }, { 0x25, 9 }, { 0xa, 10 },
-{ 0x24, 9 }, { 0x6, 11 }, { 0x21, 10 }, { 0x20, 10 },
-{ 0x8, 10 }, { 0x20, 11 }, { 0x7, 4 }, { 0xc, 6 },
-{ 0x10, 7 }, { 0x13, 8 }, { 0x11, 9 }, { 0x12, 9 },
-{ 0x4, 10 }, { 0x27, 11 }, { 0x26, 11 }, { 0x5f, 12 },
-{ 0xf, 6 }, { 0x13, 9 }, { 0x5, 10 }, { 0x25, 11 },
-{ 0xe, 6 }, { 0x14, 9 }, { 0x24, 11 }, { 0xd, 6 },
-{ 0x6, 10 }, { 0x5e, 12 }, { 0x11, 7 }, { 0x7, 10 },
-{ 0x13, 7 }, { 0x5d, 12 }, { 0x12, 7 }, { 0x5c, 12 },
-{ 0x14, 8 }, { 0x5b, 12 }, { 0x15, 8 }, { 0x1a, 8 },
-{ 0x19, 8 }, { 0x18, 8 }, { 0x17, 8 }, { 0x16, 8 },
-{ 0x19, 9 }, { 0x15, 9 }, { 0x16, 9 }, { 0x18, 9 },
-{ 0x17, 9 }, { 0x4, 11 }, { 0x5, 11 }, { 0x58, 12 },
-{ 0x59, 12 }, { 0x5a, 12 }, { 0x3, 7 },
-};
-
-const int8_t intra_run_aic[102] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 3, 3, 3, 3,
- 4, 4, 4, 5, 5, 5, 6, 6,
- 7, 7, 8, 8, 9, 9, 10, 11,
-12, 13, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 1, 1, 1, 1,
- 2, 2, 2, 3, 3, 3, 4, 4,
- 5, 5, 6, 6, 7, 7, 8, 9,
-10, 11, 12, 13, 14, 15, 16, 17,
-18, 19, 20, 21, 22, 23,
-};
-
-const int8_t intra_level_aic[102] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
-17, 18, 19, 20, 21, 22, 23, 24,
-25, 1, 2, 3, 4, 5, 6, 7,
- 1, 2, 3, 4, 1, 2, 3, 4,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 1,
- 1, 1, 1, 2, 3, 4, 5, 6,
- 7, 8, 9, 10, 1, 2, 3, 4,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
-};
-
-static RLTable rl_intra_aic = {
- 102,
- 58,
- intra_vlc_aic,
- intra_run_aic,
- intra_level_aic,
-};
-
-static const uint16_t h263_format[8][2] = {
- { 0, 0 },
- { 128, 96 },
- { 176, 144 },
- { 352, 288 },
- { 704, 576 },
- { 1408, 1152 },
-};
-
-static uint8_t h263_aic_dc_scale_table[32]={
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 0, 2, 4, 6, 8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
-};
-
+++ /dev/null
-/*
- * H.263 decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file h263dec.c
- * H.263 decoder.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#define DEBUG
-//#define PRINT_FRAME_TIME
-#ifdef PRINT_FRAME_TIME
-static inline long long rdtsc()
-{
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
-// printf("%d\n", int(l/1000));
- return l;
-}
-#endif
-
-int ff_h263_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->out_format = FMT_H263;
-
- s->width = avctx->width;
- s->height = avctx->height;
- s->workaround_bugs= avctx->workaround_bugs;
-
- // set defaults
- s->quant_precision=5;
- s->progressive_sequence=1;
- s->decode_mb= ff_h263_decode_mb;
- s->low_delay= 1;
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- /* select sub codec */
- switch(avctx->codec->id) {
- case CODEC_ID_H263:
- s->gob_number = 0;
- break;
- case CODEC_ID_MPEG4:
- s->time_increment_bits = 4; /* default value for broken headers */
- s->h263_pred = 1;
- s->low_delay = 0; //default, might be overriden in the vol header during header parsing
- break;
- case CODEC_ID_MSMPEG4V1:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=1;
- break;
- case CODEC_ID_MSMPEG4V2:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=2;
- break;
- case CODEC_ID_MSMPEG4V3:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=3;
- break;
- case CODEC_ID_WMV1:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=4;
- break;
- case CODEC_ID_WMV2:
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->msmpeg4_version=5;
- break;
- case CODEC_ID_H263I:
- s->h263_intel = 1;
- break;
- case CODEC_ID_FLV1:
- s->h263_flv = 1;
- break;
- default:
- return -1;
- }
- s->codec_id= avctx->codec->id;
-
- /* for h263, we allocate the images after having read the header */
- if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4)
- if (MPV_common_init(s) < 0)
- return -1;
-
- if (s->h263_msmpeg4)
- ff_msmpeg4_decode_init(s);
- else
- h263_decode_init_vlc(s);
-
- return 0;
-}
-
-int ff_h263_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-
-/**
- * retunrs the number of bytes consumed for building the current frame
- */
-static int get_consumed_bytes(MpegEncContext *s, int buf_size){
- int pos= (get_bits_count(&s->gb)+7)>>3;
-
- if(s->divx_packed){
- //we would have to scan through the whole buf to handle the weird reordering ...
- return buf_size;
- }else if(s->flags&CODEC_FLAG_TRUNCATED){
- pos -= s->parse_context.last_index;
- if(pos<0) pos=0; // padding is not really read so this might be -1
- return pos;
- }else{
- if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
- if(pos+10>buf_size) pos=buf_size; // oops ;)
-
- return pos;
- }
-}
-
-static int decode_slice(MpegEncContext *s){
- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
- s->last_resync_gb= s->gb;
- s->first_slice_line= 1;
-
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y;
-
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
-
- if(s->partitioned_frame){
- const int qscale= s->qscale;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- if(ff_mpeg4_decode_partitions(s) < 0)
- return -1;
- }
-
- /* restore variables which were modified */
- s->first_slice_line=1;
- s->mb_x= s->resync_mb_x;
- s->mb_y= s->resync_mb_y;
- s->qscale= qscale;
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
- }
-
- for(; s->mb_y < s->mb_height; s->mb_y++) {
- /* per-row end of slice checks */
- if(s->msmpeg4_version){
- if(s->resync_mb_y + s->slice_height == s->mb_y){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
-
- return 0;
- }
- }
-
- if(s->msmpeg4_version==1){
- s->last_dc[0]=
- s->last_dc[1]=
- s->last_dc[2]= 128;
- }
-
- ff_init_block_index(s);
- for(; s->mb_x < s->mb_width; s->mb_x++) {
- int ret;
-
- ff_update_block_index(s);
-
- if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){
- s->first_slice_line=0;
- }
-
- /* DCT & quantize */
- s->dsp.clear_blocks(s->block[0]);
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
-// s->mb_skiped = 0;
-//printf("%d %d %06X\n", ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
- ret= s->decode_mb(s, s->block);
-
- if (s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-
- if(ret<0){
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
- if(ret==SLICE_END){
- MPV_decode_mb(s, s->block);
-
-//printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- s->padding_bug_score--;
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- ff_draw_horiz_band(s, s->mb_y*16, 16);
- s->mb_y++;
- }
- return 0;
- }else if(ret==SLICE_NOEND){
- fprintf(stderr,"Slice mismatch at MB: %d\n", xy);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
- return -1;
- }
- fprintf(stderr,"Error at MB: %d\n", xy);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- MPV_decode_mb(s, s->block);
- }
-
- ff_draw_horiz_band(s, s->mb_y*16, 16);
-
- s->mb_x= 0;
- }
-
- assert(s->mb_x==0 && s->mb_y==s->mb_height);
-
- /* try to detect the padding bug */
- if( s->codec_id==CODEC_ID_MPEG4
- && (s->workaround_bugs&FF_BUG_AUTODETECT)
- && s->gb.size_in_bits - get_bits_count(&s->gb) >=0
- && s->gb.size_in_bits - get_bits_count(&s->gb) < 48
-// && !s->resync_marker
- && !s->data_partitioning){
-
- const int bits_count= get_bits_count(&s->gb);
- const int bits_left = s->gb.size_in_bits - bits_count;
-
- if(bits_left==0){
- s->padding_bug_score+=16;
- }else if(bits_left>8){
- s->padding_bug_score++;
- } else if(bits_left != 1){
- int v= show_bits(&s->gb, 8);
- v|= 0x7F >> (7-(bits_count&7));
-
- if(v==0x7F)
- s->padding_bug_score--;
- else
- s->padding_bug_score++;
- }
- }
-
- // handle formats which dont have unique end markers
- if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ //FIXME perhaps solve this more cleanly
- int left= s->gb.size_in_bits - get_bits_count(&s->gb);
- int max_extra=7;
-
- /* no markers in M$ crap */
- if(s->msmpeg4_version && s->pict_type==I_TYPE)
- max_extra+= 17;
-
- /* buggy padding but the frame should still end approximately at the bitstream end */
- if((s->workaround_bugs&FF_BUG_NO_PADDING) && s->error_resilience>=3)
- max_extra+= 48;
- else if((s->workaround_bugs&FF_BUG_NO_PADDING))
- max_extra+= 256*256*256*64;
-
- if(left>max_extra){
- fprintf(stderr, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));
- }
- else if(left<0){
- fprintf(stderr, "overreading %d bits\n", -left);
- }else
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
-
- return 0;
- }
-
- fprintf(stderr, "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
- s->gb.size_in_bits - get_bits_count(&s->gb),
- show_bits(&s->gb, 24), s->padding_bug_score);
-
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
-}
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int mpeg4_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
- ParseContext *pc= &s->parse_context;
- int vop_found, i;
- uint32_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!vop_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state == 0x1B6){
- i++;
- vop_found=1;
- break;
- }
- }
- }
-
- if(vop_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- pc->frame_start_found= vop_found;
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int h263_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
- ParseContext *pc= &s->parse_context;
- int vop_found, i;
- uint32_t state;
-
- vop_found= pc->frame_start_found;
- state= pc->state;
-
- i=0;
- if(!vop_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state>>(32-22) == 0x20){
- i++;
- vop_found=1;
- break;
- }
- }
- }
-
- if(vop_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state>>(32-22) == 0x20){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- pc->frame_start_found= vop_found;
- pc->state= state;
-
- return END_NOT_FOUND;
-}
-
-int ff_h263_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int ret;
- AVFrame *pict = data;
- float new_aspect;
-
-#ifdef PRINT_FRAME_TIME
-uint64_t time= rdtsc();
-#endif
-#ifdef DEBUG
- printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
- printf("bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
-#endif
- s->flags= avctx->flags;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0) {
- /* special case for last picture */
- if (s->low_delay==0 && s->next_picture_ptr) {
- *pict= *(AVFrame*)s->next_picture_ptr;
- s->next_picture_ptr= NULL;
-
- *data_size = sizeof(AVFrame);
- }
-
- return 0;
- }
-
- if(s->flags&CODEC_FLAG_TRUNCATED){
- int next;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- next= mpeg4_find_frame_end(s, buf, buf_size);
- }else if(s->codec_id==CODEC_ID_H263){
- next= h263_find_frame_end(s, buf, buf_size);
- }else{
- fprintf(stderr, "this codec doesnt support truncated bitstreams\n");
- return -1;
- }
-
- if( ff_combine_frame(s, next, &buf, &buf_size) < 0 )
- return buf_size;
- }
-
-retry:
-
- if(s->bitstream_buffer_size && buf_size<20){ //divx 5.01+ frame reorder
- init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8);
- }else
- init_get_bits(&s->gb, buf, buf_size*8);
- s->bitstream_buffer_size=0;
-
- if (!s->context_initialized) {
- if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
- return -1;
- }
-
- /* let's go :-) */
- if (s->msmpeg4_version==5) {
- ret= ff_wmv2_decode_picture_header(s);
- } else if (s->msmpeg4_version) {
- ret = msmpeg4_decode_picture_header(s);
- } else if (s->h263_pred) {
- if(s->avctx->extradata_size && s->picture_number==0){
- GetBitContext gb;
-
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
- ret = ff_mpeg4_decode_picture_header(s, &gb);
- }
- ret = ff_mpeg4_decode_picture_header(s, &s->gb);
-
- if(s->flags& CODEC_FLAG_LOW_DELAY)
- s->low_delay=1;
- } else if (s->h263_intel) {
- ret = intel_h263_decode_picture_header(s);
- } else if (s->h263_flv) {
- ret = flv_h263_decode_picture_header(s);
- } else {
- ret = h263_decode_picture_header(s);
- }
-
- if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_size);
-
- /* skip if the header was thrashed */
- if (ret < 0){
- fprintf(stderr, "header damaged\n");
- return -1;
- }
-
- avctx->has_b_frames= !s->low_delay;
-
- if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
- if(s->avctx->stream_codec_tag == ff_get_fourcc("XVID") ||
- s->avctx->codec_tag == ff_get_fourcc("XVID") || s->avctx->codec_tag == ff_get_fourcc("XVIX"))
- s->xvid_build= -1;
-#if 0
- if(s->avctx->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==1
- && s->padding_bug_score > 0 && s->low_delay) // XVID with modified fourcc
- s->xvid_build= -1;
-#endif
- }
-
- if(s->xvid_build==0 && s->divx_version==0 && s->lavc_build==0){
- if(s->avctx->codec_tag == ff_get_fourcc("DIVX") && s->vo_type==0 && s->vol_control_parameters==0)
- s->divx_version= 400; //divx 4
- }
-
- if(s->workaround_bugs&FF_BUG_AUTODETECT){
- s->workaround_bugs &= ~FF_BUG_NO_PADDING;
-
- if(s->padding_bug_score > -2 && !s->data_partitioning && (s->divx_version || !s->resync_marker))
- s->workaround_bugs |= FF_BUG_NO_PADDING;
-
- if(s->avctx->codec_tag == ff_get_fourcc("XVIX"))
- s->workaround_bugs|= FF_BUG_XVID_ILACE;
-
- if(s->avctx->codec_tag == ff_get_fourcc("UMP4")){
- s->workaround_bugs|= FF_BUG_UMP4;
- s->workaround_bugs|= FF_BUG_AC_VLC;
- }
-
- if(s->divx_version>=500){
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
- }
-
- if(s->divx_version>502){
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA2;
- }
-
- if(s->xvid_build && s->xvid_build<=3)
- s->padding_bug_score= 256*256*256*64;
-
- if(s->xvid_build && s->xvid_build<=1)
- s->workaround_bugs|= FF_BUG_QPEL_CHROMA;
-
- if(s->xvid_build && s->xvid_build<=12)
- s->workaround_bugs|= FF_BUG_EDGE;
-
-#define SET_QPEL_FUNC(postfix1, postfix2) \
- s->dsp.put_ ## postfix1 = ff_put_ ## postfix2;\
- s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;\
- s->dsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
-
- if(s->lavc_build && s->lavc_build<4653)
- s->workaround_bugs|= FF_BUG_STD_QPEL;
-
- if(s->lavc_build && s->lavc_build<4655)
- s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
-
- if(s->lavc_build && s->lavc_build<4618){
- s->workaround_bugs|= FF_BUG_EDGE;
- }
-
- if(s->divx_version)
- s->workaround_bugs|= FF_BUG_DIRECT_BLOCKSIZE;
-//printf("padding_bug_score: %d\n", s->padding_bug_score);
- if(s->divx_version==501 && s->divx_build==20020416)
- s->padding_bug_score= 256*256*256*64;
-
- if(s->divx_version && s->divx_version<500){
- s->workaround_bugs|= FF_BUG_EDGE;
- }
-
-#if 0
- if(s->divx_version==500)
- s->padding_bug_score= 256*256*256*64;
-
- /* very ugly XVID padding bug detection FIXME/XXX solve this differently
- * lets hope this at least works
- */
- if( s->resync_marker==0 && s->data_partitioning==0 && s->divx_version==0
- && s->codec_id==CODEC_ID_MPEG4 && s->vo_type==0)
- s->workaround_bugs|= FF_BUG_NO_PADDING;
-
- if(s->lavc_build && s->lavc_build<4609) //FIXME not sure about the version num but a 4609 file seems ok
- s->workaround_bugs|= FF_BUG_NO_PADDING;
-#endif
- }
-
- if(s->workaround_bugs& FF_BUG_STD_QPEL){
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
-
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
- }
-
- if(avctx->debug & FF_DEBUG_BUGS)
- printf("bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
- s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build,
- s->divx_packed ? "p" : "");
-
-#if 0 // dump bits per frame / qp / complexity
-{
- static FILE *f=NULL;
- if(!f) f=fopen("rate_qp_cplx.txt", "w");
- fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale);
-}
-#endif
-
- /* After H263 & mpeg4 header decode we have the height, width,*/
- /* and other parameters. So then we could init the picture */
- /* FIXME: By the way H263 decoder is evolving it should have */
- /* an H263EncContext */
- if(s->aspected_height)
- new_aspect= s->aspected_width*s->width / (float)(s->height*s->aspected_height);
- else
- new_aspect=0;
-
- if ( s->width != avctx->width || s->height != avctx->height
- || ABS(new_aspect - avctx->aspect_ratio) > 0.001) {
- /* H.263 could change picture size any time */
- MPV_common_end(s);
- }
- if (!s->context_initialized) {
- avctx->width = s->width;
- avctx->height = s->height;
- avctx->aspect_ratio= new_aspect;
-
- goto retry;
- }
-
- if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P))
- s->gob_index = ff_h263_get_gob_height(s);
-
- // for hurry_up==5
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- /* skip b frames if we dont have reference frames */
- if(s->last_picture_ptr==NULL && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
- /* skip b frames if we are in a hurry */
- if(avctx->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size);
-
- if(s->next_p_frame_damaged){
- if(s->pict_type==B_TYPE)
- return get_consumed_bytes(s, buf_size);
- else
- s->next_p_frame_damaged=0;
- }
-
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
-#ifdef DEBUG
- printf("qscale=%d\n", s->qscale);
-#endif
-
- ff_er_frame_start(s);
-
- //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type
- //which isnt available before MPV_frame_start()
- if (s->msmpeg4_version==5){
- if(ff_wmv2_decode_secondary_picture_header(s) < 0)
- return -1;
- }
-
- /* decode each macroblock */
- s->mb_x=0;
- s->mb_y=0;
-
- decode_slice(s);
- while(s->mb_y<s->mb_height){
- if(s->msmpeg4_version){
- if(s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
- break;
- }else{
- if(ff_h263_resync(s)<0)
- break;
- }
-
- if(s->msmpeg4_version<4 && s->h263_pred)
- ff_mpeg4_clean_buffers(s);
-
- decode_slice(s);
- }
-
- if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE)
- if(msmpeg4_decode_ext_header(s, buf_size) < 0){
- s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
- }
-
- /* divx 5.01+ bistream reorder stuff */
- if(s->codec_id==CODEC_ID_MPEG4 && s->bitstream_buffer_size==0 && s->divx_packed){
- int current_pos= get_bits_count(&s->gb)>>3;
-
- if( buf_size - current_pos > 5
- && buf_size - current_pos < BITSTREAM_BUFFER_SIZE){
- int i;
- int startcode_found=0;
- for(i=current_pos; i<buf_size-3; i++){
- if(buf[i]==0 && buf[i+1]==0 && buf[i+2]==1 && buf[i+3]==0xB6){
- startcode_found=1;
- break;
- }
- }
- if(startcode_found){
- memcpy(s->bitstream_buffer, buf + current_pos, buf_size - current_pos);
- s->bitstream_buffer_size= buf_size - current_pos;
- }
- }
- }
-
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type);
-assert(s->current_picture.pict_type == s->pict_type);
- if(s->pict_type==B_TYPE || s->low_delay){
- *pict= *(AVFrame*)&s->current_picture;
- ff_print_debug_info(s, s->current_picture_ptr);
- } else {
- *pict= *(AVFrame*)&s->last_picture;
- ff_print_debug_info(s, s->last_picture_ptr);
- }
-
- /* Return the Picture timestamp as the frame number */
- /* we substract 1 because it is added on utils.c */
- avctx->frame_number = s->picture_number - 1;
-
- /* dont output the last pic after seeking */
- if(s->last_picture_ptr || s->low_delay)
- *data_size = sizeof(AVFrame);
-#ifdef PRINT_FRAME_TIME
-printf("%Ld\n", rdtsc()-time);
-#endif
-
- return get_consumed_bytes(s, buf_size);
-}
-
-static const AVOption mpeg4_decoptions[] =
-{
- AVOPTION_SUB(avoptions_workaround_bug),
- AVOPTION_END()
-};
-
-AVCodec mpeg4_decoder = {
- "mpeg4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
- .options = mpeg4_decoptions,
- .flush= ff_mpeg_flush,
-};
-
-AVCodec h263_decoder = {
- "h263",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
- .flush= ff_mpeg_flush,
-};
-
-AVCodec msmpeg4v1_decoder = {
- "msmpeg4v1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V1,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- mpeg4_decoptions,
-};
-
-AVCodec msmpeg4v2_decoder = {
- "msmpeg4v2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V2,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- mpeg4_decoptions,
-};
-
-AVCodec msmpeg4v3_decoder = {
- "msmpeg4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V3,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- .options = mpeg4_decoptions,
-};
-
-AVCodec wmv1_decoder = {
- "wmv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV1,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- mpeg4_decoptions,
-};
-
-AVCodec h263i_decoder = {
- "h263i",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263I,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
- mpeg4_decoptions,
-};
-
-AVCodec flv_decoder = {
- "flv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FLV1,
- sizeof(MpegEncContext),
- ff_h263_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1
-};
+++ /dev/null
-/*
- * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file h264.c
- * H.264 / AVC / MPEG4 part10 codec.
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "common.h"
-#include "dsputil.h"
-#include "avcodec.h"
-#include "mpegvideo.h"
-#include "h264data.h"
-#include "golomb.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-#define interlaced_dct interlaced_dct_is_a_bad_name
-#define mb_intra mb_intra_isnt_initalized_see_mb_type
-
-#define LUMA_DC_BLOCK_INDEX 25
-#define CHROMA_DC_BLOCK_INDEX 26
-
-#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8
-#define COEFF_TOKEN_VLC_BITS 8
-#define TOTAL_ZEROS_VLC_BITS 9
-#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3
-#define RUN_VLC_BITS 3
-#define RUN7_VLC_BITS 6
-
-#define MAX_SPS_COUNT 32
-#define MAX_PPS_COUNT 256
-
-#define MAX_MMCO_COUNT 66
-
-/**
- * Sequence parameter set
- */
-typedef struct SPS{
-
- int profile_idc;
- int level_idc;
- int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4
- int poc_type; ///< pic_order_cnt_type
- int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4
- int delta_pic_order_always_zero_flag;
- int offset_for_non_ref_pic;
- int offset_for_top_to_bottom_field;
- int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle
- int ref_frame_count; ///< num_ref_frames
- int gaps_in_frame_num_allowed_flag;
- int mb_width; ///< frame_width_in_mbs_minus1 + 1
- int mb_height; ///< frame_height_in_mbs_minus1 + 1
- int frame_mbs_only_flag;
- int mb_aff; ///<mb_adaptive_frame_field_flag
- int direct_8x8_inference_flag;
- int crop; ///< frame_cropping_flag
- int crop_left; ///< frame_cropping_rect_left_offset
- int crop_right; ///< frame_cropping_rect_right_offset
- int crop_top; ///< frame_cropping_rect_top_offset
- int crop_bottom; ///< frame_cropping_rect_bottom_offset
- int vui_parameters_present_flag;
- int sar_width;
- int sar_height;
- short offset_for_ref_frame[256]; //FIXME dyn aloc?
-}SPS;
-
-/**
- * Picture parameter set
- */
-typedef struct PPS{
- int sps_id;
- int cabac; ///< entropy_coding_mode_flag
- int pic_order_present; ///< pic_order_present_flag
- int slice_group_count; ///< num_slice_groups_minus1 + 1
- int mb_slice_group_map_type;
- int ref_count[2]; ///< num_ref_idx_l0/1_active_minus1 + 1
- int weighted_pred; ///< weighted_pred_flag
- int weighted_bipred_idc;
- int init_qp; ///< pic_init_qp_minus26 + 26
- int init_qs; ///< pic_init_qs_minus26 + 26
- int chroma_qp_index_offset;
- int deblocking_filter_parameters_present; ///< deblocking_filter_parameters_present_flag
- int constrained_intra_pred; ///< constrained_intra_pred_flag
- int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag
-}PPS;
-
-/**
- * Memory management control operation opcode.
- */
-typedef enum MMCOOpcode{
- MMCO_END=0,
- MMCO_SHORT2UNUSED,
- MMCO_LONG2UNUSED,
- MMCO_SHORT2LONG,
- MMCO_SET_MAX_LONG,
- MMCO_RESET,
- MMCO_LONG,
-} MMCOOpcode;
-
-/**
- * Memory management control operation.
- */
-typedef struct MMCO{
- MMCOOpcode opcode;
- int short_frame_num;
- int long_index;
-} MMCO;
-
-/**
- * H264Context
- */
-typedef struct H264Context{
- MpegEncContext s;
- int nal_ref_idc;
- int nal_unit_type;
-#define NAL_SLICE 1
-#define NAL_DPA 2
-#define NAL_DPB 3
-#define NAL_DPC 4
-#define NAL_IDR_SLICE 5
-#define NAL_SEI 6
-#define NAL_SPS 7
-#define NAL_PPS 8
-#define NAL_PICTURE_DELIMITER 9
-#define NAL_FILTER_DATA 10
- uint8_t *rbsp_buffer;
- int rbsp_buffer_size;
-
- int chroma_qp; //QPc
-
- int prev_mb_skiped; //FIXME remove (IMHO not used)
-
- //prediction stuff
- int chroma_pred_mode;
- int intra16x16_pred_mode;
-
- int8_t intra4x4_pred_mode_cache[5*8];
- int8_t (*intra4x4_pred_mode)[8];
- void (*pred4x4 [9+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp?
- void (*pred8x8 [4+3])(uint8_t *src, int stride);
- void (*pred16x16[4+3])(uint8_t *src, int stride);
- unsigned int topleft_samples_available;
- unsigned int top_samples_available;
- unsigned int topright_samples_available;
- unsigned int left_samples_available;
-
- /**
- * non zero coeff count cache.
- * is 64 if not available.
- */
- uint8_t non_zero_count_cache[6*8];
- uint8_t (*non_zero_count)[16];
-
- /**
- * Motion vector cache.
- */
- int16_t mv_cache[2][5*8][2];
- int8_t ref_cache[2][5*8];
-#define LIST_NOT_USED -1 //FIXME rename?
-#define PART_NOT_AVAILABLE -2
-
- /**
- * is 1 if the specific list MV&references are set to 0,0,-2.
- */
- int mv_cache_clean[2];
-
- int block_offset[16+8];
- int chroma_subblock_offset[16]; //FIXME remove
-
- uint16_t *mb2b_xy; //FIXME are these 4 a good idea?
- uint16_t *mb2b8_xy;
- int b_stride;
- int b8_stride;
-
- int halfpel_flag;
- int thirdpel_flag;
-
- int unknown_svq3_flag;
- int next_slice_index;
-
- SPS sps_buffer[MAX_SPS_COUNT];
- SPS sps; ///< current sps
-
- PPS pps_buffer[MAX_PPS_COUNT];
- /**
- * current pps
- */
- PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that?
-
- int slice_num;
- uint8_t *slice_table_base;
- uint8_t *slice_table; ///< slice_table_base + mb_stride + 1
- int slice_type;
- int slice_type_fixed;
-
- //interlacing specific flags
- int mb_field_decoding_flag;
-
- int sub_mb_type[4];
-
- //POC stuff
- int poc_lsb;
- int poc_msb;
- int delta_poc_bottom;
- int delta_poc[2];
- int frame_num;
- int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0
- int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0
- int frame_num_offset; ///< for POC type 2
- int prev_frame_num_offset; ///< for POC type 2
- int prev_frame_num; ///< frame_num of the last pic for POC type 1/2
-
- /**
- * frame_num for frames or 2*frame_num for field pics.
- */
- int curr_pic_num;
-
- /**
- * max_frame_num or 2*max_frame_num for field pics.
- */
- int max_pic_num;
-
- //Weighted pred stuff
- int luma_log2_weight_denom;
- int chroma_log2_weight_denom;
- int luma_weight[2][16];
- int luma_offset[2][16];
- int chroma_weight[2][16][2];
- int chroma_offset[2][16][2];
-
- //deblock
- int disable_deblocking_filter_idc;
- int slice_alpha_c0_offset_div2;
- int slice_beta_offset_div2;
-
- int redundant_pic_count;
-
- int direct_spatial_mv_pred;
-
- /**
- * num_ref_idx_l0/1_active_minus1 + 1
- */
- int ref_count[2];// FIXME split for AFF
- Picture *short_ref[16];
- Picture *long_ref[16];
- Picture default_ref_list[2][32];
- Picture ref_list[2][32]; //FIXME size?
- Picture field_ref_list[2][32]; //FIXME size?
-
- /**
- * memory management control operations buffer.
- */
- MMCO mmco[MAX_MMCO_COUNT];
- int mmco_index;
-
- int long_ref_count; ///< number of actual long term references
- int short_ref_count; ///< number of actual short term references
-
- //data partitioning
- GetBitContext intra_gb;
- GetBitContext inter_gb;
- GetBitContext *intra_gb_ptr;
- GetBitContext *inter_gb_ptr;
-
- DCTELEM mb[16*24] __align8;
-}H264Context;
-
-static VLC coeff_token_vlc[4];
-static VLC chroma_dc_coeff_token_vlc;
-
-static VLC total_zeros_vlc[15];
-static VLC chroma_dc_total_zeros_vlc[3];
-
-static VLC run_vlc[6];
-static VLC run7_vlc;
-
-static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp);
-static void svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc);
-
-static inline uint32_t pack16to32(int a, int b){
-#ifdef WORDS_BIGENDIAN
- return (b&0xFFFF) + (a<<16);
-#else
- return (a&0xFFFF) + (b<<16);
-#endif
-}
-
-/**
- * fill a rectangle.
- * @param h height of the recatangle, should be a constant
- * @param w width of the recatangle, should be a constant
- * @param size the size of val (1 or 4), should be a constant
- */
-static inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ //FIXME ensure this IS inlined
- uint8_t *p= (uint8_t*)vp;
- assert(size==1 || size==4);
-
- w *= size;
- stride *= size;
-
-//FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it
- if(w==2 && h==2){
- *(uint16_t*)(p + 0)=
- *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101;
- }else if(w==2 && h==4){
- *(uint16_t*)(p + 0*stride)=
- *(uint16_t*)(p + 1*stride)=
- *(uint16_t*)(p + 2*stride)=
- *(uint16_t*)(p + 3*stride)= size==4 ? val : val*0x0101;
- }else if(w==4 && h==1){
- *(uint32_t*)(p + 0*stride)= size==4 ? val : val*0x01010101;
- }else if(w==4 && h==2){
- *(uint32_t*)(p + 0*stride)=
- *(uint32_t*)(p + 1*stride)= size==4 ? val : val*0x01010101;
- }else if(w==4 && h==4){
- *(uint32_t*)(p + 0*stride)=
- *(uint32_t*)(p + 1*stride)=
- *(uint32_t*)(p + 2*stride)=
- *(uint32_t*)(p + 3*stride)= size==4 ? val : val*0x01010101;
- }else if(w==8 && h==1){
- *(uint32_t*)(p + 0)=
- *(uint32_t*)(p + 4)= size==4 ? val : val*0x01010101;
- }else if(w==8 && h==2){
- *(uint32_t*)(p + 0 + 0*stride)=
- *(uint32_t*)(p + 4 + 0*stride)=
- *(uint32_t*)(p + 0 + 1*stride)=
- *(uint32_t*)(p + 4 + 1*stride)= size==4 ? val : val*0x01010101;
- }else if(w==8 && h==4){
- *(uint64_t*)(p + 0*stride)=
- *(uint64_t*)(p + 1*stride)=
- *(uint64_t*)(p + 2*stride)=
- *(uint64_t*)(p + 3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
- }else if(w==16 && h==2){
- *(uint64_t*)(p + 0+0*stride)=
- *(uint64_t*)(p + 8+0*stride)=
- *(uint64_t*)(p + 0+1*stride)=
- *(uint64_t*)(p + 8+1*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
- }else if(w==16 && h==4){
- *(uint64_t*)(p + 0+0*stride)=
- *(uint64_t*)(p + 8+0*stride)=
- *(uint64_t*)(p + 0+1*stride)=
- *(uint64_t*)(p + 8+1*stride)=
- *(uint64_t*)(p + 0+2*stride)=
- *(uint64_t*)(p + 8+2*stride)=
- *(uint64_t*)(p + 0+3*stride)=
- *(uint64_t*)(p + 8+3*stride)= size==4 ? val*0x0100000001ULL : val*0x0101010101010101ULL;
- }else
- assert(0);
-}
-
-static inline void fill_caches(H264Context *h, int mb_type){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int topleft_xy, top_xy, topright_xy, left_xy[2];
- int topleft_type, top_type, topright_type, left_type[2];
- int left_block[4];
- int i;
-
- //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it
-
- if(h->sps.mb_aff){
- //FIXME
- topleft_xy = 0; /* avoid warning */
- top_xy = 0; /* avoid warning */
- topright_xy = 0; /* avoid warning */
- }else{
- topleft_xy = mb_xy-1 - s->mb_stride;
- top_xy = mb_xy - s->mb_stride;
- topright_xy= mb_xy+1 - s->mb_stride;
- left_xy[0] = mb_xy-1;
- left_xy[1] = mb_xy-1;
- left_block[0]= 0;
- left_block[1]= 1;
- left_block[2]= 2;
- left_block[3]= 3;
- }
-
- topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0;
- top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;
- topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0;
- left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;
- left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;
-
- if(IS_INTRA(mb_type)){
- h->topleft_samples_available=
- h->top_samples_available=
- h->left_samples_available= 0xFFFF;
- h->topright_samples_available= 0xEEEA;
-
- if(!IS_INTRA(top_type) && (top_type==0 || h->pps.constrained_intra_pred)){
- h->topleft_samples_available= 0xB3FF;
- h->top_samples_available= 0x33FF;
- h->topright_samples_available= 0x26EA;
- }
- for(i=0; i<2; i++){
- if(!IS_INTRA(left_type[i]) && (left_type[i]==0 || h->pps.constrained_intra_pred)){
- h->topleft_samples_available&= 0xDF5F;
- h->left_samples_available&= 0x5F5F;
- }
- }
-
- if(!IS_INTRA(topleft_type) && (topleft_type==0 || h->pps.constrained_intra_pred))
- h->topleft_samples_available&= 0x7FFF;
-
- if(!IS_INTRA(topright_type) && (topright_type==0 || h->pps.constrained_intra_pred))
- h->topright_samples_available&= 0xFBFF;
-
- if(IS_INTRA4x4(mb_type)){
- if(IS_INTRA4x4(top_type)){
- h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];
- h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];
- h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];
- h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];
- }else{
- int pred;
- if(IS_INTRA16x16(top_type) || (IS_INTER(top_type) && !h->pps.constrained_intra_pred))
- pred= 2;
- else{
- pred= -1;
- }
- h->intra4x4_pred_mode_cache[4+8*0]=
- h->intra4x4_pred_mode_cache[5+8*0]=
- h->intra4x4_pred_mode_cache[6+8*0]=
- h->intra4x4_pred_mode_cache[7+8*0]= pred;
- }
- for(i=0; i<2; i++){
- if(IS_INTRA4x4(left_type[i])){
- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];
- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];
- }else{
- int pred;
- if(IS_INTRA16x16(left_type[i]) || (IS_INTER(left_type[i]) && !h->pps.constrained_intra_pred))
- pred= 2;
- else{
- pred= -1;
- }
- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;
- }
- }
- }
- }
-
-
-/*
-0 . T T. T T T T
-1 L . .L . . . .
-2 L . .L . . . .
-3 . T TL . . . .
-4 L . .L . . . .
-5 L . .. . . . .
-*/
-//FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec)
- if(top_type){
- h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][0];
- h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][1];
- h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][2];
- h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3];
-
- h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7];
- h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8];
-
- h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10];
- h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11];
- }else{
- h->non_zero_count_cache[4+8*0]=
- h->non_zero_count_cache[5+8*0]=
- h->non_zero_count_cache[6+8*0]=
- h->non_zero_count_cache[7+8*0]=
-
- h->non_zero_count_cache[1+8*0]=
- h->non_zero_count_cache[2+8*0]=
-
- h->non_zero_count_cache[1+8*3]=
- h->non_zero_count_cache[2+8*3]= 64;
- }
-
- if(left_type[0]){
- h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][6];
- h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][5];
- h->non_zero_count_cache[0+8*1]= h->non_zero_count[left_xy[0]][9]; //FIXME left_block
- h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12];
- }else{
- h->non_zero_count_cache[3+8*1]=
- h->non_zero_count_cache[3+8*2]=
- h->non_zero_count_cache[0+8*1]=
- h->non_zero_count_cache[0+8*4]= 64;
- }
-
- if(left_type[1]){
- h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[1]][4];
- h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[1]][3];
- h->non_zero_count_cache[0+8*2]= h->non_zero_count[left_xy[1]][8];
- h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11];
- }else{
- h->non_zero_count_cache[3+8*3]=
- h->non_zero_count_cache[3+8*4]=
- h->non_zero_count_cache[0+8*2]=
- h->non_zero_count_cache[0+8*5]= 64;
- }
-
-#if 1
- if(IS_INTER(mb_type)){
- int list;
- for(list=0; list<2; list++){
- if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){
- /*if(!h->mv_cache_clean[list]){
- memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all?
- memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t));
- h->mv_cache_clean[list]= 1;
- }*/
- continue; //FIXME direct mode ...
- }
- h->mv_cache_clean[list]= 0;
-
- if(IS_INTER(topleft_type)){
- const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride;
- const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + h->b8_stride;
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy];
- h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];
- }else{
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= 0;
- h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
-
- if(IS_INTER(top_type)){
- const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
- const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;
- *(uint32_t*)h->mv_cache[list][scan8[0] + 0 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 0];
- *(uint32_t*)h->mv_cache[list][scan8[0] + 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 1];
- *(uint32_t*)h->mv_cache[list][scan8[0] + 2 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 2];
- *(uint32_t*)h->mv_cache[list][scan8[0] + 3 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + 3];
- h->ref_cache[list][scan8[0] + 0 - 1*8]=
- h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0];
- h->ref_cache[list][scan8[0] + 2 - 1*8]=
- h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] + 0 - 1*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] + 1 - 1*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] + 2 - 1*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] + 3 - 1*8]= 0;
- *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101;
- }
-
- if(IS_INTER(topright_type)){
- const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;
- const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride;
- *(uint32_t*)h->mv_cache[list][scan8[0] + 4 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy];
- h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] + 4 - 1*8]= 0;
- h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
-
- //FIXME unify cleanup or sth
- if(IS_INTER(left_type[0])){
- const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
- const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]];
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1]];
- h->ref_cache[list][scan8[0] - 1 + 0*8]=
- h->ref_cache[list][scan8[0] - 1 + 1*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0]>>1)];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 1*8]= 0;
- h->ref_cache[list][scan8[0] - 1 + 0*8]=
- h->ref_cache[list][scan8[0] - 1 + 1*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
-
- if(IS_INTER(left_type[1])){
- const int b_xy= h->mb2b_xy[left_xy[1]] + 3;
- const int b8_xy= h->mb2b8_xy[left_xy[1]] + 1;
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 2*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[2]];
- *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 3*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[3]];
- h->ref_cache[list][scan8[0] - 1 + 2*8]=
- h->ref_cache[list][scan8[0] - 1 + 3*8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[2]>>1)];
- }else{
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 2*8]=
- *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 3*8]= 0;
- h->ref_cache[list][scan8[0] - 1 + 2*8]=
- h->ref_cache[list][scan8[0] - 1 + 3*8]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
- }
-
- h->ref_cache[list][scan8[5 ]+1] =
- h->ref_cache[list][scan8[7 ]+1] =
- h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else)
- h->ref_cache[list][scan8[4 ]] =
- h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;
- *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]=
- *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]=
- *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else)
- *(uint32_t*)h->mv_cache [list][scan8[4 ]]=
- *(uint32_t*)h->mv_cache [list][scan8[12]]= 0;
- }
-//FIXME
-
- }
-#endif
-}
-
-static inline void write_back_intra_pred_mode(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- h->intra4x4_pred_mode[mb_xy][0]= h->intra4x4_pred_mode_cache[7+8*1];
- h->intra4x4_pred_mode[mb_xy][1]= h->intra4x4_pred_mode_cache[7+8*2];
- h->intra4x4_pred_mode[mb_xy][2]= h->intra4x4_pred_mode_cache[7+8*3];
- h->intra4x4_pred_mode[mb_xy][3]= h->intra4x4_pred_mode_cache[7+8*4];
- h->intra4x4_pred_mode[mb_xy][4]= h->intra4x4_pred_mode_cache[4+8*4];
- h->intra4x4_pred_mode[mb_xy][5]= h->intra4x4_pred_mode_cache[5+8*4];
- h->intra4x4_pred_mode[mb_xy][6]= h->intra4x4_pred_mode_cache[6+8*4];
-}
-
-/**
- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
- */
-static inline int check_intra4x4_pred_mode(H264Context *h){
- MpegEncContext * const s = &h->s;
- static const int8_t top [12]= {-1, 0,LEFT_DC_PRED,-1,-1,-1,-1,-1, 0};
- static const int8_t left[12]= { 0,-1, TOP_DC_PRED, 0,-1,-1,-1, 0,-1,DC_128_PRED};
- int i;
-
- if(!(h->top_samples_available&0x8000)){
- for(i=0; i<4; i++){
- int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ];
- if(status<0){
- fprintf(stderr, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
- return -1;
- } else if(status){
- h->intra4x4_pred_mode_cache[scan8[0] + i]= status;
- }
- }
- }
-
- if(!(h->left_samples_available&0x8000)){
- for(i=0; i<4; i++){
- int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ];
- if(status<0){
- fprintf(stderr, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y);
- return -1;
- } else if(status){
- h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status;
- }
- }
- }
-
- return 0;
-} //FIXME cleanup like next
-
-/**
- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks.
- */
-static inline int check_intra_pred_mode(H264Context *h, int mode){
- MpegEncContext * const s = &h->s;
- static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1};
- static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8};
-
- if(!(h->top_samples_available&0x8000)){
- mode= top[ mode ];
- if(mode<0){
- fprintf(stderr, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- if(!(h->left_samples_available&0x8000)){
- mode= left[ mode ];
- if(mode<0){
- fprintf(stderr, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- return mode;
-}
-
-/**
- * gets the predicted intra4x4 prediction mode.
- */
-static inline int pred_intra_mode(H264Context *h, int n){
- const int index8= scan8[n];
- const int left= h->intra4x4_pred_mode_cache[index8 - 1];
- const int top = h->intra4x4_pred_mode_cache[index8 - 8];
- const int min= FFMIN(left, top);
-
- tprintf("mode:%d %d min:%d\n", left ,top, min);
-
- if(min<0) return DC_PRED;
- else return min;
-}
-
-static inline void write_back_non_zero_count(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[4+8*4];
- h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[5+8*4];
- h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[6+8*4];
- h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4];
- h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[7+8*3];
- h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[7+8*2];
- h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[7+8*1];
-
- h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[1+8*2];
- h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2];
- h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[2+8*1];
-
- h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[1+8*5];
- h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5];
- h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[2+8*4];
-}
-
-/**
- * gets the predicted number of non zero coefficients.
- * @param n block index
- */
-static inline int pred_non_zero_count(H264Context *h, int n){
- const int index8= scan8[n];
- const int left= h->non_zero_count_cache[index8 - 1];
- const int top = h->non_zero_count_cache[index8 - 8];
- int i= left + top;
-
- if(i<64) i= (i+1)>>1;
-
- tprintf("pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
-
- return i&31;
-}
-
-static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
- const int topright_ref= h->ref_cache[list][ i - 8 + part_width ];
-
- if(topright_ref != PART_NOT_AVAILABLE){
- *C= h->mv_cache[list][ i - 8 + part_width ];
- return topright_ref;
- }else{
- tprintf("topright MV not available\n");
-
- *C= h->mv_cache[list][ i - 8 - 1 ];
- return h->ref_cache[list][ i - 8 - 1 ];
- }
-}
-
-/**
- * gets the predicted MV.
- * @param n the block index
- * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
- * @param mx the x component of the predicted motion vector
- * @param my the y component of the predicted motion vector
- */
-static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){
- const int index8= scan8[n];
- const int top_ref= h->ref_cache[list][ index8 - 8 ];
- const int left_ref= h->ref_cache[list][ index8 - 1 ];
- const int16_t * const A= h->mv_cache[list][ index8 - 1 ];
- const int16_t * const B= h->mv_cache[list][ index8 - 8 ];
- const int16_t * C;
- int diagonal_ref, match_count;
-
- assert(part_width==1 || part_width==2 || part_width==4);
-
-/* mv_cache
- B . . A T T T T
- U . . L . . , .
- U . . L . . . .
- U . . L . . , .
- . . . L . . . .
-*/
-
- diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width);
- match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref);
- if(match_count > 1){ //most common
- *mx= mid_pred(A[0], B[0], C[0]);
- *my= mid_pred(A[1], B[1], C[1]);
- }else if(match_count==1){
- if(left_ref==ref){
- *mx= A[0];
- *my= A[1];
- }else if(top_ref==ref){
- *mx= B[0];
- *my= B[1];
- }else{
- *mx= C[0];
- *my= C[1];
- }
- }else{
- if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){
- *mx= A[0];
- *my= A[1];
- }else{
- *mx= mid_pred(A[0], B[0], C[0]);
- *my= mid_pred(A[1], B[1], C[1]);
- }
- }
-
- tprintf("pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);
-}
-
-/**
- * gets the directionally predicted 16x8 MV.
- * @param n the block index
- * @param mx the x component of the predicted motion vector
- * @param my the y component of the predicted motion vector
- */
-static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
- if(n==0){
- const int top_ref= h->ref_cache[list][ scan8[0] - 8 ];
- const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
-
- tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list);
-
- if(top_ref == ref){
- *mx= B[0];
- *my= B[1];
- return;
- }
- }else{
- const int left_ref= h->ref_cache[list][ scan8[8] - 1 ];
- const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ];
-
- tprintf("pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
-
- if(left_ref == ref){
- *mx= A[0];
- *my= A[1];
- return;
- }
- }
-
- //RARE
- pred_motion(h, n, 4, list, ref, mx, my);
-}
-
-/**
- * gets the directionally predicted 8x16 MV.
- * @param n the block index
- * @param mx the x component of the predicted motion vector
- * @param my the y component of the predicted motion vector
- */
-static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){
- if(n==0){
- const int left_ref= h->ref_cache[list][ scan8[0] - 1 ];
- const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
-
- tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list);
-
- if(left_ref == ref){
- *mx= A[0];
- *my= A[1];
- return;
- }
- }else{
- const int16_t * C;
- int diagonal_ref;
-
- diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2);
-
- tprintf("pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list);
-
- if(diagonal_ref == ref){
- *mx= C[0];
- *my= C[1];
- return;
- }
- }
-
- //RARE
- pred_motion(h, n, 2, list, ref, mx, my);
-}
-
-static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){
- const int top_ref = h->ref_cache[0][ scan8[0] - 8 ];
- const int left_ref= h->ref_cache[0][ scan8[0] - 1 ];
-
- tprintf("pred_pskip: (%d) (%d) at %2d %2d", top_ref, left_ref, h->s.mb_x, h->s.mb_y);
-
- if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE
- || (top_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ] == 0)
- || (left_ref == 0 && *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ] == 0)){
-
- *mx = *my = 0;
- return;
- }
-
- pred_motion(h, 0, 4, 0, 0, mx, my);
-
- return;
-}
-
-static inline void write_back_motion(H264Context *h, int mb_type){
- MpegEncContext * const s = &h->s;
- const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
- const int b8_xy= 2*s->mb_x + 2*s->mb_y*h->b8_stride;
- int list;
-
- for(list=0; list<2; list++){
- int y;
- if((!IS_8X8(mb_type)) && !USES_LIST(mb_type, list)){
- if(1){ //FIXME skip or never read if mb_type doesnt use it
- for(y=0; y<4; y++){
- *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]=
- *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0;
- }
- for(y=0; y<2; y++){
- *(uint16_t*)s->current_picture.motion_val[list][b8_xy + y*h->b8_stride]= (LIST_NOT_USED&0xFF)*0x0101;
- }
- }
- continue; //FIXME direct mode ...
- }
-
- for(y=0; y<4; y++){
- *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+0 + 8*y];
- *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= *(uint64_t*)h->mv_cache[list][scan8[0]+2 + 8*y];
- }
- for(y=0; y<2; y++){
- s->current_picture.ref_index[list][b8_xy + 0 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+0 + 16*y];
- s->current_picture.ref_index[list][b8_xy + 1 + y*h->b8_stride]= h->ref_cache[list][scan8[0]+2 + 16*y];
- }
- }
-}
-
-/**
- * Decodes a network abstraction layer unit.
- * @param consumed is the number of bytes used as input
- * @param length is the length of the array
- * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp ttailing?
- * @returns decoded bytes, might be src+1 if no escapes
- */
-static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){
- int i, si, di;
- uint8_t *dst;
-
-// src[0]&0x80; //forbidden bit
- h->nal_ref_idc= src[0]>>5;
- h->nal_unit_type= src[0]&0x1F;
-
- src++; length--;
-#if 0
- for(i=0; i<length; i++)
- printf("%2X ", src[i]);
-#endif
- for(i=0; i+1<length; i+=2){
- if(src[i]) continue;
- if(i>0 && src[i-1]==0) i--;
- if(i+2<length && src[i+1]==0 && src[i+2]<=3){
- if(src[i+2]!=3){
- /* startcode, so we must be past the end */
- length=i;
- }
- break;
- }
- }
-
- if(i>=length-1){ //no escaped 0
- *dst_length= length;
- *consumed= length+1; //+1 for the header
- return src;
- }
-
- h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length);
- dst= h->rbsp_buffer;
-
-//printf("deoding esc\n");
- si=di=0;
- while(si<length){
- //remove escapes (very rare 1:2^22)
- if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){
- if(src[si+2]==3){ //escape
- dst[di++]= 0;
- dst[di++]= 0;
- si+=3;
- }else //next start code
- break;
- }
-
- dst[di++]= src[si++];
- }
-
- *dst_length= di;
- *consumed= si + 1;//+1 for the header
-//FIXME store exact number of bits in the getbitcontext (its needed for decoding)
- return dst;
-}
-
-/**
- * @param src the data which should be escaped
- * @param dst the target buffer, dst+1 == src is allowed as a special case
- * @param length the length of the src data
- * @param dst_length the length of the dst array
- * @returns length of escaped data in bytes or -1 if an error occured
- */
-static int encode_nal(H264Context *h, uint8_t *dst, uint8_t *src, int length, int dst_length){
- int i, escape_count, si, di;
- uint8_t *temp;
-
- assert(length>=0);
- assert(dst_length>0);
-
- dst[0]= (h->nal_ref_idc<<5) + h->nal_unit_type;
-
- if(length==0) return 1;
-
- escape_count= 0;
- for(i=0; i<length; i+=2){
- if(src[i]) continue;
- if(i>0 && src[i-1]==0)
- i--;
- if(i+2<length && src[i+1]==0 && src[i+2]<=3){
- escape_count++;
- i+=2;
- }
- }
-
- if(escape_count==0){
- if(dst+1 != src)
- memcpy(dst+1, src, length);
- return length + 1;
- }
-
- if(length + escape_count + 1> dst_length)
- return -1;
-
- //this should be damn rare (hopefully)
-
- h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length + escape_count);
- temp= h->rbsp_buffer;
-//printf("encoding esc\n");
-
- si= 0;
- di= 0;
- while(si < length){
- if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){
- temp[di++]= 0; si++;
- temp[di++]= 0; si++;
- temp[di++]= 3;
- temp[di++]= src[si++];
- }
- else
- temp[di++]= src[si++];
- }
- memcpy(dst+1, temp, length+escape_count);
-
- assert(di == length+escape_count);
-
- return di + 1;
-}
-
-/**
- * write 1,10,100,1000,... for alignment, yes its exactly inverse to mpeg4
- */
-static void encode_rbsp_trailing(PutBitContext *pb){
- int length;
- put_bits(pb, 1, 1);
- length= (-get_bit_count(pb))&7;
- if(length) put_bits(pb, length, 0);
-}
-
-/**
- * identifies the exact end of the bitstream
- * @return the length of the trailing, or 0 if damaged
- */
-static int decode_rbsp_trailing(uint8_t *src){
- int v= *src;
- int r;
-
- tprintf("rbsp trailing %X\n", v);
-
- for(r=1; r<9; r++){
- if(v&1) return r;
- v>>=1;
- }
- return 0;
-}
-
-/**
- * idct tranforms the 16 dc values and dequantize them.
- * @param qp quantization parameter
- */
-static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp){
- const int qmul= dequant_coeff[qp][0];
-#define stride 16
- int i;
- int temp[16]; //FIXME check if this is a good idea
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
-//memset(block, 64, 2*256);
-//return;
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= block[offset+stride*0] + block[offset+stride*4];
- const int z1= block[offset+stride*0] - block[offset+stride*4];
- const int z2= block[offset+stride*1] - block[offset+stride*5];
- const int z3= block[offset+stride*1] + block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= temp[4*0+i] + temp[4*2+i];
- const int z1= temp[4*0+i] - temp[4*2+i];
- const int z2= temp[4*1+i] - temp[4*3+i];
- const int z3= temp[4*1+i] + temp[4*3+i];
-
- block[stride*0 +offset]= ((z0 + z3)*qmul + 2)>>2; //FIXME think about merging this into decode_resdual
- block[stride*2 +offset]= ((z1 + z2)*qmul + 2)>>2;
- block[stride*8 +offset]= ((z1 - z2)*qmul + 2)>>2;
- block[stride*10+offset]= ((z0 - z3)*qmul + 2)>>2;
- }
-}
-
-/**
- * dct tranforms the 16 dc values.
- * @param qp quantization parameter ??? FIXME
- */
-static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){
-// const int qmul= dequant_coeff[qp][0];
- int i;
- int temp[16]; //FIXME check if this is a good idea
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= block[offset+stride*0] + block[offset+stride*4];
- const int z1= block[offset+stride*0] - block[offset+stride*4];
- const int z2= block[offset+stride*1] - block[offset+stride*5];
- const int z3= block[offset+stride*1] + block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= temp[4*0+i] + temp[4*2+i];
- const int z1= temp[4*0+i] - temp[4*2+i];
- const int z2= temp[4*1+i] - temp[4*3+i];
- const int z3= temp[4*1+i] + temp[4*3+i];
-
- block[stride*0 +offset]= (z0 + z3)>>1;
- block[stride*2 +offset]= (z1 + z2)>>1;
- block[stride*8 +offset]= (z1 - z2)>>1;
- block[stride*10+offset]= (z0 - z3)>>1;
- }
-}
-#undef xStride
-#undef stride
-
-static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){
- const int qmul= dequant_coeff[qp][0];
- const int stride= 16*2;
- const int xStride= 16;
- int a,b,c,d,e;
-
- a= block[stride*0 + xStride*0];
- b= block[stride*0 + xStride*1];
- c= block[stride*1 + xStride*0];
- d= block[stride*1 + xStride*1];
-
- e= a-b;
- a= a+b;
- b= c-d;
- c= c+d;
-
- block[stride*0 + xStride*0]= ((a+c)*qmul + 0)>>1;
- block[stride*0 + xStride*1]= ((e+b)*qmul + 0)>>1;
- block[stride*1 + xStride*0]= ((a-c)*qmul + 0)>>1;
- block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1;
-}
-
-static void chroma_dc_dct_c(DCTELEM *block){
- const int stride= 16*2;
- const int xStride= 16;
- int a,b,c,d,e;
-
- a= block[stride*0 + xStride*0];
- b= block[stride*0 + xStride*1];
- c= block[stride*1 + xStride*0];
- d= block[stride*1 + xStride*1];
-
- e= a-b;
- a= a+b;
- b= c-d;
- c= c+d;
-
- block[stride*0 + xStride*0]= (a+c);
- block[stride*0 + xStride*1]= (e+b);
- block[stride*1 + xStride*0]= (a-c);
- block[stride*1 + xStride*1]= (e-b);
-}
-
-/**
- * gets the chroma qp.
- */
-static inline int get_chroma_qp(H264Context *h, int qscale){
-
- return chroma_qp[clip(qscale + h->pps.chroma_qp_index_offset, 0, 51)];
-}
-
-
-/**
- *
- */
-static void h264_add_idct_c(uint8_t *dst, DCTELEM *block, int stride){
- int i;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- block[0] += 32;
-#if 1
- for(i=0; i<4; i++){
- const int z0= block[i + 4*0] + block[i + 4*2];
- const int z1= block[i + 4*0] - block[i + 4*2];
- const int z2= (block[i + 4*1]>>1) - block[i + 4*3];
- const int z3= block[i + 4*1] + (block[i + 4*3]>>1);
-
- block[i + 4*0]= z0 + z3;
- block[i + 4*1]= z1 + z2;
- block[i + 4*2]= z1 - z2;
- block[i + 4*3]= z0 - z3;
- }
-
- for(i=0; i<4; i++){
- const int z0= block[0 + 4*i] + block[2 + 4*i];
- const int z1= block[0 + 4*i] - block[2 + 4*i];
- const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i];
- const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1);
-
- dst[0 + i*stride]= cm[ dst[0 + i*stride] + ((z0 + z3) >> 6) ];
- dst[1 + i*stride]= cm[ dst[1 + i*stride] + ((z1 + z2) >> 6) ];
- dst[2 + i*stride]= cm[ dst[2 + i*stride] + ((z1 - z2) >> 6) ];
- dst[3 + i*stride]= cm[ dst[3 + i*stride] + ((z0 - z3) >> 6) ];
- }
-#else
- for(i=0; i<4; i++){
- const int z0= block[0 + 4*i] + block[2 + 4*i];
- const int z1= block[0 + 4*i] - block[2 + 4*i];
- const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i];
- const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1);
-
- block[0 + 4*i]= z0 + z3;
- block[1 + 4*i]= z1 + z2;
- block[2 + 4*i]= z1 - z2;
- block[3 + 4*i]= z0 - z3;
- }
-
- for(i=0; i<4; i++){
- const int z0= block[i + 4*0] + block[i + 4*2];
- const int z1= block[i + 4*0] - block[i + 4*2];
- const int z2= (block[i + 4*1]>>1) - block[i + 4*3];
- const int z3= block[i + 4*1] + (block[i + 4*3]>>1);
-
- dst[i + 0*stride]= cm[ dst[i + 0*stride] + ((z0 + z3) >> 6) ];
- dst[i + 1*stride]= cm[ dst[i + 1*stride] + ((z1 + z2) >> 6) ];
- dst[i + 2*stride]= cm[ dst[i + 2*stride] + ((z1 - z2) >> 6) ];
- dst[i + 3*stride]= cm[ dst[i + 3*stride] + ((z0 - z3) >> 6) ];
- }
-#endif
-}
-
-static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){
- int i;
- //FIXME try int temp instead of block
-
- for(i=0; i<4; i++){
- const int d0= src1[0 + i*stride] - src2[0 + i*stride];
- const int d1= src1[1 + i*stride] - src2[1 + i*stride];
- const int d2= src1[2 + i*stride] - src2[2 + i*stride];
- const int d3= src1[3 + i*stride] - src2[3 + i*stride];
- const int z0= d0 + d3;
- const int z3= d0 - d3;
- const int z1= d1 + d2;
- const int z2= d1 - d2;
-
- block[0 + 4*i]= z0 + z1;
- block[1 + 4*i]= 2*z3 + z2;
- block[2 + 4*i]= z0 - z1;
- block[3 + 4*i]= z3 - 2*z2;
- }
-
- for(i=0; i<4; i++){
- const int z0= block[0*4 + i] + block[3*4 + i];
- const int z3= block[0*4 + i] - block[3*4 + i];
- const int z1= block[1*4 + i] + block[2*4 + i];
- const int z2= block[1*4 + i] - block[2*4 + i];
-
- block[0*4 + i]= z0 + z1;
- block[1*4 + i]= 2*z3 + z2;
- block[2*4 + i]= z0 - z1;
- block[3*4 + i]= z3 - 2*z2;
- }
-}
-
-//FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close
-//FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away)
-static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){
- int i;
- const int * const quant_table= quant_coeff[qscale];
- const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6;
- const unsigned int threshold1= (1<<QUANT_SHIFT) - bias - 1;
- const unsigned int threshold2= (threshold1<<1);
- int last_non_zero;
-
- if(seperate_dc){
- if(qscale<=18){
- //avoid overflows
- const int dc_bias= intra ? (1<<(QUANT_SHIFT-2))/3 : (1<<(QUANT_SHIFT-2))/6;
- const unsigned int dc_threshold1= (1<<(QUANT_SHIFT-2)) - dc_bias - 1;
- const unsigned int dc_threshold2= (dc_threshold1<<1);
-
- int level= block[0]*quant_coeff[qscale+18][0];
- if(((unsigned)(level+dc_threshold1))>dc_threshold2){
- if(level>0){
- level= (dc_bias + level)>>(QUANT_SHIFT-2);
- block[0]= level;
- }else{
- level= (dc_bias - level)>>(QUANT_SHIFT-2);
- block[0]= -level;
- }
-// last_non_zero = i;
- }else{
- block[0]=0;
- }
- }else{
- const int dc_bias= intra ? (1<<(QUANT_SHIFT+1))/3 : (1<<(QUANT_SHIFT+1))/6;
- const unsigned int dc_threshold1= (1<<(QUANT_SHIFT+1)) - dc_bias - 1;
- const unsigned int dc_threshold2= (dc_threshold1<<1);
-
- int level= block[0]*quant_table[0];
- if(((unsigned)(level+dc_threshold1))>dc_threshold2){
- if(level>0){
- level= (dc_bias + level)>>(QUANT_SHIFT+1);
- block[0]= level;
- }else{
- level= (dc_bias - level)>>(QUANT_SHIFT+1);
- block[0]= -level;
- }
-// last_non_zero = i;
- }else{
- block[0]=0;
- }
- }
- last_non_zero= 0;
- i=1;
- }else{
- last_non_zero= -1;
- i=0;
- }
-
- for(; i<16; i++){
- const int j= scantable[i];
- int level= block[j]*quant_table[j];
-
-// if( bias+level >= (1<<(QMAT_SHIFT - 3))
-// || bias-level >= (1<<(QMAT_SHIFT - 3))){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QUANT_SHIFT;
- block[j]= level;
- }else{
- level= (bias - level)>>QUANT_SHIFT;
- block[j]= -level;
- }
- last_non_zero = i;
- }else{
- block[j]=0;
- }
- }
-
- return last_non_zero;
-}
-
-static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- ((uint32_t*)(src+0*stride))[0]= a;
- ((uint32_t*)(src+1*stride))[0]= a;
- ((uint32_t*)(src+2*stride))[0]= a;
- ((uint32_t*)(src+3*stride))[0]= a;
-}
-
-static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){
- ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101;
- ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101;
- ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101;
- ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101;
-}
-
-static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride]
- + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){
- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2;
-
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101;
-}
-
-static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){
- ((uint32_t*)(src+0*stride))[0]=
- ((uint32_t*)(src+1*stride))[0]=
- ((uint32_t*)(src+2*stride))[0]=
- ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U;
-}
-
-
-#define LOAD_TOP_RIGHT_EDGE\
- const int t4= topright[0];\
- const int t5= topright[1];\
- const int t6= topright[2];\
- const int t7= topright[3];\
-
-#define LOAD_LEFT_EDGE\
- const int l0= src[-1+0*stride];\
- const int l1= src[-1+1*stride];\
- const int l2= src[-1+2*stride];\
- const int l3= src[-1+3*stride];\
-
-#define LOAD_TOP_EDGE\
- const int t0= src[ 0-1*stride];\
- const int t1= src[ 1-1*stride];\
- const int t2= src[ 2-1*stride];\
- const int t3= src[ 3-1*stride];\
-
-static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
-
- src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
- src[0+2*stride]=
- src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
- src[0+1*stride]=
- src[1+2*stride]=
- src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
- src[0+0*stride]=
- src[1+1*stride]=
- src[2+2*stride]=
- src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[1+0*stride]=
- src[2+1*stride]=
- src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[2+0*stride]=
- src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
-}
-
-static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_TOP_RIGHT_EDGE
-// LOAD_LEFT_EDGE
-
- src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
- src[1+0*stride]=
- src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
- src[2+0*stride]=
- src[1+1*stride]=
- src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
- src[3+0*stride]=
- src[2+1*stride]=
- src[1+2*stride]=
- src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
- src[3+1*stride]=
- src[2+2*stride]=
- src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
- src[3+2*stride]=
- src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
- src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
-}
-
-static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu= l3;
-
- src[0+0*stride]=
- src[1+2*stride]=(lt + t0 + 1)>>1;
- src[1+0*stride]=
- src[2+2*stride]=(t0 + t1 + 1)>>1;
- src[2+0*stride]=
- src[3+2*stride]=(t1 + t2 + 1)>>1;
- src[3+0*stride]=(t2 + t3 + 1)>>1;
- src[0+1*stride]=
- src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[1+1*stride]=
- src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[2+1*stride]=
- src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;
- src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
- src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
-}
-
-static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_TOP_RIGHT_EDGE
- const __attribute__((unused)) int unu= t7;
-
- src[0+0*stride]=(t0 + t1 + 1)>>1;
- src[1+0*stride]=
- src[0+2*stride]=(t1 + t2 + 1)>>1;
- src[2+0*stride]=
- src[1+2*stride]=(t2 + t3 + 1)>>1;
- src[3+0*stride]=
- src[2+2*stride]=(t3 + t4+ 1)>>1;
- src[3+2*stride]=(t4 + t5+ 1)>>1;
- src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[1+1*stride]=
- src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2;
- src[2+1*stride]=
- src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2;
- src[3+1*stride]=
- src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2;
- src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2;
-}
-
-static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_LEFT_EDGE
-
- src[0+0*stride]=(l0 + l1 + 1)>>1;
- src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2;
- src[2+0*stride]=
- src[0+1*stride]=(l1 + l2 + 1)>>1;
- src[3+0*stride]=
- src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2;
- src[2+1*stride]=
- src[0+2*stride]=(l2 + l3 + 1)>>1;
- src[3+1*stride]=
- src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2;
- src[3+2*stride]=
- src[1+3*stride]=
- src[0+3*stride]=
- src[2+2*stride]=
- src[2+3*stride]=
- src[3+3*stride]=l3;
-}
-
-static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){
- const int lt= src[-1-1*stride];
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu= t3;
-
- src[0+0*stride]=
- src[2+1*stride]=(lt + l0 + 1)>>1;
- src[1+0*stride]=
- src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
- src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
- src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
- src[0+1*stride]=
- src[2+2*stride]=(l0 + l1 + 1)>>1;
- src[1+1*stride]=
- src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
- src[0+2*stride]=
- src[2+3*stride]=(l1 + l2+ 1)>>1;
- src[1+2*stride]=
- src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
- src[0+3*stride]=(l2 + l3 + 1)>>1;
- src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
-}
-
-static void pred16x16_vertical_c(uint8_t *src, int stride){
- int i;
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- const uint32_t b= ((uint32_t*)(src-stride))[1];
- const uint32_t c= ((uint32_t*)(src-stride))[2];
- const uint32_t d= ((uint32_t*)(src-stride))[3];
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]= a;
- ((uint32_t*)(src+i*stride))[1]= b;
- ((uint32_t*)(src+i*stride))[2]= c;
- ((uint32_t*)(src+i*stride))[3]= d;
- }
-}
-
-static void pred16x16_horizontal_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101;
- }
-}
-
-static void pred16x16_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[-1+i*stride];
- }
-
- for(i=0;i<16; i++){
- dc+= src[i-stride];
- }
-
- dc= 0x01010101*((dc + 16)>>5);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-static void pred16x16_left_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[-1+i*stride];
- }
-
- dc= 0x01010101*((dc + 8)>>4);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-static void pred16x16_top_dc_c(uint8_t *src, int stride){
- int i, dc=0;
-
- for(i=0;i<16; i++){
- dc+= src[i-stride];
- }
- dc= 0x01010101*((dc + 8)>>4);
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= dc;
- }
-}
-
-static void pred16x16_128_dc_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<16; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]=
- ((uint32_t*)(src+i*stride))[2]=
- ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U;
- }
-}
-
-static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3){
- int i, j, k;
- int a;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- const uint8_t * const src0 = src+7-stride;
- const uint8_t *src1 = src+8*stride-1;
- const uint8_t *src2 = src1-2*stride; // == src+6*stride-1;
- int H = src0[1] - src0[-1];
- int V = src1[0] - src2[ 0];
- for(k=2; k<=8; ++k) {
- src1 += stride; src2 -= stride;
- H += k*(src0[k] - src0[-k]);
- V += k*(src1[0] - src2[ 0]);
- }
- if(svq3){
- H = ( 5*(H/4) ) / 16;
- V = ( 5*(V/4) ) / 16;
-
- /* required for 100% accuracy */
- i = H; H = V; V = i;
- }else{
- H = ( 5*H+32 ) >> 6;
- V = ( 5*V+32 ) >> 6;
- }
-
- a = 16*(src1[0] + src2[16] + 1) - 7*(V+H);
- for(j=16; j>0; --j) {
- int b = a;
- a += V;
- for(i=-16; i<0; i+=4) {
- src[16+i] = cm[ (b ) >> 5 ];
- src[17+i] = cm[ (b+ H) >> 5 ];
- src[18+i] = cm[ (b+2*H) >> 5 ];
- src[19+i] = cm[ (b+3*H) >> 5 ];
- b += 4*H;
- }
- src += stride;
- }
-}
-
-static void pred16x16_plane_c(uint8_t *src, int stride){
- pred16x16_plane_compat_c(src, stride, 0);
-}
-
-static void pred8x8_vertical_c(uint8_t *src, int stride){
- int i;
- const uint32_t a= ((uint32_t*)(src-stride))[0];
- const uint32_t b= ((uint32_t*)(src-stride))[1];
-
- for(i=0; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= a;
- ((uint32_t*)(src+i*stride))[1]= b;
- }
-}
-
-static void pred8x8_horizontal_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101;
- }
-}
-
-static void pred8x8_128_dc_c(uint8_t *src, int stride){
- int i;
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U;
- }
-}
-
-static void pred8x8_left_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc2;
-
- dc0=dc2=0;
- for(i=0;i<4; i++){
- dc0+= src[-1+i*stride];
- dc2+= src[-1+(i+4)*stride];
- }
- dc0= 0x01010101*((dc0 + 2)>>2);
- dc2= 0x01010101*((dc2 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= dc0;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]=
- ((uint32_t*)(src+i*stride))[1]= dc2;
- }
-}
-
-static void pred8x8_top_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc1;
-
- dc0=dc1=0;
- for(i=0;i<4; i++){
- dc0+= src[i-stride];
- dc1+= src[4+i-stride];
- }
- dc0= 0x01010101*((dc0 + 2)>>2);
- dc1= 0x01010101*((dc1 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
-}
-
-
-static void pred8x8_dc_c(uint8_t *src, int stride){
- int i;
- int dc0, dc1, dc2, dc3;
-
- dc0=dc1=dc2=0;
- for(i=0;i<4; i++){
- dc0+= src[-1+i*stride] + src[i-stride];
- dc1+= src[4+i-stride];
- dc2+= src[-1+(i+4)*stride];
- }
- dc3= 0x01010101*((dc1 + dc2 + 4)>>3);
- dc0= 0x01010101*((dc0 + 4)>>3);
- dc1= 0x01010101*((dc1 + 2)>>2);
- dc2= 0x01010101*((dc2 + 2)>>2);
-
- for(i=0; i<4; i++){
- ((uint32_t*)(src+i*stride))[0]= dc0;
- ((uint32_t*)(src+i*stride))[1]= dc1;
- }
- for(i=4; i<8; i++){
- ((uint32_t*)(src+i*stride))[0]= dc2;
- ((uint32_t*)(src+i*stride))[1]= dc3;
- }
-}
-
-static void pred8x8_plane_c(uint8_t *src, int stride){
- int j, k;
- int a;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- const uint8_t * const src0 = src+3-stride;
- const uint8_t *src1 = src+4*stride-1;
- const uint8_t *src2 = src1-2*stride; // == src+2*stride-1;
- int H = src0[1] - src0[-1];
- int V = src1[0] - src2[ 0];
- for(k=2; k<=4; ++k) {
- src1 += stride; src2 -= stride;
- H += k*(src0[k] - src0[-k]);
- V += k*(src1[0] - src2[ 0]);
- }
- H = ( 17*H+16 ) >> 5;
- V = ( 17*V+16 ) >> 5;
-
- a = 16*(src1[0] + src2[8]+1) - 3*(V+H);
- for(j=8; j>0; --j) {
- int b = a;
- a += V;
- src[0] = cm[ (b ) >> 5 ];
- src[1] = cm[ (b+ H) >> 5 ];
- src[2] = cm[ (b+2*H) >> 5 ];
- src[3] = cm[ (b+3*H) >> 5 ];
- src[4] = cm[ (b+4*H) >> 5 ];
- src[5] = cm[ (b+5*H) >> 5 ];
- src[6] = cm[ (b+6*H) >> 5 ];
- src[7] = cm[ (b+7*H) >> 5 ];
- src += stride;
- }
-}
-
-static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int src_x_offset, int src_y_offset,
- qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){
- MpegEncContext * const s = &h->s;
- const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8;
- const int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8;
- const int luma_xy= (mx&3) + ((my&3)<<2);
- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*s->linesize;
- uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*s->uvlinesize;
- uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*s->uvlinesize;
- int extra_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; //FIXME increase edge?, IMHO not worth it
- int extra_height= extra_width;
- int emu=0;
- const int full_mx= mx>>2;
- const int full_my= my>>2;
-
- assert(pic->data[0]);
-
- if(mx&7) extra_width -= 3;
- if(my&7) extra_height -= 3;
-
- if( full_mx < 0-extra_width
- || full_my < 0-extra_height
- || full_mx + 16/*FIXME*/ > s->width + extra_width
- || full_my + 16/*FIXME*/ > s->height + extra_height){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*s->linesize, s->linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, s->width, s->height);
- src_y= s->edge_emu_buffer + 2 + 2*s->linesize;
- emu=1;
- }
-
- qpix_op[luma_xy](dest_y, src_y, s->linesize); //FIXME try variable height perhaps?
- if(!square){
- qpix_op[luma_xy](dest_y + delta, src_y + delta, s->linesize);
- }
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cb, s->uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), s->width>>1, s->height>>1);
- src_cb= s->edge_emu_buffer;
- }
- chroma_op(dest_cb, src_cb, s->uvlinesize, chroma_height, mx&7, my&7);
-
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, src_cr, s->uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), s->width>>1, s->height>>1);
- src_cr= s->edge_emu_buffer;
- }
- chroma_op(dest_cr, src_cr, s->uvlinesize, chroma_height, mx&7, my&7);
-}
-
-static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int x_offset, int y_offset,
- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put,
- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg,
- int list0, int list1){
- MpegEncContext * const s = &h->s;
- qpel_mc_func *qpix_op= qpix_put;
- h264_chroma_mc_func chroma_op= chroma_put;
-
- dest_y += 2*x_offset + 2*y_offset*s-> linesize;
- dest_cb += x_offset + y_offset*s->uvlinesize;
- dest_cr += x_offset + y_offset*s->uvlinesize;
- x_offset += 8*s->mb_x;
- y_offset += 8*s->mb_y;
-
- if(list0){
- Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 0,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op);
-
- qpix_op= qpix_avg;
- chroma_op= chroma_avg;
- }
-
- if(list1){
- Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ];
- mc_dir_part(h, ref, n, square, chroma_height, delta, 1,
- dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_op, chroma_op);
- }
-}
-
-static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
- qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg)){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
-
- assert(IS_INTER(mb_type));
-
- if(IS_16X16(mb_type)){
- mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0,
- qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],
- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
- }else if(IS_16X8(mb_type)){
- mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0,
- qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
- mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4,
- qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],
- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
- }else if(IS_8X16(mb_type)){
- mc_part(h, 0, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 0, 0,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1));
- mc_part(h, 4, 0, 8, 8*s->linesize, dest_y, dest_cb, dest_cr, 4, 0,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1));
- }else{
- int i;
-
- assert(IS_8X8(mb_type));
-
- for(i=0; i<4; i++){
- const int sub_mb_type= h->sub_mb_type[i];
- const int n= 4*i;
- int x_offset= (i&1)<<2;
- int y_offset= (i&2)<<1;
-
- if(IS_SUB_8X8(sub_mb_type)){
- mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else if(IS_SUB_8X4(sub_mb_type)){
- mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,
- qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else if(IS_SUB_4X8(sub_mb_type)){
- mc_part(h, n , 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- mc_part(h, n+1, 0, 4, 4*s->linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }else{
- int j;
- assert(IS_SUB_4X4(sub_mb_type));
- for(j=0; j<4; j++){
- int sub_x_offset= x_offset + 2*(j&1);
- int sub_y_offset= y_offset + (j&2);
- mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,
- qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],
- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1));
- }
- }
- }
- }
-}
-
-static void decode_init_vlc(H264Context *h){
- static int done = 0;
-
- if (!done) {
- int i;
- done = 1;
-
- init_vlc(&chroma_dc_coeff_token_vlc, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 4*5,
- &chroma_dc_coeff_token_len [0], 1, 1,
- &chroma_dc_coeff_token_bits[0], 1, 1);
-
- for(i=0; i<4; i++){
- init_vlc(&coeff_token_vlc[i], COEFF_TOKEN_VLC_BITS, 4*17,
- &coeff_token_len [i][0], 1, 1,
- &coeff_token_bits[i][0], 1, 1);
- }
-
- for(i=0; i<3; i++){
- init_vlc(&chroma_dc_total_zeros_vlc[i], CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 4,
- &chroma_dc_total_zeros_len [i][0], 1, 1,
- &chroma_dc_total_zeros_bits[i][0], 1, 1);
- }
- for(i=0; i<15; i++){
- init_vlc(&total_zeros_vlc[i], TOTAL_ZEROS_VLC_BITS, 16,
- &total_zeros_len [i][0], 1, 1,
- &total_zeros_bits[i][0], 1, 1);
- }
-
- for(i=0; i<6; i++){
- init_vlc(&run_vlc[i], RUN_VLC_BITS, 7,
- &run_len [i][0], 1, 1,
- &run_bits[i][0], 1, 1);
- }
- init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
- &run_len [6][0], 1, 1,
- &run_bits[6][0], 1, 1);
- }
-}
-
-/**
- * Sets the intra prediction function pointers.
- */
-static void init_pred_ptrs(H264Context *h){
-// MpegEncContext * const s = &h->s;
-
- h->pred4x4[VERT_PRED ]= pred4x4_vertical_c;
- h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c;
- h->pred4x4[DC_PRED ]= pred4x4_dc_c;
- h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c;
- h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c;
- h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c;
- h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c;
- h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c;
- h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c;
- h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c;
- h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c;
- h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c;
-
- h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c;
- h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c;
- h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c;
- h->pred8x8[PLANE_PRED8x8 ]= pred8x8_plane_c;
- h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c;
- h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c;
- h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c;
-
- h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c;
- h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c;
- h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c;
- h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c;
- h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c;
- h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c;
- h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c;
-}
-
-static void free_tables(H264Context *h){
- av_freep(&h->intra4x4_pred_mode);
- av_freep(&h->non_zero_count);
- av_freep(&h->slice_table_base);
- h->slice_table= NULL;
-
- av_freep(&h->mb2b_xy);
- av_freep(&h->mb2b8_xy);
-}
-
-/**
- * allocates tables.
- * needs widzh/height
- */
-static int alloc_tables(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int big_mb_num= s->mb_stride * (s->mb_height+1);
- int x,y;
-
- CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))
- CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t))
- CHECKED_ALLOCZ(h->slice_table_base , big_mb_num * sizeof(uint8_t))
-
- memset(h->slice_table_base, -1, big_mb_num * sizeof(uint8_t));
- h->slice_table= h->slice_table_base + s->mb_stride + 1;
-
- CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint16_t));
- CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint16_t));
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- const int mb_xy= x + y*s->mb_stride;
- const int b_xy = 4*x + 4*y*h->b_stride;
- const int b8_xy= 2*x + 2*y*h->b8_stride;
-
- h->mb2b_xy [mb_xy]= b_xy;
- h->mb2b8_xy[mb_xy]= b8_xy;
- }
- }
-
- return 0;
-fail:
- free_tables(h);
- return -1;
-}
-
-static void common_init(H264Context *h){
- MpegEncContext * const s = &h->s;
-
- s->width = s->avctx->width;
- s->height = s->avctx->height;
- s->codec_id= s->avctx->codec->id;
-
- init_pred_ptrs(h);
-
- s->decode=1; //FIXME
-}
-
-static int decode_init(AVCodecContext *avctx){
- H264Context *h= avctx->priv_data;
- MpegEncContext * const s = &h->s;
-
- s->avctx = avctx;
- common_init(h);
-
- s->out_format = FMT_H264;
- s->workaround_bugs= avctx->workaround_bugs;
-
- // set defaults
- s->progressive_sequence=1;
-// s->decode_mb= ff_h263_decode_mb;
- s->low_delay= 1;
- avctx->pix_fmt= PIX_FMT_YUV420P;
-
- decode_init_vlc(h);
-
- return 0;
-}
-
-static void frame_start(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
-
- MPV_frame_start(s, s->avctx);
- ff_er_frame_start(s);
- h->mmco_index=0;
-
- assert(s->linesize && s->uvlinesize);
-
- for(i=0; i<16; i++){
- h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3);
- h->chroma_subblock_offset[i]= 2*((scan8[i] - scan8[0])&7) + 2*s->uvlinesize*((scan8[i] - scan8[0])>>3);
- }
- for(i=0; i<4; i++){
- h->block_offset[16+i]=
- h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3);
- }
-
-// s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
-}
-
-static void hl_decode_mb(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_x= s->mb_x;
- const int mb_y= s->mb_y;
- const int mb_xy= mb_x + mb_y*s->mb_stride;
- const int mb_type= s->current_picture.mb_type[mb_xy];
- uint8_t *dest_y, *dest_cb, *dest_cr;
- int linesize, uvlinesize /*dct_offset*/;
- int i;
-
- if(!s->decode)
- return;
-
- if(s->mb_skiped){
- }
-
- dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
- dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
- dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
-
- if (h->mb_field_decoding_flag) {
- linesize = s->linesize * 2;
- uvlinesize = s->uvlinesize * 2;
- if(mb_y&1){ //FIXME move out of this func?
- dest_y -= s->linesize*15;
- dest_cb-= s->linesize*7;
- dest_cr-= s->linesize*7;
- }
- } else {
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
-// dct_offset = s->linesize * 16;
- }
-
- if(IS_INTRA(mb_type)){
- if(!(s->flags&CODEC_FLAG_GRAY)){
- h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize);
- h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize);
- }
-
- if(IS_INTRA4x4(mb_type)){
- if(!s->encoding){
- for(i=0; i<16; i++){
- uint8_t * const ptr= dest_y + h->block_offset[i];
- uint8_t *topright= ptr + 4 - linesize;
- const int topright_avail= (h->topright_samples_available<<i)&0x8000;
- const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
- int tr;
-
- if(!topright_avail){
- tr= ptr[3 - linesize]*0x01010101;
- topright= (uint8_t*) &tr;
- }
-
- h->pred4x4[ dir ](ptr, topright, linesize);
- if(h->non_zero_count_cache[ scan8[i] ]){
- if(s->codec_id == CODEC_ID_H264)
- h264_add_idct_c(ptr, h->mb + i*16, linesize);
- else
- svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0);
- }
- }
- }
- }else{
- h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize);
- if(s->codec_id == CODEC_ID_H264)
- h264_luma_dc_dequant_idct_c(h->mb, s->qscale);
- else
- svq3_luma_dc_dequant_idct_c(h->mb, s->qscale);
- }
- }else if(s->codec_id == CODEC_ID_H264){
- hl_motion(h, dest_y, dest_cb, dest_cr,
- s->dsp.put_h264_qpel_pixels_tab, s->dsp.put_h264_chroma_pixels_tab,
- s->dsp.avg_h264_qpel_pixels_tab, s->dsp.avg_h264_chroma_pixels_tab);
- }
-
-
- if(!IS_INTRA4x4(mb_type)){
- if(s->codec_id == CODEC_ID_H264){
- for(i=0; i<16; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below
- uint8_t * const ptr= dest_y + h->block_offset[i];
- h264_add_idct_c(ptr, h->mb + i*16, linesize);
- }
- }
- }else{
- for(i=0; i<16; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below
- uint8_t * const ptr= dest_y + h->block_offset[i];
- svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0);
- }
- }
- }
- }
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp);
- chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp);
- if(s->codec_id == CODEC_ID_H264){
- for(i=16; i<16+4; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
- uint8_t * const ptr= dest_cb + h->block_offset[i];
- h264_add_idct_c(ptr, h->mb + i*16, uvlinesize);
- }
- }
- for(i=20; i<20+4; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
- uint8_t * const ptr= dest_cr + h->block_offset[i];
- h264_add_idct_c(ptr, h->mb + i*16, uvlinesize);
- }
- }
- }else{
- for(i=16; i<16+4; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
- uint8_t * const ptr= dest_cb + h->block_offset[i];
- svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
- }
- }
- for(i=20; i<20+4; i++){
- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
- uint8_t * const ptr= dest_cr + h->block_offset[i];
- svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
- }
- }
- }
- }
-}
-
-static void decode_mb_cabac(H264Context *h){
-// MpegEncContext * const s = &h->s;
-}
-
-/**
- * fills the default_ref_list.
- */
-static int fill_default_ref_list(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
- Picture sorted_short_ref[16];
-
- if(h->slice_type==B_TYPE){
- int out_i;
- int limit= -1;
-
- for(out_i=0; out_i<h->short_ref_count; out_i++){
- int best_i=-1;
- int best_poc=-1;
-
- for(i=0; i<h->short_ref_count; i++){
- const int poc= h->short_ref[i]->poc;
- if(poc > limit && poc < best_poc){
- best_poc= poc;
- best_i= i;
- }
- }
-
- assert(best_i != -1);
-
- limit= best_poc;
- sorted_short_ref[out_i]= *h->short_ref[best_i];
- }
- }
-
- if(s->picture_structure == PICT_FRAME){
- if(h->slice_type==B_TYPE){
- const int current_poc= s->current_picture_ptr->poc;
- int list;
-
- for(list=0; list<2; list++){
- int index=0;
-
- for(i=0; i<h->short_ref_count && index < h->ref_count[list]; i++){
- const int i2= list ? h->short_ref_count - i - 1 : i;
- const int poc= sorted_short_ref[i2].poc;
-
- if(sorted_short_ref[i2].reference != 3) continue; //FIXME refernce field shit
-
- if((list==1 && poc > current_poc) || (list==0 && poc < current_poc)){
- h->default_ref_list[list][index ]= sorted_short_ref[i2];
- h->default_ref_list[list][index++].pic_id= sorted_short_ref[i2].frame_num;
- }
- }
-
- for(i=0; i<h->long_ref_count && index < h->ref_count[ list ]; i++){
- if(h->long_ref[i]->reference != 3) continue;
-
- h->default_ref_list[ list ][index ]= *h->long_ref[i];
- h->default_ref_list[ list ][index++].pic_id= i;;
- }
-
- if(h->long_ref_count > 1 && h->short_ref_count==0){
- Picture temp= h->default_ref_list[1][0];
- h->default_ref_list[1][0] = h->default_ref_list[1][1];
- h->default_ref_list[1][0] = temp;
- }
-
- if(index < h->ref_count[ list ])
- memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index));
- }
- }else{
- int index=0;
- for(i=0; i<h->short_ref_count && index < h->ref_count[0]; i++){
- if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit
- h->default_ref_list[0][index ]= *h->short_ref[i];
- h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num;
- }
- for(i=0; i<h->long_ref_count && index < h->ref_count[0]; i++){
- if(h->long_ref[i]->reference != 3) continue;
- h->default_ref_list[0][index ]= *h->long_ref[i];
- h->default_ref_list[0][index++].pic_id= i;;
- }
- if(index < h->ref_count[0])
- memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index));
- }
- }else{ //FIELD
- if(h->slice_type==B_TYPE){
- }else{
- //FIXME second field balh
- }
- }
- return 0;
-}
-
-static int decode_ref_pic_list_reordering(H264Context *h){
- MpegEncContext * const s = &h->s;
- int list;
-
- if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func
-
- for(list=0; list<2; list++){
- memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);
-
- if(get_bits1(&s->gb)){
- int pred= h->curr_pic_num;
- int index;
-
- for(index=0; ; index++){
- int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb);
- int pic_id;
- int i;
-
-
- if(index >= h->ref_count[list]){
- fprintf(stderr, "reference count overflow\n");
- return -1;
- }
-
- if(reordering_of_pic_nums_idc<3){
- if(reordering_of_pic_nums_idc<2){
- const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1;
-
- if(abs_diff_pic_num >= h->max_pic_num){
- fprintf(stderr, "abs_diff_pic_num overflow\n");
- return -1;
- }
-
- if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num;
- else pred+= abs_diff_pic_num;
- pred &= h->max_pic_num - 1;
-
- for(i= h->ref_count[list]-1; i>=index; i--){
- if(h->ref_list[list][i].pic_id == pred && h->ref_list[list][i].long_ref==0)
- break;
- }
- }else{
- pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx
-
- for(i= h->ref_count[list]-1; i>=index; i--){
- if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1)
- break;
- }
- }
-
- if(i < index){
- fprintf(stderr, "reference picture missing during reorder\n");
- memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME
- }else if(i > index){
- Picture tmp= h->ref_list[list][i];
- for(; i>index; i--){
- h->ref_list[list][i]= h->ref_list[list][i-1];
- }
- h->ref_list[list][index]= tmp;
- }
- }else if(reordering_of_pic_nums_idc==3)
- break;
- else{
- fprintf(stderr, "illegal reordering_of_pic_nums_idc\n");
- return -1;
- }
- }
- }
-
- if(h->slice_type!=B_TYPE) break;
- }
- return 0;
-}
-
-static int pred_weight_table(H264Context *h){
- MpegEncContext * const s = &h->s;
- int list, i;
-
- h->luma_log2_weight_denom= get_ue_golomb(&s->gb);
- h->chroma_log2_weight_denom= get_ue_golomb(&s->gb);
-
- for(list=0; list<2; list++){
- for(i=0; i<h->ref_count[list]; i++){
- int luma_weight_flag, chroma_weight_flag;
-
- luma_weight_flag= get_bits1(&s->gb);
- if(luma_weight_flag){
- h->luma_weight[list][i]= get_se_golomb(&s->gb);
- h->luma_offset[list][i]= get_se_golomb(&s->gb);
- }
-
- chroma_weight_flag= get_bits1(&s->gb);
- if(chroma_weight_flag){
- int j;
- for(j=0; j<2; j++){
- h->chroma_weight[list][i][j]= get_se_golomb(&s->gb);
- h->chroma_offset[list][i][j]= get_se_golomb(&s->gb);
- }
- }
- }
- if(h->slice_type != B_TYPE) break;
- }
- return 0;
-}
-
-/**
- * instantaneos decoder refresh.
- */
-static void idr(H264Context *h){
- int i;
-
- for(i=0; i<h->long_ref_count; i++){
- h->long_ref[i]->reference=0;
- h->long_ref[i]= NULL;
- }
- h->long_ref_count=0;
-
- for(i=0; i<h->short_ref_count; i++){
- h->short_ref[i]->reference=0;
- h->short_ref[i]= NULL;
- }
- h->short_ref_count=0;
-}
-
-/**
- *
- * @return the removed picture or NULL if an error occures
- */
-static Picture * remove_short(H264Context *h, int frame_num){
- MpegEncContext * const s = &h->s;
- int i;
-
- if(s->avctx->debug&FF_DEBUG_MMCO)
- printf("remove short %d count %d\n", frame_num, h->short_ref_count);
-
- for(i=0; i<h->short_ref_count; i++){
- Picture *pic= h->short_ref[i];
- if(s->avctx->debug&FF_DEBUG_MMCO)
- printf("%d %d %p\n", i, pic->frame_num, pic);
- if(pic->frame_num == frame_num){
- h->short_ref[i]= NULL;
- memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*));
- h->short_ref_count--;
- return pic;
- }
- }
- return NULL;
-}
-
-/**
- *
- * @return the removed picture or NULL if an error occures
- */
-static Picture * remove_long(H264Context *h, int i){
- Picture *pic;
-
- if(i >= h->long_ref_count) return NULL;
- pic= h->long_ref[i];
- if(pic==NULL) return NULL;
-
- h->long_ref[i]= NULL;
- memmove(&h->long_ref[i], &h->long_ref[i+1], (h->long_ref_count - i - 1)*sizeof(Picture*));
- h->long_ref_count--;
-
- return pic;
-}
-
-/**
- * Executes the reference picture marking (memory management control operations).
- */
-static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){
- MpegEncContext * const s = &h->s;
- int i;
- int current_is_long=0;
- Picture *pic;
-
- if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0)
- printf("no mmco here\n");
-
- for(i=0; i<mmco_count; i++){
- if(s->avctx->debug&FF_DEBUG_MMCO)
- printf("mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_frame_num, h->mmco[i].long_index);
-
- switch(mmco[i].opcode){
- case MMCO_SHORT2UNUSED:
- pic= remove_short(h, mmco[i].short_frame_num);
- if(pic==NULL) return -1;
- pic->reference= 0;
- break;
- case MMCO_SHORT2LONG:
- pic= remove_long(h, mmco[i].long_index);
- if(pic) pic->reference=0;
-
- h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num);
- h->long_ref[ mmco[i].long_index ]->long_ref=1;
- break;
- case MMCO_LONG2UNUSED:
- pic= remove_long(h, mmco[i].long_index);
- if(pic==NULL) return -1;
- pic->reference= 0;
- break;
- case MMCO_LONG:
- pic= remove_long(h, mmco[i].long_index);
- if(pic) pic->reference=0;
-
- h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr;
- h->long_ref[ mmco[i].long_index ]->long_ref=1;
- h->long_ref_count++;
-
- current_is_long=1;
- break;
- case MMCO_SET_MAX_LONG:
- assert(mmco[i].long_index <= 16);
- while(mmco[i].long_index < h->long_ref_count){
- pic= remove_long(h, mmco[i].long_index);
- pic->reference=0;
- }
- while(mmco[i].long_index > h->long_ref_count){
- h->long_ref[ h->long_ref_count++ ]= NULL;
- }
- break;
- case MMCO_RESET:
- while(h->short_ref_count){
- pic= remove_short(h, h->short_ref[0]->frame_num);
- pic->reference=0;
- }
- while(h->long_ref_count){
- pic= remove_long(h, h->long_ref_count-1);
- pic->reference=0;
- }
- break;
- default: assert(0);
- }
- }
-
- if(!current_is_long){
- pic= remove_short(h, s->current_picture_ptr->frame_num);
- if(pic){
- pic->reference=0;
- fprintf(stderr, "illegal short term buffer state detected\n");
- }
-
- if(h->short_ref_count)
- memmove(&h->short_ref[1], &h->short_ref[0], h->short_ref_count*sizeof(Picture*));
-
- h->short_ref[0]= s->current_picture_ptr;
- h->short_ref[0]->long_ref=0;
- h->short_ref_count++;
- }
-
- return 0;
-}
-
-static int decode_ref_pic_marking(H264Context *h){
- MpegEncContext * const s = &h->s;
- int i;
-
- if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields
- s->broken_link= get_bits1(&s->gb) -1;
- h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx
- if(h->mmco[0].long_index == -1)
- h->mmco_index= 0;
- else{
- h->mmco[0].opcode= MMCO_LONG;
- h->mmco_index= 1;
- }
- }else{
- if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag
- for(i= h->mmco_index; i<MAX_MMCO_COUNT; i++) {
- MMCOOpcode opcode= get_ue_golomb(&s->gb);;
-
- h->mmco[i].opcode= opcode;
- if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){
- h->mmco[i].short_frame_num= (h->frame_num - get_ue_golomb(&s->gb) - 1) & ((1<<h->sps.log2_max_frame_num)-1); //FIXME fields
-/* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_num ] == NULL){
- fprintf(stderr, "illegal short ref in memory management control operation %d\n", mmco);
- return -1;
- }*/
- }
- if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){
- h->mmco[i].long_index= get_ue_golomb(&s->gb);
- if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ h->mmco[i].long_index >= 16){
- fprintf(stderr, "illegal long ref in memory management control operation %d\n", opcode);
- return -1;
- }
- }
-
- if(opcode > MMCO_LONG){
- fprintf(stderr, "illegal memory management control operation %d\n", opcode);
- return -1;
- }
- }
- h->mmco_index= i;
- }else{
- assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count);
-
- if(h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields
- h->mmco[0].opcode= MMCO_SHORT2UNUSED;
- h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num;
- h->mmco_index= 1;
- }else
- h->mmco_index= 0;
- }
- }
-
- return 0;
-}
-
-static int init_poc(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int max_frame_num= 1<<h->sps.log2_max_frame_num;
- int field_poc[2];
-
- if(h->nal_unit_type == NAL_IDR_SLICE){
- h->frame_num_offset= 0;
- }else{
- if(h->frame_num < h->prev_frame_num)
- h->frame_num_offset= h->prev_frame_num_offset + max_frame_num;
- else
- h->frame_num_offset= h->prev_frame_num_offset;
- }
-
- if(h->sps.poc_type==0){
- const int max_poc_lsb= 1<<h->sps.log2_max_poc_lsb;
-
- if (h->poc_lsb < h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb >= max_poc_lsb/2)
- h->poc_msb = h->prev_poc_msb + max_poc_lsb;
- else if(h->poc_lsb > h->prev_poc_lsb && h->prev_poc_lsb - h->poc_lsb < -max_poc_lsb/2)
- h->poc_msb = h->prev_poc_msb - max_poc_lsb;
- else
- h->poc_msb = h->prev_poc_msb;
-//printf("poc: %d %d\n", h->poc_msb, h->poc_lsb);
- field_poc[0] =
- field_poc[1] = h->poc_msb + h->poc_lsb;
- if(s->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc_bottom;
- }else if(h->sps.poc_type==1){
- int abs_frame_num, expected_delta_per_poc_cycle, expectedpoc;
- int i;
-
- if(h->sps.poc_cycle_length != 0)
- abs_frame_num = h->frame_num_offset + h->frame_num;
- else
- abs_frame_num = 0;
-
- if(h->nal_ref_idc==0 && abs_frame_num > 0)
- abs_frame_num--;
-
- expected_delta_per_poc_cycle = 0;
- for(i=0; i < h->sps.poc_cycle_length; i++)
- expected_delta_per_poc_cycle += h->sps.offset_for_ref_frame[ i ]; //FIXME integrate during sps parse
-
- if(abs_frame_num > 0){
- int poc_cycle_cnt = (abs_frame_num - 1) / h->sps.poc_cycle_length;
- int frame_num_in_poc_cycle = (abs_frame_num - 1) % h->sps.poc_cycle_length;
-
- expectedpoc = poc_cycle_cnt * expected_delta_per_poc_cycle;
- for(i = 0; i <= frame_num_in_poc_cycle; i++)
- expectedpoc = expectedpoc + h->sps.offset_for_ref_frame[ i ];
- } else
- expectedpoc = 0;
-
- if(h->nal_ref_idc == 0)
- expectedpoc = expectedpoc + h->sps.offset_for_non_ref_pic;
-
- field_poc[0] = expectedpoc + h->delta_poc[0];
- field_poc[1] = field_poc[0] + h->sps.offset_for_top_to_bottom_field;
-
- if(s->picture_structure == PICT_FRAME)
- field_poc[1] += h->delta_poc[1];
- }else{
- int poc;
- if(h->nal_unit_type == NAL_IDR_SLICE){
- poc= 0;
- }else{
- if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num);
- else poc= 2*(h->frame_num_offset + h->frame_num) - 1;
- }
- field_poc[0]= poc;
- field_poc[1]= poc;
- }
-
- if(s->picture_structure != PICT_BOTTOM_FIELD)
- s->current_picture_ptr->field_poc[0]= field_poc[0];
- if(s->picture_structure != PICT_TOP_FIELD)
- s->current_picture_ptr->field_poc[1]= field_poc[1];
- if(s->picture_structure == PICT_FRAME) // FIXME field pix?
- s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]);
-
- return 0;
-}
-
-/**
- * decodes a slice header.
- * this will allso call MPV_common_init() and frame_start() as needed
- */
-static int decode_slice_header(H264Context *h){
- MpegEncContext * const s = &h->s;
- int first_mb_in_slice, pps_id;
- int num_ref_idx_active_override_flag;
- static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
- float new_aspect;
-
- s->current_picture.reference= h->nal_ref_idc != 0;
-
- first_mb_in_slice= get_ue_golomb(&s->gb);
-
- h->slice_type= get_ue_golomb(&s->gb);
- if(h->slice_type > 9){
- fprintf(stderr, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y);
- }
- if(h->slice_type > 4){
- h->slice_type -= 5;
- h->slice_type_fixed=1;
- }else
- h->slice_type_fixed=0;
-
- h->slice_type= slice_type_map[ h->slice_type ];
-
- s->pict_type= h->slice_type; // to make a few old func happy, its wrong though
-
- pps_id= get_ue_golomb(&s->gb);
- if(pps_id>255){
- fprintf(stderr, "pps_id out of range\n");
- return -1;
- }
- h->pps= h->pps_buffer[pps_id];
- if(h->pps.slice_group_count == 0){
- fprintf(stderr, "non existing PPS referenced\n");
- return -1;
- }
-
- h->sps= h->sps_buffer[ h->pps.sps_id ];
- if(h->sps.log2_max_frame_num == 0){
- fprintf(stderr, "non existing SPS referenced\n");
- return -1;
- }
-
- s->mb_width= h->sps.mb_width;
- s->mb_height= h->sps.mb_height;
-
- h->b_stride= s->mb_width*4;
- h->b8_stride= s->mb_width*2;
-
- s->mb_x = first_mb_in_slice % s->mb_width;
- s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW
-
- s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right );
- if(h->sps.frame_mbs_only_flag)
- s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom);
- else
- s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck
-
- if(s->aspected_height) //FIXME emms at end of slice ?
- new_aspect= h->sps.sar_width*s->width / (float)(s->height*h->sps.sar_height);
- else
- new_aspect=0;
-
- if (s->context_initialized
- && ( s->width != s->avctx->width || s->height != s->avctx->height
- || ABS(new_aspect - s->avctx->aspect_ratio) > 0.001)) {
- free_tables(h);
- MPV_common_end(s);
- }
- if (!s->context_initialized) {
- if (MPV_common_init(s) < 0)
- return -1;
-
- alloc_tables(h);
-
- s->avctx->width = s->width;
- s->avctx->height = s->height;
- s->avctx->aspect_ratio= new_aspect;
- }
-
- if(first_mb_in_slice == 0){
- frame_start(h);
- }
-
- s->current_picture_ptr->frame_num= //FIXME frame_num cleanup
- h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);
-
- if(h->sps.frame_mbs_only_flag){
- s->picture_structure= PICT_FRAME;
- }else{
- if(get_bits1(&s->gb)) //field_pic_flag
- s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
- else
- s->picture_structure= PICT_FRAME;
- }
-
- if(s->picture_structure==PICT_FRAME){
- h->curr_pic_num= h->frame_num;
- h->max_pic_num= 1<< h->sps.log2_max_frame_num;
- }else{
- h->curr_pic_num= 2*h->frame_num;
- h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);
- }
-
- if(h->nal_unit_type == NAL_IDR_SLICE){
- get_ue_golomb(&s->gb); /* idr_pic_id */
- }
-
- if(h->sps.poc_type==0){
- h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);
-
- if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){
- h->delta_poc_bottom= get_se_golomb(&s->gb);
- }
- }
-
- if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){
- h->delta_poc[0]= get_se_golomb(&s->gb);
-
- if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)
- h->delta_poc[1]= get_se_golomb(&s->gb);
- }
-
- init_poc(h);
-
- if(h->pps.redundant_pic_cnt_present){
- h->redundant_pic_count= get_ue_golomb(&s->gb);
- }
-
- //set defaults, might be overriden a few line later
- h->ref_count[0]= h->pps.ref_count[0];
- h->ref_count[1]= h->pps.ref_count[1];
-
- if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){
- if(h->slice_type == B_TYPE){
- h->direct_spatial_mv_pred= get_bits1(&s->gb);
- }
- num_ref_idx_active_override_flag= get_bits1(&s->gb);
-
- if(num_ref_idx_active_override_flag){
- h->ref_count[0]= get_ue_golomb(&s->gb) + 1;
- if(h->slice_type==B_TYPE)
- h->ref_count[1]= get_ue_golomb(&s->gb) + 1;
-
- if(h->ref_count[0] > 32 || h->ref_count[1] > 32){
- fprintf(stderr, "reference overflow\n");
- return -1;
- }
- }
- }
-
- if(first_mb_in_slice == 0){
- fill_default_ref_list(h);
- }
-
- decode_ref_pic_list_reordering(h);
-
- if( (h->pps.weighted_pred && (h->slice_type == P_TYPE || h->slice_type == SP_TYPE ))
- || (h->pps.weighted_bipred_idc==1 && h->slice_type==B_TYPE ) )
- pred_weight_table(h);
-
- if(s->current_picture.reference)
- decode_ref_pic_marking(h);
- //FIXME CABAC stuff
-
- s->qscale = h->pps.init_qp + get_se_golomb(&s->gb); //slice_qp_delta
- //FIXME qscale / qp ... stuff
- if(h->slice_type == SP_TYPE){
- get_bits1(&s->gb); /* sp_for_switch_flag */
- }
- if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){
- get_se_golomb(&s->gb); /* slice_qs_delta */
- }
-
- if( h->pps.deblocking_filter_parameters_present ) {
- h->disable_deblocking_filter_idc= get_ue_golomb(&s->gb);
- if( h->disable_deblocking_filter_idc != 1 ) {
- h->slice_alpha_c0_offset_div2= get_se_golomb(&s->gb);
- h->slice_beta_offset_div2= get_se_golomb(&s->gb);
- }
- }else
- h->disable_deblocking_filter_idc= 0;
-
-#if 0 //FMO
- if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)
- slice_group_change_cycle= get_bits(&s->gb, ?);
-#endif
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d\n",
- first_mb_in_slice,
- av_get_pict_type_char(h->slice_type),
- pps_id, h->frame_num,
- s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],
- h->ref_count[0], h->ref_count[1],
- s->qscale,
- h->disable_deblocking_filter_idc
- );
- }
-
- return 0;
-}
-
-/**
- *
- */
-static inline int get_level_prefix(GetBitContext *gb){
- unsigned int buf;
- int log;
-
- OPEN_READER(re, gb);
- UPDATE_CACHE(re, gb);
- buf=GET_CACHE(re, gb);
-
- log= 32 - av_log2(buf);
-#ifdef TRACE
- print_bin(buf>>(32-log), log);
- printf("%5d %2d %3d lpr @%5d in %s get_level_prefix\n", buf>>(32-log), log, log-1, get_bits_count(gb), __FILE__);
-#endif
-
- LAST_SKIP_BITS(re, gb, log);
- CLOSE_READER(re, gb);
-
- return log-1;
-}
-
-/**
- * decodes a residual block.
- * @param n block index
- * @param scantable scantable
- * @param max_coeff number of coefficients in the block
- * @return <0 if an error occured
- */
-static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, int qp, int max_coeff){
- MpegEncContext * const s = &h->s;
- const uint16_t *qmul= dequant_coeff[qp];
- static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3};
- int level[16], run[16];
- int suffix_length, zeros_left, coeff_num, coeff_token, total_coeff, i, trailing_ones;
-
- //FIXME put trailing_onex into the context
-
- if(n == CHROMA_DC_BLOCK_INDEX){
- coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1);
- total_coeff= coeff_token>>2;
- }else{
- if(n == LUMA_DC_BLOCK_INDEX){
- total_coeff= pred_non_zero_count(h, 0);
- coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
- total_coeff= coeff_token>>2;
- }else{
- total_coeff= pred_non_zero_count(h, n);
- coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2);
- total_coeff= coeff_token>>2;
- h->non_zero_count_cache[ scan8[n] ]= total_coeff;
- }
- }
-
- //FIXME set last_non_zero?
-
- if(total_coeff==0)
- return 0;
-
- trailing_ones= coeff_token&3;
- tprintf("trailing:%d, total:%d\n", trailing_ones, total_coeff);
- assert(total_coeff<=16);
-
- for(i=0; i<trailing_ones; i++){
- level[i]= 1 - 2*get_bits1(gb);
- }
-
- suffix_length= total_coeff > 10 && trailing_ones < 3;
-
- for(; i<total_coeff; i++){
- const int prefix= get_level_prefix(gb);
- int level_code, mask;
-
- if(prefix<14){ //FIXME try to build a large unified VLC table for all this
- if(suffix_length)
- level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part
- else
- level_code= (prefix<<suffix_length); //part
- }else if(prefix==14){
- if(suffix_length)
- level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part
- else
- level_code= prefix + get_bits(gb, 4); //part
- }else if(prefix==15){
- level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part
- if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense
- }else{
- fprintf(stderr, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if(i==trailing_ones && i<3) level_code+= 2; //FIXME split first iteration
-
- mask= -(level_code&1);
- level[i]= (((2+level_code)>>1) ^ mask) - mask;
-
- if(suffix_length==0) suffix_length=1; //FIXME split first iteration
-
-#if 1
- if(ABS(level[i]) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++;
-#else
- if((2+level_code)>>1) > (3<<(suffix_length-1)) && suffix_length<6) suffix_length++;
- ? == prefix > 2 or sth
-#endif
- tprintf("level: %d suffix_length:%d\n", level[i], suffix_length);
- }
-
- if(total_coeff == max_coeff)
- zeros_left=0;
- else{
- if(n == CHROMA_DC_BLOCK_INDEX)
- zeros_left= get_vlc2(gb, chroma_dc_total_zeros_vlc[ total_coeff-1 ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
- else
- zeros_left= get_vlc2(gb, total_zeros_vlc[ total_coeff-1 ].table, TOTAL_ZEROS_VLC_BITS, 1);
- }
-
- for(i=0; i<total_coeff-1; i++){
- if(zeros_left <=0)
- break;
- else if(zeros_left < 7){
- run[i]= get_vlc2(gb, run_vlc[zeros_left-1].table, RUN_VLC_BITS, 1);
- }else{
- run[i]= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
- }
- zeros_left -= run[i];
- }
-
- if(zeros_left<0){
- fprintf(stderr, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- for(; i<total_coeff-1; i++){
- run[i]= 0;
- }
-
- run[i]= zeros_left;
-
- coeff_num=-1;
- if(n > 24){
- for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode?
- int j;
-
- coeff_num += run[i] + 1; //FIXME add 1 earlier ?
- j= scantable[ coeff_num ];
-
- block[j]= level[i];
- }
- }else{
- for(i=total_coeff-1; i>=0; i--){ //FIXME merge into rundecode?
- int j;
-
- coeff_num += run[i] + 1; //FIXME add 1 earlier ?
- j= scantable[ coeff_num ];
-
- block[j]= level[i] * qmul[j];
-// printf("%d %d ", block[j], qmul[j]);
- }
- }
- return 0;
-}
-
-/**
- * decodes a macroblock
- * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed
- */
-static int decode_mb(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
- int mb_type, partition_count, cbp;
-
- s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong?
-
- tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
- cbp = 0; /* avoid warning. FIXME: find a solution without slowing
- down the code */
- if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){
- if(s->mb_skip_run==-1)
- s->mb_skip_run= get_ue_golomb(&s->gb);
-
- if (s->mb_skip_run--) {
- int mx, my;
- /* skip mb */
-//FIXME b frame
- mb_type= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0;
-
- memset(h->non_zero_count[mb_xy], 0, 16);
- memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui
-
- if(h->sps.mb_aff && s->mb_skip_run==0 && (s->mb_y&1)==0){
- h->mb_field_decoding_flag= get_bits1(&s->gb);
- }
-
- if(h->mb_field_decoding_flag)
- mb_type|= MB_TYPE_INTERLACED;
-
- fill_caches(h, mb_type); //FIXME check what is needed and what not ...
- pred_pskip_motion(h, &mx, &my);
- fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
- fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);
- write_back_motion(h, mb_type);
-
- s->current_picture.mb_type[mb_xy]= mb_type; //FIXME SKIP type
- h->slice_table[ mb_xy ]= h->slice_num;
-
- h->prev_mb_skiped= 1;
- return 0;
- }
- }
- if(h->sps.mb_aff /* && !field pic FIXME needed? */){
- if((s->mb_y&1)==0)
- h->mb_field_decoding_flag = get_bits1(&s->gb);
- }else
- h->mb_field_decoding_flag=0; //FIXME som ed note ?!
-
- h->prev_mb_skiped= 0;
-
- mb_type= get_ue_golomb(&s->gb);
- if(h->slice_type == B_TYPE){
- if(mb_type < 23){
- partition_count= b_mb_type_info[mb_type].partition_count;
- mb_type= b_mb_type_info[mb_type].type;
- }else{
- mb_type -= 23;
- goto decode_intra_mb;
- }
- }else if(h->slice_type == P_TYPE /*|| h->slice_type == SP_TYPE */){
- if(mb_type < 5){
- partition_count= p_mb_type_info[mb_type].partition_count;
- mb_type= p_mb_type_info[mb_type].type;
- }else{
- mb_type -= 5;
- goto decode_intra_mb;
- }
- }else{
- assert(h->slice_type == I_TYPE);
-decode_intra_mb:
- if(mb_type > 25){
- fprintf(stderr, "mb_type %d in %c slice to large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y);
- return -1;
- }
- partition_count=0;
- cbp= i_mb_type_info[mb_type].cbp;
- h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;
- mb_type= i_mb_type_info[mb_type].type;
- }
-
- if(h->mb_field_decoding_flag)
- mb_type |= MB_TYPE_INTERLACED;
-
- s->current_picture.mb_type[mb_xy]= mb_type;
- h->slice_table[ mb_xy ]= h->slice_num;
-
- if(IS_INTRA_PCM(mb_type)){
- const uint8_t *ptr;
- int x, y;
-
- // we assume these blocks are very rare so we dont optimize it
- align_get_bits(&s->gb);
-
- ptr= s->gb.buffer + get_bits_count(&s->gb);
-
- for(y=0; y<16; y++){
- const int index= 4*(y&3) + 64*(y>>2);
- for(x=0; x<16; x++){
- h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++);
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++);
- }
- }
- for(y=0; y<8; y++){
- const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
- for(x=0; x<8; x++){
- h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++);
- }
- }
-
- skip_bits(&s->gb, 384); //FIXME check /fix the bitstream readers
-
- memset(h->non_zero_count[mb_xy], 16, 16);
-
- return 0;
- }
-
- fill_caches(h, mb_type);
-
- //mb_pred
- if(IS_INTRA(mb_type)){
-// init_top_left_availability(h);
- if(IS_INTRA4x4(mb_type)){
- int i;
-
-// fill_intra4x4_pred_table(h);
- for(i=0; i<16; i++){
- const int mode_coded= !get_bits1(&s->gb);
- const int predicted_mode= pred_intra_mode(h, i);
- int mode;
-
- if(mode_coded){
- const int rem_mode= get_bits(&s->gb, 3);
- if(rem_mode<predicted_mode)
- mode= rem_mode;
- else
- mode= rem_mode + 1;
- }else{
- mode= predicted_mode;
- }
-
- h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;
- }
- write_back_intra_pred_mode(h);
- if( check_intra4x4_pred_mode(h) < 0)
- return -1;
- }else{
- h->intra16x16_pred_mode= check_intra_pred_mode(h, h->intra16x16_pred_mode);
- if(h->intra16x16_pred_mode < 0)
- return -1;
- }
- h->chroma_pred_mode= get_ue_golomb(&s->gb);
-
- h->chroma_pred_mode= check_intra_pred_mode(h, h->chroma_pred_mode);
- if(h->chroma_pred_mode < 0)
- return -1;
- }else if(partition_count==4){
- int i, j, sub_partition_count[4], list, ref[2][4];
-
- if(h->slice_type == B_TYPE){
- for(i=0; i<4; i++){
- h->sub_mb_type[i]= get_ue_golomb(&s->gb);
- if(h->sub_mb_type[i] >=13){
- fprintf(stderr, "B sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
- return -1;
- }
- sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
- h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;
- }
- }else{
- assert(h->slice_type == P_TYPE || h->slice_type == SP_TYPE); //FIXME SP correct ?
- for(i=0; i<4; i++){
- h->sub_mb_type[i]= get_ue_golomb(&s->gb);
- if(h->sub_mb_type[i] >=4){
- fprintf(stderr, "P sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y);
- return -1;
- }
- sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;
- h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;
- }
- }
-
- for(list=0; list<2; list++){
- const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
- if(ref_count == 0) continue;
- for(i=0; i<4; i++){
- if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){
- ref[list][i] = get_te0_golomb(&s->gb, ref_count); //FIXME init to 0 before and skip?
- }else{
- //FIXME
- ref[list][i] = -1;
- }
- }
- }
-
- for(list=0; list<2; list++){
- const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
- if(ref_count == 0) continue;
-
- for(i=0; i<4; i++){
- h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]=
- h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];
-
- if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){
- const int sub_mb_type= h->sub_mb_type[i];
- const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;
- for(j=0; j<sub_partition_count[i]; j++){
- int mx, my;
- const int index= 4*i + block_width*j;
- int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
- pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- if(IS_SUB_8X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]=
- mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]=
- mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
- }else if(IS_SUB_8X4(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 1 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 1 ][1]= my;
- }else if(IS_SUB_4X8(sub_mb_type)){
- mv_cache[ 0 ][0]= mv_cache[ 8 ][0]= mx;
- mv_cache[ 0 ][1]= mv_cache[ 8 ][1]= my;
- }else{
- assert(IS_SUB_4X4(sub_mb_type));
- mv_cache[ 0 ][0]= mx;
- mv_cache[ 0 ][1]= my;
- }
- }
- }else{
- uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];
- p[0] = p[1]=
- p[8] = p[9]= 0;
- }
- }
- }
- }else if(!IS_DIRECT(mb_type)){
- int list, mx, my, i;
- //FIXME we should set ref_idx_l? to 0 if we use that later ...
- if(IS_16X16(mb_type)){
- for(list=0; list<2; list++){
- if(h->ref_count[0]>0){
- if(IS_DIR(mb_type, 0, list)){
- const int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
- }
- }
- }
- for(list=0; list<2; list++){
- if(IS_DIR(mb_type, 0, list)){
- pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
- }
- }
- }
- else if(IS_16X8(mb_type)){
- for(list=0; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){
- const int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);
- }
- }
- }
- }
- for(list=0; list<2; list++){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){
- pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
- }
- }
- }
- }else{
- assert(IS_8X16(mb_type));
- for(list=0; list<2; list++){
- if(h->ref_count[list]>0){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){ //FIXME optimize
- const int val= get_te0_golomb(&s->gb, h->ref_count[list]);
- fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);
- }
- }
- }
- }
- for(list=0; list<2; list++){
- for(i=0; i<2; i++){
- if(IS_DIR(mb_type, i, list)){
- pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
- mx += get_se_golomb(&s->gb);
- my += get_se_golomb(&s->gb);
- tprintf("final mv:%d %d\n", mx, my);
-
- fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
- }
- }
- }
- }
- }
-
- if(IS_INTER(mb_type))
- write_back_motion(h, mb_type);
-
- if(!IS_INTRA16x16(mb_type)){
- cbp= get_ue_golomb(&s->gb);
- if(cbp > 47){
- fprintf(stderr, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y);
- return -1;
- }
-
- if(IS_INTRA4x4(mb_type))
- cbp= golomb_to_intra4x4_cbp[cbp];
- else
- cbp= golomb_to_inter_cbp[cbp];
- }
-
- if(cbp || IS_INTRA16x16(mb_type)){
- int i8x8, i4x4, chroma_idx;
- int chroma_qp, dquant;
- GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
- const uint8_t *scan, *dc_scan;
-
-// fill_non_zero_count_cache(h);
-
- if(IS_INTERLACED(mb_type)){
- scan= field_scan;
- dc_scan= luma_dc_field_scan;
- }else{
- scan= zigzag_scan;
- dc_scan= luma_dc_zigzag_scan;
- }
-
- dquant= get_se_golomb(&s->gb);
-
- if( dquant > 25 || dquant < -26 ){
- fprintf(stderr, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
- return -1;
- }
-
- s->qscale += dquant;
- if(((unsigned)s->qscale) > 51){
- if(s->qscale<0) s->qscale+= 52;
- else s->qscale-= 52;
- }
-
- h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale);
- if(IS_INTRA16x16(mb_type)){
- if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){
- return -1; //FIXME continue if partotioned and other retirn -1 too
- }
-
- assert((cbp&15) == 0 || (cbp&15) == 15);
-
- if(cbp&15){
- for(i8x8=0; i8x8<4; i8x8++){
- for(i4x4=0; i4x4<4; i4x4++){
- const int index= i4x4 + 4*i8x8;
- if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, s->qscale, 15) < 0 ){
- return -1;
- }
- }
- }
- }else{
- memset(&h->non_zero_count_cache[8], 0, 8*4); //FIXME stupid & slow
- }
- }else{
- for(i8x8=0; i8x8<4; i8x8++){
- if(cbp & (1<<i8x8)){
- for(i4x4=0; i4x4<4; i4x4++){
- const int index= i4x4 + 4*i8x8;
-
- if( decode_residual(h, gb, h->mb + 16*index, index, scan, s->qscale, 16) <0 ){
- return -1;
- }
- }
- }else{
- uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
- nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;
- }
- }
- }
-
- if(cbp&0x30){
- for(chroma_idx=0; chroma_idx<2; chroma_idx++)
- if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX, chroma_dc_scan, chroma_qp, 4) < 0){
- return -1;
- }
- }
-
- if(cbp&0x20){
- for(chroma_idx=0; chroma_idx<2; chroma_idx++){
- for(i4x4=0; i4x4<4; i4x4++){
- const int index= 16 + 4*chroma_idx + i4x4;
- if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, chroma_qp, 15) < 0){
- return -1;
- }
- }
- }
- }else{
- uint8_t * const nnz= &h->non_zero_count_cache[0];
- nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =
- nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;
- }
- }else{
- memset(&h->non_zero_count_cache[8], 0, 8*5);
- }
- write_back_non_zero_count(h);
-
- return 0;
-}
-
-static int decode_slice(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
-
- s->mb_skip_run= -1;
-
-#if 1
- for(;;){
- int ret= decode_mb(h);
-
- hl_decode_mb(h);
-
- if(ret>=0 && h->sps.mb_aff){ //FIXME optimal? or let mb_decode decode 16x32 ?
- s->mb_y++;
- ret= decode_mb(h);
-
- hl_decode_mb(h);
- s->mb_y--;
- }
-
- if(ret<0){
- fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- if(++s->mb_y >= s->mb_height){
- tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
-
- if(get_bits_count(&s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
- }
- }
- }
-
- if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){
- if(get_bits_count(&s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
- }
- }
-#endif
-#if 0
- for(;s->mb_y < s->mb_height; s->mb_y++){
- for(;s->mb_x < s->mb_width; s->mb_x++){
- int ret= decode_mb(h);
-
- hl_decode_mb(h);
-
- if(ret<0){
- fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
-
- if(++s->mb_x >= s->mb_width){
- s->mb_x=0;
- if(++s->mb_y >= s->mb_height){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return -1;
- }
- }
- }
-
- if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){
- if(get_bits_count(s->gb) == s->gb.size_in_bits){
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
-
- return 0;
- }else{
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
-
- return -1;
- }
- }
- }
- s->mb_x=0;
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- }
-#endif
- return -1; //not reached
-}
-
-static inline int decode_vui_parameters(H264Context *h, SPS *sps){
- MpegEncContext * const s = &h->s;
- int aspect_ratio_info_present_flag, aspect_ratio_idc;
-
- aspect_ratio_info_present_flag= get_bits1(&s->gb);
-
- if( aspect_ratio_info_present_flag ) {
- aspect_ratio_idc= get_bits(&s->gb, 8);
- if( aspect_ratio_idc == EXTENDED_SAR ) {
- sps->sar_width= get_bits(&s->gb, 16);
- sps->sar_height= get_bits(&s->gb, 16);
- }else if(aspect_ratio_idc < 16){
- sps->sar_width= pixel_aspect[aspect_ratio_idc][0];
- sps->sar_height= pixel_aspect[aspect_ratio_idc][1];
- }else{
- fprintf(stderr, "illegal aspect ratio\n");
- return -1;
- }
- }else{
- sps->sar_width=
- sps->sar_height= 0;
- }
-// s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height);
-#if 0
-| overscan_info_present_flag |0 |u(1) |
-| if( overscan_info_present_flag ) | | |
-| overscan_appropriate_flag |0 |u(1) |
-| video_signal_type_present_flag |0 |u(1) |
-| if( video_signal_type_present_flag ) { | | |
-| video_format |0 |u(3) |
-| video_full_range_flag |0 |u(1) |
-| colour_description_present_flag |0 |u(1) |
-| if( colour_description_present_flag ) { | | |
-| colour_primaries |0 |u(8) |
-| transfer_characteristics |0 |u(8) |
-| matrix_coefficients |0 |u(8) |
-| } | | |
-| } | | |
-| chroma_location_info_present_flag |0 |u(1) |
-| if ( chroma_location_info_present_flag ) { | | |
-| chroma_sample_location_type_top_field |0 |ue(v) |
-| chroma_sample_location_type_bottom_field |0 |ue(v) |
-| } | | |
-| timing_info_present_flag |0 |u(1) |
-| if( timing_info_present_flag ) { | | |
-| num_units_in_tick |0 |u(32) |
-| time_scale |0 |u(32) |
-| fixed_frame_rate_flag |0 |u(1) |
-| } | | |
-| nal_hrd_parameters_present_flag |0 |u(1) |
-| if( nal_hrd_parameters_present_flag = = 1) | | |
-| hrd_parameters( ) | | |
-| vcl_hrd_parameters_present_flag |0 |u(1) |
-| if( vcl_hrd_parameters_present_flag = = 1) | | |
-| hrd_parameters( ) | | |
-| if( ( nal_hrd_parameters_present_flag = = 1 | || | |
-| | | |
-|( vcl_hrd_parameters_present_flag = = 1 ) ) | | |
-| low_delay_hrd_flag |0 |u(1) |
-| bitstream_restriction_flag |0 |u(1) |
-| if( bitstream_restriction_flag ) { |0 |u(1) |
-| motion_vectors_over_pic_boundaries_flag |0 |u(1) |
-| max_bytes_per_pic_denom |0 |ue(v) |
-| max_bits_per_mb_denom |0 |ue(v) |
-| log2_max_mv_length_horizontal |0 |ue(v) |
-| log2_max_mv_length_vertical |0 |ue(v) |
-| num_reorder_frames |0 |ue(v) |
-| max_dec_frame_buffering |0 |ue(v) |
-| } | | |
-|} | | |
-#endif
- return 0;
-}
-
-static inline int decode_seq_parameter_set(H264Context *h){
- MpegEncContext * const s = &h->s;
- int profile_idc, level_idc;
- int sps_id, i;
- SPS *sps;
-
- profile_idc= get_bits(&s->gb, 8);
- get_bits1(&s->gb); //constraint_set0_flag
- get_bits1(&s->gb); //constraint_set1_flag
- get_bits1(&s->gb); //constraint_set2_flag
- get_bits(&s->gb, 5); // reserved
- level_idc= get_bits(&s->gb, 8);
- sps_id= get_ue_golomb(&s->gb);
-
- sps= &h->sps_buffer[ sps_id ];
- sps->profile_idc= profile_idc;
- sps->level_idc= level_idc;
-
- sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
- sps->poc_type= get_ue_golomb(&s->gb);
-
- if(sps->poc_type == 0){ //FIXME #define
- sps->log2_max_poc_lsb= get_ue_golomb(&s->gb) + 4;
- } else if(sps->poc_type == 1){//FIXME #define
- sps->delta_pic_order_always_zero_flag= get_bits1(&s->gb);
- sps->offset_for_non_ref_pic= get_se_golomb(&s->gb);
- sps->offset_for_top_to_bottom_field= get_se_golomb(&s->gb);
- sps->poc_cycle_length= get_ue_golomb(&s->gb);
-
- for(i=0; i<sps->poc_cycle_length; i++)
- sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb);
- }
- if(sps->poc_type > 2){
- fprintf(stderr, "illegal POC type %d\n", sps->poc_type);
- return -1;
- }
-
- sps->ref_frame_count= get_ue_golomb(&s->gb);
- sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb);
- sps->mb_width= get_ue_golomb(&s->gb) + 1;
- sps->mb_height= get_ue_golomb(&s->gb) + 1;
- sps->frame_mbs_only_flag= get_bits1(&s->gb);
- if(!sps->frame_mbs_only_flag)
- sps->mb_aff= get_bits1(&s->gb);
- else
- sps->mb_aff= 0;
-
- sps->direct_8x8_inference_flag= get_bits1(&s->gb);
-
- sps->crop= get_bits1(&s->gb);
- if(sps->crop){
- sps->crop_left = get_ue_golomb(&s->gb);
- sps->crop_right = get_ue_golomb(&s->gb);
- sps->crop_top = get_ue_golomb(&s->gb);
- sps->crop_bottom= get_ue_golomb(&s->gb);
- if(sps->crop_left || sps->crop_top){
- fprintf(stderr, "insane croping not completly supported, this could look slightly wrong ...\n");
- }
- }else{
- sps->crop_left =
- sps->crop_right =
- sps->crop_top =
- sps->crop_bottom= 0;
- }
-
- sps->vui_parameters_present_flag= get_bits1(&s->gb);
- if( sps->vui_parameters_present_flag )
- decode_vui_parameters(h, sps);
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("sps:%d profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s\n",
- sps_id, sps->profile_idc, sps->level_idc,
- sps->poc_type,
- sps->ref_frame_count,
- sps->mb_width, sps->mb_height,
- sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),
- sps->direct_8x8_inference_flag ? "8B8" : "",
- sps->crop_left, sps->crop_right,
- sps->crop_top, sps->crop_bottom,
- sps->vui_parameters_present_flag ? "VUI" : ""
- );
- }
- return 0;
-}
-
-static inline int decode_picture_parameter_set(H264Context *h){
- MpegEncContext * const s = &h->s;
- int pps_id= get_ue_golomb(&s->gb);
- PPS *pps= &h->pps_buffer[pps_id];
-
- pps->sps_id= get_ue_golomb(&s->gb);
- pps->cabac= get_bits1(&s->gb);
- pps->pic_order_present= get_bits1(&s->gb);
- pps->slice_group_count= get_ue_golomb(&s->gb) + 1;
- if(pps->slice_group_count > 1 ){
- pps->mb_slice_group_map_type= get_ue_golomb(&s->gb);
-fprintf(stderr, "FMO not supported\n");
- switch(pps->mb_slice_group_map_type){
- case 0:
-#if 0
-| for( i = 0; i <= num_slice_groups_minus1; i++ ) | | |
-| run_length[ i ] |1 |ue(v) |
-#endif
- break;
- case 2:
-#if 0
-| for( i = 0; i < num_slice_groups_minus1; i++ ) | | |
-|{ | | |
-| top_left_mb[ i ] |1 |ue(v) |
-| bottom_right_mb[ i ] |1 |ue(v) |
-| } | | |
-#endif
- break;
- case 3:
- case 4:
- case 5:
-#if 0
-| slice_group_change_direction_flag |1 |u(1) |
-| slice_group_change_rate_minus1 |1 |ue(v) |
-#endif
- break;
- case 6:
-#if 0
-| slice_group_id_cnt_minus1 |1 |ue(v) |
-| for( i = 0; i <= slice_group_id_cnt_minus1; i++ | | |
-|) | | |
-| slice_group_id[ i ] |1 |u(v) |
-#endif
- break;
- }
- }
- pps->ref_count[0]= get_ue_golomb(&s->gb) + 1;
- pps->ref_count[1]= get_ue_golomb(&s->gb) + 1;
- if(pps->ref_count[0] > 32 || pps->ref_count[1] > 32){
- fprintf(stderr, "reference overflow (pps)\n");
- return -1;
- }
-
- pps->weighted_pred= get_bits1(&s->gb);
- pps->weighted_bipred_idc= get_bits(&s->gb, 2);
- pps->init_qp= get_se_golomb(&s->gb) + 26;
- pps->init_qs= get_se_golomb(&s->gb) + 26;
- pps->chroma_qp_index_offset= get_se_golomb(&s->gb);
- pps->deblocking_filter_parameters_present= get_bits1(&s->gb);
- pps->constrained_intra_pred= get_bits1(&s->gb);
- pps->redundant_pic_cnt_present = get_bits1(&s->gb);
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("pps:%d sps:%d %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s\n",
- pps_id, pps->sps_id,
- pps->cabac ? "CABAC" : "CAVLC",
- pps->slice_group_count,
- pps->ref_count[0], pps->ref_count[1],
- pps->weighted_pred ? "weighted" : "",
- pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset,
- pps->deblocking_filter_parameters_present ? "LPAR" : "",
- pps->constrained_intra_pred ? "CONSTR" : "",
- pps->redundant_pic_cnt_present ? "REDU" : ""
- );
- }
-
- return 0;
-}
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
- ParseContext *pc= &s->parse_context;
- int i;
- uint32_t state;
-//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]);
-// mb_addr= pc->mb_addr - 1;
- state= pc->state;
- //FIXME this will fail with slices
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){
- if(pc->frame_start_found){
- pc->state=-1;
- pc->frame_start_found= 0;
- return i-3;
- }
- pc->frame_start_found= 1;
- }
- }
-
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){
- MpegEncContext * const s = &h->s;
- AVCodecContext * const avctx= s->avctx;
- int buf_index=0;
-#if 0
- int i;
- for(i=0; i<32; i++){
- printf("%X ", buf[i]);
- }
-#endif
- for(;;){
- int consumed;
- int dst_length;
- int bit_length;
- uint8_t *ptr;
-
- // start code prefix search
- for(; buf_index + 3 < buf_size; buf_index++){
- // this should allways succeed in the first iteration
- if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)
- break;
- }
-
- if(buf_index+3 >= buf_size) break;
-
- buf_index+=3;
-
- ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, buf_size - buf_index);
- if(ptr[dst_length - 1] == 0) dst_length--;
- bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1);
-
- if(s->avctx->debug&FF_DEBUG_STARTCODE){
- printf("NAL %d at %d length %d\n", h->nal_unit_type, buf_index, dst_length);
- }
-
- buf_index += consumed;
-
- if(h->nal_ref_idc < s->hurry_up)
- continue;
-
- switch(h->nal_unit_type){
- case NAL_IDR_SLICE:
- idr(h); //FIXME ensure we dont loose some frames if there is reordering
- case NAL_SLICE:
- init_get_bits(&s->gb, ptr, bit_length);
- h->intra_gb_ptr=
- h->inter_gb_ptr= &s->gb;
- s->data_partitioning = 0;
-
- if(decode_slice_header(h) < 0) return -1;
- if(h->redundant_pic_count==0)
- decode_slice(h);
- break;
- case NAL_DPA:
- init_get_bits(&s->gb, ptr, bit_length);
- h->intra_gb_ptr=
- h->inter_gb_ptr= NULL;
- s->data_partitioning = 1;
-
- if(decode_slice_header(h) < 0) return -1;
- break;
- case NAL_DPB:
- init_get_bits(&h->intra_gb, ptr, bit_length);
- h->intra_gb_ptr= &h->intra_gb;
- break;
- case NAL_DPC:
- init_get_bits(&h->inter_gb, ptr, bit_length);
- h->inter_gb_ptr= &h->inter_gb;
-
- if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning)
- decode_slice(h);
- break;
- case NAL_SEI:
- break;
- case NAL_SPS:
- init_get_bits(&s->gb, ptr, bit_length);
- decode_seq_parameter_set(h);
-
- if(s->flags& CODEC_FLAG_LOW_DELAY)
- s->low_delay=1;
-
- avctx->has_b_frames= !s->low_delay;
- break;
- case NAL_PPS:
- init_get_bits(&s->gb, ptr, bit_length);
-
- decode_picture_parameter_set(h);
-
- break;
- case NAL_PICTURE_DELIMITER:
- break;
- case NAL_FILTER_DATA:
- break;
- }
-
- //FIXME move after where irt is set
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
- }
-
- if(!s->current_picture_ptr) return buf_index; //no frame
-
- h->prev_frame_num_offset= h->frame_num_offset;
- h->prev_frame_num= h->frame_num;
- if(s->current_picture_ptr->reference){
- h->prev_poc_msb= h->poc_msb;
- h->prev_poc_lsb= h->poc_lsb;
- }
- if(s->current_picture_ptr->reference)
- execute_ref_pic_marking(h, h->mmco, h->mmco_index);
- else
- assert(h->mmco_index==0);
-
- ff_er_frame_end(s);
- MPV_frame_end(s);
-
- return buf_index;
-}
-
-/**
- * retunrs the number of bytes consumed for building the current frame
- */
-static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){
- if(s->flags&CODEC_FLAG_TRUNCATED){
- pos -= s->parse_context.last_index;
- if(pos<0) pos=0; // FIXME remove (uneeded?)
-
- return pos;
- }else{
- if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
- if(pos+10>buf_size) pos=buf_size; // oops ;)
-
- return pos;
- }
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- H264Context *h = avctx->priv_data;
- MpegEncContext *s = &h->s;
- AVFrame *pict = data;
- int buf_index;
-
- s->flags= avctx->flags;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(s->flags&CODEC_FLAG_TRUNCATED){
- int next= find_frame_end(s, buf, buf_size);
-
- if( ff_combine_frame(s, next, &buf, &buf_size) < 0 )
- return buf_size;
-//printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index);
- }
-
- if(s->avctx->extradata_size && s->picture_number==0){
- if(0 < decode_nal_units(h, s->avctx->extradata, s->avctx->extradata_size) )
- return -1;
- }
-
- buf_index=decode_nal_units(h, buf, buf_size);
- if(buf_index < 0)
- return -1;
-
- //FIXME do something with unavailable reference frames
-
-// if(ret==FRAME_SKIPED) return get_consumed_bytes(s, buf_index, buf_size);
-#if 0
- if(s->pict_type==B_TYPE || s->low_delay){
- *pict= *(AVFrame*)&s->current_picture;
- } else {
- *pict= *(AVFrame*)&s->last_picture;
- }
-#endif
- if(!s->current_picture_ptr){
- fprintf(stderr, "error, NO frame\n");
- return -1;
- }
-
- *pict= *(AVFrame*)&s->current_picture; //FIXME
- ff_print_debug_info(s, s->current_picture_ptr);
- assert(pict->data[0]);
-//printf("out %d\n", (int)pict->data[0]);
-#if 0 //?
-
- /* Return the Picture timestamp as the frame number */
- /* we substract 1 because it is added on utils.c */
- avctx->frame_number = s->picture_number - 1;
-#endif
-#if 0
- /* dont output the last pic after seeking */
- if(s->last_picture_ptr || s->low_delay)
- //Note this isnt a issue as a IDR pic should flush teh buffers
-#endif
- *data_size = sizeof(AVFrame);
- return get_consumed_bytes(s, buf_index, buf_size);
-}
-#if 0
-static inline void fill_mb_avail(H264Context *h){
- MpegEncContext * const s = &h->s;
- const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
-
- if(s->mb_y){
- h->mb_avail[0]= s->mb_x && h->slice_table[mb_xy - s->mb_stride - 1] == h->slice_num;
- h->mb_avail[1]= h->slice_table[mb_xy - s->mb_stride ] == h->slice_num;
- h->mb_avail[2]= s->mb_x+1 < s->mb_width && h->slice_table[mb_xy - s->mb_stride + 1] == h->slice_num;
- }else{
- h->mb_avail[0]=
- h->mb_avail[1]=
- h->mb_avail[2]= 0;
- }
- h->mb_avail[3]= s->mb_x && h->slice_table[mb_xy - 1] == h->slice_num;
- h->mb_avail[4]= 1; //FIXME move out
- h->mb_avail[5]= 0; //FIXME move out
-}
-#endif
-
-#if 0 //selftest
-#define COUNT 8000
-#define SIZE (COUNT*40)
-int main(){
- int i;
- uint8_t temp[SIZE];
- PutBitContext pb;
- GetBitContext gb;
-// int int_temp[10000];
- DSPContext dsp;
- AVCodecContext avctx;
-
- dsputil_init(&dsp, &avctx);
-
- init_put_bits(&pb, temp, SIZE, NULL, NULL);
- printf("testing unsigned exp golomb\n");
- for(i=0; i<COUNT; i++){
- START_TIMER
- set_ue_golomb(&pb, i);
- STOP_TIMER("set_ue_golomb");
- }
- flush_put_bits(&pb);
-
- init_get_bits(&gb, temp, 8*SIZE);
- for(i=0; i<COUNT; i++){
- int j, s;
-
- s= show_bits(&gb, 24);
-
- START_TIMER
- j= get_ue_golomb(&gb);
- if(j != i){
- printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
-// return -1;
- }
- STOP_TIMER("get_ue_golomb");
- }
-
-
- init_put_bits(&pb, temp, SIZE, NULL, NULL);
- printf("testing signed exp golomb\n");
- for(i=0; i<COUNT; i++){
- START_TIMER
- set_se_golomb(&pb, i - COUNT/2);
- STOP_TIMER("set_se_golomb");
- }
- flush_put_bits(&pb);
-
- init_get_bits(&gb, temp, 8*SIZE);
- for(i=0; i<COUNT; i++){
- int j, s;
-
- s= show_bits(&gb, 24);
-
- START_TIMER
- j= get_se_golomb(&gb);
- if(j != i - COUNT/2){
- printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s);
-// return -1;
- }
- STOP_TIMER("get_se_golomb");
- }
-
- printf("testing 4x4 (I)DCT\n");
-
- DCTELEM block[16];
- uint8_t src[16], ref[16];
- uint64_t error= 0, max_error=0;
-
- for(i=0; i<COUNT; i++){
- int j;
-// printf("%d %d %d\n", r1, r2, (r2-r1)*16);
- for(j=0; j<16; j++){
- ref[j]= random()%255;
- src[j]= random()%255;
- }
-
- h264_diff_dct_c(block, src, ref, 4);
-
- //normalize
- for(j=0; j<16; j++){
-// printf("%d ", block[j]);
- block[j]= block[j]*4;
- if(j&1) block[j]= (block[j]*4 + 2)/5;
- if(j&4) block[j]= (block[j]*4 + 2)/5;
- }
-// printf("\n");
-
- h264_add_idct_c(ref, block, 4);
-/* for(j=0; j<16; j++){
- printf("%d ", ref[j]);
- }
- printf("\n");*/
-
- for(j=0; j<16; j++){
- int diff= ABS(src[j] - ref[j]);
-
- error+= diff*diff;
- max_error= FFMAX(max_error, diff);
- }
- }
- printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error );
-#if 0
- printf("testing quantizer\n");
- for(qp=0; qp<52; qp++){
- for(i=0; i<16; i++)
- src1_block[i]= src2_block[i]= random()%255;
-
- }
-#endif
- printf("Testing NAL layer\n");
-
- uint8_t bitstream[COUNT];
- uint8_t nal[COUNT*2];
- H264Context h;
- memset(&h, 0, sizeof(H264Context));
-
- for(i=0; i<COUNT; i++){
- int zeros= i;
- int nal_length;
- int consumed;
- int out_length;
- uint8_t *out;
- int j;
-
- for(j=0; j<COUNT; j++){
- bitstream[j]= (random() % 255) + 1;
- }
-
- for(j=0; j<zeros; j++){
- int pos= random() % COUNT;
- while(bitstream[pos] == 0){
- pos++;
- pos %= COUNT;
- }
- bitstream[pos]=0;
- }
-
- START_TIMER
-
- nal_length= encode_nal(&h, nal, bitstream, COUNT, COUNT*2);
- if(nal_length<0){
- printf("encoding failed\n");
- return -1;
- }
-
- out= decode_nal(&h, nal, &out_length, &consumed, nal_length);
-
- STOP_TIMER("NAL")
-
- if(out_length != COUNT){
- printf("incorrect length %d %d\n", out_length, COUNT);
- return -1;
- }
-
- if(consumed != nal_length){
- printf("incorrect consumed length %d %d\n", nal_length, consumed);
- return -1;
- }
-
- if(memcmp(bitstream, out, COUNT)){
- printf("missmatch\n");
- return -1;
- }
- }
-
- printf("Testing RBSP\n");
-
-
- return 0;
-}
-#endif
-
-
-static int decode_end(AVCodecContext *avctx)
-{
- H264Context *h = avctx->priv_data;
- MpegEncContext *s = &h->s;
-
- free_tables(h); //FIXME cleanup init stuff perhaps
- MPV_common_end(s);
-
-// memset(h, 0, sizeof(H264Context));
-
- return 0;
-}
-
-
-AVCodec h264_decoder = {
- "h264",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H264,
- sizeof(H264Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
-};
-
-#include "svq3.c"
+++ /dev/null
-/*
- * H26L/H264/AVC/JVT/14496-10/... encoder/decoder
- * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file h264data.h
- * @brief
- * H264 / AVC / MPEG4 part10 codec data table
- * @author Michael Niedermayer <michaelni@gmx.at>
- */
-
-#define VERT_PRED 0
-#define HOR_PRED 1
-#define DC_PRED 2
-#define DIAG_DOWN_LEFT_PRED 3
-#define DIAG_DOWN_RIGHT_PRED 4
-#define VERT_RIGHT_PRED 5
-#define HOR_DOWN_PRED 6
-#define VERT_LEFT_PRED 7
-#define HOR_UP_PRED 8
-
-#define LEFT_DC_PRED 9
-#define TOP_DC_PRED 10
-#define DC_128_PRED 11
-
-
-#define DC_PRED8x8 0
-#define HOR_PRED8x8 1
-#define VERT_PRED8x8 2
-#define PLANE_PRED8x8 3
-
-#define LEFT_DC_PRED8x8 4
-#define TOP_DC_PRED8x8 5
-#define DC_128_PRED8x8 6
-
-#define EXTENDED_SAR 255
-
-static const uint16_t pixel_aspect[16][2]={
- {0, 0},
- {1, 1},
- {12, 11},
- {10, 11},
- {16, 11},
- {40, 33},
- {24, 11},
- {20, 11},
- {32, 11},
- {80, 33},
- {18, 11},
- {15, 11},
- {64, 33},
- {160,99},
-};
-
-static const uint8_t golomb_to_pict_type[5]=
-{P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE};
-
-static const uint8_t pict_type_to_golomb[7]=
-{-1, 2, 0, 1, -1, 4, 3};
-
-static const uint8_t chroma_qp[52]={
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
- 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
- 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
- 37,38,38,38,39,39,39,39
-
-};
-
-static const uint8_t golomb_to_intra4x4_cbp[48]={
- 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46,
- 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4,
- 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41
-};
-
-static const uint8_t golomb_to_inter_cbp[48]={
- 0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13,
- 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46,
- 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41
-};
-
-static const uint8_t intra4x4_cbp_to_golomb[48]={
- 3, 29, 30, 17, 31, 18, 37, 8, 32, 38, 19, 9, 20, 10, 11, 2,
- 16, 33, 34, 21, 35, 22, 39, 4, 36, 40, 23, 5, 24, 6, 7, 1,
- 41, 42, 43, 25, 44, 26, 46, 12, 45, 47, 27, 13, 28, 14, 15, 0
-};
-
-static const uint8_t inter_cbp_to_golomb[48]={
- 0, 2, 3, 7, 4, 8, 17, 13, 5, 18, 9, 14, 10, 15, 16, 11,
- 1, 32, 33, 36, 34, 37, 44, 40, 35, 45, 38, 41, 39, 42, 43, 19,
- 6, 24, 25, 20, 26, 21, 46, 28, 27, 47, 22, 29, 23, 30, 31, 12
-};
-
-static const uint8_t chroma_dc_coeff_token_len[4*5]={
- 2, 0, 0, 0,
- 6, 1, 0, 0,
- 6, 6, 3, 0,
- 6, 7, 7, 6,
- 6, 8, 8, 7,
-};
-
-static const uint8_t chroma_dc_coeff_token_bits[4*5]={
- 1, 0, 0, 0,
- 7, 1, 0, 0,
- 4, 6, 1, 0,
- 3, 3, 2, 5,
- 2, 3, 2, 0,
-};
-
-static const uint8_t coeff_token_len[4][4*17]={
-{
- 1, 0, 0, 0,
- 6, 2, 0, 0, 8, 6, 3, 0, 9, 8, 7, 5, 10, 9, 8, 6,
- 11,10, 9, 7, 13,11,10, 8, 13,13,11, 9, 13,13,13,10,
- 14,14,13,11, 14,14,14,13, 15,15,14,14, 15,15,15,14,
- 16,15,15,15, 16,16,16,15, 16,16,16,16, 16,16,16,16,
-},
-{
- 2, 0, 0, 0,
- 6, 2, 0, 0, 6, 5, 3, 0, 7, 6, 6, 4, 8, 6, 6, 4,
- 8, 7, 7, 5, 9, 8, 8, 6, 11, 9, 9, 6, 11,11,11, 7,
- 12,11,11, 9, 12,12,12,11, 12,12,12,11, 13,13,13,12,
- 13,13,13,13, 13,14,13,13, 14,14,14,13, 14,14,14,14,
-},
-{
- 4, 0, 0, 0,
- 6, 4, 0, 0, 6, 5, 4, 0, 6, 5, 5, 4, 7, 5, 5, 4,
- 7, 5, 5, 4, 7, 6, 6, 4, 7, 6, 6, 4, 8, 7, 7, 5,
- 8, 8, 7, 6, 9, 8, 8, 7, 9, 9, 8, 8, 9, 9, 9, 8,
- 10, 9, 9, 9, 10,10,10,10, 10,10,10,10, 10,10,10,10,
-},
-{
- 6, 0, 0, 0,
- 6, 6, 0, 0, 6, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-}
-};
-
-static const uint8_t coeff_token_bits[4][4*17]={
-{
- 1, 0, 0, 0,
- 5, 1, 0, 0, 7, 4, 1, 0, 7, 6, 5, 3, 7, 6, 5, 3,
- 7, 6, 5, 4, 15, 6, 5, 4, 11,14, 5, 4, 8,10,13, 4,
- 15,14, 9, 4, 11,10,13,12, 15,14, 9,12, 11,10,13, 8,
- 15, 1, 9,12, 11,14,13, 8, 7,10, 9,12, 4, 6, 5, 8,
-},
-{
- 3, 0, 0, 0,
- 11, 2, 0, 0, 7, 7, 3, 0, 7,10, 9, 5, 7, 6, 5, 4,
- 4, 6, 5, 6, 7, 6, 5, 8, 15, 6, 5, 4, 11,14,13, 4,
- 15,10, 9, 4, 11,14,13,12, 8,10, 9, 8, 15,14,13,12,
- 11,10, 9,12, 7,11, 6, 8, 9, 8,10, 1, 7, 6, 5, 4,
-},
-{
- 15, 0, 0, 0,
- 15,14, 0, 0, 11,15,13, 0, 8,12,14,12, 15,10,11,11,
- 11, 8, 9,10, 9,14,13, 9, 8,10, 9, 8, 15,14,13,13,
- 11,14,10,12, 15,10,13,12, 11,14, 9,12, 8,10,13, 8,
- 13, 7, 9,12, 9,12,11,10, 5, 8, 7, 6, 1, 4, 3, 2,
-},
-{
- 3, 0, 0, 0,
- 0, 1, 0, 0, 4, 5, 6, 0, 8, 9,10,11, 12,13,14,15,
- 16,17,18,19, 20,21,22,23, 24,25,26,27, 28,29,30,31,
- 32,33,34,35, 36,37,38,39, 40,41,42,43, 44,45,46,47,
- 48,49,50,51, 52,53,54,55, 56,57,58,59, 60,61,62,63,
-}
-};
-
-static const uint8_t total_zeros_len[16][16]= {
- {1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
- {3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
- {4,3,3,3,4,4,3,3,4,5,5,6,5,6},
- {5,3,4,4,3,3,3,4,3,4,5,5,5},
- {4,4,4,3,3,3,3,3,4,5,4,5},
- {6,5,3,3,3,3,3,3,4,3,6},
- {6,5,3,3,3,2,3,4,3,6},
- {6,4,5,3,2,2,3,3,6},
- {6,6,4,2,2,3,2,5},
- {5,5,3,2,2,2,4},
- {4,4,3,3,1,3},
- {4,4,2,1,3},
- {3,3,1,2},
- {2,2,1},
- {1,1},
-};
-
-static const uint8_t total_zeros_bits[16][16]= {
- {1,3,2,3,2,3,2,3,2,3,2,3,2,3,2,1},
- {7,6,5,4,3,5,4,3,2,3,2,3,2,1,0},
- {5,7,6,5,4,3,4,3,2,3,2,1,1,0},
- {3,7,5,4,6,5,4,3,3,2,2,1,0},
- {5,4,3,7,6,5,4,3,2,1,1,0},
- {1,1,7,6,5,4,3,2,1,1,0},
- {1,1,5,4,3,3,2,1,1,0},
- {1,1,1,3,3,2,2,1,0},
- {1,0,1,3,2,1,1,1},
- {1,0,1,3,2,1,1},
- {0,1,1,2,1,3},
- {0,1,1,1,1},
- {0,1,1,1},
- {0,1,1},
- {0,1},
-};
-
-static const uint8_t chroma_dc_total_zeros_len[3][4]= {
- { 1, 2, 3, 3,},
- { 1, 2, 2, 0,},
- { 1, 1, 0, 0,},
-};
-
-static const uint8_t chroma_dc_total_zeros_bits[3][4]= {
- { 1, 1, 1, 0,},
- { 1, 1, 0, 0,},
- { 1, 0, 0, 0,},
-};
-
-static const uint8_t run_len[7][16]={
- {1,1},
- {1,2,2},
- {2,2,2,2},
- {2,2,2,3,3},
- {2,2,3,3,3,3},
- {2,3,3,3,3,3,3},
- {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
-};
-
-static const uint8_t run_bits[7][16]={
- {1,0},
- {1,1,0},
- {3,2,1,0},
- {3,2,1,1,0},
- {3,2,3,2,1,0},
- {3,0,1,3,2,5,4},
- {7,6,5,4,3,2,1,1,1,1,1,1,1,1,1},
-};
-
-/*
-o-o o-o
- / / /
-o-o o-o
- ,---'
-o-o o-o
- / / /
-o-o o-o
-*/
-
-static const uint8_t scan8[16 + 2*4]={
- 4+1*8, 5+1*8, 4+2*8, 5+2*8,
- 6+1*8, 7+1*8, 6+2*8, 7+2*8,
- 4+3*8, 5+3*8, 4+4*8, 5+4*8,
- 6+3*8, 7+3*8, 6+4*8, 7+4*8,
- 1+1*8, 2+1*8,
- 1+2*8, 2+2*8,
- 1+4*8, 2+4*8,
- 1+5*8, 2+5*8,
-};
-
-static const uint8_t zigzag_scan[16]={
- 0+0*4, 1+0*4, 0+1*4, 0+2*4,
- 1+1*4, 2+0*4, 3+0*4, 2+1*4,
- 1+2*4, 0+3*4, 1+3*4, 2+2*4,
- 3+1*4, 3+2*4, 2+3*4, 3+3*4,
-};
-
-static const uint8_t field_scan[16]={
- 0+0*4, 0+1*4, 1+0*4, 0+2*4,
- 0+3*4, 1+1*4, 1+2*4, 1+3*4,
- 2+0*4, 2+1*4, 2+2*4, 2+3*4,
- 3+0*4, 3+1*4, 3+2*4, 3+3*4,
-};
-
-static const uint8_t luma_dc_zigzag_scan[16]={
- 0*16 + 0*64, 1*16 + 0*64, 2*16 + 0*64, 0*16 + 2*64,
- 3*16 + 0*64, 0*16 + 1*64, 1*16 + 1*64, 2*16 + 1*64,
- 1*16 + 2*64, 2*16 + 2*64, 3*16 + 2*64, 0*16 + 3*64,
- 3*16 + 1*64, 1*16 + 3*64, 2*16 + 3*64, 3*16 + 3*64,
-};
-
-static const uint8_t luma_dc_field_scan[16]={
- 0*16 + 0*64, 2*16 + 0*64, 1*16 + 0*64, 0*16 + 2*64,
- 2*16 + 2*64, 3*16 + 0*64, 1*16 + 2*64, 3*16 + 2*64,
- 0*16 + 1*64, 2*16 + 1*64, 0*16 + 3*64, 2*16 + 3*64,
- 1*16 + 1*64, 3*16 + 1*64, 1*16 + 3*64, 3*16 + 3*64,
-};
-
-static const uint8_t chroma_dc_scan[4]={
- (0+0*2)*16, (1+0*2)*16,
- (0+1*2)*16, (1+1*2)*16, //FIXME
-};
-
-#define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16bit
-#define IS_REF0(a) ((a)&MB_TYPE_REF0)
-
-typedef struct IMbInfo{
- uint16_t type;
- uint8_t pred_mode;
- uint8_t cbp;
-} IMbInfo;
-
-static const IMbInfo i_mb_type_info[26]={
-{MB_TYPE_INTRA4x4 , -1, -1},
-{MB_TYPE_INTRA16x16, 2, 0},
-{MB_TYPE_INTRA16x16, 1, 0},
-{MB_TYPE_INTRA16x16, 0, 0},
-{MB_TYPE_INTRA16x16, 3, 0},
-{MB_TYPE_INTRA16x16, 2, 16},
-{MB_TYPE_INTRA16x16, 1, 16},
-{MB_TYPE_INTRA16x16, 0, 16},
-{MB_TYPE_INTRA16x16, 3, 16},
-{MB_TYPE_INTRA16x16, 2, 32},
-{MB_TYPE_INTRA16x16, 1, 32},
-{MB_TYPE_INTRA16x16, 0, 32},
-{MB_TYPE_INTRA16x16, 3, 32},
-{MB_TYPE_INTRA16x16, 2, 15+0},
-{MB_TYPE_INTRA16x16, 1, 15+0},
-{MB_TYPE_INTRA16x16, 0, 15+0},
-{MB_TYPE_INTRA16x16, 3, 15+0},
-{MB_TYPE_INTRA16x16, 2, 15+16},
-{MB_TYPE_INTRA16x16, 1, 15+16},
-{MB_TYPE_INTRA16x16, 0, 15+16},
-{MB_TYPE_INTRA16x16, 3, 15+16},
-{MB_TYPE_INTRA16x16, 2, 15+32},
-{MB_TYPE_INTRA16x16, 1, 15+32},
-{MB_TYPE_INTRA16x16, 0, 15+32},
-{MB_TYPE_INTRA16x16, 3, 15+32},
-{MB_TYPE_INTRA_PCM , -1, -1},
-};
-
-typedef struct PMbInfo{
- uint16_t type;
- uint8_t partition_count;
-} PMbInfo;
-
-static const PMbInfo p_mb_type_info[5]={
-{MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P1L0, 2},
-{MB_TYPE_8x8 , 4},
-{MB_TYPE_8x8 |MB_TYPE_REF0 , 4},
-};
-
-static const PMbInfo p_sub_mb_type_info[4]={
-{MB_TYPE_16x16|MB_TYPE_P0L0 , 1},
-{MB_TYPE_16x8 |MB_TYPE_P0L0 , 2},
-{MB_TYPE_8x16 |MB_TYPE_P0L0 , 2},
-{MB_TYPE_8x8 |MB_TYPE_P0L0 , 4},
-};
-
-static const PMbInfo b_mb_type_info[23]={
-{MB_TYPE_DIRECT2 , 1, },
-{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
-{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
-{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0 , 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x8 , 4, },
-};
-
-static const PMbInfo b_sub_mb_type_info[13]={
-{MB_TYPE_DIRECT2 , 1, },
-{MB_TYPE_16x16|MB_TYPE_P0L0 , 1, },
-{MB_TYPE_16x16 |MB_TYPE_P0L1 , 1, },
-{MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1 , 1, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 2, },
-{MB_TYPE_16x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x16 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 2, },
-{MB_TYPE_8x8 |MB_TYPE_P0L0 |MB_TYPE_P1L0 , 4, },
-{MB_TYPE_8x8 |MB_TYPE_P0L1 |MB_TYPE_P1L1, 4, },
-{MB_TYPE_8x8 |MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_P1L0|MB_TYPE_P1L1, 4, },
-};
-
-
-static const uint8_t rem6[52]={
-0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3,
-};
-
-static const uint8_t div6[52]={
-0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
-};
-
-static const uint16_t dequant_coeff[52][16]={
-{ 10, 13, 10, 13, 13, 16, 13, 16, 10, 13, 10, 13, 13, 16, 13, 16, },
-{ 11, 14, 11, 14, 14, 18, 14, 18, 11, 14, 11, 14, 14, 18, 14, 18, },
-{ 13, 16, 13, 16, 16, 20, 16, 20, 13, 16, 13, 16, 16, 20, 16, 20, },
-{ 14, 18, 14, 18, 18, 23, 18, 23, 14, 18, 14, 18, 18, 23, 18, 23, },
-{ 16, 20, 16, 20, 20, 25, 20, 25, 16, 20, 16, 20, 20, 25, 20, 25, },
-{ 18, 23, 18, 23, 23, 29, 23, 29, 18, 23, 18, 23, 23, 29, 23, 29, },
-{ 20, 26, 20, 26, 26, 32, 26, 32, 20, 26, 20, 26, 26, 32, 26, 32, },
-{ 22, 28, 22, 28, 28, 36, 28, 36, 22, 28, 22, 28, 28, 36, 28, 36, },
-{ 26, 32, 26, 32, 32, 40, 32, 40, 26, 32, 26, 32, 32, 40, 32, 40, },
-{ 28, 36, 28, 36, 36, 46, 36, 46, 28, 36, 28, 36, 36, 46, 36, 46, },
-{ 32, 40, 32, 40, 40, 50, 40, 50, 32, 40, 32, 40, 40, 50, 40, 50, },
-{ 36, 46, 36, 46, 46, 58, 46, 58, 36, 46, 36, 46, 46, 58, 46, 58, },
-{ 40, 52, 40, 52, 52, 64, 52, 64, 40, 52, 40, 52, 52, 64, 52, 64, },
-{ 44, 56, 44, 56, 56, 72, 56, 72, 44, 56, 44, 56, 56, 72, 56, 72, },
-{ 52, 64, 52, 64, 64, 80, 64, 80, 52, 64, 52, 64, 64, 80, 64, 80, },
-{ 56, 72, 56, 72, 72, 92, 72, 92, 56, 72, 56, 72, 72, 92, 72, 92, },
-{ 64, 80, 64, 80, 80, 100, 80, 100, 64, 80, 64, 80, 80, 100, 80, 100, },
-{ 72, 92, 72, 92, 92, 116, 92, 116, 72, 92, 72, 92, 92, 116, 92, 116, },
-{ 80, 104, 80, 104, 104, 128, 104, 128, 80, 104, 80, 104, 104, 128, 104, 128, },
-{ 88, 112, 88, 112, 112, 144, 112, 144, 88, 112, 88, 112, 112, 144, 112, 144, },
-{ 104, 128, 104, 128, 128, 160, 128, 160, 104, 128, 104, 128, 128, 160, 128, 160, },
-{ 112, 144, 112, 144, 144, 184, 144, 184, 112, 144, 112, 144, 144, 184, 144, 184, },
-{ 128, 160, 128, 160, 160, 200, 160, 200, 128, 160, 128, 160, 160, 200, 160, 200, },
-{ 144, 184, 144, 184, 184, 232, 184, 232, 144, 184, 144, 184, 184, 232, 184, 232, },
-{ 160, 208, 160, 208, 208, 256, 208, 256, 160, 208, 160, 208, 208, 256, 208, 256, },
-{ 176, 224, 176, 224, 224, 288, 224, 288, 176, 224, 176, 224, 224, 288, 224, 288, },
-{ 208, 256, 208, 256, 256, 320, 256, 320, 208, 256, 208, 256, 256, 320, 256, 320, },
-{ 224, 288, 224, 288, 288, 368, 288, 368, 224, 288, 224, 288, 288, 368, 288, 368, },
-{ 256, 320, 256, 320, 320, 400, 320, 400, 256, 320, 256, 320, 320, 400, 320, 400, },
-{ 288, 368, 288, 368, 368, 464, 368, 464, 288, 368, 288, 368, 368, 464, 368, 464, },
-{ 320, 416, 320, 416, 416, 512, 416, 512, 320, 416, 320, 416, 416, 512, 416, 512, },
-{ 352, 448, 352, 448, 448, 576, 448, 576, 352, 448, 352, 448, 448, 576, 448, 576, },
-{ 416, 512, 416, 512, 512, 640, 512, 640, 416, 512, 416, 512, 512, 640, 512, 640, },
-{ 448, 576, 448, 576, 576, 736, 576, 736, 448, 576, 448, 576, 576, 736, 576, 736, },
-{ 512, 640, 512, 640, 640, 800, 640, 800, 512, 640, 512, 640, 640, 800, 640, 800, },
-{ 576, 736, 576, 736, 736, 928, 736, 928, 576, 736, 576, 736, 736, 928, 736, 928, },
-{ 640, 832, 640, 832, 832,1024, 832,1024, 640, 832, 640, 832, 832,1024, 832,1024, },
-{ 704, 896, 704, 896, 896,1152, 896,1152, 704, 896, 704, 896, 896,1152, 896,1152, },
-{ 832,1024, 832,1024, 1024,1280,1024,1280, 832,1024, 832,1024, 1024,1280,1024,1280, },
-{ 896,1152, 896,1152, 1152,1472,1152,1472, 896,1152, 896,1152, 1152,1472,1152,1472, },
-{1024,1280,1024,1280, 1280,1600,1280,1600, 1024,1280,1024,1280, 1280,1600,1280,1600, },
-{1152,1472,1152,1472, 1472,1856,1472,1856, 1152,1472,1152,1472, 1472,1856,1472,1856, },
-{1280,1664,1280,1664, 1664,2048,1664,2048, 1280,1664,1280,1664, 1664,2048,1664,2048, },
-{1408,1792,1408,1792, 1792,2304,1792,2304, 1408,1792,1408,1792, 1792,2304,1792,2304, },
-{1664,2048,1664,2048, 2048,2560,2048,2560, 1664,2048,1664,2048, 2048,2560,2048,2560, },
-{1792,2304,1792,2304, 2304,2944,2304,2944, 1792,2304,1792,2304, 2304,2944,2304,2944, },
-{2048,2560,2048,2560, 2560,3200,2560,3200, 2048,2560,2048,2560, 2560,3200,2560,3200, },
-{2304,2944,2304,2944, 2944,3712,2944,3712, 2304,2944,2304,2944, 2944,3712,2944,3712, },
-{2560,3328,2560,3328, 3328,4096,3328,4096, 2560,3328,2560,3328, 3328,4096,3328,4096, },
-{2816,3584,2816,3584, 3584,4608,3584,4608, 2816,3584,2816,3584, 3584,4608,3584,4608, },
-{3328,4096,3328,4096, 4096,5120,4096,5120, 3328,4096,3328,4096, 4096,5120,4096,5120, },
-{3584,4608,3584,4608, 4608,5888,4608,5888, 3584,4608,3584,4608, 4608,5888,4608,5888, },
-//{4096,5120,4096,5120, 5120,6400,5120,6400, 4096,5120,4096,5120, 5120,6400,5120,6400, },
-//{4608,5888,4608,5888, 5888,7424,5888,7424, 4608,5888,4608,5888, 5888,7424,5888,7424, },
-};
-
-#define QUANT_SHIFT 22
-
-static const int quant_coeff[52][16]={
- { 419430,258111,419430,258111,258111,167772,258111,167772,419430,258111,419430,258111,258111,167772,258111,167772,},
- { 381300,239675,381300,239675,239675,149131,239675,149131,381300,239675,381300,239675,239675,149131,239675,149131,},
- { 322639,209715,322639,209715,209715,134218,209715,134218,322639,209715,322639,209715,209715,134218,209715,134218,},
- { 299593,186414,299593,186414,186414,116711,186414,116711,299593,186414,299593,186414,186414,116711,186414,116711,},
- { 262144,167772,262144,167772,167772,107374,167772,107374,262144,167772,262144,167772,167772,107374,167772,107374,},
- { 233017,145889,233017,145889,145889, 92564,145889, 92564,233017,145889,233017,145889,145889, 92564,145889, 92564,},
- { 209715,129056,209715,129056,129056, 83886,129056, 83886,209715,129056,209715,129056,129056, 83886,129056, 83886,},
- { 190650,119837,190650,119837,119837, 74565,119837, 74565,190650,119837,190650,119837,119837, 74565,119837, 74565,},
- { 161319,104858,161319,104858,104858, 67109,104858, 67109,161319,104858,161319,104858,104858, 67109,104858, 67109,},
- { 149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,149797, 93207,149797, 93207, 93207, 58356, 93207, 58356,},
- { 131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,131072, 83886,131072, 83886, 83886, 53687, 83886, 53687,},
- { 116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,116508, 72944,116508, 72944, 72944, 46282, 72944, 46282,},
- { 104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,104858, 64528,104858, 64528, 64528, 41943, 64528, 41943,},
- { 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283, 95325, 59919, 95325, 59919, 59919, 37283, 59919, 37283,},
- { 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554, 80660, 52429, 80660, 52429, 52429, 33554, 52429, 33554,},
- { 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178, 74898, 46603, 74898, 46603, 46603, 29178, 46603, 29178,},
- { 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844, 65536, 41943, 65536, 41943, 41943, 26844, 41943, 26844,},
- { 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141, 58254, 36472, 58254, 36472, 36472, 23141, 36472, 23141,},
- { 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972, 52429, 32264, 52429, 32264, 32264, 20972, 32264, 20972,},
- { 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641, 47663, 29959, 47663, 29959, 29959, 18641, 29959, 18641,},
- { 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777, 40330, 26214, 40330, 26214, 26214, 16777, 26214, 16777,},
- { 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589, 37449, 23302, 37449, 23302, 23302, 14589, 23302, 14589,},
- { 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422, 32768, 20972, 32768, 20972, 20972, 13422, 20972, 13422,},
- { 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570, 29127, 18236, 29127, 18236, 18236, 11570, 18236, 11570,},
- { 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486, 26214, 16132, 26214, 16132, 16132, 10486, 16132, 10486,},
- { 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321, 23831, 14980, 23831, 14980, 14980, 9321, 14980, 9321,},
- { 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389, 20165, 13107, 20165, 13107, 13107, 8389, 13107, 8389,},
- { 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294, 18725, 11651, 18725, 11651, 11651, 7294, 11651, 7294,},
- { 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711, 16384, 10486, 16384, 10486, 10486, 6711, 10486, 6711,},
- { 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785, 14564, 9118, 14564, 9118, 9118, 5785, 9118, 5785,},
- { 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243, 13107, 8066, 13107, 8066, 8066, 5243, 8066, 5243,},
- { 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660, 11916, 7490, 11916, 7490, 7490, 4660, 7490, 4660,},
- { 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194, 10082, 6554, 10082, 6554, 6554, 4194, 6554, 4194,},
- { 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647, 9362, 5825, 9362, 5825, 5825, 3647, 5825, 3647,},
- { 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355, 8192, 5243, 8192, 5243, 5243, 3355, 5243, 3355,},
- { 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893, 7282, 4559, 7282, 4559, 4559, 2893, 4559, 2893,},
- { 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621, 6554, 4033, 6554, 4033, 4033, 2621, 4033, 2621,},
- { 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330, 5958, 3745, 5958, 3745, 3745, 2330, 3745, 2330,},
- { 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097, 5041, 3277, 5041, 3277, 3277, 2097, 3277, 2097,},
- { 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824, 4681, 2913, 4681, 2913, 2913, 1824, 2913, 1824,},
- { 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678, 4096, 2621, 4096, 2621, 2621, 1678, 2621, 1678,},
- { 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446, 3641, 2280, 3641, 2280, 2280, 1446, 2280, 1446,},
- { 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311, 3277, 2016, 3277, 2016, 2016, 1311, 2016, 1311,},
- { 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165, 2979, 1872, 2979, 1872, 1872, 1165, 1872, 1165,},
- { 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049, 2521, 1638, 2521, 1638, 1638, 1049, 1638, 1049,},
- { 2341, 1456, 2341, 1456, 1456, 912, 1456, 912, 2341, 1456, 2341, 1456, 1456, 912, 1456, 912,},
- { 2048, 1311, 2048, 1311, 1311, 839, 1311, 839, 2048, 1311, 2048, 1311, 1311, 839, 1311, 839,},
- { 1820, 1140, 1820, 1140, 1140, 723, 1140, 723, 1820, 1140, 1820, 1140, 1140, 723, 1140, 723,},
- { 1638, 1008, 1638, 1008, 1008, 655, 1008, 655, 1638, 1008, 1638, 1008, 1008, 655, 1008, 655,},
- { 1489, 936, 1489, 936, 936, 583, 936, 583, 1489, 936, 1489, 936, 936, 583, 936, 583,},
- { 1260, 819, 1260, 819, 819, 524, 819, 524, 1260, 819, 1260, 819, 819, 524, 819, 524,},
- { 1170, 728, 1170, 728, 728, 456, 728, 456, 1170, 728, 1170, 728, 728, 456, 728, 456,},
-};
+++ /dev/null
-/*
- * huffyuv codec for libavcodec
- *
- * Copyright (c) 2002-2003 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of
- * the algorithm used
- */
-
-/**
- * @file huffyuv.c
- * huffyuv codec for libavcodec.
- */
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#ifndef INT64_MAX
-#define INT64_MAX 9223372036854775807LL
-#endif
-
-#define VLC_BITS 11
-
-typedef enum Predictor{
- LEFT= 0,
- PLANE,
- MEDIAN,
-} Predictor;
-
-typedef struct HYuvContext{
- AVCodecContext *avctx;
- Predictor predictor;
- GetBitContext gb;
- PutBitContext pb;
- int interlaced;
- int decorrelate;
- int bitstream_bpp;
- int version;
- int yuy2; //use yuy2 instead of 422P
- int bgr32; //use bgr32 instead of bgr24
- int width, height;
- int flags;
- int picture_number;
- int last_slice_end;
- uint8_t __align8 temp[3][2500];
- uint64_t stats[3][256];
- uint8_t len[3][256];
- uint32_t bits[3][256];
- VLC vlc[3];
- AVFrame picture;
- uint8_t __align8 bitstream_buffer[1024*1024*3]; //FIXME dynamic alloc or some other solution
- DSPContext dsp;
-}HYuvContext;
-
-static const unsigned char classic_shift_luma[] = {
- 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8,
- 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70,
- 69,68, 0
-};
-
-static const unsigned char classic_shift_chroma[] = {
- 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183,
- 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119,
- 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0
-};
-
-static const unsigned char classic_add_luma[256] = {
- 3, 9, 5, 12, 10, 35, 32, 29, 27, 50, 48, 45, 44, 41, 39, 37,
- 73, 70, 68, 65, 64, 61, 58, 56, 53, 50, 49, 46, 44, 41, 38, 36,
- 68, 65, 63, 61, 58, 55, 53, 51, 48, 46, 45, 43, 41, 39, 38, 36,
- 35, 33, 32, 30, 29, 27, 26, 25, 48, 47, 46, 44, 43, 41, 40, 39,
- 37, 36, 35, 34, 32, 31, 30, 28, 27, 26, 24, 23, 22, 20, 19, 37,
- 35, 34, 33, 31, 30, 29, 27, 26, 24, 23, 21, 20, 18, 17, 15, 29,
- 27, 26, 24, 22, 21, 19, 17, 16, 14, 26, 25, 23, 21, 19, 18, 16,
- 15, 27, 25, 23, 21, 19, 17, 16, 14, 26, 25, 23, 21, 18, 17, 14,
- 12, 17, 19, 13, 4, 9, 2, 11, 1, 7, 8, 0, 16, 3, 14, 6,
- 12, 10, 5, 15, 18, 11, 10, 13, 15, 16, 19, 20, 22, 24, 27, 15,
- 18, 20, 22, 24, 26, 14, 17, 20, 22, 24, 27, 15, 18, 20, 23, 25,
- 28, 16, 19, 22, 25, 28, 32, 36, 21, 25, 29, 33, 38, 42, 45, 49,
- 28, 31, 34, 37, 40, 42, 44, 47, 49, 50, 52, 54, 56, 57, 59, 60,
- 62, 64, 66, 67, 69, 35, 37, 39, 40, 42, 43, 45, 47, 48, 51, 52,
- 54, 55, 57, 59, 60, 62, 63, 66, 67, 69, 71, 72, 38, 40, 42, 43,
- 46, 47, 49, 51, 26, 28, 30, 31, 33, 34, 18, 19, 11, 13, 7, 8,
-};
-
-static const unsigned char classic_add_chroma[256] = {
- 3, 1, 2, 2, 2, 2, 3, 3, 7, 5, 7, 5, 8, 6, 11, 9,
- 7, 13, 11, 10, 9, 8, 7, 5, 9, 7, 6, 4, 7, 5, 8, 7,
- 11, 8, 13, 11, 19, 15, 22, 23, 20, 33, 32, 28, 27, 29, 51, 77,
- 43, 45, 76, 81, 46, 82, 75, 55, 56,144, 58, 80, 60, 74,147, 63,
- 143, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 27, 30, 21, 22,
- 17, 14, 5, 6,100, 54, 47, 50, 51, 53,106,107,108,109,110,111,
- 112,113,114,115, 4,117,118, 92, 94,121,122, 3,124,103, 2, 1,
- 0,129,130,131,120,119,126,125,136,137,138,139,140,141,142,134,
- 135,132,133,104, 64,101, 62, 57,102, 95, 93, 59, 61, 28, 97, 96,
- 52, 49, 48, 29, 32, 25, 24, 46, 23, 98, 45, 44, 43, 20, 42, 41,
- 19, 18, 99, 40, 15, 39, 38, 16, 13, 12, 11, 37, 10, 9, 8, 36,
- 7,128,127,105,123,116, 35, 34, 33,145, 31, 79, 42,146, 78, 26,
- 83, 48, 49, 50, 44, 47, 26, 31, 30, 18, 17, 19, 21, 24, 25, 13,
- 14, 16, 17, 18, 20, 21, 12, 14, 15, 9, 10, 6, 9, 6, 5, 8,
- 6, 12, 8, 10, 7, 9, 6, 4, 6, 2, 2, 3, 3, 3, 3, 2,
-};
-
-static inline int add_left_prediction(uint8_t *dst, uint8_t *src, int w, int acc){
- int i;
-
- for(i=0; i<w-1; i++){
- acc+= src[i];
- dst[i]= acc;
- i++;
- acc+= src[i];
- dst[i]= acc;
- }
-
- for(; i<w; i++){
- acc+= src[i];
- dst[i]= acc;
- }
-
- return acc;
-}
-
-static inline void add_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){
- int i;
- uint8_t l, lt;
-
- l= *left;
- lt= *left_top;
-
- for(i=0; i<w; i++){
- l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i];
- lt= src1[i];
- dst[i]= l;
- }
-
- *left= l;
- *left_top= lt;
-}
-
-//FIXME optimize
-static inline void sub_median_prediction(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){
- int i;
- uint8_t l, lt;
-
- l= *left;
- lt= *left_top;
-
- for(i=0; i<w; i++){
- const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF);
- lt= src1[i];
- l= src2[i];
- dst[i]= l - pred;
- }
-
- *left= l;
- *left_top= lt;
-}
-
-static inline void add_left_prediction_bgr32(uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){
- int i;
- int r,g,b;
- r= *red;
- g= *green;
- b= *blue;
-
- for(i=0; i<w; i++){
- b+= src[4*i+0];
- g+= src[4*i+1];
- r+= src[4*i+2];
-
- dst[4*i+0]= b;
- dst[4*i+1]= g;
- dst[4*i+2]= r;
- }
-
- *red= r;
- *green= g;
- *blue= b;
-}
-
-static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int left){
- int i;
- if(w<32){
- for(i=0; i<w; i++){
- const int temp= src[i];
- dst[i]= temp - left;
- left= temp;
- }
- return left;
- }else{
- for(i=0; i<16; i++){
- const int temp= src[i];
- dst[i]= temp - left;
- left= temp;
- }
- s->dsp.diff_bytes(dst+16, src+16, src+15, w-16);
- return src[w-1];
- }
-}
-
-static void read_len_table(uint8_t *dst, GetBitContext *gb){
- int i, val, repeat;
-
- for(i=0; i<256;){
- repeat= get_bits(gb, 3);
- val = get_bits(gb, 5);
- if(repeat==0)
- repeat= get_bits(gb, 8);
-//printf("%d %d\n", val, repeat);
- while (repeat--)
- dst[i++] = val;
- }
-}
-
-static int generate_bits_table(uint32_t *dst, uint8_t *len_table){
- int len, index;
- uint32_t bits=0;
-
- for(len=32; len>0; len--){
- for(index=0; index<256; index++){
- if(len_table[index]==len)
- dst[index]= bits++;
- }
- if(bits & 1){
- fprintf(stderr, "Error generating huffman table\n");
- return -1;
- }
- bits >>= 1;
- }
- return 0;
-}
-
-static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){
- uint64_t counts[2*size];
- int up[2*size];
- int offset, i, next;
-
- for(offset=1; ; offset<<=1){
- for(i=0; i<size; i++){
- counts[i]= stats[i] + offset - 1;
- }
-
- for(next=size; next<size*2; next++){
- uint64_t min1, min2;
- int min1_i, min2_i;
-
- min1=min2= INT64_MAX;
- min1_i= min2_i=-1;
-
- for(i=0; i<next; i++){
- if(min2 > counts[i]){
- if(min1 > counts[i]){
- min2= min1;
- min2_i= min1_i;
- min1= counts[i];
- min1_i= i;
- }else{
- min2= counts[i];
- min2_i= i;
- }
- }
- }
-
- if(min2==INT64_MAX) break;
-
- counts[next]= min1 + min2;
- counts[min1_i]=
- counts[min2_i]= INT64_MAX;
- up[min1_i]=
- up[min2_i]= next;
- up[next]= -1;
- }
-
- for(i=0; i<size; i++){
- int len;
- int index=i;
-
- for(len=0; up[index] != -1; len++)
- index= up[index];
-
- if(len > 32) break;
-
- dst[i]= len;
- }
- if(i==size) break;
- }
-}
-
-static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){
- GetBitContext gb;
- int i;
-
- init_get_bits(&gb, src, length*8);
-
- for(i=0; i<3; i++){
- read_len_table(s->len[i], &gb);
-
- if(generate_bits_table(s->bits[i], s->len[i])<0){
- return -1;
- }
-#if 0
-for(j=0; j<256; j++){
-printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j);
-}
-#endif
- init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4);
- }
-
- return 0;
-}
-
-static int read_old_huffman_tables(HYuvContext *s){
-#if 1
- GetBitContext gb;
- int i;
-
- init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8);
- read_len_table(s->len[0], &gb);
- init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8);
- read_len_table(s->len[1], &gb);
-
- for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];
- for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];
-
- if(s->bitstream_bpp >= 24){
- memcpy(s->bits[1], s->bits[0], 256*sizeof(uint32_t));
- memcpy(s->len[1] , s->len [0], 256*sizeof(uint8_t));
- }
- memcpy(s->bits[2], s->bits[1], 256*sizeof(uint32_t));
- memcpy(s->len[2] , s->len [1], 256*sizeof(uint8_t));
-
- for(i=0; i<3; i++)
- init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4);
-
- return 0;
-#else
- fprintf(stderr, "v1 huffyuv is not supported \n");
- return -1;
-#endif
-}
-
-static int decode_init(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
- int width, height;
-
- s->avctx= avctx;
- s->flags= avctx->flags;
-
- dsputil_init(&s->dsp, avctx);
-
- width= s->width= avctx->width;
- height= s->height= avctx->height;
- avctx->coded_frame= &s->picture;
-
-s->bgr32=1;
- assert(width && height);
-//if(avctx->extradata)
-// printf("extradata:%X, extradata_size:%d\n", *(uint32_t*)avctx->extradata, avctx->extradata_size);
- if(avctx->extradata_size){
- if((avctx->bits_per_sample&7) && avctx->bits_per_sample != 12)
- s->version=1; // do such files exist at all?
- else
- s->version=2;
- }else
- s->version=0;
-
- if(s->version==2){
- int method;
-
- method= ((uint8_t*)avctx->extradata)[0];
- s->decorrelate= method&64 ? 1 : 0;
- s->predictor= method&63;
- s->bitstream_bpp= ((uint8_t*)avctx->extradata)[1];
- if(s->bitstream_bpp==0)
- s->bitstream_bpp= avctx->bits_per_sample&~7;
-
- if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0)
- return -1;
- }else{
- switch(avctx->bits_per_sample&7){
- case 1:
- s->predictor= LEFT;
- s->decorrelate= 0;
- break;
- case 2:
- s->predictor= LEFT;
- s->decorrelate= 1;
- break;
- case 3:
- s->predictor= PLANE;
- s->decorrelate= avctx->bits_per_sample >= 24;
- break;
- case 4:
- s->predictor= MEDIAN;
- s->decorrelate= 0;
- break;
- default:
- s->predictor= LEFT; //OLD
- s->decorrelate= 0;
- break;
- }
- s->bitstream_bpp= avctx->bits_per_sample & ~7;
-
- if(read_old_huffman_tables(s) < 0)
- return -1;
- }
-
- s->interlaced= height > 288;
-
- switch(s->bitstream_bpp){
- case 12:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- case 16:
- if(s->yuy2){
- avctx->pix_fmt = PIX_FMT_YUV422;
- }else{
- avctx->pix_fmt = PIX_FMT_YUV422P;
- }
- break;
- case 24:
- case 32:
- if(s->bgr32){
- avctx->pix_fmt = PIX_FMT_RGBA32;
- }else{
- avctx->pix_fmt = PIX_FMT_BGR24;
- }
- break;
- default:
- assert(0);
- }
-
-// printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
-
- return 0;
-}
-
-static void store_table(HYuvContext *s, uint8_t *len){
- int i;
- int index= s->avctx->extradata_size;
-
- for(i=0; i<256;){
- int cur=i;
- int val= len[i];
- int repeat;
-
- for(; i<256 && len[i]==val; i++);
-
- repeat= i - cur;
-
- if(repeat>7){
- ((uint8_t*)s->avctx->extradata)[index++]= val;
- ((uint8_t*)s->avctx->extradata)[index++]= repeat;
- }else{
- ((uint8_t*)s->avctx->extradata)[index++]= val | (repeat<<5);
- }
- }
-
- s->avctx->extradata_size= index;
-}
-
-static int encode_init(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
- int i, j, width, height;
-
- s->avctx= avctx;
- s->flags= avctx->flags;
-
- dsputil_init(&s->dsp, avctx);
-
- width= s->width= avctx->width;
- height= s->height= avctx->height;
-
- assert(width && height);
-
- avctx->extradata= av_mallocz(1024*10);
- avctx->stats_out= av_mallocz(1024*10);
- s->version=2;
-
- avctx->coded_frame= &s->picture;
-
- switch(avctx->pix_fmt){
- case PIX_FMT_YUV420P:
- if(avctx->strict_std_compliance>=0){
- fprintf(stderr, "YV12-huffyuv is experimental, there WILL be no compatbility! (use (v)strict=-1)\n");
- return -1;
- }
- s->bitstream_bpp= 12;
- break;
- case PIX_FMT_YUV422P:
- s->bitstream_bpp= 16;
- break;
- default:
- fprintf(stderr, "format not supported\n");
- return -1;
- }
- avctx->bits_per_sample= s->bitstream_bpp;
- s->decorrelate= s->bitstream_bpp >= 24;
- s->predictor= avctx->prediction_method;
-
- ((uint8_t*)avctx->extradata)[0]= s->predictor;
- ((uint8_t*)avctx->extradata)[1]= s->bitstream_bpp;
- ((uint8_t*)avctx->extradata)[2]=
- ((uint8_t*)avctx->extradata)[3]= 0;
- s->avctx->extradata_size= 4;
-
- if(avctx->stats_in){
- char *p= avctx->stats_in;
-
- for(i=0; i<3; i++)
- for(j=0; j<256; j++)
- s->stats[i][j]= 1;
-
- for(;;){
- for(i=0; i<3; i++){
- char *next;
-
- for(j=0; j<256; j++){
- s->stats[i][j]+= strtol(p, &next, 0);
- if(next==p) return -1;
- p=next;
- }
- }
- if(p[0]==0 || p[1]==0 || p[2]==0) break;
- }
- }else{
- for(i=0; i<3; i++)
- for(j=0; j<256; j++){
- int d= FFMIN(j, 256-j);
-
- s->stats[i][j]= 100000000/(d+1);
- }
- }
-
- for(i=0; i<3; i++){
- generate_len_table(s->len[i], s->stats[i], 256);
-
- if(generate_bits_table(s->bits[i], s->len[i])<0){
- return -1;
- }
-
- store_table(s, s->len[i]);
- }
-
- for(i=0; i<3; i++)
- for(j=0; j<256; j++)
- s->stats[i][j]= 0;
-
- s->interlaced= height > 288;
-
-// printf("pred:%d bpp:%d hbpp:%d il:%d\n", s->predictor, s->bitstream_bpp, avctx->bits_per_sample, s->interlaced);
-
- s->picture_number=0;
-
- return 0;
-}
-
-static void decode_422_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
-
- for(i=0; i<count; i++){
- s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- }
-}
-
-static void decode_gray_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
-
- for(i=0; i<count; i++){
- s->temp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- }
-}
-
-static void encode_422_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
- if(s->flags&CODEC_FLAG_PASS1){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- s->stats[1][ s->temp[1][ i ] ]++;
- s->stats[0][ s->temp[0][2*i+1] ]++;
- s->stats[2][ s->temp[2][ i ] ]++;
- }
- }else{
- for(i=0; i<count; i++){
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]);
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]);
- }
- }
-}
-
-static void encode_gray_bitstream(HYuvContext *s, int count){
- int i;
-
- count/=2;
- if(s->flags&CODEC_FLAG_PASS1){
- for(i=0; i<count; i++){
- s->stats[0][ s->temp[0][2*i ] ]++;
- s->stats[0][ s->temp[0][2*i+1] ]++;
- }
- }else{
- for(i=0; i<count; i++){
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]);
- put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]);
- }
- }
-}
-
-static void decode_bgr_bitstream(HYuvContext *s, int count){
- int i;
-
- if(s->decorrelate){
- if(s->bitstream_bpp==24){
- for(i=0; i<count; i++){
- s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1];
- s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1];
- }
- }else{
- for(i=0; i<count; i++){
- s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+1];
- s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+1];
- get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
- }
- }
- }else{
- if(s->bitstream_bpp==24){
- for(i=0; i<count; i++){
- s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- }
- }else{
- for(i=0; i<count; i++){
- s->temp[0][4*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);
- s->temp[0][4*i+1]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3);
- s->temp[0][4*i+2]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3);
- get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?!
- }
- }
- }
-}
-
-static void draw_slice(HYuvContext *s, int y){
- int h, cy;
- int offset[4];
-
- if(s->avctx->draw_horiz_band==NULL)
- return;
-
- h= y - s->last_slice_end;
- y -= h;
-
- if(s->bitstream_bpp==12){
- cy= y>>1;
- }else{
- cy= y;
- }
-
- offset[0] = s->picture.linesize[0]*y;
- offset[1] = s->picture.linesize[1]*cy;
- offset[2] = s->picture.linesize[2]*cy;
- offset[3] = 0;
- emms_c();
-
- s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h);
-
- s->last_slice_end= y + h;
-}
-
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){
- HYuvContext *s = avctx->priv_data;
- const int width= s->width;
- const int width2= s->width>>1;
- const int height= s->height;
- int fake_ystride, fake_ustride, fake_vstride;
- AVFrame * const p= &s->picture;
-
- AVFrame *picture = data;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
- s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4);
-
- init_get_bits(&s->gb, s->bitstream_buffer, buf_size*8);
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- fake_ystride= s->interlaced ? p->linesize[0]*2 : p->linesize[0];
- fake_ustride= s->interlaced ? p->linesize[1]*2 : p->linesize[1];
- fake_vstride= s->interlaced ? p->linesize[2]*2 : p->linesize[2];
-
- s->last_slice_end= 0;
-
- if(s->bitstream_bpp<24){
- int y, cy;
- int lefty, leftu, leftv;
- int lefttopy, lefttopu, lefttopv;
-
- if(s->yuy2){
- p->data[0][3]= get_bits(&s->gb, 8);
- p->data[0][2]= get_bits(&s->gb, 8);
- p->data[0][1]= get_bits(&s->gb, 8);
- p->data[0][0]= get_bits(&s->gb, 8);
-
- fprintf(stderr, "YUY2 output isnt implemenetd yet\n");
- return -1;
- }else{
-
- leftv= p->data[2][0]= get_bits(&s->gb, 8);
- lefty= p->data[0][1]= get_bits(&s->gb, 8);
- leftu= p->data[1][0]= get_bits(&s->gb, 8);
- p->data[0][0]= get_bits(&s->gb, 8);
-
- switch(s->predictor){
- case LEFT:
- case PLANE:
- decode_422_bitstream(s, width-2);
- lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu);
- leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv);
- }
-
- for(cy=y=1; y<s->height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- decode_gray_bitstream(s, width);
-
- ydst= p->data[0] + p->linesize[0]*y;
-
- lefty= add_left_prediction(ydst, s->temp[0], width, lefty);
- if(s->predictor == PLANE){
- if(y>s->interlaced)
- s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
- }
- y++;
- if(y>=s->height) break;
- }
-
- draw_slice(s, y);
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- decode_422_bitstream(s, width);
- lefty= add_left_prediction(ydst, s->temp[0], width, lefty);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- leftu= add_left_prediction(udst, s->temp[1], width2, leftu);
- leftv= add_left_prediction(vdst, s->temp[2], width2, leftv);
- }
- if(s->predictor == PLANE){
- if(cy>s->interlaced){
- s->dsp.add_bytes(ydst, ydst - fake_ystride, width);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- s->dsp.add_bytes(udst, udst - fake_ustride, width2);
- s->dsp.add_bytes(vdst, vdst - fake_vstride, width2);
- }
- }
- }
- }
- draw_slice(s, height);
-
- break;
- case MEDIAN:
- /* first line except first 2 pixels is left predicted */
- decode_422_bitstream(s, width-2);
- lefty= add_left_prediction(p->data[0] + 2, s->temp[0], width-2, lefty);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- leftu= add_left_prediction(p->data[1] + 1, s->temp[1], width2-1, leftu);
- leftv= add_left_prediction(p->data[2] + 1, s->temp[2], width2-1, leftv);
- }
-
- cy=y=1;
-
- /* second line is left predicted for interlaced case */
- if(s->interlaced){
- decode_422_bitstream(s, width);
- lefty= add_left_prediction(p->data[0] + p->linesize[0], s->temp[0], width, lefty);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- leftu= add_left_prediction(p->data[1] + p->linesize[2], s->temp[1], width2, leftu);
- leftv= add_left_prediction(p->data[2] + p->linesize[1], s->temp[2], width2, leftv);
- }
- y++; cy++;
- }
-
- /* next 4 pixels are left predicted too */
- decode_422_bitstream(s, 4);
- lefty= add_left_prediction(p->data[0] + fake_ystride, s->temp[0], 4, lefty);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- leftu= add_left_prediction(p->data[1] + fake_ustride, s->temp[1], 2, leftu);
- leftv= add_left_prediction(p->data[2] + fake_vstride, s->temp[2], 2, leftv);
- }
-
- /* next line except the first 4 pixels is median predicted */
- lefttopy= p->data[0][3];
- decode_422_bitstream(s, width-4);
- add_median_prediction(p->data[0] + fake_ystride+4, p->data[0]+4, s->temp[0], width-4, &lefty, &lefttopy);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- lefttopu= p->data[1][1];
- lefttopv= p->data[2][1];
- add_median_prediction(p->data[1] + fake_ustride+2, p->data[1]+2, s->temp[1], width2-2, &leftu, &lefttopu);
- add_median_prediction(p->data[2] + fake_vstride+2, p->data[2]+2, s->temp[2], width2-2, &leftv, &lefttopv);
- }
- y++; cy++;
-
- for(; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- while(2*cy > y){
- decode_gray_bitstream(s, width);
- ydst= p->data[0] + p->linesize[0]*y;
- add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
- y++;
- }
- if(y>=height) break;
- }
- draw_slice(s, y);
-
- decode_422_bitstream(s, width);
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- add_median_prediction(ydst, ydst - fake_ystride, s->temp[0], width, &lefty, &lefttopy);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- add_median_prediction(udst, udst - fake_ustride, s->temp[1], width2, &leftu, &lefttopu);
- add_median_prediction(vdst, vdst - fake_vstride, s->temp[2], width2, &leftv, &lefttopv);
- }
- }
-
- draw_slice(s, height);
- break;
- }
- }
- }else{
- int y;
- int leftr, leftg, leftb;
- const int last_line= (height-1)*p->linesize[0];
-
- if(s->bitstream_bpp==32){
- p->data[0][last_line+3]= get_bits(&s->gb, 8);
- leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8);
- leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8);
- leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8);
- }else{
- leftr= p->data[0][last_line+2]= get_bits(&s->gb, 8);
- leftg= p->data[0][last_line+1]= get_bits(&s->gb, 8);
- leftb= p->data[0][last_line+0]= get_bits(&s->gb, 8);
- skip_bits(&s->gb, 8);
- }
-
- if(s->bgr32){
- switch(s->predictor){
- case LEFT:
- case PLANE:
- decode_bgr_bitstream(s, width-1);
- add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb);
-
- for(y=s->height-2; y>=0; y--){ //yes its stored upside down
- decode_bgr_bitstream(s, width);
-
- add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb);
- if(s->predictor == PLANE){
- if((y&s->interlaced)==0){
- s->dsp.add_bytes(p->data[0] + p->linesize[0]*y,
- p->data[0] + p->linesize[0]*y + fake_ystride, fake_ystride);
- }
- }
- }
- draw_slice(s, height); // just 1 large slice as this isnt possible in reverse order
- break;
- default:
- fprintf(stderr, "prediction type not supported!\n");
- }
- }else{
-
- fprintf(stderr, "BGR24 output isnt implemenetd yet\n");
- return -1;
- }
- }
- emms_c();
-
- *picture= *p;
- *data_size = sizeof(AVFrame);
-
- return (get_bits_count(&s->gb)+31)/32*4;
-}
-
-static int decode_end(AVCodecContext *avctx)
-{
- HYuvContext *s = avctx->priv_data;
- int i;
-
- for(i=0; i<3; i++){
- free_vlc(&s->vlc[i]);
- }
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- HYuvContext *s = avctx->priv_data;
- AVFrame *pict = data;
- const int width= s->width;
- const int width2= s->width>>1;
- const int height= s->height;
- const int fake_ystride= s->interlaced ? pict->linesize[0]*2 : pict->linesize[0];
- const int fake_ustride= s->interlaced ? pict->linesize[1]*2 : pict->linesize[1];
- const int fake_vstride= s->interlaced ? pict->linesize[2]*2 : pict->linesize[2];
- AVFrame * const p= &s->picture;
- int i, size;
-
- init_put_bits(&s->pb, buf, buf_size, NULL, NULL);
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
-
- if(avctx->pix_fmt == PIX_FMT_YUV422P || avctx->pix_fmt == PIX_FMT_YUV420P){
- int lefty, leftu, leftv, y, cy;
-
- put_bits(&s->pb, 8, leftv= p->data[2][0]);
- put_bits(&s->pb, 8, lefty= p->data[0][1]);
- put_bits(&s->pb, 8, leftu= p->data[1][0]);
- put_bits(&s->pb, 8, p->data[0][0]);
-
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+2, width-2 , lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+1, width2-1, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+1, width2-1, leftv);
-
- encode_422_bitstream(s, width-2);
-
- if(s->predictor==MEDIAN){
- int lefttopy, lefttopu, lefttopv;
- cy=y=1;
- if(s->interlaced){
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+p->linesize[0], width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+p->linesize[1], width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+p->linesize[2], width2, leftv);
-
- encode_422_bitstream(s, width);
- y++; cy++;
- }
-
- lefty= sub_left_prediction(s, s->temp[0], p->data[0]+fake_ystride, 4, lefty);
- leftu= sub_left_prediction(s, s->temp[1], p->data[1]+fake_ystride, 2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], p->data[2]+fake_ystride, 2, leftv);
-
- encode_422_bitstream(s, 4);
-
- lefttopy= p->data[0][3];
- lefttopu= p->data[1][1];
- lefttopv= p->data[2][1];
- sub_median_prediction(s->temp[0], p->data[0]+4, p->data[0] + fake_ystride+4, width-4 , &lefty, &lefttopy);
- sub_median_prediction(s->temp[1], p->data[1]+2, p->data[1] + fake_ustride+2, width2-2, &leftu, &lefttopu);
- sub_median_prediction(s->temp[2], p->data[2]+2, p->data[2] + fake_vstride+2, width2-2, &leftv, &lefttopv);
- encode_422_bitstream(s, width-4);
- y++; cy++;
-
- for(; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- if(s->bitstream_bpp==12){
- while(2*cy > y){
- ydst= p->data[0] + p->linesize[0]*y;
- sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
- encode_gray_bitstream(s, width);
- y++;
- }
- if(y>=height) break;
- }
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- sub_median_prediction(s->temp[0], ydst - fake_ystride, ydst, width , &lefty, &lefttopy);
- sub_median_prediction(s->temp[1], udst - fake_ustride, udst, width2, &leftu, &lefttopu);
- sub_median_prediction(s->temp[2], vdst - fake_vstride, vdst, width2, &leftv, &lefttopv);
-
- encode_422_bitstream(s, width);
- }
- }else{
- for(cy=y=1; y<height; y++,cy++){
- uint8_t *ydst, *udst, *vdst;
-
- /* encode a luma only line & y++ */
- if(s->bitstream_bpp==12){
- ydst= p->data[0] + p->linesize[0]*y;
-
- if(s->predictor == PLANE && s->interlaced < y){
- s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
-
- lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
- }else{
- lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
- }
- encode_gray_bitstream(s, width);
- y++;
- if(y>=height) break;
- }
-
- ydst= p->data[0] + p->linesize[0]*y;
- udst= p->data[1] + p->linesize[1]*cy;
- vdst= p->data[2] + p->linesize[2]*cy;
-
- if(s->predictor == PLANE && s->interlaced < cy){
- s->dsp.diff_bytes(s->temp[1], ydst, ydst - fake_ystride, width);
- s->dsp.diff_bytes(s->temp[2], udst, udst - fake_ustride, width2);
- s->dsp.diff_bytes(s->temp[3], vdst, vdst - fake_vstride, width2);
-
- lefty= sub_left_prediction(s, s->temp[0], s->temp[1], width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], s->temp[2], width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], s->temp[3], width2, leftv);
- }else{
- lefty= sub_left_prediction(s, s->temp[0], ydst, width , lefty);
- leftu= sub_left_prediction(s, s->temp[1], udst, width2, leftu);
- leftv= sub_left_prediction(s, s->temp[2], vdst, width2, leftv);
- }
-
- encode_422_bitstream(s, width);
- }
- }
- }else{
- fprintf(stderr, "Format not supported!\n");
- }
- emms_c();
-
- size= (get_bit_count(&s->pb)+31)/32;
-
- if((s->flags&CODEC_FLAG_PASS1) && (s->picture_number&31)==0){
- int j;
- char *p= avctx->stats_out;
- for(i=0; i<3; i++){
- for(j=0; j<256; j++){
- sprintf(p, "%llu ", s->stats[i][j]);
- p+= strlen(p);
- s->stats[i][j]= 0;
- }
- sprintf(p, "\n");
- p++;
- }
- }else{
- flush_put_bits(&s->pb);
- s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size);
- }
-
- s->picture_number++;
-
- return size*4;
-}
-
-static int encode_end(AVCodecContext *avctx)
-{
-// HYuvContext *s = avctx->priv_data;
-
- av_freep(&avctx->extradata);
- av_freep(&avctx->stats_out);
-
- return 0;
-}
-
-static const AVOption huffyuv_options[] =
-{
- AVOPTION_CODEC_INT("prediction_method", "prediction_method", prediction_method, 0, 2, 0),
- AVOPTION_END()
-};
-
-AVCodec huffyuv_decoder = {
- "huffyuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec huffyuv_encoder = {
- "huffyuv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_HUFFYUV,
- sizeof(HYuvContext),
- encode_init,
- encode_frame,
- encode_end,
- .options = huffyuv_options,
-};
-
-#endif //CONFIG_ENCODERS
+++ /dev/null
-/* Cpu detection code, extracted from mmx.h ((c)1997-99 by H. Dietz
- and R. Fisher). Converted to C and improved by Fabrice Bellard */
-
-#include <stdlib.h>
-#include "../dsputil.h"
-
-/* ebx saving is necessary for PIC. gcc seems unable to see it alone */
-#define cpuid(index,eax,ebx,ecx,edx)\
- __asm __volatile\
- ("movl %%ebx, %%esi\n\t"\
- "cpuid\n\t"\
- "xchgl %%ebx, %%esi"\
- : "=a" (eax), "=S" (ebx),\
- "=c" (ecx), "=d" (edx)\
- : "0" (index));
-
-/* Function to test if multimedia instructions are supported... */
-int mm_support(void)
-{
- int rval;
- int eax, ebx, ecx, edx;
-
- __asm__ __volatile__ (
- /* See if CPUID instruction is supported ... */
- /* ... Get copies of EFLAGS into eax and ecx */
- "pushf\n\t"
- "popl %0\n\t"
- "movl %0, %1\n\t"
-
- /* ... Toggle the ID bit in one copy and store */
- /* to the EFLAGS reg */
- "xorl $0x200000, %0\n\t"
- "push %0\n\t"
- "popf\n\t"
-
- /* ... Get the (hopefully modified) EFLAGS */
- "pushf\n\t"
- "popl %0\n\t"
- : "=a" (eax), "=c" (ecx)
- :
- : "cc"
- );
-
- if (eax == ecx)
- return 0; /* CPUID not supported */
-
- cpuid(0, eax, ebx, ecx, edx);
-
- if (ebx == 0x756e6547 &&
- edx == 0x49656e69 &&
- ecx == 0x6c65746e) {
-
- /* intel */
- inteltest:
- cpuid(1, eax, ebx, ecx, edx);
- if ((edx & 0x00800000) == 0)
- return 0;
- rval = MM_MMX;
- if (edx & 0x02000000)
- rval |= MM_MMXEXT | MM_SSE;
- if (edx & 0x04000000)
- rval |= MM_SSE2;
- return rval;
- } else if (ebx == 0x68747541 &&
- edx == 0x69746e65 &&
- ecx == 0x444d4163) {
- /* AMD */
- cpuid(0x80000000, eax, ebx, ecx, edx);
- if ((unsigned)eax < 0x80000001)
- goto inteltest;
- cpuid(0x80000001, eax, ebx, ecx, edx);
- if ((edx & 0x00800000) == 0)
- return 0;
- rval = MM_MMX;
- if (edx & 0x80000000)
- rval |= MM_3DNOW;
- if (edx & 0x00400000)
- rval |= MM_MMXEXT;
- return rval;
- } else if (ebx == 0x746e6543 &&
- edx == 0x48727561 &&
- ecx == 0x736c7561) { /* "CentaurHauls" */
- /* VIA C3 */
- cpuid(0x80000000, eax, ebx, ecx, edx);
- if ((unsigned)eax < 0x80000001)
- goto inteltest;
- cpuid(0x80000001, eax, ebx, ecx, edx);
- rval = 0;
- if( edx & ( 1 << 31) )
- rval |= MM_3DNOW;
- if( edx & ( 1 << 23) )
- rval |= MM_MMX;
- if( edx & ( 1 << 24) )
- rval |= MM_MMXEXT;
- return rval;
- } else if (ebx == 0x69727943 &&
- edx == 0x736e4978 &&
- ecx == 0x64616574) {
- /* Cyrix Section */
- /* See if extended CPUID level 80000001 is supported */
- /* The value of CPUID/80000001 for the 6x86MX is undefined
- according to the Cyrix CPU Detection Guide (Preliminary
- Rev. 1.01 table 1), so we'll check the value of eax for
- CPUID/0 to see if standard CPUID level 2 is supported.
- According to the table, the only CPU which supports level
- 2 is also the only one which supports extended CPUID levels.
- */
- if (eax != 2)
- goto inteltest;
- cpuid(0x80000001, eax, ebx, ecx, edx);
- if ((eax & 0x00800000) == 0)
- return 0;
- rval = MM_MMX;
- if (eax & 0x01000000)
- rval |= MM_MMXEXT;
- return rval;
- } else {
- return 0;
- }
-}
-
-#ifdef __TEST__
-int main ( void )
-{
- int mm_flags;
- mm_flags = mm_support();
- printf("mm_support = 0x%08u\n",mm_flags);
- return 0;
-}
-#endif
+++ /dev/null
-/*
- * MMX optimized DSP utils
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
- */
-
-#include "../dsputil.h"
-#include "../simple_idct.h"
-
-int mm_flags; /* multimedia extension flags */
-
-/* pixel operations */
-static const uint64_t mm_bone __attribute__ ((aligned(8))) = 0x0101010101010101ULL;
-static const uint64_t mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
-static const uint64_t mm_wtwo __attribute__ ((aligned(8))) = 0x0002000200020002ULL;
-
-static const uint64_t ff_pw_20 __attribute__ ((aligned(8))) = 0x0014001400140014ULL;
-static const uint64_t ff_pw_3 __attribute__ ((aligned(8))) = 0x0003000300030003ULL;
-static const uint64_t ff_pw_16 __attribute__ ((aligned(8))) = 0x0010001000100010ULL;
-static const uint64_t ff_pw_15 __attribute__ ((aligned(8))) = 0x000F000F000F000FULL;
-
-#define JUMPALIGN() __asm __volatile (".balign 8"::)
-#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::)
-
-#define MOVQ_WONE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd ::)
-
-#define MOVQ_BFE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t"\
- "paddb %%" #regd ", %%" #regd " \n\t" ::)
-
-#ifndef PIC
-#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone))
-#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo))
-#else
-// for shared library it's better to use this way for accessing constants
-// pcmpeqd -> -1
-#define MOVQ_BONE(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd " \n\t" \
- "packuswb %%" #regd ", %%" #regd " \n\t" ::)
-
-#define MOVQ_WTWO(regd) \
- __asm __volatile ( \
- "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
- "psrlw $15, %%" #regd " \n\t" \
- "psllw $1, %%" #regd " \n\t"::)
-
-#endif
-
-// using regr as temporary and for the output result
-// first argument is unmodifed and second is trashed
-// regfe is supposed to contain 0xfefefefefefefefe
-#define PAVGB_MMX_NO_RND(rega, regb, regr, regfe) \
- "movq " #rega ", " #regr " \n\t"\
- "pand " #regb ", " #regr " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pand " #regfe "," #regb " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "paddb " #regb ", " #regr " \n\t"
-
-#define PAVGB_MMX(rega, regb, regr, regfe) \
- "movq " #rega ", " #regr " \n\t"\
- "por " #regb ", " #regr " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pand " #regfe "," #regb " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psubb " #regb ", " #regr " \n\t"
-
-// mm6 is supposed to contain 0xfefefefefefefefe
-#define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
- "movq " #rega ", " #regr " \n\t"\
- "movq " #regc ", " #regp " \n\t"\
- "pand " #regb ", " #regr " \n\t"\
- "pand " #regd ", " #regp " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pxor " #regc ", " #regd " \n\t"\
- "pand %%mm6, " #regb " \n\t"\
- "pand %%mm6, " #regd " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psrlq $1, " #regd " \n\t"\
- "paddb " #regb ", " #regr " \n\t"\
- "paddb " #regd ", " #regp " \n\t"
-
-#define PAVGBP_MMX(rega, regb, regr, regc, regd, regp) \
- "movq " #rega ", " #regr " \n\t"\
- "movq " #regc ", " #regp " \n\t"\
- "por " #regb ", " #regr " \n\t"\
- "por " #regd ", " #regp " \n\t"\
- "pxor " #rega ", " #regb " \n\t"\
- "pxor " #regc ", " #regd " \n\t"\
- "pand %%mm6, " #regb " \n\t"\
- "pand %%mm6, " #regd " \n\t"\
- "psrlq $1, " #regd " \n\t"\
- "psrlq $1, " #regb " \n\t"\
- "psubb " #regb ", " #regr " \n\t"\
- "psubb " #regd ", " #regp " \n\t"
-
-/***********************************/
-/* MMX no rounding */
-#define DEF(x, y) x ## _no_rnd_ ## y ##_mmx
-#define SET_RND MOVQ_WONE
-#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX_NO_RND(a, b, c, d, e, f)
-#define PAVGB(a, b, c, e) PAVGB_MMX_NO_RND(a, b, c, e)
-
-#include "dsputil_mmx_rnd.h"
-
-#undef DEF
-#undef SET_RND
-#undef PAVGBP
-#undef PAVGB
-/***********************************/
-/* MMX rounding */
-
-#define DEF(x, y) x ## _ ## y ##_mmx
-#define SET_RND MOVQ_WTWO
-#define PAVGBP(a, b, c, d, e, f) PAVGBP_MMX(a, b, c, d, e, f)
-#define PAVGB(a, b, c, e) PAVGB_MMX(a, b, c, e)
-
-#include "dsputil_mmx_rnd.h"
-
-#undef DEF
-#undef SET_RND
-#undef PAVGBP
-#undef PAVGB
-
-/***********************************/
-/* 3Dnow specific */
-
-#define DEF(x) x ## _3dnow
-/* for Athlons PAVGUSB is prefered */
-#define PAVGB "pavgusb"
-
-#include "dsputil_mmx_avg.h"
-
-#undef DEF
-#undef PAVGB
-
-/***********************************/
-/* MMX2 specific */
-
-#define DEF(x) x ## _mmx2
-
-/* Introduced only in MMX2 set */
-#define PAVGB "pavgb"
-
-#include "dsputil_mmx_avg.h"
-
-#undef DEF
-#undef PAVGB
-
-/***********************************/
-/* standard MMX */
-
-static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size)
-{
- asm volatile(
- "movl $-128, %%eax \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%0), %%mm0 \n\t"
- "movq (%0, %2), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "movq %%mm0, (%1, %%eax)\n\t"
- "movq %%mm1, 8(%1, %%eax)\n\t"
- "movq %%mm2, 16(%1, %%eax)\n\t"
- "movq %%mm3, 24(%1, %%eax)\n\t"
- "addl %3, %0 \n\t"
- "addl $32, %%eax \n\t"
- "js 1b \n\t"
- : "+r" (pixels)
- : "r" (block+64), "r" (line_size), "r" (line_size*2)
- : "%eax"
- );
-}
-
-static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride)
-{
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "movl $-128, %%eax \n\t"
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%0), %%mm0 \n\t"
- "movq (%1), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "movq %%mm0, (%2, %%eax)\n\t"
- "movq %%mm1, 8(%2, %%eax)\n\t"
- "addl %3, %0 \n\t"
- "addl %3, %1 \n\t"
- "addl $16, %%eax \n\t"
- "jnz 1b \n\t"
- : "+r" (s1), "+r" (s2)
- : "r" (block+64), "r" (stride)
- : "%eax"
- );
-}
-
-void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- const DCTELEM *p;
- uint8_t *pix;
-
- /* read the pixels */
- p = block;
- pix = pixels;
- /* unrolled loop */
- __asm __volatile(
- "movq %3, %%mm0\n\t"
- "movq 8%3, %%mm1\n\t"
- "movq 16%3, %%mm2\n\t"
- "movq 24%3, %%mm3\n\t"
- "movq 32%3, %%mm4\n\t"
- "movq 40%3, %%mm5\n\t"
- "movq 48%3, %%mm6\n\t"
- "movq 56%3, %%mm7\n\t"
- "packuswb %%mm1, %%mm0\n\t"
- "packuswb %%mm3, %%mm2\n\t"
- "packuswb %%mm5, %%mm4\n\t"
- "packuswb %%mm7, %%mm6\n\t"
- "movq %%mm0, (%0)\n\t"
- "movq %%mm2, (%0, %1)\n\t"
- "movq %%mm4, (%0, %1, 2)\n\t"
- "movq %%mm6, (%0, %2)\n\t"
- ::"r" (pix), "r" (line_size), "r" (line_size*3), "m"(*p)
- :"memory");
- pix += line_size*4;
- p += 32;
-
- // if here would be an exact copy of the code above
- // compiler would generate some very strange code
- // thus using "r"
- __asm __volatile(
- "movq (%3), %%mm0\n\t"
- "movq 8(%3), %%mm1\n\t"
- "movq 16(%3), %%mm2\n\t"
- "movq 24(%3), %%mm3\n\t"
- "movq 32(%3), %%mm4\n\t"
- "movq 40(%3), %%mm5\n\t"
- "movq 48(%3), %%mm6\n\t"
- "movq 56(%3), %%mm7\n\t"
- "packuswb %%mm1, %%mm0\n\t"
- "packuswb %%mm3, %%mm2\n\t"
- "packuswb %%mm5, %%mm4\n\t"
- "packuswb %%mm7, %%mm6\n\t"
- "movq %%mm0, (%0)\n\t"
- "movq %%mm2, (%0, %1)\n\t"
- "movq %%mm4, (%0, %1, 2)\n\t"
- "movq %%mm6, (%0, %2)\n\t"
- ::"r" (pix), "r" (line_size), "r" (line_size*3), "r"(p)
- :"memory");
-}
-
-void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size)
-{
- const DCTELEM *p;
- uint8_t *pix;
- int i;
-
- /* read the pixels */
- p = block;
- pix = pixels;
- MOVQ_ZERO(mm7);
- i = 4;
- do {
- __asm __volatile(
- "movq (%2), %%mm0\n\t"
- "movq 8(%2), %%mm1\n\t"
- "movq 16(%2), %%mm2\n\t"
- "movq 24(%2), %%mm3\n\t"
- "movq %0, %%mm4\n\t"
- "movq %1, %%mm6\n\t"
- "movq %%mm4, %%mm5\n\t"
- "punpcklbw %%mm7, %%mm4\n\t"
- "punpckhbw %%mm7, %%mm5\n\t"
- "paddsw %%mm4, %%mm0\n\t"
- "paddsw %%mm5, %%mm1\n\t"
- "movq %%mm6, %%mm5\n\t"
- "punpcklbw %%mm7, %%mm6\n\t"
- "punpckhbw %%mm7, %%mm5\n\t"
- "paddsw %%mm6, %%mm2\n\t"
- "paddsw %%mm5, %%mm3\n\t"
- "packuswb %%mm1, %%mm0\n\t"
- "packuswb %%mm3, %%mm2\n\t"
- "movq %%mm0, %0\n\t"
- "movq %%mm2, %1\n\t"
- :"+m"(*pix), "+m"(*(pix+line_size))
- :"r"(p)
- :"memory");
- pix += line_size*2;
- p += 16;
- } while (--i);
-}
-
-static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- : "+g"(h), "+r" (pixels), "+r" (block)
- : "r"(line_size)
- : "%eax", "memory"
- );
-}
-
-static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm4 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm5 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm4 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm5 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- : "+g"(h), "+r" (pixels), "+r" (block)
- : "r"(line_size)
- : "%eax", "memory"
- );
-}
-
-static void clear_blocks_mmx(DCTELEM *blocks)
-{
- __asm __volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "movl $-128*6, %%eax \n\t"
- "1: \n\t"
- "movq %%mm7, (%0, %%eax) \n\t"
- "movq %%mm7, 8(%0, %%eax) \n\t"
- "movq %%mm7, 16(%0, %%eax) \n\t"
- "movq %%mm7, 24(%0, %%eax) \n\t"
- "addl $32, %%eax \n\t"
- " js 1b \n\t"
- : : "r" (((int)blocks)+128*6)
- : "%eax"
- );
-}
-
-static int pix_sum16_mmx(uint8_t * pix, int line_size){
- const int h=16;
- int sum;
- int index= -line_size*h;
-
- __asm __volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq (%2, %1), %%mm0 \n\t"
- "movq (%2, %1), %%mm1 \n\t"
- "movq 8(%2, %1), %%mm2 \n\t"
- "movq 8(%2, %1), %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddw %%mm0, %%mm1 \n\t"
- "paddw %%mm2, %%mm3 \n\t"
- "paddw %%mm1, %%mm3 \n\t"
- "paddw %%mm3, %%mm6 \n\t"
- "addl %3, %1 \n\t"
- " js 1b \n\t"
- "movq %%mm6, %%mm5 \n\t"
- "psrlq $32, %%mm6 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
- "movq %%mm6, %%mm5 \n\t"
- "psrlq $16, %%mm6 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
- "movd %%mm6, %0 \n\t"
- "andl $0xFFFF, %0 \n\t"
- : "=&r" (sum), "+r" (index)
- : "r" (pix - index), "r" (line_size)
- );
-
- return sum;
-}
-
-static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){
- int i=0;
- asm volatile(
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq (%2, %0), %%mm1 \n\t"
- "paddb %%mm0, %%mm1 \n\t"
- "movq %%mm1, (%2, %0) \n\t"
- "movq 8(%1, %0), %%mm0 \n\t"
- "movq 8(%2, %0), %%mm1 \n\t"
- "paddb %%mm0, %%mm1 \n\t"
- "movq %%mm1, 8(%2, %0) \n\t"
- "addl $16, %0 \n\t"
- "cmpl %3, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (i)
- : "r"(src), "r"(dst), "r"(w-15)
- );
- for(; i<w; i++)
- dst[i+0] += src[i+0];
-}
-
-static int pix_norm1_mmx(uint8_t *pix, int line_size) {
- int tmp;
- asm volatile (
- "movl $16,%%ecx\n"
- "pxor %%mm0,%%mm0\n"
- "pxor %%mm7,%%mm7\n"
- "1:\n"
- "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */
- "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */
-
- "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */
-
- "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */
- "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */
-
- "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */
- "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */
- "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */
-
- "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */
- "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */
-
- "pmaddwd %%mm3,%%mm3\n"
- "pmaddwd %%mm4,%%mm4\n"
-
- "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2,
- pix2^2+pix3^2+pix6^2+pix7^2) */
- "paddd %%mm3,%%mm4\n"
- "paddd %%mm2,%%mm7\n"
-
- "addl %2, %0\n"
- "paddd %%mm4,%%mm7\n"
- "dec %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm7,%%mm1\n"
- "psrlq $32, %%mm7\n" /* shift hi dword to lo */
- "paddd %%mm7,%%mm1\n"
- "movd %%mm1,%1\n"
- : "+r" (pix), "=r"(tmp) : "r" (line_size) : "%ecx" );
- return tmp;
-}
-
-static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size) {
- int tmp;
- asm volatile (
- "movl $16,%%ecx\n"
- "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
- "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
- "1:\n"
- "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
- "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
- "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
- "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
-
- /* todo: mm1-mm2, mm3-mm4 */
- /* algo: substract mm1 from mm2 with saturation and vice versa */
- /* OR the results to get absolute difference */
- "movq %%mm1,%%mm5\n"
- "movq %%mm3,%%mm6\n"
- "psubusb %%mm2,%%mm1\n"
- "psubusb %%mm4,%%mm3\n"
- "psubusb %%mm5,%%mm2\n"
- "psubusb %%mm6,%%mm4\n"
-
- "por %%mm1,%%mm2\n"
- "por %%mm3,%%mm4\n"
-
- /* now convert to 16-bit vectors so we can square them */
- "movq %%mm2,%%mm1\n"
- "movq %%mm4,%%mm3\n"
-
- "punpckhbw %%mm0,%%mm2\n"
- "punpckhbw %%mm0,%%mm4\n"
- "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
- "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
-
- "pmaddwd %%mm2,%%mm2\n"
- "pmaddwd %%mm4,%%mm4\n"
- "pmaddwd %%mm1,%%mm1\n"
- "pmaddwd %%mm3,%%mm3\n"
-
- "addl %3,%0\n"
- "addl %3,%1\n"
-
- "paddd %%mm2,%%mm1\n"
- "paddd %%mm4,%%mm3\n"
- "paddd %%mm1,%%mm7\n"
- "paddd %%mm3,%%mm7\n"
-
- "decl %%ecx\n"
- "jnz 1b\n"
-
- "movq %%mm7,%%mm1\n"
- "psrlq $32, %%mm7\n" /* shift hi dword to lo */
- "paddd %%mm7,%%mm1\n"
- "movd %%mm1,%2\n"
- : "+r" (pix1), "+r" (pix2), "=r"(tmp) : "r" (line_size) : "ecx");
- return tmp;
-}
-
-static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
- int i=0;
- asm volatile(
- "1: \n\t"
- "movq (%2, %0), %%mm0 \n\t"
- "movq (%1, %0), %%mm1 \n\t"
- "psubb %%mm0, %%mm1 \n\t"
- "movq %%mm1, (%3, %0) \n\t"
- "movq 8(%2, %0), %%mm0 \n\t"
- "movq 8(%1, %0), %%mm1 \n\t"
- "psubb %%mm0, %%mm1 \n\t"
- "movq %%mm1, 8(%3, %0) \n\t"
- "addl $16, %0 \n\t"
- "cmpl %4, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (i)
- : "r"(src1), "r"(src2), "r"(dst), "r"(w-15)
- );
- for(; i<w; i++)
- dst[i+0] = src1[i+0]-src2[i+0];
-}
-#define LBUTTERFLY2(a1,b1,a2,b2)\
- "paddw " #b1 ", " #a1 " \n\t"\
- "paddw " #b2 ", " #a2 " \n\t"\
- "paddw " #b1 ", " #b1 " \n\t"\
- "paddw " #b2 ", " #b2 " \n\t"\
- "psubw " #a1 ", " #b1 " \n\t"\
- "psubw " #a2 ", " #b2 " \n\t"
-
-#define HADAMARD48\
- LBUTTERFLY2(%%mm0, %%mm1, %%mm2, %%mm3)\
- LBUTTERFLY2(%%mm4, %%mm5, %%mm6, %%mm7)\
- LBUTTERFLY2(%%mm0, %%mm2, %%mm1, %%mm3)\
- LBUTTERFLY2(%%mm4, %%mm6, %%mm5, %%mm7)\
- LBUTTERFLY2(%%mm0, %%mm4, %%mm1, %%mm5)\
- LBUTTERFLY2(%%mm2, %%mm6, %%mm3, %%mm7)\
-
-#define MMABS(a,z)\
- "pxor " #z ", " #z " \n\t"\
- "pcmpgtw " #a ", " #z " \n\t"\
- "pxor " #z ", " #a " \n\t"\
- "psubw " #z ", " #a " \n\t"
-
-#define MMABS_SUM(a,z, sum)\
- "pxor " #z ", " #z " \n\t"\
- "pcmpgtw " #a ", " #z " \n\t"\
- "pxor " #z ", " #a " \n\t"\
- "psubw " #z ", " #a " \n\t"\
- "paddusw " #a ", " #sum " \n\t"
-
-#define MMABS_MMX2(a,z)\
- "pxor " #z ", " #z " \n\t"\
- "psubw " #a ", " #z " \n\t"\
- "pmaxsw " #z ", " #a " \n\t"
-
-#define MMABS_SUM_MMX2(a,z, sum)\
- "pxor " #z ", " #z " \n\t"\
- "psubw " #a ", " #z " \n\t"\
- "pmaxsw " #z ", " #a " \n\t"\
- "paddusw " #a ", " #sum " \n\t"
-
-#define SBUTTERFLY(a,b,t,n)\
- "movq " #a ", " #t " \n\t" /* abcd */\
- "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
- "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
-
-#define TRANSPOSE4(a,b,c,d,t)\
- SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\
- SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\
- SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\
- SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */
-
-#define LOAD4(o, a, b, c, d)\
- "movq "#o"(%1), " #a " \n\t"\
- "movq "#o"+16(%1), " #b " \n\t"\
- "movq "#o"+32(%1), " #c " \n\t"\
- "movq "#o"+48(%1), " #d " \n\t"
-
-#define STORE4(o, a, b, c, d)\
- "movq "#a", "#o"(%1) \n\t"\
- "movq "#b", "#o"+16(%1) \n\t"\
- "movq "#c", "#o"+32(%1) \n\t"\
- "movq "#d", "#o"+48(%1) \n\t"\
-
-static int hadamard8_diff_mmx(void *s, uint8_t *src1, uint8_t *src2, int stride){
- uint64_t temp[16] __align8;
- int sum=0;
-
- diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
-
- asm volatile(
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 112(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 112(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
-
- LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 120(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 120(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- "movq %%mm7, %%mm5 \n\t"//FIXME remove
- "movq %%mm6, %%mm7 \n\t"
- "movq %%mm0, %%mm6 \n\t"
-// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
-
- LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
-// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, 64(%1) \n\t"
- MMABS(%%mm0, %%mm7)
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- MMABS_SUM(%%mm2, %%mm7, %%mm0)
- MMABS_SUM(%%mm3, %%mm7, %%mm0)
- MMABS_SUM(%%mm4, %%mm7, %%mm0)
- MMABS_SUM(%%mm5, %%mm7, %%mm0)
- MMABS_SUM(%%mm6, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- "movq %%mm0, 64(%1) \n\t"
-
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, (%1) \n\t"
- MMABS(%%mm0, %%mm7)
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- MMABS_SUM(%%mm2, %%mm7, %%mm0)
- MMABS_SUM(%%mm3, %%mm7, %%mm0)
- MMABS_SUM(%%mm4, %%mm7, %%mm0)
- MMABS_SUM(%%mm5, %%mm7, %%mm0)
- MMABS_SUM(%%mm6, %%mm7, %%mm0)
- "movq (%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM(%%mm1, %%mm7, %%mm0)
-
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $16, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movd %%mm0, %0 \n\t"
-
- : "=r" (sum)
- : "r"(temp)
- );
- return sum&0xFFFF;
-}
-
-static int hadamard8_diff_mmx2(void *s, uint8_t *src1, uint8_t *src2, int stride){
- uint64_t temp[16] __align8;
- int sum=0;
-
- diff_pixels_mmx((DCTELEM*)temp, src1, src2, stride);
-
- asm volatile(
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(64, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 112(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(0 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 112(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- STORE4(64, %%mm4, %%mm7, %%mm0, %%mm6)
-
- LOAD4(8 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
-
- "movq %%mm7, 120(%1) \n\t"
-
- TRANSPOSE4(%%mm0, %%mm1, %%mm2, %%mm3, %%mm7)
- STORE4(8 , %%mm0, %%mm3, %%mm7, %%mm2)
-
- "movq 120(%1), %%mm7 \n\t"
- TRANSPOSE4(%%mm4, %%mm5, %%mm6, %%mm7, %%mm0)
- "movq %%mm7, %%mm5 \n\t"//FIXME remove
- "movq %%mm6, %%mm7 \n\t"
- "movq %%mm0, %%mm6 \n\t"
-// STORE4(72, %%mm4, %%mm7, %%mm0, %%mm6) //FIXME remove
-
- LOAD4(64, %%mm0, %%mm1, %%mm2, %%mm3)
-// LOAD4(72, %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, 64(%1) \n\t"
- MMABS_MMX2(%%mm0, %%mm7)
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- "movq %%mm0, 64(%1) \n\t"
-
- LOAD4(0 , %%mm0, %%mm1, %%mm2, %%mm3)
- LOAD4(8 , %%mm4, %%mm5, %%mm6, %%mm7)
-
- HADAMARD48
- "movq %%mm7, (%1) \n\t"
- MMABS_MMX2(%%mm0, %%mm7)
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm2, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm3, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm4, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm5, %%mm7, %%mm0)
- MMABS_SUM_MMX2(%%mm6, %%mm7, %%mm0)
- "movq (%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
- "movq 64(%1), %%mm1 \n\t"
- MMABS_SUM_MMX2(%%mm1, %%mm7, %%mm0)
-
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $16, %%mm0 \n\t"
- "paddusw %%mm1, %%mm0 \n\t"
- "movd %%mm0, %0 \n\t"
-
- : "=r" (sum)
- : "r"(temp)
- );
- return sum&0xFFFF;
-}
-
-
-WARPER88_1616(hadamard8_diff_mmx, hadamard8_diff16_mmx)
-WARPER88_1616(hadamard8_diff_mmx2, hadamard8_diff16_mmx2)
-
-#define put_no_rnd_pixels8_mmx(a,b,c,d) put_pixels8_mmx(a,b,c,d)
-#define put_no_rnd_pixels16_mmx(a,b,c,d) put_pixels16_mmx(a,b,c,d)
-
-#define QPEL_V_LOW(m3,m4,m5,m6, pw_20, pw_3, rnd, in0, in1, in2, in7, out, OP)\
- "paddw " #m4 ", " #m3 " \n\t" /* x1 */\
- "movq "MANGLE(ff_pw_20)", %%mm4 \n\t" /* 20 */\
- "pmullw " #m3 ", %%mm4 \n\t" /* 20x1 */\
- "movq "#in7", " #m3 " \n\t" /* d */\
- "movq "#in0", %%mm5 \n\t" /* D */\
- "paddw " #m3 ", %%mm5 \n\t" /* x4 */\
- "psubw %%mm5, %%mm4 \n\t" /* 20x1 - x4 */\
- "movq "#in1", %%mm5 \n\t" /* C */\
- "movq "#in2", %%mm6 \n\t" /* B */\
- "paddw " #m6 ", %%mm5 \n\t" /* x3 */\
- "paddw " #m5 ", %%mm6 \n\t" /* x2 */\
- "paddw %%mm6, %%mm6 \n\t" /* 2x2 */\
- "psubw %%mm6, %%mm5 \n\t" /* -2x2 + x3 */\
- "pmullw "MANGLE(ff_pw_3)", %%mm5 \n\t" /* -6x2 + 3x3 */\
- "paddw " #rnd ", %%mm4 \n\t" /* x2 */\
- "paddw %%mm4, %%mm5 \n\t" /* 20x1 - 6x2 + 3x3 - x4 */\
- "psraw $5, %%mm5 \n\t"\
- "packuswb %%mm5, %%mm5 \n\t"\
- OP(%%mm5, out, %%mm7, d)
-
-#define QPEL_BASE(OPNAME, ROUNDER, RND, OP_MMX2, OP_3DNOW)\
-static void OPNAME ## mpeg4_qpel16_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint64_t temp;\
-\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
- "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
- "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
- "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
- "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
- "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
- "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
- "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
- "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
- "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
- "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
- "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
- "paddw %%mm3, %%mm5 \n\t" /* b */\
- "paddw %%mm2, %%mm6 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
- "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
- "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
- "paddw %%mm4, %%mm0 \n\t" /* a */\
- "paddw %%mm1, %%mm5 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
- "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
- "paddw %6, %%mm6 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- "movq %%mm0, %5 \n\t"\
- /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
- \
- "movq 5(%0), %%mm0 \n\t" /* FGHIJKLM */\
- "movq %%mm0, %%mm5 \n\t" /* FGHIJKLM */\
- "movq %%mm0, %%mm6 \n\t" /* FGHIJKLM */\
- "psrlq $8, %%mm0 \n\t" /* GHIJKLM0 */\
- "psrlq $16, %%mm5 \n\t" /* HIJKLM00 */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0G0H0I0J */\
- "punpcklbw %%mm7, %%mm5 \n\t" /* 0H0I0J0K */\
- "paddw %%mm0, %%mm2 \n\t" /* b */\
- "paddw %%mm5, %%mm3 \n\t" /* c */\
- "paddw %%mm2, %%mm2 \n\t" /* 2b */\
- "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
- "movq %%mm6, %%mm2 \n\t" /* FGHIJKLM */\
- "psrlq $24, %%mm6 \n\t" /* IJKLM000 */\
- "punpcklbw %%mm7, %%mm2 \n\t" /* 0F0G0H0I */\
- "punpcklbw %%mm7, %%mm6 \n\t" /* 0I0J0K0L */\
- "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
- "paddw %%mm2, %%mm1 \n\t" /* a */\
- "paddw %%mm6, %%mm4 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
- "psubw %%mm4, %%mm3 \n\t" /* - 6b +3c - d */\
- "paddw %6, %%mm1 \n\t"\
- "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b +3c - d */\
- "psraw $5, %%mm3 \n\t"\
- "movq %5, %%mm1 \n\t"\
- "packuswb %%mm3, %%mm1 \n\t"\
- OP_MMX2(%%mm1, (%1),%%mm4, q)\
- /* mm0= GHIJ, mm2=FGHI, mm5=HIJK, mm6=IJKL, mm7=0 */\
- \
- "movq 9(%0), %%mm1 \n\t" /* JKLMNOPQ */\
- "movq %%mm1, %%mm4 \n\t" /* JKLMNOPQ */\
- "movq %%mm1, %%mm3 \n\t" /* JKLMNOPQ */\
- "psrlq $8, %%mm1 \n\t" /* KLMNOPQ0 */\
- "psrlq $16, %%mm4 \n\t" /* LMNOPQ00 */\
- "punpcklbw %%mm7, %%mm1 \n\t" /* 0K0L0M0N */\
- "punpcklbw %%mm7, %%mm4 \n\t" /* 0L0M0N0O */\
- "paddw %%mm1, %%mm5 \n\t" /* b */\
- "paddw %%mm4, %%mm0 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm0 \n\t" /* c - 2b */\
- "movq %%mm3, %%mm5 \n\t" /* JKLMNOPQ */\
- "psrlq $24, %%mm3 \n\t" /* MNOPQ000 */\
- "pmullw "MANGLE(ff_pw_3)", %%mm0 \n\t" /* 3c - 6b */\
- "punpcklbw %%mm7, %%mm3 \n\t" /* 0M0N0O0P */\
- "paddw %%mm3, %%mm2 \n\t" /* d */\
- "psubw %%mm2, %%mm0 \n\t" /* -6b + 3c - d */\
- "movq %%mm5, %%mm2 \n\t" /* JKLMNOPQ */\
- "punpcklbw %%mm7, %%mm2 \n\t" /* 0J0K0L0M */\
- "punpckhbw %%mm7, %%mm5 \n\t" /* 0N0O0P0Q */\
- "paddw %%mm2, %%mm6 \n\t" /* a */\
- "pmullw "MANGLE(ff_pw_20)", %%mm6 \n\t" /* 20a */\
- "paddw %6, %%mm0 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- /* mm1=KLMN, mm2=JKLM, mm3=MNOP, mm4=LMNO, mm5=NOPQ mm7=0 */\
- \
- "paddw %%mm5, %%mm3 \n\t" /* a */\
- "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0O0P0Q0Q */\
- "paddw %%mm4, %%mm6 \n\t" /* b */\
- "pshufw $0xBE, %%mm5, %%mm4 \n\t" /* 0P0Q0Q0P */\
- "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0Q0Q0P0O */\
- "paddw %%mm1, %%mm4 \n\t" /* c */\
- "paddw %%mm2, %%mm5 \n\t" /* d */\
- "paddw %%mm6, %%mm6 \n\t" /* 2b */\
- "psubw %%mm6, %%mm4 \n\t" /* c - 2b */\
- "pmullw "MANGLE(ff_pw_20)", %%mm3 \n\t" /* 20a */\
- "pmullw "MANGLE(ff_pw_3)", %%mm4 \n\t" /* 3c - 6b */\
- "psubw %%mm5, %%mm3 \n\t" /* -6b + 3c - d */\
- "paddw %6, %%mm4 \n\t"\
- "paddw %%mm3, %%mm4 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm4 \n\t"\
- "packuswb %%mm4, %%mm0 \n\t"\
- OP_MMX2(%%mm0, 8(%1), %%mm4, q)\
- \
- "addl %3, %0 \n\t"\
- "addl %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "d"(srcStride), "S"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel16_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- int i;\
- int16_t temp[16];\
- /* quick HACK, XXX FIXME MUST be optimized */\
- for(i=0; i<h; i++)\
- {\
- temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
- temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
- temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
- temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
- temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
- temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]);\
- temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]);\
- temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]);\
- temp[ 8]= (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]);\
- temp[ 9]= (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]);\
- temp[10]= (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]);\
- temp[11]= (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]);\
- temp[12]= (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]);\
- temp[13]= (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]);\
- temp[14]= (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]);\
- temp[15]= (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]);\
- asm volatile(\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, (%1), %%mm1, q)\
- "movq 16(%0), %%mm0 \n\t"\
- "movq 24(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, 8(%1), %%mm1, q)\
- :: "r"(temp), "r"(dst), "m"(ROUNDER)\
- : "memory"\
- );\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_h_lowpass_mmx2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- uint64_t temp;\
-\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm1 \n\t" /* ABCDEFGH */\
- "movq %%mm0, %%mm2 \n\t" /* ABCDEFGH */\
- "punpcklbw %%mm7, %%mm0 \n\t" /* 0A0B0C0D */\
- "punpckhbw %%mm7, %%mm1 \n\t" /* 0E0F0G0H */\
- "pshufw $0x90, %%mm0, %%mm5 \n\t" /* 0A0A0B0C */\
- "pshufw $0x41, %%mm0, %%mm6 \n\t" /* 0B0A0A0B */\
- "movq %%mm2, %%mm3 \n\t" /* ABCDEFGH */\
- "movq %%mm2, %%mm4 \n\t" /* ABCDEFGH */\
- "psllq $8, %%mm2 \n\t" /* 0ABCDEFG */\
- "psllq $16, %%mm3 \n\t" /* 00ABCDEF */\
- "psllq $24, %%mm4 \n\t" /* 000ABCDE */\
- "punpckhbw %%mm7, %%mm2 \n\t" /* 0D0E0F0G */\
- "punpckhbw %%mm7, %%mm3 \n\t" /* 0C0D0E0F */\
- "punpckhbw %%mm7, %%mm4 \n\t" /* 0B0C0D0E */\
- "paddw %%mm3, %%mm5 \n\t" /* b */\
- "paddw %%mm2, %%mm6 \n\t" /* c */\
- "paddw %%mm5, %%mm5 \n\t" /* 2b */\
- "psubw %%mm5, %%mm6 \n\t" /* c - 2b */\
- "pshufw $0x06, %%mm0, %%mm5 \n\t" /* 0C0B0A0A */\
- "pmullw "MANGLE(ff_pw_3)", %%mm6 \n\t" /* 3c - 6b */\
- "paddw %%mm4, %%mm0 \n\t" /* a */\
- "paddw %%mm1, %%mm5 \n\t" /* d */\
- "pmullw "MANGLE(ff_pw_20)", %%mm0 \n\t" /* 20a */\
- "psubw %%mm5, %%mm0 \n\t" /* 20a - d */\
- "paddw %6, %%mm6 \n\t"\
- "paddw %%mm6, %%mm0 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm0 \n\t"\
- /* mm1=EFGH, mm2=DEFG, mm3=CDEF, mm4=BCDE, mm7=0 */\
- \
- "movd 5(%0), %%mm5 \n\t" /* FGHI */\
- "punpcklbw %%mm7, %%mm5 \n\t" /* 0F0G0H0I */\
- "pshufw $0xF9, %%mm5, %%mm6 \n\t" /* 0G0H0I0I */\
- "paddw %%mm5, %%mm1 \n\t" /* a */\
- "paddw %%mm6, %%mm2 \n\t" /* b */\
- "pshufw $0xBE, %%mm5, %%mm6 \n\t" /* 0H0I0I0H */\
- "pshufw $0x6F, %%mm5, %%mm5 \n\t" /* 0I0I0H0G */\
- "paddw %%mm6, %%mm3 \n\t" /* c */\
- "paddw %%mm5, %%mm4 \n\t" /* d */\
- "paddw %%mm2, %%mm2 \n\t" /* 2b */\
- "psubw %%mm2, %%mm3 \n\t" /* c - 2b */\
- "pmullw "MANGLE(ff_pw_20)", %%mm1 \n\t" /* 20a */\
- "pmullw "MANGLE(ff_pw_3)", %%mm3 \n\t" /* 3c - 6b */\
- "psubw %%mm4, %%mm3 \n\t" /* -6b + 3c - d */\
- "paddw %6, %%mm1 \n\t"\
- "paddw %%mm1, %%mm3 \n\t" /* 20a - 6b + 3c - d */\
- "psraw $5, %%mm3 \n\t"\
- "packuswb %%mm3, %%mm0 \n\t"\
- OP_MMX2(%%mm0, (%1), %%mm4, q)\
- \
- "addl %3, %0 \n\t"\
- "addl %4, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+a"(src), "+c"(dst), "+m"(h)\
- : "S"(srcStride), "D"(dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(temp), "m"(ROUNDER)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_h_lowpass_3dnow(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\
- int i;\
- int16_t temp[8];\
- /* quick HACK, XXX FIXME MUST be optimized */\
- for(i=0; i<h; i++)\
- {\
- temp[ 0]= (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]);\
- temp[ 1]= (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]);\
- temp[ 2]= (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]);\
- temp[ 3]= (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]);\
- temp[ 4]= (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]);\
- temp[ 5]= (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 8]);\
- temp[ 6]= (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 8])*3 - (src[ 3]+src[ 7]);\
- temp[ 7]= (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 8])*6 + (src[ 5]+src[ 7])*3 - (src[ 4]+src[ 6]);\
- asm volatile(\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "paddw %2, %%mm0 \n\t"\
- "paddw %2, %%mm1 \n\t"\
- "psraw $5, %%mm0 \n\t"\
- "psraw $5, %%mm1 \n\t"\
- "packuswb %%mm1, %%mm0 \n\t"\
- OP_3DNOW(%%mm0, (%1), %%mm1, q)\
- :: "r"(temp), "r"(dst), "m"(ROUNDER)\
- :"memory"\
- );\
- dst+=dstStride;\
- src+=srcStride;\
- }\
-}
-
-#define QPEL_OP(OPNAME, ROUNDER, RND, OP, MMX)\
-\
-static void OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint64_t temp[17*4];\
- uint64_t *temp_ptr= temp;\
- int count= 17;\
-\
- /*FIXME unroll */\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq (%0), %%mm1 \n\t"\
- "movq 8(%0), %%mm2 \n\t"\
- "movq 8(%0), %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "movq %%mm0, (%1) \n\t"\
- "movq %%mm1, 17*8(%1) \n\t"\
- "movq %%mm2, 2*17*8(%1) \n\t"\
- "movq %%mm3, 3*17*8(%1) \n\t"\
- "addl $8, %1 \n\t"\
- "addl %3, %0 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+r" (src), "+r" (temp_ptr), "+r"(count)\
- : "r" (srcStride)\
- : "memory"\
- );\
- \
- temp_ptr= temp;\
- count=4;\
- \
-/*FIXME reorder for speed */\
- asm volatile(\
- /*"pxor %%mm7, %%mm7 \n\t"*/\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "movq 16(%0), %%mm2 \n\t"\
- "movq 24(%0), %%mm3 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 72(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 80(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 88(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 40(%0), 48(%0), 56(%0), 96(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 48(%0), 56(%0), 64(%0),104(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 56(%0), 64(%0), 72(%0),112(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 64(%0), 72(%0), 80(%0),120(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 72(%0), 80(%0), 88(%0),128(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 80(%0), 88(%0), 96(%0),128(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t" \
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 88(%0), 96(%0),104(%0),120(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 96(%0),104(%0),112(%0),112(%0), (%1, %3), OP)\
- \
- "addl $136, %0 \n\t"\
- "addl %6, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- \
- : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
- : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-14*dstStride)\
- :"memory"\
- );\
-}\
-\
-static void OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
- uint64_t temp[9*4];\
- uint64_t *temp_ptr= temp;\
- int count= 9;\
-\
- /*FIXME unroll */\
- asm volatile(\
- "pxor %%mm7, %%mm7 \n\t"\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq (%0), %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "movq %%mm0, (%1) \n\t"\
- "movq %%mm1, 9*8(%1) \n\t"\
- "addl $8, %1 \n\t"\
- "addl %3, %0 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- : "+r" (src), "+r" (temp_ptr), "+r"(count)\
- : "r" (srcStride)\
- : "memory"\
- );\
- \
- temp_ptr= temp;\
- count=2;\
- \
-/*FIXME reorder for speed */\
- asm volatile(\
- /*"pxor %%mm7, %%mm7 \n\t"*/\
- "1: \n\t"\
- "movq (%0), %%mm0 \n\t"\
- "movq 8(%0), %%mm1 \n\t"\
- "movq 16(%0), %%mm2 \n\t"\
- "movq 24(%0), %%mm3 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 16(%0), 8(%0), (%0), 32(%0), (%1), OP)\
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 8(%0), (%0), (%0), 40(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, (%0), (%0), 8(%0), 48(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, (%0), 8(%0), 16(%0), 56(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm0, %%mm1, %%mm2, %%mm3, %5, %6, %5, 8(%0), 16(%0), 24(%0), 64(%0), (%1), OP)\
- \
- QPEL_V_LOW(%%mm1, %%mm2, %%mm3, %%mm0, %5, %6, %5, 16(%0), 24(%0), 32(%0), 64(%0), (%1, %3), OP)\
- "addl %4, %1 \n\t"\
- QPEL_V_LOW(%%mm2, %%mm3, %%mm0, %%mm1, %5, %6, %5, 24(%0), 32(%0), 40(%0), 56(%0), (%1), OP)\
- QPEL_V_LOW(%%mm3, %%mm0, %%mm1, %%mm2, %5, %6, %5, 32(%0), 40(%0), 48(%0), 48(%0), (%1, %3), OP)\
- \
- "addl $72, %0 \n\t"\
- "addl %6, %1 \n\t"\
- "decl %2 \n\t"\
- " jnz 1b \n\t"\
- \
- : "+r"(temp_ptr), "+r"(dst), "+g"(count)\
- : "r"(dstStride), "r"(2*dstStride), /*"m"(ff_pw_20), "m"(ff_pw_3),*/ "m"(ROUNDER), "g"(4-6*dstStride)\
- : "memory"\
- );\
-}\
-\
-static void OPNAME ## qpel8_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels8_mmx(dst, src, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_h_lowpass_ ## MMX(dst, src, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(half, src, 8, stride, 8);\
- OPNAME ## pixels8_l2_mmx(dst, src+1, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
- OPNAME ## pixels8_l2_mmx(dst, src, half, stride, stride, 8);\
-}\
-\
-static void OPNAME ## qpel8_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## qpel8_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[8];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(half, src, 8, stride);\
- OPNAME ## pixels8_l2_mmx(dst, src+stride, half, stride, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half) + 64;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## mpeg4_qpel8_v_lowpass_ ## MMX(halfHV, halfH, 8, 8);\
- OPNAME ## pixels8_l2_mmx(dst, halfH+8, halfHV, stride, 8, 8);\
-}\
-static void OPNAME ## qpel8_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src, halfH, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[8 + 9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- put ## RND ## pixels8_l2_mmx(halfH, src+1, halfH, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel8_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[9];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel8_h_lowpass_ ## MMX(halfH, src, 8, stride, 9);\
- OPNAME ## mpeg4_qpel8_v_lowpass_ ## MMX(dst, halfH, stride, 8);\
-}\
-static void OPNAME ## qpel16_mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## pixels16_mmx(dst, src, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc20_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_h_lowpass_ ## MMX(dst, src, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(half, src, 16, stride, 16);\
- OPNAME ## pixels16_l2_mmx(dst, src+1, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
- OPNAME ## pixels16_l2_mmx(dst, src, half, stride, stride, 16);\
-}\
-\
-static void OPNAME ## qpel16_mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, src, stride, stride);\
-}\
-\
-static void OPNAME ## qpel16_mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t temp[32];\
- uint8_t * const half= (uint8_t*)temp;\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(half, src, 16, stride);\
- OPNAME ## pixels16_l2_mmx(dst, src+stride, half, stride, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[16*2 + 17*2];\
- uint8_t * const halfH= ((uint8_t*)half) + 256;\
- uint8_t * const halfHV= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## mpeg4_qpel16_v_lowpass_ ## MMX(halfHV, halfH, 16, 16);\
- OPNAME ## pixels16_l2_mmx(dst, halfH+16, halfHV, stride, 16, 16);\
-}\
-static void OPNAME ## qpel16_mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src, halfH, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- put ## RND ## pixels16_l2_mmx(halfH, src+1, halfH, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}\
-static void OPNAME ## qpel16_mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\
- uint64_t half[17*2];\
- uint8_t * const halfH= ((uint8_t*)half);\
- put ## RND ## mpeg4_qpel16_h_lowpass_ ## MMX(halfH, src, 16, stride, 17);\
- OPNAME ## mpeg4_qpel16_v_lowpass_ ## MMX(dst, halfH, stride, 16);\
-}
-
-
-#define PUT_OP(a,b,temp, size) "mov" #size " " #a ", " #b " \n\t"
-#define AVG_3DNOW_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgusb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-#define AVG_MMX2_OP(a,b,temp, size) \
-"mov" #size " " #b ", " #temp " \n\t"\
-"pavgb " #temp ", " #a " \n\t"\
-"mov" #size " " #a ", " #b " \n\t"
-
-QPEL_BASE(put_ , ff_pw_16, _ , PUT_OP, PUT_OP)
-QPEL_BASE(avg_ , ff_pw_16, _ , AVG_MMX2_OP, AVG_3DNOW_OP)
-QPEL_BASE(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, PUT_OP)
-QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, 3dnow)
-QPEL_OP(avg_ , ff_pw_16, _ , AVG_3DNOW_OP, 3dnow)
-QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, 3dnow)
-QPEL_OP(put_ , ff_pw_16, _ , PUT_OP, mmx2)
-QPEL_OP(avg_ , ff_pw_16, _ , AVG_MMX2_OP, mmx2)
-QPEL_OP(put_no_rnd_, ff_pw_15, _no_rnd_, PUT_OP, mmx2)
-
-#if 0
-static void just_return() { return; }
-#endif
-
-#define SET_QPEL_FUNC(postfix1, postfix2) \
- c->put_ ## postfix1 = put_ ## postfix2;\
- c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\
- c->avg_ ## postfix1 = avg_ ## postfix2;
-
-/* external functions, from idct_mmx.c */
-void ff_mmx_idct(DCTELEM *block);
-void ff_mmxext_idct(DCTELEM *block);
-
-/* XXX: those functions should be suppressed ASAP when all IDCTs are
- converted */
-static void ff_libmpeg2mmx_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmx_idct (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmx_idct (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx2_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmxext_idct (block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- ff_mmxext_idct (block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
-
-void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
-{
- mm_flags = mm_support();
-
- if (avctx->dsp_mask) {
- if (avctx->dsp_mask & FF_MM_FORCE)
- mm_flags |= (avctx->dsp_mask & 0xffff);
- else
- mm_flags &= ~(avctx->dsp_mask & 0xffff);
- }
-
-#if 0
- fprintf(stderr, "libavcodec: CPU flags:");
- if (mm_flags & MM_MMX)
- fprintf(stderr, " mmx");
- if (mm_flags & MM_MMXEXT)
- fprintf(stderr, " mmxext");
- if (mm_flags & MM_3DNOW)
- fprintf(stderr, " 3dnow");
- if (mm_flags & MM_SSE)
- fprintf(stderr, " sse");
- if (mm_flags & MM_SSE2)
- fprintf(stderr, " sse2");
- fprintf(stderr, "\n");
-#endif
-
- if (mm_flags & MM_MMX) {
- const int dct_algo = avctx->dct_algo;
- const int idct_algo= avctx->idct_algo;
-
-#ifdef CONFIG_ENCODERS
- if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX)
- c->fdct = ff_fdct_mmx;
-#endif //CONFIG_ENCODERS
-
- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){
- c->idct_put= ff_simple_idct_put_mmx;
- c->idct_add= ff_simple_idct_add_mmx;
- c->idct = ff_simple_idct_mmx;
- c->idct_permutation_type= FF_SIMPLE_IDCT_PERM;
- }else if(idct_algo==FF_IDCT_LIBMPEG2MMX){
- if(mm_flags & MM_MMXEXT){
- c->idct_put= ff_libmpeg2mmx2_idct_put;
- c->idct_add= ff_libmpeg2mmx2_idct_add;
- c->idct = ff_mmxext_idct;
- }else{
- c->idct_put= ff_libmpeg2mmx_idct_put;
- c->idct_add= ff_libmpeg2mmx_idct_add;
- c->idct = ff_mmx_idct;
- }
- c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;
- }
-
- c->get_pixels = get_pixels_mmx;
- c->diff_pixels = diff_pixels_mmx;
- c->put_pixels_clamped = put_pixels_clamped_mmx;
- c->add_pixels_clamped = add_pixels_clamped_mmx;
- c->clear_blocks = clear_blocks_mmx;
- c->pix_sum = pix_sum16_mmx;
-
- c->put_pixels_tab[0][0] = put_pixels16_mmx;
- c->put_pixels_tab[0][1] = put_pixels16_x2_mmx;
- c->put_pixels_tab[0][2] = put_pixels16_y2_mmx;
- c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx;
-
- c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx;
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx;
- c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_mmx;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx;
-
- c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx;
- c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx;
- c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx;
- c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx;
-
- c->put_pixels_tab[1][0] = put_pixels8_mmx;
- c->put_pixels_tab[1][1] = put_pixels8_x2_mmx;
- c->put_pixels_tab[1][2] = put_pixels8_y2_mmx;
- c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx;
-
- c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx;
- c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_mmx;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx;
-
- c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx;
- c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx;
- c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx;
- c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx;
-
- c->add_bytes= add_bytes_mmx;
- c->diff_bytes= diff_bytes_mmx;
-
- c->hadamard8_diff[0]= hadamard8_diff16_mmx;
- c->hadamard8_diff[1]= hadamard8_diff_mmx;
-
- c->pix_norm1 = pix_norm1_mmx;
- c->sse[0] = sse16_mmx;
-
- if (mm_flags & MM_MMXEXT) {
- c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2;
- c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_mmx2;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx2;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx2;
-
- c->put_pixels_tab[1][1] = put_pixels8_x2_mmx2;
- c->put_pixels_tab[1][2] = put_pixels8_y2_mmx2;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_mmx2;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2;
-
- c->hadamard8_diff[0]= hadamard8_diff16_mmx2;
- c->hadamard8_diff[1]= hadamard8_diff_mmx2;
-
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2;
- }
-
-#if 1
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2)
-#endif
- } else if (mm_flags & MM_3DNOW) {
- c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow;
- c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow;
-
- c->avg_pixels_tab[0][0] = avg_pixels16_3dnow;
- c->avg_pixels_tab[0][1] = avg_pixels16_x2_3dnow;
- c->avg_pixels_tab[0][2] = avg_pixels16_y2_3dnow;
-
- c->put_pixels_tab[1][1] = put_pixels8_x2_3dnow;
- c->put_pixels_tab[1][2] = put_pixels8_y2_3dnow;
-
- c->avg_pixels_tab[1][0] = avg_pixels8_3dnow;
- c->avg_pixels_tab[1][1] = avg_pixels8_x2_3dnow;
- c->avg_pixels_tab[1][2] = avg_pixels8_y2_3dnow;
-
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_3dnow;
- c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_3dnow;
- c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_3dnow;
- c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_3dnow;
- c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow;
- c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow;
- }
-
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow)
- SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow)
- }
- }
-
- dsputil_init_pix_mmx(c, avctx);
-#if 0
- // for speed testing
- get_pixels = just_return;
- put_pixels_clamped = just_return;
- add_pixels_clamped = just_return;
-
- pix_abs16x16 = just_return;
- pix_abs16x16_x2 = just_return;
- pix_abs16x16_y2 = just_return;
- pix_abs16x16_xy2 = just_return;
-
- put_pixels_tab[0] = just_return;
- put_pixels_tab[1] = just_return;
- put_pixels_tab[2] = just_return;
- put_pixels_tab[3] = just_return;
-
- put_no_rnd_pixels_tab[0] = just_return;
- put_no_rnd_pixels_tab[1] = just_return;
- put_no_rnd_pixels_tab[2] = just_return;
- put_no_rnd_pixels_tab[3] = just_return;
-
- avg_pixels_tab[0] = just_return;
- avg_pixels_tab[1] = just_return;
- avg_pixels_tab[2] = just_return;
- avg_pixels_tab[3] = just_return;
-
- avg_no_rnd_pixels_tab[0] = just_return;
- avg_no_rnd_pixels_tab[1] = just_return;
- avg_no_rnd_pixels_tab[2] = just_return;
- avg_no_rnd_pixels_tab[3] = just_return;
-
- //av_fdct = just_return;
- //ff_idct = just_return;
-#endif
-}
+++ /dev/null
-/*
- * DSP utils : average functions are compiled twice for 3dnow/mmx2
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- * Copyright (c) 2002 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
- * mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
- * and improved by Zdenek Kabelac <kabi@users.sf.net>
- */
-
-/* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm
- clobber bug - now it will work with 2.95.2 and also with -fPIC
- */
-static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- "addl %%eax, %1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- __asm __volatile(
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "addl %4, %1 \n\t"
- "movq (%1), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- PAVGB" (%2), %%mm0 \n\t"
- PAVGB" 8(%2), %%mm1 \n\t"
- "movq %%mm0, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq %%mm1, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq (%1), %%mm0 \n\t"
- "addl %4, %1 \n\t"
- "movq (%1), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- PAVGB" 16(%2), %%mm0 \n\t"
- PAVGB" 24(%2), %%mm1 \n\t"
- "movq %%mm0, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq %%mm1, (%3) \n\t"
- "addl %5, %3 \n\t"
- "addl $32, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
- :"r"(src1Stride), "r"(dstStride)
- :"memory");
-}
-
-static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1), %%mm2 \n\t"
- "movq 8(%1, %3), %%mm3 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- PAVGB" 9(%1), %%mm2 \n\t"
- PAVGB" 9(%1, %3), %%mm3 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm2, 8(%2) \n\t"
- "movq %%mm3, 8(%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq 8(%1), %%mm2 \n\t"
- "movq 8(%1, %3), %%mm3 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- PAVGB" 9(%1), %%mm2 \n\t"
- PAVGB" 9(%1, %3), %%mm3 \n\t"
- "addl %%eax, %1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq %%mm2, 8(%2) \n\t"
- "movq %%mm3, 8(%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- __asm __volatile(
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- PAVGB" (%2), %%mm0 \n\t"
- PAVGB" 8(%2), %%mm1 \n\t"
- "movq %%mm0, (%3) \n\t"
- "movq %%mm1, 8(%3) \n\t"
- "addl %5, %3 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 8(%1), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- PAVGB" 16(%2), %%mm0 \n\t"
- PAVGB" 24(%2), %%mm1 \n\t"
- "movq %%mm0, (%3) \n\t"
- "movq %%mm1, 8(%3) \n\t"
- "addl %5, %3 \n\t"
- "addl $32, %2 \n\t"
- "subl $2, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+r"(src1), "+r"(src2), "+r"(dst)
- :"r"(src1Stride), "r"(dstStride)
- :"memory");
-}
-
-/* GL: this function does incorrect rounding if overflow */
-static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BONE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- "addl %%eax, %1 \n\t"
- "psubusb %%mm6, %%mm0 \n\t"
- "psubusb %%mm6, %%mm2 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm3, %%mm2 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- "psubusb %%mm6, %%mm0 \n\t"
- "psubusb %%mm6, %%mm2 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm3, %%mm2 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- "subl %3, %2 \n\t"
- "1: \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm2, %%mm1 \n\t"
- "movq %%mm0, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" %%mm1, %%mm2 \n\t"
- PAVGB" %%mm0, %%mm1 \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D" (block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-/* GL: this function does incorrect rounding if overflow */
-static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BONE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- "subl %3, %2 \n\t"
- "1: \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- "addl %%eax, %1 \n\t"
- "psubusb %%mm6, %%mm1 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm2, %%mm1 \n\t"
- "movq %%mm0, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- "psubusb %%mm6, %%mm1 \n\t"
- PAVGB" %%mm1, %%mm2 \n\t"
- PAVGB" %%mm0, %%mm1 \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D" (block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "1: \n\t"
- "movq (%2), %%mm0 \n\t"
- "movq (%2, %3), %%mm1 \n\t"
- PAVGB" (%1), %%mm0 \n\t"
- PAVGB" (%1, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%2), %%mm0 \n\t"
- "movq (%2, %3), %%mm1 \n\t"
- PAVGB" (%1), %%mm0 \n\t"
- PAVGB" (%1, %3), %%mm1 \n\t"
- "addl %%eax, %1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm2 \n\t"
- PAVGB" (%2), %%mm0 \n\t"
- PAVGB" (%2, %3), %%mm2 \n\t"
- "addl %%eax, %1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm2 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" (%2), %%mm0 \n\t"
- PAVGB" (%2, %3), %%mm2 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- "subl %3, %2 \n\t"
- "1: \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm2, %%mm1 \n\t"
- "movq (%2, %3), %%mm3 \n\t"
- "movq (%2, %%eax), %%mm4 \n\t"
- PAVGB" %%mm3, %%mm0 \n\t"
- PAVGB" %%mm4, %%mm1 \n\t"
- "movq %%mm0, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- PAVGB" %%mm1, %%mm2 \n\t"
- PAVGB" %%mm0, %%mm1 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- "movq (%2, %3), %%mm3 \n\t"
- "movq (%2, %%eax), %%mm4 \n\t"
- PAVGB" %%mm3, %%mm2 \n\t"
- PAVGB" %%mm4, %%mm1 \n\t"
- "movq %%mm2, (%2, %3) \n\t"
- "movq %%mm1, (%2, %%eax) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-// Note this is not correctly rounded, but this function is only used for b frames so it doesnt matter
-static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BONE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- PAVGB" 1(%1), %%mm0 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "psubusb %%mm6, %%mm2 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- PAVGB" 1(%1, %%eax), %%mm2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" %%mm1, %%mm0 \n\t"
- PAVGB" %%mm2, %%mm1 \n\t"
- PAVGB" (%2), %%mm0 \n\t"
- PAVGB" (%2, %3), %%mm1 \n\t"
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- PAVGB" 1(%1, %3), %%mm1 \n\t"
- PAVGB" 1(%1, %%eax), %%mm0 \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- PAVGB" %%mm1, %%mm2 \n\t"
- PAVGB" %%mm0, %%mm1 \n\t"
- PAVGB" (%2), %%mm2 \n\t"
- PAVGB" (%2, %3), %%mm1 \n\t"
- "movq %%mm2, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r" (line_size)
- :"%eax", "memory");
-}
-
-//FIXME the following could be optimized too ...
-static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(put_no_rnd_pixels8_x2)(block , pixels , line_size, h);
- DEF(put_no_rnd_pixels8_x2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(put_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(put_pixels8_y2)(block , pixels , line_size, h);
- DEF(put_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(put_no_rnd_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(put_no_rnd_pixels8_y2)(block , pixels , line_size, h);
- DEF(put_no_rnd_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg_pixels8)(block , pixels , line_size, h);
- DEF(avg_pixels8)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg_pixels8_x2)(block , pixels , line_size, h);
- DEF(avg_pixels8_x2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg_pixels8_y2)(block , pixels , line_size, h);
- DEF(avg_pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-static void DEF(avg_pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg_pixels8_xy2)(block , pixels , line_size, h);
- DEF(avg_pixels8_xy2)(block+8, pixels+8, line_size, h);
-}
-
+++ /dev/null
-/*
- * DSP utils mmx functions are compiled twice for rnd/no_rnd
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
- * mostly rewritten by Michael Niedermayer <michaelni@gmx.at>
- * and improved by Zdenek Kabelac <kabi@users.sf.net>
- */
-
-// put_pixels
-static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r"(line_size)
- :"eax", "memory");
-}
-
-static void DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "testl $1, %0 \n\t"
- " jz 1f \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%2), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- "addl $8, %2 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm4, %%mm6)
- "movq %%mm4, (%3) \n\t"
- "addl %5, %3 \n\t"
- "decl %0 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%2), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- "movq (%1), %%mm2 \n\t"
- "movq 8(%2), %%mm3 \n\t"
- "addl %4, %1 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq %%mm5, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 16(%2), %%mm1 \n\t"
- "addl %4, %1 \n\t"
- "movq (%1), %%mm2 \n\t"
- "movq 24(%2), %%mm3 \n\t"
- "addl %4, %1 \n\t"
- "addl $32, %2 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%3) \n\t"
- "addl %5, %3 \n\t"
- "movq %%mm5, (%3) \n\t"
- "addl %5, %3 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
-#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
- :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
- :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
- :"S"(src1Stride), "D"(dstStride)
- :"memory");
-}
-
-static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "movq 8(%1), %%mm0 \n\t"
- "movq 9(%1), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm2 \n\t"
- "movq 9(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm1 \n\t"
- "movq (%1, %3), %%mm2 \n\t"
- "movq 1(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "movq 8(%1), %%mm0 \n\t"
- "movq 9(%1), %%mm1 \n\t"
- "movq 8(%1, %3), %%mm2 \n\t"
- "movq 9(%1, %3), %%mm3 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, 8(%2) \n\t"
- "movq %%mm5, 8(%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r"(line_size)
- :"eax", "memory");
-}
-
-static void DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "testl $1, %0 \n\t"
- " jz 1f \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%2), %%mm1 \n\t"
- "movq 8(%1), %%mm2 \n\t"
- "movq 8(%2), %%mm3 \n\t"
- "addl %4, %1 \n\t"
- "addl $16, %2 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%3) \n\t"
- "movq %%mm5, 8(%3) \n\t"
- "addl %5, %3 \n\t"
- "decl %0 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq (%2), %%mm1 \n\t"
- "movq 8(%1), %%mm2 \n\t"
- "movq 8(%2), %%mm3 \n\t"
- "addl %4, %1 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%3) \n\t"
- "movq %%mm5, 8(%3) \n\t"
- "addl %5, %3 \n\t"
- "movq (%1), %%mm0 \n\t"
- "movq 16(%2), %%mm1 \n\t"
- "movq 8(%1), %%mm2 \n\t"
- "movq 24(%2), %%mm3 \n\t"
- "addl %4, %1 \n\t"
- PAVGBP(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
- "movq %%mm4, (%3) \n\t"
- "movq %%mm5, 8(%3) \n\t"
- "addl %5, %3 \n\t"
- "addl $32, %2 \n\t"
- "subl $2, %0 \n\t"
- "jnz 1b \n\t"
-#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used
- :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#else
- :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst)
-#endif
- :"S"(src1Stride), "D"(dstStride)
- :"memory");
-}
-
-static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax),%%mm2 \n\t"
- PAVGBP(%%mm1, %%mm0, %%mm4, %%mm2, %%mm1, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax),%%mm0 \n\t"
- PAVGBP(%%mm1, %%mm2, %%mm4, %%mm0, %%mm1, %%mm5)
- "movq %%mm4, (%2) \n\t"
- "movq %%mm5, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r"(line_size)
- :"eax", "memory");
-}
-
-static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_ZERO(mm7);
- SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
- __asm __volatile(
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm4 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddusw %%mm0, %%mm4 \n\t"
- "paddusw %%mm1, %%mm5 \n\t"
- "xorl %%eax, %%eax \n\t"
- "addl %3, %1 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq 1(%1, %%eax), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddusw %%mm2, %%mm0 \n\t"
- "paddusw %%mm3, %%mm1 \n\t"
- "paddusw %%mm6, %%mm4 \n\t"
- "paddusw %%mm6, %%mm5 \n\t"
- "paddusw %%mm0, %%mm4 \n\t"
- "paddusw %%mm1, %%mm5 \n\t"
- "psrlw $2, %%mm4 \n\t"
- "psrlw $2, %%mm5 \n\t"
- "packuswb %%mm5, %%mm4 \n\t"
- "movq %%mm4, (%2, %%eax) \n\t"
- "addl %3, %%eax \n\t"
-
- "movq (%1, %%eax), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
- "movq 1(%1, %%eax), %%mm4 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddusw %%mm2, %%mm4 \n\t"
- "paddusw %%mm3, %%mm5 \n\t"
- "paddusw %%mm6, %%mm0 \n\t"
- "paddusw %%mm6, %%mm1 \n\t"
- "paddusw %%mm4, %%mm0 \n\t"
- "paddusw %%mm5, %%mm1 \n\t"
- "psrlw $2, %%mm0 \n\t"
- "psrlw $2, %%mm1 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "movq %%mm0, (%2, %%eax) \n\t"
- "addl %3, %%eax \n\t"
-
- "subl $2, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels)
- :"D"(block), "r"(line_size)
- :"eax", "memory");
-}
-
-// avg_pixels
-// in case more speed is needed - unroling would certainly help
-static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %0, %%mm0 \n\t"
- "movq %1, %%mm1 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- "movq %%mm2, %0 \n\t"
- :"+m"(*block)
- :"m"(*pixels)
- :"memory");
- pixels += line_size;
- block += line_size;
- }
- while (--h);
-}
-
-static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %0, %%mm0 \n\t"
- "movq %1, %%mm1 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- "movq %%mm2, %0 \n\t"
- "movq 8%0, %%mm0 \n\t"
- "movq 8%1, %%mm1 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- "movq %%mm2, 8%0 \n\t"
- :"+m"(*block)
- :"m"(*pixels)
- :"memory");
- pixels += line_size;
- block += line_size;
- }
- while (--h);
-}
-
-static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %1, %%mm0 \n\t"
- "movq 1%1, %%mm1 \n\t"
- "movq %0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, %0 \n\t"
- :"+m"(*block)
- :"m"(*pixels)
- :"memory");
- pixels += line_size;
- block += line_size;
- } while (--h);
-}
-
-static void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %1, %%mm0 \n\t"
- "movq %2, %%mm1 \n\t"
- "movq %0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, %0 \n\t"
- :"+m"(*dst)
- :"m"(*src1), "m"(*src2)
- :"memory");
- dst += dstStride;
- src1 += src1Stride;
- src2 += 8;
- } while (--h);
-}
-
-static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %1, %%mm0 \n\t"
- "movq 1%1, %%mm1 \n\t"
- "movq %0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, %0 \n\t"
- "movq 8%1, %%mm0 \n\t"
- "movq 9%1, %%mm1 \n\t"
- "movq 8%0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, 8%0 \n\t"
- :"+m"(*block)
- :"m"(*pixels)
- :"memory");
- pixels += line_size;
- block += line_size;
- } while (--h);
-}
-
-static void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h)
-{
- MOVQ_BFE(mm6);
- JUMPALIGN();
- do {
- __asm __volatile(
- "movq %1, %%mm0 \n\t"
- "movq %2, %%mm1 \n\t"
- "movq %0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, %0 \n\t"
- "movq 8%1, %%mm0 \n\t"
- "movq 8%2, %%mm1 \n\t"
- "movq 8%0, %%mm3 \n\t"
- PAVGB(%%mm0, %%mm1, %%mm2, %%mm6)
- PAVGB(%%mm3, %%mm2, %%mm0, %%mm6)
- "movq %%mm0, 8%0 \n\t"
- :"+m"(*dst)
- :"m"(*src1), "m"(*src2)
- :"memory");
- dst += dstStride;
- src1 += src1Stride;
- src2 += 16;
- } while (--h);
-}
-
-static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_BFE(mm6);
- __asm __volatile(
- "lea (%3, %3), %%eax \n\t"
- "movq (%1), %%mm0 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- PAVGBP(%%mm1, %%mm0, %%mm4, %%mm2, %%mm1, %%mm5)
- "movq (%2), %%mm3 \n\t"
- PAVGB(%%mm3, %%mm4, %%mm0, %%mm6)
- "movq (%2, %3), %%mm3 \n\t"
- PAVGB(%%mm3, %%mm5, %%mm1, %%mm6)
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
-
- "movq (%1, %3), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- PAVGBP(%%mm1, %%mm2, %%mm4, %%mm0, %%mm1, %%mm5)
- "movq (%2), %%mm3 \n\t"
- PAVGB(%%mm3, %%mm4, %%mm2, %%mm6)
- "movq (%2, %3), %%mm3 \n\t"
- PAVGB(%%mm3, %%mm5, %%mm1, %%mm6)
- "movq %%mm2, (%2) \n\t"
- "movq %%mm1, (%2, %3) \n\t"
- "addl %%eax, %1 \n\t"
- "addl %%eax, %2 \n\t"
-
- "subl $4, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels), "+D"(block)
- :"r"(line_size)
- :"eax", "memory");
-}
-
-// this routine is 'slightly' suboptimal but mostly unused
-static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
-{
- MOVQ_ZERO(mm7);
- SET_RND(mm6); // =2 for rnd and =1 for no_rnd version
- __asm __volatile(
- "movq (%1), %%mm0 \n\t"
- "movq 1(%1), %%mm4 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddusw %%mm0, %%mm4 \n\t"
- "paddusw %%mm1, %%mm5 \n\t"
- "xorl %%eax, %%eax \n\t"
- "addl %3, %1 \n\t"
- ".balign 8 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq 1(%1, %%eax), %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddusw %%mm2, %%mm0 \n\t"
- "paddusw %%mm3, %%mm1 \n\t"
- "paddusw %%mm6, %%mm4 \n\t"
- "paddusw %%mm6, %%mm5 \n\t"
- "paddusw %%mm0, %%mm4 \n\t"
- "paddusw %%mm1, %%mm5 \n\t"
- "psrlw $2, %%mm4 \n\t"
- "psrlw $2, %%mm5 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "packuswb %%mm5, %%mm4 \n\t"
- "pcmpeqd %%mm2, %%mm2 \n\t"
- "paddb %%mm2, %%mm2 \n\t"
- PAVGB(%%mm3, %%mm4, %%mm5, %%mm2)
- "movq %%mm5, (%2, %%eax) \n\t"
- "addl %3, %%eax \n\t"
-
- "movq (%1, %%eax), %%mm2 \n\t" // 0 <-> 2 1 <-> 3
- "movq 1(%1, %%eax), %%mm4 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "punpckhbw %%mm7, %%mm5 \n\t"
- "paddusw %%mm2, %%mm4 \n\t"
- "paddusw %%mm3, %%mm5 \n\t"
- "paddusw %%mm6, %%mm0 \n\t"
- "paddusw %%mm6, %%mm1 \n\t"
- "paddusw %%mm4, %%mm0 \n\t"
- "paddusw %%mm5, %%mm1 \n\t"
- "psrlw $2, %%mm0 \n\t"
- "psrlw $2, %%mm1 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "packuswb %%mm1, %%mm0 \n\t"
- "pcmpeqd %%mm2, %%mm2 \n\t"
- "paddb %%mm2, %%mm2 \n\t"
- PAVGB(%%mm3, %%mm0, %%mm1, %%mm2)
- "movq %%mm1, (%2, %%eax) \n\t"
- "addl %3, %%eax \n\t"
-
- "subl $2, %0 \n\t"
- "jnz 1b \n\t"
- :"+g"(h), "+S"(pixels)
- :"D"(block), "r"(line_size)
- :"eax", "memory");
-}
-
-//FIXME optimize
-static void DEF(put, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(put, pixels8_y2)(block , pixels , line_size, h);
- DEF(put, pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-
-static void DEF(put, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(put, pixels8_xy2)(block , pixels , line_size, h);
- DEF(put, pixels8_xy2)(block+8, pixels+8, line_size, h);
-}
-
-static void DEF(avg, pixels16_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg, pixels8_y2)(block , pixels , line_size, h);
- DEF(avg, pixels8_y2)(block+8, pixels+8, line_size, h);
-}
-
-static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){
- DEF(avg, pixels8_xy2)(block , pixels , line_size, h);
- DEF(avg, pixels8_xy2)(block+8, pixels+8, line_size, h);
-}
-
-
+++ /dev/null
-/*
- * MMX optimized forward DCT
- * The gcc porting is Copyright (c) 2001 Fabrice Bellard.
- *
- * from fdctam32.c - AP922 MMX(3D-Now) forward-DCT
- *
- * Intel Application Note AP-922 - fast, precise implementation of DCT
- * http://developer.intel.com/vtune/cbts/appnotes.htm
- */
-#include "../common.h"
-#include "mmx.h"
-
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
-
-//////////////////////////////////////////////////////////////////////
-//
-// constants for the forward DCT
-// -----------------------------
-//
-// Be sure to check that your compiler is aligning all constants to QWORD
-// (8-byte) memory boundaries! Otherwise the unaligned memory access will
-// severely stall MMX execution.
-//
-//////////////////////////////////////////////////////////////////////
-
-#define BITS_FRW_ACC 3 //; 2 or 3 for accuracy
-#define SHIFT_FRW_COL BITS_FRW_ACC
-#define SHIFT_FRW_ROW (BITS_FRW_ACC + 17 - 3)
-//#define RND_FRW_ROW (262144 * (BITS_FRW_ACC - 1)) //; 1 << (SHIFT_FRW_ROW-1)
-#define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
-//#define RND_FRW_COL (2 * (BITS_FRW_ACC - 1)) //; 1 << (SHIFT_FRW_COL-1)
-#define RND_FRW_COL (1 << (SHIFT_FRW_COL-1))
-
-//concatenated table, for forward DCT transformation
-static const int16_t fdct_tg_all_16[] ATTR_ALIGN(8) = {
- 13036, 13036, 13036, 13036, // tg * (2<<16) + 0.5
- 27146, 27146, 27146, 27146, // tg * (2<<16) + 0.5
- -21746, -21746, -21746, -21746, // tg * (2<<16) + 0.5
-};
-static const int16_t cos_4_16[4] ATTR_ALIGN(8) = {
- -19195, -19195, -19195, -19195, //cos * (2<<16) + 0.5
-};
-
-static const int16_t ocos_4_16[4] ATTR_ALIGN(8) = {
- 23170, 23170, 23170, 23170, //cos * (2<<15) + 0.5
-};
-
-static const long long fdct_one_corr ATTR_ALIGN(8) = 0x0001000100010001LL;
-static const long fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW };
-
-static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = { // forward_dct coeff table
- //row0
- 16384, 16384, 21407, -8867, // w09 w01 w08 w00
- 16384, 16384, 8867, -21407, // w13 w05 w12 w04
- 16384, -16384, 8867, 21407, // w11 w03 w10 w02
- -16384, 16384, -21407, -8867, // w15 w07 w14 w06
- 22725, 12873, 19266, -22725, // w22 w20 w18 w16
- 19266, 4520, -4520, -12873, // w23 w21 w19 w17
- 12873, 4520, 4520, 19266, // w30 w28 w26 w24
- -22725, 19266, -12873, -22725, // w31 w29 w27 w25
-
- //row1
- 22725, 22725, 29692, -12299, // w09 w01 w08 w00
- 22725, 22725, 12299, -29692, // w13 w05 w12 w04
- 22725, -22725, 12299, 29692, // w11 w03 w10 w02
- -22725, 22725, -29692, -12299, // w15 w07 w14 w06
- 31521, 17855, 26722, -31521, // w22 w20 w18 w16
- 26722, 6270, -6270, -17855, // w23 w21 w19 w17
- 17855, 6270, 6270, 26722, // w30 w28 w26 w24
- -31521, 26722, -17855, -31521, // w31 w29 w27 w25
-
- //row2
- 21407, 21407, 27969, -11585, // w09 w01 w08 w00
- 21407, 21407, 11585, -27969, // w13 w05 w12 w04
- 21407, -21407, 11585, 27969, // w11 w03 w10 w02
- -21407, 21407, -27969, -11585, // w15 w07 w14 w06
- 29692, 16819, 25172, -29692, // w22 w20 w18 w16
- 25172, 5906, -5906, -16819, // w23 w21 w19 w17
- 16819, 5906, 5906, 25172, // w30 w28 w26 w24
- -29692, 25172, -16819, -29692, // w31 w29 w27 w25
-
- //row3
- 19266, 19266, 25172, -10426, // w09 w01 w08 w00
- 19266, 19266, 10426, -25172, // w13 w05 w12 w04
- 19266, -19266, 10426, 25172, // w11 w03 w10 w02
- -19266, 19266, -25172, -10426, // w15 w07 w14 w06,
- 26722, 15137, 22654, -26722, // w22 w20 w18 w16
- 22654, 5315, -5315, -15137, // w23 w21 w19 w17
- 15137, 5315, 5315, 22654, // w30 w28 w26 w24
- -26722, 22654, -15137, -26722, // w31 w29 w27 w25,
-
- //row4
- 16384, 16384, 21407, -8867, // w09 w01 w08 w00
- 16384, 16384, 8867, -21407, // w13 w05 w12 w04
- 16384, -16384, 8867, 21407, // w11 w03 w10 w02
- -16384, 16384, -21407, -8867, // w15 w07 w14 w06
- 22725, 12873, 19266, -22725, // w22 w20 w18 w16
- 19266, 4520, -4520, -12873, // w23 w21 w19 w17
- 12873, 4520, 4520, 19266, // w30 w28 w26 w24
- -22725, 19266, -12873, -22725, // w31 w29 w27 w25
-
- //row5
- 19266, 19266, 25172, -10426, // w09 w01 w08 w00
- 19266, 19266, 10426, -25172, // w13 w05 w12 w04
- 19266, -19266, 10426, 25172, // w11 w03 w10 w02
- -19266, 19266, -25172, -10426, // w15 w07 w14 w06
- 26722, 15137, 22654, -26722, // w22 w20 w18 w16
- 22654, 5315, -5315, -15137, // w23 w21 w19 w17
- 15137, 5315, 5315, 22654, // w30 w28 w26 w24
- -26722, 22654, -15137, -26722, // w31 w29 w27 w25
-
- //row6
- 21407, 21407, 27969, -11585, // w09 w01 w08 w00
- 21407, 21407, 11585, -27969, // w13 w05 w12 w04
- 21407, -21407, 11585, 27969, // w11 w03 w10 w02
- -21407, 21407, -27969, -11585, // w15 w07 w14 w06,
- 29692, 16819, 25172, -29692, // w22 w20 w18 w16
- 25172, 5906, -5906, -16819, // w23 w21 w19 w17
- 16819, 5906, 5906, 25172, // w30 w28 w26 w24
- -29692, 25172, -16819, -29692, // w31 w29 w27 w25,
-
- //row7
- 22725, 22725, 29692, -12299, // w09 w01 w08 w00
- 22725, 22725, 12299, -29692, // w13 w05 w12 w04
- 22725, -22725, 12299, 29692, // w11 w03 w10 w02
- -22725, 22725, -29692, -12299, // w15 w07 w14 w06,
- 31521, 17855, 26722, -31521, // w22 w20 w18 w16
- 26722, 6270, -6270, -17855, // w23 w21 w19 w17
- 17855, 6270, 6270, 26722, // w30 w28 w26 w24
- -31521, 26722, -17855, -31521 // w31 w29 w27 w25
-};
-
-
-static inline void fdct_col(const int16_t *in, int16_t *out, int offset)
-{
- movq_m2r(*(in + offset + 1 * 8), mm0);
- movq_m2r(*(in + offset + 6 * 8), mm1);
- movq_r2r(mm0, mm2);
- movq_m2r(*(in + offset + 2 * 8), mm3);
- paddsw_r2r(mm1, mm0);
- movq_m2r(*(in + offset + 5 * 8), mm4);
- psllw_i2r(SHIFT_FRW_COL, mm0);
- movq_m2r(*(in + offset + 0 * 8), mm5);
- paddsw_r2r(mm3, mm4);
- paddsw_m2r(*(in + offset + 7 * 8), mm5);
- psllw_i2r(SHIFT_FRW_COL, mm4);
- movq_r2r(mm0, mm6);
- psubsw_r2r(mm1, mm2);
- movq_m2r(*(fdct_tg_all_16 + 4), mm1);
- psubsw_r2r(mm4, mm0);
- movq_m2r(*(in + offset + 3 * 8), mm7);
- pmulhw_r2r(mm0, mm1);
- paddsw_m2r(*(in + offset + 4 * 8), mm7);
- psllw_i2r(SHIFT_FRW_COL, mm5);
- paddsw_r2r(mm4, mm6);
- psllw_i2r(SHIFT_FRW_COL, mm7);
- movq_r2r(mm5, mm4);
- psubsw_r2r(mm7, mm5);
- paddsw_r2r(mm5, mm1);
- paddsw_r2r(mm7, mm4);
- por_m2r(fdct_one_corr, mm1);
- psllw_i2r(SHIFT_FRW_COL + 1, mm2);
- pmulhw_m2r(*(fdct_tg_all_16 + 4), mm5);
- movq_r2r(mm4, mm7);
- psubsw_m2r(*(in + offset + 5 * 8), mm3);
- psubsw_r2r(mm6, mm4);
- movq_r2m(mm1, *(out + offset + 2 * 8));
- paddsw_r2r(mm6, mm7);
- movq_m2r(*(in + offset + 3 * 8), mm1);
- psllw_i2r(SHIFT_FRW_COL + 1, mm3);
- psubsw_m2r(*(in + offset + 4 * 8), mm1);
- movq_r2r(mm2, mm6);
- movq_r2m(mm4, *(out + offset + 4 * 8));
- paddsw_r2r(mm3, mm2);
- pmulhw_m2r(*ocos_4_16, mm2);
- psubsw_r2r(mm3, mm6);
- pmulhw_m2r(*ocos_4_16, mm6);
- psubsw_r2r(mm0, mm5);
- por_m2r(fdct_one_corr, mm5);
- psllw_i2r(SHIFT_FRW_COL, mm1);
- por_m2r(fdct_one_corr, mm2);
- movq_r2r(mm1, mm4);
- movq_m2r(*(in + offset + 0 * 8), mm3);
- paddsw_r2r(mm6, mm1);
- psubsw_m2r(*(in + offset + 7 * 8), mm3);
- psubsw_r2r(mm6, mm4);
- movq_m2r(*(fdct_tg_all_16 + 0), mm0);
- psllw_i2r(SHIFT_FRW_COL, mm3);
- movq_m2r(*(fdct_tg_all_16 + 8), mm6);
- pmulhw_r2r(mm1, mm0);
- movq_r2m(mm7, *(out + offset + 0 * 8));
- pmulhw_r2r(mm4, mm6);
- movq_r2m(mm5, *(out + offset + 6 * 8));
- movq_r2r(mm3, mm7);
- movq_m2r(*(fdct_tg_all_16 + 8), mm5);
- psubsw_r2r(mm2, mm7);
- paddsw_r2r(mm2, mm3);
- pmulhw_r2r(mm7, mm5);
- paddsw_r2r(mm3, mm0);
- paddsw_r2r(mm4, mm6);
- pmulhw_m2r(*(fdct_tg_all_16 + 0), mm3);
- por_m2r(fdct_one_corr, mm0);
- paddsw_r2r(mm7, mm5);
- psubsw_r2r(mm6, mm7);
- movq_r2m(mm0, *(out + offset + 1 * 8));
- paddsw_r2r(mm4, mm5);
- movq_r2m(mm7, *(out + offset + 3 * 8));
- psubsw_r2r(mm1, mm3);
- movq_r2m(mm5, *(out + offset + 5 * 8));
- movq_r2m(mm3, *(out + offset + 7 * 8));
-}
-
-static inline void fdct_row(const int16_t *in, int16_t *out, const int16_t *table)
-{
- movd_m2r(*(in + 6), mm5);
- punpcklwd_m2r(*(in + 4), mm5);
- movq_r2r(mm5, mm2);
- psrlq_i2r(0x20, mm5);
- movq_m2r(*(in + 0), mm0);
- punpcklwd_r2r(mm2, mm5);
- movq_r2r(mm0, mm1);
- paddsw_r2r(mm5, mm0);
- psubsw_r2r(mm5, mm1);
- movq_r2r(mm0, mm2);
- punpcklwd_r2r(mm1, mm0);
- punpckhwd_r2r(mm1, mm2);
- movq_r2r(mm2, mm1);
- movq_r2r(mm0, mm2);
- movq_m2r(*(table + 0), mm3);
- punpcklwd_r2r(mm1, mm0);
- movq_r2r(mm0, mm5);
- punpckldq_r2r(mm0, mm0);
- movq_m2r(*(table + 4), mm4);
- punpckhwd_r2r(mm1, mm2);
- pmaddwd_r2r(mm0, mm3);
- movq_r2r(mm2, mm6);
- movq_m2r(*(table + 16), mm1);
- punpckldq_r2r(mm2, mm2);
- pmaddwd_r2r(mm2, mm4);
- punpckhdq_r2r(mm5, mm5);
- pmaddwd_m2r(*(table + 8), mm0);
- punpckhdq_r2r(mm6, mm6);
- movq_m2r(*(table + 20), mm7);
- pmaddwd_r2r(mm5, mm1);
- paddd_m2r(*fdct_r_row, mm3);
- pmaddwd_r2r(mm6, mm7);
- pmaddwd_m2r(*(table + 12), mm2);
- paddd_r2r(mm4, mm3);
- pmaddwd_m2r(*(table + 24), mm5);
- pmaddwd_m2r(*(table + 28), mm6);
- paddd_r2r(mm7, mm1);
- paddd_m2r(*fdct_r_row, mm0);
- psrad_i2r(SHIFT_FRW_ROW, mm3);
- paddd_m2r(*fdct_r_row, mm1);
- paddd_r2r(mm2, mm0);
- paddd_m2r(*fdct_r_row, mm5);
- psrad_i2r(SHIFT_FRW_ROW, mm1);
- paddd_r2r(mm6, mm5);
- psrad_i2r(SHIFT_FRW_ROW, mm0);
- psrad_i2r(SHIFT_FRW_ROW, mm5);
- packssdw_r2r(mm0, mm3);
- packssdw_r2r(mm5, mm1);
- movq_r2r(mm3, mm6);
- punpcklwd_r2r(mm1, mm3);
- punpckhwd_r2r(mm1, mm6);
- movq_r2m(mm3, *(out + 0));
- movq_r2m(mm6, *(out + 4));
-}
-
-void ff_fdct_mmx(int16_t *block)
-{
- int64_t align_tmp[16] ATTR_ALIGN(8);
- int16_t * const block_tmp= (int16_t*)align_tmp;
- int16_t *block1, *out;
- const int16_t *table;
- int i;
-
- block1 = block_tmp;
- fdct_col(block, block1, 0);
- fdct_col(block, block1, 4);
-
- block1 = block_tmp;
- table = tab_frw_01234567;
- out = block;
- for(i=8;i>0;i--) {
- fdct_row(block1, out, table);
- block1 += 8;
- table += 32;
- out += 8;
- }
-}
+++ /dev/null
-/*
- * FFT/MDCT transform with SSE optimizations
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "../dsputil.h"
-#include <math.h>
-
-#ifdef HAVE_BUILTIN_VECTOR
-
-#include <xmmintrin.h>
-
-static const float p1p1p1m1[4] __attribute__((aligned(16))) =
- { 1.0, 1.0, 1.0, -1.0 };
-
-static const float p1p1m1p1[4] __attribute__((aligned(16))) =
- { 1.0, 1.0, -1.0, 1.0 };
-
-static const float p1p1m1m1[4] __attribute__((aligned(16))) =
- { 1.0, 1.0, -1.0, -1.0 };
-
-#if 0
-static void print_v4sf(const char *str, __m128 a)
-{
- float *p = (float *)&a;
- printf("%s: %f %f %f %f\n",
- str, p[0], p[1], p[2], p[3]);
-}
-#endif
-
-/* XXX: handle reverse case */
-void fft_calc_sse(FFTContext *s, FFTComplex *z)
-{
- int ln = s->nbits;
- int j, np, np2;
- int nblocks, nloops;
- register FFTComplex *p, *q;
- FFTComplex *cptr, *cptr1;
- int k;
-
- np = 1 << ln;
-
- {
- __m128 *r, a, b, a1, c1, c2;
-
- r = (__m128 *)&z[0];
- c1 = *(__m128 *)p1p1m1m1;
- c2 = *(__m128 *)p1p1p1m1;
- if (s->inverse)
- c2 = *(__m128 *)p1p1m1p1;
- else
- c2 = *(__m128 *)p1p1p1m1;
-
- j = (np >> 2);
- do {
- a = r[0];
- b = _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2));
- a = _mm_mul_ps(a, c1);
- /* do the pass 0 butterfly */
- a = _mm_add_ps(a, b);
-
- a1 = r[1];
- b = _mm_shuffle_ps(a1, a1, _MM_SHUFFLE(1, 0, 3, 2));
- a1 = _mm_mul_ps(a1, c1);
- /* do the pass 0 butterfly */
- b = _mm_add_ps(a1, b);
-
- /* multiply third by -i */
- b = _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 3, 1, 0));
- b = _mm_mul_ps(b, c2);
-
- /* do the pass 1 butterfly */
- r[0] = _mm_add_ps(a, b);
- r[1] = _mm_sub_ps(a, b);
- r += 2;
- } while (--j != 0);
- }
- /* pass 2 .. ln-1 */
-
- nblocks = np >> 3;
- nloops = 1 << 2;
- np2 = np >> 1;
-
- cptr1 = s->exptab1;
- do {
- p = z;
- q = z + nloops;
- j = nblocks;
- do {
- cptr = cptr1;
- k = nloops >> 1;
- do {
- __m128 a, b, c, t1, t2;
-
- a = *(__m128 *)p;
- b = *(__m128 *)q;
-
- /* complex mul */
- c = *(__m128 *)cptr;
- /* cre*re cim*re */
- t1 = _mm_mul_ps(c,
- _mm_shuffle_ps(b, b, _MM_SHUFFLE(2, 2, 0, 0)));
- c = *(__m128 *)(cptr + 2);
- /* -cim*im cre*im */
- t2 = _mm_mul_ps(c,
- _mm_shuffle_ps(b, b, _MM_SHUFFLE(3, 3, 1, 1)));
- b = _mm_add_ps(t1, t2);
-
- /* butterfly */
- *(__m128 *)p = _mm_add_ps(a, b);
- *(__m128 *)q = _mm_sub_ps(a, b);
-
- p += 2;
- q += 2;
- cptr += 4;
- } while (--k);
-
- p += nloops;
- q += nloops;
- } while (--j);
- cptr1 += nloops * 2;
- nblocks = nblocks >> 1;
- nloops = nloops << 1;
- } while (nblocks != 0);
-}
-
-#endif
+++ /dev/null
-/*
- * Note: For libavcodec, this code can also be used under the LGPL license
- */
-/*
- * idct_mmx.c
- * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
- *
- * mpeg2dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * mpeg2dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "../common.h"
-
-#include "mmx.h"
-
-#define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
-
-#define ROW_SHIFT 11
-#define COL_SHIFT 6
-
-#define round(bias) ((int)(((bias)+0.5) * (1<<ROW_SHIFT)))
-#define rounder(bias) {round (bias), round (bias)}
-
-#if 0
-/* C row IDCT - its just here to document the MMXEXT and MMX versions */
-static inline void idct_row (int16_t * row, int offset,
- int16_t * table, int32_t * rounder)
-{
- int C1, C2, C3, C4, C5, C6, C7;
- int a0, a1, a2, a3, b0, b1, b2, b3;
-
- row += offset;
-
- C1 = table[1];
- C2 = table[2];
- C3 = table[3];
- C4 = table[4];
- C5 = table[5];
- C6 = table[6];
- C7 = table[7];
-
- a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + *rounder;
- a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + *rounder;
- a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + *rounder;
- a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + *rounder;
-
- b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
- b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
- b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
- b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
-}
-#endif
-
-
-/* MMXEXT row IDCT */
-
-#define mmxext_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, -c4, -c2, \
- c4, c6, c4, c6, \
- c1, c3, -c1, -c5, \
- c5, c7, c3, -c7, \
- c4, -c6, c4, -c6, \
- -c4, c2, c4, -c2, \
- c5, -c1, c3, -c1, \
- c7, c3, c7, -c5 }
-
-static inline void mmxext_row_head (int16_t * row, int offset, int16_t * table)
-{
- movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
-
- movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
- movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
-
- movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4
- movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
-
- movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4
- pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
-
- pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4
-}
-
-static inline void mmxext_row (int16_t * table, int32_t * rounder)
-{
- movq_m2r (*(table+8), mm1); // mm1 = -C5 -C1 C3 C1
- pmaddwd_r2r (mm2, mm4); // mm4 = C4*x0+C6*x2 C4*x4+C6*x6
-
- pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x4-C6*x6 C4*x0-C6*x2
- pshufw_r2r (mm6, mm6, 0x4e); // mm6 = x3 x1 x7 x5
-
- movq_m2r (*(table+12), mm7); // mm7 = -C7 C3 C7 C5
- pmaddwd_r2r (mm5, mm1); // mm1 = -C1*x5-C5*x7 C1*x1+C3*x3
-
- paddd_m2r (*rounder, mm3); // mm3 += rounder
- pmaddwd_r2r (mm6, mm7); // mm7 = C3*x1-C7*x3 C5*x5+C7*x7
-
- pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x0-C2*x2 -C4*x4+C2*x6
- paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder
-
- pmaddwd_m2r (*(table+24), mm5); // mm5 = C3*x5-C1*x7 C5*x1-C1*x3
- movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder
-
- pmaddwd_m2r (*(table+28), mm6); // mm6 = C7*x1-C5*x3 C7*x5+C3*x7
- paddd_r2r (mm7, mm1); // mm1 = b1 b0
-
- paddd_m2r (*rounder, mm0); // mm0 += rounder
- psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder
-
- psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7
- paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder
-
- paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder
- psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0
-
- paddd_r2r (mm6, mm5); // mm5 = b3 b2
- movq_r2r (mm0, mm4); // mm4 = a3 a2 + rounder
-
- paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder
- psubd_r2r (mm5, mm4); // mm4 = a3-b3 a2-b2 + rounder
-}
-
-static inline void mmxext_row_tail (int16_t * row, int store)
-{
- psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
-
- psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5
-
- packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
-
- packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5
-
- movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
- pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4
-
- /* slot */
-
- movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4
-}
-
-static inline void mmxext_row_mid (int16_t * row, int store,
- int offset, int16_t * table)
-{
- movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
- psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
-
- movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
- psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5
-
- packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
- movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
-
- packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5
- movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
-
- movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
- pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4
-
- movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4
- movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4
-
- pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2
-
- movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4
- pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4
-}
-
-
-/* MMX row IDCT */
-
-#define mmx_table(c1,c2,c3,c4,c5,c6,c7) { c4, c2, c4, c6, \
- c4, c6, -c4, -c2, \
- c1, c3, c3, -c7, \
- c5, c7, -c1, -c5, \
- c4, -c6, c4, -c2, \
- -c4, c2, c4, -c6, \
- c5, -c1, c7, -c5, \
- c7, c3, c3, -c1 }
-
-static inline void mmx_row_head (int16_t * row, int offset, int16_t * table)
-{
- movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
-
- movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
- movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
-
- movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4
- movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
-
- punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0
-
- movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4
- pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2
-
- movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1
- punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4
-}
-
-static inline void mmx_row (int16_t * table, int32_t * rounder)
-{
- pmaddwd_r2r (mm2, mm4); // mm4 = -C4*x4-C2*x6 C4*x4+C6*x6
- punpckldq_r2r (mm5, mm5); // mm5 = x3 x1 x3 x1
-
- pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x0-C2*x2 C4*x0-C6*x2
- punpckhdq_r2r (mm6, mm6); // mm6 = x7 x5 x7 x5
-
- movq_m2r (*(table+12), mm7); // mm7 = -C5 -C1 C7 C5
- pmaddwd_r2r (mm5, mm1); // mm1 = C3*x1-C7*x3 C1*x1+C3*x3
-
- paddd_m2r (*rounder, mm3); // mm3 += rounder
- pmaddwd_r2r (mm6, mm7); // mm7 = -C1*x5-C5*x7 C5*x5+C7*x7
-
- pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x4-C6*x6 -C4*x4+C2*x6
- paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder
-
- pmaddwd_m2r (*(table+24), mm5); // mm5 = C7*x1-C5*x3 C5*x1-C1*x3
- movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder
-
- pmaddwd_m2r (*(table+28), mm6); // mm6 = C3*x5-C1*x7 C7*x5+C3*x7
- paddd_r2r (mm7, mm1); // mm1 = b1 b0
-
- paddd_m2r (*rounder, mm0); // mm0 += rounder
- psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder
-
- psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7
- paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder
-
- paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder
- psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0
-
- paddd_r2r (mm6, mm5); // mm5 = b3 b2
- movq_r2r (mm0, mm7); // mm7 = a3 a2 + rounder
-
- paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder
- psubd_r2r (mm5, mm7); // mm7 = a3-b3 a2-b2 + rounder
-}
-
-static inline void mmx_row_tail (int16_t * row, int store)
-{
- psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
-
- psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5
-
- packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
-
- packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5
-
- movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
- movq_r2r (mm7, mm4); // mm4 = y6 y7 y4 y5
-
- pslld_i2r (16, mm7); // mm7 = y7 0 y5 0
-
- psrld_i2r (16, mm4); // mm4 = 0 y6 0 y4
-
- por_r2r (mm4, mm7); // mm7 = y7 y6 y5 y4
-
- /* slot */
-
- movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4
-}
-
-static inline void mmx_row_mid (int16_t * row, int store,
- int offset, int16_t * table)
-{
- movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0
- psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2
-
- movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1
- psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5
-
- packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0
- movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1
-
- packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5
- movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0
-
- movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0
- movq_r2r (mm7, mm1); // mm1 = y6 y7 y4 y5
-
- punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0
- psrld_i2r (16, mm7); // mm7 = 0 y6 0 y4
-
- movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4
- pslld_i2r (16, mm1); // mm1 = y7 0 y5 0
-
- movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4
- por_r2r (mm1, mm7); // mm7 = y7 y6 y5 y4
-
- movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1
- punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4
-
- movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4
- pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2
-}
-
-
-#if 0
-// C column IDCT - its just here to document the MMXEXT and MMX versions
-static inline void idct_col (int16_t * col, int offset)
-{
-/* multiplication - as implemented on mmx */
-#define F(c,x) (((c) * (x)) >> 16)
-
-/* saturation - it helps us handle torture test cases */
-#define S(x) (((x)>32767) ? 32767 : ((x)<-32768) ? -32768 : (x))
-
- int16_t x0, x1, x2, x3, x4, x5, x6, x7;
- int16_t y0, y1, y2, y3, y4, y5, y6, y7;
- int16_t a0, a1, a2, a3, b0, b1, b2, b3;
- int16_t u04, v04, u26, v26, u17, v17, u35, v35, u12, v12;
-
- col += offset;
-
- x0 = col[0*8];
- x1 = col[1*8];
- x2 = col[2*8];
- x3 = col[3*8];
- x4 = col[4*8];
- x5 = col[5*8];
- x6 = col[6*8];
- x7 = col[7*8];
-
- u04 = S (x0 + x4);
- v04 = S (x0 - x4);
- u26 = S (F (T2, x6) + x2);
- v26 = S (F (T2, x2) - x6);
-
- a0 = S (u04 + u26);
- a1 = S (v04 + v26);
- a2 = S (v04 - v26);
- a3 = S (u04 - u26);
-
- u17 = S (F (T1, x7) + x1);
- v17 = S (F (T1, x1) - x7);
- u35 = S (F (T3, x5) + x3);
- v35 = S (F (T3, x3) - x5);
-
- b0 = S (u17 + u35);
- b3 = S (v17 - v35);
- u12 = S (u17 - u35);
- v12 = S (v17 + v35);
- u12 = S (2 * F (C4, u12));
- v12 = S (2 * F (C4, v12));
- b1 = S (u12 + v12);
- b2 = S (u12 - v12);
-
- y0 = S (a0 + b0) >> COL_SHIFT;
- y1 = S (a1 + b1) >> COL_SHIFT;
- y2 = S (a2 + b2) >> COL_SHIFT;
- y3 = S (a3 + b3) >> COL_SHIFT;
-
- y4 = S (a3 - b3) >> COL_SHIFT;
- y5 = S (a2 - b2) >> COL_SHIFT;
- y6 = S (a1 - b1) >> COL_SHIFT;
- y7 = S (a0 - b0) >> COL_SHIFT;
-
- col[0*8] = y0;
- col[1*8] = y1;
- col[2*8] = y2;
- col[3*8] = y3;
- col[4*8] = y4;
- col[5*8] = y5;
- col[6*8] = y6;
- col[7*8] = y7;
-}
-#endif
-
-
-// MMX column IDCT
-static inline void idct_col (int16_t * col, int offset)
-{
-#define T1 13036
-#define T2 27146
-#define T3 43790
-#define C4 23170
-
- static short _T1[] ATTR_ALIGN(8) = {T1,T1,T1,T1};
- static short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2};
- static short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3};
- static short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4};
-
- /* column code adapted from peter gubanov */
- /* http://www.elecard.com/peter/idct.shtml */
-
- movq_m2r (*_T1, mm0); // mm0 = T1
-
- movq_m2r (*(col+offset+1*8), mm1); // mm1 = x1
- movq_r2r (mm0, mm2); // mm2 = T1
-
- movq_m2r (*(col+offset+7*8), mm4); // mm4 = x7
- pmulhw_r2r (mm1, mm0); // mm0 = T1*x1
-
- movq_m2r (*_T3, mm5); // mm5 = T3
- pmulhw_r2r (mm4, mm2); // mm2 = T1*x7
-
- movq_m2r (*(col+offset+5*8), mm6); // mm6 = x5
- movq_r2r (mm5, mm7); // mm7 = T3-1
-
- movq_m2r (*(col+offset+3*8), mm3); // mm3 = x3
- psubsw_r2r (mm4, mm0); // mm0 = v17
-
- movq_m2r (*_T2, mm4); // mm4 = T2
- pmulhw_r2r (mm3, mm5); // mm5 = (T3-1)*x3
-
- paddsw_r2r (mm2, mm1); // mm1 = u17
- pmulhw_r2r (mm6, mm7); // mm7 = (T3-1)*x5
-
- /* slot */
-
- movq_r2r (mm4, mm2); // mm2 = T2
- paddsw_r2r (mm3, mm5); // mm5 = T3*x3
-
- pmulhw_m2r (*(col+offset+2*8), mm4);// mm4 = T2*x2
- paddsw_r2r (mm6, mm7); // mm7 = T3*x5
-
- psubsw_r2r (mm6, mm5); // mm5 = v35
- paddsw_r2r (mm3, mm7); // mm7 = u35
-
- movq_m2r (*(col+offset+6*8), mm3); // mm3 = x6
- movq_r2r (mm0, mm6); // mm6 = v17
-
- pmulhw_r2r (mm3, mm2); // mm2 = T2*x6
- psubsw_r2r (mm5, mm0); // mm0 = b3
-
- psubsw_r2r (mm3, mm4); // mm4 = v26
- paddsw_r2r (mm6, mm5); // mm5 = v12
-
- movq_r2m (mm0, *(col+offset+3*8)); // save b3 in scratch0
- movq_r2r (mm1, mm6); // mm6 = u17
-
- paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26
- paddsw_r2r (mm7, mm6); // mm6 = b0
-
- psubsw_r2r (mm7, mm1); // mm1 = u12
- movq_r2r (mm1, mm7); // mm7 = u12
-
- movq_m2r (*(col+offset+0*8), mm3); // mm3 = x0
- paddsw_r2r (mm5, mm1); // mm1 = u12+v12
-
- movq_m2r (*_C4, mm0); // mm0 = C4/2
- psubsw_r2r (mm5, mm7); // mm7 = u12-v12
-
- movq_r2m (mm6, *(col+offset+5*8)); // save b0 in scratch1
- pmulhw_r2r (mm0, mm1); // mm1 = b1/2
-
- movq_r2r (mm4, mm6); // mm6 = v26
- pmulhw_r2r (mm0, mm7); // mm7 = b2/2
-
- movq_m2r (*(col+offset+4*8), mm5); // mm5 = x4
- movq_r2r (mm3, mm0); // mm0 = x0
-
- psubsw_r2r (mm5, mm3); // mm3 = v04
- paddsw_r2r (mm5, mm0); // mm0 = u04
-
- paddsw_r2r (mm3, mm4); // mm4 = a1
- movq_r2r (mm0, mm5); // mm5 = u04
-
- psubsw_r2r (mm6, mm3); // mm3 = a2
- paddsw_r2r (mm2, mm5); // mm5 = a0
-
- paddsw_r2r (mm1, mm1); // mm1 = b1
- psubsw_r2r (mm2, mm0); // mm0 = a3
-
- paddsw_r2r (mm7, mm7); // mm7 = b2
- movq_r2r (mm3, mm2); // mm2 = a2
-
- movq_r2r (mm4, mm6); // mm6 = a1
- paddsw_r2r (mm7, mm3); // mm3 = a2+b2
-
- psraw_i2r (COL_SHIFT, mm3); // mm3 = y2
- paddsw_r2r (mm1, mm4); // mm4 = a1+b1
-
- psraw_i2r (COL_SHIFT, mm4); // mm4 = y1
- psubsw_r2r (mm1, mm6); // mm6 = a1-b1
-
- movq_m2r (*(col+offset+5*8), mm1); // mm1 = b0
- psubsw_r2r (mm7, mm2); // mm2 = a2-b2
-
- psraw_i2r (COL_SHIFT, mm6); // mm6 = y6
- movq_r2r (mm5, mm7); // mm7 = a0
-
- movq_r2m (mm4, *(col+offset+1*8)); // save y1
- psraw_i2r (COL_SHIFT, mm2); // mm2 = y5
-
- movq_r2m (mm3, *(col+offset+2*8)); // save y2
- paddsw_r2r (mm1, mm5); // mm5 = a0+b0
-
- movq_m2r (*(col+offset+3*8), mm4); // mm4 = b3
- psubsw_r2r (mm1, mm7); // mm7 = a0-b0
-
- psraw_i2r (COL_SHIFT, mm5); // mm5 = y0
- movq_r2r (mm0, mm3); // mm3 = a3
-
- movq_r2m (mm2, *(col+offset+5*8)); // save y5
- psubsw_r2r (mm4, mm3); // mm3 = a3-b3
-
- psraw_i2r (COL_SHIFT, mm7); // mm7 = y7
- paddsw_r2r (mm0, mm4); // mm4 = a3+b3
-
- movq_r2m (mm5, *(col+offset+0*8)); // save y0
- psraw_i2r (COL_SHIFT, mm3); // mm3 = y4
-
- movq_r2m (mm6, *(col+offset+6*8)); // save y6
- psraw_i2r (COL_SHIFT, mm4); // mm4 = y3
-
- movq_r2m (mm7, *(col+offset+7*8)); // save y7
-
- movq_r2m (mm3, *(col+offset+4*8)); // save y4
-
- movq_r2m (mm4, *(col+offset+3*8)); // save y3
-
-#undef T1
-#undef T2
-#undef T3
-#undef C4
-}
-
-static int32_t rounder0[] ATTR_ALIGN(8) =
- rounder ((1 << (COL_SHIFT - 1)) - 0.5);
-static int32_t rounder4[] ATTR_ALIGN(8) = rounder (0);
-static int32_t rounder1[] ATTR_ALIGN(8) =
- rounder (1.25683487303); /* C1*(C1/C4+C1+C7)/2 */
-static int32_t rounder7[] ATTR_ALIGN(8) =
- rounder (-0.25); /* C1*(C7/C4+C7-C1)/2 */
-static int32_t rounder2[] ATTR_ALIGN(8) =
- rounder (0.60355339059); /* C2 * (C6+C2)/2 */
-static int32_t rounder6[] ATTR_ALIGN(8) =
- rounder (-0.25); /* C2 * (C6-C2)/2 */
-static int32_t rounder3[] ATTR_ALIGN(8) =
- rounder (0.087788325588); /* C3*(-C3/C4+C3+C5)/2 */
-static int32_t rounder5[] ATTR_ALIGN(8) =
- rounder (-0.441341716183); /* C3*(-C5/C4+C5-C3)/2 */
-
-#undef COL_SHIFT
-#undef ROW_SHIFT
-
-#define declare_idct(idct,table,idct_row_head,idct_row,idct_row_tail,idct_row_mid) \
-void idct (int16_t * block) \
-{ \
- static int16_t table04[] ATTR_ALIGN(16) = \
- table (22725, 21407, 19266, 16384, 12873, 8867, 4520); \
- static int16_t table17[] ATTR_ALIGN(16) = \
- table (31521, 29692, 26722, 22725, 17855, 12299, 6270); \
- static int16_t table26[] ATTR_ALIGN(16) = \
- table (29692, 27969, 25172, 21407, 16819, 11585, 5906); \
- static int16_t table35[] ATTR_ALIGN(16) = \
- table (26722, 25172, 22654, 19266, 15137, 10426, 5315); \
- \
- idct_row_head (block, 0*8, table04); \
- idct_row (table04, rounder0); \
- idct_row_mid (block, 0*8, 4*8, table04); \
- idct_row (table04, rounder4); \
- idct_row_mid (block, 4*8, 1*8, table17); \
- idct_row (table17, rounder1); \
- idct_row_mid (block, 1*8, 7*8, table17); \
- idct_row (table17, rounder7); \
- idct_row_mid (block, 7*8, 2*8, table26); \
- idct_row (table26, rounder2); \
- idct_row_mid (block, 2*8, 6*8, table26); \
- idct_row (table26, rounder6); \
- idct_row_mid (block, 6*8, 3*8, table35); \
- idct_row (table35, rounder3); \
- idct_row_mid (block, 3*8, 5*8, table35); \
- idct_row (table35, rounder5); \
- idct_row_tail (block, 5*8); \
- \
- idct_col (block, 0); \
- idct_col (block, 4); \
-}
-
-
-declare_idct (ff_mmxext_idct, mmxext_table,
- mmxext_row_head, mmxext_row, mmxext_row_tail, mmxext_row_mid)
-
-declare_idct (ff_mmx_idct, mmx_table,
- mmx_row_head, mmx_row, mmx_row_tail, mmx_row_mid)
+++ /dev/null
-/*
- * mmx.h
- * Copyright (C) 1997-2001 H. Dietz and R. Fisher
- */
-#ifndef AVCODEC_I386MMX_H
-#define AVCODEC_I386MMX_H
-
-/*
- * The type of an value that fits in an MMX register (note that long
- * long constant values MUST be suffixed by LL and unsigned long long
- * values by ULL, lest they be truncated by the compiler)
- */
-
-typedef union {
- long long q; /* Quadword (64-bit) value */
- unsigned long long uq; /* Unsigned Quadword */
- int d[2]; /* 2 Doubleword (32-bit) values */
- unsigned int ud[2]; /* 2 Unsigned Doubleword */
- short w[4]; /* 4 Word (16-bit) values */
- unsigned short uw[4]; /* 4 Unsigned Word */
- char b[8]; /* 8 Byte (8-bit) values */
- unsigned char ub[8]; /* 8 Unsigned Byte */
- float s[2]; /* Single-precision (32-bit) value */
-} mmx_t; /* On an 8-byte (64-bit) boundary */
-
-
-#define mmx_i2r(op,imm,reg) \
- __asm__ __volatile__ (#op " %0, %%" #reg \
- : /* nothing */ \
- : "i" (imm) )
-
-#define mmx_m2r(op,mem,reg) \
- __asm__ __volatile__ (#op " %0, %%" #reg \
- : /* nothing */ \
- : "m" (mem))
-
-#define mmx_r2m(op,reg,mem) \
- __asm__ __volatile__ (#op " %%" #reg ", %0" \
- : "=m" (mem) \
- : /* nothing */ )
-
-#define mmx_r2r(op,regs,regd) \
- __asm__ __volatile__ (#op " %" #regs ", %" #regd)
-
-
-#define emms() __asm__ __volatile__ ("emms")
-
-#define movd_m2r(var,reg) mmx_m2r (movd, var, reg)
-#define movd_r2m(reg,var) mmx_r2m (movd, reg, var)
-#define movd_r2r(regs,regd) mmx_r2r (movd, regs, regd)
-
-#define movq_m2r(var,reg) mmx_m2r (movq, var, reg)
-#define movq_r2m(reg,var) mmx_r2m (movq, reg, var)
-#define movq_r2r(regs,regd) mmx_r2r (movq, regs, regd)
-
-#define packssdw_m2r(var,reg) mmx_m2r (packssdw, var, reg)
-#define packssdw_r2r(regs,regd) mmx_r2r (packssdw, regs, regd)
-#define packsswb_m2r(var,reg) mmx_m2r (packsswb, var, reg)
-#define packsswb_r2r(regs,regd) mmx_r2r (packsswb, regs, regd)
-
-#define packuswb_m2r(var,reg) mmx_m2r (packuswb, var, reg)
-#define packuswb_r2r(regs,regd) mmx_r2r (packuswb, regs, regd)
-
-#define paddb_m2r(var,reg) mmx_m2r (paddb, var, reg)
-#define paddb_r2r(regs,regd) mmx_r2r (paddb, regs, regd)
-#define paddd_m2r(var,reg) mmx_m2r (paddd, var, reg)
-#define paddd_r2r(regs,regd) mmx_r2r (paddd, regs, regd)
-#define paddw_m2r(var,reg) mmx_m2r (paddw, var, reg)
-#define paddw_r2r(regs,regd) mmx_r2r (paddw, regs, regd)
-
-#define paddsb_m2r(var,reg) mmx_m2r (paddsb, var, reg)
-#define paddsb_r2r(regs,regd) mmx_r2r (paddsb, regs, regd)
-#define paddsw_m2r(var,reg) mmx_m2r (paddsw, var, reg)
-#define paddsw_r2r(regs,regd) mmx_r2r (paddsw, regs, regd)
-
-#define paddusb_m2r(var,reg) mmx_m2r (paddusb, var, reg)
-#define paddusb_r2r(regs,regd) mmx_r2r (paddusb, regs, regd)
-#define paddusw_m2r(var,reg) mmx_m2r (paddusw, var, reg)
-#define paddusw_r2r(regs,regd) mmx_r2r (paddusw, regs, regd)
-
-#define pand_m2r(var,reg) mmx_m2r (pand, var, reg)
-#define pand_r2r(regs,regd) mmx_r2r (pand, regs, regd)
-
-#define pandn_m2r(var,reg) mmx_m2r (pandn, var, reg)
-#define pandn_r2r(regs,regd) mmx_r2r (pandn, regs, regd)
-
-#define pcmpeqb_m2r(var,reg) mmx_m2r (pcmpeqb, var, reg)
-#define pcmpeqb_r2r(regs,regd) mmx_r2r (pcmpeqb, regs, regd)
-#define pcmpeqd_m2r(var,reg) mmx_m2r (pcmpeqd, var, reg)
-#define pcmpeqd_r2r(regs,regd) mmx_r2r (pcmpeqd, regs, regd)
-#define pcmpeqw_m2r(var,reg) mmx_m2r (pcmpeqw, var, reg)
-#define pcmpeqw_r2r(regs,regd) mmx_r2r (pcmpeqw, regs, regd)
-
-#define pcmpgtb_m2r(var,reg) mmx_m2r (pcmpgtb, var, reg)
-#define pcmpgtb_r2r(regs,regd) mmx_r2r (pcmpgtb, regs, regd)
-#define pcmpgtd_m2r(var,reg) mmx_m2r (pcmpgtd, var, reg)
-#define pcmpgtd_r2r(regs,regd) mmx_r2r (pcmpgtd, regs, regd)
-#define pcmpgtw_m2r(var,reg) mmx_m2r (pcmpgtw, var, reg)
-#define pcmpgtw_r2r(regs,regd) mmx_r2r (pcmpgtw, regs, regd)
-
-#define pmaddwd_m2r(var,reg) mmx_m2r (pmaddwd, var, reg)
-#define pmaddwd_r2r(regs,regd) mmx_r2r (pmaddwd, regs, regd)
-
-#define pmulhw_m2r(var,reg) mmx_m2r (pmulhw, var, reg)
-#define pmulhw_r2r(regs,regd) mmx_r2r (pmulhw, regs, regd)
-
-#define pmullw_m2r(var,reg) mmx_m2r (pmullw, var, reg)
-#define pmullw_r2r(regs,regd) mmx_r2r (pmullw, regs, regd)
-
-#define por_m2r(var,reg) mmx_m2r (por, var, reg)
-#define por_r2r(regs,regd) mmx_r2r (por, regs, regd)
-
-#define pslld_i2r(imm,reg) mmx_i2r (pslld, imm, reg)
-#define pslld_m2r(var,reg) mmx_m2r (pslld, var, reg)
-#define pslld_r2r(regs,regd) mmx_r2r (pslld, regs, regd)
-#define psllq_i2r(imm,reg) mmx_i2r (psllq, imm, reg)
-#define psllq_m2r(var,reg) mmx_m2r (psllq, var, reg)
-#define psllq_r2r(regs,regd) mmx_r2r (psllq, regs, regd)
-#define psllw_i2r(imm,reg) mmx_i2r (psllw, imm, reg)
-#define psllw_m2r(var,reg) mmx_m2r (psllw, var, reg)
-#define psllw_r2r(regs,regd) mmx_r2r (psllw, regs, regd)
-
-#define psrad_i2r(imm,reg) mmx_i2r (psrad, imm, reg)
-#define psrad_m2r(var,reg) mmx_m2r (psrad, var, reg)
-#define psrad_r2r(regs,regd) mmx_r2r (psrad, regs, regd)
-#define psraw_i2r(imm,reg) mmx_i2r (psraw, imm, reg)
-#define psraw_m2r(var,reg) mmx_m2r (psraw, var, reg)
-#define psraw_r2r(regs,regd) mmx_r2r (psraw, regs, regd)
-
-#define psrld_i2r(imm,reg) mmx_i2r (psrld, imm, reg)
-#define psrld_m2r(var,reg) mmx_m2r (psrld, var, reg)
-#define psrld_r2r(regs,regd) mmx_r2r (psrld, regs, regd)
-#define psrlq_i2r(imm,reg) mmx_i2r (psrlq, imm, reg)
-#define psrlq_m2r(var,reg) mmx_m2r (psrlq, var, reg)
-#define psrlq_r2r(regs,regd) mmx_r2r (psrlq, regs, regd)
-#define psrlw_i2r(imm,reg) mmx_i2r (psrlw, imm, reg)
-#define psrlw_m2r(var,reg) mmx_m2r (psrlw, var, reg)
-#define psrlw_r2r(regs,regd) mmx_r2r (psrlw, regs, regd)
-
-#define psubb_m2r(var,reg) mmx_m2r (psubb, var, reg)
-#define psubb_r2r(regs,regd) mmx_r2r (psubb, regs, regd)
-#define psubd_m2r(var,reg) mmx_m2r (psubd, var, reg)
-#define psubd_r2r(regs,regd) mmx_r2r (psubd, regs, regd)
-#define psubw_m2r(var,reg) mmx_m2r (psubw, var, reg)
-#define psubw_r2r(regs,regd) mmx_r2r (psubw, regs, regd)
-
-#define psubsb_m2r(var,reg) mmx_m2r (psubsb, var, reg)
-#define psubsb_r2r(regs,regd) mmx_r2r (psubsb, regs, regd)
-#define psubsw_m2r(var,reg) mmx_m2r (psubsw, var, reg)
-#define psubsw_r2r(regs,regd) mmx_r2r (psubsw, regs, regd)
-
-#define psubusb_m2r(var,reg) mmx_m2r (psubusb, var, reg)
-#define psubusb_r2r(regs,regd) mmx_r2r (psubusb, regs, regd)
-#define psubusw_m2r(var,reg) mmx_m2r (psubusw, var, reg)
-#define psubusw_r2r(regs,regd) mmx_r2r (psubusw, regs, regd)
-
-#define punpckhbw_m2r(var,reg) mmx_m2r (punpckhbw, var, reg)
-#define punpckhbw_r2r(regs,regd) mmx_r2r (punpckhbw, regs, regd)
-#define punpckhdq_m2r(var,reg) mmx_m2r (punpckhdq, var, reg)
-#define punpckhdq_r2r(regs,regd) mmx_r2r (punpckhdq, regs, regd)
-#define punpckhwd_m2r(var,reg) mmx_m2r (punpckhwd, var, reg)
-#define punpckhwd_r2r(regs,regd) mmx_r2r (punpckhwd, regs, regd)
-
-#define punpcklbw_m2r(var,reg) mmx_m2r (punpcklbw, var, reg)
-#define punpcklbw_r2r(regs,regd) mmx_r2r (punpcklbw, regs, regd)
-#define punpckldq_m2r(var,reg) mmx_m2r (punpckldq, var, reg)
-#define punpckldq_r2r(regs,regd) mmx_r2r (punpckldq, regs, regd)
-#define punpcklwd_m2r(var,reg) mmx_m2r (punpcklwd, var, reg)
-#define punpcklwd_r2r(regs,regd) mmx_r2r (punpcklwd, regs, regd)
-
-#define pxor_m2r(var,reg) mmx_m2r (pxor, var, reg)
-#define pxor_r2r(regs,regd) mmx_r2r (pxor, regs, regd)
-
-
-/* 3DNOW extensions */
-
-#define pavgusb_m2r(var,reg) mmx_m2r (pavgusb, var, reg)
-#define pavgusb_r2r(regs,regd) mmx_r2r (pavgusb, regs, regd)
-
-
-/* AMD MMX extensions - also available in intel SSE */
-
-
-#define mmx_m2ri(op,mem,reg,imm) \
- __asm__ __volatile__ (#op " %1, %0, %%" #reg \
- : /* nothing */ \
- : "X" (mem), "X" (imm))
-#define mmx_r2ri(op,regs,regd,imm) \
- __asm__ __volatile__ (#op " %0, %%" #regs ", %%" #regd \
- : /* nothing */ \
- : "X" (imm) )
-
-#define mmx_fetch(mem,hint) \
- __asm__ __volatile__ ("prefetch" #hint " %0" \
- : /* nothing */ \
- : "X" (mem))
-
-
-#define maskmovq(regs,maskreg) mmx_r2ri (maskmovq, regs, maskreg)
-
-#define movntq_r2m(mmreg,var) mmx_r2m (movntq, mmreg, var)
-
-#define pavgb_m2r(var,reg) mmx_m2r (pavgb, var, reg)
-#define pavgb_r2r(regs,regd) mmx_r2r (pavgb, regs, regd)
-#define pavgw_m2r(var,reg) mmx_m2r (pavgw, var, reg)
-#define pavgw_r2r(regs,regd) mmx_r2r (pavgw, regs, regd)
-
-#define pextrw_r2r(mmreg,reg,imm) mmx_r2ri (pextrw, mmreg, reg, imm)
-
-#define pinsrw_r2r(reg,mmreg,imm) mmx_r2ri (pinsrw, reg, mmreg, imm)
-
-#define pmaxsw_m2r(var,reg) mmx_m2r (pmaxsw, var, reg)
-#define pmaxsw_r2r(regs,regd) mmx_r2r (pmaxsw, regs, regd)
-
-#define pmaxub_m2r(var,reg) mmx_m2r (pmaxub, var, reg)
-#define pmaxub_r2r(regs,regd) mmx_r2r (pmaxub, regs, regd)
-
-#define pminsw_m2r(var,reg) mmx_m2r (pminsw, var, reg)
-#define pminsw_r2r(regs,regd) mmx_r2r (pminsw, regs, regd)
-
-#define pminub_m2r(var,reg) mmx_m2r (pminub, var, reg)
-#define pminub_r2r(regs,regd) mmx_r2r (pminub, regs, regd)
-
-#define pmovmskb(mmreg,reg) \
- __asm__ __volatile__ ("movmskps %" #mmreg ", %" #reg)
-
-#define pmulhuw_m2r(var,reg) mmx_m2r (pmulhuw, var, reg)
-#define pmulhuw_r2r(regs,regd) mmx_r2r (pmulhuw, regs, regd)
-
-#define prefetcht0(mem) mmx_fetch (mem, t0)
-#define prefetcht1(mem) mmx_fetch (mem, t1)
-#define prefetcht2(mem) mmx_fetch (mem, t2)
-#define prefetchnta(mem) mmx_fetch (mem, nta)
-
-#define psadbw_m2r(var,reg) mmx_m2r (psadbw, var, reg)
-#define psadbw_r2r(regs,regd) mmx_r2r (psadbw, regs, regd)
-
-#define pshufw_m2r(var,reg,imm) mmx_m2ri(pshufw, var, reg, imm)
-#define pshufw_r2r(regs,regd,imm) mmx_r2ri(pshufw, regs, regd, imm)
-
-#define sfence() __asm__ __volatile__ ("sfence\n\t")
-
-#endif /* AVCODEC_I386MMX_H */
+++ /dev/null
-/*
- * MMX optimized motion estimation
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * mostly by Michael Niedermayer <michaelni@gmx.at>
- */
-#include "../dsputil.h"
-
-static const __attribute__ ((aligned(8))) uint64_t round_tab[3]={
-0x0000000000000000,
-0x0001000100010001,
-0x0002000200020002,
-};
-
-static __attribute__ ((aligned(8), unused)) uint64_t bone= 0x0101010101010101LL;
-
-static inline void sad8_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
-{
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm2 \n\t"
- "movq (%2, %%eax), %%mm4 \n\t"
- "addl %3, %%eax \n\t"
- "psubusb %%mm0, %%mm2 \n\t"
- "psubusb %%mm4, %%mm0 \n\t"
- "movq (%1, %%eax), %%mm1 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "movq (%2, %%eax), %%mm5 \n\t"
- "psubusb %%mm1, %%mm3 \n\t"
- "psubusb %%mm5, %%mm1 \n\t"
- "por %%mm2, %%mm0 \n\t"
- "por %%mm1, %%mm3 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm3, %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm3 \n\t"
- "punpckhbw %%mm7, %%mm2 \n\t"
- "paddw %%mm1, %%mm0 \n\t"
- "paddw %%mm3, %%mm2 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %3, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1 - len), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline void sad8_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
-{
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm2 \n\t"
- "psadbw %%mm2, %%mm0 \n\t"
- "addl %3, %%eax \n\t"
- "movq (%1, %%eax), %%mm1 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "psadbw %%mm1, %%mm3 \n\t"
- "paddw %%mm3, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %3, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1 - len), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline void sad8_2_mmx2(uint8_t *blk1a, uint8_t *blk1b, uint8_t *blk2, int stride, int h)
-{
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm2 \n\t"
- "pavgb %%mm2, %%mm0 \n\t"
- "movq (%3, %%eax), %%mm2 \n\t"
- "psadbw %%mm2, %%mm0 \n\t"
- "addl %4, %%eax \n\t"
- "movq (%1, %%eax), %%mm1 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "pavgb %%mm1, %%mm3 \n\t"
- "movq (%3, %%eax), %%mm1 \n\t"
- "psadbw %%mm1, %%mm3 \n\t"
- "paddw %%mm3, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %4, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1a - len), "r" (blk1b -len), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline void sad8_4_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h)
-{ //FIXME reuse src
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "movq "MANGLE(bone)", %%mm5 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm2 \n\t"
- "movq 1(%1, %%eax), %%mm1 \n\t"
- "movq 1(%2, %%eax), %%mm3 \n\t"
- "pavgb %%mm2, %%mm0 \n\t"
- "pavgb %%mm1, %%mm3 \n\t"
- "psubusb %%mm5, %%mm3 \n\t"
- "pavgb %%mm3, %%mm0 \n\t"
- "movq (%3, %%eax), %%mm2 \n\t"
- "psadbw %%mm2, %%mm0 \n\t"
- "addl %4, %%eax \n\t"
- "movq (%1, %%eax), %%mm1 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "movq 1(%1, %%eax), %%mm2 \n\t"
- "movq 1(%2, %%eax), %%mm4 \n\t"
- "pavgb %%mm3, %%mm1 \n\t"
- "pavgb %%mm4, %%mm2 \n\t"
- "psubusb %%mm5, %%mm2 \n\t"
- "pavgb %%mm1, %%mm2 \n\t"
- "movq (%3, %%eax), %%mm1 \n\t"
- "psadbw %%mm1, %%mm2 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %4, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1 - len), "r" (blk1 - len + stride), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline void sad8_2_mmx(uint8_t *blk1a, uint8_t *blk1b, uint8_t *blk2, int stride, int h)
-{
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm2 \n\t"
- "movq (%2, %%eax), %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm3 \n\t"
- "paddw %%mm0, %%mm1 \n\t"
- "paddw %%mm2, %%mm3 \n\t"
- "movq (%3, %%eax), %%mm4 \n\t"
- "movq (%3, %%eax), %%mm2 \n\t"
- "paddw %%mm5, %%mm1 \n\t"
- "paddw %%mm5, %%mm3 \n\t"
- "psrlw $1, %%mm1 \n\t"
- "psrlw $1, %%mm3 \n\t"
- "packuswb %%mm3, %%mm1 \n\t"
- "psubusb %%mm1, %%mm4 \n\t"
- "psubusb %%mm2, %%mm1 \n\t"
- "por %%mm4, %%mm1 \n\t"
- "movq %%mm1, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "paddw %%mm1, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %4, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1a - len), "r" (blk1b -len), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline void sad8_4_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h)
-{
- int len= -(stride<<h);
- asm volatile(
- ".balign 16 \n\t"
- "1: \n\t"
- "movq (%1, %%eax), %%mm0 \n\t"
- "movq (%2, %%eax), %%mm1 \n\t"
- "movq %%mm0, %%mm4 \n\t"
- "movq %%mm1, %%mm2 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm7, %%mm4 \n\t"
- "punpckhbw %%mm7, %%mm2 \n\t"
- "paddw %%mm1, %%mm0 \n\t"
- "paddw %%mm2, %%mm4 \n\t"
- "movq 1(%1, %%eax), %%mm2 \n\t"
- "movq 1(%2, %%eax), %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t"
- "punpckhbw %%mm7, %%mm1 \n\t"
- "paddw %%mm0, %%mm2 \n\t"
- "paddw %%mm4, %%mm1 \n\t"
- "movq %%mm3, %%mm4 \n\t"
- "punpcklbw %%mm7, %%mm3 \n\t"
- "punpckhbw %%mm7, %%mm4 \n\t"
- "paddw %%mm3, %%mm2 \n\t"
- "paddw %%mm4, %%mm1 \n\t"
- "movq (%3, %%eax), %%mm3 \n\t"
- "movq (%3, %%eax), %%mm4 \n\t"
- "paddw %%mm5, %%mm2 \n\t"
- "paddw %%mm5, %%mm1 \n\t"
- "psrlw $2, %%mm2 \n\t"
- "psrlw $2, %%mm1 \n\t"
- "packuswb %%mm1, %%mm2 \n\t"
- "psubusb %%mm2, %%mm3 \n\t"
- "psubusb %%mm4, %%mm2 \n\t"
- "por %%mm3, %%mm2 \n\t"
- "movq %%mm2, %%mm0 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t"
- "punpckhbw %%mm7, %%mm2 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "addl %4, %%eax \n\t"
- " js 1b \n\t"
- : "+a" (len)
- : "r" (blk1 - len), "r" (blk1 -len + stride), "r" (blk2 - len), "r" (stride)
- );
-}
-
-static inline int sum_mmx(void)
-{
- int ret;
- asm volatile(
- "movq %%mm6, %%mm0 \n\t"
- "psrlq $32, %%mm6 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "movq %%mm6, %%mm0 \n\t"
- "psrlq $16, %%mm6 \n\t"
- "paddw %%mm0, %%mm6 \n\t"
- "movd %%mm6, %0 \n\t"
- : "=r" (ret)
- );
- return ret&0xFFFF;
-}
-
-static inline int sum_mmx2(void)
-{
- int ret;
- asm volatile(
- "movd %%mm6, %0 \n\t"
- : "=r" (ret)
- );
- return ret;
-}
-
-
-#define PIX_SAD(suf)\
-static int pix_abs8x8_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t":);\
-\
- sad8_ ## suf(blk1, blk2, stride, 3);\
-\
- return sum_ ## suf();\
-}\
-static int sad8x8_ ## suf(void *s, uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t":);\
-\
- sad8_ ## suf(blk1, blk2, stride, 3);\
-\
- return sum_ ## suf();\
-}\
-\
-static int pix_abs8x8_x2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[1]) \
- );\
-\
- sad8_2_ ## suf(blk1, blk1+1, blk2, stride, 3);\
-\
- return sum_ ## suf();\
-}\
-\
-static int pix_abs8x8_y2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[1]) \
- );\
-\
- sad8_2_ ## suf(blk1, blk1+stride, blk2, stride, 3);\
-\
- return sum_ ## suf();\
-}\
-\
-static int pix_abs8x8_xy2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[2]) \
- );\
-\
- sad8_4_ ## suf(blk1, blk2, stride, 3);\
-\
- return sum_ ## suf();\
-}\
-\
-static int pix_abs16x16_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t":);\
-\
- sad8_ ## suf(blk1 , blk2 , stride, 4);\
- sad8_ ## suf(blk1+8, blk2+8, stride, 4);\
-\
- return sum_ ## suf();\
-}\
-static int sad16x16_ ## suf(void *s, uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t":);\
-\
- sad8_ ## suf(blk1 , blk2 , stride, 4);\
- sad8_ ## suf(blk1+8, blk2+8, stride, 4);\
-\
- return sum_ ## suf();\
-}\
-static int pix_abs16x16_x2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[1]) \
- );\
-\
- sad8_2_ ## suf(blk1 , blk1+1, blk2 , stride, 4);\
- sad8_2_ ## suf(blk1+8, blk1+9, blk2+8, stride, 4);\
-\
- return sum_ ## suf();\
-}\
-static int pix_abs16x16_y2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[1]) \
- );\
-\
- sad8_2_ ## suf(blk1 , blk1+stride, blk2 , stride, 4);\
- sad8_2_ ## suf(blk1+8, blk1+stride+8,blk2+8, stride, 4);\
-\
- return sum_ ## suf();\
-}\
-static int pix_abs16x16_xy2_ ## suf(uint8_t *blk2, uint8_t *blk1, int stride)\
-{\
- asm volatile("pxor %%mm7, %%mm7 \n\t"\
- "pxor %%mm6, %%mm6 \n\t"\
- "movq %0, %%mm5 \n\t"\
- :: "m"(round_tab[2]) \
- );\
-\
- sad8_4_ ## suf(blk1 , blk2 , stride, 4);\
- sad8_4_ ## suf(blk1+8, blk2+8, stride, 4);\
-\
- return sum_ ## suf();\
-}\
-
-PIX_SAD(mmx)
-PIX_SAD(mmx2)
-
-void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx)
-{
- if (mm_flags & MM_MMX) {
- c->pix_abs16x16 = pix_abs16x16_mmx;
- c->pix_abs16x16_x2 = pix_abs16x16_x2_mmx;
- c->pix_abs16x16_y2 = pix_abs16x16_y2_mmx;
- c->pix_abs16x16_xy2 = pix_abs16x16_xy2_mmx;
- c->pix_abs8x8 = pix_abs8x8_mmx;
- c->pix_abs8x8_x2 = pix_abs8x8_x2_mmx;
- c->pix_abs8x8_y2 = pix_abs8x8_y2_mmx;
- c->pix_abs8x8_xy2 = pix_abs8x8_xy2_mmx;
-
- c->sad[0]= sad16x16_mmx;
- c->sad[1]= sad8x8_mmx;
- }
- if (mm_flags & MM_MMXEXT) {
- c->pix_abs16x16 = pix_abs16x16_mmx2;
- c->pix_abs8x8 = pix_abs8x8_mmx2;
-
- c->sad[0]= sad16x16_mmx2;
- c->sad[1]= sad8x8_mmx2;
-
- if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
- c->pix_abs16x16_x2 = pix_abs16x16_x2_mmx2;
- c->pix_abs16x16_y2 = pix_abs16x16_y2_mmx2;
- c->pix_abs16x16_xy2 = pix_abs16x16_xy2_mmx2;
- c->pix_abs8x8_x2 = pix_abs8x8_x2_mmx2;
- c->pix_abs8x8_y2 = pix_abs8x8_y2_mmx2;
- c->pix_abs8x8_xy2 = pix_abs8x8_xy2_mmx2;
- }
- }
-}
+++ /dev/null
-/*
- * The simplest mpeg encoder (well, it was the simplest!)
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Optimized for ia32 cpus by Nick Kurshev <nickols_k@mail.ru>
- * h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
- */
-
-#include "../dsputil.h"
-#include "../mpegvideo.h"
-#include "../avcodec.h"
-
-extern uint8_t zigzag_direct_noperm[64];
-extern uint16_t inv_zigzag_direct16[64];
-
-static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL;
-static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL;
-
-
-static void dct_unquantize_h263_mmx(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int level, qmul, qadd, nCoeffs;
-
- qmul = qscale << 1;
- qadd = (qscale - 1) | 1;
-
- assert(s->block_last_index[n]>=0);
-
- if (s->mb_intra) {
- if (!s->h263_aic) {
- if (n < 4)
- level = block[0] * s->y_dc_scale;
- else
- level = block[0] * s->c_dc_scale;
- }else{
- qadd = 0;
- level= block[0];
- }
- nCoeffs=63;
- } else {
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
- level = 0;/* keep gcc quiet */
- }
-//printf("%d %d ", qmul, qadd);
-asm volatile(
- "movd %1, %%mm6 \n\t" //qmul
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "movd %2, %%mm5 \n\t" //qadd
- "pxor %%mm7, %%mm7 \n\t"
- "packssdw %%mm5, %%mm5 \n\t"
- "packssdw %%mm5, %%mm5 \n\t"
- "psubw %%mm5, %%mm7 \n\t"
- "pxor %%mm4, %%mm4 \n\t"
- ".balign 16\n\t"
- "1: \n\t"
- "movq (%0, %3), %%mm0 \n\t"
- "movq 8(%0, %3), %%mm1 \n\t"
-
- "pmullw %%mm6, %%mm0 \n\t"
- "pmullw %%mm6, %%mm1 \n\t"
-
- "movq (%0, %3), %%mm2 \n\t"
- "movq 8(%0, %3), %%mm3 \n\t"
-
- "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
-
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
-
- "paddw %%mm7, %%mm0 \n\t"
- "paddw %%mm7, %%mm1 \n\t"
-
- "pxor %%mm0, %%mm2 \n\t"
- "pxor %%mm1, %%mm3 \n\t"
-
- "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
-
- "pandn %%mm2, %%mm0 \n\t"
- "pandn %%mm3, %%mm1 \n\t"
-
- "movq %%mm0, (%0, %3) \n\t"
- "movq %%mm1, 8(%0, %3) \n\t"
-
- "addl $16, %3 \n\t"
- "jng 1b \n\t"
- ::"r" (block+nCoeffs), "g"(qmul), "g" (qadd), "r" (2*(-nCoeffs))
- : "memory"
- );
- if(s->mb_intra)
- block[0]= level;
-}
-
-
-/*
- NK:
- Note: looking at PARANOID:
- "enable all paranoid tests for rounding, overflows, etc..."
-
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- We can suppose that result of two multiplications can't be greate of 0xFFFF
- i.e. is 16-bit, so we use here only PMULLW instruction and can avoid
- a complex multiplication.
-=====================================================
- Full formula for multiplication of 2 integer numbers
- which are represent as high:low words:
- input: value1 = high1:low1
- value2 = high2:low2
- output: value3 = value1*value2
- value3=high3:low3 (on overflow: modulus 2^32 wrap-around)
- this mean that for 0x123456 * 0x123456 correct result is 0x766cb0ce4
- but this algorithm will compute only 0x66cb0ce4
- this limited by 16-bit size of operands
- ---------------------------------
- tlow1 = high1*low2
- tlow2 = high2*low1
- tlow1 = tlow1 + tlow2
- high3:low3 = low1*low2
- high3 += tlow1
-*/
-static void dct_unquantize_mpeg1_mmx(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int nCoeffs;
- const uint16_t *quant_matrix;
-
- assert(s->block_last_index[n]>=0);
-
- nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
-
- if (s->mb_intra) {
- int block0;
- if (n < 4)
- block0 = block[0] * s->y_dc_scale;
- else
- block0 = block[0] * s->c_dc_scale;
- /* XXX: only mpeg1 */
- quant_matrix = s->intra_matrix;
-asm volatile(
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlw $15, %%mm7 \n\t"
- "movd %2, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "movl %3, %%eax \n\t"
- ".balign 16\n\t"
- "1: \n\t"
- "movq (%0, %%eax), %%mm0 \n\t"
- "movq 8(%0, %%eax), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm4 \n\t"
- "movq 8(%1, %%eax), %%mm5 \n\t"
- "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
- "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
- "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
- "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
- "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
- "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t" // FIXME slow
- "pcmpeqw (%0, %%eax), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw 8(%0, %%eax), %%mm5 \n\t" // block[i] == 0 ? -1 : 0
- "psraw $3, %%mm0 \n\t"
- "psraw $3, %%mm1 \n\t"
- "psubw %%mm7, %%mm0 \n\t"
- "psubw %%mm7, %%mm1 \n\t"
- "por %%mm7, %%mm0 \n\t"
- "por %%mm7, %%mm1 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "pandn %%mm0, %%mm4 \n\t"
- "pandn %%mm1, %%mm5 \n\t"
- "movq %%mm4, (%0, %%eax) \n\t"
- "movq %%mm5, 8(%0, %%eax) \n\t"
-
- "addl $16, %%eax \n\t"
- "js 1b \n\t"
- ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
- : "%eax", "memory"
- );
- block[0]= block0;
-
- } else {
- quant_matrix = s->inter_matrix;
-asm volatile(
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlw $15, %%mm7 \n\t"
- "movd %2, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "movl %3, %%eax \n\t"
- ".balign 16\n\t"
- "1: \n\t"
- "movq (%0, %%eax), %%mm0 \n\t"
- "movq 8(%0, %%eax), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm4 \n\t"
- "movq 8(%1, %%eax), %%mm5 \n\t"
- "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
- "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
- "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
- "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
- "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
- "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
- "paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
- "paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
- "pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
- "pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t" // FIXME slow
- "pcmpeqw (%0, %%eax), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw 8(%0, %%eax), %%mm5 \n\t" // block[i] == 0 ? -1 : 0
- "psraw $4, %%mm0 \n\t"
- "psraw $4, %%mm1 \n\t"
- "psubw %%mm7, %%mm0 \n\t"
- "psubw %%mm7, %%mm1 \n\t"
- "por %%mm7, %%mm0 \n\t"
- "por %%mm7, %%mm1 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "pandn %%mm0, %%mm4 \n\t"
- "pandn %%mm1, %%mm5 \n\t"
- "movq %%mm4, (%0, %%eax) \n\t"
- "movq %%mm5, 8(%0, %%eax) \n\t"
-
- "addl $16, %%eax \n\t"
- "js 1b \n\t"
- ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
- : "%eax", "memory"
- );
- }
-
-}
-
-static void dct_unquantize_mpeg2_mmx(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int nCoeffs;
- const uint16_t *quant_matrix;
-
- assert(s->block_last_index[n]>=0);
-
- if(s->alternate_scan) nCoeffs= 63; //FIXME
- else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
-
- if (s->mb_intra) {
- int block0;
- if (n < 4)
- block0 = block[0] * s->y_dc_scale;
- else
- block0 = block[0] * s->c_dc_scale;
- quant_matrix = s->intra_matrix;
-asm volatile(
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlw $15, %%mm7 \n\t"
- "movd %2, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "movl %3, %%eax \n\t"
- ".balign 16\n\t"
- "1: \n\t"
- "movq (%0, %%eax), %%mm0 \n\t"
- "movq 8(%0, %%eax), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm4 \n\t"
- "movq 8(%1, %%eax), %%mm5 \n\t"
- "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
- "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
- "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
- "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
- "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
- "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t" // FIXME slow
- "pcmpeqw (%0, %%eax), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw 8(%0, %%eax), %%mm5 \n\t" // block[i] == 0 ? -1 : 0
- "psraw $3, %%mm0 \n\t"
- "psraw $3, %%mm1 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "pandn %%mm0, %%mm4 \n\t"
- "pandn %%mm1, %%mm5 \n\t"
- "movq %%mm4, (%0, %%eax) \n\t"
- "movq %%mm5, 8(%0, %%eax) \n\t"
-
- "addl $16, %%eax \n\t"
- "jng 1b \n\t"
- ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "g" (-2*nCoeffs)
- : "%eax", "memory"
- );
- block[0]= block0;
- //Note, we dont do mismatch control for intra as errors cannot accumulate
-
- } else {
- quant_matrix = s->inter_matrix;
-asm volatile(
- "pcmpeqw %%mm7, %%mm7 \n\t"
- "psrlq $48, %%mm7 \n\t"
- "movd %2, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "packssdw %%mm6, %%mm6 \n\t"
- "movl %3, %%eax \n\t"
- ".balign 16\n\t"
- "1: \n\t"
- "movq (%0, %%eax), %%mm0 \n\t"
- "movq 8(%0, %%eax), %%mm1 \n\t"
- "movq (%1, %%eax), %%mm4 \n\t"
- "movq 8(%1, %%eax), %%mm5 \n\t"
- "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
- "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
- "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
- "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
- "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
- "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
- "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
- "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*2*q
- "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*2*q
- "paddw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
- "paddw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
- "pxor %%mm4, %%mm4 \n\t"
- "pxor %%mm5, %%mm5 \n\t" // FIXME slow
- "pcmpeqw (%0, %%eax), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
- "pcmpeqw 8(%0, %%eax), %%mm5 \n\t" // block[i] == 0 ? -1 : 0
- "psrlw $4, %%mm0 \n\t"
- "psrlw $4, %%mm1 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t"
- "psubw %%mm3, %%mm1 \n\t"
- "pandn %%mm0, %%mm4 \n\t"
- "pandn %%mm1, %%mm5 \n\t"
- "pxor %%mm4, %%mm7 \n\t"
- "pxor %%mm5, %%mm7 \n\t"
- "movq %%mm4, (%0, %%eax) \n\t"
- "movq %%mm5, 8(%0, %%eax) \n\t"
-
- "addl $16, %%eax \n\t"
- "jng 1b \n\t"
- "movd 124(%0, %3), %%mm0 \n\t"
- "movq %%mm7, %%mm6 \n\t"
- "psrlq $32, %%mm7 \n\t"
- "pxor %%mm6, %%mm7 \n\t"
- "movq %%mm7, %%mm6 \n\t"
- "psrlq $16, %%mm7 \n\t"
- "pxor %%mm6, %%mm7 \n\t"
- "pslld $31, %%mm7 \n\t"
- "psrlq $15, %%mm7 \n\t"
- "pxor %%mm7, %%mm0 \n\t"
- "movd %%mm0, 124(%0, %3) \n\t"
-
- ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "g" (qscale), "r" (-2*nCoeffs)
- : "%eax", "memory"
- );
- }
-}
-
-/* draw the edges of width 'w' of an image of size width, height
- this mmx version can only handle w==8 || w==16 */
-static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
-{
- uint8_t *ptr, *last_line;
- int i;
-
- last_line = buf + (height - 1) * wrap;
- /* left and right */
- ptr = buf;
- if(w==8)
- {
- asm volatile(
- "1: \n\t"
- "movd (%0), %%mm0 \n\t"
- "punpcklbw %%mm0, %%mm0 \n\t"
- "punpcklwd %%mm0, %%mm0 \n\t"
- "punpckldq %%mm0, %%mm0 \n\t"
- "movq %%mm0, -8(%0) \n\t"
- "movq -8(%0, %2), %%mm1 \n\t"
- "punpckhbw %%mm1, %%mm1 \n\t"
- "punpckhwd %%mm1, %%mm1 \n\t"
- "punpckhdq %%mm1, %%mm1 \n\t"
- "movq %%mm1, (%0, %2) \n\t"
- "addl %1, %0 \n\t"
- "cmpl %3, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (ptr)
- : "r" (wrap), "r" (width), "r" (ptr + wrap*height)
- );
- }
- else
- {
- asm volatile(
- "1: \n\t"
- "movd (%0), %%mm0 \n\t"
- "punpcklbw %%mm0, %%mm0 \n\t"
- "punpcklwd %%mm0, %%mm0 \n\t"
- "punpckldq %%mm0, %%mm0 \n\t"
- "movq %%mm0, -8(%0) \n\t"
- "movq %%mm0, -16(%0) \n\t"
- "movq -8(%0, %2), %%mm1 \n\t"
- "punpckhbw %%mm1, %%mm1 \n\t"
- "punpckhwd %%mm1, %%mm1 \n\t"
- "punpckhdq %%mm1, %%mm1 \n\t"
- "movq %%mm1, (%0, %2) \n\t"
- "movq %%mm1, 8(%0, %2) \n\t"
- "addl %1, %0 \n\t"
- "cmpl %3, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (ptr)
- : "r" (wrap), "r" (width), "r" (ptr + wrap*height)
- );
- }
-
- for(i=0;i<w;i+=4) {
- /* top and bottom (and hopefully also the corners) */
- ptr= buf - (i + 1) * wrap - w;
- asm volatile(
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm0, (%0, %2) \n\t"
- "movq %%mm0, (%0, %2, 2) \n\t"
- "movq %%mm0, (%0, %3) \n\t"
- "addl $8, %0 \n\t"
- "cmpl %4, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (ptr)
- : "r" ((int)buf - (int)ptr - w), "r" (-wrap), "r" (-wrap*3), "r" (ptr+width+2*w)
- );
- ptr= last_line + (i + 1) * wrap - w;
- asm volatile(
- "1: \n\t"
- "movq (%1, %0), %%mm0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm0, (%0, %2) \n\t"
- "movq %%mm0, (%0, %2, 2) \n\t"
- "movq %%mm0, (%0, %3) \n\t"
- "addl $8, %0 \n\t"
- "cmpl %4, %0 \n\t"
- " jb 1b \n\t"
- : "+r" (ptr)
- : "r" ((int)last_line - (int)ptr - w), "r" (wrap), "r" (wrap*3), "r" (ptr+width+2*w)
- );
- }
-}
-
-#undef HAVE_MMX2
-#define RENAME(a) a ## _MMX
-#include "mpegvideo_mmx_template.c"
-
-#define HAVE_MMX2
-#undef RENAME
-#define RENAME(a) a ## _MMX2
-#include "mpegvideo_mmx_template.c"
-
-void MPV_common_init_mmx(MpegEncContext *s)
-{
- if (mm_flags & MM_MMX) {
- const int dct_algo = s->avctx->dct_algo;
-
- s->dct_unquantize_h263 = dct_unquantize_h263_mmx;
- s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_mmx;
- s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_mmx;
-
- draw_edges = draw_edges_mmx;
-
- if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){
- if(mm_flags & MM_MMXEXT){
- s->dct_quantize= dct_quantize_MMX2;
- } else {
- s->dct_quantize= dct_quantize_MMX;
- }
- }
- }
-}
+++ /dev/null
-/*
- * MPEG video MMX templates
- *
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#undef SPREADW
-#undef PMAXW
-#ifdef HAVE_MMX2
-#define SPREADW(a) "pshufw $0, " #a ", " #a " \n\t"
-#define PMAXW(a,b) "pmaxsw " #a ", " #b " \n\t"
-
-#else
-#define SPREADW(a) \
- "punpcklwd " #a ", " #a " \n\t"\
- "punpcklwd " #a ", " #a " \n\t"
-#define PMAXW(a,b) \
- "psubusw " #a ", " #b " \n\t"\
- "paddw " #a ", " #b " \n\t"
-#endif
-
-static int RENAME(dct_quantize)(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow)
-{
- int level=0, last_non_zero_p1, q; //=0 is cuz gcc says uninitalized ...
- const uint16_t *qmat, *bias;
- __align8 int16_t temp_block[64];
-
- assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly?
-
- //s->fdct (block);
- ff_fdct_mmx (block); //cant be anything else ...
-
- if (s->mb_intra) {
- int dummy;
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- /* note: block[0] is assumed to be positive */
- if (!s->h263_aic) {
-#if 1
- asm volatile (
- "imul %%ecx \n\t"
- : "=d" (level), "=a"(dummy)
- : "a" ((block[0]>>2) + q), "c" (inverse[q<<1])
- );
-#else
- asm volatile (
- "xorl %%edx, %%edx \n\t"
- "divw %%cx \n\t"
- "movzwl %%ax, %%eax \n\t"
- : "=a" (level)
- : "a" ((block[0]>>2) + q), "c" (q<<1)
- : "%edx"
- );
-#endif
- } else
- /* For AIC we skip quant/dequant of INTRADC */
- level = (block[0] + 4)>>3;
-
- block[0]=0; //avoid fake overflow
-// temp_block[0] = (block[0] + (q >> 1)) / q;
- last_non_zero_p1 = 1;
- bias = s->q_intra_matrix16_bias[qscale];
- qmat = s->q_intra_matrix16[qscale];
- } else {
- last_non_zero_p1 = 0;
- bias = s->q_inter_matrix16_bias[qscale];
- qmat = s->q_inter_matrix16[qscale];
- }
-
- if(s->out_format == FMT_H263 && s->mpeg_quant==0){
-
- asm volatile(
- "movd %%eax, %%mm3 \n\t" // last_non_zero_p1
- SPREADW(%%mm3)
- "pxor %%mm7, %%mm7 \n\t" // 0
- "pxor %%mm4, %%mm4 \n\t" // 0
- "movq (%2), %%mm5 \n\t" // qmat[0]
- "pxor %%mm6, %%mm6 \n\t"
- "psubw (%3), %%mm6 \n\t" // -bias[0]
- "movl $-128, %%eax \n\t"
- ".balign 16 \n\t"
- "1: \n\t"
- "pxor %%mm1, %%mm1 \n\t" // 0
- "movq (%1, %%eax), %%mm0 \n\t" // block[i]
- "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00
- "pxor %%mm1, %%mm0 \n\t"
- "psubw %%mm1, %%mm0 \n\t" // ABS(block[i])
- "psubusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0]
- "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16
- "por %%mm0, %%mm4 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
- "movq %%mm0, (%5, %%eax) \n\t"
- "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00
- "movq (%4, %%eax), %%mm1 \n\t"
- "movq %%mm7, (%1, %%eax) \n\t" // 0
- "pandn %%mm1, %%mm0 \n\t"
- PMAXW(%%mm0, %%mm3)
- "addl $8, %%eax \n\t"
- " js 1b \n\t"
- "movq %%mm3, %%mm0 \n\t"
- "psrlq $32, %%mm3 \n\t"
- PMAXW(%%mm0, %%mm3)
- "movq %%mm3, %%mm0 \n\t"
- "psrlq $16, %%mm3 \n\t"
- PMAXW(%%mm0, %%mm3)
- "movd %%mm3, %%eax \n\t"
- "movzbl %%al, %%eax \n\t" // last_non_zero_p1
- : "+a" (last_non_zero_p1)
- : "r" (block+64), "r" (qmat), "r" (bias),
- "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
- );
- // note the asm is split cuz gcc doesnt like that many operands ...
- asm volatile(
- "movd %1, %%mm1 \n\t" // max_qcoeff
- SPREADW(%%mm1)
- "psubusw %%mm1, %%mm4 \n\t"
- "packuswb %%mm4, %%mm4 \n\t"
- "movd %%mm4, %0 \n\t" // *overflow
- : "=g" (*overflow)
- : "g" (s->max_qcoeff)
- );
- }else{ // FMT_H263
- asm volatile(
- "movd %%eax, %%mm3 \n\t" // last_non_zero_p1
- SPREADW(%%mm3)
- "pxor %%mm7, %%mm7 \n\t" // 0
- "pxor %%mm4, %%mm4 \n\t" // 0
- "movl $-128, %%eax \n\t"
- ".balign 16 \n\t"
- "1: \n\t"
- "pxor %%mm1, %%mm1 \n\t" // 0
- "movq (%1, %%eax), %%mm0 \n\t" // block[i]
- "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00
- "pxor %%mm1, %%mm0 \n\t"
- "psubw %%mm1, %%mm0 \n\t" // ABS(block[i])
- "movq (%3, %%eax), %%mm6 \n\t" // bias[0]
- "paddusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0]
- "movq (%2, %%eax), %%mm5 \n\t" // qmat[i]
- "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16
- "por %%mm0, %%mm4 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i])
- "movq %%mm0, (%5, %%eax) \n\t"
- "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00
- "movq (%4, %%eax), %%mm1 \n\t"
- "movq %%mm7, (%1, %%eax) \n\t" // 0
- "pandn %%mm1, %%mm0 \n\t"
- PMAXW(%%mm0, %%mm3)
- "addl $8, %%eax \n\t"
- " js 1b \n\t"
- "movq %%mm3, %%mm0 \n\t"
- "psrlq $32, %%mm3 \n\t"
- PMAXW(%%mm0, %%mm3)
- "movq %%mm3, %%mm0 \n\t"
- "psrlq $16, %%mm3 \n\t"
- PMAXW(%%mm0, %%mm3)
- "movd %%mm3, %%eax \n\t"
- "movzbl %%al, %%eax \n\t" // last_non_zero_p1
- : "+a" (last_non_zero_p1)
- : "r" (block+64), "r" (qmat+64), "r" (bias+64),
- "r" (inv_zigzag_direct16+64), "r" (temp_block+64)
- );
- // note the asm is split cuz gcc doesnt like that many operands ...
- asm volatile(
- "movd %1, %%mm1 \n\t" // max_qcoeff
- SPREADW(%%mm1)
- "psubusw %%mm1, %%mm4 \n\t"
- "packuswb %%mm4, %%mm4 \n\t"
- "movd %%mm4, %0 \n\t" // *overflow
- : "=g" (*overflow)
- : "g" (s->max_qcoeff)
- );
- }
-
- if(s->mb_intra) block[0]= level;
- else block[0]= temp_block[0];
-
- if(s->dsp.idct_permutation_type == FF_SIMPLE_IDCT_PERM){
- if(last_non_zero_p1 <= 1) goto end;
- block[0x08] = temp_block[0x01]; block[0x10] = temp_block[0x08];
- block[0x20] = temp_block[0x10];
- if(last_non_zero_p1 <= 4) goto end;
- block[0x18] = temp_block[0x09]; block[0x04] = temp_block[0x02];
- block[0x09] = temp_block[0x03];
- if(last_non_zero_p1 <= 7) goto end;
- block[0x14] = temp_block[0x0A]; block[0x28] = temp_block[0x11];
- block[0x12] = temp_block[0x18]; block[0x02] = temp_block[0x20];
- if(last_non_zero_p1 <= 11) goto end;
- block[0x1A] = temp_block[0x19]; block[0x24] = temp_block[0x12];
- block[0x19] = temp_block[0x0B]; block[0x01] = temp_block[0x04];
- block[0x0C] = temp_block[0x05];
- if(last_non_zero_p1 <= 16) goto end;
- block[0x11] = temp_block[0x0C]; block[0x29] = temp_block[0x13];
- block[0x16] = temp_block[0x1A]; block[0x0A] = temp_block[0x21];
- block[0x30] = temp_block[0x28]; block[0x22] = temp_block[0x30];
- block[0x38] = temp_block[0x29]; block[0x06] = temp_block[0x22];
- if(last_non_zero_p1 <= 24) goto end;
- block[0x1B] = temp_block[0x1B]; block[0x21] = temp_block[0x14];
- block[0x1C] = temp_block[0x0D]; block[0x05] = temp_block[0x06];
- block[0x0D] = temp_block[0x07]; block[0x15] = temp_block[0x0E];
- block[0x2C] = temp_block[0x15]; block[0x13] = temp_block[0x1C];
- if(last_non_zero_p1 <= 32) goto end;
- block[0x0B] = temp_block[0x23]; block[0x34] = temp_block[0x2A];
- block[0x2A] = temp_block[0x31]; block[0x32] = temp_block[0x38];
- block[0x3A] = temp_block[0x39]; block[0x26] = temp_block[0x32];
- block[0x39] = temp_block[0x2B]; block[0x03] = temp_block[0x24];
- if(last_non_zero_p1 <= 40) goto end;
- block[0x1E] = temp_block[0x1D]; block[0x25] = temp_block[0x16];
- block[0x1D] = temp_block[0x0F]; block[0x2D] = temp_block[0x17];
- block[0x17] = temp_block[0x1E]; block[0x0E] = temp_block[0x25];
- block[0x31] = temp_block[0x2C]; block[0x2B] = temp_block[0x33];
- if(last_non_zero_p1 <= 48) goto end;
- block[0x36] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
- block[0x23] = temp_block[0x34]; block[0x3C] = temp_block[0x2D];
- block[0x07] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
- block[0x0F] = temp_block[0x27]; block[0x35] = temp_block[0x2E];
- if(last_non_zero_p1 <= 56) goto end;
- block[0x2E] = temp_block[0x35]; block[0x33] = temp_block[0x3C];
- block[0x3E] = temp_block[0x3D]; block[0x27] = temp_block[0x36];
- block[0x3D] = temp_block[0x2F]; block[0x2F] = temp_block[0x37];
- block[0x37] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
- }else if(s->dsp.idct_permutation_type == FF_LIBMPEG2_IDCT_PERM){
- if(last_non_zero_p1 <= 1) goto end;
- block[0x04] = temp_block[0x01];
- block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
- if(last_non_zero_p1 <= 4) goto end;
- block[0x0C] = temp_block[0x09]; block[0x01] = temp_block[0x02];
- block[0x05] = temp_block[0x03];
- if(last_non_zero_p1 <= 7) goto end;
- block[0x09] = temp_block[0x0A]; block[0x14] = temp_block[0x11];
- block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
- if(last_non_zero_p1 <= 11) goto end;
- block[0x1C] = temp_block[0x19];
- block[0x11] = temp_block[0x12]; block[0x0D] = temp_block[0x0B];
- block[0x02] = temp_block[0x04]; block[0x06] = temp_block[0x05];
- if(last_non_zero_p1 <= 16) goto end;
- block[0x0A] = temp_block[0x0C]; block[0x15] = temp_block[0x13];
- block[0x19] = temp_block[0x1A]; block[0x24] = temp_block[0x21];
- block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
- block[0x2C] = temp_block[0x29]; block[0x21] = temp_block[0x22];
- if(last_non_zero_p1 <= 24) goto end;
- block[0x1D] = temp_block[0x1B]; block[0x12] = temp_block[0x14];
- block[0x0E] = temp_block[0x0D]; block[0x03] = temp_block[0x06];
- block[0x07] = temp_block[0x07]; block[0x0B] = temp_block[0x0E];
- block[0x16] = temp_block[0x15]; block[0x1A] = temp_block[0x1C];
- if(last_non_zero_p1 <= 32) goto end;
- block[0x25] = temp_block[0x23]; block[0x29] = temp_block[0x2A];
- block[0x34] = temp_block[0x31]; block[0x38] = temp_block[0x38];
- block[0x3C] = temp_block[0x39]; block[0x31] = temp_block[0x32];
- block[0x2D] = temp_block[0x2B]; block[0x22] = temp_block[0x24];
- if(last_non_zero_p1 <= 40) goto end;
- block[0x1E] = temp_block[0x1D]; block[0x13] = temp_block[0x16];
- block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
- block[0x1B] = temp_block[0x1E]; block[0x26] = temp_block[0x25];
- block[0x2A] = temp_block[0x2C]; block[0x35] = temp_block[0x33];
- if(last_non_zero_p1 <= 48) goto end;
- block[0x39] = temp_block[0x3A]; block[0x3D] = temp_block[0x3B];
- block[0x32] = temp_block[0x34]; block[0x2E] = temp_block[0x2D];
- block[0x23] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
- block[0x27] = temp_block[0x27]; block[0x2B] = temp_block[0x2E];
- if(last_non_zero_p1 <= 56) goto end;
- block[0x36] = temp_block[0x35]; block[0x3A] = temp_block[0x3C];
- block[0x3E] = temp_block[0x3D]; block[0x33] = temp_block[0x36];
- block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
- block[0x3B] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
- }else{
- if(last_non_zero_p1 <= 1) goto end;
- block[0x01] = temp_block[0x01];
- block[0x08] = temp_block[0x08]; block[0x10] = temp_block[0x10];
- if(last_non_zero_p1 <= 4) goto end;
- block[0x09] = temp_block[0x09]; block[0x02] = temp_block[0x02];
- block[0x03] = temp_block[0x03];
- if(last_non_zero_p1 <= 7) goto end;
- block[0x0A] = temp_block[0x0A]; block[0x11] = temp_block[0x11];
- block[0x18] = temp_block[0x18]; block[0x20] = temp_block[0x20];
- if(last_non_zero_p1 <= 11) goto end;
- block[0x19] = temp_block[0x19];
- block[0x12] = temp_block[0x12]; block[0x0B] = temp_block[0x0B];
- block[0x04] = temp_block[0x04]; block[0x05] = temp_block[0x05];
- if(last_non_zero_p1 <= 16) goto end;
- block[0x0C] = temp_block[0x0C]; block[0x13] = temp_block[0x13];
- block[0x1A] = temp_block[0x1A]; block[0x21] = temp_block[0x21];
- block[0x28] = temp_block[0x28]; block[0x30] = temp_block[0x30];
- block[0x29] = temp_block[0x29]; block[0x22] = temp_block[0x22];
- if(last_non_zero_p1 <= 24) goto end;
- block[0x1B] = temp_block[0x1B]; block[0x14] = temp_block[0x14];
- block[0x0D] = temp_block[0x0D]; block[0x06] = temp_block[0x06];
- block[0x07] = temp_block[0x07]; block[0x0E] = temp_block[0x0E];
- block[0x15] = temp_block[0x15]; block[0x1C] = temp_block[0x1C];
- if(last_non_zero_p1 <= 32) goto end;
- block[0x23] = temp_block[0x23]; block[0x2A] = temp_block[0x2A];
- block[0x31] = temp_block[0x31]; block[0x38] = temp_block[0x38];
- block[0x39] = temp_block[0x39]; block[0x32] = temp_block[0x32];
- block[0x2B] = temp_block[0x2B]; block[0x24] = temp_block[0x24];
- if(last_non_zero_p1 <= 40) goto end;
- block[0x1D] = temp_block[0x1D]; block[0x16] = temp_block[0x16];
- block[0x0F] = temp_block[0x0F]; block[0x17] = temp_block[0x17];
- block[0x1E] = temp_block[0x1E]; block[0x25] = temp_block[0x25];
- block[0x2C] = temp_block[0x2C]; block[0x33] = temp_block[0x33];
- if(last_non_zero_p1 <= 48) goto end;
- block[0x3A] = temp_block[0x3A]; block[0x3B] = temp_block[0x3B];
- block[0x34] = temp_block[0x34]; block[0x2D] = temp_block[0x2D];
- block[0x26] = temp_block[0x26]; block[0x1F] = temp_block[0x1F];
- block[0x27] = temp_block[0x27]; block[0x2E] = temp_block[0x2E];
- if(last_non_zero_p1 <= 56) goto end;
- block[0x35] = temp_block[0x35]; block[0x3C] = temp_block[0x3C];
- block[0x3D] = temp_block[0x3D]; block[0x36] = temp_block[0x36];
- block[0x2F] = temp_block[0x2F]; block[0x37] = temp_block[0x37];
- block[0x3E] = temp_block[0x3E]; block[0x3F] = temp_block[0x3F];
- }
- end:
-/*
- for(i=0; i<last_non_zero_p1; i++)
- {
- int j= zigzag_direct_noperm[i];
- block[block_permute_op(j)]= temp_block[j];
- }
-*/
-
- return last_non_zero_p1 - 1;
-}
+++ /dev/null
-/*
- * Simple IDCT MMX
- *
- * Copyright (c) 2001, 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "../dsputil.h"
-
-/*
-23170.475006
-22725.260826
-21406.727617
-19265.545870
-16384.000000
-12872.826198
-8866.956905
-4520.335430
-*/
-#define C0 23170 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define C1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define C2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define C3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#if 0
-#define C4 16384 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#else
-#define C4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5
-#endif
-#define C5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define C6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define C7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-
-#define ROW_SHIFT 11
-#define COL_SHIFT 20 // 6
-
-static const uint64_t __attribute__((aligned(8))) wm1010= 0xFFFF0000FFFF0000ULL;
-static const uint64_t __attribute__((aligned(8))) d40000= 0x0000000000040000ULL;
-
-static const int16_t __attribute__((aligned(8))) coeffs[]= {
- 1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0,
-// 1<<(COL_SHIFT-1), 0, 1<<(COL_SHIFT-1), 0,
-// 0, 1<<(COL_SHIFT-1-16), 0, 1<<(COL_SHIFT-1-16),
- 1<<(ROW_SHIFT-1), 1, 1<<(ROW_SHIFT-1), 0,
- // the 1 = ((1<<(COL_SHIFT-1))/C4)<<ROW_SHIFT :)
-// 0, 0, 0, 0,
-// 0, 0, 0, 0,
-
- C4, C4, C4, C4,
- C4, -C4, C4, -C4,
-
- C2, C6, C2, C6,
- C6, -C2, C6, -C2,
-
- C1, C3, C1, C3,
- C5, C7, C5, C7,
-
- C3, -C7, C3, -C7,
--C1, -C5, -C1, -C5,
-
- C5, -C1, C5, -C1,
- C7, C3, C7, C3,
-
- C7, -C5, C7, -C5,
- C3, -C1, C3, -C1
-};
-
-#if 0
-static void unused_var_killer(){
- int a= wm1010 + d40000;
- temp[0]=a;
-}
-
-static void inline idctCol (int16_t * col, int16_t *input)
-{
-#undef C0
-#undef C1
-#undef C2
-#undef C3
-#undef C4
-#undef C5
-#undef C6
-#undef C7
- int a0, a1, a2, a3, b0, b1, b2, b3;
- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-/*
- if( !(col[8*1] | col[8*2] |col[8*3] |col[8*4] |col[8*5] |col[8*6] | col[8*7])) {
- col[8*0] = col[8*1] = col[8*2] = col[8*3] = col[8*4] =
- col[8*5] = col[8*6] = col[8*7] = col[8*0]<<3;
- return;
- }*/
-
-col[8*0] = input[8*0 + 0];
-col[8*1] = input[8*2 + 0];
-col[8*2] = input[8*0 + 1];
-col[8*3] = input[8*2 + 1];
-col[8*4] = input[8*4 + 0];
-col[8*5] = input[8*6 + 0];
-col[8*6] = input[8*4 + 1];
-col[8*7] = input[8*6 + 1];
-
- a0 = C4*col[8*0] + C2*col[8*2] + C4*col[8*4] + C6*col[8*6] + (1<<(COL_SHIFT-1));
- a1 = C4*col[8*0] + C6*col[8*2] - C4*col[8*4] - C2*col[8*6] + (1<<(COL_SHIFT-1));
- a2 = C4*col[8*0] - C6*col[8*2] - C4*col[8*4] + C2*col[8*6] + (1<<(COL_SHIFT-1));
- a3 = C4*col[8*0] - C2*col[8*2] + C4*col[8*4] - C6*col[8*6] + (1<<(COL_SHIFT-1));
-
- b0 = C1*col[8*1] + C3*col[8*3] + C5*col[8*5] + C7*col[8*7];
- b1 = C3*col[8*1] - C7*col[8*3] - C1*col[8*5] - C5*col[8*7];
- b2 = C5*col[8*1] - C1*col[8*3] + C7*col[8*5] + C3*col[8*7];
- b3 = C7*col[8*1] - C5*col[8*3] + C3*col[8*5] - C1*col[8*7];
-
- col[8*0] = (a0 + b0) >> COL_SHIFT;
- col[8*1] = (a1 + b1) >> COL_SHIFT;
- col[8*2] = (a2 + b2) >> COL_SHIFT;
- col[8*3] = (a3 + b3) >> COL_SHIFT;
- col[8*4] = (a3 - b3) >> COL_SHIFT;
- col[8*5] = (a2 - b2) >> COL_SHIFT;
- col[8*6] = (a1 - b1) >> COL_SHIFT;
- col[8*7] = (a0 - b0) >> COL_SHIFT;
-}
-
-static void inline idctRow (int16_t * output, int16_t * input)
-{
- int16_t row[8];
-
- int a0, a1, a2, a3, b0, b1, b2, b3;
- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-
-row[0] = input[0];
-row[2] = input[1];
-row[4] = input[4];
-row[6] = input[5];
-row[1] = input[8];
-row[3] = input[9];
-row[5] = input[12];
-row[7] = input[13];
-
- if( !(row[1] | row[2] |row[3] |row[4] |row[5] |row[6] | row[7]) ) {
- row[0] = row[1] = row[2] = row[3] = row[4] =
- row[5] = row[6] = row[7] = row[0]<<3;
- output[0] = row[0];
- output[2] = row[1];
- output[4] = row[2];
- output[6] = row[3];
- output[8] = row[4];
- output[10] = row[5];
- output[12] = row[6];
- output[14] = row[7];
- return;
- }
-
- a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + (1<<(ROW_SHIFT-1));
- a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + (1<<(ROW_SHIFT-1));
- a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + (1<<(ROW_SHIFT-1));
- a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + (1<<(ROW_SHIFT-1));
-
- b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
- b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
- b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
- b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
-
- output[0] = row[0];
- output[2] = row[1];
- output[4] = row[2];
- output[6] = row[3];
- output[8] = row[4];
- output[10] = row[5];
- output[12] = row[6];
- output[14] = row[7];
-}
-#endif
-
-static inline void idct(int16_t *block)
-{
- int64_t __attribute__((aligned(8))) align_tmp[16];
- int16_t * const temp= (int16_t*)align_tmp;
-
- asm volatile(
-#if 0 //Alternative, simpler variant
-
-#define ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq 56(%2), %%mm5 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm0, %%mm0 \n\t" \
- "psubd %%mm1, %%mm0 \n\t" /* A2 a2 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm5, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm5 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm5 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm1, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm5, %%mm1 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm5, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm7 \n\t" /* A1+B1 a1+b1 A0+B0 a0+b0 */\
- "packssdw %%mm4, %%mm2 \n\t" /* A0-B0 a0-b0 A1-B1 a1-b1 */\
- "movq %%mm7, " #dst " \n\t"\
- "movq " #src1 ", %%mm1 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "movq %%mm2, 24+" #dst " \n\t"\
- "pmaddwd %%mm1, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm1 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm0, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm0 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm1, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm6, %%mm2 \n\t" /* A3+B3 a3+b3 A2+B2 a2+b2 */\
- "movq %%mm2, 8+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm0, %%mm4 \n\t" /* A2-B2 a2-b2 A3-B3 a3-b3 */\
- "movq %%mm4, 16+" #dst " \n\t"\
-
-#define COL_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- #rounder ", %%mm0 \n\t"\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1 a1 */\
- "psubd %%mm1, %%mm5 \n\t" /* A2 a2 */\
- "movq 56(%2), %%mm1 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm1, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm1 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm1 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm1, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm7, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm7, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm2, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq " #src1 ", %%mm0 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm0 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm5, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm0, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm2, 32+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm4, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"\
-
-
-#define DC_COND_ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq "MANGLE(wm1010)", %%mm4 \n\t"\
- "pand %%mm0, %%mm4 \n\t"\
- "por %%mm1, %%mm4 \n\t"\
- "por %%mm2, %%mm4 \n\t"\
- "por %%mm3, %%mm4 \n\t"\
- "packssdw %%mm4,%%mm4 \n\t"\
- "movd %%mm4, %%eax \n\t"\
- "orl %%eax, %%eax \n\t"\
- "jz 1f \n\t"\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq 56(%2), %%mm5 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm0, %%mm0 \n\t" \
- "psubd %%mm1, %%mm0 \n\t" /* A2 a2 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm5, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm5 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm5 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm1, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm5, %%mm1 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm5, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm7 \n\t" /* A1+B1 a1+b1 A0+B0 a0+b0 */\
- "packssdw %%mm4, %%mm2 \n\t" /* A0-B0 a0-b0 A1-B1 a1-b1 */\
- "movq %%mm7, " #dst " \n\t"\
- "movq " #src1 ", %%mm1 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "movq %%mm2, 24+" #dst " \n\t"\
- "pmaddwd %%mm1, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm1 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm0, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm0 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm1, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm6, %%mm2 \n\t" /* A3+B3 a3+b3 A2+B2 a2+b2 */\
- "movq %%mm2, 8+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm0, %%mm4 \n\t" /* A2-B2 a2-b2 A3-B3 a3-b3 */\
- "movq %%mm4, 16+" #dst " \n\t"\
- "jmp 2f \n\t"\
- "1: \n\t"\
- "pslld $16, %%mm0 \n\t"\
- "#paddd "MANGLE(d40000)", %%mm0 \n\t"\
- "psrad $13, %%mm0 \n\t"\
- "packssdw %%mm0, %%mm0 \n\t"\
- "movq %%mm0, " #dst " \n\t"\
- "movq %%mm0, 8+" #dst " \n\t"\
- "movq %%mm0, 16+" #dst " \n\t"\
- "movq %%mm0, 24+" #dst " \n\t"\
- "2: \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-ROW_IDCT( (%0), 8(%0), 16(%0), 24(%0), 0(%1),paddd 8(%2), 11)
-/*ROW_IDCT( 32(%0), 40(%0), 48(%0), 56(%0), 32(%1), paddd (%2), 11)
-ROW_IDCT( 64(%0), 72(%0), 80(%0), 88(%0), 64(%1), paddd (%2), 11)
-ROW_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1), paddd (%2), 11)*/
-
-DC_COND_ROW_IDCT( 32(%0), 40(%0), 48(%0), 56(%0), 32(%1),paddd (%2), 11)
-DC_COND_ROW_IDCT( 64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11)
-DC_COND_ROW_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11)
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-COL_IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-COL_IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-COL_IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-COL_IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
-
-#else
-
-#define DC_COND_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq "MANGLE(wm1010)", %%mm4 \n\t"\
- "pand %%mm0, %%mm4 \n\t"\
- "por %%mm1, %%mm4 \n\t"\
- "por %%mm2, %%mm4 \n\t"\
- "por %%mm3, %%mm4 \n\t"\
- "packssdw %%mm4,%%mm4 \n\t"\
- "movd %%mm4, %%eax \n\t"\
- "orl %%eax, %%eax \n\t"\
- "jz 1f \n\t"\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq 56(%2), %%mm5 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm0, %%mm0 \n\t" \
- "psubd %%mm1, %%mm0 \n\t" /* A2 a2 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm5, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm5 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm5 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm1, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm5, %%mm1 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm5, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm7 \n\t" /* A1+B1 a1+b1 A0+B0 a0+b0 */\
- "packssdw %%mm4, %%mm2 \n\t" /* A0-B0 a0-b0 A1-B1 a1-b1 */\
- "movq %%mm7, " #dst " \n\t"\
- "movq " #src1 ", %%mm1 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "movq %%mm2, 24+" #dst " \n\t"\
- "pmaddwd %%mm1, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm1 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm0, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm0 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm1, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm6, %%mm2 \n\t" /* A3+B3 a3+b3 A2+B2 a2+b2 */\
- "movq %%mm2, 8+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm0, %%mm4 \n\t" /* A2-B2 a2-b2 A3-B3 a3-b3 */\
- "movq %%mm4, 16+" #dst " \n\t"\
- "jmp 2f \n\t"\
- "1: \n\t"\
- "pslld $16, %%mm0 \n\t"\
- "paddd "MANGLE(d40000)", %%mm0 \n\t"\
- "psrad $13, %%mm0 \n\t"\
- "packssdw %%mm0, %%mm0 \n\t"\
- "movq %%mm0, " #dst " \n\t"\
- "movq %%mm0, 8+" #dst " \n\t"\
- "movq %%mm0, 16+" #dst " \n\t"\
- "movq %%mm0, 24+" #dst " \n\t"\
- "2: \n\t"
-
-#define Z_COND_IDCT(src0, src4, src1, src5, dst, rounder, shift, bt) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq %%mm0, %%mm4 \n\t"\
- "por %%mm1, %%mm4 \n\t"\
- "por %%mm2, %%mm4 \n\t"\
- "por %%mm3, %%mm4 \n\t"\
- "packssdw %%mm4,%%mm4 \n\t"\
- "movd %%mm4, %%eax \n\t"\
- "orl %%eax, %%eax \n\t"\
- "jz " #bt " \n\t"\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq 56(%2), %%mm5 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm0, %%mm0 \n\t" \
- "psubd %%mm1, %%mm0 \n\t" /* A2 a2 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm5, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm5 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm5 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm1, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm5, %%mm1 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm5, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm7 \n\t" /* A1+B1 a1+b1 A0+B0 a0+b0 */\
- "packssdw %%mm4, %%mm2 \n\t" /* A0-B0 a0-b0 A1-B1 a1-b1 */\
- "movq %%mm7, " #dst " \n\t"\
- "movq " #src1 ", %%mm1 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "movq %%mm2, 24+" #dst " \n\t"\
- "pmaddwd %%mm1, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm1 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm0, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm0 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm1, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm6, %%mm2 \n\t" /* A3+B3 a3+b3 A2+B2 a2+b2 */\
- "movq %%mm2, 8+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm0, %%mm4 \n\t" /* A2-B2 a2-b2 A3-B3 a3-b3 */\
- "movq %%mm4, 16+" #dst " \n\t"\
-
-#define ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq 56(%2), %%mm5 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm0, %%mm0 \n\t" \
- "psubd %%mm1, %%mm0 \n\t" /* A2 a2 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm5, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm5 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm5 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm5 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm1, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm5, %%mm1 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm5, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm7 \n\t" /* A1+B1 a1+b1 A0+B0 a0+b0 */\
- "packssdw %%mm4, %%mm2 \n\t" /* A0-B0 a0-b0 A1-B1 a1-b1 */\
- "movq %%mm7, " #dst " \n\t"\
- "movq " #src1 ", %%mm1 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "movq %%mm2, 24+" #dst " \n\t"\
- "pmaddwd %%mm1, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm1 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm0, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm0 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm1, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm6, %%mm2 \n\t" /* A3+B3 a3+b3 A2+B2 a2+b2 */\
- "movq %%mm2, 8+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm0, %%mm4 \n\t" /* A2-B2 a2-b2 A3-B3 a3-b3 */\
- "movq %%mm4, 16+" #dst " \n\t"\
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-DC_COND_IDCT( 0(%0), 8(%0), 16(%0), 24(%0), 0(%1),paddd 8(%2), 11)
-Z_COND_IDCT( 32(%0), 40(%0), 48(%0), 56(%0), 32(%1),paddd (%2), 11, 4f)
-Z_COND_IDCT( 64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11, 2f)
-Z_COND_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 1f)
-
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- #rounder ", %%mm0 \n\t"\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1 a1 */\
- "psubd %%mm1, %%mm5 \n\t" /* A2 a2 */\
- "movq 56(%2), %%mm1 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm1, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm1 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm1 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm1, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm7, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm7, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm2, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq " #src1 ", %%mm0 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm0 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm5, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm0, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm2, 32+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm4, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
- "#.balign 16 \n\t"\
- "4: \n\t"
-Z_COND_IDCT( 64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11, 6f)
-Z_COND_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 5f)
-
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- #rounder ", %%mm0 \n\t"\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1 a1 */\
- "psubd %%mm1, %%mm5 \n\t" /* A2 a2 */\
- "movq 56(%2), %%mm1 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- "movq 72(%2), %%mm7 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm1 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm1, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm7, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm7, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm1, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm2, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq 88(%2), %%mm1 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm5, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm1, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm1, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm1 \n\t" /* A3 a3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm1 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm1 \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm2, 32+" #dst " \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm1, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
- "#.balign 16 \n\t"\
- "6: \n\t"
-Z_COND_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 7f)
-
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- #rounder ", %%mm0 \n\t"\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 56(%2), %%mm1 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- "movq 72(%2), %%mm7 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm1 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm1, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm7, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm7, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm1, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm2, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq 88(%2), %%mm1 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm5, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm1, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm1, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm1 \n\t" /* A3 a3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm1 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm1 \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm2, 32+" #dst " \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm1, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
- "#.balign 16 \n\t"\
- "2: \n\t"
-Z_COND_IDCT( 96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 3f)
-
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq " #src5 ", %%mm3 \n\t" /* R7 R5 r7 r5 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- #rounder ", %%mm0 \n\t"\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 56(%2), %%mm1 \n\t" /* C7 C5 C7 C5 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* C7R7+C5R5 C7r7+C5r5 */\
- "pmaddwd 64(%2), %%mm2 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm1, %%mm7 \n\t" /* B0 b0 */\
- "movq 72(%2), %%mm1 \n\t" /* -C5 -C1 -C5 -C1 */\
- "pmaddwd %%mm3, %%mm1 \n\t" /* -C5R7-C1R5 -C5r7-C1r5 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "paddd %%mm2, %%mm1 \n\t" /* B1 b1 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm2 \n\t" /* A1 a1 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm1, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm7, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm7, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm2, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq " #src1 ", %%mm0 \n\t" /* R3 R1 r3 r1 */\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "movq 88(%2), %%mm7 \n\t" /* C3 C7 C3 C7 */\
- "pmaddwd 96(%2), %%mm0 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C3R7+C7R5 C3r7+C7r5 */\
- "movq %%mm5, %%mm2 \n\t" /* A2 a2 */\
- "pmaddwd 104(%2), %%mm3 \n\t" /* -C1R7+C3R5 -C1r7+C3r5 */\
- "paddd %%mm7, %%mm4 \n\t" /* B2 b2 */\
- "paddd %%mm4, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm0, %%mm3 \n\t" /* B3 b3 */\
- "paddd %%mm3, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm3, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm2, %%mm2 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm2, 32+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm4, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
- "#.balign 16 \n\t"\
- "3: \n\t"
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- #rounder ", %%mm0 \n\t"\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 64(%2), %%mm3 \n\t"\
- "pmaddwd %%mm2, %%mm3 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm1 \n\t" /* A1 a1 */\
- "paddd %%mm3, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm3, %%mm1 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm1 \n\t"\
- "packssdw %%mm7, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm7, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm1, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "pmaddwd %%mm2, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "pmaddwd 96(%2), %%mm2 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "movq %%mm5, %%mm1 \n\t" /* A2 a2 */\
- "paddd %%mm4, %%mm1 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm1 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm2, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm2, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm1, %%mm1 \n\t" /* A2+B2 a2+b2 */\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm1, 32+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "movd %%mm4, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
- "#.balign 16 \n\t"\
- "5: \n\t"
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- #rounder ", %%mm0 \n\t"\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1 a1 */\
- "psubd %%mm1, %%mm5 \n\t" /* A2 a2 */\
- "movq 8+" #src0 ", %%mm2 \n\t" /* R4 R0 r4 r0 */\
- "movq 8+" #src4 ", %%mm3 \n\t" /* R6 R2 r6 r2 */\
- "movq 16(%2), %%mm1 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm2, %%mm1 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm7 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm7, %%mm2 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm7 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm3, %%mm7 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "pmaddwd 40(%2), %%mm3 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm1 \n\t"\
- "paddd %%mm1, %%mm7 \n\t" /* A0 a0 */\
- "paddd %%mm1, %%mm1 \n\t" /* 2C0 2c0 */\
- #rounder ", %%mm2 \n\t"\
- "psubd %%mm7, %%mm1 \n\t" /* A3 a3 */\
- "paddd %%mm2, %%mm3 \n\t" /* A1 a1 */\
- "paddd %%mm2, %%mm2 \n\t" /* 2C1 2c1 */\
- "psubd %%mm3, %%mm2 \n\t" /* A2 a2 */\
- "psrad $" #shift ", %%mm4 \n\t"\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm3 \n\t"\
- "packssdw %%mm7, %%mm4 \n\t" /* A0 a0 */\
- "movq %%mm4, " #dst " \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "packssdw %%mm3, %%mm0 \n\t" /* A1 a1 */\
- "movq %%mm0, 16+" #dst " \n\t"\
- "movq %%mm0, 96+" #dst " \n\t"\
- "movq %%mm4, 112+" #dst " \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "psrad $" #shift ", %%mm6 \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm2, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movq %%mm5, 32+" #dst " \n\t"\
- "psrad $" #shift ", %%mm1 \n\t"\
- "packssdw %%mm1, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movq %%mm6, 48+" #dst " \n\t"\
- "movq %%mm6, 64+" #dst " \n\t"\
- "movq %%mm5, 80+" #dst " \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( 0(%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-//IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-//IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
-
- "#.balign 16 \n\t"\
- "1: \n\t"
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq " #src4 ", %%mm1 \n\t" /* R6 R2 r6 r2 */\
- "movq " #src1 ", %%mm2 \n\t" /* R3 R1 r3 r1 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm5 \n\t" /* C6 C2 C6 C2 */\
- "pmaddwd %%mm1, %%mm5 \n\t" /* C6R6+C2R2 C6r6+C2r2 */\
- "movq 40(%2), %%mm6 \n\t" /* -C2 C6 -C2 C6 */\
- "pmaddwd %%mm6, %%mm1 \n\t" /* -C2R6+C6R2 -C2r6+C6r2 */\
- #rounder ", %%mm4 \n\t"\
- "movq %%mm4, %%mm6 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 48(%2), %%mm7 \n\t" /* C3 C1 C3 C1 */\
- #rounder ", %%mm0 \n\t"\
- "pmaddwd %%mm2, %%mm7 \n\t" /* C3R3+C1R1 C3r3+C1r1 */\
- "paddd %%mm5, %%mm4 \n\t" /* A0 a0 */\
- "psubd %%mm5, %%mm6 \n\t" /* A3 a3 */\
- "movq %%mm0, %%mm5 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1 a1 */\
- "psubd %%mm1, %%mm5 \n\t" /* A2 a2 */\
- "movq 64(%2), %%mm1 \n\t"\
- "pmaddwd %%mm2, %%mm1 \n\t" /* -C7R3+C3R1 -C7r3+C3r1 */\
- "paddd %%mm4, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "paddd %%mm4, %%mm4 \n\t" /* 2A0 2a0 */\
- "psubd %%mm7, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "psrad $" #shift ", %%mm7 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "movq %%mm0, %%mm3 \n\t" /* A1 a1 */\
- "paddd %%mm1, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "psubd %%mm1, %%mm3 \n\t" /* A1-B1 a1-b1 */\
- "psrad $" #shift ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm3 \n\t"\
- "packssdw %%mm7, %%mm7 \n\t" /* A0+B0 a0+b0 */\
- "movd %%mm7, " #dst " \n\t"\
- "packssdw %%mm0, %%mm0 \n\t" /* A1+B1 a1+b1 */\
- "movd %%mm0, 16+" #dst " \n\t"\
- "packssdw %%mm3, %%mm3 \n\t" /* A1-B1 a1-b1 */\
- "movd %%mm3, 96+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A0-B0 a0-b0 */\
- "movd %%mm4, 112+" #dst " \n\t"\
- "movq 80(%2), %%mm4 \n\t" /* -C1 C5 -C1 C5 */\
- "pmaddwd %%mm2, %%mm4 \n\t" /* -C1R3+C5R1 -C1r3+C5r1 */\
- "pmaddwd 96(%2), %%mm2 \n\t" /* -C5R3+C7R1 -C5r3+C7r1 */\
- "movq %%mm5, %%mm3 \n\t" /* A2 a2 */\
- "paddd %%mm4, %%mm3 \n\t" /* A2+B2 a2+b2 */\
- "psubd %%mm4, %%mm5 \n\t" /* a2-B2 a2-b2 */\
- "psrad $" #shift ", %%mm3 \n\t"\
- "psrad $" #shift ", %%mm5 \n\t"\
- "movq %%mm6, %%mm4 \n\t" /* A3 a3 */\
- "paddd %%mm2, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "psubd %%mm2, %%mm4 \n\t" /* a3-B3 a3-b3 */\
- "psrad $" #shift ", %%mm6 \n\t"\
- "packssdw %%mm3, %%mm3 \n\t" /* A2+B2 a2+b2 */\
- "movd %%mm3, 32+" #dst " \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "packssdw %%mm6, %%mm6 \n\t" /* A3+B3 a3+b3 */\
- "movd %%mm6, 48+" #dst " \n\t"\
- "packssdw %%mm4, %%mm4 \n\t" /* A3-B3 a3-b3 */\
- "packssdw %%mm5, %%mm5 \n\t" /* A2-B2 a2-b2 */\
- "movd %%mm4, 64+" #dst " \n\t"\
- "movd %%mm5, 80+" #dst " \n\t"
-
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( (%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
- "jmp 9f \n\t"
-
-
- "#.balign 16 \n\t"
- "7: \n\t"
-#undef IDCT
-#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
- "movq " #src0 ", %%mm0 \n\t" /* R4 R0 r4 r0 */\
- "movq 16(%2), %%mm4 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm0, %%mm4 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm5 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm5, %%mm0 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- #rounder ", %%mm4 \n\t"\
- #rounder ", %%mm0 \n\t"\
- "psrad $" #shift ", %%mm4 \n\t"\
- "psrad $" #shift ", %%mm0 \n\t"\
- "movq 8+" #src0 ", %%mm2 \n\t" /* R4 R0 r4 r0 */\
- "movq 16(%2), %%mm1 \n\t" /* C4 C4 C4 C4 */\
- "pmaddwd %%mm2, %%mm1 \n\t" /* C4R4+C4R0 C4r4+C4r0 */\
- "movq 24(%2), %%mm7 \n\t" /* -C4 C4 -C4 C4 */\
- "pmaddwd %%mm7, %%mm2 \n\t" /* -C4R4+C4R0 -C4r4+C4r0 */\
- "movq 32(%2), %%mm7 \n\t" /* C6 C2 C6 C2 */\
- #rounder ", %%mm1 \n\t"\
- #rounder ", %%mm2 \n\t"\
- "psrad $" #shift ", %%mm1 \n\t"\
- "packssdw %%mm1, %%mm4 \n\t" /* A0 a0 */\
- "movq %%mm4, " #dst " \n\t"\
- "psrad $" #shift ", %%mm2 \n\t"\
- "packssdw %%mm2, %%mm0 \n\t" /* A1 a1 */\
- "movq %%mm0, 16+" #dst " \n\t"\
- "movq %%mm0, 96+" #dst " \n\t"\
- "movq %%mm4, 112+" #dst " \n\t"\
- "movq %%mm0, 32+" #dst " \n\t"\
- "movq %%mm4, 48+" #dst " \n\t"\
- "movq %%mm4, 64+" #dst " \n\t"\
- "movq %%mm0, 80+" #dst " \n\t"
-
-//IDCT( src0, src4, src1, src5, dst, rounder, shift)
-IDCT( 0(%1), 64(%1), 32(%1), 96(%1), 0(%0),/nop, 20)
-//IDCT( 8(%1), 72(%1), 40(%1), 104(%1), 4(%0),/nop, 20)
-IDCT( 16(%1), 80(%1), 48(%1), 112(%1), 8(%0),/nop, 20)
-//IDCT( 24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
-
-
-#endif
-
-/*
-Input
- 00 40 04 44 20 60 24 64
- 10 30 14 34 50 70 54 74
- 01 41 03 43 21 61 23 63
- 11 31 13 33 51 71 53 73
- 02 42 06 46 22 62 26 66
- 12 32 16 36 52 72 56 76
- 05 45 07 47 25 65 27 67
- 15 35 17 37 55 75 57 77
-
-Temp
- 00 04 10 14 20 24 30 34
- 40 44 50 54 60 64 70 74
- 01 03 11 13 21 23 31 33
- 41 43 51 53 61 63 71 73
- 02 06 12 16 22 26 32 36
- 42 46 52 56 62 66 72 76
- 05 07 15 17 25 27 35 37
- 45 47 55 57 65 67 75 77
-*/
-
-"9: \n\t"
- :: "r" (block), "r" (temp), "r" (coeffs)
- : "%eax"
- );
-}
-
-void ff_simple_idct_mmx(int16_t *block)
-{
- idct(block);
-}
-
-//FIXME merge add/put into the idct
-
-void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block)
-{
- idct(block);
- put_pixels_clamped_mmx(block, dest, line_size);
-}
-void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block)
-{
- idct(block);
- add_pixels_clamped_mmx(block, dest, line_size);
-}
+++ /dev/null
-/*
- * Misc image convertion routines
- * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file imgconvert.c
- * Misc image convertion routines.
- */
-
-/* TODO:
- * - write 'ffimg' program to test all the image related stuff
- * - move all api to slice based system
- * - integrate deinterlacing, postprocessing and scaling in the conversion process
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-
-#ifdef HAVE_MMX
-#include "i386/mmx.h"
-#endif
-
-#define xglue(x, y) x ## y
-#define glue(x, y) xglue(x, y)
-
-#define FF_COLOR_RGB 0 /* RGB color space */
-#define FF_COLOR_GRAY 1 /* gray color space */
-#define FF_COLOR_YUV 2 /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
-#define FF_COLOR_YUV_JPEG 3 /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
-
-#define FF_PIXEL_PLANAR 0 /* each channel has one component in AVPicture */
-#define FF_PIXEL_PACKED 1 /* only one components containing all the channels */
-#define FF_PIXEL_PALETTE 2 /* one components containing indexes for a palette */
-
-typedef struct PixFmtInfo {
- const char *name;
- uint8_t nb_channels; /* number of channels (including alpha) */
- uint8_t color_type; /* color type (see FF_COLOR_xxx constants) */
- uint8_t pixel_type; /* pixel storage type (see FF_PIXEL_xxx constants) */
- uint8_t is_alpha : 1; /* true if alpha can be specified */
- uint8_t x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */
- uint8_t y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */
- uint8_t depth; /* bit depth of the color components */
-} PixFmtInfo;
-
-/* this table gives more information about formats */
-static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
- /* YUV formats */
- [PIX_FMT_YUV420P] = {
- .name = "yuv420p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 1, .y_chroma_shift = 1,
- },
- [PIX_FMT_YUV422P] = {
- .name = "yuv422p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 1, .y_chroma_shift = 0,
- },
- [PIX_FMT_YUV444P] = {
- .name = "yuv444p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 0, .y_chroma_shift = 0,
- },
- [PIX_FMT_YUV422] = {
- .name = "yuv422",
- .nb_channels = 1,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
- .x_chroma_shift = 1, .y_chroma_shift = 0,
- },
- [PIX_FMT_YUV410P] = {
- .name = "yuv410p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 2, .y_chroma_shift = 2,
- },
- [PIX_FMT_YUV411P] = {
- .name = "yuv411p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 2, .y_chroma_shift = 0,
- },
-
- /* JPEG YUV */
- [PIX_FMT_YUVJ420P] = {
- .name = "yuvj420p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 1, .y_chroma_shift = 1,
- },
- [PIX_FMT_YUVJ422P] = {
- .name = "yuvj422p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 1, .y_chroma_shift = 0,
- },
- [PIX_FMT_YUVJ444P] = {
- .name = "yuvj444p",
- .nb_channels = 3,
- .color_type = FF_COLOR_YUV_JPEG,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- .x_chroma_shift = 0, .y_chroma_shift = 0,
- },
-
- /* RGB formats */
- [PIX_FMT_RGB24] = {
- .name = "rgb24",
- .nb_channels = 3,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
- },
- [PIX_FMT_BGR24] = {
- .name = "bgr24",
- .nb_channels = 3,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
- },
- [PIX_FMT_RGBA32] = {
- .name = "rgba32",
- .nb_channels = 4, .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 8,
- },
- [PIX_FMT_RGB565] = {
- .name = "rgb565",
- .nb_channels = 3,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
- },
- [PIX_FMT_RGB555] = {
- .name = "rgb555",
- .nb_channels = 4, .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PACKED,
- .depth = 5,
- },
-
- /* gray / mono formats */
- [PIX_FMT_GRAY8] = {
- .name = "gray",
- .nb_channels = 1,
- .color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 8,
- },
- [PIX_FMT_MONOWHITE] = {
- .name = "monow",
- .nb_channels = 1,
- .color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 1,
- },
- [PIX_FMT_MONOBLACK] = {
- .name = "monob",
- .nb_channels = 1,
- .color_type = FF_COLOR_GRAY,
- .pixel_type = FF_PIXEL_PLANAR,
- .depth = 1,
- },
-
- /* paletted formats */
- [PIX_FMT_PAL8] = {
- .name = "pal8",
- .nb_channels = 4, .is_alpha = 1,
- .color_type = FF_COLOR_RGB,
- .pixel_type = FF_PIXEL_PALETTE,
- .depth = 8,
- },
-};
-
-void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift)
-{
- *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
- *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
-}
-
-const char *avcodec_get_pix_fmt_name(int pix_fmt)
-{
- if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
- return "???";
- else
- return pix_fmt_info[pix_fmt].name;
-}
-
-enum PixelFormat avcodec_get_pix_fmt(const char* name)
-{
- int i;
-
- for (i=0; i < PIX_FMT_NB; i++)
- if (!strcmp(pix_fmt_info[i].name, name))
- break;
- return i;
-}
-
-/* Picture field are filled with 'ptr' addresses. Also return size */
-int avpicture_fill(AVPicture *picture, uint8_t *ptr,
- int pix_fmt, int width, int height)
-{
- int size, w2, h2, size2;
- PixFmtInfo *pinfo;
-
- pinfo = &pix_fmt_info[pix_fmt];
- size = width * height;
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV410P:
- case PIX_FMT_YUV411P:
- case PIX_FMT_YUVJ420P:
- case PIX_FMT_YUVJ422P:
- case PIX_FMT_YUVJ444P:
- w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
- h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
- size2 = w2 * h2;
- picture->data[0] = ptr;
- picture->data[1] = picture->data[0] + size;
- picture->data[2] = picture->data[1] + size2;
- picture->linesize[0] = width;
- picture->linesize[1] = w2;
- picture->linesize[2] = w2;
- return size + 2 * size2;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 3;
- return size * 3;
- case PIX_FMT_RGBA32:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 4;
- return size * 4;
- case PIX_FMT_RGB555:
- case PIX_FMT_RGB565:
- case PIX_FMT_YUV422:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width * 2;
- return size * 2;
- case PIX_FMT_GRAY8:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = width;
- return size;
- case PIX_FMT_MONOWHITE:
- case PIX_FMT_MONOBLACK:
- picture->data[0] = ptr;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->linesize[0] = (width + 7) >> 3;
- return picture->linesize[0] * height;
- case PIX_FMT_PAL8:
- size2 = (size + 3) & ~3;
- picture->data[0] = ptr;
- picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
- picture->data[2] = NULL;
- picture->linesize[0] = width;
- picture->linesize[1] = 4;
- return size2 + 256 * 4;
- default:
- picture->data[0] = NULL;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->data[3] = NULL;
- return -1;
- }
-}
-
-int avpicture_layout(AVPicture* src, int pix_fmt, int width, int height,
- unsigned char *dest, int dest_size)
-{
- PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
- int i, j, w, h, data_planes;
- unsigned char* s;
- int size = avpicture_get_size(pix_fmt, width, height);
-
- if (size > dest_size)
- return -1;
-
- if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
- if (pix_fmt == PIX_FMT_YUV422 || pix_fmt == PIX_FMT_RGB565 ||
- pix_fmt == PIX_FMT_RGB555)
- w = width * 2;
- else if (pix_fmt == PIX_FMT_PAL8)
- w = width;
- else
- w = width * (pf->depth * pf->nb_channels / 8);
-
- data_planes = 1;
- h = height;
- } else {
- data_planes = pf->nb_channels;
- w = width;
- h = height;
- }
-
- for (i=0; i<data_planes; i++) {
- if (i == 1) {
- w = width >> pf->x_chroma_shift;
- h = height >> pf->y_chroma_shift;
- }
- s = src->data[i];
- for(j=0; j<h; j++) {
- memcpy(dest, s, w);
- dest += w;
- s += src->linesize[i];
- }
- }
-
- if (pf->pixel_type == FF_PIXEL_PALETTE)
- memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4);
-
- return size;
-}
-
-int avpicture_get_size(int pix_fmt, int width, int height)
-{
- AVPicture dummy_pict;
- return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
-}
-
-/**
- * compute the loss when converting from a pixel format to another
- */
-int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
- int has_alpha)
-{
- const PixFmtInfo *pf, *ps;
- int loss;
-
- ps = &pix_fmt_info[src_pix_fmt];
- pf = &pix_fmt_info[dst_pix_fmt];
-
- /* compute loss */
- loss = 0;
- pf = &pix_fmt_info[dst_pix_fmt];
- if (pf->depth < ps->depth ||
- (dst_pix_fmt == PIX_FMT_RGB555 && src_pix_fmt == PIX_FMT_RGB565))
- loss |= FF_LOSS_DEPTH;
- if (pf->x_chroma_shift > ps->x_chroma_shift ||
- pf->y_chroma_shift > ps->y_chroma_shift)
- loss |= FF_LOSS_RESOLUTION;
- switch(pf->color_type) {
- case FF_COLOR_RGB:
- if (ps->color_type != FF_COLOR_RGB &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_GRAY:
- if (ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_YUV:
- if (ps->color_type != FF_COLOR_YUV)
- loss |= FF_LOSS_COLORSPACE;
- break;
- case FF_COLOR_YUV_JPEG:
- if (ps->color_type != FF_COLOR_YUV_JPEG &&
- ps->color_type != FF_COLOR_YUV &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_COLORSPACE;
- break;
- default:
- /* fail safe test */
- if (ps->color_type != pf->color_type)
- loss |= FF_LOSS_COLORSPACE;
- break;
- }
- if (pf->color_type == FF_COLOR_GRAY &&
- ps->color_type != FF_COLOR_GRAY)
- loss |= FF_LOSS_CHROMA;
- if (!pf->is_alpha && (ps->is_alpha && has_alpha))
- loss |= FF_LOSS_ALPHA;
- if (pf->pixel_type == FF_PIXEL_PALETTE &&
- (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY))
- loss |= FF_LOSS_COLORQUANT;
- return loss;
-}
-
-static int avg_bits_per_pixel(int pix_fmt)
-{
- int bits;
- const PixFmtInfo *pf;
-
- pf = &pix_fmt_info[pix_fmt];
- switch(pf->pixel_type) {
- case FF_PIXEL_PACKED:
- switch(pix_fmt) {
- case PIX_FMT_YUV422:
- case PIX_FMT_RGB565:
- case PIX_FMT_RGB555:
- bits = 16;
- break;
- default:
- bits = pf->depth * pf->nb_channels;
- break;
- }
- break;
- case FF_PIXEL_PLANAR:
- if (pf->x_chroma_shift == 0 && pf->y_chroma_shift == 0) {
- bits = pf->depth * pf->nb_channels;
- } else {
- bits = pf->depth + ((2 * pf->depth) >>
- (pf->x_chroma_shift + pf->y_chroma_shift));
- }
- break;
- case FF_PIXEL_PALETTE:
- bits = 8;
- break;
- default:
- bits = -1;
- break;
- }
- return bits;
-}
-
-static int avcodec_find_best_pix_fmt1(int pix_fmt_mask,
- int src_pix_fmt,
- int has_alpha,
- int loss_mask)
-{
- int dist, i, loss, min_dist, dst_pix_fmt;
-
- /* find exact color match with smallest size */
- dst_pix_fmt = -1;
- min_dist = 0x7fffffff;
- for(i = 0;i < PIX_FMT_NB; i++) {
- if (pix_fmt_mask & (1 << i)) {
- loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
- if (loss == 0) {
- dist = avg_bits_per_pixel(i);
- if (dist < min_dist) {
- min_dist = dist;
- dst_pix_fmt = i;
- }
- }
- }
- }
- return dst_pix_fmt;
-}
-
-/**
- * find best pixel format to convert to. Return -1 if none found
- */
-int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
- int has_alpha, int *loss_ptr)
-{
- int dst_pix_fmt, loss_mask, i;
- static const int loss_mask_order[] = {
- ~0, /* no loss first */
- ~FF_LOSS_ALPHA,
- ~FF_LOSS_RESOLUTION,
- ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
- ~FF_LOSS_COLORQUANT,
- ~FF_LOSS_DEPTH,
- 0,
- };
-
- /* try with successive loss */
- i = 0;
- for(;;) {
- loss_mask = loss_mask_order[i++];
- dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,
- has_alpha, loss_mask);
- if (dst_pix_fmt >= 0)
- goto found;
- if (loss_mask == 0)
- break;
- }
- return -1;
- found:
- if (loss_ptr)
- *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);
- return dst_pix_fmt;
-}
-
-static void img_copy_plane(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- memcpy(dst, src, width);
- dst += dst_wrap;
- src += src_wrap;
- }
-}
-
-/**
- * Copy image 'src' to 'dst'.
- */
-void img_copy(AVPicture *dst, AVPicture *src,
- int pix_fmt, int width, int height)
-{
- int bwidth, bits, i;
- PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
-
- pf = &pix_fmt_info[pix_fmt];
- switch(pf->pixel_type) {
- case FF_PIXEL_PACKED:
- switch(pix_fmt) {
- case PIX_FMT_YUV422:
- case PIX_FMT_RGB565:
- case PIX_FMT_RGB555:
- bits = 16;
- break;
- default:
- bits = pf->depth * pf->nb_channels;
- break;
- }
- bwidth = (width * bits + 7) >> 3;
- img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- bwidth, height);
- break;
- case FF_PIXEL_PLANAR:
- for(i = 0; i < pf->nb_channels; i++) {
- int w, h;
- w = width;
- h = height;
- if (i == 1 || i == 2) {
- w >>= pf->x_chroma_shift;
- h >>= pf->y_chroma_shift;
- }
- bwidth = (w * pf->depth + 7) >> 3;
- img_copy_plane(dst->data[i], dst->linesize[i],
- src->data[i], src->linesize[i],
- bwidth, h);
- }
- break;
- case FF_PIXEL_PALETTE:
- img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- width, height);
- /* copy the palette */
- img_copy_plane(dst->data[1], dst->linesize[1],
- src->data[1], src->linesize[1],
- 4, 256);
- break;
- }
-}
-
-/* XXX: totally non optimized */
-
-static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
-
- for(;height >= 1; height -= 2) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- cb[0] = p[1];
- lum[1] = p[2];
- cr[0] = p[3];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- if (w) {
- lum[0] = p[0];
- cb[0] = p[1];
- cr[0] = p[3];
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- if (height>1) {
- p = p1;
- lum = lum1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- lum[1] = p[2];
- p += 4;
- lum += 2;
- }
- if (w) {
- lum[0] = p[0];
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- }
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-static void yuv422_to_yuv422p(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *p, *p1;
- uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = src->data[0];
- lum1 = dst->data[0];
- cb1 = dst->data[1];
- cr1 = dst->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- lum[0] = p[0];
- cb[0] = p[1];
- lum[1] = p[2];
- cr[0] = p[3];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += src->linesize[0];
- lum1 += dst->linesize[0];
- cb1 += dst->linesize[1];
- cr1 += dst->linesize[2];
- }
-}
-
-static void yuv422p_to_yuv422(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- uint8_t *p, *p1;
- const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
- int w;
-
- p1 = dst->data[0];
- lum1 = src->data[0];
- cb1 = src->data[1];
- cr1 = src->data[2];
- for(;height > 0; height--) {
- p = p1;
- lum = lum1;
- cb = cb1;
- cr = cr1;
- for(w = width; w >= 2; w -= 2) {
- p[0] = lum[0];
- p[1] = cb[0];
- p[2] = lum[1];
- p[3] = cr[0];
- p += 4;
- lum += 2;
- cb++;
- cr++;
- }
- p1 += dst->linesize[0];
- lum1 += src->linesize[0];
- cb1 += src->linesize[1];
- cr1 += src->linesize[2];
- }
-}
-
-#define SCALEBITS 10
-#define ONE_HALF (1 << (SCALEBITS - 1))
-#define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
-
-#define YUV_TO_RGB1_CCIR(cb1, cr1)\
-{\
- cb = (cb1) - 128;\
- cr = (cr1) - 128;\
- r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
- g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
- ONE_HALF;\
- b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
-}
-
-#define YUV_TO_RGB2_CCIR(r, g, b, y1)\
-{\
- y = ((y1) - 16) * FIX(255.0/219.0);\
- r = cm[(y + r_add) >> SCALEBITS];\
- g = cm[(y + g_add) >> SCALEBITS];\
- b = cm[(y + b_add) >> SCALEBITS];\
-}
-
-#define YUV_TO_RGB1(cb1, cr1)\
-{\
- cb = (cb1) - 128;\
- cr = (cr1) - 128;\
- r_add = FIX(1.40200) * cr + ONE_HALF;\
- g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
- b_add = FIX(1.77200) * cb + ONE_HALF;\
-}
-
-#define YUV_TO_RGB2(r, g, b, y1)\
-{\
- y = (y1) << SCALEBITS;\
- r = cm[(y + r_add) >> SCALEBITS];\
- g = cm[(y + g_add) >> SCALEBITS];\
- b = cm[(y + b_add) >> SCALEBITS];\
-}
-
-#define Y_CCIR_TO_JPEG(y)\
- cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
-
-#define Y_JPEG_TO_CCIR(y)\
- (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
-
-#define C_CCIR_TO_JPEG(y)\
- cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
-
-/* NOTE: the clamp is really necessary! */
-static inline int C_JPEG_TO_CCIR(int y) {
- y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
- if (y < 16)
- y = 16;
- return y;
-}
-
-
-#define RGB_TO_Y(r, g, b) \
-((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
- FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
-
-#define RGB_TO_U(r1, g1, b1, shift)\
-(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
- FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_V(r1, g1, b1, shift)\
-(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
- FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_Y_CCIR(r, g, b) \
-((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
- FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
-
-#define RGB_TO_U_CCIR(r1, g1, b1, shift)\
-(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
- FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-#define RGB_TO_V_CCIR(r1, g1, b1, shift)\
-(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
- FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
-
-static uint8_t y_ccir_to_jpeg[256];
-static uint8_t y_jpeg_to_ccir[256];
-static uint8_t c_ccir_to_jpeg[256];
-static uint8_t c_jpeg_to_ccir[256];
-
-/* init various conversion tables */
-static void img_convert_init(void)
-{
- int i;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- for(i = 0;i < 256; i++) {
- y_ccir_to_jpeg[i] = Y_CCIR_TO_JPEG(i);
- y_jpeg_to_ccir[i] = Y_JPEG_TO_CCIR(i);
- c_ccir_to_jpeg[i] = C_CCIR_TO_JPEG(i);
- c_jpeg_to_ccir[i] = C_JPEG_TO_CCIR(i);
- }
-}
-
-/* apply to each pixel the given table */
-static void img_apply_table(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height, const uint8_t *table1)
-{
- int n;
- const uint8_t *s;
- uint8_t *d;
- const uint8_t *table;
-
- table = table1;
- for(;height > 0; height--) {
- s = src;
- d = dst;
- n = width;
- while (n >= 4) {
- d[0] = table[s[0]];
- d[1] = table[s[1]];
- d[2] = table[s[2]];
- d[3] = table[s[3]];
- d += 4;
- s += 4;
- n -= 4;
- }
- while (n > 0) {
- d[0] = table[s[0]];
- d++;
- s++;
- n--;
- }
- dst += dst_wrap;
- src += src_wrap;
- }
-}
-
-/* XXX: use generic filter ? */
-/* XXX: in most cases, the sampling position is incorrect */
-
-/* 4x1 -> 1x1 */
-static void shrink41(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s = src;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s[0] + s[1] + s[2] + s[3] + 2) >> 2;
- s += 4;
- d++;
- }
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 2x1 -> 1x1 */
-static void shrink21(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s = src;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s[0] + s[1]) >> 1;
- s += 2;
- d++;
- }
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x2 -> 1x1 */
-static void shrink12(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- uint8_t *d;
- const uint8_t *s1, *s2;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[0] = (s1[0] + s2[0]) >> 1;
- d[1] = (s1[1] + s2[1]) >> 1;
- d[2] = (s1[2] + s2[2]) >> 1;
- d[3] = (s1[3] + s2[3]) >> 1;
- s1 += 4;
- s2 += 4;
- d += 4;
- }
- for(;w > 0; w--) {
- d[0] = (s1[0] + s2[0]) >> 1;
- s1++;
- s2++;
- d++;
- }
- src += 2 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 2x2 -> 1x1 */
-static void shrink22(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s1, *s2;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
- d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 2;
- d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 2;
- d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 2;
- s1 += 8;
- s2 += 8;
- d += 4;
- }
- for(;w > 0; w--) {
- d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 2;
- s1 += 2;
- s2 += 2;
- d++;
- }
- src += 2 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 4x4 -> 1x1 */
-static void shrink44(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w;
- const uint8_t *s1, *s2, *s3, *s4;
- uint8_t *d;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = s1 + src_wrap;
- s3 = s2 + src_wrap;
- s4 = s3 + src_wrap;
- d = dst;
- for(w = width;w > 0; w--) {
- d[0] = (s1[0] + s1[1] + s1[2] + s1[3] +
- s2[0] + s2[1] + s2[2] + s2[3] +
- s3[0] + s3[1] + s3[2] + s3[3] +
- s4[0] + s4[1] + s4[2] + s4[3] + 8) >> 4;
- s1 += 4;
- s2 += 4;
- s3 += 4;
- s4 += 4;
- d++;
- }
- src += 4 * src_wrap;
- dst += dst_wrap;
- }
-}
-
-static void grow21_line(uint8_t *dst, const uint8_t *src,
- int width)
-{
- int w;
- const uint8_t *s1;
- uint8_t *d;
-
- s1 = src;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- d[1] = d[0] = s1[0];
- d[3] = d[2] = s1[1];
- s1 += 2;
- d += 4;
- }
- for(;w >= 2; w -= 2) {
- d[1] = d[0] = s1[0];
- s1 ++;
- d += 2;
- }
- /* only needed if width is not a multiple of two */
- /* XXX: veryfy that */
- if (w) {
- d[0] = s1[0];
- }
-}
-
-static void grow41_line(uint8_t *dst, const uint8_t *src,
- int width)
-{
- int w, v;
- const uint8_t *s1;
- uint8_t *d;
-
- s1 = src;
- d = dst;
- for(w = width;w >= 4; w-=4) {
- v = s1[0];
- d[0] = v;
- d[1] = v;
- d[2] = v;
- d[3] = v;
- s1 ++;
- d += 4;
- }
-}
-
-/* 1x1 -> 2x1 */
-static void grow21(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow21_line(dst, src, width);
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 2x2 */
-static void grow22(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow21_line(dst, src, width);
- if (height%2)
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 4x1 */
-static void grow41(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow41_line(dst, src, width);
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x1 -> 4x4 */
-static void grow44(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- grow41_line(dst, src, width);
- if ((height & 3) == 1)
- src += src_wrap;
- dst += dst_wrap;
- }
-}
-
-/* 1x2 -> 2x1 */
-static void conv411(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height)
-{
- int w, c;
- const uint8_t *s1, *s2;
- uint8_t *d;
-
- width>>=1;
-
- for(;height > 0; height--) {
- s1 = src;
- s2 = src + src_wrap;
- d = dst;
- for(w = width;w > 0; w--) {
- c = (s1[0] + s2[0]) >> 1;
- d[0] = c;
- d[1] = c;
- s1++;
- s2++;
- d += 2;
- }
- src += src_wrap * 2;
- dst += dst_wrap;
- }
-}
-
-/* XXX: add jpeg quantize code */
-
-#define TRANSP_INDEX (6*6*6)
-
-/* this is maybe slow, but allows for extensions */
-static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
-{
- return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
-}
-
-static void build_rgb_palette(uint8_t *palette, int has_alpha)
-{
- uint32_t *pal;
- static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
- int i, r, g, b;
-
- pal = (uint32_t *)palette;
- i = 0;
- for(r = 0; r < 6; r++) {
- for(g = 0; g < 6; g++) {
- for(b = 0; b < 6; b++) {
- pal[i++] = (0xff << 24) | (pal_value[r] << 16) |
- (pal_value[g] << 8) | pal_value[b];
- }
- }
- }
- if (has_alpha)
- pal[i++] = 0;
- while (i < 256)
- pal[i++] = 0xff000000;
-}
-
-/* copy bit n to bits 0 ... n - 1 */
-static inline unsigned int bitcopy_n(unsigned int a, int n)
-{
- int mask;
- mask = (1 << n) - 1;
- return (a & (0xff & ~mask)) | ((-((a >> n) & 1)) & mask);
-}
-
-/* rgb555 handling */
-
-#define RGB_NAME rgb555
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint16_t *)(s))[0];\
- r = bitcopy_n(v >> (10 - 3), 3);\
- g = bitcopy_n(v >> (5 - 3), 3);\
- b = bitcopy_n(v << 3, 3);\
-}
-
-#define RGBA_IN(r, g, b, a, s)\
-{\
- unsigned int v = ((const uint16_t *)(s))[0];\
- r = bitcopy_n(v >> (10 - 3), 3);\
- g = bitcopy_n(v >> (5 - 3), 3);\
- b = bitcopy_n(v << 3, 3);\
- a = (-(v >> 15)) & 0xff;\
-}
-
-#define RGBA_OUT(d, r, g, b, a)\
-{\
- ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | \
- ((a << 8) & 0x8000);\
-}
-
-#define BPP 2
-
-#include "imgconvert_template.h"
-
-/* rgb565 handling */
-
-#define RGB_NAME rgb565
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint16_t *)(s))[0];\
- r = bitcopy_n(v >> (11 - 3), 3);\
- g = bitcopy_n(v >> (5 - 2), 2);\
- b = bitcopy_n(v << 3, 3);\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
-}
-
-#define BPP 2
-
-#include "imgconvert_template.h"
-
-/* bgr24 handling */
-
-#define RGB_NAME bgr24
-
-#define RGB_IN(r, g, b, s)\
-{\
- b = (s)[0];\
- g = (s)[1];\
- r = (s)[2];\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- (d)[0] = b;\
- (d)[1] = g;\
- (d)[2] = r;\
-}
-
-#define BPP 3
-
-#include "imgconvert_template.h"
-
-#undef RGB_IN
-#undef RGB_OUT
-#undef BPP
-
-/* rgb24 handling */
-
-#define RGB_NAME rgb24
-#define FMT_RGB24
-
-#define RGB_IN(r, g, b, s)\
-{\
- r = (s)[0];\
- g = (s)[1];\
- b = (s)[2];\
-}
-
-#define RGB_OUT(d, r, g, b)\
-{\
- (d)[0] = r;\
- (d)[1] = g;\
- (d)[2] = b;\
-}
-
-#define BPP 3
-
-#include "imgconvert_template.h"
-
-/* rgba32 handling */
-
-#define RGB_NAME rgba32
-#define FMT_RGBA32
-
-#define RGB_IN(r, g, b, s)\
-{\
- unsigned int v = ((const uint32_t *)(s))[0];\
- r = (v >> 16) & 0xff;\
- g = (v >> 8) & 0xff;\
- b = v & 0xff;\
-}
-
-#define RGBA_IN(r, g, b, a, s)\
-{\
- unsigned int v = ((const uint32_t *)(s))[0];\
- a = (v >> 24) & 0xff;\
- r = (v >> 16) & 0xff;\
- g = (v >> 8) & 0xff;\
- b = v & 0xff;\
-}
-
-#define RGBA_OUT(d, r, g, b, a)\
-{\
- ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;\
-}
-
-#define BPP 4
-
-#include "imgconvert_template.h"
-
-static void mono_to_gray(AVPicture *dst, AVPicture *src,
- int width, int height, int xor_mask)
-{
- const unsigned char *p;
- unsigned char *q;
- int v, dst_wrap, src_wrap;
- int y, w;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - ((width + 7) >> 3);
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
- for(y=0;y<height;y++) {
- w = width;
- while (w >= 8) {
- v = *p++ ^ xor_mask;
- q[0] = -(v >> 7);
- q[1] = -((v >> 6) & 1);
- q[2] = -((v >> 5) & 1);
- q[3] = -((v >> 4) & 1);
- q[4] = -((v >> 3) & 1);
- q[5] = -((v >> 2) & 1);
- q[6] = -((v >> 1) & 1);
- q[7] = -((v >> 0) & 1);
- w -= 8;
- q += 8;
- }
- if (w > 0) {
- v = *p++ ^ xor_mask;
- do {
- q[0] = -((v >> 7) & 1);
- q++;
- v <<= 1;
- } while (--w);
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void monowhite_to_gray(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- mono_to_gray(dst, src, width, height, 0xff);
-}
-
-static void monoblack_to_gray(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- mono_to_gray(dst, src, width, height, 0x00);
-}
-
-static void gray_to_mono(AVPicture *dst, AVPicture *src,
- int width, int height, int xor_mask)
-{
- int n;
- const uint8_t *s;
- uint8_t *d;
- int j, b, v, n1, src_wrap, dst_wrap, y;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - ((width + 7) >> 3);
-
- for(y=0;y<height;y++) {
- n = width;
- while (n >= 8) {
- v = 0;
- for(j=0;j<8;j++) {
- b = s[0];
- s++;
- v = (v << 1) | (b >> 7);
- }
- d[0] = v ^ xor_mask;
- d++;
- n -= 8;
- }
- if (n > 0) {
- n1 = n;
- v = 0;
- while (n > 0) {
- b = s[0];
- s++;
- v = (v << 1) | (b >> 7);
- n--;
- }
- d[0] = (v << (8 - (n1 & 7))) ^ xor_mask;
- d++;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void gray_to_monowhite(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- gray_to_mono(dst, src, width, height, 0xff);
-}
-
-static void gray_to_monoblack(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- gray_to_mono(dst, src, width, height, 0x00);
-}
-
-typedef struct ConvertEntry {
- void (*convert)(AVPicture *dst, AVPicture *src, int width, int height);
-} ConvertEntry;
-
-/* Add each new convertion function in this table. In order to be able
- to convert from any format to any format, the following constraints
- must be satisfied:
-
- - all FF_COLOR_RGB formats must convert to and from PIX_FMT_RGB24
-
- - all FF_COLOR_GRAY formats must convert to and from PIX_FMT_GRAY8
-
- - all FF_COLOR_RGB formats with alpha must convert to and from PIX_FMT_RGBA32
-
- - PIX_FMT_YUV444P and PIX_FMT_YUVJ444P must convert to and from
- PIX_FMT_RGB24.
-
- - PIX_FMT_422 must convert to and from PIX_FMT_422P.
-
- The other conversion functions are just optimisations for common cases.
-*/
-static ConvertEntry convert_table[PIX_FMT_NB][PIX_FMT_NB] = {
- [PIX_FMT_YUV420P] = {
- [PIX_FMT_RGB555] = {
- .convert = yuv420p_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = yuv420p_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = yuv420p_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = yuv420p_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = yuv420p_to_rgba32
- },
- },
- [PIX_FMT_YUV422P] = {
- [PIX_FMT_YUV422] = {
- .convert = yuv422p_to_yuv422,
- },
- },
- [PIX_FMT_YUV444P] = {
- [PIX_FMT_RGB24] = {
- .convert = yuv444p_to_rgb24
- },
- },
- [PIX_FMT_YUVJ420P] = {
- [PIX_FMT_RGB555] = {
- .convert = yuvj420p_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = yuvj420p_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = yuvj420p_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = yuvj420p_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = yuvj420p_to_rgba32
- },
- },
- [PIX_FMT_YUVJ444P] = {
- [PIX_FMT_RGB24] = {
- .convert = yuvj444p_to_rgb24
- },
- },
- [PIX_FMT_YUV422] = {
- [PIX_FMT_YUV420P] = {
- .convert = yuv422_to_yuv420p,
- },
- [PIX_FMT_YUV422P] = {
- .convert = yuv422_to_yuv422p,
- },
- },
-
- [PIX_FMT_RGB24] = {
- [PIX_FMT_YUV420P] = {
- .convert = rgb24_to_yuv420p
- },
- [PIX_FMT_RGB565] = {
- .convert = rgb24_to_rgb565
- },
- [PIX_FMT_RGB555] = {
- .convert = rgb24_to_rgb555
- },
- [PIX_FMT_RGBA32] = {
- .convert = rgb24_to_rgba32
- },
- [PIX_FMT_BGR24] = {
- .convert = rgb24_to_bgr24
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb24_to_gray
- },
- [PIX_FMT_PAL8] = {
- .convert = rgb24_to_pal8
- },
- [PIX_FMT_YUV444P] = {
- .convert = rgb24_to_yuv444p
- },
- [PIX_FMT_YUVJ420P] = {
- .convert = rgb24_to_yuvj420p
- },
- [PIX_FMT_YUVJ444P] = {
- .convert = rgb24_to_yuvj444p
- },
- },
- [PIX_FMT_RGBA32] = {
- [PIX_FMT_RGB24] = {
- .convert = rgba32_to_rgb24
- },
- [PIX_FMT_RGB555] = {
- .convert = rgba32_to_rgb555
- },
- [PIX_FMT_PAL8] = {
- .convert = rgba32_to_pal8
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgba32_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgba32_to_gray
- },
- },
- [PIX_FMT_BGR24] = {
- [PIX_FMT_RGB24] = {
- .convert = bgr24_to_rgb24
- },
- [PIX_FMT_YUV420P] = {
- .convert = bgr24_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = bgr24_to_gray
- },
- },
- [PIX_FMT_RGB555] = {
- [PIX_FMT_RGB24] = {
- .convert = rgb555_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = rgb555_to_rgba32
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgb555_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb555_to_gray
- },
- },
- [PIX_FMT_RGB565] = {
- [PIX_FMT_RGB24] = {
- .convert = rgb565_to_rgb24
- },
- [PIX_FMT_YUV420P] = {
- .convert = rgb565_to_yuv420p
- },
- [PIX_FMT_GRAY8] = {
- .convert = rgb565_to_gray
- },
- },
- [PIX_FMT_GRAY8] = {
- [PIX_FMT_RGB555] = {
- .convert = gray_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = gray_to_rgb565
- },
- [PIX_FMT_RGB24] = {
- .convert = gray_to_rgb24
- },
- [PIX_FMT_BGR24] = {
- .convert = gray_to_bgr24
- },
- [PIX_FMT_RGBA32] = {
- .convert = gray_to_rgba32
- },
- [PIX_FMT_MONOWHITE] = {
- .convert = gray_to_monowhite
- },
- [PIX_FMT_MONOBLACK] = {
- .convert = gray_to_monoblack
- },
- },
- [PIX_FMT_MONOWHITE] = {
- [PIX_FMT_GRAY8] = {
- .convert = monowhite_to_gray
- },
- },
- [PIX_FMT_MONOBLACK] = {
- [PIX_FMT_GRAY8] = {
- .convert = monoblack_to_gray
- },
- },
- [PIX_FMT_PAL8] = {
- [PIX_FMT_RGB555] = {
- .convert = pal8_to_rgb555
- },
- [PIX_FMT_RGB565] = {
- .convert = pal8_to_rgb565
- },
- [PIX_FMT_BGR24] = {
- .convert = pal8_to_bgr24
- },
- [PIX_FMT_RGB24] = {
- .convert = pal8_to_rgb24
- },
- [PIX_FMT_RGBA32] = {
- .convert = pal8_to_rgba32
- },
- },
-};
-
-static int avpicture_alloc(AVPicture *picture,
- int pix_fmt, int width, int height)
-{
- unsigned int size;
- void *ptr;
-
- size = avpicture_get_size(pix_fmt, width, height);
- ptr = av_malloc(size);
- if (!ptr)
- goto fail;
- avpicture_fill(picture, ptr, pix_fmt, width, height);
- return 0;
- fail:
- memset(picture, 0, sizeof(AVPicture));
- return -1;
-}
-
-static void avpicture_free(AVPicture *picture)
-{
- av_free(picture->data[0]);
-}
-
-/* return true if yuv planar */
-static inline int is_yuv_planar(PixFmtInfo *ps)
-{
- return (ps->color_type == FF_COLOR_YUV ||
- ps->color_type == FF_COLOR_YUV_JPEG) &&
- ps->pixel_type == FF_PIXEL_PLANAR;
-}
-
-/* XXX: always use linesize. Return -1 if not supported */
-int img_convert(AVPicture *dst, int dst_pix_fmt,
- AVPicture *src, int src_pix_fmt,
- int src_width, int src_height)
-{
- static int inited;
- int i, ret, dst_width, dst_height, int_pix_fmt;
- PixFmtInfo *src_pix, *dst_pix;
- ConvertEntry *ce;
- AVPicture tmp1, *tmp = &tmp1;
-
- if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB ||
- dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB)
- return -1;
- if (src_width <= 0 || src_height <= 0)
- return 0;
-
- if (!inited) {
- inited = 1;
- img_convert_init();
- }
-
- dst_width = src_width;
- dst_height = src_height;
-
- dst_pix = &pix_fmt_info[dst_pix_fmt];
- src_pix = &pix_fmt_info[src_pix_fmt];
- if (src_pix_fmt == dst_pix_fmt) {
- /* no conversion needed: just copy */
- img_copy(dst, src, dst_pix_fmt, dst_width, dst_height);
- return 0;
- }
-
- ce = &convert_table[src_pix_fmt][dst_pix_fmt];
- if (ce->convert) {
- /* specific convertion routine */
- ce->convert(dst, src, dst_width, dst_height);
- return 0;
- }
-
- /* gray to YUV */
- if (is_yuv_planar(dst_pix) &&
- src_pix_fmt == PIX_FMT_GRAY8) {
- int w, h, y;
- uint8_t *d;
-
- if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
- img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
- } else {
- img_apply_table(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height,
- y_jpeg_to_ccir);
- }
- /* fill U and V with 128 */
- w = dst_width;
- h = dst_height;
- w >>= dst_pix->x_chroma_shift;
- h >>= dst_pix->y_chroma_shift;
- for(i = 1; i <= 2; i++) {
- d = dst->data[i];
- for(y = 0; y< h; y++) {
- memset(d, 128, w);
- d += dst->linesize[i];
- }
- }
- return 0;
- }
-
- /* YUV to gray */
- if (is_yuv_planar(src_pix) &&
- dst_pix_fmt == PIX_FMT_GRAY8) {
- if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
- img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
- } else {
- img_apply_table(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height,
- y_ccir_to_jpeg);
- }
- return 0;
- }
-
- /* YUV to YUV planar */
- if (is_yuv_planar(dst_pix) && is_yuv_planar(src_pix)) {
- int x_shift, y_shift, w, h, xy_shift;
- void (*resize_func)(uint8_t *dst, int dst_wrap,
- const uint8_t *src, int src_wrap,
- int width, int height);
-
- /* compute chroma size of the smallest dimensions */
- w = dst_width;
- h = dst_height;
- if (dst_pix->x_chroma_shift >= src_pix->x_chroma_shift)
- w >>= dst_pix->x_chroma_shift;
- else
- w >>= src_pix->x_chroma_shift;
- if (dst_pix->y_chroma_shift >= src_pix->y_chroma_shift)
- h >>= dst_pix->y_chroma_shift;
- else
- h >>= src_pix->y_chroma_shift;
-
- x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
- y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
- xy_shift = ((x_shift & 0xf) << 4) | (y_shift & 0xf);
- /* there must be filters for conversion at least from and to
- YUV444 format */
- switch(xy_shift) {
- case 0x00:
- resize_func = img_copy_plane;
- break;
- case 0x10:
- resize_func = shrink21;
- break;
- case 0x20:
- resize_func = shrink41;
- break;
- case 0x01:
- resize_func = shrink12;
- break;
- case 0x11:
- resize_func = shrink22;
- break;
- case 0x22:
- resize_func = shrink44;
- break;
- case 0xf0:
- resize_func = grow21;
- break;
- case 0xe0:
- resize_func = grow41;
- break;
- case 0xff:
- resize_func = grow22;
- break;
- case 0xee:
- resize_func = grow44;
- break;
- case 0xf1:
- resize_func = conv411;
- break;
- default:
- /* currently not handled */
- goto no_chroma_filter;
- }
-
- img_copy_plane(dst->data[0], dst->linesize[0],
- src->data[0], src->linesize[0],
- dst_width, dst_height);
-
- for(i = 1;i <= 2; i++)
- resize_func(dst->data[i], dst->linesize[i],
- src->data[i], src->linesize[i],
- dst_width>>dst_pix->x_chroma_shift, dst_height>>dst_pix->y_chroma_shift);
- /* if yuv color space conversion is needed, we do it here on
- the destination image */
- if (dst_pix->color_type != src_pix->color_type) {
- const uint8_t *y_table, *c_table;
- if (dst_pix->color_type == FF_COLOR_YUV) {
- y_table = y_jpeg_to_ccir;
- c_table = c_jpeg_to_ccir;
- } else {
- y_table = y_ccir_to_jpeg;
- c_table = c_ccir_to_jpeg;
- }
- img_apply_table(dst->data[0], dst->linesize[0],
- dst->data[0], dst->linesize[0],
- dst_width, dst_height,
- y_table);
-
- for(i = 1;i <= 2; i++)
- img_apply_table(dst->data[i], dst->linesize[i],
- dst->data[i], dst->linesize[i],
- dst_width>>dst_pix->x_chroma_shift,
- dst_height>>dst_pix->y_chroma_shift,
- c_table);
- }
- return 0;
- }
- no_chroma_filter:
-
- /* try to use an intermediate format */
- if (src_pix_fmt == PIX_FMT_YUV422 ||
- dst_pix_fmt == PIX_FMT_YUV422) {
- /* specific case: convert to YUV422P first */
- int_pix_fmt = PIX_FMT_YUV422P;
- } else if ((src_pix->color_type == FF_COLOR_GRAY &&
- src_pix_fmt != PIX_FMT_GRAY8) ||
- (dst_pix->color_type == FF_COLOR_GRAY &&
- dst_pix_fmt != PIX_FMT_GRAY8)) {
- /* gray8 is the normalized format */
- int_pix_fmt = PIX_FMT_GRAY8;
- } else if ((is_yuv_planar(src_pix) &&
- src_pix_fmt != PIX_FMT_YUV444P &&
- src_pix_fmt != PIX_FMT_YUVJ444P)) {
- /* yuv444 is the normalized format */
- if (src_pix->color_type == FF_COLOR_YUV_JPEG)
- int_pix_fmt = PIX_FMT_YUVJ444P;
- else
- int_pix_fmt = PIX_FMT_YUV444P;
- } else if ((is_yuv_planar(dst_pix) &&
- dst_pix_fmt != PIX_FMT_YUV444P &&
- dst_pix_fmt != PIX_FMT_YUVJ444P)) {
- /* yuv444 is the normalized format */
- if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
- int_pix_fmt = PIX_FMT_YUVJ444P;
- else
- int_pix_fmt = PIX_FMT_YUV444P;
- } else {
- /* the two formats are rgb or gray8 or yuv[j]444p */
- if (src_pix->is_alpha && dst_pix->is_alpha)
- int_pix_fmt = PIX_FMT_RGBA32;
- else
- int_pix_fmt = PIX_FMT_RGB24;
- }
- if (avpicture_alloc(tmp, int_pix_fmt, dst_width, dst_height) < 0)
- return -1;
- ret = -1;
- if (img_convert(tmp, int_pix_fmt,
- src, src_pix_fmt, src_width, src_height) < 0)
- goto fail1;
- if (img_convert(dst, dst_pix_fmt,
- tmp, int_pix_fmt, dst_width, dst_height) < 0)
- goto fail1;
- ret = 0;
- fail1:
- avpicture_free(tmp);
- return ret;
-}
-
-/* NOTE: we scan all the pixels to have an exact information */
-static int get_alpha_info_pal8(AVPicture *src, int width, int height)
-{
- const unsigned char *p;
- int src_wrap, ret, x, y;
- unsigned int a;
- uint32_t *palette = (uint32_t *)src->data[1];
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
- ret = 0;
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- a = palette[p[0]] >> 24;
- if (a == 0x00) {
- ret |= FF_ALPHA_TRANSP;
- } else if (a != 0xff) {
- ret |= FF_ALPHA_SEMI_TRANSP;
- }
- p++;
- }
- p += src_wrap;
- }
- return ret;
-}
-
-/**
- * Tell if an image really has transparent alpha values.
- * @return ored mask of FF_ALPHA_xxx constants
- */
-int img_get_alpha_info(AVPicture *src, int pix_fmt, int width, int height)
-{
- PixFmtInfo *pf = &pix_fmt_info[pix_fmt];
- int ret;
-
- pf = &pix_fmt_info[pix_fmt];
- /* no alpha can be represented in format */
- if (!pf->is_alpha)
- return 0;
- switch(pix_fmt) {
- case PIX_FMT_RGBA32:
- ret = get_alpha_info_rgba32(src, width, height);
- break;
- case PIX_FMT_RGB555:
- ret = get_alpha_info_rgb555(src, width, height);
- break;
- case PIX_FMT_PAL8:
- ret = get_alpha_info_pal8(src, width, height);
- break;
- default:
- /* we do not know, so everything is indicated */
- ret = FF_ALPHA_TRANSP | FF_ALPHA_SEMI_TRANSP;
- break;
- }
- return ret;
-}
-
-#ifdef HAVE_MMX
-#define DEINT_INPLACE_LINE_LUM \
- movd_m2r(lum_m4[0],mm0);\
- movd_m2r(lum_m3[0],mm1);\
- movd_m2r(lum_m2[0],mm2);\
- movd_m2r(lum_m1[0],mm3);\
- movd_m2r(lum[0],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- movd_r2m(mm2,lum_m4[0]);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm3,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm4,mm0);\
- psllw_i2r(2,mm1);\
- paddw_r2r(mm6,mm2);\
- paddw_r2r(mm2,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum_m2[0]);
-
-#define DEINT_LINE_LUM \
- movd_m2r(lum_m4[0],mm0);\
- movd_m2r(lum_m3[0],mm1);\
- movd_m2r(lum_m2[0],mm2);\
- movd_m2r(lum_m1[0],mm3);\
- movd_m2r(lum[0],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm3,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm4,mm0);\
- psllw_i2r(2,mm1);\
- paddw_r2r(mm6,mm2);\
- paddw_r2r(mm2,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,dst[0]);
-#endif
-
-/* filter parameters: [-1 4 2 4 -1] // 8 */
-static void deinterlace_line(uint8_t *dst, uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
- int size)
-{
-#ifndef HAVE_MMX
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- int sum;
-
- for(;size > 0;size--) {
- sum = -lum_m4[0];
- sum += lum_m3[0] << 2;
- sum += lum_m2[0] << 1;
- sum += lum_m1[0] << 2;
- sum += -lum[0];
- dst[0] = cm[(sum + 4) >> 3];
- lum_m4++;
- lum_m3++;
- lum_m2++;
- lum_m1++;
- lum++;
- dst++;
- }
-#else
-
- {
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
- }
- for (;size > 3; size-=4) {
- DEINT_LINE_LUM
- lum_m4+=4;
- lum_m3+=4;
- lum_m2+=4;
- lum_m1+=4;
- lum+=4;
- dst+=4;
- }
-#endif
-}
-static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
- int size)
-{
-#ifndef HAVE_MMX
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- int sum;
-
- for(;size > 0;size--) {
- sum = -lum_m4[0];
- sum += lum_m3[0] << 2;
- sum += lum_m2[0] << 1;
- lum_m4[0]=lum_m2[0];
- sum += lum_m1[0] << 2;
- sum += -lum[0];
- lum_m2[0] = cm[(sum + 4) >> 3];
- lum_m4++;
- lum_m3++;
- lum_m2++;
- lum_m1++;
- lum++;
- }
-#else
-
- {
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
- }
- for (;size > 3; size-=4) {
- DEINT_INPLACE_LINE_LUM
- lum_m4+=4;
- lum_m3+=4;
- lum_m2+=4;
- lum_m1+=4;
- lum+=4;
- }
-#endif
-}
-
-/* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
- top field is copied as is, but the bottom field is deinterlaced
- against the top field. */
-static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
- uint8_t *src1, int src_wrap,
- int width, int height)
-{
- uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
- int y;
-
- src_m2 = src1;
- src_m1 = src1;
- src_0=&src_m1[src_wrap];
- src_p1=&src_0[src_wrap];
- src_p2=&src_p1[src_wrap];
- for(y=0;y<(height-2);y+=2) {
- memcpy(dst,src_m1,width);
- dst += dst_wrap;
- deinterlace_line(dst,src_m2,src_m1,src_0,src_p1,src_p2,width);
- src_m2 = src_0;
- src_m1 = src_p1;
- src_0 = src_p2;
- src_p1 += 2*src_wrap;
- src_p2 += 2*src_wrap;
- dst += dst_wrap;
- }
- memcpy(dst,src_m1,width);
- dst += dst_wrap;
- /* do last line */
- deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
-}
-
-static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
- int width, int height)
-{
- uint8_t *src_m1, *src_0, *src_p1, *src_p2;
- int y;
- uint8_t *buf;
- buf = (uint8_t*)av_malloc(width);
-
- src_m1 = src1;
- memcpy(buf,src_m1,width);
- src_0=&src_m1[src_wrap];
- src_p1=&src_0[src_wrap];
- src_p2=&src_p1[src_wrap];
- for(y=0;y<(height-2);y+=2) {
- deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
- src_m1 = src_p1;
- src_0 = src_p2;
- src_p1 += 2*src_wrap;
- src_p2 += 2*src_wrap;
- }
- /* do last line */
- deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
- av_free(buf);
-}
-
-
-/* deinterlace - if not supported return -1 */
-int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
- int pix_fmt, int width, int height)
-{
- int i;
-
- if (pix_fmt != PIX_FMT_YUV420P &&
- pix_fmt != PIX_FMT_YUV422P &&
- pix_fmt != PIX_FMT_YUV444P &&
- pix_fmt != PIX_FMT_YUV411P)
- return -1;
- if ((width & 3) != 0 || (height & 3) != 0)
- return -1;
-
- for(i=0;i<3;i++) {
- if (i == 1) {
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- width >>= 1;
- height >>= 1;
- break;
- case PIX_FMT_YUV422P:
- width >>= 1;
- break;
- case PIX_FMT_YUV411P:
- width >>= 2;
- break;
- default:
- break;
- }
- }
- if (src == dst) {
- deinterlace_bottom_field_inplace(src->data[i], src->linesize[i],
- width, height);
- } else {
- deinterlace_bottom_field(dst->data[i],dst->linesize[i],
- src->data[i], src->linesize[i],
- width, height);
- }
- }
-#ifdef HAVE_MMX
- emms();
-#endif
- return 0;
-}
-
-#undef FIX
+++ /dev/null
-/*
- * Templates for image convertion routines
- * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef RGB_OUT
-#define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff)
-#endif
-
-static void glue(yuv420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
- int w, y, cb, cr, r_add, g_add, b_add, width2;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- width2 = (width + 1) >> 1;
- for(;height >= 2; height -= 2) {
- d1 = d;
- d2 = d + dst->linesize[0];
- y2_ptr = y1_ptr + src->linesize[0];
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 4 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]);
- RGB_OUT(d2 + BPP, r, g, b);
-
- d1 += 2 * BPP;
- d2 += 2 * BPP;
-
- y1_ptr += 2;
- y2_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle odd width */
- if (w) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
- d1 += BPP;
- d2 += BPP;
- y1_ptr++;
- y2_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += 2 * dst->linesize[0];
- y1_ptr += 2 * src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width2;
- cr_ptr += src->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- d1 = d;
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- d1 += 2 * BPP;
-
- y1_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle width */
- if (w) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- }
-}
-
-static void glue(yuvj420p_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2;
- int w, y, cb, cr, r_add, g_add, b_add, width2;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- width2 = (width + 1) >> 1;
- for(;height >= 2; height -= 2) {
- d1 = d;
- d2 = d + dst->linesize[0];
- y2_ptr = y1_ptr + src->linesize[0];
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 4 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[1]);
- RGB_OUT(d2 + BPP, r, g, b);
-
- d1 += 2 * BPP;
- d2 += 2 * BPP;
-
- y1_ptr += 2;
- y2_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle odd width */
- if (w) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y2_ptr[0]);
- RGB_OUT(d2, r, g, b);
- d1 += BPP;
- d2 += BPP;
- y1_ptr++;
- y2_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += 2 * dst->linesize[0];
- y1_ptr += 2 * src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width2;
- cr_ptr += src->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- d1 = d;
- for(w = width; w >= 2; w -= 2) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[1]);
- RGB_OUT(d1 + BPP, r, g, b);
-
- d1 += 2 * BPP;
-
- y1_ptr += 2;
- cb_ptr++;
- cr_ptr++;
- }
- /* handle width */
- if (w) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
- /* output 2 pixels */
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- }
-}
-
-static void glue(RGB_NAME, _to_yuv420p)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- int wrap, wrap3, width2;
- int r, g, b, r1, g1, b1, w;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- width2 = (width + 1) >> 1;
- wrap = dst->linesize[0];
- wrap3 = src->linesize[0];
- p = src->data[0];
- for(;height>=2;height -= 2) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
- p += wrap3;
- lum += wrap;
-
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
-
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2);
-
- cb++;
- cr++;
- p += -wrap3 + 2 * BPP;
- lum += -wrap + 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- p += wrap3;
- lum += wrap;
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
- cb++;
- cr++;
- p += -wrap3 + BPP;
- lum += -wrap + 1;
- }
- p += wrap3 + (wrap3 - width * BPP);
- lum += wrap + (wrap - width);
- cb += dst->linesize[1] - width2;
- cr += dst->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1);
- cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1);
- cb++;
- cr++;
- p += 2 * BPP;
- lum += 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
- cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
- }
- }
-}
-
-static void glue(RGB_NAME, _to_gray)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, g, b, dst_wrap, src_wrap;
- int x, y;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- q[0] = RGB_TO_Y(r, g, b);
- q++;
- p += BPP;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void glue(gray_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, dst_wrap, src_wrap;
- int x, y;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - BPP * width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- r = p[0];
- RGB_OUT(q, r, r, r);
- q += BPP;
- p ++;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int r, g, b, dst_wrap, src_wrap;
- int x, y;
- uint32_t v;
- const uint32_t *palette;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - width;
- palette = (uint32_t *)src->data[1];
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - BPP * width;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- v = palette[p[0]];
- r = (v >> 16) & 0xff;
- g = (v >> 8) & 0xff;
- b = (v) & 0xff;
-#ifdef RGBA_OUT
- {
- int a;
- a = (v >> 24) & 0xff;
- RGBA_OUT(q, r, g, b, a);
- }
-#else
- RGB_OUT(q, r, g, b);
-#endif
- q += BPP;
- p ++;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-}
-
-#if !defined(FMT_RGBA32) && defined(RGBA_OUT)
-/* alpha support */
-
-static void glue(rgba32_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int v, r, g, b, a;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * 4;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * BPP;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- v = ((const uint32_t *)(s))[0];
- a = (v >> 24) & 0xff;
- r = (v >> 16) & 0xff;
- g = (v >> 8) & 0xff;
- b = v & 0xff;
- RGBA_OUT(d, r, g, b, a);
- s += 4;
- d += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void glue(RGB_NAME, _to_rgba32)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g, b, a;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * BPP;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * 4;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- RGBA_IN(r, g, b, a, s);
- ((uint32_t *)(d))[0] = (a << 24) | (r << 16) | (g << 8) | b;
- d += 4;
- s += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-#endif /* !defined(FMT_RGBA32) && defined(RGBA_IN) */
-
-#ifndef FMT_RGB24
-
-static void glue(rgb24_to_, RGB_NAME)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g, b;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * 3;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * BPP;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- r = s[0];
- g = s[1];
- b = s[2];
- RGB_OUT(d, r, g, b);
- s += 3;
- d += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-static void glue(RGB_NAME, _to_rgb24)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const uint8_t *s;
- uint8_t *d;
- int src_wrap, dst_wrap, j, y;
- unsigned int r, g , b;
-
- s = src->data[0];
- src_wrap = src->linesize[0] - width * BPP;
-
- d = dst->data[0];
- dst_wrap = dst->linesize[0] - width * 3;
-
- for(y=0;y<height;y++) {
- for(j = 0;j < width; j++) {
- RGB_IN(r, g, b, s)
- d[0] = r;
- d[1] = g;
- d[2] = b;
- d += 3;
- s += BPP;
- }
- s += src_wrap;
- d += dst_wrap;
- }
-}
-
-#endif /* !FMT_RGB24 */
-
-#ifdef FMT_RGB24
-
-static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
- int w, y, cb, cr, r_add, g_add, b_add;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- for(;height > 0; height --) {
- d1 = d;
- for(w = width; w > 0; w--) {
- YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
-
- YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += dst->linesize[0];
- y1_ptr += src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width;
- cr_ptr += src->linesize[2] - width;
- }
-}
-
-static void yuvj444p_to_rgb24(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
- int w, y, cb, cr, r_add, g_add, b_add;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
- unsigned int r, g, b;
-
- d = dst->data[0];
- y1_ptr = src->data[0];
- cb_ptr = src->data[1];
- cr_ptr = src->data[2];
- for(;height > 0; height --) {
- d1 = d;
- for(w = width; w > 0; w--) {
- YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
-
- YUV_TO_RGB2(r, g, b, y1_ptr[0]);
- RGB_OUT(d1, r, g, b);
- d1 += BPP;
-
- y1_ptr++;
- cb_ptr++;
- cr_ptr++;
- }
- d += dst->linesize[0];
- y1_ptr += src->linesize[0] - width;
- cb_ptr += src->linesize[1] - width;
- cr_ptr += src->linesize[2] - width;
- }
-}
-
-static void rgb24_to_yuv444p(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- int src_wrap, x, y;
- int r, g, b;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- src_wrap = src->linesize[0] - width * BPP;
- p = src->data[0];
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y_CCIR(r, g, b);
- cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
- cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
- p += BPP;
- cb++;
- cr++;
- lum++;
- }
- p += src_wrap;
- lum += dst->linesize[0] - width;
- cb += dst->linesize[1] - width;
- cr += dst->linesize[2] - width;
- }
-}
-
-static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- int wrap, wrap3, width2;
- int r, g, b, r1, g1, b1, w;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- width2 = (width + 1) >> 1;
- wrap = dst->linesize[0];
- wrap3 = src->linesize[0];
- p = src->data[0];
- for(;height>=2;height -= 2) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
- p += wrap3;
- lum += wrap;
-
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
-
- cb[0] = RGB_TO_U(r1, g1, b1, 2);
- cr[0] = RGB_TO_V(r1, g1, b1, 2);
-
- cb++;
- cr++;
- p += -wrap3 + 2 * BPP;
- lum += -wrap + 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
- p += wrap3;
- lum += wrap;
- RGB_IN(r, g, b, p);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r1, g1, b1, 1);
- cr[0] = RGB_TO_V(r1, g1, b1, 1);
- cb++;
- cr++;
- p += -wrap3 + BPP;
- lum += -wrap + 1;
- }
- p += wrap3 + (wrap3 - width * BPP);
- lum += wrap + (wrap - width);
- cb += dst->linesize[1] - width2;
- cr += dst->linesize[2] - width2;
- }
- /* handle odd height */
- if (height) {
- for(w = width; w >= 2; w -= 2) {
- RGB_IN(r, g, b, p);
- r1 = r;
- g1 = g;
- b1 = b;
- lum[0] = RGB_TO_Y(r, g, b);
-
- RGB_IN(r, g, b, p + BPP);
- r1 += r;
- g1 += g;
- b1 += b;
- lum[1] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r1, g1, b1, 1);
- cr[0] = RGB_TO_V(r1, g1, b1, 1);
- cb++;
- cr++;
- p += 2 * BPP;
- lum += 2;
- }
- if (w) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r, g, b, 0);
- cr[0] = RGB_TO_V(r, g, b, 0);
- }
- }
-}
-
-static void rgb24_to_yuvj444p(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- int src_wrap, x, y;
- int r, g, b;
- uint8_t *lum, *cb, *cr;
- const uint8_t *p;
-
- lum = dst->data[0];
- cb = dst->data[1];
- cr = dst->data[2];
-
- src_wrap = src->linesize[0] - width * BPP;
- p = src->data[0];
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGB_IN(r, g, b, p);
- lum[0] = RGB_TO_Y(r, g, b);
- cb[0] = RGB_TO_U(r, g, b, 0);
- cr[0] = RGB_TO_V(r, g, b, 0);
- p += BPP;
- cb++;
- cr++;
- lum++;
- }
- p += src_wrap;
- lum += dst->linesize[0] - width;
- cb += dst->linesize[1] - width;
- cr += dst->linesize[2] - width;
- }
-}
-
-#endif /* FMT_RGB24 */
-
-#if defined(FMT_RGB24) || defined(FMT_RGBA32)
-
-static void glue(RGB_NAME, _to_pal8)(AVPicture *dst, AVPicture *src,
- int width, int height)
-{
- const unsigned char *p;
- unsigned char *q;
- int dst_wrap, src_wrap;
- int x, y, has_alpha;
- unsigned int r, g, b;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
-
- q = dst->data[0];
- dst_wrap = dst->linesize[0] - width;
- has_alpha = 0;
-
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
-#ifdef RGBA_IN
- {
- unsigned int a;
- RGBA_IN(r, g, b, a, p);
- /* crude approximation for alpha ! */
- if (a < 0x80) {
- has_alpha = 1;
- q[0] = TRANSP_INDEX;
- } else {
- q[0] = gif_clut_index(r, g, b);
- }
- }
-#else
- RGB_IN(r, g, b, p);
- q[0] = gif_clut_index(r, g, b);
-#endif
- q++;
- p += BPP;
- }
- p += src_wrap;
- q += dst_wrap;
- }
-
- build_rgb_palette(dst->data[1], has_alpha);
-}
-
-#endif /* defined(FMT_RGB24) || defined(FMT_RGBA32) */
-
-#ifdef RGBA_IN
-
-static int glue(get_alpha_info_, RGB_NAME)(AVPicture *src, int width, int height)
-{
- const unsigned char *p;
- int src_wrap, ret, x, y;
- unsigned int r, g, b, a;
-
- p = src->data[0];
- src_wrap = src->linesize[0] - BPP * width;
- ret = 0;
- for(y=0;y<height;y++) {
- for(x=0;x<width;x++) {
- RGBA_IN(r, g, b, a, p);
- if (a == 0x00) {
- ret |= FF_ALPHA_TRANSP;
- } else if (a != 0xff) {
- ret |= FF_ALPHA_SEMI_TRANSP;
- }
- p += BPP;
- }
- p += src_wrap;
- }
- return ret;
-}
-
-#endif /* RGBA_IN */
-
-#undef RGB_IN
-#undef RGBA_IN
-#undef RGB_OUT
-#undef RGBA_OUT
-#undef BPP
-#undef RGB_NAME
-#undef FMT_RGB24
-#undef FMT_RGBA32
+++ /dev/null
-/*
- * High quality image resampling with polyphase filters
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file imgresample.c
- * High quality image resampling with polyphase filters .
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-
-#define NB_COMPONENTS 3
-
-#define PHASE_BITS 4
-#define NB_PHASES (1 << PHASE_BITS)
-#define NB_TAPS 4
-#define FCENTER 1 /* index of the center of the filter */
-//#define TEST 1 /* Test it */
-
-#define POS_FRAC_BITS 16
-#define POS_FRAC (1 << POS_FRAC_BITS)
-/* 6 bits precision is needed for MMX */
-#define FILTER_BITS 8
-
-#define LINE_BUF_HEIGHT (NB_TAPS * 4)
-
-struct ImgReSampleContext {
- int iwidth, iheight, owidth, oheight, topBand, bottomBand, leftBand, rightBand;
- int h_incr, v_incr;
- int16_t h_filters[NB_PHASES][NB_TAPS] __align8; /* horizontal filters */
- int16_t v_filters[NB_PHASES][NB_TAPS] __align8; /* vertical filters */
- uint8_t *line_buf;
-};
-
-static inline int get_phase(int pos)
-{
- return ((pos) >> (POS_FRAC_BITS - PHASE_BITS)) & ((1 << PHASE_BITS) - 1);
-}
-
-/* This function must be optimized */
-static void h_resample_fast(uint8_t *dst, int dst_width, uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int src_pos, phase, sum, i;
- uint8_t *s;
- int16_t *filter;
-
- src_pos = src_start;
- for(i=0;i<dst_width;i++) {
-#ifdef TEST
- /* test */
- if ((src_pos >> POS_FRAC_BITS) < 0 ||
- (src_pos >> POS_FRAC_BITS) > (src_width - NB_TAPS))
- av_abort();
-#endif
- s = src + (src_pos >> POS_FRAC_BITS);
- phase = get_phase(src_pos);
- filter = filters + phase * NB_TAPS;
-#if NB_TAPS == 4
- sum = s[0] * filter[0] +
- s[1] * filter[1] +
- s[2] * filter[2] +
- s[3] * filter[3];
-#else
- {
- int j;
- sum = 0;
- for(j=0;j<NB_TAPS;j++)
- sum += s[j] * filter[j];
- }
-#endif
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- src_pos += src_incr;
- dst++;
- }
-}
-
-/* This function must be optimized */
-static void v_resample(uint8_t *dst, int dst_width, uint8_t *src, int wrap,
- int16_t *filter)
-{
- int sum, i;
- uint8_t *s;
-
- s = src;
- for(i=0;i<dst_width;i++) {
-#if NB_TAPS == 4
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
-#else
- {
- int j;
- uint8_t *s1 = s;
-
- sum = 0;
- for(j=0;j<NB_TAPS;j++) {
- sum += s1[0] * filter[j];
- s1 += wrap;
- }
- }
-#endif
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- dst++;
- s++;
- }
-}
-
-#ifdef HAVE_MMX
-
-#include "i386/mmx.h"
-
-#define FILTER4(reg) \
-{\
- s = src + (src_pos >> POS_FRAC_BITS);\
- phase = get_phase(src_pos);\
- filter = filters + phase * NB_TAPS;\
- movq_m2r(*s, reg);\
- punpcklbw_r2r(mm7, reg);\
- movq_m2r(*filter, mm6);\
- pmaddwd_r2r(reg, mm6);\
- movq_r2r(mm6, reg);\
- psrlq_i2r(32, reg);\
- paddd_r2r(mm6, reg);\
- psrad_i2r(FILTER_BITS, reg);\
- src_pos += src_incr;\
-}
-
-#define DUMP(reg) movq_r2m(reg, tmp); printf(#reg "=%016Lx\n", tmp.uq);
-
-/* XXX: do four pixels at a time */
-static void h_resample_fast4_mmx(uint8_t *dst, int dst_width, uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int src_pos, phase;
- uint8_t *s;
- int16_t *filter;
- mmx_t tmp;
-
- src_pos = src_start;
- pxor_r2r(mm7, mm7);
-
- while (dst_width >= 4) {
-
- FILTER4(mm0);
- FILTER4(mm1);
- FILTER4(mm2);
- FILTER4(mm3);
-
- packuswb_r2r(mm7, mm0);
- packuswb_r2r(mm7, mm1);
- packuswb_r2r(mm7, mm3);
- packuswb_r2r(mm7, mm2);
- movq_r2m(mm0, tmp);
- dst[0] = tmp.ub[0];
- movq_r2m(mm1, tmp);
- dst[1] = tmp.ub[0];
- movq_r2m(mm2, tmp);
- dst[2] = tmp.ub[0];
- movq_r2m(mm3, tmp);
- dst[3] = tmp.ub[0];
- dst += 4;
- dst_width -= 4;
- }
- while (dst_width > 0) {
- FILTER4(mm0);
- packuswb_r2r(mm7, mm0);
- movq_r2m(mm0, tmp);
- dst[0] = tmp.ub[0];
- dst++;
- dst_width--;
- }
- emms();
-}
-
-static void v_resample4_mmx(uint8_t *dst, int dst_width, uint8_t *src, int wrap,
- int16_t *filter)
-{
- int sum, i, v;
- uint8_t *s;
- mmx_t tmp;
- mmx_t coefs[4];
-
- for(i=0;i<4;i++) {
- v = filter[i];
- coefs[i].uw[0] = v;
- coefs[i].uw[1] = v;
- coefs[i].uw[2] = v;
- coefs[i].uw[3] = v;
- }
-
- pxor_r2r(mm7, mm7);
- s = src;
- while (dst_width >= 4) {
- movq_m2r(s[0 * wrap], mm0);
- punpcklbw_r2r(mm7, mm0);
- movq_m2r(s[1 * wrap], mm1);
- punpcklbw_r2r(mm7, mm1);
- movq_m2r(s[2 * wrap], mm2);
- punpcklbw_r2r(mm7, mm2);
- movq_m2r(s[3 * wrap], mm3);
- punpcklbw_r2r(mm7, mm3);
-
- pmullw_m2r(coefs[0], mm0);
- pmullw_m2r(coefs[1], mm1);
- pmullw_m2r(coefs[2], mm2);
- pmullw_m2r(coefs[3], mm3);
-
- paddw_r2r(mm1, mm0);
- paddw_r2r(mm3, mm2);
- paddw_r2r(mm2, mm0);
- psraw_i2r(FILTER_BITS, mm0);
-
- packuswb_r2r(mm7, mm0);
- movq_r2m(mm0, tmp);
-
- *(uint32_t *)dst = tmp.ud[0];
- dst += 4;
- s += 4;
- dst_width -= 4;
- }
- while (dst_width > 0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- }
- emms();
-}
-#endif
-
-#ifdef HAVE_ALTIVEC
-typedef union {
- vector unsigned char v;
- unsigned char c[16];
-} vec_uc_t;
-
-typedef union {
- vector signed short v;
- signed short s[8];
-} vec_ss_t;
-
-void v_resample16_altivec(uint8_t *dst, int dst_width, uint8_t *src, int wrap,
- int16_t *filter)
-{
- int sum, i;
- uint8_t *s;
- vector unsigned char *tv, tmp, dstv, zero;
- vec_ss_t srchv[4], srclv[4], fv[4];
- vector signed short zeros, sumhv, sumlv;
- s = src;
-
- for(i=0;i<4;i++)
- {
- /*
- The vec_madds later on does an implicit >>15 on the result.
- Since FILTER_BITS is 8, and we have 15 bits of magnitude in
- a signed short, we have just enough bits to pre-shift our
- filter constants <<7 to compensate for vec_madds.
- */
- fv[i].s[0] = filter[i] << (15-FILTER_BITS);
- fv[i].v = vec_splat(fv[i].v, 0);
- }
-
- zero = vec_splat_u8(0);
- zeros = vec_splat_s16(0);
-
-
- /*
- When we're resampling, we'd ideally like both our input buffers,
- and output buffers to be 16-byte aligned, so we can do both aligned
- reads and writes. Sadly we can't always have this at the moment, so
- we opt for aligned writes, as unaligned writes have a huge overhead.
- To do this, do enough scalar resamples to get dst 16-byte aligned.
- */
- i = (-(int)dst) & 0xf;
- while(i>0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum<0) sum = 0; else if (sum>255) sum=255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- i--;
- }
-
- /* Do our altivec resampling on 16 pixels at once. */
- while(dst_width>=16) {
- /*
- Read 16 (potentially unaligned) bytes from each of
- 4 lines into 4 vectors, and split them into shorts.
- Interleave the multipy/accumulate for the resample
- filter with the loads to hide the 3 cycle latency
- the vec_madds have.
- */
- tv = (vector unsigned char *) &s[0 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[i * wrap]));
- srchv[0].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[0].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[0].v, fv[0].v, zeros);
- sumlv = vec_madds(srclv[0].v, fv[0].v, zeros);
-
- tv = (vector unsigned char *) &s[1 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[1 * wrap]));
- srchv[1].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[1].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[1].v, fv[1].v, sumhv);
- sumlv = vec_madds(srclv[1].v, fv[1].v, sumlv);
-
- tv = (vector unsigned char *) &s[2 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[2 * wrap]));
- srchv[2].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[2].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[2].v, fv[2].v, sumhv);
- sumlv = vec_madds(srclv[2].v, fv[2].v, sumlv);
-
- tv = (vector unsigned char *) &s[3 * wrap];
- tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[3 * wrap]));
- srchv[3].v = (vector signed short) vec_mergeh(zero, tmp);
- srclv[3].v = (vector signed short) vec_mergel(zero, tmp);
- sumhv = vec_madds(srchv[3].v, fv[3].v, sumhv);
- sumlv = vec_madds(srclv[3].v, fv[3].v, sumlv);
-
- /*
- Pack the results into our destination vector,
- and do an aligned write of that back to memory.
- */
- dstv = vec_packsu(sumhv, sumlv) ;
- vec_st(dstv, 0, (vector unsigned char *) dst);
-
- dst+=16;
- s+=16;
- dst_width-=16;
- }
-
- /*
- If there are any leftover pixels, resample them
- with the slow scalar method.
- */
- while(dst_width>0) {
- sum = s[0 * wrap] * filter[0] +
- s[1 * wrap] * filter[1] +
- s[2 * wrap] * filter[2] +
- s[3 * wrap] * filter[3];
- sum = sum >> FILTER_BITS;
- if (sum<0) sum = 0; else if (sum>255) sum=255;
- dst[0] = sum;
- dst++;
- s++;
- dst_width--;
- }
-}
-#endif
-
-/* slow version to handle limit cases. Does not need optimisation */
-static void h_resample_slow(uint8_t *dst, int dst_width, uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int src_pos, phase, sum, j, v, i;
- uint8_t *s, *src_end;
- int16_t *filter;
-
- src_end = src + src_width;
- src_pos = src_start;
- for(i=0;i<dst_width;i++) {
- s = src + (src_pos >> POS_FRAC_BITS);
- phase = get_phase(src_pos);
- filter = filters + phase * NB_TAPS;
- sum = 0;
- for(j=0;j<NB_TAPS;j++) {
- if (s < src)
- v = src[0];
- else if (s >= src_end)
- v = src_end[-1];
- else
- v = s[0];
- sum += v * filter[j];
- s++;
- }
- sum = sum >> FILTER_BITS;
- if (sum < 0)
- sum = 0;
- else if (sum > 255)
- sum = 255;
- dst[0] = sum;
- src_pos += src_incr;
- dst++;
- }
-}
-
-static void h_resample(uint8_t *dst, int dst_width, uint8_t *src, int src_width,
- int src_start, int src_incr, int16_t *filters)
-{
- int n, src_end;
-
- if (src_start < 0) {
- n = (0 - src_start + src_incr - 1) / src_incr;
- h_resample_slow(dst, n, src, src_width, src_start, src_incr, filters);
- dst += n;
- dst_width -= n;
- src_start += n * src_incr;
- }
- src_end = src_start + dst_width * src_incr;
- if (src_end > ((src_width - NB_TAPS) << POS_FRAC_BITS)) {
- n = (((src_width - NB_TAPS + 1) << POS_FRAC_BITS) - 1 - src_start) /
- src_incr;
- } else {
- n = dst_width;
- }
-#ifdef HAVE_MMX
- if ((mm_flags & MM_MMX) && NB_TAPS == 4)
- h_resample_fast4_mmx(dst, n,
- src, src_width, src_start, src_incr, filters);
- else
-#endif
- h_resample_fast(dst, n,
- src, src_width, src_start, src_incr, filters);
- if (n < dst_width) {
- dst += n;
- dst_width -= n;
- src_start += n * src_incr;
- h_resample_slow(dst, dst_width,
- src, src_width, src_start, src_incr, filters);
- }
-}
-
-static void component_resample(ImgReSampleContext *s,
- uint8_t *output, int owrap, int owidth, int oheight,
- uint8_t *input, int iwrap, int iwidth, int iheight)
-{
- int src_y, src_y1, last_src_y, ring_y, phase_y, y1, y;
- uint8_t *new_line, *src_line;
-
- last_src_y = - FCENTER - 1;
- /* position of the bottom of the filter in the source image */
- src_y = (last_src_y + NB_TAPS) * POS_FRAC;
- ring_y = NB_TAPS; /* position in ring buffer */
- for(y=0;y<oheight;y++) {
- /* apply horizontal filter on new lines from input if needed */
- src_y1 = src_y >> POS_FRAC_BITS;
- while (last_src_y < src_y1) {
- if (++ring_y >= LINE_BUF_HEIGHT + NB_TAPS)
- ring_y = NB_TAPS;
- last_src_y++;
- /* handle limit conditions : replicate line (slightly
- inefficient because we filter multiple times) */
- y1 = last_src_y;
- if (y1 < 0) {
- y1 = 0;
- } else if (y1 >= iheight) {
- y1 = iheight - 1;
- }
- src_line = input + y1 * iwrap;
- new_line = s->line_buf + ring_y * owidth;
- /* apply filter and handle limit cases correctly */
- h_resample(new_line, owidth,
- src_line, iwidth, - FCENTER * POS_FRAC, s->h_incr,
- &s->h_filters[0][0]);
- /* handle ring buffer wraping */
- if (ring_y >= LINE_BUF_HEIGHT) {
- memcpy(s->line_buf + (ring_y - LINE_BUF_HEIGHT) * owidth,
- new_line, owidth);
- }
- }
- /* apply vertical filter */
- phase_y = get_phase(src_y);
-#ifdef HAVE_MMX
- /* desactivated MMX because loss of precision */
- if ((mm_flags & MM_MMX) && NB_TAPS == 4 && 0)
- v_resample4_mmx(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
- else
-#endif
-#ifdef HAVE_ALTIVEC
- if ((mm_flags & MM_ALTIVEC) && NB_TAPS == 4 && FILTER_BITS <= 6)
- v_resample16_altivec(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
- else
-#endif
- v_resample(output, owidth,
- s->line_buf + (ring_y - NB_TAPS + 1) * owidth, owidth,
- &s->v_filters[phase_y][0]);
-
- src_y += s->v_incr;
- output += owrap;
- }
-}
-
-/* XXX: the following filter is quite naive, but it seems to suffice
- for 4 taps */
-static void build_filter(int16_t *filter, float factor)
-{
- int ph, i, v;
- float x, y, tab[NB_TAPS], norm, mult;
-
- /* if upsampling, only need to interpolate, no filter */
- if (factor > 1.0)
- factor = 1.0;
-
- for(ph=0;ph<NB_PHASES;ph++) {
- norm = 0;
- for(i=0;i<NB_TAPS;i++) {
-
- x = M_PI * ((float)(i - FCENTER) - (float)ph / NB_PHASES) * factor;
- if (x == 0)
- y = 1.0;
- else
- y = sin(x) / x;
- tab[i] = y;
- norm += y;
- }
-
- /* normalize so that an uniform color remains the same */
- mult = (float)(1 << FILTER_BITS) / norm;
- for(i=0;i<NB_TAPS;i++) {
- v = (int)(tab[i] * mult);
- filter[ph * NB_TAPS + i] = v;
- }
- }
-}
-
-ImgReSampleContext *img_resample_init(int owidth, int oheight,
- int iwidth, int iheight)
-{
- return img_resample_full_init(owidth, oheight, iwidth, iheight, 0, 0, 0, 0);
-}
-
-ImgReSampleContext *img_resample_full_init(int owidth, int oheight,
- int iwidth, int iheight,
- int topBand, int bottomBand,
- int leftBand, int rightBand)
-{
- ImgReSampleContext *s;
-
- s = av_mallocz(sizeof(ImgReSampleContext));
- if (!s)
- return NULL;
- s->line_buf = av_mallocz(owidth * (LINE_BUF_HEIGHT + NB_TAPS));
- if (!s->line_buf)
- goto fail;
-
- s->owidth = owidth;
- s->oheight = oheight;
- s->iwidth = iwidth;
- s->iheight = iheight;
- s->topBand = topBand;
- s->bottomBand = bottomBand;
- s->leftBand = leftBand;
- s->rightBand = rightBand;
-
- s->h_incr = ((iwidth - leftBand - rightBand) * POS_FRAC) / owidth;
- s->v_incr = ((iheight - topBand - bottomBand) * POS_FRAC) / oheight;
-
- build_filter(&s->h_filters[0][0], (float) owidth / (float) (iwidth - leftBand - rightBand));
- build_filter(&s->v_filters[0][0], (float) oheight / (float) (iheight - topBand - bottomBand));
-
- return s;
- fail:
- av_free(s);
- return NULL;
-}
-
-void img_resample(ImgReSampleContext *s,
- AVPicture *output, AVPicture *input)
-{
- int i, shift;
-
- for(i=0;i<3;i++) {
- shift = (i == 0) ? 0 : 1;
- component_resample(s, output->data[i], output->linesize[i],
- s->owidth >> shift, s->oheight >> shift,
- input->data[i] + (input->linesize[i] * (s->topBand >> shift)) + (s->leftBand >> shift),
- input->linesize[i], ((s->iwidth - s->leftBand - s->rightBand) >> shift),
- (s->iheight - s->topBand - s->bottomBand) >> shift);
- }
-}
-
-void img_resample_close(ImgReSampleContext *s)
-{
- av_free(s->line_buf);
- av_free(s);
-}
-
-#ifdef TEST
-
-void *av_mallocz(int size)
-{
- void *ptr;
- ptr = malloc(size);
- memset(ptr, 0, size);
- return ptr;
-}
-
-void av_free(void *ptr)
-{
- /* XXX: this test should not be needed on most libcs */
- if (ptr)
- free(ptr);
-}
-
-/* input */
-#define XSIZE 256
-#define YSIZE 256
-uint8_t img[XSIZE * YSIZE];
-
-/* output */
-#define XSIZE1 512
-#define YSIZE1 512
-uint8_t img1[XSIZE1 * YSIZE1];
-uint8_t img2[XSIZE1 * YSIZE1];
-
-void save_pgm(const char *filename, uint8_t *img, int xsize, int ysize)
-{
- FILE *f;
- f=fopen(filename,"w");
- fprintf(f,"P5\n%d %d\n%d\n", xsize, ysize, 255);
- fwrite(img,1, xsize * ysize,f);
- fclose(f);
-}
-
-static void dump_filter(int16_t *filter)
-{
- int i, ph;
-
- for(ph=0;ph<NB_PHASES;ph++) {
- printf("%2d: ", ph);
- for(i=0;i<NB_TAPS;i++) {
- printf(" %5.2f", filter[ph * NB_TAPS + i] / 256.0);
- }
- printf("\n");
- }
-}
-
-#ifdef HAVE_MMX
-int mm_flags;
-#endif
-
-int main(int argc, char **argv)
-{
- int x, y, v, i, xsize, ysize;
- ImgReSampleContext *s;
- float fact, factors[] = { 1/2.0, 3.0/4.0, 1.0, 4.0/3.0, 16.0/9.0, 2.0 };
- char buf[256];
-
- /* build test image */
- for(y=0;y<YSIZE;y++) {
- for(x=0;x<XSIZE;x++) {
- if (x < XSIZE/2 && y < YSIZE/2) {
- if (x < XSIZE/4 && y < YSIZE/4) {
- if ((x % 10) <= 6 &&
- (y % 10) <= 6)
- v = 0xff;
- else
- v = 0x00;
- } else if (x < XSIZE/4) {
- if (x & 1)
- v = 0xff;
- else
- v = 0;
- } else if (y < XSIZE/4) {
- if (y & 1)
- v = 0xff;
- else
- v = 0;
- } else {
- if (y < YSIZE*3/8) {
- if ((y+x) & 1)
- v = 0xff;
- else
- v = 0;
- } else {
- if (((x+3) % 4) <= 1 &&
- ((y+3) % 4) <= 1)
- v = 0xff;
- else
- v = 0x00;
- }
- }
- } else if (x < XSIZE/2) {
- v = ((x - (XSIZE/2)) * 255) / (XSIZE/2);
- } else if (y < XSIZE/2) {
- v = ((y - (XSIZE/2)) * 255) / (XSIZE/2);
- } else {
- v = ((x + y - XSIZE) * 255) / XSIZE;
- }
- img[(YSIZE - y) * XSIZE + (XSIZE - x)] = v;
- }
- }
- save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE);
- for(i=0;i<sizeof(factors)/sizeof(float);i++) {
- fact = factors[i];
- xsize = (int)(XSIZE * fact);
- ysize = (int)((YSIZE - 100) * fact);
- s = img_resample_full_init(xsize, ysize, XSIZE, YSIZE, 50 ,50, 0, 0);
- printf("Factor=%0.2f\n", fact);
- dump_filter(&s->h_filters[0][0]);
- component_resample(s, img1, xsize, xsize, ysize,
- img + 50 * XSIZE, XSIZE, XSIZE, YSIZE - 100);
- img_resample_close(s);
-
- sprintf(buf, "/tmp/out%d.pgm", i);
- save_pgm(buf, img1, xsize, ysize);
- }
-
- /* mmx test */
-#ifdef HAVE_MMX
- printf("MMX test\n");
- fact = 0.72;
- xsize = (int)(XSIZE * fact);
- ysize = (int)(YSIZE * fact);
- mm_flags = MM_MMX;
- s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
- component_resample(s, img1, xsize, xsize, ysize,
- img, XSIZE, XSIZE, YSIZE);
-
- mm_flags = 0;
- s = img_resample_init(xsize, ysize, XSIZE, YSIZE);
- component_resample(s, img2, xsize, xsize, ysize,
- img, XSIZE, XSIZE, YSIZE);
- if (memcmp(img1, img2, xsize * ysize) != 0) {
- fprintf(stderr, "mmx error\n");
- exit(1);
- }
- printf("MMX OK\n");
-#endif
- return 0;
-}
-
-#endif
+++ /dev/null
-/*
- * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
- * written, produced, and directed by Alan Smithee
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#include "indeo3data.h"
-
-typedef struct
-{
- unsigned char *Ybuf;
- unsigned char *Ubuf;
- unsigned char *Vbuf;
- unsigned char *the_buf;
- unsigned int the_buf_size;
- unsigned short y_w, y_h;
- unsigned short uv_w, uv_h;
-} YUVBufs;
-
-typedef struct Indeo3DecodeContext {
- AVCodecContext *avctx;
- int width, height;
- AVFrame frame;
-
- YUVBufs iv_frame[2];
- YUVBufs *cur_frame;
- YUVBufs *ref_frame;
-
- unsigned char *ModPred;
- unsigned short *corrector_type;
-} Indeo3DecodeContext;
-
-static int corrector_type_0[24] = {
- 195, 159, 133, 115, 101, 93, 87, 77,
- 195, 159, 133, 115, 101, 93, 87, 77,
- 128, 79, 79, 79, 79, 79, 79, 79
-};
-
-static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
-
-static void build_modpred(Indeo3DecodeContext *s)
-{
- int i, j;
-
- s->ModPred = (unsigned char *) av_malloc (8 * 128);
-
- for (i=0; i < 128; ++i) {
- s->ModPred[i+0*128] = (i > 126) ? 254 : 2*((i + 1) - ((i + 1) % 2));
- s->ModPred[i+1*128] = (i == 7) ? 20 : ((i == 119 || i == 120)
- ? 236 : 2*((i + 2) - ((i + 1) % 3)));
- s->ModPred[i+2*128] = (i > 125) ? 248 : 2*((i + 2) - ((i + 2) % 4));
- s->ModPred[i+3*128] = 2*((i + 1) - ((i - 3) % 5));
- s->ModPred[i+4*128] = (i == 8) ? 20 : 2*((i + 1) - ((i - 3) % 6));
- s->ModPred[i+5*128] = 2*((i + 4) - ((i + 3) % 7));
- s->ModPred[i+6*128] = (i > 123) ? 240 : 2*((i + 4) - ((i + 4) % 8));
- s->ModPred[i+7*128] = 2*((i + 5) - ((i + 4) % 9));
- }
-
- s->corrector_type = (unsigned short *) av_malloc (24 * 256 * sizeof(unsigned short));
-
- for (i=0; i < 24; ++i) {
- for (j=0; j < 256; ++j) {
- s->corrector_type[i*256+j] = (j < corrector_type_0[i])
- ? 1 : ((j < 248 || (i == 16 && j == 248))
- ? 0 : corrector_type_2[j - 248]);
- }
- }
-}
-
-static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur,
- unsigned char *ref, int width, int height, unsigned char *buf1,
- long fflags2, unsigned char *hdr,
- unsigned char *buf2, int min_width_160);
-
-#define min(a,b) ((a) < (b) ? (a) : (b))
-
-/* ---------------------------------------------------------------------- */
-static void iv_alloc_frames(Indeo3DecodeContext *s)
-{
- int luma_width, luma_height, luma_pixels, chroma_width, chroma_height,
- chroma_pixels, bufsize, i;
-
- luma_width = (s->width + 3) & (~3);
- luma_height = (s->height + 3) & (~3);
-
- s->iv_frame[0].y_w = s->iv_frame[0].y_h =
- s->iv_frame[0].the_buf_size = 0;
- s->iv_frame[1].y_w = s->iv_frame[1].y_h =
- s->iv_frame[1].the_buf_size = 0;
- s->iv_frame[1].the_buf = NULL;
-
- chroma_width = ((luma_width >> 2) + 3) & (~3);
- chroma_height = ((luma_height>> 2) + 3) & (~3);
- luma_pixels = luma_width * luma_height;
- chroma_pixels = chroma_width * chroma_height;
-
- bufsize = luma_pixels * 2 + luma_width * 3 +
- (chroma_pixels + chroma_width) * 4;
-
- if((s->iv_frame[0].the_buf =
- (s->iv_frame[0].the_buf_size == 0 ? av_malloc(bufsize) :
- av_realloc(s->iv_frame[0].the_buf, bufsize))) == NULL)
- return;
- s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width;
- s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height;
- s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width;
- s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height;
- s->iv_frame[0].the_buf_size = bufsize;
-
- s->iv_frame[0].Ybuf = s->iv_frame[0].the_buf + luma_width;
- i = luma_pixels + luma_width * 2;
- s->iv_frame[1].Ybuf = s->iv_frame[0].the_buf + i;
- i += (luma_pixels + luma_width);
- s->iv_frame[0].Ubuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[1].Ubuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[0].Vbuf = s->iv_frame[0].the_buf + i;
- i += (chroma_pixels + chroma_width);
- s->iv_frame[1].Vbuf = s->iv_frame[0].the_buf + i;
-
- for(i = 1; i <= luma_width; i++)
- s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] =
- s->iv_frame[0].Ubuf[-i] = 0x80;
-
- for(i = 1; i <= chroma_width; i++) {
- s->iv_frame[1].Ubuf[-i] = 0x80;
- s->iv_frame[0].Vbuf[-i] = 0x80;
- s->iv_frame[1].Vbuf[-i] = 0x80;
- s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80;
- }
-}
-
-/* ---------------------------------------------------------------------- */
-static void iv_free_func(Indeo3DecodeContext *s)
-{
- int i;
-
- for(i = 0 ; i < 2 ; i++) {
- if(s->iv_frame[i].the_buf != NULL)
- av_free(s->iv_frame[i].the_buf);
- s->iv_frame[i].Ybuf = s->iv_frame[i].Ubuf =
- s->iv_frame[i].Vbuf = NULL;
- s->iv_frame[i].the_buf = NULL;
- s->iv_frame[i].the_buf_size = 0;
- s->iv_frame[i].y_w = s->iv_frame[i].y_h = 0;
- s->iv_frame[i].uv_w = s->iv_frame[i].uv_h = 0;
- }
-
- av_free(s->ModPred);
- av_free(s->corrector_type);
-}
-
-/* ---------------------------------------------------------------------- */
-static unsigned long iv_decode_frame(Indeo3DecodeContext *s,
- unsigned char *buf, int buf_size)
-{
- unsigned int hdr_width, hdr_height,
- chroma_width, chroma_height;
- unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs;
- unsigned char *hdr_pos, *buf_pos;
-
- buf_pos = buf;
- buf_pos += 18;
-
- fflags1 = le2me_16(*(uint16_t *)buf_pos);
- buf_pos += 2;
- fflags3 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- fflags2 = *buf_pos++;
- buf_pos += 3;
- hdr_height = le2me_16(*(uint16_t *)buf_pos);
- buf_pos += 2;
- hdr_width = le2me_16(*(uint16_t *)buf_pos);
- buf_pos += 2;
- chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc;
- chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc;
- offs1 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- offs2 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
- offs3 = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 8;
- hdr_pos = buf_pos;
- if(fflags3 == 0x80) return 4;
-
- if(fflags1 & 0x200) {
- s->cur_frame = s->iv_frame + 1;
- s->ref_frame = s->iv_frame;
- } else {
- s->cur_frame = s->iv_frame;
- s->ref_frame = s->iv_frame + 1;
- }
-
- buf_pos = buf + 16 + offs1;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width,
- hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(hdr_width, 160));
-
- buf_pos = buf + 16 + offs2;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
- chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(chroma_width, 40));
-
- buf_pos = buf + 16 + offs3;
- offs = le2me_32(*(uint32_t *)buf_pos);
- buf_pos += 4;
-
- iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
- chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos,
- min(chroma_width, 40));
-
- return 8;
-}
-
-typedef struct {
- long xpos;
- long ypos;
- long width;
- long height;
- long split_flag;
- long split_direction;
- long usl7;
-} ustr_t;
-
-/* ---------------------------------------------------------------------- */
-
-#define LV1_CHECK(buf1,rle_v3,lv1,lp2) \
- if((lv1 & 0x80) != 0) { \
- if(rle_v3 != 0) \
- rle_v3 = 0; \
- else { \
- rle_v3 = 1; \
- buf1 -= 2; \
- } \
- } \
- lp2 = 4;
-
-
-#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \
- if(rle_v3 == 0) { \
- rle_v2 = *buf1; \
- rle_v1 = 1; \
- if(rle_v2 > 32) { \
- rle_v2 -= 32; \
- rle_v1 = 0; \
- } \
- rle_v3 = 1; \
- } \
- buf1--;
-
-
-#define LP2_CHECK(buf1,rle_v3,lp2) \
- if(lp2 == 0 && rle_v3 != 0) \
- rle_v3 = 0; \
- else { \
- buf1--; \
- rle_v3 = 1; \
- }
-
-
-#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \
- rle_v2--; \
- if(rle_v2 == 0) { \
- rle_v3 = 0; \
- buf1 += 2; \
- } \
- lp2 = 4;
-
-static void iv_Decode_Chunk(Indeo3DecodeContext *s,
- unsigned char *cur, unsigned char *ref, int width, int height,
- unsigned char *buf1, long fflags2, unsigned char *hdr,
- unsigned char *buf2, int min_width_160)
-{
- unsigned char bit_buf;
- unsigned long bit_pos, lv, lv1, lv2;
- long *width_tbl, width_tbl_arr[10];
- char *ref_vectors;
- unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2;
- uint32_t *cur_lp, *ref_lp;
- const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2];
- unsigned short *correction_type_sp[2];
- ustr_t strip_tbl[20], *strip;
- int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width,
- rle_v1, rle_v2, rle_v3;
-
- bit_buf = 0;
- ref_vectors = NULL;
-
- width_tbl = width_tbl_arr + 1;
- i = (width < 0 ? width + 3 : width)/4;
- for(j = -1; j < 8; j++)
- width_tbl[j] = i * j;
-
- strip = strip_tbl;
-
- for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160);
-
- strip->ypos = strip->xpos = 0;
- for(strip->width = min_width_160; width > strip->width; strip->width *= 2);
- strip->height = height;
- strip->split_direction = 0;
- strip->split_flag = 0;
- strip->usl7 = 0;
-
- bit_pos = 0;
-
- rle_v1 = rle_v2 = rle_v3 = 0;
-
- while(strip >= strip_tbl) {
- if(bit_pos <= 0) {
- bit_pos = 8;
- bit_buf = *buf1++;
- }
-
- bit_pos -= 2;
- cmd = (bit_buf >> bit_pos) & 0x03;
-
- if(cmd == 0) {
- strip++;
- memcpy(strip, strip-1, sizeof(ustr_t));
- strip->split_flag = 1;
- strip->split_direction = 0;
- strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4);
- continue;
- } else if(cmd == 1) {
- strip++;
- memcpy(strip, strip-1, sizeof(ustr_t));
- strip->split_flag = 1;
- strip->split_direction = 1;
- strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4);
- continue;
- } else if(cmd == 2) {
- if(strip->usl7 == 0) {
- strip->usl7 = 1;
- ref_vectors = NULL;
- continue;
- }
- } else if(cmd == 3) {
- if(strip->usl7 == 0) {
- strip->usl7 = 1;
- ref_vectors = buf2 + (*buf1 * 2);
- buf1++;
- continue;
- }
- }
-
- cur_frm_pos = cur + width * strip->ypos + strip->xpos;
-
- if((blks_width = strip->width) < 0)
- blks_width += 3;
- blks_width >>= 2;
- blks_height = strip->height;
-
- if(ref_vectors != NULL) {
- ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width +
- ref_vectors[1] + strip->xpos;
- } else
- ref_frm_pos = cur_frm_pos - width_tbl[4];
-
- if(cmd == 2) {
- if(bit_pos <= 0) {
- bit_pos = 8;
- bit_buf = *buf1++;
- }
-
- bit_pos -= 2;
- cmd = (bit_buf >> bit_pos) & 0x03;
-
- if(cmd == 0 || ref_vectors != NULL) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1])
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
- } else if(cmd != 1)
- return;
- } else {
- k = *buf1 >> 4;
- j = *buf1 & 0x0f;
- buf1++;
- lv = j + fflags2;
-
- if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) {
- cp2 = s->ModPred + ((lv - 8) << 7);
- cp = ref_frm_pos;
- for(i = 0; i < blks_width << 2; i++) {
- int v = *cp >> 1;
- *(cp++) = cp2[v];
- }
- }
-
- if(k == 1 || k == 4) {
- lv = (hdr[j] & 0xf) + fflags2;
- correction_type_sp[0] = s->corrector_type + (lv << 8);
- correction_lp[0] = correction + (lv << 8);
- lv = (hdr[j] >> 4) + fflags2;
- correction_lp[1] = correction + (lv << 8);
- correction_type_sp[1] = s->corrector_type + (lv << 8);
- } else {
- correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8);
- correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8);
- correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8);
- correction_lp[0] = correction_lp[1] = correction + (lv << 8);
- }
-
- switch(k) {
- case 1:
- case 0: /********** CASE 0 **********/
- for( ; blks_height > 0; blks_height -= 4) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2];
-
- switch(correction_type_sp[0][k]) {
- case 0:
- *cur_lp = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- lp2++;
- break;
- case 1:
- ((unsigned short *)cur_lp)[0] = ((((unsigned short *)(ref_lp))[0] >> 1)
- + correction_lp[lp2 & 0x01][*buf1++]) << 1;
- ((unsigned short *)cur_lp)[1] = ((((unsigned short *)(ref_lp))[1] >> 1)
- + correction_lp[lp2 & 0x01][k]) << 1;
- lp2++;
- break;
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 2; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 += 2;
- }
- break;
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 3;
- }
- break;
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- if(rle_v1 == 1 || ref_vectors != NULL) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = *buf1 - 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 4;
- break;
-
- case 7:
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- case 6:
- if(ref_vectors != NULL) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
- lp2 = 4;
- break;
-
- case 9:
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
-
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
-
- cur_frm_pos += ((width - blks_width) * 4);
- ref_frm_pos += ((width - blks_width) * 4);
- }
- break;
-
- case 4:
- case 3: /********** CASE 3 **********/
- if(ref_vectors != NULL)
- return;
- flag1 = 1;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
-
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[width_tbl[1]] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- else
- cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- lp2++;
- break;
-
- case 1:
- ((unsigned short *)cur_lp)[width_tbl[2]] =
- ((((unsigned short *)ref_lp)[0] >> 1) + correction_lp[lp2 & 0x01][*buf1++]) << 1;
- ((unsigned short *)cur_lp)[width_tbl[2]+1] =
- ((((unsigned short *)ref_lp)[1] >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0)
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- else
- cur_lp[0] = cur_lp[width_tbl[1]];
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 = 3;
- }
- break;
-
- case 6:
- lp2 = 4;
- break;
-
- case 7:
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- lp2 = 4;
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- if(rle_v1 == 1) {
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- }
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v2 = (*buf1) - 1;
- rle_v1 = 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = *ref_lp;
- lp2 = 4;
- break;
-
- case 9:
- fprintf(stderr, "UNTESTED.\n");
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
-
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
-
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- flag1 = 0;
- }
- break;
-
- case 10: /********** CASE 10 **********/
- if(ref_vectors == NULL) {
- flag1 = 1;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1];
- lv1 = ref_lp[0];
- lv2 = ref_lp[1];
- if(lp2 == 0 && flag1 != 0) {
- lv1 = lv1 & 0x00FF00FF;
- lv1 = (lv1 << 8) | lv1;
- lv2 = lv2 & 0x00FF00FF;
- lv2 = (lv2 << 8) | lv2;
- }
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1;
- cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1;
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- lp2++;
- break;
-
- case 1:
- cur_lp[width_tbl[1]] = ((lv1 >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1++]) << 1;
- cur_lp[width_tbl[1]+1] = ((lv2 >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1;
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- if(flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- if(lp2 == 0 && flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
- if(rle_v1 == 1) {
- if(flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- }
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- if(lp2 == 0 && flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- }
- lp2 = 4;
- break;
-
- case 6:
- lp2 = 4;
- break;
-
- case 7:
- if(lp2 == 0) {
- if(rle_v3 != 0)
- rle_v3 = 0;
- else {
- buf1--;
- rle_v3 = 1;
- }
- lp2 = 4;
- }
- break;
-
- case 9:
- fprintf(stderr, "UNTESTED.\n");
- lv1 = *buf1;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 8;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- flag1 = 0;
- }
- } else {
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1 += 2) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- lv1 = correctionloworder_lp[lp2 & 0x01][k];
- lv2 = correctionhighorder_lp[lp2 & 0x01][k];
- cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1;
- cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1;
- cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1;
- cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1;
- lp2++;
- break;
-
- case 1:
- lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++];
- lv2 = correctionloworder_lp[lp2 & 0x01][k];
- cur_lp[0] = ((ref_lp[0] >> 1) + lv1) << 1;
- cur_lp[1] = ((ref_lp[1] >> 1) + lv2) << 1;
- cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + lv1) << 1;
- cur_lp[width_tbl[1]+1] = ((ref_lp[width_tbl[1]+1] >> 1) + lv2) << 1;
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) {
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j];
- ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1];
- }
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- case 7:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 6:
- case 4:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) {
- cur_lp[j] = ref_lp[j];
- cur_lp[j+1] = ref_lp[j+1];
- }
- lp2 = 4;
- break;
-
- case 9:
- fprintf(stderr, "UNTESTED.\n");
- lv1 = *buf1;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 8;
- ref_frm_pos += 8;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- ref_frm_pos += (((width * 2) - blks_width) * 4);
- }
- }
- break;
-
- case 11: /********** CASE 11 **********/
- if(ref_vectors == NULL)
- return;
-
- for( ; blks_height > 0; blks_height -= 8) {
- for(lp1 = 0; lp1 < blks_width; lp1++) {
- for(lp2 = 0; lp2 < 4; ) {
- k = *buf1++;
- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2];
- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2];
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[0] = ((*ref_lp >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- cur_lp[width_tbl[1]] = ((ref_lp[width_tbl[1]] >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
- lp2++;
- break;
-
- case 1:
- lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]);
- lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]);
- ((unsigned short *)cur_lp)[0] = ((((unsigned short *)ref_lp)[0] >> 1) + lv1) << 1;
- ((unsigned short *)cur_lp)[1] = ((((unsigned short *)ref_lp)[1] >> 1) + lv2) << 1;
- ((unsigned short *)cur_lp)[width_tbl[2]] = ((((unsigned short *)ref_lp)[width_tbl[2]] >> 1) + lv1) << 1;
- ((unsigned short *)cur_lp)[width_tbl[2]+1] = ((((unsigned short *)ref_lp)[width_tbl[2]+1] >> 1) + lv2) << 1;
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 += 2;
- }
- break;
-
- case 3:
- if(lp2 < 2) {
- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 3;
- }
- break;
-
- case 8:
- if(lp2 == 0) {
- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3)
-
- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
-
- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2)
- break;
- } else {
- rle_v1 = 1;
- rle_v2 = (*buf1) - 1;
- }
- case 5:
- case 7:
- LP2_CHECK(buf1,rle_v3,lp2)
- case 4:
- case 6:
- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1])
- cur_lp[j] = ref_lp[j];
- lp2 = 4;
- break;
-
- case 9:
- fprintf(stderr, "UNTESTED.\n");
- lv1 = *buf1++;
- lv = (lv1 & 0x7F) << 1;
- lv += (lv << 8);
- lv += (lv << 16);
- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1])
- cur_lp[j] = lv;
- LV1_CHECK(buf1,rle_v3,lv1,lp2)
- break;
-
- default:
- return;
- }
- }
-
- cur_frm_pos += 4;
- ref_frm_pos += 4;
- }
-
- cur_frm_pos += (((width * 2) - blks_width) * 4);
- ref_frm_pos += (((width * 2) - blks_width) * 4);
- }
- break;
-
- default:
- return;
- }
- }
-
- if(strip < strip_tbl)
- return;
-
- for( ; strip >= strip_tbl; strip--) {
- if(strip->split_flag != 0) {
- strip->split_flag = 0;
- strip->usl7 = (strip-1)->usl7;
-
- if(strip->split_direction) {
- strip->xpos += strip->width;
- strip->width = (strip-1)->width - strip->width;
- if(region_160_width <= strip->xpos && width < strip->width + strip->xpos)
- strip->width = width - strip->xpos;
- } else {
- strip->ypos += strip->height;
- strip->height = (strip-1)->height - strip->height;
- }
- break;
- }
- }
- }
-}
-
-static int indeo3_decode_init(AVCodecContext *avctx)
-{
- Indeo3DecodeContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->width = avctx->width;
- s->height = avctx->height;
- avctx->pix_fmt = PIX_FMT_YUV410P;
- avctx->has_b_frames = 0;
-
- build_modpred(s);
- iv_alloc_frames(s);
-
- return 0;
-}
-
-static int indeo3_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- unsigned char *buf, int buf_size)
-{
- Indeo3DecodeContext *s=avctx->priv_data;
- unsigned char *src, *dest;
- int y;
-
- iv_decode_frame(s, buf, buf_size);
-
- if(s->frame.data[0])
- avctx->release_buffer(avctx, &s->frame);
-
- s->frame.reference = 0;
- if(avctx->get_buffer(avctx, &s->frame) < 0) {
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
-
- src = s->cur_frame->Ybuf;
- dest = s->frame.data[0];
- for (y = 0; y < s->height; y++) {
- memcpy(dest, src, s->cur_frame->y_w);
- src += s->cur_frame->y_w;
- dest += s->frame.linesize[0];
- }
-
- src = s->cur_frame->Ubuf;
- dest = s->frame.data[1];
- for (y = 0; y < s->height / 4; y++) {
- memcpy(dest, src, s->cur_frame->uv_w);
- src += s->cur_frame->uv_w;
- dest += s->frame.linesize[1];
- }
-
- src = s->cur_frame->Vbuf;
- dest = s->frame.data[2];
- for (y = 0; y < s->height / 4; y++) {
- memcpy(dest, src, s->cur_frame->uv_w);
- src += s->cur_frame->uv_w;
- dest += s->frame.linesize[2];
- }
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data= s->frame;
-
- return buf_size;
-}
-
-static int indeo3_decode_end(AVCodecContext *avctx)
-{
- Indeo3DecodeContext *s = avctx->priv_data;
-
- iv_free_func(s);
-
- return 0;
-}
-
-AVCodec indeo3_decoder = {
- "indeo3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_INDEO3,
- sizeof(Indeo3DecodeContext),
- indeo3_decode_init,
- NULL,
- indeo3_decode_end,
- indeo3_decode_frame,
- 0,
- NULL
-};
+++ /dev/null
-
-static const uint32_t correction[] = {
- 0x00000000, 0x00000202, 0xfffffdfe, 0x000002ff, 0xfffffd01, 0xffffff03, 0x000000fd, 0x00000404,
- 0xfffffbfc, 0x00000501, 0xfffffaff, 0x00000105, 0xfffffefb, 0x000003fc, 0xfffffc04, 0x000005fe,
- 0xfffffa02, 0xfffffe06, 0x000001fa, 0x00000904, 0xfffff6fc, 0x00000409, 0xfffffbf7, 0x00000909,
- 0xfffff6f7, 0x00000a01, 0xfffff5ff, 0x0000010a, 0xfffffef6, 0x000007fb, 0xfffff805, 0xfffffb08,
- 0x000004f8, 0x00000f09, 0xfffff0f7, 0x0000090f, 0xfffff6f1, 0x00000bfd, 0xfffff403, 0xfffffd0c,
- 0x000002f4, 0x00001004, 0xffffeffc, 0x00000410, 0xfffffbf0, 0x00001010, 0xffffeff0, 0x00001200,
- 0xffffee00, 0x00000012, 0xffffffee, 0x00000bf4, 0xfffff40c, 0x00000ff7, 0xfffff009, 0xfffff710,
- 0x000008f0, 0x00001b0b, 0xffffe4f5, 0x00000b1b, 0xfffff4e5, 0x00001c13, 0xffffe3ed, 0x0000131c,
- 0xffffece4, 0x000015fa, 0xffffea06, 0xfffffa16, 0x000005ea, 0x00001d04, 0xffffe2fc, 0x0000041d,
- 0xfffffbe3, 0x00001e1e, 0xffffe1e2, 0x000020fe, 0xffffdf02, 0xfffffe21, 0x000001df, 0x000016ee,
- 0xffffe912, 0xffffee17, 0x000011e9, 0x00001df1, 0xffffe20f, 0xfffff11e, 0x00000ee2, 0x00002e16,
- 0xffffd1ea, 0x0000162e, 0xffffe9d2, 0x00002f0d, 0xffffd0f3, 0x00000d2f, 0xfffff2d1, 0x00003123,
- 0xffffcedd, 0x00002331, 0xffffdccf, 0x000028f5, 0xffffd70b, 0xfffff529, 0x00000ad7, 0x00003304,
- 0xffffccfc, 0x00000433, 0xfffffbcd, 0x00003636, 0xffffc9ca, 0x000021de, 0xffffde22, 0x000029e3,
- 0xffffd61d, 0xffffe32a, 0x00001cd6, 0x00003bfa, 0xffffc406, 0xfffffa3c, 0x000005c4, 0x00004c1b,
- 0xffffb3e5, 0x00001b4c, 0xffffe4b4, 0x00004d2b, 0xffffb2d5, 0x00002b4d, 0xffffd4b3, 0x000036e8,
- 0xffffc918, 0xffffe837, 0x000017c9, 0x00004f0e, 0xffffb0f2, 0x00000e4f, 0xfffff1b1, 0x0000533f,
- 0xffffacc1, 0x00003f53, 0xffffc0ad, 0x000049ec, 0xffffb614, 0xffffec4a, 0x000013b6, 0x00005802,
- 0xffffa7fe, 0x00000258, 0xfffffda8, 0x00005d5d, 0xffffa2a3, 0x00003ccc, 0xffffc334, 0xffffcc3d,
- 0x000033c3, 0x00007834, 0xffff87cc, 0x00003478, 0xffffcb88, 0x00004ad3, 0xffffb52d, 0xffffd34b,
- 0x00002cb5, 0x00007d4b, 0xffff82b5, 0x00004b7d, 0xffffb483, 0x00007a21, 0xffff85df, 0x0000217a,
- 0xffffde86, 0x000066f3, 0xffff990d, 0xfffff367, 0x00000c99, 0x00005fd8, 0xffffa028, 0xffffd860,
- 0x000027a0, 0x00007ede, 0xffff8122, 0xffffde7f, 0x00002181, 0x000058a7, 0xffffa759, 0x000068b2,
- 0xffff974e, 0xffffb269, 0x00004d97, 0x00000c0c, 0xfffff3f4, 0x00001717, 0xffffe8e9, 0x00002a2a,
- 0xffffd5d6, 0x00004949, 0xffffb6b7, 0x00000000, 0x02020000, 0xfdfe0000, 0x02ff0000, 0xfd010000,
- 0xff030000, 0x00fd0000, 0x00000202, 0x02020202, 0xfdfe0202, 0x02ff0202, 0xfd010202, 0xff030202,
- 0x00fd0202, 0xfffffdfe, 0x0201fdfe, 0xfdfdfdfe, 0x02fefdfe, 0xfd00fdfe, 0xff02fdfe, 0x00fcfdfe,
- 0x000002ff, 0x020202ff, 0xfdfe02ff, 0x02ff02ff, 0xfd0102ff, 0xff0302ff, 0x00fd02ff, 0xfffffd01,
- 0x0201fd01, 0xfdfdfd01, 0x02fefd01, 0xfd00fd01, 0xff02fd01, 0x00fcfd01, 0xffffff03, 0x0201ff03,
- 0xfdfdff03, 0x02feff03, 0xfd00ff03, 0xff02ff03, 0x00fcff03, 0x000000fd, 0x020200fd, 0xfdfe00fd,
- 0x02ff00fd, 0xfd0100fd, 0xff0300fd, 0x00fd00fd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000303, 0xfffffcfd, 0x000003ff, 0xfffffc01, 0xffffff04, 0x000000fc, 0x00000707,
- 0xfffff8f9, 0x00000802, 0xfffff7fe, 0x00000208, 0xfffffdf8, 0x000008fe, 0xfffff702, 0xfffffe09,
- 0x000001f7, 0x000005fa, 0xfffffa06, 0x00000d06, 0xfffff2fa, 0x0000060d, 0xfffff9f3, 0x00000d0d,
- 0xfffff2f3, 0x00000e01, 0xfffff1ff, 0x0000010e, 0xfffffef2, 0x00000bf8, 0xfffff408, 0xfffff80c,
- 0x000007f4, 0x0000170e, 0xffffe8f2, 0x00000e17, 0xfffff1e9, 0x000011fb, 0xffffee05, 0xfffffb12,
- 0x000004ee, 0x00001806, 0xffffe7fa, 0x00000618, 0xfffff9e8, 0x00001818, 0xffffe7e8, 0x00001aff,
- 0xffffe501, 0xffffff1b, 0x000000e5, 0x000010ef, 0xffffef11, 0x000016f3, 0xffffe90d, 0xfffff317,
- 0x00000ce9, 0x00002810, 0xffffd7f0, 0x00001028, 0xffffefd8, 0x0000291c, 0xffffd6e4, 0x00001c29,
- 0xffffe3d7, 0x000020f7, 0xffffdf09, 0xfffff721, 0x000008df, 0x00002b06, 0xffffd4fa, 0x0000062b,
- 0xfffff9d5, 0x00002e2e, 0xffffd1d2, 0x000031fc, 0xffffce04, 0xfffffc32, 0x000003ce, 0x000021e5,
- 0xffffde1b, 0xffffe522, 0x00001ade, 0x00002cea, 0xffffd316, 0xffffea2d, 0x000015d3, 0x00004522,
- 0xffffbade, 0x00002245, 0xffffddbb, 0x00004613, 0xffffb9ed, 0x00001346, 0xffffecba, 0x00004935,
- 0xffffb6cb, 0x00003549, 0xffffcab7, 0x00003def, 0xffffc211, 0xffffef3e, 0x000010c2, 0x00004d05,
- 0xffffb2fb, 0x0000054d, 0xfffffab3, 0x00005252, 0xffffadae, 0x000032cd, 0xffffcd33, 0x00003fd5,
- 0xffffc02b, 0xffffd540, 0x00002ac0, 0x000059f6, 0xffffa60a, 0xfffff65a, 0x000009a6, 0x00007229,
- 0xffff8dd7, 0x00002972, 0xffffd68e, 0x00007440, 0xffff8bc0, 0x00004074, 0xffffbf8c, 0x000051db,
- 0xffffae25, 0xffffdb52, 0x000024ae, 0x00007716, 0xffff88ea, 0x00001677, 0xffffe989, 0x00007c5f,
- 0xffff83a1, 0x00005f7c, 0xffffa084, 0x00006ee2, 0xffff911e, 0xffffe26f, 0x00001d91, 0x00005bb2,
- 0xffffa44e, 0xffffb25c, 0x00004da4, 0x000070bc, 0xffff8f44, 0xffffbc71, 0x0000438f, 0x00001212,
- 0xffffedee, 0x00002222, 0xffffddde, 0x00003f3f, 0xffffc0c1, 0x00006d6d, 0xffff9293, 0x00000000,
- 0x03030000, 0xfcfd0000, 0x03ff0000, 0xfc010000, 0xff040000, 0x00fc0000, 0x07070000, 0xf8f90000,
- 0x00000303, 0x03030303, 0xfcfd0303, 0x03ff0303, 0xfc010303, 0xff040303, 0x00fc0303, 0x07070303,
- 0xf8f90303, 0xfffffcfd, 0x0302fcfd, 0xfcfcfcfd, 0x03fefcfd, 0xfc00fcfd, 0xff03fcfd, 0x00fbfcfd,
- 0x0706fcfd, 0xf8f8fcfd, 0x000003ff, 0x030303ff, 0xfcfd03ff, 0x03ff03ff, 0xfc0103ff, 0xff0403ff,
- 0x00fc03ff, 0x070703ff, 0xf8f903ff, 0xfffffc01, 0x0302fc01, 0xfcfcfc01, 0x03fefc01, 0xfc00fc01,
- 0xff03fc01, 0x00fbfc01, 0x0706fc01, 0xf8f8fc01, 0xffffff04, 0x0302ff04, 0xfcfcff04, 0x03feff04,
- 0xfc00ff04, 0xff03ff04, 0x00fbff04, 0x0706ff04, 0xf8f8ff04, 0x000000fc, 0x030300fc, 0xfcfd00fc,
- 0x03ff00fc, 0xfc0100fc, 0xff0400fc, 0x00fc00fc, 0x070700fc, 0xf8f900fc, 0x00000707, 0x03030707,
- 0xfcfd0707, 0x03ff0707, 0xfc010707, 0xff040707, 0x00fc0707, 0x07070707, 0xf8f90707, 0xfffff8f9,
- 0x0302f8f9, 0xfcfcf8f9, 0x03fef8f9, 0xfc00f8f9, 0xff03f8f9, 0x00fbf8f9, 0x0706f8f9, 0xf8f8f8f9,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000404, 0xfffffbfc, 0x000004ff, 0xfffffb01, 0xffffff05, 0x000000fb, 0x00000a03,
- 0xfffff5fd, 0x0000030a, 0xfffffcf6, 0x00000909, 0xfffff6f7, 0x000006f9, 0xfffff907, 0x00000bfd,
- 0xfffff403, 0xfffffd0c, 0x000002f4, 0x00001108, 0xffffeef8, 0x00000811, 0xfffff7ef, 0x00001111,
- 0xffffeeef, 0x00001301, 0xffffecff, 0x00000113, 0xfffffeed, 0x00000ff5, 0xfffff00b, 0xfffff510,
- 0x00000af0, 0x000016fa, 0xffffe906, 0xfffffa17, 0x000005e9, 0x00001f12, 0xffffe0ee, 0x0000121f,
- 0xffffede1, 0x00002008, 0xffffdff8, 0x00000820, 0xfffff7e0, 0x00002121, 0xffffdedf, 0x000023ff,
- 0xffffdc01, 0xffffff24, 0x000000dc, 0x000016e9, 0xffffe917, 0x00001eef, 0xffffe111, 0xffffef1f,
- 0x000010e1, 0x00003615, 0xffffc9eb, 0x00001536, 0xffffeaca, 0x00003725, 0xffffc8db, 0x00002537,
- 0xffffdac9, 0x00002bf4, 0xffffd40c, 0xfffff42c, 0x00000bd4, 0x00003908, 0xffffc6f8, 0x00000839,
- 0xfffff7c7, 0x00003d3d, 0xffffc2c3, 0x000041fb, 0xffffbe05, 0xfffffb42, 0x000004be, 0x00002cdc,
- 0xffffd324, 0xffffdc2d, 0x000023d3, 0x00003be3, 0xffffc41d, 0xffffe33c, 0x00001cc4, 0x00005c2d,
- 0xffffa3d3, 0x00002d5c, 0xffffd2a4, 0x00005d19, 0xffffa2e7, 0x0000195d, 0xffffe6a3, 0x00006147,
- 0xffff9eb9, 0x00004761, 0xffffb89f, 0x000052ea, 0xffffad16, 0xffffea53, 0x000015ad, 0x00006607,
- 0xffff99f9, 0x00000766, 0xfffff89a, 0x00006d6d, 0xffff9293, 0x000043bc, 0xffffbc44, 0x000054c7,
- 0xffffab39, 0xffffc755, 0x000038ab, 0x000077f3, 0xffff880d, 0xfffff378, 0x00000c88, 0x00006dcf,
- 0xffff9231, 0xffffcf6e, 0x00003092, 0x00007a98, 0xffff8568, 0xffff987b, 0x00006785, 0x00001818,
- 0xffffe7e8, 0x00002e2e, 0xffffd1d2, 0x00005454, 0xffffabac, 0x00000000, 0x04040000, 0xfbfc0000,
- 0x04ff0000, 0xfb010000, 0xff050000, 0x00fb0000, 0x0a030000, 0xf5fd0000, 0x030a0000, 0x00000404,
- 0x04040404, 0xfbfc0404, 0x04ff0404, 0xfb010404, 0xff050404, 0x00fb0404, 0x0a030404, 0xf5fd0404,
- 0x030a0404, 0xfffffbfc, 0x0403fbfc, 0xfbfbfbfc, 0x04fefbfc, 0xfb00fbfc, 0xff04fbfc, 0x00fafbfc,
- 0x0a02fbfc, 0xf5fcfbfc, 0x0309fbfc, 0x000004ff, 0x040404ff, 0xfbfc04ff, 0x04ff04ff, 0xfb0104ff,
- 0xff0504ff, 0x00fb04ff, 0x0a0304ff, 0xf5fd04ff, 0x030a04ff, 0xfffffb01, 0x0403fb01, 0xfbfbfb01,
- 0x04fefb01, 0xfb00fb01, 0xff04fb01, 0x00fafb01, 0x0a02fb01, 0xf5fcfb01, 0x0309fb01, 0xffffff05,
- 0x0403ff05, 0xfbfbff05, 0x04feff05, 0xfb00ff05, 0xff04ff05, 0x00faff05, 0x0a02ff05, 0xf5fcff05,
- 0x0309ff05, 0x000000fb, 0x040400fb, 0xfbfc00fb, 0x04ff00fb, 0xfb0100fb, 0xff0500fb, 0x00fb00fb,
- 0x0a0300fb, 0xf5fd00fb, 0x030a00fb, 0x00000a03, 0x04040a03, 0xfbfc0a03, 0x04ff0a03, 0xfb010a03,
- 0xff050a03, 0x00fb0a03, 0x0a030a03, 0xf5fd0a03, 0x030a0a03, 0xfffff5fd, 0x0403f5fd, 0xfbfbf5fd,
- 0x04fef5fd, 0xfb00f5fd, 0xff04f5fd, 0x00faf5fd, 0x0a02f5fd, 0xf5fcf5fd, 0x0309f5fd, 0x0000030a,
- 0x0404030a, 0xfbfc030a, 0x04ff030a, 0xfb01030a, 0xff05030a, 0x00fb030a, 0x0a03030a, 0xf5fd030a,
- 0x030a030a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000505, 0xfffffafb, 0x000006fe, 0xfffff902, 0xfffffe07, 0x000001f9, 0x00000b0b,
- 0xfffff4f5, 0x00000d03, 0xfffff2fd, 0x0000030d, 0xfffffcf3, 0x000008f7, 0xfffff709, 0x00000efc,
- 0xfffff104, 0xfffffc0f, 0x000003f1, 0x0000160b, 0xffffe9f5, 0x00000b16, 0xfffff4ea, 0x00001515,
- 0xffffeaeb, 0x00001802, 0xffffe7fe, 0x00000218, 0xfffffde8, 0x000013f2, 0xffffec0e, 0xfffff214,
- 0x00000dec, 0x00002617, 0xffffd9e9, 0x00001726, 0xffffe8da, 0x00001cf8, 0xffffe308, 0xfffff81d,
- 0x000007e3, 0x0000270b, 0xffffd8f5, 0x00000b27, 0xfffff4d9, 0x00002929, 0xffffd6d7, 0x00002cff,
- 0xffffd301, 0xffffff2d, 0x000000d3, 0x00001ce3, 0xffffe31d, 0x000026ea, 0xffffd916, 0xffffea27,
- 0x000015d9, 0x0000431b, 0xffffbce5, 0x00001b43, 0xffffe4bd, 0x0000452f, 0xffffbad1, 0x00002f45,
- 0xffffd0bb, 0x000037f1, 0xffffc80f, 0xfffff138, 0x00000ec8, 0x0000470b, 0xffffb8f5, 0x00000b47,
- 0xfffff4b9, 0x00004c4c, 0xffffb3b4, 0x000052fa, 0xffffad06, 0xfffffa53, 0x000005ad, 0x000038d3,
- 0xffffc72d, 0xffffd339, 0x00002cc7, 0x00004adc, 0xffffb524, 0xffffdc4b, 0x000023b5, 0x00007338,
- 0xffff8cc8, 0x00003873, 0xffffc78d, 0x0000751f, 0xffff8ae1, 0x00001f75, 0xffffe08b, 0x00007a58,
- 0xffff85a8, 0x0000587a, 0xffffa786, 0x000067e4, 0xffff981c, 0xffffe468, 0x00001b98, 0x000054ab,
- 0xffffab55, 0x000069b8, 0xffff9648, 0xffffb86a, 0x00004796, 0x00001e1e, 0xffffe1e2, 0x00003a3a,
- 0xffffc5c6, 0x00006969, 0xffff9697, 0x00000000, 0x05050000, 0xfafb0000, 0x06fe0000, 0xf9020000,
- 0xfe070000, 0x01f90000, 0x0b0b0000, 0xf4f50000, 0x0d030000, 0xf2fd0000, 0x00000505, 0x05050505,
- 0xfafb0505, 0x06fe0505, 0xf9020505, 0xfe070505, 0x01f90505, 0x0b0b0505, 0xf4f50505, 0x0d030505,
- 0xf2fd0505, 0xfffffafb, 0x0504fafb, 0xfafafafb, 0x06fdfafb, 0xf901fafb, 0xfe06fafb, 0x01f8fafb,
- 0x0b0afafb, 0xf4f4fafb, 0x0d02fafb, 0xf2fcfafb, 0x000006fe, 0x050506fe, 0xfafb06fe, 0x06fe06fe,
- 0xf90206fe, 0xfe0706fe, 0x01f906fe, 0x0b0b06fe, 0xf4f506fe, 0x0d0306fe, 0xf2fd06fe, 0xfffff902,
- 0x0504f902, 0xfafaf902, 0x06fdf902, 0xf901f902, 0xfe06f902, 0x01f8f902, 0x0b0af902, 0xf4f4f902,
- 0x0d02f902, 0xf2fcf902, 0xfffffe07, 0x0504fe07, 0xfafafe07, 0x06fdfe07, 0xf901fe07, 0xfe06fe07,
- 0x01f8fe07, 0x0b0afe07, 0xf4f4fe07, 0x0d02fe07, 0xf2fcfe07, 0x000001f9, 0x050501f9, 0xfafb01f9,
- 0x06fe01f9, 0xf90201f9, 0xfe0701f9, 0x01f901f9, 0x0b0b01f9, 0xf4f501f9, 0x0d0301f9, 0xf2fd01f9,
- 0x00000b0b, 0x05050b0b, 0xfafb0b0b, 0x06fe0b0b, 0xf9020b0b, 0xfe070b0b, 0x01f90b0b, 0x0b0b0b0b,
- 0xf4f50b0b, 0x0d030b0b, 0xf2fd0b0b, 0xfffff4f5, 0x0504f4f5, 0xfafaf4f5, 0x06fdf4f5, 0xf901f4f5,
- 0xfe06f4f5, 0x01f8f4f5, 0x0b0af4f5, 0xf4f4f4f5, 0x0d02f4f5, 0xf2fcf4f5, 0x00000d03, 0x05050d03,
- 0xfafb0d03, 0x06fe0d03, 0xf9020d03, 0xfe070d03, 0x01f90d03, 0x0b0b0d03, 0xf4f50d03, 0x0d030d03,
- 0xf2fd0d03, 0xfffff2fd, 0x0504f2fd, 0xfafaf2fd, 0x06fdf2fd, 0xf901f2fd, 0xfe06f2fd, 0x01f8f2fd,
- 0x0b0af2fd, 0xf4f4f2fd, 0x0d02f2fd, 0xf2fcf2fd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000606, 0xfffff9fa, 0x000007fe, 0xfffff802, 0xfffffe08, 0x000001f8, 0x00000d0d,
- 0xfffff2f3, 0x00000f04, 0xfffff0fc, 0x0000040f, 0xfffffbf1, 0x00000af5, 0xfffff50b, 0x000011fb,
- 0xffffee05, 0xfffffb12, 0x000004ee, 0x00001a0d, 0xffffe5f3, 0x00000d1a, 0xfffff2e6, 0x00001a1a,
- 0xffffe5e6, 0x00001d02, 0xffffe2fe, 0x0000021d, 0xfffffde3, 0x000017f0, 0xffffe810, 0xfffff018,
- 0x00000fe8, 0x00002e1c, 0xffffd1e4, 0x00001c2e, 0xffffe3d2, 0x000022f7, 0xffffdd09, 0xfffff723,
- 0x000008dd, 0x00002f0d, 0xffffd0f3, 0x00000d2f, 0xfffff2d1, 0x00003131, 0xffffcecf, 0x000035ff,
- 0xffffca01, 0xffffff36, 0x000000ca, 0x000022dd, 0xffffdd23, 0x00002ee6, 0xffffd11a, 0xffffe62f,
- 0x000019d1, 0x00005120, 0xffffaee0, 0x00002051, 0xffffdfaf, 0x00005338, 0xffffacc8, 0x00003853,
- 0xffffc7ad, 0x000042ee, 0xffffbd12, 0xffffee43, 0x000011bd, 0x0000560d, 0xffffa9f3, 0x00000d56,
- 0xfffff2aa, 0x00005b5b, 0xffffa4a5, 0x000062f9, 0xffff9d07, 0xfffff963, 0x0000069d, 0x000043ca,
- 0xffffbc36, 0xffffca44, 0x000035bc, 0x000059d4, 0xffffa62c, 0xffffd45a, 0x00002ba6, 0x00007bdf,
- 0xffff8421, 0xffffdf7c, 0x00002084, 0x00006699, 0xffff9967, 0x00007eaa, 0xffff8156, 0xffffaa7f,
- 0x00005581, 0x00002525, 0xffffdadb, 0x00004545, 0xffffbabb, 0x00000000, 0x06060000, 0xf9fa0000,
- 0x07fe0000, 0xf8020000, 0xfe080000, 0x01f80000, 0x0d0d0000, 0xf2f30000, 0x0f040000, 0xf0fc0000,
- 0x040f0000, 0x00000606, 0x06060606, 0xf9fa0606, 0x07fe0606, 0xf8020606, 0xfe080606, 0x01f80606,
- 0x0d0d0606, 0xf2f30606, 0x0f040606, 0xf0fc0606, 0x040f0606, 0xfffff9fa, 0x0605f9fa, 0xf9f9f9fa,
- 0x07fdf9fa, 0xf801f9fa, 0xfe07f9fa, 0x01f7f9fa, 0x0d0cf9fa, 0xf2f2f9fa, 0x0f03f9fa, 0xf0fbf9fa,
- 0x040ef9fa, 0x000007fe, 0x060607fe, 0xf9fa07fe, 0x07fe07fe, 0xf80207fe, 0xfe0807fe, 0x01f807fe,
- 0x0d0d07fe, 0xf2f307fe, 0x0f0407fe, 0xf0fc07fe, 0x040f07fe, 0xfffff802, 0x0605f802, 0xf9f9f802,
- 0x07fdf802, 0xf801f802, 0xfe07f802, 0x01f7f802, 0x0d0cf802, 0xf2f2f802, 0x0f03f802, 0xf0fbf802,
- 0x040ef802, 0xfffffe08, 0x0605fe08, 0xf9f9fe08, 0x07fdfe08, 0xf801fe08, 0xfe07fe08, 0x01f7fe08,
- 0x0d0cfe08, 0xf2f2fe08, 0x0f03fe08, 0xf0fbfe08, 0x040efe08, 0x000001f8, 0x060601f8, 0xf9fa01f8,
- 0x07fe01f8, 0xf80201f8, 0xfe0801f8, 0x01f801f8, 0x0d0d01f8, 0xf2f301f8, 0x0f0401f8, 0xf0fc01f8,
- 0x040f01f8, 0x00000d0d, 0x06060d0d, 0xf9fa0d0d, 0x07fe0d0d, 0xf8020d0d, 0xfe080d0d, 0x01f80d0d,
- 0x0d0d0d0d, 0xf2f30d0d, 0x0f040d0d, 0xf0fc0d0d, 0x040f0d0d, 0xfffff2f3, 0x0605f2f3, 0xf9f9f2f3,
- 0x07fdf2f3, 0xf801f2f3, 0xfe07f2f3, 0x01f7f2f3, 0x0d0cf2f3, 0xf2f2f2f3, 0x0f03f2f3, 0xf0fbf2f3,
- 0x040ef2f3, 0x00000f04, 0x06060f04, 0xf9fa0f04, 0x07fe0f04, 0xf8020f04, 0xfe080f04, 0x01f80f04,
- 0x0d0d0f04, 0xf2f30f04, 0x0f040f04, 0xf0fc0f04, 0x040f0f04, 0xfffff0fc, 0x0605f0fc, 0xf9f9f0fc,
- 0x07fdf0fc, 0xf801f0fc, 0xfe07f0fc, 0x01f7f0fc, 0x0d0cf0fc, 0xf2f2f0fc, 0x0f03f0fc, 0xf0fbf0fc,
- 0x040ef0fc, 0x0000040f, 0x0606040f, 0xf9fa040f, 0x07fe040f, 0xf802040f, 0xfe08040f, 0x01f8040f,
- 0x0d0d040f, 0xf2f3040f, 0x0f04040f, 0xf0fc040f, 0x040f040f, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000707, 0xfffff8f9, 0x000009fd, 0xfffff603, 0xfffffd0a, 0x000002f6, 0x00001010,
- 0xffffeff0, 0x00001205, 0xffffedfb, 0x00000512, 0xfffffaee, 0x00000cf3, 0xfffff30d, 0x000014fa,
- 0xffffeb06, 0xfffffa15, 0x000005eb, 0x00001e0f, 0xffffe1f1, 0x00000f1e, 0xfffff0e2, 0x00001e1e,
- 0xffffe1e2, 0x00002202, 0xffffddfe, 0x00000222, 0xfffffdde, 0x00001bed, 0xffffe413, 0xffffed1c,
- 0x000012e4, 0x00003620, 0xffffc9e0, 0x00002036, 0xffffdfca, 0x000028f5, 0xffffd70b, 0xfffff529,
- 0x00000ad7, 0x0000370f, 0xffffc8f1, 0x00000f37, 0xfffff0c9, 0x00003939, 0xffffc6c7, 0x00003eff,
- 0xffffc101, 0xffffff3f, 0x000000c1, 0x000027d8, 0xffffd828, 0x000036e2, 0xffffc91e, 0xffffe237,
- 0x00001dc9, 0x00005e25, 0xffffa1db, 0x0000255e, 0xffffdaa2, 0x00006041, 0xffff9fbf, 0x00004160,
- 0xffffbea0, 0x00004deb, 0xffffb215, 0xffffeb4e, 0x000014b2, 0x0000640f, 0xffff9bf1, 0x00000f64,
- 0xfffff09c, 0x00006a6a, 0xffff9596, 0x000073f8, 0xffff8c08, 0xfffff874, 0x0000078c, 0x00004ec1,
- 0xffffb13f, 0xffffc14f, 0x00003eb1, 0x000068cd, 0xffff9733, 0xffffcd69, 0x00003297, 0x00007788,
- 0xffff8878, 0x00002b2b, 0xffffd4d5, 0x00005050, 0xffffafb0, 0x00000000, 0x07070000, 0xf8f90000,
- 0x09fd0000, 0xf6030000, 0xfd0a0000, 0x02f60000, 0x10100000, 0xeff00000, 0x12050000, 0xedfb0000,
- 0x05120000, 0x00000707, 0x07070707, 0xf8f90707, 0x09fd0707, 0xf6030707, 0xfd0a0707, 0x02f60707,
- 0x10100707, 0xeff00707, 0x12050707, 0xedfb0707, 0x05120707, 0xfffff8f9, 0x0706f8f9, 0xf8f8f8f9,
- 0x09fcf8f9, 0xf602f8f9, 0xfd09f8f9, 0x02f5f8f9, 0x100ff8f9, 0xefeff8f9, 0x1204f8f9, 0xedfaf8f9,
- 0x0511f8f9, 0x000009fd, 0x070709fd, 0xf8f909fd, 0x09fd09fd, 0xf60309fd, 0xfd0a09fd, 0x02f609fd,
- 0x101009fd, 0xeff009fd, 0x120509fd, 0xedfb09fd, 0x051209fd, 0xfffff603, 0x0706f603, 0xf8f8f603,
- 0x09fcf603, 0xf602f603, 0xfd09f603, 0x02f5f603, 0x100ff603, 0xefeff603, 0x1204f603, 0xedfaf603,
- 0x0511f603, 0xfffffd0a, 0x0706fd0a, 0xf8f8fd0a, 0x09fcfd0a, 0xf602fd0a, 0xfd09fd0a, 0x02f5fd0a,
- 0x100ffd0a, 0xefeffd0a, 0x1204fd0a, 0xedfafd0a, 0x0511fd0a, 0x000002f6, 0x070702f6, 0xf8f902f6,
- 0x09fd02f6, 0xf60302f6, 0xfd0a02f6, 0x02f602f6, 0x101002f6, 0xeff002f6, 0x120502f6, 0xedfb02f6,
- 0x051202f6, 0x00001010, 0x07071010, 0xf8f91010, 0x09fd1010, 0xf6031010, 0xfd0a1010, 0x02f61010,
- 0x10101010, 0xeff01010, 0x12051010, 0xedfb1010, 0x05121010, 0xffffeff0, 0x0706eff0, 0xf8f8eff0,
- 0x09fceff0, 0xf602eff0, 0xfd09eff0, 0x02f5eff0, 0x100feff0, 0xefefeff0, 0x1204eff0, 0xedfaeff0,
- 0x0511eff0, 0x00001205, 0x07071205, 0xf8f91205, 0x09fd1205, 0xf6031205, 0xfd0a1205, 0x02f61205,
- 0x10101205, 0xeff01205, 0x12051205, 0xedfb1205, 0x05121205, 0xffffedfb, 0x0706edfb, 0xf8f8edfb,
- 0x09fcedfb, 0xf602edfb, 0xfd09edfb, 0x02f5edfb, 0x100fedfb, 0xefefedfb, 0x1204edfb, 0xedfaedfb,
- 0x0511edfb, 0x00000512, 0x07070512, 0xf8f90512, 0x09fd0512, 0xf6030512, 0xfd0a0512, 0x02f60512,
- 0x10100512, 0xeff00512, 0x12050512, 0xedfb0512, 0x05120512, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000808, 0xfffff7f8, 0x00000afd, 0xfffff503, 0xfffffd0b, 0x000002f5, 0x00001212,
- 0xffffedee, 0x00001405, 0xffffebfb, 0x00000514, 0xfffffaec, 0x00000ef1, 0xfffff10f, 0x000017f9,
- 0xffffe807, 0xfffff918, 0x000006e8, 0x00002311, 0xffffdcef, 0x00001123, 0xffffeedd, 0x00002222,
- 0xffffddde, 0x00002603, 0xffffd9fd, 0x00000326, 0xfffffcda, 0x00001fea, 0xffffe016, 0xffffea20,
- 0x000015e0, 0x00003d25, 0xffffc2db, 0x0000253d, 0xffffdac3, 0x00002ef3, 0xffffd10d, 0xfffff32f,
- 0x00000cd1, 0x00003f11, 0xffffc0ef, 0x0000113f, 0xffffeec1, 0x00004141, 0xffffbebf, 0x000047ff,
- 0xffffb801, 0xffffff48, 0x000000b8, 0x00002dd2, 0xffffd22e, 0x00003edd, 0xffffc123, 0xffffdd3f,
- 0x000022c1, 0x00006b2b, 0xffff94d5, 0x00002b6b, 0xffffd495, 0x00006e4b, 0xffff91b5, 0x00004b6e,
- 0xffffb492, 0x000058e8, 0xffffa718, 0xffffe859, 0x000017a7, 0x00007211, 0xffff8def, 0x00001172,
- 0xffffee8e, 0x00007979, 0xffff8687, 0x00005ab8, 0xffffa548, 0xffffb85b, 0x000047a5, 0x000077c6,
- 0xffff883a, 0xffffc678, 0x00003988, 0x00003131, 0xffffcecf, 0x00005c5c, 0xffffa3a4, 0x00000000,
- 0x08080000, 0xf7f80000, 0x0afd0000, 0xf5030000, 0xfd0b0000, 0x02f50000, 0x12120000, 0xedee0000,
- 0x14050000, 0xebfb0000, 0x05140000, 0x00000808, 0x08080808, 0xf7f80808, 0x0afd0808, 0xf5030808,
- 0xfd0b0808, 0x02f50808, 0x12120808, 0xedee0808, 0x14050808, 0xebfb0808, 0x05140808, 0xfffff7f8,
- 0x0807f7f8, 0xf7f7f7f8, 0x0afcf7f8, 0xf502f7f8, 0xfd0af7f8, 0x02f4f7f8, 0x1211f7f8, 0xededf7f8,
- 0x1404f7f8, 0xebfaf7f8, 0x0513f7f8, 0x00000afd, 0x08080afd, 0xf7f80afd, 0x0afd0afd, 0xf5030afd,
- 0xfd0b0afd, 0x02f50afd, 0x12120afd, 0xedee0afd, 0x14050afd, 0xebfb0afd, 0x05140afd, 0xfffff503,
- 0x0807f503, 0xf7f7f503, 0x0afcf503, 0xf502f503, 0xfd0af503, 0x02f4f503, 0x1211f503, 0xededf503,
- 0x1404f503, 0xebfaf503, 0x0513f503, 0xfffffd0b, 0x0807fd0b, 0xf7f7fd0b, 0x0afcfd0b, 0xf502fd0b,
- 0xfd0afd0b, 0x02f4fd0b, 0x1211fd0b, 0xededfd0b, 0x1404fd0b, 0xebfafd0b, 0x0513fd0b, 0x000002f5,
- 0x080802f5, 0xf7f802f5, 0x0afd02f5, 0xf50302f5, 0xfd0b02f5, 0x02f502f5, 0x121202f5, 0xedee02f5,
- 0x140502f5, 0xebfb02f5, 0x051402f5, 0x00001212, 0x08081212, 0xf7f81212, 0x0afd1212, 0xf5031212,
- 0xfd0b1212, 0x02f51212, 0x12121212, 0xedee1212, 0x14051212, 0xebfb1212, 0x05141212, 0xffffedee,
- 0x0807edee, 0xf7f7edee, 0x0afcedee, 0xf502edee, 0xfd0aedee, 0x02f4edee, 0x1211edee, 0xedededee,
- 0x1404edee, 0xebfaedee, 0x0513edee, 0x00001405, 0x08081405, 0xf7f81405, 0x0afd1405, 0xf5031405,
- 0xfd0b1405, 0x02f51405, 0x12121405, 0xedee1405, 0x14051405, 0xebfb1405, 0x05141405, 0xffffebfb,
- 0x0807ebfb, 0xf7f7ebfb, 0x0afcebfb, 0xf502ebfb, 0xfd0aebfb, 0x02f4ebfb, 0x1211ebfb, 0xededebfb,
- 0x1404ebfb, 0xebfaebfb, 0x0513ebfb, 0x00000514, 0x08080514, 0xf7f80514, 0x0afd0514, 0xf5030514,
- 0xfd0b0514, 0x02f50514, 0x12120514, 0xedee0514, 0x14050514, 0xebfb0514, 0x05140514, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000909, 0xfffff6f7, 0x00000bfd, 0xfffff403, 0xfffffd0c, 0x000002f4, 0x00001414,
- 0xffffebec, 0x00001706, 0xffffe8fa, 0x00000617, 0xfffff9e9, 0x000010ef, 0xffffef11, 0x00001af9,
- 0xffffe507, 0xfffff91b, 0x000006e5, 0x00002713, 0xffffd8ed, 0x00001327, 0xffffecd9, 0x00002727,
- 0xffffd8d9, 0x00002b03, 0xffffd4fd, 0x0000032b, 0xfffffcd5, 0x000023e8, 0xffffdc18, 0xffffe824,
- 0x000017dc, 0x0000452a, 0xffffbad6, 0x00002a45, 0xffffd5bb, 0x000034f2, 0xffffcb0e, 0xfffff235,
- 0x00000dcb, 0x00004713, 0xffffb8ed, 0x00001347, 0xffffecb9, 0x00004949, 0xffffb6b7, 0x00004ffe,
- 0xffffb002, 0xfffffe50, 0x000001b0, 0x000033cc, 0xffffcc34, 0x000045d9, 0xffffba27, 0xffffd946,
- 0x000026ba, 0x00007930, 0xffff86d0, 0x00003079, 0xffffcf87, 0x00007c54, 0xffff83ac, 0x0000547c,
- 0xffffab84, 0x000063e5, 0xffff9c1b, 0xffffe564, 0x00001a9c, 0x000065af, 0xffff9a51, 0xffffaf66,
- 0x0000509a, 0x00003737, 0xffffc8c9, 0x00006868, 0xffff9798, 0x00000000, 0x09090000, 0xf6f70000,
- 0x0bfd0000, 0xf4030000, 0xfd0c0000, 0x02f40000, 0x14140000, 0xebec0000, 0x17060000, 0xe8fa0000,
- 0x06170000, 0xf9e90000, 0x00000909, 0x09090909, 0xf6f70909, 0x0bfd0909, 0xf4030909, 0xfd0c0909,
- 0x02f40909, 0x14140909, 0xebec0909, 0x17060909, 0xe8fa0909, 0x06170909, 0xf9e90909, 0xfffff6f7,
- 0x0908f6f7, 0xf6f6f6f7, 0x0bfcf6f7, 0xf402f6f7, 0xfd0bf6f7, 0x02f3f6f7, 0x1413f6f7, 0xebebf6f7,
- 0x1705f6f7, 0xe8f9f6f7, 0x0616f6f7, 0xf9e8f6f7, 0x00000bfd, 0x09090bfd, 0xf6f70bfd, 0x0bfd0bfd,
- 0xf4030bfd, 0xfd0c0bfd, 0x02f40bfd, 0x14140bfd, 0xebec0bfd, 0x17060bfd, 0xe8fa0bfd, 0x06170bfd,
- 0xf9e90bfd, 0xfffff403, 0x0908f403, 0xf6f6f403, 0x0bfcf403, 0xf402f403, 0xfd0bf403, 0x02f3f403,
- 0x1413f403, 0xebebf403, 0x1705f403, 0xe8f9f403, 0x0616f403, 0xf9e8f403, 0xfffffd0c, 0x0908fd0c,
- 0xf6f6fd0c, 0x0bfcfd0c, 0xf402fd0c, 0xfd0bfd0c, 0x02f3fd0c, 0x1413fd0c, 0xebebfd0c, 0x1705fd0c,
- 0xe8f9fd0c, 0x0616fd0c, 0xf9e8fd0c, 0x000002f4, 0x090902f4, 0xf6f702f4, 0x0bfd02f4, 0xf40302f4,
- 0xfd0c02f4, 0x02f402f4, 0x141402f4, 0xebec02f4, 0x170602f4, 0xe8fa02f4, 0x061702f4, 0xf9e902f4,
- 0x00001414, 0x09091414, 0xf6f71414, 0x0bfd1414, 0xf4031414, 0xfd0c1414, 0x02f41414, 0x14141414,
- 0xebec1414, 0x17061414, 0xe8fa1414, 0x06171414, 0xf9e91414, 0xffffebec, 0x0908ebec, 0xf6f6ebec,
- 0x0bfcebec, 0xf402ebec, 0xfd0bebec, 0x02f3ebec, 0x1413ebec, 0xebebebec, 0x1705ebec, 0xe8f9ebec,
- 0x0616ebec, 0xf9e8ebec, 0x00001706, 0x09091706, 0xf6f71706, 0x0bfd1706, 0xf4031706, 0xfd0c1706,
- 0x02f41706, 0x14141706, 0xebec1706, 0x17061706, 0xe8fa1706, 0x06171706, 0xf9e91706, 0xffffe8fa,
- 0x0908e8fa, 0xf6f6e8fa, 0x0bfce8fa, 0xf402e8fa, 0xfd0be8fa, 0x02f3e8fa, 0x1413e8fa, 0xebebe8fa,
- 0x1705e8fa, 0xe8f9e8fa, 0x0616e8fa, 0xf9e8e8fa, 0x00000617, 0x09090617, 0xf6f70617, 0x0bfd0617,
- 0xf4030617, 0xfd0c0617, 0x02f40617, 0x14140617, 0xebec0617, 0x17060617, 0xe8fa0617, 0x06170617,
- 0xf9e90617, 0xfffff9e9, 0x0908f9e9, 0xf6f6f9e9, 0x0bfcf9e9, 0xf402f9e9, 0xfd0bf9e9, 0x02f3f9e9,
- 0x1413f9e9, 0xebebf9e9, 0x1705f9e9, 0xe8f9f9e9, 0x0616f9e9, 0xf9e8f9e9, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404,
- 0xfffffbfc, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x000003fc, 0xfffffc04, 0x000005fe,
- 0xfffffa02, 0xfffffe06, 0x000001fa, 0x00000804, 0xfffff7fc, 0x00000408, 0xfffffbf8, 0x00000808,
- 0xfffff7f8, 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x000007fc, 0xfffff804, 0xfffffc08,
- 0x000003f8, 0x00000e08, 0xfffff1f8, 0x0000080e, 0xfffff7f2, 0x00000bfe, 0xfffff402, 0xfffffe0c,
- 0x000001f4, 0x00001004, 0xffffeffc, 0x00000410, 0xfffffbf0, 0x00001010, 0xffffeff0, 0x00001200,
- 0xffffee00, 0x00000012, 0xffffffee, 0x00000bf4, 0xfffff40c, 0x00000ff8, 0xfffff008, 0xfffff810,
- 0x000007f0, 0x00001a0a, 0xffffe5f6, 0x00000a1a, 0xfffff5e6, 0x00001c12, 0xffffe3ee, 0x0000121c,
- 0xffffede4, 0x000015fa, 0xffffea06, 0xfffffa16, 0x000005ea, 0x00001c04, 0xffffe3fc, 0x0000041c,
- 0xfffffbe4, 0x00001e1e, 0xffffe1e2, 0x00001ffe, 0xffffe002, 0xfffffe20, 0x000001e0, 0x000015ee,
- 0xffffea12, 0xffffee16, 0x000011ea, 0x00001df2, 0xffffe20e, 0xfffff21e, 0x00000de2, 0x00002e16,
- 0xffffd1ea, 0x0000162e, 0xffffe9d2, 0x00002e0c, 0xffffd1f4, 0x00000c2e, 0xfffff3d2, 0x00003022,
- 0xffffcfde, 0x00002230, 0xffffddd0, 0x000027f6, 0xffffd80a, 0xfffff628, 0x000009d8, 0x00003204,
- 0xffffcdfc, 0x00000432, 0xfffffbce, 0x00003636, 0xffffc9ca, 0x000021de, 0xffffde22, 0x000029e4,
- 0xffffd61c, 0xffffe42a, 0x00001bd6, 0x00003bfa, 0xffffc406, 0xfffffa3c, 0x000005c4, 0x00004c1a,
- 0xffffb3e6, 0x00001a4c, 0xffffe5b4, 0x00004c2a, 0xffffb3d6, 0x00002a4c, 0xffffd5b4, 0x000035e8,
- 0xffffca18, 0xffffe836, 0x000017ca, 0x00004e0e, 0xffffb1f2, 0x00000e4e, 0xfffff1b2, 0x0000523e,
- 0xffffadc2, 0x00003e52, 0xffffc1ae, 0x000049ec, 0xffffb614, 0xffffec4a, 0x000013b6, 0x00005802,
- 0xffffa7fe, 0x00000258, 0xfffffda8, 0x00005c5c, 0xffffa3a4, 0x00003bcc, 0xffffc434, 0xffffcc3c,
- 0x000033c4, 0x00007634, 0xffff89cc, 0x00003476, 0xffffcb8a, 0x000049d4, 0xffffb62c, 0xffffd44a,
- 0x00002bb6, 0x0000764a, 0xffff89b6, 0x00004a76, 0xffffb58a, 0x00007620, 0xffff89e0, 0x00002076,
- 0xffffdf8a, 0x000065f4, 0xffff9a0c, 0xfffff466, 0x00000b9a, 0x00005fd8, 0xffffa028, 0xffffd860,
- 0x000027a0, 0x000075de, 0xffff8a22, 0xffffde76, 0x0000218a, 0x000057a8, 0xffffa858, 0x000067b2,
- 0xffff984e, 0xffffb268, 0x00004d98, 0x00000c0c, 0xfffff3f4, 0x00001616, 0xffffe9ea, 0x00002a2a,
- 0xffffd5d6, 0x00004848, 0xffffb7b8, 0x00000000, 0x02020000, 0xfdfe0000, 0x02000000, 0xfe000000,
- 0x00020000, 0xfffe0000, 0x00000202, 0x02020202, 0xfdfe0202, 0x02000202, 0xfe000202, 0x00020202,
- 0xfffe0202, 0xfffffdfe, 0x0201fdfe, 0xfdfdfdfe, 0x01fffdfe, 0xfdfffdfe, 0x0001fdfe, 0xfffdfdfe,
- 0x00000200, 0x02020200, 0xfdfe0200, 0x02000200, 0xfe000200, 0x00020200, 0xfffe0200, 0xfffffe00,
- 0x0201fe00, 0xfdfdfe00, 0x01fffe00, 0xfdfffe00, 0x0001fe00, 0xfffdfe00, 0x00000002, 0x02020002,
- 0xfdfe0002, 0x02000002, 0xfe000002, 0x00020002, 0xfffe0002, 0xfffffffe, 0x0201fffe, 0xfdfdfffe,
- 0x01fffffe, 0xfdfffffe, 0x0001fffe, 0xfffdfffe, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000303, 0xfffffcfd, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606,
- 0xfffff9fa, 0x00000903, 0xfffff6fd, 0x00000309, 0xfffffcf7, 0x000008fd, 0xfffff703, 0xfffffd09,
- 0x000002f7, 0x000005fa, 0xfffffa06, 0x00000c06, 0xfffff3fa, 0x0000060c, 0xfffff9f4, 0x00000c0c,
- 0xfffff3f4, 0x00000f00, 0xfffff100, 0x0000000f, 0xfffffff1, 0x00000bf7, 0xfffff409, 0xfffff70c,
- 0x000008f4, 0x0000180f, 0xffffe7f1, 0x00000f18, 0xfffff0e8, 0x000011fa, 0xffffee06, 0xfffffa12,
- 0x000005ee, 0x00001806, 0xffffe7fa, 0x00000618, 0xfffff9e8, 0x00001818, 0xffffe7e8, 0x00001b00,
- 0xffffe500, 0x0000001b, 0xffffffe5, 0x000011ee, 0xffffee12, 0x000017f4, 0xffffe80c, 0xfffff418,
- 0x00000be8, 0x0000270f, 0xffffd8f1, 0x00000f27, 0xfffff0d9, 0x00002a1b, 0xffffd5e5, 0x00001b2a,
- 0xffffe4d6, 0x000020f7, 0xffffdf09, 0xfffff721, 0x000008df, 0x00002a06, 0xffffd5fa, 0x0000062a,
- 0xfffff9d6, 0x00002d2d, 0xffffd2d3, 0x000032fd, 0xffffcd03, 0xfffffd33, 0x000002cd, 0x000020e5,
- 0xffffdf1b, 0xffffe521, 0x00001adf, 0x00002ceb, 0xffffd315, 0xffffeb2d, 0x000014d3, 0x00004521,
- 0xffffbadf, 0x00002145, 0xffffdebb, 0x00004512, 0xffffbaee, 0x00001245, 0xffffedbb, 0x00004836,
- 0xffffb7ca, 0x00003648, 0xffffc9b8, 0x00003eee, 0xffffc112, 0xffffee3f, 0x000011c1, 0x00004e06,
- 0xffffb1fa, 0x0000064e, 0xfffff9b2, 0x00005151, 0xffffaeaf, 0x000032cd, 0xffffcd33, 0x00003ed6,
- 0xffffc12a, 0xffffd63f, 0x000029c1, 0x000059f7, 0xffffa609, 0xfffff75a, 0x000008a6, 0x0000722a,
- 0xffff8dd6, 0x00002a72, 0xffffd58e, 0x0000753f, 0xffff8ac1, 0x00003f75, 0xffffc08b, 0x000050dc,
- 0xffffaf24, 0xffffdc51, 0x000023af, 0x00007815, 0xffff87eb, 0x00001578, 0xffffea88, 0x00007b60,
- 0xffff84a0, 0x0000607b, 0xffff9f85, 0x00006ee2, 0xffff911e, 0xffffe26f, 0x00001d91, 0x00005cb2,
- 0xffffa34e, 0xffffb25d, 0x00004da3, 0x000071bb, 0xffff8e45, 0xffffbb72, 0x0000448e, 0x00001212,
- 0xffffedee, 0x00002121, 0xffffdedf, 0x00003f3f, 0xffffc0c1, 0x00006c6c, 0xffff9394, 0x00000000,
- 0x03030000, 0xfcfd0000, 0x03000000, 0xfd000000, 0x00030000, 0xfffd0000, 0x06060000, 0xf9fa0000,
- 0x00000303, 0x03030303, 0xfcfd0303, 0x03000303, 0xfd000303, 0x00030303, 0xfffd0303, 0x06060303,
- 0xf9fa0303, 0xfffffcfd, 0x0302fcfd, 0xfcfcfcfd, 0x02fffcfd, 0xfcfffcfd, 0x0002fcfd, 0xfffcfcfd,
- 0x0605fcfd, 0xf9f9fcfd, 0x00000300, 0x03030300, 0xfcfd0300, 0x03000300, 0xfd000300, 0x00030300,
- 0xfffd0300, 0x06060300, 0xf9fa0300, 0xfffffd00, 0x0302fd00, 0xfcfcfd00, 0x02fffd00, 0xfcfffd00,
- 0x0002fd00, 0xfffcfd00, 0x0605fd00, 0xf9f9fd00, 0x00000003, 0x03030003, 0xfcfd0003, 0x03000003,
- 0xfd000003, 0x00030003, 0xfffd0003, 0x06060003, 0xf9fa0003, 0xfffffffd, 0x0302fffd, 0xfcfcfffd,
- 0x02fffffd, 0xfcfffffd, 0x0002fffd, 0xfffcfffd, 0x0605fffd, 0xf9f9fffd, 0x00000606, 0x03030606,
- 0xfcfd0606, 0x03000606, 0xfd000606, 0x00030606, 0xfffd0606, 0x06060606, 0xf9fa0606, 0xfffff9fa,
- 0x0302f9fa, 0xfcfcf9fa, 0x02fff9fa, 0xfcfff9fa, 0x0002f9fa, 0xfffcf9fa, 0x0605f9fa, 0xf9f9f9fa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000404, 0xfffffbfc, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000804,
- 0xfffff7fc, 0x00000408, 0xfffffbf8, 0x00000808, 0xfffff7f8, 0x000007f8, 0xfffff808, 0x00000bfc,
- 0xfffff404, 0xfffffc0c, 0x000003f4, 0x00001008, 0xffffeff8, 0x00000810, 0xfffff7f0, 0x00001010,
- 0xffffeff0, 0x00001400, 0xffffec00, 0x00000014, 0xffffffec, 0x00000ff4, 0xfffff00c, 0xfffff410,
- 0x00000bf0, 0x000017fc, 0xffffe804, 0xfffffc18, 0x000003e8, 0x00002010, 0xffffdff0, 0x00001020,
- 0xffffefe0, 0x00002008, 0xffffdff8, 0x00000820, 0xfffff7e0, 0x00002020, 0xffffdfe0, 0x00002400,
- 0xffffdc00, 0x00000024, 0xffffffdc, 0x000017e8, 0xffffe818, 0x00001ff0, 0xffffe010, 0xfffff020,
- 0x00000fe0, 0x00003414, 0xffffcbec, 0x00001434, 0xffffebcc, 0x00003824, 0xffffc7dc, 0x00002438,
- 0xffffdbc8, 0x00002bf4, 0xffffd40c, 0xfffff42c, 0x00000bd4, 0x00003808, 0xffffc7f8, 0x00000838,
- 0xfffff7c8, 0x00003c3c, 0xffffc3c4, 0x00003ffc, 0xffffc004, 0xfffffc40, 0x000003c0, 0x00002bdc,
- 0xffffd424, 0xffffdc2c, 0x000023d4, 0x00003be4, 0xffffc41c, 0xffffe43c, 0x00001bc4, 0x00005c2c,
- 0xffffa3d4, 0x00002c5c, 0xffffd3a4, 0x00005c18, 0xffffa3e8, 0x0000185c, 0xffffe7a4, 0x00006048,
- 0xffff9fb8, 0x00004860, 0xffffb7a0, 0x000053ec, 0xffffac14, 0xffffec54, 0x000013ac, 0x00006408,
- 0xffff9bf8, 0x00000864, 0xfffff79c, 0x00006c6c, 0xffff9394, 0x000043bc, 0xffffbc44, 0x000053c8,
- 0xffffac38, 0xffffc854, 0x000037ac, 0x000077f4, 0xffff880c, 0xfffff478, 0x00000b88, 0x00006bd0,
- 0xffff9430, 0xffffd06c, 0x00002f94, 0x00007b98, 0xffff8468, 0xffff987c, 0x00006784, 0x00001818,
- 0xffffe7e8, 0x00002c2c, 0xffffd3d4, 0x00005454, 0xffffabac, 0x00000000, 0x04040000, 0xfbfc0000,
- 0x04000000, 0xfc000000, 0x00040000, 0xfffc0000, 0x08040000, 0xf7fc0000, 0x04080000, 0x00000404,
- 0x04040404, 0xfbfc0404, 0x04000404, 0xfc000404, 0x00040404, 0xfffc0404, 0x08040404, 0xf7fc0404,
- 0x04080404, 0xfffffbfc, 0x0403fbfc, 0xfbfbfbfc, 0x03fffbfc, 0xfbfffbfc, 0x0003fbfc, 0xfffbfbfc,
- 0x0803fbfc, 0xf7fbfbfc, 0x0407fbfc, 0x00000400, 0x04040400, 0xfbfc0400, 0x04000400, 0xfc000400,
- 0x00040400, 0xfffc0400, 0x08040400, 0xf7fc0400, 0x04080400, 0xfffffc00, 0x0403fc00, 0xfbfbfc00,
- 0x03fffc00, 0xfbfffc00, 0x0003fc00, 0xfffbfc00, 0x0803fc00, 0xf7fbfc00, 0x0407fc00, 0x00000004,
- 0x04040004, 0xfbfc0004, 0x04000004, 0xfc000004, 0x00040004, 0xfffc0004, 0x08040004, 0xf7fc0004,
- 0x04080004, 0xfffffffc, 0x0403fffc, 0xfbfbfffc, 0x03fffffc, 0xfbfffffc, 0x0003fffc, 0xfffbfffc,
- 0x0803fffc, 0xf7fbfffc, 0x0407fffc, 0x00000804, 0x04040804, 0xfbfc0804, 0x04000804, 0xfc000804,
- 0x00040804, 0xfffc0804, 0x08040804, 0xf7fc0804, 0x04080804, 0xfffff7fc, 0x0403f7fc, 0xfbfbf7fc,
- 0x03fff7fc, 0xfbfff7fc, 0x0003f7fc, 0xfffbf7fc, 0x0803f7fc, 0xf7fbf7fc, 0x0407f7fc, 0x00000408,
- 0x04040408, 0xfbfc0408, 0x04000408, 0xfc000408, 0x00040408, 0xfffc0408, 0x08040408, 0xf7fc0408,
- 0x04080408, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000505, 0xfffffafb, 0x00000500, 0xfffffb00, 0x00000005, 0xfffffffb, 0x00000a0a,
- 0xfffff5f6, 0x00000f05, 0xfffff0fb, 0x0000050f, 0xfffffaf1, 0x000009f6, 0xfffff60a, 0x00000efb,
- 0xfffff105, 0xfffffb0f, 0x000004f1, 0x0000140a, 0xffffebf6, 0x00000a14, 0xfffff5ec, 0x00001414,
- 0xffffebec, 0x00001900, 0xffffe700, 0x00000019, 0xffffffe7, 0x000013f1, 0xffffec0f, 0xfffff114,
- 0x00000eec, 0x00002819, 0xffffd7e7, 0x00001928, 0xffffe6d8, 0x00001df6, 0xffffe20a, 0xfffff61e,
- 0x000009e2, 0x0000280a, 0xffffd7f6, 0x00000a28, 0xfffff5d8, 0x00002828, 0xffffd7d8, 0x00002d00,
- 0xffffd300, 0x0000002d, 0xffffffd3, 0x00001de2, 0xffffe21e, 0x000027ec, 0xffffd814, 0xffffec28,
- 0x000013d8, 0x00004119, 0xffffbee7, 0x00001941, 0xffffe6bf, 0x0000462d, 0xffffb9d3, 0x00002d46,
- 0xffffd2ba, 0x000036f1, 0xffffc90f, 0xfffff137, 0x00000ec9, 0x0000460a, 0xffffb9f6, 0x00000a46,
- 0xfffff5ba, 0x00004b4b, 0xffffb4b5, 0x000054fb, 0xffffab05, 0xfffffb55, 0x000004ab, 0x000036d3,
- 0xffffc92d, 0xffffd337, 0x00002cc9, 0x00004add, 0xffffb523, 0xffffdd4b, 0x000022b5, 0x00007337,
- 0xffff8cc9, 0x00003773, 0xffffc88d, 0x0000731e, 0xffff8ce2, 0x00001e73, 0xffffe18d, 0x0000785a,
- 0xffff87a6, 0x00005a78, 0xffffa588, 0x000068e2, 0xffff971e, 0xffffe269, 0x00001d97, 0x000054ab,
- 0xffffab55, 0x000068ba, 0xffff9746, 0xffffba69, 0x00004597, 0x00001e1e, 0xffffe1e2, 0x00003c3c,
- 0xffffc3c4, 0x00006969, 0xffff9697, 0x00000000, 0x05050000, 0xfafb0000, 0x05000000, 0xfb000000,
- 0x00050000, 0xfffb0000, 0x0a0a0000, 0xf5f60000, 0x0f050000, 0xf0fb0000, 0x00000505, 0x05050505,
- 0xfafb0505, 0x05000505, 0xfb000505, 0x00050505, 0xfffb0505, 0x0a0a0505, 0xf5f60505, 0x0f050505,
- 0xf0fb0505, 0xfffffafb, 0x0504fafb, 0xfafafafb, 0x04fffafb, 0xfafffafb, 0x0004fafb, 0xfffafafb,
- 0x0a09fafb, 0xf5f5fafb, 0x0f04fafb, 0xf0fafafb, 0x00000500, 0x05050500, 0xfafb0500, 0x05000500,
- 0xfb000500, 0x00050500, 0xfffb0500, 0x0a0a0500, 0xf5f60500, 0x0f050500, 0xf0fb0500, 0xfffffb00,
- 0x0504fb00, 0xfafafb00, 0x04fffb00, 0xfafffb00, 0x0004fb00, 0xfffafb00, 0x0a09fb00, 0xf5f5fb00,
- 0x0f04fb00, 0xf0fafb00, 0x00000005, 0x05050005, 0xfafb0005, 0x05000005, 0xfb000005, 0x00050005,
- 0xfffb0005, 0x0a0a0005, 0xf5f60005, 0x0f050005, 0xf0fb0005, 0xfffffffb, 0x0504fffb, 0xfafafffb,
- 0x04fffffb, 0xfafffffb, 0x0004fffb, 0xfffafffb, 0x0a09fffb, 0xf5f5fffb, 0x0f04fffb, 0xf0fafffb,
- 0x00000a0a, 0x05050a0a, 0xfafb0a0a, 0x05000a0a, 0xfb000a0a, 0x00050a0a, 0xfffb0a0a, 0x0a0a0a0a,
- 0xf5f60a0a, 0x0f050a0a, 0xf0fb0a0a, 0xfffff5f6, 0x0504f5f6, 0xfafaf5f6, 0x04fff5f6, 0xfafff5f6,
- 0x0004f5f6, 0xfffaf5f6, 0x0a09f5f6, 0xf5f5f5f6, 0x0f04f5f6, 0xf0faf5f6, 0x00000f05, 0x05050f05,
- 0xfafb0f05, 0x05000f05, 0xfb000f05, 0x00050f05, 0xfffb0f05, 0x0a0a0f05, 0xf5f60f05, 0x0f050f05,
- 0xf0fb0f05, 0xfffff0fb, 0x0504f0fb, 0xfafaf0fb, 0x04fff0fb, 0xfafff0fb, 0x0004f0fb, 0xfffaf0fb,
- 0x0a09f0fb, 0xf5f5f0fb, 0x0f04f0fb, 0xf0faf0fb, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000606, 0xfffff9fa, 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x00000c0c,
- 0xfffff3f4, 0x00000c06, 0xfffff3fa, 0x0000060c, 0xfffff9f4, 0x00000bf4, 0xfffff40c, 0x000011fa,
- 0xffffee06, 0xfffffa12, 0x000005ee, 0x0000180c, 0xffffe7f4, 0x00000c18, 0xfffff3e8, 0x00001818,
- 0xffffe7e8, 0x00001e00, 0xffffe200, 0x0000001e, 0xffffffe2, 0x000017ee, 0xffffe812, 0xffffee18,
- 0x000011e8, 0x0000301e, 0xffffcfe2, 0x00001e30, 0xffffe1d0, 0x000023fa, 0xffffdc06, 0xfffffa24,
- 0x000005dc, 0x0000300c, 0xffffcff4, 0x00000c30, 0xfffff3d0, 0x00003030, 0xffffcfd0, 0x00003600,
- 0xffffca00, 0x00000036, 0xffffffca, 0x000023dc, 0xffffdc24, 0x00002fe8, 0xffffd018, 0xffffe830,
- 0x000017d0, 0x00004e1e, 0xffffb1e2, 0x00001e4e, 0xffffe1b2, 0x00005436, 0xffffabca, 0x00003654,
- 0xffffc9ac, 0x000041ee, 0xffffbe12, 0xffffee42, 0x000011be, 0x0000540c, 0xffffabf4, 0x00000c54,
- 0xfffff3ac, 0x00005a5a, 0xffffa5a6, 0x00005ffa, 0xffffa006, 0xfffffa60, 0x000005a0, 0x000041ca,
- 0xffffbe36, 0xffffca42, 0x000035be, 0x000059d6, 0xffffa62a, 0xffffd65a, 0x000029a6, 0x00007de2,
- 0xffff821e, 0xffffe27e, 0x00001d82, 0x0000659a, 0xffff9a66, 0x00007dac, 0xffff8254, 0xffffac7e,
- 0x00005382, 0x00002424, 0xffffdbdc, 0x00004242, 0xffffbdbe, 0x00000000, 0x06060000, 0xf9fa0000,
- 0x06000000, 0xfa000000, 0x00060000, 0xfffa0000, 0x0c0c0000, 0xf3f40000, 0x0c060000, 0xf3fa0000,
- 0x060c0000, 0x00000606, 0x06060606, 0xf9fa0606, 0x06000606, 0xfa000606, 0x00060606, 0xfffa0606,
- 0x0c0c0606, 0xf3f40606, 0x0c060606, 0xf3fa0606, 0x060c0606, 0xfffff9fa, 0x0605f9fa, 0xf9f9f9fa,
- 0x05fff9fa, 0xf9fff9fa, 0x0005f9fa, 0xfff9f9fa, 0x0c0bf9fa, 0xf3f3f9fa, 0x0c05f9fa, 0xf3f9f9fa,
- 0x060bf9fa, 0x00000600, 0x06060600, 0xf9fa0600, 0x06000600, 0xfa000600, 0x00060600, 0xfffa0600,
- 0x0c0c0600, 0xf3f40600, 0x0c060600, 0xf3fa0600, 0x060c0600, 0xfffffa00, 0x0605fa00, 0xf9f9fa00,
- 0x05fffa00, 0xf9fffa00, 0x0005fa00, 0xfff9fa00, 0x0c0bfa00, 0xf3f3fa00, 0x0c05fa00, 0xf3f9fa00,
- 0x060bfa00, 0x00000006, 0x06060006, 0xf9fa0006, 0x06000006, 0xfa000006, 0x00060006, 0xfffa0006,
- 0x0c0c0006, 0xf3f40006, 0x0c060006, 0xf3fa0006, 0x060c0006, 0xfffffffa, 0x0605fffa, 0xf9f9fffa,
- 0x05fffffa, 0xf9fffffa, 0x0005fffa, 0xfff9fffa, 0x0c0bfffa, 0xf3f3fffa, 0x0c05fffa, 0xf3f9fffa,
- 0x060bfffa, 0x00000c0c, 0x06060c0c, 0xf9fa0c0c, 0x06000c0c, 0xfa000c0c, 0x00060c0c, 0xfffa0c0c,
- 0x0c0c0c0c, 0xf3f40c0c, 0x0c060c0c, 0xf3fa0c0c, 0x060c0c0c, 0xfffff3f4, 0x0605f3f4, 0xf9f9f3f4,
- 0x05fff3f4, 0xf9fff3f4, 0x0005f3f4, 0xfff9f3f4, 0x0c0bf3f4, 0xf3f3f3f4, 0x0c05f3f4, 0xf3f9f3f4,
- 0x060bf3f4, 0x00000c06, 0x06060c06, 0xf9fa0c06, 0x06000c06, 0xfa000c06, 0x00060c06, 0xfffa0c06,
- 0x0c0c0c06, 0xf3f40c06, 0x0c060c06, 0xf3fa0c06, 0x060c0c06, 0xfffff3fa, 0x0605f3fa, 0xf9f9f3fa,
- 0x05fff3fa, 0xf9fff3fa, 0x0005f3fa, 0xfff9f3fa, 0x0c0bf3fa, 0xf3f3f3fa, 0x0c05f3fa, 0xf3f9f3fa,
- 0x060bf3fa, 0x0000060c, 0x0606060c, 0xf9fa060c, 0x0600060c, 0xfa00060c, 0x0006060c, 0xfffa060c,
- 0x0c0c060c, 0xf3f4060c, 0x0c06060c, 0xf3fa060c, 0x060c060c, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000707, 0xfffff8f9, 0x00000700, 0xfffff900, 0x00000007, 0xfffffff9, 0x00000e0e,
- 0xfffff1f2, 0x00001507, 0xffffeaf9, 0x00000715, 0xfffff8eb, 0x00000df2, 0xfffff20e, 0x000014f9,
- 0xffffeb07, 0xfffff915, 0x000006eb, 0x00001c0e, 0xffffe3f2, 0x00000e1c, 0xfffff1e4, 0x00001c1c,
- 0xffffe3e4, 0x00002300, 0xffffdd00, 0x00000023, 0xffffffdd, 0x00001beb, 0xffffe415, 0xffffeb1c,
- 0x000014e4, 0x00003823, 0xffffc7dd, 0x00002338, 0xffffdcc8, 0x000029f2, 0xffffd60e, 0xfffff22a,
- 0x00000dd6, 0x0000380e, 0xffffc7f2, 0x00000e38, 0xfffff1c8, 0x00003838, 0xffffc7c8, 0x00003f00,
- 0xffffc100, 0x0000003f, 0xffffffc1, 0x000029d6, 0xffffd62a, 0x000037e4, 0xffffc81c, 0xffffe438,
- 0x00001bc8, 0x00005b23, 0xffffa4dd, 0x0000235b, 0xffffdca5, 0x0000623f, 0xffff9dc1, 0x00003f62,
- 0xffffc09e, 0x00004ceb, 0xffffb315, 0xffffeb4d, 0x000014b3, 0x0000620e, 0xffff9df2, 0x00000e62,
- 0xfffff19e, 0x00006969, 0xffff9697, 0x000076f9, 0xffff8907, 0xfffff977, 0x00000689, 0x00004cc1,
- 0xffffb33f, 0xffffc14d, 0x00003eb3, 0x000068cf, 0xffff9731, 0xffffcf69, 0x00003097, 0x00007689,
- 0xffff8977, 0x00002a2a, 0xffffd5d6, 0x00004d4d, 0xffffb2b3, 0x00000000, 0x07070000, 0xf8f90000,
- 0x07000000, 0xf9000000, 0x00070000, 0xfff90000, 0x0e0e0000, 0xf1f20000, 0x15070000, 0xeaf90000,
- 0x07150000, 0x00000707, 0x07070707, 0xf8f90707, 0x07000707, 0xf9000707, 0x00070707, 0xfff90707,
- 0x0e0e0707, 0xf1f20707, 0x15070707, 0xeaf90707, 0x07150707, 0xfffff8f9, 0x0706f8f9, 0xf8f8f8f9,
- 0x06fff8f9, 0xf8fff8f9, 0x0006f8f9, 0xfff8f8f9, 0x0e0df8f9, 0xf1f1f8f9, 0x1506f8f9, 0xeaf8f8f9,
- 0x0714f8f9, 0x00000700, 0x07070700, 0xf8f90700, 0x07000700, 0xf9000700, 0x00070700, 0xfff90700,
- 0x0e0e0700, 0xf1f20700, 0x15070700, 0xeaf90700, 0x07150700, 0xfffff900, 0x0706f900, 0xf8f8f900,
- 0x06fff900, 0xf8fff900, 0x0006f900, 0xfff8f900, 0x0e0df900, 0xf1f1f900, 0x1506f900, 0xeaf8f900,
- 0x0714f900, 0x00000007, 0x07070007, 0xf8f90007, 0x07000007, 0xf9000007, 0x00070007, 0xfff90007,
- 0x0e0e0007, 0xf1f20007, 0x15070007, 0xeaf90007, 0x07150007, 0xfffffff9, 0x0706fff9, 0xf8f8fff9,
- 0x06fffff9, 0xf8fffff9, 0x0006fff9, 0xfff8fff9, 0x0e0dfff9, 0xf1f1fff9, 0x1506fff9, 0xeaf8fff9,
- 0x0714fff9, 0x00000e0e, 0x07070e0e, 0xf8f90e0e, 0x07000e0e, 0xf9000e0e, 0x00070e0e, 0xfff90e0e,
- 0x0e0e0e0e, 0xf1f20e0e, 0x15070e0e, 0xeaf90e0e, 0x07150e0e, 0xfffff1f2, 0x0706f1f2, 0xf8f8f1f2,
- 0x06fff1f2, 0xf8fff1f2, 0x0006f1f2, 0xfff8f1f2, 0x0e0df1f2, 0xf1f1f1f2, 0x1506f1f2, 0xeaf8f1f2,
- 0x0714f1f2, 0x00001507, 0x07071507, 0xf8f91507, 0x07001507, 0xf9001507, 0x00071507, 0xfff91507,
- 0x0e0e1507, 0xf1f21507, 0x15071507, 0xeaf91507, 0x07151507, 0xffffeaf9, 0x0706eaf9, 0xf8f8eaf9,
- 0x06ffeaf9, 0xf8ffeaf9, 0x0006eaf9, 0xfff8eaf9, 0x0e0deaf9, 0xf1f1eaf9, 0x1506eaf9, 0xeaf8eaf9,
- 0x0714eaf9, 0x00000715, 0x07070715, 0xf8f90715, 0x07000715, 0xf9000715, 0x00070715, 0xfff90715,
- 0x0e0e0715, 0xf1f20715, 0x15070715, 0xeaf90715, 0x07150715, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000808, 0xfffff7f8, 0x00000800, 0xfffff800, 0x00000008, 0xfffffff8, 0x00001010,
- 0xffffeff0, 0x00001008, 0xffffeff8, 0x00000810, 0xfffff7f0, 0x00000ff0, 0xfffff010, 0x000017f8,
- 0xffffe808, 0xfffff818, 0x000007e8, 0x00002010, 0xffffdff0, 0x00001020, 0xffffefe0, 0x00002020,
- 0xffffdfe0, 0x00002800, 0xffffd800, 0x00000028, 0xffffffd8, 0x00001fe8, 0xffffe018, 0xffffe820,
- 0x000017e0, 0x00004028, 0xffffbfd8, 0x00002840, 0xffffd7c0, 0x00002ff0, 0xffffd010, 0xfffff030,
- 0x00000fd0, 0x00004010, 0xffffbff0, 0x00001040, 0xffffefc0, 0x00004040, 0xffffbfc0, 0x00004800,
- 0xffffb800, 0x00000048, 0xffffffb8, 0x00002fd0, 0xffffd030, 0x00003fe0, 0xffffc020, 0xffffe040,
- 0x00001fc0, 0x00006828, 0xffff97d8, 0x00002868, 0xffffd798, 0x00007048, 0xffff8fb8, 0x00004870,
- 0xffffb790, 0x000057e8, 0xffffa818, 0xffffe858, 0x000017a8, 0x00007010, 0xffff8ff0, 0x00001070,
- 0xffffef90, 0x00007878, 0xffff8788, 0x000057b8, 0xffffa848, 0xffffb858, 0x000047a8, 0x000077c8,
- 0xffff8838, 0xffffc878, 0x00003788, 0x00003030, 0xffffcfd0, 0x00005858, 0xffffa7a8, 0x00000000,
- 0x08080000, 0xf7f80000, 0x08000000, 0xf8000000, 0x00080000, 0xfff80000, 0x10100000, 0xeff00000,
- 0x10080000, 0xeff80000, 0x08100000, 0x00000808, 0x08080808, 0xf7f80808, 0x08000808, 0xf8000808,
- 0x00080808, 0xfff80808, 0x10100808, 0xeff00808, 0x10080808, 0xeff80808, 0x08100808, 0xfffff7f8,
- 0x0807f7f8, 0xf7f7f7f8, 0x07fff7f8, 0xf7fff7f8, 0x0007f7f8, 0xfff7f7f8, 0x100ff7f8, 0xefeff7f8,
- 0x1007f7f8, 0xeff7f7f8, 0x080ff7f8, 0x00000800, 0x08080800, 0xf7f80800, 0x08000800, 0xf8000800,
- 0x00080800, 0xfff80800, 0x10100800, 0xeff00800, 0x10080800, 0xeff80800, 0x08100800, 0xfffff800,
- 0x0807f800, 0xf7f7f800, 0x07fff800, 0xf7fff800, 0x0007f800, 0xfff7f800, 0x100ff800, 0xefeff800,
- 0x1007f800, 0xeff7f800, 0x080ff800, 0x00000008, 0x08080008, 0xf7f80008, 0x08000008, 0xf8000008,
- 0x00080008, 0xfff80008, 0x10100008, 0xeff00008, 0x10080008, 0xeff80008, 0x08100008, 0xfffffff8,
- 0x0807fff8, 0xf7f7fff8, 0x07fffff8, 0xf7fffff8, 0x0007fff8, 0xfff7fff8, 0x100ffff8, 0xefeffff8,
- 0x1007fff8, 0xeff7fff8, 0x080ffff8, 0x00001010, 0x08081010, 0xf7f81010, 0x08001010, 0xf8001010,
- 0x00081010, 0xfff81010, 0x10101010, 0xeff01010, 0x10081010, 0xeff81010, 0x08101010, 0xffffeff0,
- 0x0807eff0, 0xf7f7eff0, 0x07ffeff0, 0xf7ffeff0, 0x0007eff0, 0xfff7eff0, 0x100feff0, 0xefefeff0,
- 0x1007eff0, 0xeff7eff0, 0x080feff0, 0x00001008, 0x08081008, 0xf7f81008, 0x08001008, 0xf8001008,
- 0x00081008, 0xfff81008, 0x10101008, 0xeff01008, 0x10081008, 0xeff81008, 0x08101008, 0xffffeff8,
- 0x0807eff8, 0xf7f7eff8, 0x07ffeff8, 0xf7ffeff8, 0x0007eff8, 0xfff7eff8, 0x100feff8, 0xefefeff8,
- 0x1007eff8, 0xeff7eff8, 0x080feff8, 0x00000810, 0x08080810, 0xf7f80810, 0x08000810, 0xf8000810,
- 0x00080810, 0xfff80810, 0x10100810, 0xeff00810, 0x10080810, 0xeff80810, 0x08100810, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000909, 0xfffff6f7, 0x00000900, 0xfffff700, 0x00000009, 0xfffffff7, 0x00001212,
- 0xffffedee, 0x00001b09, 0xffffe4f7, 0x0000091b, 0xfffff6e5, 0x000011ee, 0xffffee12, 0x00001af7,
- 0xffffe509, 0xfffff71b, 0x000008e5, 0x00002412, 0xffffdbee, 0x00001224, 0xffffeddc, 0x00002424,
- 0xffffdbdc, 0x00002d00, 0xffffd300, 0x0000002d, 0xffffffd3, 0x000023e5, 0xffffdc1b, 0xffffe524,
- 0x00001adc, 0x0000482d, 0xffffb7d3, 0x00002d48, 0xffffd2b8, 0x000035ee, 0xffffca12, 0xffffee36,
- 0x000011ca, 0x00004812, 0xffffb7ee, 0x00001248, 0xffffedb8, 0x00004848, 0xffffb7b8, 0x00005100,
- 0xffffaf00, 0x00000051, 0xffffffaf, 0x000035ca, 0xffffca36, 0x000047dc, 0xffffb824, 0xffffdc48,
- 0x000023b8, 0x0000752d, 0xffff8ad3, 0x00002d75, 0xffffd28b, 0x00007e51, 0xffff81af, 0x0000517e,
- 0xffffae82, 0x000062e5, 0xffff9d1b, 0xffffe563, 0x00001a9d, 0x000062af, 0xffff9d51, 0xffffaf63,
- 0x0000509d, 0x00003636, 0xffffc9ca, 0x00006c6c, 0xffff9394, 0x00000000, 0x09090000, 0xf6f70000,
- 0x09000000, 0xf7000000, 0x00090000, 0xfff70000, 0x12120000, 0xedee0000, 0x1b090000, 0xe4f70000,
- 0x091b0000, 0xf6e50000, 0x00000909, 0x09090909, 0xf6f70909, 0x09000909, 0xf7000909, 0x00090909,
- 0xfff70909, 0x12120909, 0xedee0909, 0x1b090909, 0xe4f70909, 0x091b0909, 0xf6e50909, 0xfffff6f7,
- 0x0908f6f7, 0xf6f6f6f7, 0x08fff6f7, 0xf6fff6f7, 0x0008f6f7, 0xfff6f6f7, 0x1211f6f7, 0xededf6f7,
- 0x1b08f6f7, 0xe4f6f6f7, 0x091af6f7, 0xf6e4f6f7, 0x00000900, 0x09090900, 0xf6f70900, 0x09000900,
- 0xf7000900, 0x00090900, 0xfff70900, 0x12120900, 0xedee0900, 0x1b090900, 0xe4f70900, 0x091b0900,
- 0xf6e50900, 0xfffff700, 0x0908f700, 0xf6f6f700, 0x08fff700, 0xf6fff700, 0x0008f700, 0xfff6f700,
- 0x1211f700, 0xededf700, 0x1b08f700, 0xe4f6f700, 0x091af700, 0xf6e4f700, 0x00000009, 0x09090009,
- 0xf6f70009, 0x09000009, 0xf7000009, 0x00090009, 0xfff70009, 0x12120009, 0xedee0009, 0x1b090009,
- 0xe4f70009, 0x091b0009, 0xf6e50009, 0xfffffff7, 0x0908fff7, 0xf6f6fff7, 0x08fffff7, 0xf6fffff7,
- 0x0008fff7, 0xfff6fff7, 0x1211fff7, 0xededfff7, 0x1b08fff7, 0xe4f6fff7, 0x091afff7, 0xf6e4fff7,
- 0x00001212, 0x09091212, 0xf6f71212, 0x09001212, 0xf7001212, 0x00091212, 0xfff71212, 0x12121212,
- 0xedee1212, 0x1b091212, 0xe4f71212, 0x091b1212, 0xf6e51212, 0xffffedee, 0x0908edee, 0xf6f6edee,
- 0x08ffedee, 0xf6ffedee, 0x0008edee, 0xfff6edee, 0x1211edee, 0xedededee, 0x1b08edee, 0xe4f6edee,
- 0x091aedee, 0xf6e4edee, 0x00001b09, 0x09091b09, 0xf6f71b09, 0x09001b09, 0xf7001b09, 0x00091b09,
- 0xfff71b09, 0x12121b09, 0xedee1b09, 0x1b091b09, 0xe4f71b09, 0x091b1b09, 0xf6e51b09, 0xffffe4f7,
- 0x0908e4f7, 0xf6f6e4f7, 0x08ffe4f7, 0xf6ffe4f7, 0x0008e4f7, 0xfff6e4f7, 0x1211e4f7, 0xedede4f7,
- 0x1b08e4f7, 0xe4f6e4f7, 0x091ae4f7, 0xf6e4e4f7, 0x0000091b, 0x0909091b, 0xf6f7091b, 0x0900091b,
- 0xf700091b, 0x0009091b, 0xfff7091b, 0x1212091b, 0xedee091b, 0x1b09091b, 0xe4f7091b, 0x091b091b,
- 0xf6e5091b, 0xfffff6e5, 0x0908f6e5, 0xf6f6f6e5, 0x08fff6e5, 0xf6fff6e5, 0x0008f6e5, 0xfff6f6e5,
- 0x1211f6e5, 0xededf6e5, 0x1b08f6e5, 0xe4f6f6e5, 0x091af6e5, 0xf6e4f6e5, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606,
- 0xfffff9fa, 0x00000700, 0xfffff900, 0x00000007, 0xfffffff9, 0x000004fb, 0xfffffb05, 0xfffffb05,
- 0x000004fb, 0x00000b06, 0xfffff4fa, 0x0000060b, 0xfffff9f5, 0x00000800, 0xfffff800, 0x00000008,
- 0xfffffff8, 0x00000b0b, 0xfffff4f5, 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x0000110c,
- 0xffffeef4, 0x00000c11, 0xfffff3ef, 0x00001111, 0xffffeeef, 0x00001206, 0xffffedfa, 0x00000612,
- 0xfffff9ee, 0x00000af8, 0xfffff508, 0xfffff80b, 0x000007f5, 0x00000f00, 0xfffff100, 0x0000000f,
- 0xfffffff1, 0x00001400, 0xffffec00, 0x00000014, 0xffffffec, 0x00001912, 0xffffe6ee, 0x00001219,
- 0xffffede7, 0x0000190b, 0xffffe6f5, 0x00000b19, 0xfffff4e7, 0x00001919, 0xffffe6e7, 0x00000df2,
- 0xfffff20e, 0xfffff20e, 0x00000df2, 0x00001a00, 0xffffe600, 0x0000001a, 0xffffffe6, 0x000011f5,
- 0xffffee0b, 0xfffff512, 0x00000aee, 0x000015f9, 0xffffea07, 0xfffff916, 0x000006ea, 0x0000221a,
- 0xffffdde6, 0x00001a22, 0xffffe5de, 0x00002212, 0xffffddee, 0x00001222, 0xffffedde, 0x00002222,
- 0xffffddde, 0x0000230b, 0xffffdcf5, 0x00000b23, 0xfffff4dd, 0x00001d00, 0xffffe300, 0x0000001d,
- 0xffffffe3, 0x000015ed, 0xffffea13, 0xffffed16, 0x000012ea, 0x000019f1, 0xffffe60f, 0xfffff11a,
- 0x00000ee6, 0x00002500, 0xffffdb00, 0x00000025, 0xffffffdb, 0x00002c1b, 0xffffd3e5, 0x00001b2c,
- 0xffffe4d4, 0x00002c24, 0xffffd3dc, 0x0000242c, 0xffffdbd4, 0x00002c12, 0xffffd3ee, 0x0000122c,
- 0xffffedd4, 0x000020f6, 0xffffdf0a, 0xfffff621, 0x000009df, 0x00002d2d, 0xffffd2d3, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606,
- 0xfffff9fa, 0x00000700, 0xfffff900, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020300, 0x0201fd00,
- 0x02020003, 0x0201fffd, 0x02020606, 0x0201f9fa, 0x02020700, 0x0201f900, 0xfdfe0000, 0xfdfe0202,
- 0xfdfdfdfe, 0xfdfe0300, 0xfdfdfd00, 0xfdfe0003, 0xfdfdfffd, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0700,
- 0xfdfdf900, 0x03000000, 0x03000202, 0x02fffdfe, 0x03000300, 0x02fffd00, 0x03000003, 0x02fffffd,
- 0x03000606, 0x02fff9fa, 0x03000700, 0x02fff900, 0xfd000000, 0xfd000202, 0xfcfffdfe, 0xfd000300,
- 0xfcfffd00, 0xfd000003, 0xfcfffffd, 0xfd000606, 0xfcfff9fa, 0xfd000700, 0xfcfff900, 0x00030000,
- 0x00030202, 0x0002fdfe, 0x00030300, 0x0002fd00, 0x00030003, 0x0002fffd, 0x00030606, 0x0002f9fa,
- 0x00030700, 0x0002f900, 0xfffd0000, 0xfffd0202, 0xfffcfdfe, 0xfffd0300, 0xfffcfd00, 0xfffd0003,
- 0xfffcfffd, 0xfffd0606, 0xfffcf9fa, 0xfffd0700, 0xfffcf900, 0x06060000, 0x06060202, 0x0605fdfe,
- 0x06060300, 0x0605fd00, 0x06060003, 0x0605fffd, 0x06060606, 0x0605f9fa, 0x06060700, 0x0605f900,
- 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0300, 0xf9f9fd00, 0xf9fa0003, 0xf9f9fffd, 0xf9fa0606,
- 0xf9f9f9fa, 0xf9fa0700, 0xf9f9f900, 0x07000000, 0x07000202, 0x06fffdfe, 0x07000300, 0x06fffd00,
- 0x07000003, 0x06fffffd, 0x07000606, 0x06fff9fa, 0x07000700, 0x06fff900, 0xf9000000, 0xf9000202,
- 0xf8fffdfe, 0xf9000300, 0xf8fffd00, 0xf9000003, 0xf8fffffd, 0xf9000606, 0xf8fff9fa, 0xf9000700,
- 0xf8fff900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000202, 0xfffffdfe, 0x00000606,
- 0xfffff9fa, 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x000003fc, 0xfffffc04, 0xfffffa0a,
- 0x000005f6, 0xfffff400, 0x00000c00, 0xfffff3fa, 0xfffff406, 0x00000bfa, 0x00000c06, 0xfffffff2,
- 0x0000000e, 0x00000c0c, 0xfffff3f4, 0xffffee00, 0x00001200, 0xfffff40e, 0x00000bf2, 0xfffff9ee,
- 0xfffffa12, 0x000005ee, 0x00000612, 0xffffedf6, 0xffffee0a, 0x000011f6, 0x0000120a, 0xffffffea,
- 0x00000016, 0xffffe800, 0x00001800, 0xfffff3ea, 0xfffff416, 0x00000bea, 0x00000c16, 0xffffe7f8,
- 0xffffe808, 0x000017f8, 0x00001808, 0xfffff9e6, 0xfffffa1a, 0x000005e6, 0x0000061a, 0xffffffe4,
- 0x0000001c, 0x00001414, 0xffffebec, 0xffffe5f2, 0x00001a0e, 0xfffff3e2, 0x00000c1e, 0xffffdff6,
- 0x0000200a, 0xffffdfee, 0x00002012, 0xffffe5e6, 0x00001a1a, 0xffffebde, 0x00001422, 0xfffff3da,
- 0x00000c26, 0xffffdfe0, 0x00002020, 0x00002020, 0xffffd7ea, 0xffffddde, 0x00002222, 0x00000000,
- 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa,
- 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x02000000, 0x02000200, 0x01fffe00, 0x02000002,
- 0x01fffffe, 0x02000202, 0x01fffdfe, 0x02000606, 0x01fff9fa, 0x02000600, 0x01fffa00, 0x02000006,
- 0x01fffffa, 0xfe000000, 0xfe000200, 0xfdfffe00, 0xfe000002, 0xfdfffffe, 0xfe000202, 0xfdfffdfe,
- 0xfe000606, 0xfdfff9fa, 0xfe000600, 0xfdfffa00, 0xfe000006, 0xfdfffffa, 0x00020000, 0x00020200,
- 0x0001fe00, 0x00020002, 0x0001fffe, 0x00020202, 0x0001fdfe, 0x00020606, 0x0001f9fa, 0x00020600,
- 0x0001fa00, 0x00020006, 0x0001fffa, 0xfffe0000, 0xfffe0200, 0xfffdfe00, 0xfffe0002, 0xfffdfffe,
- 0xfffe0202, 0xfffdfdfe, 0xfffe0606, 0xfffdf9fa, 0xfffe0600, 0xfffdfa00, 0xfffe0006, 0xfffdfffa,
- 0x02020000, 0x02020200, 0x0201fe00, 0x02020002, 0x0201fffe, 0x02020202, 0x0201fdfe, 0x02020606,
- 0x0201f9fa, 0x02020600, 0x0201fa00, 0x02020006, 0x0201fffa, 0xfdfe0000, 0xfdfe0200, 0xfdfdfe00,
- 0xfdfe0002, 0xfdfdfffe, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0600, 0xfdfdfa00,
- 0xfdfe0006, 0xfdfdfffa, 0x06060000, 0x06060200, 0x0605fe00, 0x06060002, 0x0605fffe, 0x06060202,
- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060600, 0x0605fa00, 0x06060006, 0x0605fffa, 0xf9fa0000,
- 0xf9fa0200, 0xf9f9fe00, 0xf9fa0002, 0xf9f9fffe, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa,
- 0xf9fa0600, 0xf9f9fa00, 0xf9fa0006, 0xf9f9fffa, 0x06000000, 0x06000200, 0x05fffe00, 0x06000002,
- 0x05fffffe, 0x06000202, 0x05fffdfe, 0x06000606, 0x05fff9fa, 0x06000600, 0x05fffa00, 0x06000006,
- 0x05fffffa, 0xfa000000, 0xfa000200, 0xf9fffe00, 0xfa000002, 0xf9fffffe, 0xfa000202, 0xf9fffdfe,
- 0xfa000606, 0xf9fff9fa, 0xfa000600, 0xf9fffa00, 0xfa000006, 0xf9fffffa, 0x00060000, 0x00060200,
- 0x0005fe00, 0x00060002, 0x0005fffe, 0x00060202, 0x0005fdfe, 0x00060606, 0x0005f9fa, 0x00060600,
- 0x0005fa00, 0x00060006, 0x0005fffa, 0xfffa0000, 0xfffa0200, 0xfff9fe00, 0xfffa0002, 0xfff9fffe,
- 0xfffa0202, 0xfff9fdfe, 0xfffa0606, 0xfff9f9fa, 0xfffa0600, 0xfff9fa00, 0xfffa0006, 0xfff9fffa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404, 0xfffffbfc, 0x00000a0a,
- 0xfffff5f6, 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x000005fa, 0xfffffa06, 0xfffff80e,
- 0x000007f2, 0xffffffee, 0x00000012, 0xfffff00a, 0x00000ff6, 0xffffe800, 0x00001800, 0xfffff7e8,
- 0xfffff818, 0x000007e8, 0x00000818, 0x00001212, 0xffffedee, 0xfffff014, 0x00000fec, 0xffffe5f2,
- 0xffffe60e, 0x000019f2, 0x00001a0e, 0xffffffe2, 0x0000001e, 0xffffde00, 0x00002200, 0xfffff7de,
- 0xfffff822, 0x000007de, 0x00000822, 0xffffede2, 0xffffee1e, 0x000011e2, 0x0000121e, 0xffffddf6,
- 0xffffde0a, 0x000021f6, 0x0000220a, 0xffffddec, 0x00002214, 0xffffffd8, 0x00000028, 0x00001e1e,
- 0xffffe1e2, 0xffffedd8, 0x00001228, 0xffffd400, 0x00002c00, 0xffffd3f0, 0x00002c10, 0xffffdbdc,
- 0xffffdbdc, 0x00002424, 0xffffd3e6, 0x00002c1a, 0xffffe5d2, 0x00001a2e, 0xffffedcc, 0x00001234,
- 0xffffc9ec, 0xffffd3d4, 0x00002c2c, 0xffffc9e0, 0xffffd1d2, 0xffffd1d2, 0x00002e2e, 0x00000000,
- 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404, 0xfffffbfc, 0x00000a0a, 0xfffff5f6,
- 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x02000000, 0x02000200, 0x01fffe00, 0x02000002,
- 0x01fffffe, 0x02000404, 0x01fffbfc, 0x02000a0a, 0x01fff5f6, 0x02000a00, 0x01fff600, 0x0200000a,
- 0x01fffff6, 0xfe000000, 0xfe000200, 0xfdfffe00, 0xfe000002, 0xfdfffffe, 0xfe000404, 0xfdfffbfc,
- 0xfe000a0a, 0xfdfff5f6, 0xfe000a00, 0xfdfff600, 0xfe00000a, 0xfdfffff6, 0x00020000, 0x00020200,
- 0x0001fe00, 0x00020002, 0x0001fffe, 0x00020404, 0x0001fbfc, 0x00020a0a, 0x0001f5f6, 0x00020a00,
- 0x0001f600, 0x0002000a, 0x0001fff6, 0xfffe0000, 0xfffe0200, 0xfffdfe00, 0xfffe0002, 0xfffdfffe,
- 0xfffe0404, 0xfffdfbfc, 0xfffe0a0a, 0xfffdf5f6, 0xfffe0a00, 0xfffdf600, 0xfffe000a, 0xfffdfff6,
- 0x04040000, 0x04040200, 0x0403fe00, 0x04040002, 0x0403fffe, 0x04040404, 0x0403fbfc, 0x04040a0a,
- 0x0403f5f6, 0x04040a00, 0x0403f600, 0x0404000a, 0x0403fff6, 0xfbfc0000, 0xfbfc0200, 0xfbfbfe00,
- 0xfbfc0002, 0xfbfbfffe, 0xfbfc0404, 0xfbfbfbfc, 0xfbfc0a0a, 0xfbfbf5f6, 0xfbfc0a00, 0xfbfbf600,
- 0xfbfc000a, 0xfbfbfff6, 0x0a0a0000, 0x0a0a0200, 0x0a09fe00, 0x0a0a0002, 0x0a09fffe, 0x0a0a0404,
- 0x0a09fbfc, 0x0a0a0a0a, 0x0a09f5f6, 0x0a0a0a00, 0x0a09f600, 0x0a0a000a, 0x0a09fff6, 0xf5f60000,
- 0xf5f60200, 0xf5f5fe00, 0xf5f60002, 0xf5f5fffe, 0xf5f60404, 0xf5f5fbfc, 0xf5f60a0a, 0xf5f5f5f6,
- 0xf5f60a00, 0xf5f5f600, 0xf5f6000a, 0xf5f5fff6, 0x0a000000, 0x0a000200, 0x09fffe00, 0x0a000002,
- 0x09fffffe, 0x0a000404, 0x09fffbfc, 0x0a000a0a, 0x09fff5f6, 0x0a000a00, 0x09fff600, 0x0a00000a,
- 0x09fffff6, 0xf6000000, 0xf6000200, 0xf5fffe00, 0xf6000002, 0xf5fffffe, 0xf6000404, 0xf5fffbfc,
- 0xf6000a0a, 0xf5fff5f6, 0xf6000a00, 0xf5fff600, 0xf600000a, 0xf5fffff6, 0x000a0000, 0x000a0200,
- 0x0009fe00, 0x000a0002, 0x0009fffe, 0x000a0404, 0x0009fbfc, 0x000a0a0a, 0x0009f5f6, 0x000a0a00,
- 0x0009f600, 0x000a000a, 0x0009fff6, 0xfff60000, 0xfff60200, 0xfff5fe00, 0xfff60002, 0xfff5fffe,
- 0xfff60404, 0xfff5fbfc, 0xfff60a0a, 0xfff5f5f6, 0xfff60a00, 0xfff5f600, 0xfff6000a, 0xfff5fff6,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000404, 0xfffffbfc, 0x00000c0c,
- 0xfffff3f4, 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x000007f8, 0xfffff808, 0xfffff008,
- 0x00000ff8, 0xffffe800, 0x00001800, 0xfffff7e8, 0xfffff818, 0x000007e8, 0x00000818, 0xfffff014,
- 0x00000fec, 0xffffffe4, 0x0000001c, 0xffffe7f0, 0xffffe810, 0x000017f0, 0x00001810, 0xffffe000,
- 0x00002000, 0xffffefe4, 0xfffff01c, 0x00000fe4, 0x0000101c, 0xffffdff8, 0xffffe008, 0xfffff7e0,
- 0xfffff820, 0x000007e0, 0x00000820, 0x00001ff8, 0x00002008, 0x00001818, 0xffffe7e8, 0xffffe818,
- 0x000017e8, 0xffffdfec, 0x00002014, 0xffffffd8, 0x00000028, 0xffffefd8, 0x00001028, 0xffffd400,
- 0xffffd400, 0xffffffd4, 0x0000002c, 0x00002c00, 0x00002c00, 0xffffdfe0, 0x00002020, 0xffffd3f0,
- 0x00002c10, 0xffffd3e8, 0xffffe7d4, 0x0000182c, 0x00002c18, 0xffffefd0, 0x00001030, 0xffffdbdc,
- 0xffffdbdc, 0x00002424, 0x00002424, 0xffffcbec, 0x00002828, 0xffffd7d8, 0xffffcbe0, 0x00000000,
- 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000404, 0xfffffbfc, 0x00000c0c, 0xfffff3f4,
- 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x04000000, 0x04000400, 0x03fffc00, 0x04000004,
- 0x03fffffc, 0x04000404, 0x03fffbfc, 0x04000c0c, 0x03fff3f4, 0x04000c00, 0x03fff400, 0x0400000c,
- 0x03fffff4, 0xfc000000, 0xfc000400, 0xfbfffc00, 0xfc000004, 0xfbfffffc, 0xfc000404, 0xfbfffbfc,
- 0xfc000c0c, 0xfbfff3f4, 0xfc000c00, 0xfbfff400, 0xfc00000c, 0xfbfffff4, 0x00040000, 0x00040400,
- 0x0003fc00, 0x00040004, 0x0003fffc, 0x00040404, 0x0003fbfc, 0x00040c0c, 0x0003f3f4, 0x00040c00,
- 0x0003f400, 0x0004000c, 0x0003fff4, 0xfffc0000, 0xfffc0400, 0xfffbfc00, 0xfffc0004, 0xfffbfffc,
- 0xfffc0404, 0xfffbfbfc, 0xfffc0c0c, 0xfffbf3f4, 0xfffc0c00, 0xfffbf400, 0xfffc000c, 0xfffbfff4,
- 0x04040000, 0x04040400, 0x0403fc00, 0x04040004, 0x0403fffc, 0x04040404, 0x0403fbfc, 0x04040c0c,
- 0x0403f3f4, 0x04040c00, 0x0403f400, 0x0404000c, 0x0403fff4, 0xfbfc0000, 0xfbfc0400, 0xfbfbfc00,
- 0xfbfc0004, 0xfbfbfffc, 0xfbfc0404, 0xfbfbfbfc, 0xfbfc0c0c, 0xfbfbf3f4, 0xfbfc0c00, 0xfbfbf400,
- 0xfbfc000c, 0xfbfbfff4, 0x0c0c0000, 0x0c0c0400, 0x0c0bfc00, 0x0c0c0004, 0x0c0bfffc, 0x0c0c0404,
- 0x0c0bfbfc, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c0c00, 0x0c0bf400, 0x0c0c000c, 0x0c0bfff4, 0xf3f40000,
- 0xf3f40400, 0xf3f3fc00, 0xf3f40004, 0xf3f3fffc, 0xf3f40404, 0xf3f3fbfc, 0xf3f40c0c, 0xf3f3f3f4,
- 0xf3f40c00, 0xf3f3f400, 0xf3f4000c, 0xf3f3fff4, 0x0c000000, 0x0c000400, 0x0bfffc00, 0x0c000004,
- 0x0bfffffc, 0x0c000404, 0x0bfffbfc, 0x0c000c0c, 0x0bfff3f4, 0x0c000c00, 0x0bfff400, 0x0c00000c,
- 0x0bfffff4, 0xf4000000, 0xf4000400, 0xf3fffc00, 0xf4000004, 0xf3fffffc, 0xf4000404, 0xf3fffbfc,
- 0xf4000c0c, 0xf3fff3f4, 0xf4000c00, 0xf3fff400, 0xf400000c, 0xf3fffff4, 0x000c0000, 0x000c0400,
- 0x000bfc00, 0x000c0004, 0x000bfffc, 0x000c0404, 0x000bfbfc, 0x000c0c0c, 0x000bf3f4, 0x000c0c00,
- 0x000bf400, 0x000c000c, 0x000bfff4, 0xfff40000, 0xfff40400, 0xfff3fc00, 0xfff40004, 0xfff3fffc,
- 0xfff40404, 0xfff3fbfc, 0xfff40c0c, 0xfff3f3f4, 0xfff40c00, 0xfff3f400, 0xfff4000c, 0xfff3fff4,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414,
- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec,
- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606,
- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e,
- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4,
- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202,
- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020,
- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa,
- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2,
- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414,
- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe,
- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0,
- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c,
- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000,
- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec,
- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606,
- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e,
- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4,
- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202,
- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020,
- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa,
- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414,
- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec,
- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606,
- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e,
- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4,
- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202,
- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020,
- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa,
- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2,
- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414,
- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe,
- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0,
- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c,
- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000,
- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec,
- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606,
- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e,
- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4,
- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202,
- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020,
- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa,
- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414,
- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec,
- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606,
- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e,
- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4,
- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202,
- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020,
- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa,
- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2,
- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414,
- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe,
- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0,
- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c,
- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000,
- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec,
- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606,
- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e,
- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4,
- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202,
- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020,
- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa,
- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414,
- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec,
- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606,
- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e,
- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4,
- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202,
- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020,
- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa,
- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2,
- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414,
- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe,
- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0,
- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c,
- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000,
- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec,
- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606,
- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e,
- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4,
- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202,
- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020,
- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa,
- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
-};
-
-
-static const uint32_t correctionloworder[] = {
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x04040404,
- 0xfbfbfbfc, 0x05050101, 0xfafafeff, 0x01010505, 0xfefefafb, 0x0403fbfc, 0xfbfc0404, 0x0605fdfe,
- 0xf9fa0202, 0xfdfe0606, 0x0201f9fa, 0x09090404, 0xf6f6fbfc, 0x04040909, 0xfbfbf6f7, 0x09090909,
- 0xf6f6f6f7, 0x0a0a0101, 0xf5f5feff, 0x01010a0a, 0xfefef5f6, 0x0807fafb, 0xf7f80505, 0xfafb0808,
- 0x0504f7f8, 0x0f0f0909, 0xf0f0f6f7, 0x09090f0f, 0xf6f6f0f1, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c,
- 0x0302f3f4, 0x10100404, 0xefeffbfc, 0x04041010, 0xfbfbeff0, 0x10101010, 0xefefeff0, 0x12120000,
- 0xedee0000, 0x00001212, 0xffffedee, 0x0c0bf3f4, 0xf3f40c0c, 0x100ff6f7, 0xeff00909, 0xf6f71010,
- 0x0908eff0, 0x1b1b0b0b, 0xe4e4f4f5, 0x0b0b1b1b, 0xf4f4e4e5, 0x1c1c1313, 0xe3e3eced, 0x13131c1c,
- 0xecece3e4, 0x1615f9fa, 0xe9ea0606, 0xf9fa1616, 0x0605e9ea, 0x1d1d0404, 0xe2e2fbfc, 0x04041d1d,
- 0xfbfbe2e3, 0x1e1e1e1e, 0xe1e1e1e2, 0x2120fdfe, 0xdedf0202, 0xfdfe2121, 0x0201dedf, 0x1716edee,
- 0xe8e91212, 0xedee1717, 0x1211e8e9, 0x1e1df0f1, 0xe1e20f0f, 0xf0f11e1e, 0x0f0ee1e2, 0x2e2e1616,
- 0xd1d1e9ea, 0x16162e2e, 0xe9e9d1d2, 0x2f2f0d0d, 0xd0d0f2f3, 0x0d0d2f2f, 0xf2f2d0d1, 0x31312323,
- 0xcecedcdd, 0x23233131, 0xdcdccecf, 0x2928f4f5, 0xd6d70b0b, 0xf4f52929, 0x0b0ad6d7, 0x33330404,
- 0xccccfbfc, 0x04043333, 0xfbfbcccd, 0x36363636, 0xc9c9c9ca, 0x2221ddde, 0xddde2222, 0x2a29e2e3,
- 0xd5d61d1d, 0xe2e32a2a, 0x1d1cd5d6, 0x3c3bf9fa, 0xc3c40606, 0xf9fa3c3c, 0x0605c3c4, 0x4c4c1b1b,
- 0xb3b3e4e5, 0x1b1b4c4c, 0xe4e4b3b4, 0x4d4d2b2b, 0xb2b2d4d5, 0x2b2b4d4d, 0xd4d4b2b3, 0x3736e7e8,
- 0xc8c91818, 0xe7e83737, 0x1817c8c9, 0x4f4f0e0e, 0xb0b0f1f2, 0x0e0e4f4f, 0xf1f1b0b1, 0x53533f3f,
- 0xacacc0c1, 0x3f3f5353, 0xc0c0acad, 0x4a49ebec, 0xb5b61414, 0xebec4a4a, 0x1413b5b6, 0x58580202,
- 0xa7a7fdfe, 0x02025858, 0xfdfda7a8, 0x5d5d5d5d, 0xa2a2a2a3, 0x3d3ccbcc, 0xc2c33434, 0xcbcc3d3d,
- 0x3433c2c3, 0x78783434, 0x8787cbcc, 0x34347878, 0xcbcb8788, 0x4b4ad2d3, 0xb4b52d2d, 0xd2d34b4b,
- 0x2d2cb4b5, 0x7d7d4b4b, 0x8282b4b5, 0x4b4b7d7d, 0xb4b48283, 0x7a7a2121, 0x8585dedf, 0x21217a7a,
- 0xdede8586, 0x6766f2f3, 0x98990d0d, 0xf2f36767, 0x0d0c9899, 0x605fd7d8, 0x9fa02828, 0xd7d86060,
- 0x28279fa0, 0x7f7eddde, 0x80812222, 0xddde7f7f, 0x22218081, 0x5958a6a7, 0xa6a75959, 0x6968b1b2,
- 0x96974e4e, 0xb1b26969, 0x4e4d9697, 0x0c0c0c0c, 0xf3f3f3f4, 0x17171717, 0xe8e8e8e9, 0x2a2a2a2a,
- 0xd5d5d5d6, 0x49494949, 0xb6b6b6b7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0xfcfd0101,
- 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfeff0303, 0xfeff0303,
- 0xfeff0303, 0xfeff0303, 0xfeff0303, 0xfeff0303, 0xfeff0303, 0x0100fcfd, 0x0100fcfd, 0x0100fcfd,
- 0x0100fcfd, 0x0100fcfd, 0x0100fcfd, 0x0100fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707,
- 0xf8f8f8f9, 0x08080202, 0xf7f7fdfe, 0x02020808, 0xfdfdf7f8, 0x0908fdfe, 0xf6f70202, 0xfdfe0909,
- 0x0201f6f7, 0x0605f9fa, 0xf9fa0606, 0x0d0d0606, 0xf2f2f9fa, 0x06060d0d, 0xf9f9f2f3, 0x0d0d0d0d,
- 0xf2f2f2f3, 0x0e0e0101, 0xf1f1feff, 0x01010e0e, 0xfefef1f2, 0x0c0bf7f8, 0xf3f40808, 0xf7f80c0c,
- 0x0807f3f4, 0x17170e0e, 0xe8e8f1f2, 0x0e0e1717, 0xf1f1e8e9, 0x1211fafb, 0xedee0505, 0xfafb1212,
- 0x0504edee, 0x18180606, 0xe7e7f9fa, 0x06061818, 0xf9f9e7e8, 0x18181818, 0xe7e7e7e8, 0x1b1afeff,
- 0xe4e50101, 0xfeff1b1b, 0x0100e4e5, 0x1110eeef, 0xeeef1111, 0x1716f2f3, 0xe8e90d0d, 0xf2f31717,
- 0x0d0ce8e9, 0x28281010, 0xd7d7eff0, 0x10102828, 0xefefd7d8, 0x29291c1c, 0xd6d6e3e4, 0x1c1c2929,
- 0xe3e3d6d7, 0x2120f6f7, 0xdedf0909, 0xf6f72121, 0x0908dedf, 0x2b2b0606, 0xd4d4f9fa, 0x06062b2b,
- 0xf9f9d4d5, 0x2e2e2e2e, 0xd1d1d1d2, 0x3231fbfc, 0xcdce0404, 0xfbfc3232, 0x0403cdce, 0x2221e4e5,
- 0xddde1b1b, 0xe4e52222, 0x1b1addde, 0x2d2ce9ea, 0xd2d31616, 0xe9ea2d2d, 0x1615d2d3, 0x45452222,
- 0xbabaddde, 0x22224545, 0xddddbabb, 0x46461313, 0xb9b9eced, 0x13134646, 0xececb9ba, 0x49493535,
- 0xb6b6cacb, 0x35354949, 0xcacab6b7, 0x3e3deeef, 0xc1c21111, 0xeeef3e3e, 0x1110c1c2, 0x4d4d0505,
- 0xb2b2fafb, 0x05054d4d, 0xfafab2b3, 0x52525252, 0xadadadae, 0x3332cccd, 0xcccd3333, 0x403fd4d5,
- 0xbfc02b2b, 0xd4d54040, 0x2b2abfc0, 0x5a59f5f6, 0xa5a60a0a, 0xf5f65a5a, 0x0a09a5a6, 0x72722929,
- 0x8d8dd6d7, 0x29297272, 0xd6d68d8e, 0x74744040, 0x8b8bbfc0, 0x40407474, 0xbfbf8b8c, 0x5251dadb,
- 0xadae2525, 0xdadb5252, 0x2524adae, 0x77771616, 0x8888e9ea, 0x16167777, 0xe9e98889, 0x7c7c5f5f,
- 0x8383a0a1, 0x5f5f7c7c, 0xa0a08384, 0x6f6ee1e2, 0x90911e1e, 0xe1e26f6f, 0x1e1d9091, 0x5c5bb1b2,
- 0xa3a44e4e, 0xb1b25c5c, 0x4e4da3a4, 0x7170bbbc, 0x8e8f4444, 0xbbbc7171, 0x44438e8f, 0x12121212,
- 0xedededee, 0x22222222, 0xddddddde, 0x3f3f3f3f, 0xc0c0c0c1, 0x6d6d6d6d, 0x92929293, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303,
- 0x03030303, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd,
- 0xfcfcfcfd, 0xfcfcfcfd, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff,
- 0x0403feff, 0x0403feff, 0x0403feff, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101,
- 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404,
- 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc,
- 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x07070707, 0x07070707,
- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9,
- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303,
- 0xf5f5fcfd, 0x03030a0a, 0xfcfcf5f6, 0x09090909, 0xf6f6f6f7, 0x0706f8f9, 0xf8f90707, 0x0c0bfcfd,
- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x11110808, 0xeeeef7f8, 0x08081111, 0xf7f7eeef, 0x11111111,
- 0xeeeeeeef, 0x13130101, 0xececfeff, 0x01011313, 0xfefeeced, 0x100ff4f5, 0xeff00b0b, 0xf4f51010,
- 0x0b0aeff0, 0x1716f9fa, 0xe8e90606, 0xf9fa1717, 0x0605e8e9, 0x1f1f1212, 0xe0e0edee, 0x12121f1f,
- 0xedede0e1, 0x20200808, 0xdfdff7f8, 0x08082020, 0xf7f7dfe0, 0x21212121, 0xdedededf, 0x2423feff,
- 0xdbdc0101, 0xfeff2424, 0x0100dbdc, 0x1716e8e9, 0xe8e91717, 0x1f1eeeef, 0xe0e11111, 0xeeef1f1f,
- 0x1110e0e1, 0x36361515, 0xc9c9eaeb, 0x15153636, 0xeaeac9ca, 0x37372525, 0xc8c8dadb, 0x25253737,
- 0xdadac8c9, 0x2c2bf3f4, 0xd3d40c0c, 0xf3f42c2c, 0x0c0bd3d4, 0x39390808, 0xc6c6f7f8, 0x08083939,
- 0xf7f7c6c7, 0x3d3d3d3d, 0xc2c2c2c3, 0x4241fafb, 0xbdbe0505, 0xfafb4242, 0x0504bdbe, 0x2d2cdbdc,
- 0xd2d32424, 0xdbdc2d2d, 0x2423d2d3, 0x3c3be2e3, 0xc3c41d1d, 0xe2e33c3c, 0x1d1cc3c4, 0x5c5c2d2d,
- 0xa3a3d2d3, 0x2d2d5c5c, 0xd2d2a3a4, 0x5d5d1919, 0xa2a2e6e7, 0x19195d5d, 0xe6e6a2a3, 0x61614747,
- 0x9e9eb8b9, 0x47476161, 0xb8b89e9f, 0x5352e9ea, 0xacad1616, 0xe9ea5353, 0x1615acad, 0x66660707,
- 0x9999f8f9, 0x07076666, 0xf8f8999a, 0x6d6d6d6d, 0x92929293, 0x4443bbbc, 0xbbbc4444, 0x5554c6c7,
- 0xaaab3939, 0xc6c75555, 0x3938aaab, 0x7877f2f3, 0x87880d0d, 0xf2f37878, 0x0d0c8788, 0x6e6dcecf,
- 0x91923131, 0xcecf6e6e, 0x31309192, 0x7b7a9798, 0x84856868, 0x97987b7b, 0x68678485, 0x18181818,
- 0xe7e7e7e8, 0x2e2e2e2e, 0xd1d1d1d2, 0x54545454, 0xabababac, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040404,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404,
- 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff,
- 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0xfafb0101, 0xfafb0101, 0xfafb0101,
- 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfeff0505,
- 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505,
- 0xfeff0505, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb,
- 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303,
- 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd,
- 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0x03030a0a,
- 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a,
- 0x03030a0a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b,
- 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x03030d0d, 0xfcfcf2f3, 0x0908f6f7, 0xf6f70909, 0x0f0efbfc,
- 0xf0f10404, 0xfbfc0f0f, 0x0403f0f1, 0x16160b0b, 0xe9e9f4f5, 0x0b0b1616, 0xf4f4e9ea, 0x15151515,
- 0xeaeaeaeb, 0x18180202, 0xe7e7fdfe, 0x02021818, 0xfdfde7e8, 0x1413f1f2, 0xebec0e0e, 0xf1f21414,
- 0x0e0debec, 0x26261717, 0xd9d9e8e9, 0x17172626, 0xe8e8d9da, 0x1d1cf7f8, 0xe2e30808, 0xf7f81d1d,
- 0x0807e2e3, 0x27270b0b, 0xd8d8f4f5, 0x0b0b2727, 0xf4f4d8d9, 0x29292929, 0xd6d6d6d7, 0x2d2cfeff,
- 0xd2d30101, 0xfeff2d2d, 0x0100d2d3, 0x1d1ce2e3, 0xe2e31d1d, 0x2726e9ea, 0xd8d91616, 0xe9ea2727,
- 0x1615d8d9, 0x43431b1b, 0xbcbce4e5, 0x1b1b4343, 0xe4e4bcbd, 0x45452f2f, 0xbabad0d1, 0x2f2f4545,
- 0xd0d0babb, 0x3837f0f1, 0xc7c80f0f, 0xf0f13838, 0x0f0ec7c8, 0x47470b0b, 0xb8b8f4f5, 0x0b0b4747,
- 0xf4f4b8b9, 0x4c4c4c4c, 0xb3b3b3b4, 0x5352f9fa, 0xacad0606, 0xf9fa5353, 0x0605acad, 0x3938d2d3,
- 0xc6c72d2d, 0xd2d33939, 0x2d2cc6c7, 0x4b4adbdc, 0xb4b52424, 0xdbdc4b4b, 0x2423b4b5, 0x73733838,
- 0x8c8cc7c8, 0x38387373, 0xc7c78c8d, 0x75751f1f, 0x8a8ae0e1, 0x1f1f7575, 0xe0e08a8b, 0x7a7a5858,
- 0x8585a7a8, 0x58587a7a, 0xa7a78586, 0x6867e3e4, 0x97981c1c, 0xe3e46868, 0x1c1b9798, 0x5554aaab,
- 0xaaab5555, 0x6a69b7b8, 0x95964848, 0xb7b86a6a, 0x48479596, 0x1e1e1e1e, 0xe1e1e1e2, 0x3a3a3a3a,
- 0xc5c5c5c6, 0x69696969, 0x96969697, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x05050505, 0x05050505,
- 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505,
- 0x05050505, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb,
- 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe,
- 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0xf8f90202,
- 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202,
- 0xf8f90202, 0xf8f90202, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707,
- 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9,
- 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9,
- 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b,
- 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5,
- 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0x0d0d0303, 0x0d0d0303,
- 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303,
- 0x0d0d0303, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd,
- 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d,
- 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0xfbfbf0f1, 0x0b0af4f5, 0xf4f50b0b, 0x1211fafb,
- 0xedee0505, 0xfafb1212, 0x0504edee, 0x1a1a0d0d, 0xe5e5f2f3, 0x0d0d1a1a, 0xf2f2e5e6, 0x1a1a1a1a,
- 0xe5e5e5e6, 0x1d1d0202, 0xe2e2fdfe, 0x02021d1d, 0xfdfde2e3, 0x1817eff0, 0xe7e81010, 0xeff01818,
- 0x100fe7e8, 0x2e2e1c1c, 0xd1d1e3e4, 0x1c1c2e2e, 0xe3e3d1d2, 0x2322f6f7, 0xdcdd0909, 0xf6f72323,
- 0x0908dcdd, 0x2f2f0d0d, 0xd0d0f2f3, 0x0d0d2f2f, 0xf2f2d0d1, 0x31313131, 0xcecececf, 0x3635feff,
- 0xc9ca0101, 0xfeff3636, 0x0100c9ca, 0x2322dcdd, 0xdcdd2323, 0x2f2ee5e6, 0xd0d11a1a, 0xe5e62f2f,
- 0x1a19d0d1, 0x51512020, 0xaeaedfe0, 0x20205151, 0xdfdfaeaf, 0x53533838, 0xacacc7c8, 0x38385353,
- 0xc7c7acad, 0x4342edee, 0xbcbd1212, 0xedee4343, 0x1211bcbd, 0x56560d0d, 0xa9a9f2f3, 0x0d0d5656,
- 0xf2f2a9aa, 0x5b5b5b5b, 0xa4a4a4a5, 0x6362f8f9, 0x9c9d0707, 0xf8f96363, 0x07069c9d, 0x4443c9ca,
- 0xbbbc3636, 0xc9ca4444, 0x3635bbbc, 0x5a59d3d4, 0xa5a62c2c, 0xd3d45a5a, 0x2c2ba5a6, 0x7c7bdedf,
- 0x83842121, 0xdedf7c7c, 0x21208384, 0x67669899, 0x98996767, 0x7f7ea9aa, 0x80815656, 0xa9aa7f7f,
- 0x56558081, 0x25252525, 0xdadadadb, 0x45454545, 0xbabababb, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe,
- 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0xf7f80202, 0xf7f80202, 0xf7f80202,
- 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202,
- 0xf7f80202, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808,
- 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8,
- 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8,
- 0x0201f7f8, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d,
- 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3,
- 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3,
- 0xf2f2f2f3, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404,
- 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc,
- 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc,
- 0xf0f0fbfc, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f,
- 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010,
- 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0xfafaedee, 0x0d0cf2f3, 0xf2f30d0d, 0x1514f9fa,
- 0xeaeb0606, 0xf9fa1515, 0x0605eaeb, 0x1e1e0f0f, 0xe1e1f0f1, 0x0f0f1e1e, 0xf0f0e1e2, 0x1e1e1e1e,
- 0xe1e1e1e2, 0x22220202, 0xddddfdfe, 0x02022222, 0xfdfdddde, 0x1c1beced, 0xe3e41313, 0xeced1c1c,
- 0x1312e3e4, 0x36362020, 0xc9c9dfe0, 0x20203636, 0xdfdfc9ca, 0x2928f4f5, 0xd6d70b0b, 0xf4f52929,
- 0x0b0ad6d7, 0x37370f0f, 0xc8c8f0f1, 0x0f0f3737, 0xf0f0c8c9, 0x39393939, 0xc6c6c6c7, 0x3f3efeff,
- 0xc0c10101, 0xfeff3f3f, 0x0100c0c1, 0x2827d7d8, 0xd7d82828, 0x3736e1e2, 0xc8c91e1e, 0xe1e23737,
- 0x1e1dc8c9, 0x5e5e2525, 0xa1a1dadb, 0x25255e5e, 0xdadaa1a2, 0x60604141, 0x9f9fbebf, 0x41416060,
- 0xbebe9fa0, 0x4e4deaeb, 0xb1b21515, 0xeaeb4e4e, 0x1514b1b2, 0x64640f0f, 0x9b9bf0f1, 0x0f0f6464,
- 0xf0f09b9c, 0x6a6a6a6a, 0x95959596, 0x7473f7f8, 0x8b8c0808, 0xf7f87474, 0x08078b8c, 0x4f4ec0c1,
- 0xb0b13f3f, 0xc0c14f4f, 0x3f3eb0b1, 0x6968cccd, 0x96973333, 0xcccd6969, 0x33329697, 0x78778788,
- 0x87887878, 0x2b2b2b2b, 0xd4d4d4d5, 0x50505050, 0xafafafb0, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707,
- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9,
- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9,
- 0xf8f8f8f9, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd,
- 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0xf5f60303, 0xf5f60303, 0xf5f60303,
- 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303,
- 0xf5f60303, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a,
- 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6,
- 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6,
- 0x0302f5f6, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010,
- 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0xefefeff0, 0xefefeff0, 0xefefeff0,
- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0,
- 0xefefeff0, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505,
- 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0xededfafb, 0xededfafb, 0xededfafb,
- 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb,
- 0xededfafb, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212,
- 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212,
- 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0xfafaebec, 0x0f0ef0f1, 0xf0f10f0f, 0x1817f8f9,
- 0xe7e80707, 0xf8f91818, 0x0706e7e8, 0x23231111, 0xdcdceeef, 0x11112323, 0xeeeedcdd, 0x22222222,
- 0xddddddde, 0x26260303, 0xd9d9fcfd, 0x03032626, 0xfcfcd9da, 0x201fe9ea, 0xdfe01616, 0xe9ea2020,
- 0x1615dfe0, 0x3d3d2525, 0xc2c2dadb, 0x25253d3d, 0xdadac2c3, 0x2f2ef2f3, 0xd0d10d0d, 0xf2f32f2f,
- 0x0d0cd0d1, 0x3f3f1111, 0xc0c0eeef, 0x11113f3f, 0xeeeec0c1, 0x41414141, 0xbebebebf, 0x4847feff,
- 0xb7b80101, 0xfeff4848, 0x0100b7b8, 0x2e2dd1d2, 0xd1d22e2e, 0x3f3edcdd, 0xc0c12323, 0xdcdd3f3f,
- 0x2322c0c1, 0x6b6b2b2b, 0x9494d4d5, 0x2b2b6b6b, 0xd4d49495, 0x6e6e4b4b, 0x9191b4b5, 0x4b4b6e6e,
- 0xb4b49192, 0x5958e7e8, 0xa6a71818, 0xe7e85959, 0x1817a6a7, 0x72721111, 0x8d8deeef, 0x11117272,
- 0xeeee8d8e, 0x79797979, 0x86868687, 0x5b5ab7b8, 0xa4a54848, 0xb7b85b5b, 0x4847a4a5, 0x7877c5c6,
- 0x87883a3a, 0xc5c67878, 0x3a398788, 0x31313131, 0xcecececf, 0x5c5c5c5c, 0xa3a3a3a4, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808,
- 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0xf7f7f7f8,
- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8,
- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd,
- 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0xf4f50303,
- 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303,
- 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b,
- 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0x0302f4f5,
- 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5,
- 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212,
- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0xedededee,
- 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee,
- 0xedededee, 0xedededee, 0xedededee, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505,
- 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0xebebfafb,
- 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb,
- 0xebebfafb, 0xebebfafb, 0xebebfafb, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414,
- 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414,
- 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x1110eeef, 0xeeef1111, 0x1b1af8f9,
- 0xe4e50707, 0xf8f91b1b, 0x0706e4e5, 0x27271313, 0xd8d8eced, 0x13132727, 0xececd8d9, 0x27272727,
- 0xd8d8d8d9, 0x2b2b0303, 0xd4d4fcfd, 0x03032b2b, 0xfcfcd4d5, 0x2423e7e8, 0xdbdc1818, 0xe7e82424,
- 0x1817dbdc, 0x45452a2a, 0xbabad5d6, 0x2a2a4545, 0xd5d5babb, 0x3534f1f2, 0xcacb0e0e, 0xf1f23535,
- 0x0e0dcacb, 0x47471313, 0xb8b8eced, 0x13134747, 0xececb8b9, 0x49494949, 0xb6b6b6b7, 0x504ffdfe,
- 0xafb00202, 0xfdfe5050, 0x0201afb0, 0x3433cbcc, 0xcbcc3434, 0x4645d8d9, 0xb9ba2727, 0xd8d94646,
- 0x2726b9ba, 0x79793030, 0x8686cfd0, 0x30307979, 0xcfcf8687, 0x7c7c5454, 0x8383abac, 0x54547c7c,
- 0xabab8384, 0x6463e4e5, 0x9b9c1b1b, 0xe4e56464, 0x1b1a9b9c, 0x6665aeaf, 0x999a5151, 0xaeaf6666,
- 0x5150999a, 0x37373737, 0xc8c8c8c9, 0x68686868, 0x97979798, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909,
- 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0xf6f6f6f7,
- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7,
- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd,
- 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd,
- 0x0c0bfcfd, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303,
- 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xfcfd0c0c, 0xfcfd0c0c,
- 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c,
- 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4,
- 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606,
- 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0xe8e8f9fa,
- 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa,
- 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0x06061717, 0x06061717, 0x06061717, 0x06061717,
- 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717,
- 0x06061717, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9,
- 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404,
- 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x0403fbfc, 0xfbfc0404, 0x0605fdfe,
- 0xf9fa0202, 0xfdfe0606, 0x0201f9fa, 0x08080404, 0xf7f7fbfc, 0x04040808, 0xfbfbf7f8, 0x08080808,
- 0xf7f7f7f8, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x0807fbfc, 0xf7f80404, 0xfbfc0808,
- 0x0403f7f8, 0x0e0e0808, 0xf1f1f7f8, 0x08080e0e, 0xf7f7f1f2, 0x0c0bfdfe, 0xf3f40202, 0xfdfe0c0c,
- 0x0201f3f4, 0x10100404, 0xefeffbfc, 0x04041010, 0xfbfbeff0, 0x10101010, 0xefefeff0, 0x12120000,
- 0xedee0000, 0x00001212, 0xffffedee, 0x0c0bf3f4, 0xf3f40c0c, 0x100ff7f8, 0xeff00808, 0xf7f81010,
- 0x0807eff0, 0x1a1a0a0a, 0xe5e5f5f6, 0x0a0a1a1a, 0xf5f5e5e6, 0x1c1c1212, 0xe3e3edee, 0x12121c1c,
- 0xedede3e4, 0x1615f9fa, 0xe9ea0606, 0xf9fa1616, 0x0605e9ea, 0x1c1c0404, 0xe3e3fbfc, 0x04041c1c,
- 0xfbfbe3e4, 0x1e1e1e1e, 0xe1e1e1e2, 0x201ffdfe, 0xdfe00202, 0xfdfe2020, 0x0201dfe0, 0x1615edee,
- 0xe9ea1212, 0xedee1616, 0x1211e9ea, 0x1e1df1f2, 0xe1e20e0e, 0xf1f21e1e, 0x0e0de1e2, 0x2e2e1616,
- 0xd1d1e9ea, 0x16162e2e, 0xe9e9d1d2, 0x2e2e0c0c, 0xd1d1f3f4, 0x0c0c2e2e, 0xf3f3d1d2, 0x30302222,
- 0xcfcfddde, 0x22223030, 0xddddcfd0, 0x2827f5f6, 0xd7d80a0a, 0xf5f62828, 0x0a09d7d8, 0x32320404,
- 0xcdcdfbfc, 0x04043232, 0xfbfbcdce, 0x36363636, 0xc9c9c9ca, 0x2221ddde, 0xddde2222, 0x2a29e3e4,
- 0xd5d61c1c, 0xe3e42a2a, 0x1c1bd5d6, 0x3c3bf9fa, 0xc3c40606, 0xf9fa3c3c, 0x0605c3c4, 0x4c4c1a1a,
- 0xb3b3e5e6, 0x1a1a4c4c, 0xe5e5b3b4, 0x4c4c2a2a, 0xb3b3d5d6, 0x2a2a4c4c, 0xd5d5b3b4, 0x3635e7e8,
- 0xc9ca1818, 0xe7e83636, 0x1817c9ca, 0x4e4e0e0e, 0xb1b1f1f2, 0x0e0e4e4e, 0xf1f1b1b2, 0x52523e3e,
- 0xadadc1c2, 0x3e3e5252, 0xc1c1adae, 0x4a49ebec, 0xb5b61414, 0xebec4a4a, 0x1413b5b6, 0x58580202,
- 0xa7a7fdfe, 0x02025858, 0xfdfda7a8, 0x5c5c5c5c, 0xa3a3a3a4, 0x3c3bcbcc, 0xc3c43434, 0xcbcc3c3c,
- 0x3433c3c4, 0x76763434, 0x8989cbcc, 0x34347676, 0xcbcb898a, 0x4a49d3d4, 0xb5b62c2c, 0xd3d44a4a,
- 0x2c2bb5b6, 0x76764a4a, 0x8989b5b6, 0x4a4a7676, 0xb5b5898a, 0x76762020, 0x8989dfe0, 0x20207676,
- 0xdfdf898a, 0x6665f3f4, 0x999a0c0c, 0xf3f46666, 0x0c0b999a, 0x605fd7d8, 0x9fa02828, 0xd7d86060,
- 0x28279fa0, 0x7675ddde, 0x898a2222, 0xddde7676, 0x2221898a, 0x5857a7a8, 0xa7a85858, 0x6867b1b2,
- 0x97984e4e, 0xb1b26868, 0x4e4d9798, 0x0c0c0c0c, 0xf3f3f3f4, 0x16161616, 0xe9e9e9ea, 0x2a2a2a2a,
- 0xd5d5d5d6, 0x48484848, 0xb7b7b7b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0xfdfe0000,
- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202,
- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe,
- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606,
- 0xf9f9f9fa, 0x09090303, 0xf6f6fcfd, 0x03030909, 0xfcfcf6f7, 0x0908fcfd, 0xf6f70303, 0xfcfd0909,
- 0x0302f6f7, 0x0605f9fa, 0xf9fa0606, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0xf9f9f3f4, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x0f0f0000, 0xf0f10000, 0x00000f0f, 0xfffff0f1, 0x0c0bf6f7, 0xf3f40909, 0xf6f70c0c,
- 0x0908f3f4, 0x18180f0f, 0xe7e7f0f1, 0x0f0f1818, 0xf0f0e7e8, 0x1211f9fa, 0xedee0606, 0xf9fa1212,
- 0x0605edee, 0x18180606, 0xe7e7f9fa, 0x06061818, 0xf9f9e7e8, 0x18181818, 0xe7e7e7e8, 0x1b1b0000,
- 0xe4e50000, 0x00001b1b, 0xffffe4e5, 0x1211edee, 0xedee1212, 0x1817f3f4, 0xe7e80c0c, 0xf3f41818,
- 0x0c0be7e8, 0x27270f0f, 0xd8d8f0f1, 0x0f0f2727, 0xf0f0d8d9, 0x2a2a1b1b, 0xd5d5e4e5, 0x1b1b2a2a,
- 0xe4e4d5d6, 0x2120f6f7, 0xdedf0909, 0xf6f72121, 0x0908dedf, 0x2a2a0606, 0xd5d5f9fa, 0x06062a2a,
- 0xf9f9d5d6, 0x2d2d2d2d, 0xd2d2d2d3, 0x3332fcfd, 0xcccd0303, 0xfcfd3333, 0x0302cccd, 0x2120e4e5,
- 0xdedf1b1b, 0xe4e52121, 0x1b1adedf, 0x2d2ceaeb, 0xd2d31515, 0xeaeb2d2d, 0x1514d2d3, 0x45452121,
- 0xbabadedf, 0x21214545, 0xdedebabb, 0x45451212, 0xbabaedee, 0x12124545, 0xededbabb, 0x48483636,
- 0xb7b7c9ca, 0x36364848, 0xc9c9b7b8, 0x3f3eedee, 0xc0c11212, 0xedee3f3f, 0x1211c0c1, 0x4e4e0606,
- 0xb1b1f9fa, 0x06064e4e, 0xf9f9b1b2, 0x51515151, 0xaeaeaeaf, 0x3332cccd, 0xcccd3333, 0x3f3ed5d6,
- 0xc0c12a2a, 0xd5d63f3f, 0x2a29c0c1, 0x5a59f6f7, 0xa5a60909, 0xf6f75a5a, 0x0908a5a6, 0x72722a2a,
- 0x8d8dd5d6, 0x2a2a7272, 0xd5d58d8e, 0x75753f3f, 0x8a8ac0c1, 0x3f3f7575, 0xc0c08a8b, 0x5150dbdc,
- 0xaeaf2424, 0xdbdc5151, 0x2423aeaf, 0x78781515, 0x8787eaeb, 0x15157878, 0xeaea8788, 0x7b7b6060,
- 0x84849fa0, 0x60607b7b, 0x9f9f8485, 0x6f6ee1e2, 0x90911e1e, 0xe1e26f6f, 0x1e1d9091, 0x5d5cb1b2,
- 0xa2a34e4e, 0xb1b25d5d, 0x4e4da2a3, 0x7271babb, 0x8d8e4545, 0xbabb7272, 0x45448d8e, 0x12121212,
- 0xedededee, 0x21212121, 0xdedededf, 0x3f3f3f3f, 0xc0c0c0c1, 0x6c6c6c6c, 0x93939394, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303,
- 0x03030303, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd,
- 0xfcfcfcfd, 0xfcfcfcfd, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000,
- 0x03030000, 0x03030000, 0x03030000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000,
- 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0x00000303, 0x00000303, 0x00000303, 0x00000303,
- 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd,
- 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404,
- 0xf7f7fbfc, 0x04040808, 0xfbfbf7f8, 0x08080808, 0xf7f7f7f8, 0x0807f7f8, 0xf7f80808, 0x0c0bfbfc,
- 0xf3f40404, 0xfbfc0c0c, 0x0403f3f4, 0x10100808, 0xefeff7f8, 0x08081010, 0xf7f7eff0, 0x10101010,
- 0xefefeff0, 0x14140000, 0xebec0000, 0x00001414, 0xffffebec, 0x100ff3f4, 0xeff00c0c, 0xf3f41010,
- 0x0c0beff0, 0x1817fbfc, 0xe7e80404, 0xfbfc1818, 0x0403e7e8, 0x20201010, 0xdfdfeff0, 0x10102020,
- 0xefefdfe0, 0x20200808, 0xdfdff7f8, 0x08082020, 0xf7f7dfe0, 0x20202020, 0xdfdfdfe0, 0x24240000,
- 0xdbdc0000, 0x00002424, 0xffffdbdc, 0x1817e7e8, 0xe7e81818, 0x201feff0, 0xdfe01010, 0xeff02020,
- 0x100fdfe0, 0x34341414, 0xcbcbebec, 0x14143434, 0xebebcbcc, 0x38382424, 0xc7c7dbdc, 0x24243838,
- 0xdbdbc7c8, 0x2c2bf3f4, 0xd3d40c0c, 0xf3f42c2c, 0x0c0bd3d4, 0x38380808, 0xc7c7f7f8, 0x08083838,
- 0xf7f7c7c8, 0x3c3c3c3c, 0xc3c3c3c4, 0x403ffbfc, 0xbfc00404, 0xfbfc4040, 0x0403bfc0, 0x2c2bdbdc,
- 0xd3d42424, 0xdbdc2c2c, 0x2423d3d4, 0x3c3be3e4, 0xc3c41c1c, 0xe3e43c3c, 0x1c1bc3c4, 0x5c5c2c2c,
- 0xa3a3d3d4, 0x2c2c5c5c, 0xd3d3a3a4, 0x5c5c1818, 0xa3a3e7e8, 0x18185c5c, 0xe7e7a3a4, 0x60604848,
- 0x9f9fb7b8, 0x48486060, 0xb7b79fa0, 0x5453ebec, 0xabac1414, 0xebec5454, 0x1413abac, 0x64640808,
- 0x9b9bf7f8, 0x08086464, 0xf7f79b9c, 0x6c6c6c6c, 0x93939394, 0x4443bbbc, 0xbbbc4444, 0x5453c7c8,
- 0xabac3838, 0xc7c85454, 0x3837abac, 0x7877f3f4, 0x87880c0c, 0xf3f47878, 0x0c0b8788, 0x6c6bcfd0,
- 0x93943030, 0xcfd06c6c, 0x302f9394, 0x7c7b9798, 0x83846868, 0x97987c7c, 0x68678384, 0x18181818,
- 0xe7e7e7e8, 0x2c2c2c2c, 0xd3d3d3d4, 0x54545454, 0xabababac, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040404,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404,
- 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000,
- 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000,
- 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0x00000404,
- 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404,
- 0x00000404, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc,
- 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0x08080404,
- 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc,
- 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0x04040808,
- 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808,
- 0x04040808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a,
- 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x05050f0f, 0xfafaf0f1, 0x0a09f5f6, 0xf5f60a0a, 0x0f0efafb,
- 0xf0f10505, 0xfafb0f0f, 0x0504f0f1, 0x14140a0a, 0xebebf5f6, 0x0a0a1414, 0xf5f5ebec, 0x14141414,
- 0xebebebec, 0x19190000, 0xe6e70000, 0x00001919, 0xffffe6e7, 0x1413f0f1, 0xebec0f0f, 0xf0f11414,
- 0x0f0eebec, 0x28281919, 0xd7d7e6e7, 0x19192828, 0xe6e6d7d8, 0x1e1df5f6, 0xe1e20a0a, 0xf5f61e1e,
- 0x0a09e1e2, 0x28280a0a, 0xd7d7f5f6, 0x0a0a2828, 0xf5f5d7d8, 0x28282828, 0xd7d7d7d8, 0x2d2d0000,
- 0xd2d30000, 0x00002d2d, 0xffffd2d3, 0x1e1de1e2, 0xe1e21e1e, 0x2827ebec, 0xd7d81414, 0xebec2828,
- 0x1413d7d8, 0x41411919, 0xbebee6e7, 0x19194141, 0xe6e6bebf, 0x46462d2d, 0xb9b9d2d3, 0x2d2d4646,
- 0xd2d2b9ba, 0x3736f0f1, 0xc8c90f0f, 0xf0f13737, 0x0f0ec8c9, 0x46460a0a, 0xb9b9f5f6, 0x0a0a4646,
- 0xf5f5b9ba, 0x4b4b4b4b, 0xb4b4b4b5, 0x5554fafb, 0xaaab0505, 0xfafb5555, 0x0504aaab, 0x3736d2d3,
- 0xc8c92d2d, 0xd2d33737, 0x2d2cc8c9, 0x4b4adcdd, 0xb4b52323, 0xdcdd4b4b, 0x2322b4b5, 0x73733737,
- 0x8c8cc8c9, 0x37377373, 0xc8c88c8d, 0x73731e1e, 0x8c8ce1e2, 0x1e1e7373, 0xe1e18c8d, 0x78785a5a,
- 0x8787a5a6, 0x5a5a7878, 0xa5a58788, 0x6968e1e2, 0x96971e1e, 0xe1e26969, 0x1e1d9697, 0x5554aaab,
- 0xaaab5555, 0x6968b9ba, 0x96974646, 0xb9ba6969, 0x46459697, 0x1e1e1e1e, 0xe1e1e1e2, 0x3c3c3c3c,
- 0xc3c3c3c4, 0x69696969, 0x96969697, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x05050505, 0x05050505,
- 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505,
- 0x05050505, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb,
- 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0x05050000, 0x05050000, 0x05050000, 0x05050000,
- 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0xfafb0000,
- 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000,
- 0xfafb0000, 0xfafb0000, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505,
- 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0xfffffafb, 0xfffffafb, 0xfffffafb,
- 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb,
- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a,
- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6,
- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0x0f0f0505, 0x0f0f0505,
- 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505,
- 0x0f0f0505, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb,
- 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0xf9f9f3f4, 0x0c0bf3f4, 0xf3f40c0c, 0x1211f9fa,
- 0xedee0606, 0xf9fa1212, 0x0605edee, 0x18180c0c, 0xe7e7f3f4, 0x0c0c1818, 0xf3f3e7e8, 0x18181818,
- 0xe7e7e7e8, 0x1e1e0000, 0xe1e20000, 0x00001e1e, 0xffffe1e2, 0x1817edee, 0xe7e81212, 0xedee1818,
- 0x1211e7e8, 0x30301e1e, 0xcfcfe1e2, 0x1e1e3030, 0xe1e1cfd0, 0x2423f9fa, 0xdbdc0606, 0xf9fa2424,
- 0x0605dbdc, 0x30300c0c, 0xcfcff3f4, 0x0c0c3030, 0xf3f3cfd0, 0x30303030, 0xcfcfcfd0, 0x36360000,
- 0xc9ca0000, 0x00003636, 0xffffc9ca, 0x2423dbdc, 0xdbdc2424, 0x302fe7e8, 0xcfd01818, 0xe7e83030,
- 0x1817cfd0, 0x4e4e1e1e, 0xb1b1e1e2, 0x1e1e4e4e, 0xe1e1b1b2, 0x54543636, 0xababc9ca, 0x36365454,
- 0xc9c9abac, 0x4241edee, 0xbdbe1212, 0xedee4242, 0x1211bdbe, 0x54540c0c, 0xababf3f4, 0x0c0c5454,
- 0xf3f3abac, 0x5a5a5a5a, 0xa5a5a5a6, 0x605ff9fa, 0x9fa00606, 0xf9fa6060, 0x06059fa0, 0x4241c9ca,
- 0xbdbe3636, 0xc9ca4242, 0x3635bdbe, 0x5a59d5d6, 0xa5a62a2a, 0xd5d65a5a, 0x2a29a5a6, 0x7e7de1e2,
- 0x81821e1e, 0xe1e27e7e, 0x1e1d8182, 0x6665999a, 0x999a6666, 0x7e7dabac, 0x81825454, 0xabac7e7e,
- 0x54538182, 0x24242424, 0xdbdbdbdc, 0x42424242, 0xbdbdbdbe, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000,
- 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000,
- 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000,
- 0xf9fa0000, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606,
- 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa,
- 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa,
- 0xfffff9fa, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606,
- 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa,
- 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa,
- 0xf3f3f9fa, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c,
- 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e,
- 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0xf8f8eaeb, 0x0e0df1f2, 0xf1f20e0e, 0x1514f8f9,
- 0xeaeb0707, 0xf8f91515, 0x0706eaeb, 0x1c1c0e0e, 0xe3e3f1f2, 0x0e0e1c1c, 0xf1f1e3e4, 0x1c1c1c1c,
- 0xe3e3e3e4, 0x23230000, 0xdcdd0000, 0x00002323, 0xffffdcdd, 0x1c1beaeb, 0xe3e41515, 0xeaeb1c1c,
- 0x1514e3e4, 0x38382323, 0xc7c7dcdd, 0x23233838, 0xdcdcc7c8, 0x2a29f1f2, 0xd5d60e0e, 0xf1f22a2a,
- 0x0e0dd5d6, 0x38380e0e, 0xc7c7f1f2, 0x0e0e3838, 0xf1f1c7c8, 0x38383838, 0xc7c7c7c8, 0x3f3f0000,
- 0xc0c10000, 0x00003f3f, 0xffffc0c1, 0x2a29d5d6, 0xd5d62a2a, 0x3837e3e4, 0xc7c81c1c, 0xe3e43838,
- 0x1c1bc7c8, 0x5b5b2323, 0xa4a4dcdd, 0x23235b5b, 0xdcdca4a5, 0x62623f3f, 0x9d9dc0c1, 0x3f3f6262,
- 0xc0c09d9e, 0x4d4ceaeb, 0xb2b31515, 0xeaeb4d4d, 0x1514b2b3, 0x62620e0e, 0x9d9df1f2, 0x0e0e6262,
- 0xf1f19d9e, 0x69696969, 0x96969697, 0x7776f8f9, 0x88890707, 0xf8f97777, 0x07068889, 0x4d4cc0c1,
- 0xb2b33f3f, 0xc0c14d4d, 0x3f3eb2b3, 0x6968cecf, 0x96973131, 0xcecf6969, 0x31309697, 0x77768889,
- 0x88897777, 0x2a2a2a2a, 0xd5d5d5d6, 0x4d4d4d4d, 0xb2b2b2b3, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707,
- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9,
- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9,
- 0xf8f8f8f9, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000,
- 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0xf8f90000, 0xf8f90000, 0xf8f90000,
- 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000,
- 0xf8f90000, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707,
- 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9,
- 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9,
- 0xfffff8f9, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e,
- 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2,
- 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2,
- 0xf1f1f1f2, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707,
- 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9,
- 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9,
- 0xeaeaf8f9, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515,
- 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010,
- 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0xf7f7eff0, 0x100feff0, 0xeff01010, 0x1817f7f8,
- 0xe7e80808, 0xf7f81818, 0x0807e7e8, 0x20201010, 0xdfdfeff0, 0x10102020, 0xefefdfe0, 0x20202020,
- 0xdfdfdfe0, 0x28280000, 0xd7d80000, 0x00002828, 0xffffd7d8, 0x201fe7e8, 0xdfe01818, 0xe7e82020,
- 0x1817dfe0, 0x40402828, 0xbfbfd7d8, 0x28284040, 0xd7d7bfc0, 0x302feff0, 0xcfd01010, 0xeff03030,
- 0x100fcfd0, 0x40401010, 0xbfbfeff0, 0x10104040, 0xefefbfc0, 0x40404040, 0xbfbfbfc0, 0x48480000,
- 0xb7b80000, 0x00004848, 0xffffb7b8, 0x302fcfd0, 0xcfd03030, 0x403fdfe0, 0xbfc02020, 0xdfe04040,
- 0x201fbfc0, 0x68682828, 0x9797d7d8, 0x28286868, 0xd7d79798, 0x70704848, 0x8f8fb7b8, 0x48487070,
- 0xb7b78f90, 0x5857e7e8, 0xa7a81818, 0xe7e85858, 0x1817a7a8, 0x70701010, 0x8f8feff0, 0x10107070,
- 0xefef8f90, 0x78787878, 0x87878788, 0x5857b7b8, 0xa7a84848, 0xb7b85858, 0x4847a7a8, 0x7877c7c8,
- 0x87883838, 0xc7c87878, 0x38378788, 0x30303030, 0xcfcfcfd0, 0x58585858, 0xa7a7a7a8, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808,
- 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0xf7f7f7f8,
- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8,
- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000,
- 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0xf7f80000,
- 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000,
- 0xf7f80000, 0xf7f80000, 0xf7f80000, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808,
- 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0xfffff7f8,
- 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8,
- 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010,
- 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0xefefeff0,
- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0,
- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808,
- 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0xefeff7f8,
- 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8,
- 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010,
- 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212,
- 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x1211edee, 0xedee1212, 0x1b1af6f7,
- 0xe4e50909, 0xf6f71b1b, 0x0908e4e5, 0x24241212, 0xdbdbedee, 0x12122424, 0xededdbdc, 0x24242424,
- 0xdbdbdbdc, 0x2d2d0000, 0xd2d30000, 0x00002d2d, 0xffffd2d3, 0x2423e4e5, 0xdbdc1b1b, 0xe4e52424,
- 0x1b1adbdc, 0x48482d2d, 0xb7b7d2d3, 0x2d2d4848, 0xd2d2b7b8, 0x3635edee, 0xc9ca1212, 0xedee3636,
- 0x1211c9ca, 0x48481212, 0xb7b7edee, 0x12124848, 0xededb7b8, 0x48484848, 0xb7b7b7b8, 0x51510000,
- 0xaeaf0000, 0x00005151, 0xffffaeaf, 0x3635c9ca, 0xc9ca3636, 0x4847dbdc, 0xb7b82424, 0xdbdc4848,
- 0x2423b7b8, 0x75752d2d, 0x8a8ad2d3, 0x2d2d7575, 0xd2d28a8b, 0x7e7e5151, 0x8181aeaf, 0x51517e7e,
- 0xaeae8182, 0x6362e4e5, 0x9c9d1b1b, 0xe4e56363, 0x1b1a9c9d, 0x6362aeaf, 0x9c9d5151, 0xaeaf6363,
- 0x51509c9d, 0x36363636, 0xc9c9c9ca, 0x6c6c6c6c, 0x93939394, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909,
- 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0xf6f6f6f7,
- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7,
- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0x09090000, 0x09090000, 0x09090000, 0x09090000,
- 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000,
- 0x09090000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000,
- 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0x00000909, 0x00000909,
- 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909,
- 0x00000909, 0x00000909, 0x00000909, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7,
- 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7,
- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212,
- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0xedededee, 0xedededee, 0xedededee,
- 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee,
- 0xedededee, 0xedededee, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909,
- 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0xe4e4f6f7,
- 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7,
- 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b,
- 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b,
- 0x09091b1b, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5,
- 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606,
- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0504fafb, 0xfafb0505, 0xfafb0505,
- 0x0504fafb, 0x0b0b0606, 0xf4f4f9fa, 0x06060b0b, 0xf9f9f4f5, 0x08080000, 0xf7f80000, 0x00000808,
- 0xfffff7f8, 0x0b0b0b0b, 0xf4f4f4f5, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x11110c0c,
- 0xeeeef3f4, 0x0c0c1111, 0xf3f3eeef, 0x11111111, 0xeeeeeeef, 0x12120606, 0xededf9fa, 0x06061212,
- 0xf9f9edee, 0x0b0af7f8, 0xf4f50808, 0xf7f80b0b, 0x0807f4f5, 0x0f0f0000, 0xf0f10000, 0x00000f0f,
- 0xfffff0f1, 0x14140000, 0xebec0000, 0x00001414, 0xffffebec, 0x19191212, 0xe6e6edee, 0x12121919,
- 0xedede6e7, 0x19190b0b, 0xe6e6f4f5, 0x0b0b1919, 0xf4f4e6e7, 0x19191919, 0xe6e6e6e7, 0x0e0df1f2,
- 0xf1f20e0e, 0xf1f20e0e, 0x0e0df1f2, 0x1a1a0000, 0xe5e60000, 0x00001a1a, 0xffffe5e6, 0x1211f4f5,
- 0xedee0b0b, 0xf4f51212, 0x0b0aedee, 0x1615f8f9, 0xe9ea0707, 0xf8f91616, 0x0706e9ea, 0x22221a1a,
- 0xdddde5e6, 0x1a1a2222, 0xe5e5ddde, 0x22221212, 0xddddedee, 0x12122222, 0xededddde, 0x22222222,
- 0xddddddde, 0x23230b0b, 0xdcdcf4f5, 0x0b0b2323, 0xf4f4dcdd, 0x1d1d0000, 0xe2e30000, 0x00001d1d,
- 0xffffe2e3, 0x1615eced, 0xe9ea1313, 0xeced1616, 0x1312e9ea, 0x1a19f0f1, 0xe5e60f0f, 0xf0f11a1a,
- 0x0f0ee5e6, 0x25250000, 0xdadb0000, 0x00002525, 0xffffdadb, 0x2c2c1b1b, 0xd3d3e4e5, 0x1b1b2c2c,
- 0xe4e4d3d4, 0x2c2c2424, 0xd3d3dbdc, 0x24242c2c, 0xdbdbd3d4, 0x2c2c1212, 0xd3d3edee, 0x12122c2c,
- 0xededd3d4, 0x2120f5f6, 0xdedf0a0a, 0xf5f62121, 0x0a09dedf, 0x2d2d2d2d, 0xd2d2d2d3, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606,
- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000,
- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000,
- 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd,
- 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000,
- 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa,
- 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303,
- 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606,
- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000,
- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000,
- 0xf8f90000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0403fbfc, 0xfbfc0404, 0xf9fa0a0a,
- 0x0605f5f6, 0xf3f40000, 0x0c0c0000, 0xf3f3f9fa, 0xf3f40606, 0x0c0bf9fa, 0x0c0c0606, 0xfffff1f2,
- 0x00000e0e, 0x0c0c0c0c, 0xf3f3f3f4, 0xedee0000, 0x12120000, 0xf3f40e0e, 0x0c0bf1f2, 0xf9f9edee,
- 0xf9fa1212, 0x0605edee, 0x06061212, 0xededf5f6, 0xedee0a0a, 0x1211f5f6, 0x12120a0a, 0xffffe9ea,
- 0x00001616, 0xe7e80000, 0x18180000, 0xf3f3e9ea, 0xf3f41616, 0x0c0be9ea, 0x0c0c1616, 0xe7e7f7f8,
- 0xe7e80808, 0x1817f7f8, 0x18180808, 0xf9f9e5e6, 0xf9fa1a1a, 0x0605e5e6, 0x06061a1a, 0xffffe3e4,
- 0x00001c1c, 0x14141414, 0xebebebec, 0xe5e5f1f2, 0x1a1a0e0e, 0xf3f3e1e2, 0x0c0c1e1e, 0xdfdff5f6,
- 0x20200a0a, 0xdfdfedee, 0x20201212, 0xe5e5e5e6, 0x1a1a1a1a, 0xebebddde, 0x14142222, 0xf3f3d9da,
- 0x0c0c2626, 0xdfdfdfe0, 0x20202020, 0x20202020, 0xd7d7e9ea, 0xddddddde, 0x22222222, 0x00000000,
- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202,
- 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606,
- 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000,
- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000,
- 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000,
- 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000,
- 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000,
- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202,
- 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606,
- 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000,
- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000,
- 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a,
- 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x0605f9fa, 0xf9fa0606, 0xf7f80e0e,
- 0x0807f1f2, 0xffffedee, 0x00001212, 0xeff00a0a, 0x100ff5f6, 0xe7e80000, 0x18180000, 0xf7f7e7e8,
- 0xf7f81818, 0x0807e7e8, 0x08081818, 0x12121212, 0xedededee, 0xeff01414, 0x100febec, 0xe5e5f1f2,
- 0xe5e60e0e, 0x1a19f1f2, 0x1a1a0e0e, 0xffffe1e2, 0x00001e1e, 0xddde0000, 0x22220000, 0xf7f7ddde,
- 0xf7f82222, 0x0807ddde, 0x08082222, 0xedede1e2, 0xedee1e1e, 0x1211e1e2, 0x12121e1e, 0xddddf5f6,
- 0xddde0a0a, 0x2221f5f6, 0x22220a0a, 0xddddebec, 0x22221414, 0xffffd7d8, 0x00002828, 0x1e1e1e1e,
- 0xe1e1e1e2, 0xededd7d8, 0x12122828, 0xd3d40000, 0x2c2c0000, 0xd3d3eff0, 0x2c2c1010, 0xdbdbdbdc,
- 0xdbdbdbdc, 0x24242424, 0xd3d3e5e6, 0x2c2c1a1a, 0xe5e5d1d2, 0x1a1a2e2e, 0xededcbcc, 0x12123434,
- 0xc9c9ebec, 0xd3d3d3d4, 0x2c2c2c2c, 0xc9c9dfe0, 0xd1d1d1d2, 0xd1d1d1d2, 0x2e2e2e2e, 0x00000000,
- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6,
- 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202,
- 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a,
- 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc,
- 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000,
- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000,
- 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe,
- 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6,
- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a,
- 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000,
- 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000,
- 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404,
- 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000,
- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6,
- 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202,
- 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a,
- 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc,
- 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000,
- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000,
- 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe,
- 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x0807f7f8, 0xf7f80808, 0xeff00808,
- 0x100ff7f8, 0xe7e80000, 0x18180000, 0xf7f7e7e8, 0xf7f81818, 0x0807e7e8, 0x08081818, 0xeff01414,
- 0x100febec, 0xffffe3e4, 0x00001c1c, 0xe7e7eff0, 0xe7e81010, 0x1817eff0, 0x18181010, 0xdfe00000,
- 0x20200000, 0xefefe3e4, 0xeff01c1c, 0x100fe3e4, 0x10101c1c, 0xdfdff7f8, 0xdfe00808, 0xf7f7dfe0,
- 0xf7f82020, 0x0807dfe0, 0x08082020, 0x201ff7f8, 0x20200808, 0x18181818, 0xe7e7e7e8, 0xe7e81818,
- 0x1817e7e8, 0xdfdfebec, 0x20201414, 0xffffd7d8, 0x00002828, 0xefefd7d8, 0x10102828, 0xd3d40000,
- 0xd3d40000, 0xffffd3d4, 0x00002c2c, 0x2c2c0000, 0x2c2c0000, 0xdfdfdfe0, 0x20202020, 0xd3d3eff0,
- 0x2c2c1010, 0xd3d3e7e8, 0xe7e7d3d4, 0x18182c2c, 0x2c2c1818, 0xefefcfd0, 0x10103030, 0xdbdbdbdc,
- 0xdbdbdbdc, 0x24242424, 0x24242424, 0xcbcbebec, 0x28282828, 0xd7d7d7d8, 0xcbcbdfe0, 0x00000000,
- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404,
- 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c,
- 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000,
- 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000,
- 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc,
- 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4,
- 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000,
- 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000,
- 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404,
- 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000,
- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404,
- 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c,
- 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000,
- 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000,
- 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc,
- 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0,
- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0,
- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0,
- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414,
- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0,
- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c,
- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec,
- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606,
- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e,
- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4,
- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020,
- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
-};
-
-
-static const uint32_t correctionhighorder[] = {
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101,
- 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303,
- 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9,
- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707,
- 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc,
- 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404,
- 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101,
- 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff,
- 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd,
- 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303,
- 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000,
- 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd,
- 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb,
- 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101,
- 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd,
- 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb,
- 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101,
- 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd,
- 0x03030a0a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202,
- 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505,
- 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303,
- 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9,
- 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe,
- 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000,
- 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5,
- 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707,
- 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb,
- 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd,
- 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b,
- 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202,
- 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505,
- 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303,
- 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9,
- 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc,
- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8,
- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb,
- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6,
- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee,
- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303,
- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x09090909, 0xf6f6f6f7,
- 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa,
- 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c,
- 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000,
- 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec,
- 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd,
- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717,
- 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4,
- 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909,
- 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606,
- 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303,
- 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9,
- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414,
- 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7,
- 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa,
- 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c,
- 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000,
- 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec,
- 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd,
- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717,
- 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4,
- 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000,
- 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202,
- 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe,
- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000,
- 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202,
- 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe,
- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa,
- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606,
- 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd,
- 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303,
- 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000,
- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000,
- 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd,
- 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303,
- 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000,
- 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc,
- 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc,
- 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000,
- 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc,
- 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc,
- 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000,
- 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc,
- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000,
- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc,
- 0x04040808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000,
- 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505,
- 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505,
- 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb,
- 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000,
- 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000,
- 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6,
- 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505,
- 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb,
- 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb,
- 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a,
- 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000,
- 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505,
- 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505,
- 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb,
- 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa,
- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa,
- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa,
- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9,
- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9,
- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9,
- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0,
- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000,
- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x09090909, 0xf6f6f6f7,
- 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7,
- 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909,
- 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000,
- 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee,
- 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000,
- 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b,
- 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7,
- 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909,
- 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909,
- 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000,
- 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5,
- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212,
- 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7,
- 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7,
- 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909,
- 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000,
- 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee,
- 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000,
- 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b,
- 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7,
- 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000,
- 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000,
- 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0x00000303,
- 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303,
- 0x00000303, 0x00000303, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd,
- 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000,
- 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0xf8f90000, 0xf8f90000,
- 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000,
- 0xf8f90000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020000, 0x02020000, 0x02020000, 0x02020000,
- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000,
- 0x02020000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000,
- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202,
- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202,
- 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe,
- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0x06060000, 0x06060000, 0x06060000, 0x06060000,
- 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000,
- 0x06060000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000,
- 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0x00000606, 0x00000606,
- 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606,
- 0x00000606, 0x00000606, 0x00000606, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa,
- 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020000, 0x02020000, 0x02020000, 0x02020000,
- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000,
- 0x02020000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000,
- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202,
- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202,
- 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe,
- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a,
- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0xf5f5f5f6,
- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6,
- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000,
- 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000,
- 0x0a0a0000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000,
- 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0x00000a0a, 0x00000a0a,
- 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a,
- 0x00000a0a, 0x00000a0a, 0x00000a0a, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6,
- 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040000, 0x04040000, 0x04040000, 0x04040000,
- 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000,
- 0x04040000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000,
- 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0x00000404, 0x00000404,
- 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404,
- 0x00000404, 0x00000404, 0x00000404, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc,
- 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404,
- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc,
- 0xfbfbfbfc, 0xfbfbfbfc, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000,
- 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000,
- 0x0c0c0000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000,
- 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0x00000c0c, 0x00000c0c,
- 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c,
- 0x00000c0c, 0x00000c0c, 0x00000c0c, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4,
- 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0,
- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0,
- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0,
- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef,
- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202,
- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe,
- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606,
- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c,
- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4,
- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414,
- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec,
- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0,
- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e,
- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2,
- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000
-};
+++ /dev/null
-/*
- * Interplay MVE Video Decoder
- * Copyright (C) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file interplayvideo.c
- * Interplay MVE Video Decoder by Mike Melanson (melanson@pcisys.net)
- * For more information about the Interplay MVE format, visit:
- * http://www.pcisys.net/~melanson/codecs/interplay-mve.txt
- * This code is written in such a way that the identifiers match up
- * with the encoding descriptions in the document.
- *
- * This decoder presently only supports a PAL8 output colorspace.
- *
- * An Interplay video frame consists of 2 parts: The decoding map and
- * the video data. A demuxer must load these 2 parts together in a single
- * buffer before sending it through the stream to this decoder.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#define PALETTE_COUNT 256
-
-/* debugging support */
-#define DEBUG_INTERPLAY 0
-#if DEBUG_INTERPLAY
-#define debug_interplay printf
-#else
-static inline void debug_interplay(const char *format, ...) { }
-#endif
-
-typedef struct IpvideoContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame second_last_frame;
- AVFrame last_frame;
- AVFrame current_frame;
- unsigned char *decoding_map;
- int decoding_map_size;
-
- unsigned char *buf;
- int size;
-
- unsigned char palette[PALETTE_COUNT * 4];
-
- unsigned char *stream_ptr;
- unsigned char *stream_end;
- unsigned char *pixel_ptr;
- int line_inc;
- int stride;
- int upper_motion_limit_offset;
-
-} IpvideoContext;
-
-#define CHECK_STREAM_PTR(n) \
- if ((s->stream_ptr + n) > s->stream_end) { \
- printf ("Interplay video warning: stream_ptr out of bounds (%p >= %p)\n", \
- s->stream_ptr + n, s->stream_end); \
- return -1; \
- }
-
-static void ipvideo_new_palette(IpvideoContext *s, unsigned char *palette) {
-
- int i;
- unsigned char r, g, b;
- unsigned int *palette32;
-
- palette32 = (unsigned int *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette++;
- g = *palette++;
- b = *palette++;
- palette32[i] = (r << 16) | (g << 8) | (b);
- }
-}
-
-#define COPY_FROM_CURRENT() \
- motion_offset = current_offset; \
- motion_offset += y * s->stride; \
- motion_offset += x; \
- if (motion_offset < 0) { \
- printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \
- return -1; \
- } else if (motion_offset > s->upper_motion_limit_offset) { \
- printf (" Interplay video: motion offset above limit (%d >= %d)\n", \
- motion_offset, s->upper_motion_limit_offset); \
- return -1; \
- } \
- s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
- s->current_frame.data[0] + motion_offset, s->stride, 8);
-
-#define COPY_FROM_PREVIOUS() \
- motion_offset = current_offset; \
- motion_offset += y * s->stride; \
- motion_offset += x; \
- if (motion_offset < 0) { \
- printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \
- return -1; \
- } else if (motion_offset > s->upper_motion_limit_offset) { \
- printf (" Interplay video: motion offset above limit (%d >= %d)\n", \
- motion_offset, s->upper_motion_limit_offset); \
- return -1; \
- } \
- s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
- s->last_frame.data[0] + motion_offset, s->stride, 8);
-
-#define COPY_FROM_SECOND_LAST() \
- motion_offset = current_offset; \
- motion_offset += y * s->stride; \
- motion_offset += x; \
- if (motion_offset < 0) { \
- printf (" Interplay video: motion offset < 0 (%d)\n", motion_offset); \
- return -1; \
- } else if (motion_offset > s->upper_motion_limit_offset) { \
- printf (" Interplay video: motion offset above limit (%d >= %d)\n", \
- motion_offset, s->upper_motion_limit_offset); \
- return -1; \
- } \
- s->dsp.put_pixels_tab[0][0](s->pixel_ptr, \
- s->second_last_frame.data[0] + motion_offset, s->stride, 8);
-
-static int ipvideo_decode_block_opcode_0x0(IpvideoContext *s)
-{
- int x, y;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy a block from the previous frame */
- x = y = 0;
- COPY_FROM_PREVIOUS();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x1(IpvideoContext *s)
-{
- int x, y;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy block from 2 frames ago */
- x = y = 0;
- COPY_FROM_SECOND_LAST();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x2(IpvideoContext *s)
-{
- unsigned char B;
- int x, y;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy block from 2 frames ago using a motion vector; need 1 more byte */
- CHECK_STREAM_PTR(1);
- B = *s->stream_ptr++;
-
- if (B < 56) {
- x = 8 + (B % 7);
- y = B / 7;
- } else {
- x = -14 + ((B - 56) % 29);
- y = 8 + ((B - 56) / 29);
- }
-
- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
- COPY_FROM_SECOND_LAST();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x3(IpvideoContext *s)
-{
- unsigned char B;
- int x, y;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy 8x8 block from current frame from an up/left block */
-
- /* need 1 more byte for motion */
- CHECK_STREAM_PTR(1);
- B = *s->stream_ptr++;
-
- if (B < 56) {
- x = -(8 + (B % 7));
- y = -(B / 7);
- } else {
- x = -(-14 + ((B - 56) % 29));
- y = -( 8 + ((B - 56) / 29));
- }
-
- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
- COPY_FROM_CURRENT();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x4(IpvideoContext *s)
-{
- int x, y;
- unsigned char B, BL, BH;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy a block from the previous frame; need 1 more byte */
- CHECK_STREAM_PTR(1);
-
- B = *s->stream_ptr++;
- BL = B & 0x0F;
- BH = (B >> 4) & 0x0F;
- x = -8 + BL;
- y = -8 + BH;
-
- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y);
- COPY_FROM_PREVIOUS();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x5(IpvideoContext *s)
-{
- signed char x, y;
- int motion_offset;
- int current_offset = s->pixel_ptr - s->current_frame.data[0];
-
- /* copy a block from the previous frame using an expanded range;
- * need 2 more bytes */
- CHECK_STREAM_PTR(2);
-
- x = *s->stream_ptr++;
- y = *s->stream_ptr++;
-
- debug_interplay (" motion bytes = %d, %d\n", x, y);
- COPY_FROM_PREVIOUS();
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x6(IpvideoContext *s)
-{
- /* mystery opcode? skip multiple blocks? */
- printf (" Interplay video: Help! Mystery opcode 0x6 seen\n");
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s)
-{
- int x, y;
- unsigned char P0, P1;
- unsigned char B[8];
- unsigned int flags;
- int bitmask;
-
- /* 2-color encoding */
- CHECK_STREAM_PTR(2);
-
- P0 = *s->stream_ptr++;
- P1 = *s->stream_ptr++;
-
- if (P0 <= P1) {
-
- /* need 8 more bytes from the stream */
- CHECK_STREAM_PTR(8);
- for (y = 0; y < 8; y++)
- B[y] = *s->stream_ptr++;
-
- for (y = 0; y < 8; y++) {
- flags = B[y];
- for (x = 0x01; x <= 0x80; x <<= 1) {
- if (flags & x)
- *s->pixel_ptr++ = P1;
- else
- *s->pixel_ptr++ = P0;
- }
- s->pixel_ptr += s->line_inc;
- }
-
- } else {
-
- /* need 2 more bytes from the stream */
- CHECK_STREAM_PTR(2);
- B[0] = *s->stream_ptr++;
- B[1] = *s->stream_ptr++;
-
- flags = (B[1] << 8) | B[0];
- bitmask = 0x0001;
- for (y = 0; y < 8; y += 2) {
- for (x = 0; x < 8; x += 2, bitmask <<= 1) {
- if (flags & bitmask) {
- *(s->pixel_ptr + x) = P1;
- *(s->pixel_ptr + x + 1) = P1;
- *(s->pixel_ptr + s->stride + x) = P1;
- *(s->pixel_ptr + s->stride + x + 1) = P1;
- } else {
- *(s->pixel_ptr + x) = P0;
- *(s->pixel_ptr + x + 1) = P0;
- *(s->pixel_ptr + s->stride + x) = P0;
- *(s->pixel_ptr + s->stride + x + 1) = P0;
- }
- }
- s->pixel_ptr += s->stride * 2;
- }
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x8(IpvideoContext *s)
-{
- int x, y;
- unsigned char P[8];
- unsigned char B[8];
- unsigned int flags = 0;
- unsigned int bitmask = 0;
- unsigned char P0 = 0, P1 = 0;
- int lower_half = 0;
-
- /* 2-color encoding for each 4x4 quadrant, or 2-color encoding on
- * either top and bottom or left and right halves */
- CHECK_STREAM_PTR(2);
-
- P[0] = *s->stream_ptr++;
- P[1] = *s->stream_ptr++;
-
- if (P[0] <= P[1]) {
-
- /* need 12 more bytes */
- CHECK_STREAM_PTR(12);
- B[0] = *s->stream_ptr++; B[1] = *s->stream_ptr++;
- P[2] = *s->stream_ptr++; P[3] = *s->stream_ptr++;
- B[2] = *s->stream_ptr++; B[3] = *s->stream_ptr++;
- P[4] = *s->stream_ptr++; P[5] = *s->stream_ptr++;
- B[4] = *s->stream_ptr++; B[5] = *s->stream_ptr++;
- P[6] = *s->stream_ptr++; P[7] = *s->stream_ptr++;
- B[6] = *s->stream_ptr++; B[7] = *s->stream_ptr++;
-
- for (y = 0; y < 8; y++) {
-
- /* time to reload flags? */
- if (y == 0) {
- flags =
- ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) |
- ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) |
- ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |
- ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);
- bitmask = 0x00000001;
- lower_half = 0; /* still on top half */
- } else if (y == 4) {
- flags =
- ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) |
- ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) |
- ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |
- ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);
- bitmask = 0x00000001;
- lower_half = 2;
- }
-
- for (x = 0; x < 8; x++, bitmask <<= 1) {
- /* get the pixel values ready for this quadrant */
- if (x == 0) {
- P0 = P[lower_half + 0];
- P1 = P[lower_half + 1];
- } else if (x == 4) {
- P0 = P[lower_half + 4];
- P1 = P[lower_half + 5];
- }
-
- if (flags & bitmask)
- *s->pixel_ptr++ = P1;
- else
- *s->pixel_ptr++ = P0;
- }
- s->pixel_ptr += s->line_inc;
- }
-
- } else {
-
- /* need 10 more bytes */
- CHECK_STREAM_PTR(10);
- B[0] = *s->stream_ptr++; B[1] = *s->stream_ptr++;
- B[2] = *s->stream_ptr++; B[3] = *s->stream_ptr++;
- P[2] = *s->stream_ptr++; P[3] = *s->stream_ptr++;
- B[4] = *s->stream_ptr++; B[5] = *s->stream_ptr++;
- B[6] = *s->stream_ptr++; B[7] = *s->stream_ptr++;
-
- if (P[2] <= P[3]) {
-
- /* vertical split; left & right halves are 2-color encoded */
-
- for (y = 0; y < 8; y++) {
-
- /* time to reload flags? */
- if (y == 0) {
- flags =
- ((B[0] & 0xF0) << 4) | ((B[4] & 0xF0) << 8) |
- ((B[0] & 0x0F) ) | ((B[4] & 0x0F) << 4) |
- ((B[1] & 0xF0) << 20) | ((B[5] & 0xF0) << 24) |
- ((B[1] & 0x0F) << 16) | ((B[5] & 0x0F) << 20);
- bitmask = 0x00000001;
- } else if (y == 4) {
- flags =
- ((B[2] & 0xF0) << 4) | ((B[6] & 0xF0) << 8) |
- ((B[2] & 0x0F) ) | ((B[6] & 0x0F) << 4) |
- ((B[3] & 0xF0) << 20) | ((B[7] & 0xF0) << 24) |
- ((B[3] & 0x0F) << 16) | ((B[7] & 0x0F) << 20);
- bitmask = 0x00000001;
- }
-
- for (x = 0; x < 8; x++, bitmask <<= 1) {
- /* get the pixel values ready for this half */
- if (x == 0) {
- P0 = P[0];
- P1 = P[1];
- } else if (x == 4) {
- P0 = P[2];
- P1 = P[3];
- }
-
- if (flags & bitmask)
- *s->pixel_ptr++ = P1;
- else
- *s->pixel_ptr++ = P0;
- }
- s->pixel_ptr += s->line_inc;
- }
-
- } else {
-
- /* horizontal split; top & bottom halves are 2-color encoded */
-
- for (y = 0; y < 8; y++) {
-
- flags = B[y];
- if (y == 0) {
- P0 = P[0];
- P1 = P[1];
- } else if (y == 4) {
- P0 = P[2];
- P1 = P[3];
- }
-
- for (bitmask = 0x01; bitmask <= 0x80; bitmask <<= 1) {
-
- if (flags & bitmask)
- *s->pixel_ptr++ = P1;
- else
- *s->pixel_ptr++ = P0;
- }
- s->pixel_ptr += s->line_inc;
- }
- }
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s)
-{
- int x, y;
- unsigned char P[4];
- unsigned char B[4];
- unsigned int flags = 0;
- int shifter = 0;
- unsigned char pix;
-
- /* 4-color encoding */
- CHECK_STREAM_PTR(4);
-
- for (y = 0; y < 4; y++)
- P[y] = *s->stream_ptr++;
-
- if ((P[0] <= P[1]) && (P[2] <= P[3])) {
-
- /* 1 of 4 colors for each pixel, need 16 more bytes */
- CHECK_STREAM_PTR(16);
-
- for (y = 0; y < 8; y++) {
- /* get the next set of 8 2-bit flags */
- flags = (s->stream_ptr[1] << 8) | s->stream_ptr[0];
- s->stream_ptr += 2;
- for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
- *s->pixel_ptr++ = P[(flags >> shifter) & 0x03];
- }
- s->pixel_ptr += s->line_inc;
- }
-
- } else if ((P[0] <= P[1]) && (P[2] > P[3])) {
-
- /* 1 of 4 colors for each 2x2 block, need 4 more bytes */
- CHECK_STREAM_PTR(4);
-
- B[0] = *s->stream_ptr++;
- B[1] = *s->stream_ptr++;
- B[2] = *s->stream_ptr++;
- B[3] = *s->stream_ptr++;
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
- shifter = 0;
-
- for (y = 0; y < 8; y += 2) {
- for (x = 0; x < 8; x += 2, shifter += 2) {
- pix = P[(flags >> shifter) & 0x03];
- *(s->pixel_ptr + x) = pix;
- *(s->pixel_ptr + x + 1) = pix;
- *(s->pixel_ptr + s->stride + x) = pix;
- *(s->pixel_ptr + s->stride + x + 1) = pix;
- }
- s->pixel_ptr += s->stride * 2;
- }
-
- } else if ((P[0] > P[1]) && (P[2] <= P[3])) {
-
- /* 1 of 4 colors for each 2x1 block, need 8 more bytes */
- CHECK_STREAM_PTR(8);
-
- for (y = 0; y < 8; y++) {
- /* time to reload flags? */
- if ((y == 0) || (y == 4)) {
- B[0] = *s->stream_ptr++;
- B[1] = *s->stream_ptr++;
- B[2] = *s->stream_ptr++;
- B[3] = *s->stream_ptr++;
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
- shifter = 0;
- }
- for (x = 0; x < 8; x += 2, shifter += 2) {
- pix = P[(flags >> shifter) & 0x03];
- *(s->pixel_ptr + x) = pix;
- *(s->pixel_ptr + x + 1) = pix;
- }
- s->pixel_ptr += s->stride;
- }
-
- } else {
-
- /* 1 of 4 colors for each 1x2 block, need 8 more bytes */
- CHECK_STREAM_PTR(8);
-
- for (y = 0; y < 8; y += 2) {
- /* time to reload flags? */
- if ((y == 0) || (y == 4)) {
- B[0] = *s->stream_ptr++;
- B[1] = *s->stream_ptr++;
- B[2] = *s->stream_ptr++;
- B[3] = *s->stream_ptr++;
- flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0];
- shifter = 0;
- }
- for (x = 0; x < 8; x++, shifter += 2) {
- pix = P[(flags >> shifter) & 0x03];
- *(s->pixel_ptr + x) = pix;
- *(s->pixel_ptr + s->stride + x) = pix;
- }
- s->pixel_ptr += s->stride * 2;
- }
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xA(IpvideoContext *s)
-{
- int x, y;
- unsigned char P[16];
- unsigned char B[16];
- int flags = 0;
- int shifter = 0;
- int index;
- int split;
- int lower_half;
-
- /* 4-color encoding for each 4x4 quadrant, or 4-color encoding on
- * either top and bottom or left and right halves */
- CHECK_STREAM_PTR(4);
-
- for (y = 0; y < 4; y++)
- P[y] = *s->stream_ptr++;
-
- if (P[0] <= P[1]) {
-
- /* 4-color encoding for each quadrant; need 28 more bytes */
- CHECK_STREAM_PTR(28);
-
- for (y = 0; y < 4; y++)
- B[y] = *s->stream_ptr++;
- for (y = 4; y < 16; y += 4) {
- for (x = y; x < y + 4; x++)
- P[x] = *s->stream_ptr++;
- for (x = y; x < y + 4; x++)
- B[x] = *s->stream_ptr++;
- }
-
- for (y = 0; y < 8; y++) {
-
- lower_half = (y >= 4) ? 4 : 0;
- flags = (B[y + 8] << 8) | B[y];
-
- for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
- split = (x >= 4) ? 8 : 0;
- index = split + lower_half + ((flags >> shifter) & 0x03);
- *s->pixel_ptr++ = P[index];
- }
-
- s->pixel_ptr += s->line_inc;
- }
-
- } else {
-
- /* 4-color encoding for either left and right or top and bottom
- * halves; need 20 more bytes */
- CHECK_STREAM_PTR(20);
-
- for (y = 0; y < 8; y++)
- B[y] = *s->stream_ptr++;
- for (y = 4; y < 8; y++)
- P[y] = *s->stream_ptr++;
- for (y = 8; y < 16; y++)
- B[y] = *s->stream_ptr++;
-
- if (P[4] <= P[5]) {
-
- /* block is divided into left and right halves */
- for (y = 0; y < 8; y++) {
-
- flags = (B[y + 8] << 8) | B[y];
- split = 0;
-
- for (x = 0, shifter = 0; x < 8; x++, shifter += 2) {
- if (x == 4)
- split = 4;
- *s->pixel_ptr++ = P[split + ((flags >> shifter) & 0x03)];
- }
-
- s->pixel_ptr += s->line_inc;
- }
-
- } else {
-
- /* block is divided into top and bottom halves */
- split = 0;
- for (y = 0; y < 8; y++) {
-
- flags = (B[y * 2 + 1] << 8) | B[y * 2];
- if (y == 4)
- split = 4;
-
- for (x = 0, shifter = 0; x < 8; x++, shifter += 2)
- *s->pixel_ptr++ = P[split + ((flags >> shifter) & 0x03)];
-
- s->pixel_ptr += s->line_inc;
- }
- }
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xB(IpvideoContext *s)
-{
- int x, y;
-
- /* 64-color encoding (each pixel in block is a different color) */
- CHECK_STREAM_PTR(64);
-
- for (y = 0; y < 8; y++) {
- for (x = 0; x < 8; x++) {
- *s->pixel_ptr++ = *s->stream_ptr++;
- }
- s->pixel_ptr += s->line_inc;
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xC(IpvideoContext *s)
-{
- int x, y;
- unsigned char pix;
-
- /* 16-color block encoding: each 2x2 block is a different color */
- CHECK_STREAM_PTR(16);
-
- for (y = 0; y < 8; y += 2) {
- for (x = 0; x < 8; x += 2) {
- pix = *s->stream_ptr++;
- *(s->pixel_ptr + x) = pix;
- *(s->pixel_ptr + x + 1) = pix;
- *(s->pixel_ptr + s->stride + x) = pix;
- *(s->pixel_ptr + s->stride + x + 1) = pix;
- }
- s->pixel_ptr += s->stride * 2;
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xD(IpvideoContext *s)
-{
- int x, y;
- unsigned char P[4];
- unsigned char index = 0;
-
- /* 4-color block encoding: each 4x4 block is a different color */
- CHECK_STREAM_PTR(4);
-
- for (y = 0; y < 4; y++)
- P[y] = *s->stream_ptr++;
-
- for (y = 0; y < 8; y++) {
- if (y < 4)
- index = 0;
- else
- index = 2;
-
- for (x = 0; x < 8; x++) {
- if (x == 4)
- index++;
- *s->pixel_ptr++ = P[index];
- }
- s->pixel_ptr += s->line_inc;
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xE(IpvideoContext *s)
-{
- int x, y;
- unsigned char pix;
-
- /* 1-color encoding: the whole block is 1 solid color */
- CHECK_STREAM_PTR(1);
- pix = *s->stream_ptr++;
-
- for (y = 0; y < 8; y++) {
- for (x = 0; x < 8; x++) {
- *s->pixel_ptr++ = pix;
- }
- s->pixel_ptr += s->line_inc;
- }
-
- /* report success */
- return 0;
-}
-
-static int ipvideo_decode_block_opcode_0xF(IpvideoContext *s)
-{
- int x, y;
- unsigned char sample0, sample1;
-
- /* dithered encoding */
- CHECK_STREAM_PTR(2);
- sample0 = *s->stream_ptr++;
- sample1 = *s->stream_ptr++;
-
- for (y = 0; y < 8; y++) {
- for (x = 0; x < 8; x += 2) {
- if (y & 1) {
- *s->pixel_ptr++ = sample1;
- *s->pixel_ptr++ = sample0;
- } else {
- *s->pixel_ptr++ = sample0;
- *s->pixel_ptr++ = sample1;
- }
- }
- s->pixel_ptr += s->line_inc;
- }
-
- /* report success */
- return 0;
-}
-
-static int (*ipvideo_decode_block[16])(IpvideoContext *s);
-
-static void ipvideo_decode_opcodes(IpvideoContext *s)
-{
- int x, y;
- int index = 0;
- unsigned char opcode;
- int ret;
- int code_counts[16];
- static int frame = 0;
-
- debug_interplay("------------------ frame %d\n", frame);
- frame++;
-
- for (x = 0; x < 16; x++)
- code_counts[x] = 0;
-
- /* this is PAL8, so make the palette available */
- memcpy(s->current_frame.data[1], s->palette, PALETTE_COUNT * 4);
-
- s->stride = s->current_frame.linesize[0];
- s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */
- s->stream_end = s->buf + s->size;
- s->line_inc = s->stride - 8;
- s->upper_motion_limit_offset = (s->avctx->height - 8) * s->stride
- + s->avctx->width - 8;
- s->dsp = s->dsp;
-
- for (y = 0; y < (s->stride * s->avctx->height); y += s->stride * 8) {
- for (x = y; x < y + s->avctx->width; x += 8) {
- /* bottom nibble first, then top nibble (which makes it
- * hard to use a GetBitcontext) */
- if (index & 1)
- opcode = s->decoding_map[index >> 1] >> 4;
- else
- opcode = s->decoding_map[index >> 1] & 0xF;
- index++;
-
- debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n",
- x - y, y / s->stride, opcode, s->stream_ptr);
- code_counts[opcode]++;
-
- s->pixel_ptr = s->current_frame.data[0] + x;
- ret = ipvideo_decode_block[opcode](s);
- if (ret != 0) {
- printf(" Interplay video: decode problem on frame %d, @ block (%d, %d)\n",
- frame, x - y, y / s->stride);
- return;
- }
- }
- }
- if ((s->stream_ptr != s->stream_end) &&
- (s->stream_ptr + 1 != s->stream_end)) {
- printf (" Interplay video: decode finished with %d bytes left over\n",
- s->stream_end - s->stream_ptr);
- }
-}
-
-static int ipvideo_decode_init(AVCodecContext *avctx)
-{
- IpvideoContext *s = avctx->priv_data;
-
- s->avctx = avctx;
-
- if (s->avctx->extradata_size != sizeof(AVPaletteControl)) {
- printf (" Interplay video: expected extradata_size of %d\n",
- sizeof(AVPaletteControl));
- return -1;
- }
-
- avctx->pix_fmt = PIX_FMT_PAL8;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- /* decoding map contains 4 bits of information per 8x8 block */
- s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
-
- /* assign block decode functions */
- ipvideo_decode_block[0x0] = ipvideo_decode_block_opcode_0x0;
- ipvideo_decode_block[0x1] = ipvideo_decode_block_opcode_0x1;
- ipvideo_decode_block[0x2] = ipvideo_decode_block_opcode_0x2;
- ipvideo_decode_block[0x3] = ipvideo_decode_block_opcode_0x3;
- ipvideo_decode_block[0x4] = ipvideo_decode_block_opcode_0x4;
- ipvideo_decode_block[0x5] = ipvideo_decode_block_opcode_0x5;
- ipvideo_decode_block[0x6] = ipvideo_decode_block_opcode_0x6;
- ipvideo_decode_block[0x7] = ipvideo_decode_block_opcode_0x7;
- ipvideo_decode_block[0x8] = ipvideo_decode_block_opcode_0x8;
- ipvideo_decode_block[0x9] = ipvideo_decode_block_opcode_0x9;
- ipvideo_decode_block[0xA] = ipvideo_decode_block_opcode_0xA;
- ipvideo_decode_block[0xB] = ipvideo_decode_block_opcode_0xB;
- ipvideo_decode_block[0xC] = ipvideo_decode_block_opcode_0xC;
- ipvideo_decode_block[0xD] = ipvideo_decode_block_opcode_0xD;
- ipvideo_decode_block[0xE] = ipvideo_decode_block_opcode_0xE;
- ipvideo_decode_block[0xF] = ipvideo_decode_block_opcode_0xF;
-
- s->current_frame.data[0] = s->last_frame.data[0] =
- s->second_last_frame.data[0] = NULL;
-
- return 0;
-}
-
-static int ipvideo_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- IpvideoContext *s = avctx->priv_data;
- AVPaletteControl *palette_control = (AVPaletteControl *)avctx->extradata;
-
- if (palette_control->palette_changed) {
- /* load the new palette and reset the palette control */
- ipvideo_new_palette(s, palette_control->palette);
- palette_control->palette_changed = 0;
- }
-
- s->decoding_map = buf;
- s->buf = buf + s->decoding_map_size;
- s->size = buf_size - s->decoding_map_size;
-
- s->current_frame.reference = 3;
- if (avctx->get_buffer(avctx, &s->current_frame)) {
- printf (" Interplay Video: get_buffer() failed\n");
- return -1;
- }
-
- ipvideo_decode_opcodes(s);
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->current_frame;
-
- /* shuffle frames */
- if (s->second_last_frame.data[0])
- avctx->release_buffer(avctx, &s->second_last_frame);
- s->second_last_frame = s->last_frame;
- s->last_frame = s->current_frame;
- s->current_frame.data[0] = NULL; /* catch any access attempts */
-
- /* report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int ipvideo_decode_end(AVCodecContext *avctx)
-{
- IpvideoContext *s = avctx->priv_data;
-
- /* release the last frame */
- if (s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->last_frame);
- if (s->second_last_frame.data[0])
- avctx->release_buffer(avctx, &s->second_last_frame);
-
- return 0;
-}
-
-AVCodec interplay_video_decoder = {
- "interplayvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_INTERPLAY_VIDEO,
- sizeof(IpvideoContext),
- ipvideo_decode_init,
- NULL,
- ipvideo_decode_end,
- ipvideo_decode_frame,
- CODEC_CAP_DR1,
-};
+++ /dev/null
-/*
- * jfdctfst.c
- *
- * Copyright (C) 1994-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a fast, not so accurate integer implementation of the
- * forward DCT (Discrete Cosine Transform).
- *
- * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- * on each column. Direct algorithms are also available, but they are
- * much more complex and seem not to be any faster when reduced to code.
- *
- * This implementation is based on Arai, Agui, and Nakajima's algorithm for
- * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
- * Japanese, but the algorithm is described in the Pennebaker & Mitchell
- * JPEG textbook (see REFERENCES section in file README). The following code
- * is based directly on figure 4-8 in P&M.
- * While an 8-point DCT cannot be done in less than 11 multiplies, it is
- * possible to arrange the computation so that many of the multiplies are
- * simple scalings of the final outputs. These multiplies can then be
- * folded into the multiplications or divisions by the JPEG quantization
- * table entries. The AA&N method leaves only 5 multiplies and 29 adds
- * to be done in the DCT itself.
- * The primary disadvantage of this method is that with fixed-point math,
- * accuracy is lost due to imprecise representation of the scaled
- * quantization values. The smaller the quantization table entry, the less
- * precise the scaled value, so this implementation does worse with high-
- * quality-setting files than with low-quality ones.
- */
-
-/**
- * @file jfdctfst.c
- * Independent JPEG Group's fast AAN dct.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "common.h"
-#include "dsputil.h"
-
-#define DCTSIZE 8
-#define GLOBAL(x) x
-#define RIGHT_SHIFT(x, n) ((x) >> (n))
-#define SHIFT_TEMPS
-
-/*
- * This module is specialized to the case DCTSIZE = 8.
- */
-
-#if DCTSIZE != 8
- Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
-#endif
-
-
-/* Scaling decisions are generally the same as in the LL&M algorithm;
- * see jfdctint.c for more details. However, we choose to descale
- * (right shift) multiplication products as soon as they are formed,
- * rather than carrying additional fractional bits into subsequent additions.
- * This compromises accuracy slightly, but it lets us save a few shifts.
- * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)
- * everywhere except in the multiplications proper; this saves a good deal
- * of work on 16-bit-int machines.
- *
- * Again to save a few shifts, the intermediate results between pass 1 and
- * pass 2 are not upscaled, but are represented only to integral precision.
- *
- * A final compromise is to represent the multiplicative constants to only
- * 8 fractional bits, rather than 13. This saves some shifting work on some
- * machines, and may also reduce the cost of multiplication (since there
- * are fewer one-bits in the constants).
- */
-
-#define CONST_BITS 8
-
-
-/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
- * causing a lot of useless floating-point operations at run time.
- * To get around this we use the following pre-calculated constants.
- * If you change CONST_BITS you may want to add appropriate values.
- * (With a reasonable C compiler, you can just rely on the FIX() macro...)
- */
-
-#if CONST_BITS == 8
-#define FIX_0_382683433 ((int32_t) 98) /* FIX(0.382683433) */
-#define FIX_0_541196100 ((int32_t) 139) /* FIX(0.541196100) */
-#define FIX_0_707106781 ((int32_t) 181) /* FIX(0.707106781) */
-#define FIX_1_306562965 ((int32_t) 334) /* FIX(1.306562965) */
-#else
-#define FIX_0_382683433 FIX(0.382683433)
-#define FIX_0_541196100 FIX(0.541196100)
-#define FIX_0_707106781 FIX(0.707106781)
-#define FIX_1_306562965 FIX(1.306562965)
-#endif
-
-
-/* We can gain a little more speed, with a further compromise in accuracy,
- * by omitting the addition in a descaling shift. This yields an incorrectly
- * rounded result half the time...
- */
-
-#ifndef USE_ACCURATE_ROUNDING
-#undef DESCALE
-#define DESCALE(x,n) RIGHT_SHIFT(x, n)
-#endif
-
-
-/* Multiply a DCTELEM variable by an int32_t constant, and immediately
- * descale to yield a DCTELEM result.
- */
-
-#define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
-
-
-/*
- * Perform the forward DCT on one block of samples.
- */
-
-GLOBAL(void)
-fdct_ifast (DCTELEM * data)
-{
- DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- DCTELEM tmp10, tmp11, tmp12, tmp13;
- DCTELEM z1, z2, z3, z4, z5, z11, z13;
- DCTELEM *dataptr;
- int ctr;
- SHIFT_TEMPS
-
- /* Pass 1: process rows. */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[0] + dataptr[7];
- tmp7 = dataptr[0] - dataptr[7];
- tmp1 = dataptr[1] + dataptr[6];
- tmp6 = dataptr[1] - dataptr[6];
- tmp2 = dataptr[2] + dataptr[5];
- tmp5 = dataptr[2] - dataptr[5];
- tmp3 = dataptr[3] + dataptr[4];
- tmp4 = dataptr[3] - dataptr[4];
-
- /* Even part */
-
- tmp10 = tmp0 + tmp3; /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[0] = tmp10 + tmp11; /* phase 3 */
- dataptr[4] = tmp10 - tmp11;
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
- dataptr[2] = tmp13 + z1; /* phase 5 */
- dataptr[6] = tmp13 - z1;
-
- /* Odd part */
-
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
- z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
- z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
- z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
- z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
-
- z11 = tmp7 + z3; /* phase 5 */
- z13 = tmp7 - z3;
-
- dataptr[5] = z13 + z2; /* phase 6 */
- dataptr[3] = z13 - z2;
- dataptr[1] = z11 + z4;
- dataptr[7] = z11 - z4;
-
- dataptr += DCTSIZE; /* advance pointer to next row */
- }
-
- /* Pass 2: process columns. */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
- tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
- tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
- tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
- tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
- tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
- tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
-
- /* Even part */
-
- tmp10 = tmp0 + tmp3; /* phase 2 */
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
- dataptr[DCTSIZE*4] = tmp10 - tmp11;
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
- dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
- dataptr[DCTSIZE*6] = tmp13 - z1;
-
- /* Odd part */
-
- tmp10 = tmp4 + tmp5; /* phase 2 */
- tmp11 = tmp5 + tmp6;
- tmp12 = tmp6 + tmp7;
-
- /* The rotator is modified from fig 4-8 to avoid extra negations. */
- z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
- z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
- z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
- z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
-
- z11 = tmp7 + z3; /* phase 5 */
- z13 = tmp7 - z3;
-
- dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
- dataptr[DCTSIZE*3] = z13 - z2;
- dataptr[DCTSIZE*1] = z11 + z4;
- dataptr[DCTSIZE*7] = z11 - z4;
-
- dataptr++; /* advance pointer to next column */
- }
-}
-
-
-#undef GLOBAL
-#undef CONST_BITS
-#undef DESCALE
-#undef FIX_0_541196100
-#undef FIX_1_306562965
+++ /dev/null
-/*
- * jfdctint.c
- *
- * Copyright (C) 1991-1996, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains a slow-but-accurate integer implementation of the
- * forward DCT (Discrete Cosine Transform).
- *
- * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
- * on each column. Direct algorithms are also available, but they are
- * much more complex and seem not to be any faster when reduced to code.
- *
- * This implementation is based on an algorithm described in
- * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- * The primary algorithm described there uses 11 multiplies and 29 adds.
- * We use their alternate method with 12 multiplies and 32 adds.
- * The advantage of this method is that no data path contains more than one
- * multiplication; this allows a very simple and accurate implementation in
- * scaled fixed-point arithmetic, with a minimal number of shifts.
- */
-
-/**
- * @file jfdctint.c
- * Independent JPEG Group's slow & accurate dct.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include "common.h"
-#include "dsputil.h"
-
-#define SHIFT_TEMPS
-#define DCTSIZE 8
-#define BITS_IN_JSAMPLE 8
-#define GLOBAL(x) x
-#define RIGHT_SHIFT(x, n) ((x) >> (n))
-#define MULTIPLY16C16(var,const) ((var)*(const))
-
-#if 1 //def USE_ACCURATE_ROUNDING
-#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n)
-#else
-#define DESCALE(x,n) RIGHT_SHIFT(x, n)
-#endif
-
-
-/*
- * This module is specialized to the case DCTSIZE = 8.
- */
-
-#if DCTSIZE != 8
- Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
-#endif
-
-
-/*
- * The poop on this scaling stuff is as follows:
- *
- * Each 1-D DCT step produces outputs which are a factor of sqrt(N)
- * larger than the true DCT outputs. The final outputs are therefore
- * a factor of N larger than desired; since N=8 this can be cured by
- * a simple right shift at the end of the algorithm. The advantage of
- * this arrangement is that we save two multiplications per 1-D DCT,
- * because the y0 and y4 outputs need not be divided by sqrt(N).
- * In the IJG code, this factor of 8 is removed by the quantization step
- * (in jcdctmgr.c), NOT in this module.
- *
- * We have to do addition and subtraction of the integer inputs, which
- * is no problem, and multiplication by fractional constants, which is
- * a problem to do in integer arithmetic. We multiply all the constants
- * by CONST_SCALE and convert them to integer constants (thus retaining
- * CONST_BITS bits of precision in the constants). After doing a
- * multiplication we have to divide the product by CONST_SCALE, with proper
- * rounding, to produce the correct output. This division can be done
- * cheaply as a right shift of CONST_BITS bits. We postpone shifting
- * as long as possible so that partial sums can be added together with
- * full fractional precision.
- *
- * The outputs of the first pass are scaled up by PASS1_BITS bits so that
- * they are represented to better-than-integral precision. These outputs
- * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- * with the recommended scaling. (For 12-bit sample data, the intermediate
- * array is int32_t anyway.)
- *
- * To avoid overflow of the 32-bit intermediate results in pass 2, we must
- * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- * shows that the values given below are the most effective.
- */
-
-#if BITS_IN_JSAMPLE == 8
-#define CONST_BITS 13
-#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */
-#else
-#define CONST_BITS 13
-#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
-#endif
-
-/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
- * causing a lot of useless floating-point operations at run time.
- * To get around this we use the following pre-calculated constants.
- * If you change CONST_BITS you may want to add appropriate values.
- * (With a reasonable C compiler, you can just rely on the FIX() macro...)
- */
-
-#if CONST_BITS == 13
-#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */
-#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */
-#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */
-#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */
-#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */
-#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */
-#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */
-#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */
-#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */
-#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */
-#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */
-#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */
-#else
-#define FIX_0_298631336 FIX(0.298631336)
-#define FIX_0_390180644 FIX(0.390180644)
-#define FIX_0_541196100 FIX(0.541196100)
-#define FIX_0_765366865 FIX(0.765366865)
-#define FIX_0_899976223 FIX(0.899976223)
-#define FIX_1_175875602 FIX(1.175875602)
-#define FIX_1_501321110 FIX(1.501321110)
-#define FIX_1_847759065 FIX(1.847759065)
-#define FIX_1_961570560 FIX(1.961570560)
-#define FIX_2_053119869 FIX(2.053119869)
-#define FIX_2_562915447 FIX(2.562915447)
-#define FIX_3_072711026 FIX(3.072711026)
-#endif
-
-
-/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
- * For 8-bit samples with the recommended scaling, all the variable
- * and constant values involved are no more than 16 bits wide, so a
- * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
- * For 12-bit samples, a full 32-bit multiplication will be needed.
- */
-
-#if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2
-#define MULTIPLY(var,const) MULTIPLY16C16(var,const)
-#else
-#define MULTIPLY(var,const) ((var) * (const))
-#endif
-
-
-/*
- * Perform the forward DCT on one block of samples.
- */
-
-GLOBAL(void)
-ff_jpeg_fdct_islow (DCTELEM * data)
-{
- int32_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- int32_t tmp10, tmp11, tmp12, tmp13;
- int32_t z1, z2, z3, z4, z5;
- DCTELEM *dataptr;
- int ctr;
- SHIFT_TEMPS
-
- /* Pass 1: process rows. */
- /* Note results are scaled up by sqrt(8) compared to a true DCT; */
- /* furthermore, we scale the results by 2**PASS1_BITS. */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[0] + dataptr[7];
- tmp7 = dataptr[0] - dataptr[7];
- tmp1 = dataptr[1] + dataptr[6];
- tmp6 = dataptr[1] - dataptr[6];
- tmp2 = dataptr[2] + dataptr[5];
- tmp5 = dataptr[2] - dataptr[5];
- tmp3 = dataptr[3] + dataptr[4];
- tmp4 = dataptr[3] - dataptr[4];
-
- /* Even part per LL&M figure 1 --- note that published figure is faulty;
- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
- */
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
- dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS-PASS1_BITS);
- dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS-PASS1_BITS);
-
- /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
-
- z1 = tmp4 + tmp7;
- z2 = tmp5 + tmp6;
- z3 = tmp4 + tmp6;
- z4 = tmp5 + tmp7;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
-
- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
- dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
- dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
- dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
-
- dataptr += DCTSIZE; /* advance pointer to next row */
- }
-
- /* Pass 2: process columns.
- * We remove the PASS1_BITS scaling, but leave the results scaled up
- * by an overall factor of 8.
- */
-
- dataptr = data;
- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
- tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
- tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
- tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
- tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
- tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
- tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
-
- /* Even part per LL&M figure 1 --- note that published figure is faulty;
- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
- */
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
-
- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
-
- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
- CONST_BITS+PASS1_BITS);
-
- /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
- * cK represents cos(K*pi/16).
- * i0..i3 in the paper are tmp4..tmp7 here.
- */
-
- z1 = tmp4 + tmp7;
- z2 = tmp5 + tmp6;
- z3 = tmp4 + tmp6;
- z4 = tmp5 + tmp7;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
-
- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
-
- z3 += z5;
- z4 += z5;
-
- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
- CONST_BITS+PASS1_BITS);
- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
- CONST_BITS+PASS1_BITS);
-
- dataptr++; /* advance pointer to next column */
- }
-}
+++ /dev/null
-/*
- * jrevdct.c
- *
- * Copyright (C) 1991, 1992, Thomas G. Lane.
- * This file is part of the Independent JPEG Group's software.
- * For conditions of distribution and use, see the accompanying README file.
- *
- * This file contains the basic inverse-DCT transformation subroutine.
- *
- * This implementation is based on an algorithm described in
- * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT
- * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics,
- * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.
- * The primary algorithm described there uses 11 multiplies and 29 adds.
- * We use their alternate method with 12 multiplies and 32 adds.
- * The advantage of this method is that no data path contains more than one
- * multiplication; this allows a very simple and accurate implementation in
- * scaled fixed-point arithmetic, with a minimal number of shifts.
- *
- * I've made lots of modifications to attempt to take advantage of the
- * sparse nature of the DCT matrices we're getting. Although the logic
- * is cumbersome, it's straightforward and the resulting code is much
- * faster.
- *
- * A better way to do this would be to pass in the DCT block as a sparse
- * matrix, perhaps with the difference cases encoded.
- */
-
-/**
- * @file jrevdct.c
- * Independent JPEG Group's LLM idct.
- */
-
-#include "common.h"
-#include "dsputil.h"
-
-#define EIGHT_BIT_SAMPLES
-
-#define DCTSIZE 8
-#define DCTSIZE2 64
-
-#define GLOBAL
-
-#define RIGHT_SHIFT(x, n) ((x) >> (n))
-
-typedef DCTELEM DCTBLOCK[DCTSIZE2];
-
-#define CONST_BITS 13
-
-/*
- * This routine is specialized to the case DCTSIZE = 8.
- */
-
-#if DCTSIZE != 8
- Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
-#endif
-
-
-/*
- * A 2-D IDCT can be done by 1-D IDCT on each row followed by 1-D IDCT
- * on each column. Direct algorithms are also available, but they are
- * much more complex and seem not to be any faster when reduced to code.
- *
- * The poop on this scaling stuff is as follows:
- *
- * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)
- * larger than the true IDCT outputs. The final outputs are therefore
- * a factor of N larger than desired; since N=8 this can be cured by
- * a simple right shift at the end of the algorithm. The advantage of
- * this arrangement is that we save two multiplications per 1-D IDCT,
- * because the y0 and y4 inputs need not be divided by sqrt(N).
- *
- * We have to do addition and subtraction of the integer inputs, which
- * is no problem, and multiplication by fractional constants, which is
- * a problem to do in integer arithmetic. We multiply all the constants
- * by CONST_SCALE and convert them to integer constants (thus retaining
- * CONST_BITS bits of precision in the constants). After doing a
- * multiplication we have to divide the product by CONST_SCALE, with proper
- * rounding, to produce the correct output. This division can be done
- * cheaply as a right shift of CONST_BITS bits. We postpone shifting
- * as long as possible so that partial sums can be added together with
- * full fractional precision.
- *
- * The outputs of the first pass are scaled up by PASS1_BITS bits so that
- * they are represented to better-than-integral precision. These outputs
- * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word
- * with the recommended scaling. (To scale up 12-bit sample data further, an
- * intermediate int32 array would be needed.)
- *
- * To avoid overflow of the 32-bit intermediate results in pass 2, we must
- * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis
- * shows that the values given below are the most effective.
- */
-
-#ifdef EIGHT_BIT_SAMPLES
-#define PASS1_BITS 2
-#else
-#define PASS1_BITS 1 /* lose a little precision to avoid overflow */
-#endif
-
-#define ONE ((int32_t) 1)
-
-#define CONST_SCALE (ONE << CONST_BITS)
-
-/* Convert a positive real constant to an integer scaled by CONST_SCALE.
- * IMPORTANT: if your compiler doesn't do this arithmetic at compile time,
- * you will pay a significant penalty in run time. In that case, figure
- * the correct integer constant values and insert them by hand.
- */
-
-/* Actually FIX is no longer used, we precomputed them all */
-#define FIX(x) ((int32_t) ((x) * CONST_SCALE + 0.5))
-
-/* Descale and correctly round an int32_t value that's scaled by N bits.
- * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
- * the fudge factor is correct for either sign of X.
- */
-
-#define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
-
-/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result.
- * For 8-bit samples with the recommended scaling, all the variable
- * and constant values involved are no more than 16 bits wide, so a
- * 16x16->32 bit multiply can be used instead of a full 32x32 multiply;
- * this provides a useful speedup on many machines.
- * There is no way to specify a 16x16->32 multiply in portable C, but
- * some C compilers will do the right thing if you provide the correct
- * combination of casts.
- * NB: for 12-bit samples, a full 32-bit multiplication will be needed.
- */
-
-#ifdef EIGHT_BIT_SAMPLES
-#ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
-#define MULTIPLY(var,const) (((int16_t) (var)) * ((int16_t) (const)))
-#endif
-#ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
-#define MULTIPLY(var,const) (((int16_t) (var)) * ((int32_t) (const)))
-#endif
-#endif
-
-#ifndef MULTIPLY /* default definition */
-#define MULTIPLY(var,const) ((var) * (const))
-#endif
-
-
-/*
- Unlike our decoder where we approximate the FIXes, we need to use exact
-ones here or successive P-frames will drift too much with Reference frame coding
-*/
-#define FIX_0_211164243 1730
-#define FIX_0_275899380 2260
-#define FIX_0_298631336 2446
-#define FIX_0_390180644 3196
-#define FIX_0_509795579 4176
-#define FIX_0_541196100 4433
-#define FIX_0_601344887 4926
-#define FIX_0_765366865 6270
-#define FIX_0_785694958 6436
-#define FIX_0_899976223 7373
-#define FIX_1_061594337 8697
-#define FIX_1_111140466 9102
-#define FIX_1_175875602 9633
-#define FIX_1_306562965 10703
-#define FIX_1_387039845 11363
-#define FIX_1_451774981 11893
-#define FIX_1_501321110 12299
-#define FIX_1_662939225 13623
-#define FIX_1_847759065 15137
-#define FIX_1_961570560 16069
-#define FIX_2_053119869 16819
-#define FIX_2_172734803 17799
-#define FIX_2_562915447 20995
-#define FIX_3_072711026 25172
-
-/*
- * Perform the inverse DCT on one block of coefficients.
- */
-
-void j_rev_dct(DCTBLOCK data)
-{
- int32_t tmp0, tmp1, tmp2, tmp3;
- int32_t tmp10, tmp11, tmp12, tmp13;
- int32_t z1, z2, z3, z4, z5;
- int32_t d0, d1, d2, d3, d4, d5, d6, d7;
- register DCTELEM *dataptr;
- int rowctr;
-
- /* Pass 1: process rows. */
- /* Note results are scaled up by sqrt(8) compared to a true IDCT; */
- /* furthermore, we scale the results by 2**PASS1_BITS. */
-
- dataptr = data;
-
- for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
- /* Due to quantization, we will usually find that many of the input
- * coefficients are zero, especially the AC terms. We can exploit this
- * by short-circuiting the IDCT calculation for any row in which all
- * the AC terms are zero. In that case each output is equal to the
- * DC coefficient (with scale factor as needed).
- * With typical images and quantization tables, half or more of the
- * row DCT calculations can be simplified this way.
- */
-
- register int *idataptr = (int*)dataptr;
-
- /* WARNING: we do the same permutation as MMX idct to simplify the
- video core */
- d0 = dataptr[0];
- d2 = dataptr[1];
- d4 = dataptr[2];
- d6 = dataptr[3];
- d1 = dataptr[4];
- d3 = dataptr[5];
- d5 = dataptr[6];
- d7 = dataptr[7];
-
- if ((d1 | d2 | d3 | d4 | d5 | d6 | d7) == 0) {
- /* AC terms all zero */
- if (d0) {
- /* Compute a 32 bit value to assign. */
- DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS);
- register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000);
-
- idataptr[0] = v;
- idataptr[1] = v;
- idataptr[2] = v;
- idataptr[3] = v;
- }
-
- dataptr += DCTSIZE; /* advance pointer to next row */
- continue;
- }
-
- /* Even part: reverse the even part of the forward DCT. */
- /* The rotator is sqrt(2)*c(-6). */
-{
- if (d6) {
- if (d4) {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 != 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- }
- } else {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 == 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 == 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- }
- }
- } else {
- if (d4) {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 != 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
- tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
- tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
- } else {
- /* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
- tmp10 = tmp13 = d4 << CONST_BITS;
- tmp11 = tmp12 = -tmp10;
- }
- }
- } else {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 == 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 == 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
- tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
- } else {
- /* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
- tmp10 = tmp13 = tmp11 = tmp12 = 0;
- }
- }
- }
- }
-
- /* Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
-
- if (d7) {
- if (d5) {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
- z1 = d7 + d1;
- z2 = d5 + d3;
- z3 = d7 + d3;
- z4 = d5 + d1;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
- z2 = d5 + d3;
- z3 = d7 + d3;
- z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 = z1 + z4;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
- z1 = d7 + d1;
- z4 = d5 + d1;
- z5 = MULTIPLY(d7 + z4, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 = z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
- tmp0 = MULTIPLY(-d7, FIX_0_601344887);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- tmp1 = MULTIPLY(-d5, FIX_0_509795579);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
- z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z3;
- tmp1 += z4;
- tmp2 = z2 + z3;
- tmp3 = z1 + z4;
- }
- }
- } else {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
- z1 = d7 + d1;
- z3 = d7 + d3;
- z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-d3, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-d1, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 = z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
- z3 = d7 + d3;
-
- tmp0 = MULTIPLY(-d7, FIX_0_601344887);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- tmp2 = MULTIPLY(d3, FIX_0_509795579);
- z2 = MULTIPLY(-d3, FIX_2_562915447);
- z5 = MULTIPLY(z3, FIX_1_175875602);
- z3 = MULTIPLY(-z3, FIX_0_785694958);
-
- tmp0 += z3;
- tmp1 = z2 + z5;
- tmp2 += z3;
- tmp3 = z1 + z5;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
- z1 = d7 + d1;
- z5 = MULTIPLY(z1, FIX_1_175875602);
-
- z1 = MULTIPLY(z1, FIX_0_275899380);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- tmp0 = MULTIPLY(-d7, FIX_1_662939225);
- z4 = MULTIPLY(-d1, FIX_0_390180644);
- tmp3 = MULTIPLY(d1, FIX_1_111140466);
-
- tmp0 += z1;
- tmp1 = z4 + z5;
- tmp2 = z3 + z5;
- tmp3 += z1;
- } else {
- /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
- tmp0 = MULTIPLY(-d7, FIX_1_387039845);
- tmp1 = MULTIPLY(d7, FIX_1_175875602);
- tmp2 = MULTIPLY(-d7, FIX_0_785694958);
- tmp3 = MULTIPLY(d7, FIX_0_275899380);
- }
- }
- }
- } else {
- if (d5) {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
- z2 = d5 + d3;
- z4 = d5 + d1;
- z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
-
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-d1, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-d3, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 = z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
- z2 = d5 + d3;
-
- z5 = MULTIPLY(z2, FIX_1_175875602);
- tmp1 = MULTIPLY(d5, FIX_1_662939225);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
- z2 = MULTIPLY(-z2, FIX_1_387039845);
- tmp2 = MULTIPLY(d3, FIX_1_111140466);
- z3 = MULTIPLY(-d3, FIX_1_961570560);
-
- tmp0 = z3 + z5;
- tmp1 += z2;
- tmp2 += z2;
- tmp3 = z4 + z5;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
- z4 = d5 + d1;
-
- z5 = MULTIPLY(z4, FIX_1_175875602);
- z1 = MULTIPLY(-d1, FIX_0_899976223);
- tmp3 = MULTIPLY(d1, FIX_0_601344887);
- tmp1 = MULTIPLY(-d5, FIX_0_509795579);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z4 = MULTIPLY(z4, FIX_0_785694958);
-
- tmp0 = z1 + z5;
- tmp1 += z4;
- tmp2 = z2 + z5;
- tmp3 += z4;
- } else {
- /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
- tmp0 = MULTIPLY(d5, FIX_1_175875602);
- tmp1 = MULTIPLY(d5, FIX_0_275899380);
- tmp2 = MULTIPLY(-d5, FIX_1_387039845);
- tmp3 = MULTIPLY(d5, FIX_0_785694958);
- }
- }
- } else {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
- z5 = d1 + d3;
- tmp3 = MULTIPLY(d1, FIX_0_211164243);
- tmp2 = MULTIPLY(-d3, FIX_1_451774981);
- z1 = MULTIPLY(d1, FIX_1_061594337);
- z2 = MULTIPLY(-d3, FIX_2_172734803);
- z4 = MULTIPLY(z5, FIX_0_785694958);
- z5 = MULTIPLY(z5, FIX_1_175875602);
-
- tmp0 = z1 - z4;
- tmp1 = z2 + z4;
- tmp2 += z5;
- tmp3 += z5;
- } else {
- /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
- tmp0 = MULTIPLY(-d3, FIX_0_785694958);
- tmp1 = MULTIPLY(-d3, FIX_1_387039845);
- tmp2 = MULTIPLY(-d3, FIX_0_275899380);
- tmp3 = MULTIPLY(d3, FIX_1_175875602);
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
- tmp0 = MULTIPLY(d1, FIX_0_275899380);
- tmp1 = MULTIPLY(d1, FIX_0_785694958);
- tmp2 = MULTIPLY(d1, FIX_1_175875602);
- tmp3 = MULTIPLY(d1, FIX_1_387039845);
- } else {
- /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
- tmp0 = tmp1 = tmp2 = tmp3 = 0;
- }
- }
- }
- }
-}
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-
- dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
- dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
- dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
- dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
- dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
- dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
- dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
- dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
-
- dataptr += DCTSIZE; /* advance pointer to next row */
- }
-
- /* Pass 2: process columns. */
- /* Note that we must descale the results by a factor of 8 == 2**3, */
- /* and also undo the PASS1_BITS scaling. */
-
- dataptr = data;
- for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) {
- /* Columns of zeroes can be exploited in the same way as we did with rows.
- * However, the row calculation has created many nonzero AC terms, so the
- * simplification applies less often (typically 5% to 10% of the time).
- * On machines with very fast multiplication, it's possible that the
- * test takes more time than it's worth. In that case this section
- * may be commented out.
- */
-
- d0 = dataptr[DCTSIZE*0];
- d1 = dataptr[DCTSIZE*1];
- d2 = dataptr[DCTSIZE*2];
- d3 = dataptr[DCTSIZE*3];
- d4 = dataptr[DCTSIZE*4];
- d5 = dataptr[DCTSIZE*5];
- d6 = dataptr[DCTSIZE*6];
- d7 = dataptr[DCTSIZE*7];
-
- /* Even part: reverse the even part of the forward DCT. */
- /* The rotator is sqrt(2)*c(-6). */
- if (d6) {
- if (d4) {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 != 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 == 0, d4 != 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- }
- } else {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 == 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 == 0, d6 != 0 */
- z1 = MULTIPLY(d2 + d6, FIX_0_541196100);
- tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065);
- tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 == 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 == 0, d4 == 0, d6 != 0 */
- tmp2 = MULTIPLY(-d6, FIX_1_306562965);
- tmp3 = MULTIPLY(d6, FIX_0_541196100);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- }
- }
- } else {
- if (d4) {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = (d0 + d4) << CONST_BITS;
- tmp1 = (d0 - d4) << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp1 + tmp2;
- tmp12 = tmp1 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 != 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = d4 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp2 - tmp0;
- tmp12 = -(tmp0 + tmp2);
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */
- tmp10 = tmp13 = (d0 + d4) << CONST_BITS;
- tmp11 = tmp12 = (d0 - d4) << CONST_BITS;
- } else {
- /* d0 == 0, d2 == 0, d4 != 0, d6 == 0 */
- tmp10 = tmp13 = d4 << CONST_BITS;
- tmp11 = tmp12 = -tmp10;
- }
- }
- } else {
- if (d2) {
- if (d0) {
- /* d0 != 0, d2 != 0, d4 == 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp0 = d0 << CONST_BITS;
-
- tmp10 = tmp0 + tmp3;
- tmp13 = tmp0 - tmp3;
- tmp11 = tmp0 + tmp2;
- tmp12 = tmp0 - tmp2;
- } else {
- /* d0 == 0, d2 != 0, d4 == 0, d6 == 0 */
- tmp2 = MULTIPLY(d2, FIX_0_541196100);
- tmp3 = MULTIPLY(d2, FIX_1_306562965);
-
- tmp10 = tmp3;
- tmp13 = -tmp3;
- tmp11 = tmp2;
- tmp12 = -tmp2;
- }
- } else {
- if (d0) {
- /* d0 != 0, d2 == 0, d4 == 0, d6 == 0 */
- tmp10 = tmp13 = tmp11 = tmp12 = d0 << CONST_BITS;
- } else {
- /* d0 == 0, d2 == 0, d4 == 0, d6 == 0 */
- tmp10 = tmp13 = tmp11 = tmp12 = 0;
- }
- }
- }
- }
-
- /* Odd part per figure 8; the matrix is unitary and hence its
- * transpose is its inverse. i0..i3 are y7,y5,y3,y1 respectively.
- */
- if (d7) {
- if (d5) {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 != 0, d7 != 0 */
- z1 = d7 + d1;
- z2 = d5 + d3;
- z3 = d7 + d3;
- z4 = d5 + d1;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 != 0, d7 != 0 */
- z1 = d7;
- z2 = d5 + d3;
- z3 = d7 + d3;
- z5 = MULTIPLY(z3 + d5, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 = z1 + z4;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 != 0, d7 != 0 */
- z1 = d7 + d1;
- z2 = d5;
- z3 = d7;
- z4 = d5 + d1;
- z5 = MULTIPLY(z3 + z4, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 += z2 + z4;
- tmp2 = z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 == 0, d5 != 0, d7 != 0 */
- tmp0 = MULTIPLY(-d7, FIX_0_601344887);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- tmp1 = MULTIPLY(-d5, FIX_0_509795579);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
- z5 = MULTIPLY(d5 + d7, FIX_1_175875602);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z3;
- tmp1 += z4;
- tmp2 = z2 + z3;
- tmp3 = z1 + z4;
- }
- }
- } else {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 == 0, d7 != 0 */
- z1 = d7 + d1;
- z3 = d7 + d3;
- z5 = MULTIPLY(z3 + d1, FIX_1_175875602);
-
- tmp0 = MULTIPLY(d7, FIX_0_298631336);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-z1, FIX_0_899976223);
- z2 = MULTIPLY(-d3, FIX_2_562915447);
- z3 = MULTIPLY(-z3, FIX_1_961570560);
- z4 = MULTIPLY(-d1, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 += z1 + z3;
- tmp1 = z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 == 0, d7 != 0 */
- z3 = d7 + d3;
-
- tmp0 = MULTIPLY(-d7, FIX_0_601344887);
- z1 = MULTIPLY(-d7, FIX_0_899976223);
- tmp2 = MULTIPLY(d3, FIX_0_509795579);
- z2 = MULTIPLY(-d3, FIX_2_562915447);
- z5 = MULTIPLY(z3, FIX_1_175875602);
- z3 = MULTIPLY(-z3, FIX_0_785694958);
-
- tmp0 += z3;
- tmp1 = z2 + z5;
- tmp2 += z3;
- tmp3 = z1 + z5;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 == 0, d7 != 0 */
- z1 = d7 + d1;
- z5 = MULTIPLY(z1, FIX_1_175875602);
-
- z1 = MULTIPLY(z1, FIX_0_275899380);
- z3 = MULTIPLY(-d7, FIX_1_961570560);
- tmp0 = MULTIPLY(-d7, FIX_1_662939225);
- z4 = MULTIPLY(-d1, FIX_0_390180644);
- tmp3 = MULTIPLY(d1, FIX_1_111140466);
-
- tmp0 += z1;
- tmp1 = z4 + z5;
- tmp2 = z3 + z5;
- tmp3 += z1;
- } else {
- /* d1 == 0, d3 == 0, d5 == 0, d7 != 0 */
- tmp0 = MULTIPLY(-d7, FIX_1_387039845);
- tmp1 = MULTIPLY(d7, FIX_1_175875602);
- tmp2 = MULTIPLY(-d7, FIX_0_785694958);
- tmp3 = MULTIPLY(d7, FIX_0_275899380);
- }
- }
- }
- } else {
- if (d5) {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 != 0, d7 == 0 */
- z2 = d5 + d3;
- z4 = d5 + d1;
- z5 = MULTIPLY(d3 + z4, FIX_1_175875602);
-
- tmp1 = MULTIPLY(d5, FIX_2_053119869);
- tmp2 = MULTIPLY(d3, FIX_3_072711026);
- tmp3 = MULTIPLY(d1, FIX_1_501321110);
- z1 = MULTIPLY(-d1, FIX_0_899976223);
- z2 = MULTIPLY(-z2, FIX_2_562915447);
- z3 = MULTIPLY(-d3, FIX_1_961570560);
- z4 = MULTIPLY(-z4, FIX_0_390180644);
-
- z3 += z5;
- z4 += z5;
-
- tmp0 = z1 + z3;
- tmp1 += z2 + z4;
- tmp2 += z2 + z3;
- tmp3 += z1 + z4;
- } else {
- /* d1 == 0, d3 != 0, d5 != 0, d7 == 0 */
- z2 = d5 + d3;
-
- z5 = MULTIPLY(z2, FIX_1_175875602);
- tmp1 = MULTIPLY(d5, FIX_1_662939225);
- z4 = MULTIPLY(-d5, FIX_0_390180644);
- z2 = MULTIPLY(-z2, FIX_1_387039845);
- tmp2 = MULTIPLY(d3, FIX_1_111140466);
- z3 = MULTIPLY(-d3, FIX_1_961570560);
-
- tmp0 = z3 + z5;
- tmp1 += z2;
- tmp2 += z2;
- tmp3 = z4 + z5;
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 != 0, d7 == 0 */
- z4 = d5 + d1;
-
- z5 = MULTIPLY(z4, FIX_1_175875602);
- z1 = MULTIPLY(-d1, FIX_0_899976223);
- tmp3 = MULTIPLY(d1, FIX_0_601344887);
- tmp1 = MULTIPLY(-d5, FIX_0_509795579);
- z2 = MULTIPLY(-d5, FIX_2_562915447);
- z4 = MULTIPLY(z4, FIX_0_785694958);
-
- tmp0 = z1 + z5;
- tmp1 += z4;
- tmp2 = z2 + z5;
- tmp3 += z4;
- } else {
- /* d1 == 0, d3 == 0, d5 != 0, d7 == 0 */
- tmp0 = MULTIPLY(d5, FIX_1_175875602);
- tmp1 = MULTIPLY(d5, FIX_0_275899380);
- tmp2 = MULTIPLY(-d5, FIX_1_387039845);
- tmp3 = MULTIPLY(d5, FIX_0_785694958);
- }
- }
- } else {
- if (d3) {
- if (d1) {
- /* d1 != 0, d3 != 0, d5 == 0, d7 == 0 */
- z5 = d1 + d3;
- tmp3 = MULTIPLY(d1, FIX_0_211164243);
- tmp2 = MULTIPLY(-d3, FIX_1_451774981);
- z1 = MULTIPLY(d1, FIX_1_061594337);
- z2 = MULTIPLY(-d3, FIX_2_172734803);
- z4 = MULTIPLY(z5, FIX_0_785694958);
- z5 = MULTIPLY(z5, FIX_1_175875602);
-
- tmp0 = z1 - z4;
- tmp1 = z2 + z4;
- tmp2 += z5;
- tmp3 += z5;
- } else {
- /* d1 == 0, d3 != 0, d5 == 0, d7 == 0 */
- tmp0 = MULTIPLY(-d3, FIX_0_785694958);
- tmp1 = MULTIPLY(-d3, FIX_1_387039845);
- tmp2 = MULTIPLY(-d3, FIX_0_275899380);
- tmp3 = MULTIPLY(d3, FIX_1_175875602);
- }
- } else {
- if (d1) {
- /* d1 != 0, d3 == 0, d5 == 0, d7 == 0 */
- tmp0 = MULTIPLY(d1, FIX_0_275899380);
- tmp1 = MULTIPLY(d1, FIX_0_785694958);
- tmp2 = MULTIPLY(d1, FIX_1_175875602);
- tmp3 = MULTIPLY(d1, FIX_1_387039845);
- } else {
- /* d1 == 0, d3 == 0, d5 == 0, d7 == 0 */
- tmp0 = tmp1 = tmp2 = tmp3 = 0;
- }
- }
- }
- }
-
- /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
-
- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0,
- CONST_BITS+PASS1_BITS+3);
- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0,
- CONST_BITS+PASS1_BITS+3);
-
- dataptr++; /* advance pointer to next column */
- }
-}
-
-#undef FIX
-#undef CONST_BITS
+++ /dev/null
-/*
- * a52.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef A52_H
-#define A52_H
-
-#include "../avcodec.h"
-
-#undef malloc
-#undef free
-#undef realloc
-
-#if defined(LIBA52_FIXED)
-typedef int32_t sample_t;
-typedef int32_t level_t;
-#elif defined(LIBA52_DOUBLE)
-typedef double sample_t;
-typedef double level_t;
-#else
-typedef float sample_t;
-typedef float level_t;
-#endif
-
-typedef struct a52_state_s a52_state_t;
-
-#define A52_CHANNEL 0
-#define A52_MONO 1
-#define A52_STEREO 2
-#define A52_3F 3
-#define A52_2F1R 4
-#define A52_3F1R 5
-#define A52_2F2R 6
-#define A52_3F2R 7
-#define A52_CHANNEL1 8
-#define A52_CHANNEL2 9
-#define A52_DOLBY 10
-#define A52_CHANNEL_MASK 15
-
-#define A52_LFE 16
-#define A52_ADJUST_LEVEL 32
-
-a52_state_t * a52_init (uint32_t mm_accel);
-sample_t * a52_samples (a52_state_t * state);
-int a52_syncinfo (uint8_t * buf, int * flags,
- int * sample_rate, int * bit_rate);
-int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
- level_t * level, sample_t bias);
-void a52_dynrng (a52_state_t * state,
- level_t (* call) (level_t, void *), void * data);
-int a52_block (a52_state_t * state);
-void a52_free (a52_state_t * state);
-
-#endif /* A52_H */
+++ /dev/null
-/*
- * a52_internal.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-typedef struct {
- uint8_t bai; /* fine SNR offset, fast gain */
- uint8_t deltbae; /* delta bit allocation exists */
- int8_t deltba[50]; /* per-band delta bit allocation */
-} ba_t;
-
-typedef struct {
- uint8_t exp[256]; /* decoded channel exponents */
- int8_t bap[256]; /* derived channel bit allocation */
-} expbap_t;
-
-struct a52_state_s {
- uint8_t fscod; /* sample rate */
- uint8_t halfrate; /* halfrate factor */
- uint8_t acmod; /* coded channels */
- uint8_t lfeon; /* coded lfe channel */
- level_t clev; /* centre channel mix level */
- level_t slev; /* surround channels mix level */
-
- int output; /* type of output */
- level_t level; /* output level */
- sample_t bias; /* output bias */
-
- int dynrnge; /* apply dynamic range */
- level_t dynrng; /* dynamic range */
- void * dynrngdata; /* dynamic range callback funtion and data */
- level_t (* dynrngcall) (level_t range, void * dynrngdata);
-
- uint8_t chincpl; /* channel coupled */
- uint8_t phsflginu; /* phase flags in use (stereo only) */
- uint8_t cplstrtmant; /* coupling channel start mantissa */
- uint8_t cplendmant; /* coupling channel end mantissa */
- uint32_t cplbndstrc; /* coupling band structure */
- level_t cplco[5][18]; /* coupling coordinates */
-
- /* derived information */
- uint8_t cplstrtbnd; /* coupling start band (for bit allocation) */
- uint8_t ncplbnd; /* number of coupling bands */
-
- uint8_t rematflg; /* stereo rematrixing */
-
- uint8_t endmant[5]; /* channel end mantissa */
-
- uint16_t bai; /* bit allocation information */
-
- uint32_t * buffer_start;
- uint16_t lfsr_state; /* dither state */
- uint32_t bits_left;
- uint32_t current_word;
-
- uint8_t csnroffst; /* coarse SNR offset */
- ba_t cplba; /* coupling bit allocation parameters */
- ba_t ba[5]; /* channel bit allocation parameters */
- ba_t lfeba; /* lfe bit allocation parameters */
-
- uint8_t cplfleak; /* coupling fast leak init */
- uint8_t cplsleak; /* coupling slow leak init */
-
- expbap_t cpl_expbap;
- expbap_t fbw_expbap[5];
- expbap_t lfe_expbap;
-
- sample_t * samples;
- int downmixed;
-};
-
-#define LEVEL_PLUS6DB 2.0
-#define LEVEL_PLUS3DB 1.4142135623730951
-#define LEVEL_3DB 0.7071067811865476
-#define LEVEL_45DB 0.5946035575013605
-#define LEVEL_6DB 0.5
-
-#define EXP_REUSE (0)
-#define EXP_D15 (1)
-#define EXP_D25 (2)
-#define EXP_D45 (3)
-
-#define DELTA_BIT_REUSE (0)
-#define DELTA_BIT_NEW (1)
-#define DELTA_BIT_NONE (2)
-#define DELTA_BIT_RESERVED (3)
-
-void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
- int start, int end, int fastleak, int slowleak,
- expbap_t * expbap);
-
-int a52_downmix_init (int input, int flags, level_t * level,
- level_t clev, level_t slev);
-int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
- level_t clev, level_t slev);
-void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
- level_t clev, level_t slev);
-void a52_upmix (sample_t * samples, int acmod, int output);
-
-void a52_imdct_init (uint32_t mm_accel);
-void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias);
-void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias);
-//extern void (* a52_imdct_256) (sample_t data[], sample_t delay[], sample_t bias);
-//extern void (* a52_imdct_512) (sample_t data[], sample_t delay[], sample_t bias);
-
-#define ROUND(x) ((int)((x) + ((x) > 0 ? 0.5 : -0.5)))
-
-#ifndef LIBA52_FIXED
-
-typedef sample_t quantizer_t;
-#define SAMPLE(x) (x)
-#define LEVEL(x) (x)
-#define MUL(a,b) ((a) * (b))
-#define MUL_L(a,b) ((a) * (b))
-#define MUL_C(a,b) ((a) * (b))
-#define DIV(a,b) ((a) / (b))
-#define BIAS(x) ((x) + bias)
-
-#else /* LIBA52_FIXED */
-
-typedef int16_t quantizer_t;
-#define SAMPLE(x) (sample_t)((x) * (1 << 30))
-#define LEVEL(x) (level_t)((x) * (1 << 26))
-
-#if 0
-#define MUL(a,b) ((int)(((int64_t)(a) * (b) + (1 << 29)) >> 30))
-#define MUL_L(a,b) ((int)(((int64_t)(a) * (b) + (1 << 25)) >> 26))
-#elif 1
-#define MUL(a,b) \
-({ int32_t _ta=(a), _tb=(b), _tc; \
- _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)(((_tc >> 14))+ (((_ta >> 16)*(_tb >> 16)) << 2 )); })
-#define MUL_L(a,b) \
-({ int32_t _ta=(a), _tb=(b), _tc; \
- _tc=(_ta & 0xffff)*(_tb >> 16)+(_ta >> 16)*(_tb & 0xffff); (int32_t)((_tc >> 10) + (((_ta >> 16)*(_tb >> 16)) << 6)); })
-#else
-#define MUL(a,b) (((a) >> 15) * ((b) >> 15))
-#define MUL_L(a,b) (((a) >> 13) * ((b) >> 13))
-#endif
-
-#define MUL_C(a,b) MUL_L (a, LEVEL (b))
-#define DIV(a,b) ((((int64_t)LEVEL (a)) << 26) / (b))
-#define BIAS(x) (x)
-
-#endif
+++ /dev/null
-/*
- * a52_util.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef A52_UTIL_H
-#define A52_UTIL_H
-
-uint16_t a52_crc16_block(uint8_t *data,uint32_t num_bytes);
-
-void* a52_resample_init(uint32_t mm_accel,int flags,int chans);
-extern int (* a52_resample) (float * _f, int16_t * s16);
-
-#endif /* A52_H */
+++ /dev/null
-/*
- * bit_allocate.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "a52.h"
-#include "a52_internal.h"
-
-static int hthtab[3][50] = {
- {0x730, 0x730, 0x7c0, 0x800, 0x820, 0x840, 0x850, 0x850, 0x860, 0x860,
- 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x890, 0x890,
- 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900,
- 0x910, 0x910, 0x910, 0x910, 0x900, 0x8f0, 0x8c0, 0x870, 0x820, 0x7e0,
- 0x7a0, 0x770, 0x760, 0x7a0, 0x7c0, 0x7c0, 0x6e0, 0x400, 0x3c0, 0x3c0},
- {0x710, 0x710, 0x7a0, 0x7f0, 0x820, 0x830, 0x840, 0x850, 0x850, 0x860,
- 0x860, 0x860, 0x860, 0x860, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880,
- 0x890, 0x890, 0x8a0, 0x8a0, 0x8b0, 0x8b0, 0x8c0, 0x8c0, 0x8e0, 0x8f0,
- 0x900, 0x910, 0x910, 0x910, 0x910, 0x900, 0x8e0, 0x8b0, 0x870, 0x820,
- 0x7e0, 0x7b0, 0x760, 0x770, 0x7a0, 0x7c0, 0x780, 0x5d0, 0x3c0, 0x3c0},
- {0x680, 0x680, 0x750, 0x7b0, 0x7e0, 0x810, 0x820, 0x830, 0x840, 0x850,
- 0x850, 0x850, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860, 0x860,
- 0x870, 0x870, 0x870, 0x870, 0x880, 0x880, 0x880, 0x890, 0x8a0, 0x8b0,
- 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x900, 0x910, 0x910, 0x910, 0x900, 0x8f0,
- 0x8d0, 0x8b0, 0x840, 0x7f0, 0x790, 0x760, 0x7a0, 0x7c0, 0x7b0, 0x720}
-};
-
-static int8_t baptab[305] = {
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, /* 93 padding elems */
-
- 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 14, 14, 14, 14,
- 14, 12, 12, 12, 12, 11, 11, 11, 11, 10, 10, 10, 10, 9, 9, 9,
- 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5,
- 5, 4, 4, -3, -3, 3, 3, 3, -2, -2, -1, -1, -1, -1, -1, 0,
-
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0 /* 148 padding elems */
-};
-
-static int bndtab[30] = {21, 22, 23, 24, 25, 26, 27, 28, 31, 34,
- 37, 40, 43, 46, 49, 55, 61, 67, 73, 79,
- 85, 97, 109, 121, 133, 157, 181, 205, 229, 253};
-
-static int8_t latab[256] = {
- -64, -63, -62, -61, -60, -59, -58, -57, -56, -55, -54, -53,
- -52, -52, -51, -50, -49, -48, -47, -47, -46, -45, -44, -44,
- -43, -42, -41, -41, -40, -39, -38, -38, -37, -36, -36, -35,
- -35, -34, -33, -33, -32, -32, -31, -30, -30, -29, -29, -28,
- -28, -27, -27, -26, -26, -25, -25, -24, -24, -23, -23, -22,
- -22, -21, -21, -21, -20, -20, -19, -19, -19, -18, -18, -18,
- -17, -17, -17, -16, -16, -16, -15, -15, -15, -14, -14, -14,
- -13, -13, -13, -13, -12, -12, -12, -12, -11, -11, -11, -11,
- -10, -10, -10, -10, -10, -9, -9, -9, -9, -9, -8, -8,
- -8, -8, -8, -8, -7, -7, -7, -7, -7, -7, -6, -6,
- -6, -6, -6, -6, -6, -6, -5, -5, -5, -5, -5, -5,
- -5, -5, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4,
- -4, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
- -3, -3, -3, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0
-};
-
-#define UPDATE_LEAK() \
-do { \
- fastleak += fdecay; \
- if (fastleak > psd + fgain) \
- fastleak = psd + fgain; \
- slowleak += sdecay; \
- if (slowleak > psd + sgain) \
- slowleak = psd + sgain; \
-} while (0)
-
-#define COMPUTE_MASK() \
-do { \
- if (psd > dbknee) \
- mask -= (psd - dbknee) >> 2; \
- if (mask > hth [i >> halfrate]) \
- mask = hth [i >> halfrate]; \
- mask -= snroffset + 128 * deltba[i]; \
- mask = (mask > 0) ? 0 : ((-mask) >> 5); \
- mask -= floor; \
-} while (0)
-
-void a52_bit_allocate (a52_state_t * state, ba_t * ba, int bndstart,
- int start, int end, int fastleak, int slowleak,
- expbap_t * expbap)
-{
- static int slowgain[4] = {0x540, 0x4d8, 0x478, 0x410};
- static int dbpbtab[4] = {0xc00, 0x500, 0x300, 0x100};
- static int floortab[8] = {0x910, 0x950, 0x990, 0x9d0,
- 0xa10, 0xa90, 0xb10, 0x1400};
-
- int i, j;
- uint8_t * exp;
- int8_t * bap;
- int fdecay, fgain, sdecay, sgain, dbknee, floor, snroffset;
- int psd, mask;
- int8_t * deltba;
- int * hth;
- int halfrate;
-
- halfrate = state->halfrate;
- fdecay = (63 + 20 * ((state->bai >> 7) & 3)) >> halfrate; /* fdcycod */
- fgain = 128 + 128 * (ba->bai & 7); /* fgaincod */
- sdecay = (15 + 2 * (state->bai >> 9)) >> halfrate; /* sdcycod */
- sgain = slowgain[(state->bai >> 5) & 3]; /* sgaincod */
- dbknee = dbpbtab[(state->bai >> 3) & 3]; /* dbpbcod */
- hth = hthtab[state->fscod];
- /*
- * if there is no delta bit allocation, make deltba point to an area
- * known to contain zeroes. baptab+156 here.
- */
- deltba = (ba->deltbae == DELTA_BIT_NONE) ? baptab + 156 : ba->deltba;
- floor = floortab[state->bai & 7]; /* floorcod */
- snroffset = 960 - 64 * state->csnroffst - 4 * (ba->bai >> 3) + floor;
- floor >>= 5;
-
- exp = expbap->exp;
- bap = expbap->bap;
-
- i = bndstart;
- j = start;
- if (start == 0) { /* not the coupling channel */
- int lowcomp;
-
- lowcomp = 0;
- j = end - 1;
- do {
- if (i < j) {
- if (exp[i+1] == exp[i] - 2)
- lowcomp = 384;
- else if (lowcomp && (exp[i+1] > exp[i]))
- lowcomp -= 64;
- }
- psd = 128 * exp[i];
- mask = psd + fgain + lowcomp;
- COMPUTE_MASK ();
- bap[i] = (baptab+156)[mask + 4 * exp[i]];
- i++;
- } while ((i < 3) || ((i < 7) && (exp[i] > exp[i-1])));
- fastleak = psd + fgain;
- slowleak = psd + sgain;
-
- while (i < 7) {
- if (i < j) {
- if (exp[i+1] == exp[i] - 2)
- lowcomp = 384;
- else if (lowcomp && (exp[i+1] > exp[i]))
- lowcomp -= 64;
- }
- psd = 128 * exp[i];
- UPDATE_LEAK ();
- mask = ((fastleak + lowcomp < slowleak) ?
- fastleak + lowcomp : slowleak);
- COMPUTE_MASK ();
- bap[i] = (baptab+156)[mask + 4 * exp[i]];
- i++;
- }
-
- if (end == 7) /* lfe channel */
- return;
-
- do {
- if (exp[i+1] == exp[i] - 2)
- lowcomp = 320;
- else if (lowcomp && (exp[i+1] > exp[i]))
- lowcomp -= 64;
- psd = 128 * exp[i];
- UPDATE_LEAK ();
- mask = ((fastleak + lowcomp < slowleak) ?
- fastleak + lowcomp : slowleak);
- COMPUTE_MASK ();
- bap[i] = (baptab+156)[mask + 4 * exp[i]];
- i++;
- } while (i < 20);
-
- while (lowcomp > 128) { /* two iterations maximum */
- lowcomp -= 128;
- psd = 128 * exp[i];
- UPDATE_LEAK ();
- mask = ((fastleak + lowcomp < slowleak) ?
- fastleak + lowcomp : slowleak);
- COMPUTE_MASK ();
- bap[i] = (baptab+156)[mask + 4 * exp[i]];
- i++;
- }
- j = i;
- }
-
- do {
- int startband, endband;
-
- startband = j;
- endband = (bndtab[i-20] < end) ? bndtab[i-20] : end;
- psd = 128 * exp[j++];
- while (j < endband) {
- int next, delta;
-
- next = 128 * exp[j++];
- delta = next - psd;
- switch (delta >> 9) {
- case -6: case -5: case -4: case -3: case -2:
- psd = next;
- break;
- case -1:
- psd = next + latab[(-delta) >> 1];
- break;
- case 0:
- psd += latab[delta >> 1];
- break;
- }
- }
- /* minpsd = -289 */
- UPDATE_LEAK ();
- mask = (fastleak < slowleak) ? fastleak : slowleak;
- COMPUTE_MASK ();
- i++;
- j = startband;
- do {
- /* max(mask+4*exp)=147=-(minpsd+fgain-deltba-snroffset)>>5+4*exp */
- /* min(mask+4*exp)=-156=-(sgain-deltba-snroffset)>>5 */
- bap[j] = (baptab+156)[mask + 4 * exp[j]];
- } while (++j < endband);
- } while (j < end);
-}
+++ /dev/null
-/*
- * bitstream.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "a52.h"
-#include "a52_internal.h"
-#include "bitstream.h"
-
-#define BUFFER_SIZE 4096
-
-void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
-{
- int align;
-
- align = (long)buf & 3;
- state->buffer_start = (uint32_t *) (buf - align);
- state->bits_left = 0;
- state->current_word = 0;
- bitstream_get (state, align * 8);
-}
-
-static inline void bitstream_fill_current (a52_state_t * state)
-{
- uint32_t tmp;
-
- tmp = *(state->buffer_start++);
- state->current_word = swab32 (tmp);
-}
-
-/*
- * The fast paths for _get is in the
- * bitstream.h header file so it can be inlined.
- *
- * The "bottom half" of this routine is suffixed _bh
- *
- * -ah
- */
-
-uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits)
-{
- uint32_t result;
-
- num_bits -= state->bits_left;
- result = ((state->current_word << (32 - state->bits_left)) >>
- (32 - state->bits_left));
-
- bitstream_fill_current (state);
-
- if (num_bits != 0)
- result = (result << num_bits) | (state->current_word >> (32 - num_bits));
-
- state->bits_left = 32 - num_bits;
-
- return result;
-}
-
-int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits)
-{
- int32_t result;
-
- num_bits -= state->bits_left;
- result = ((((int32_t)state->current_word) << (32 - state->bits_left)) >>
- (32 - state->bits_left));
-
- bitstream_fill_current(state);
-
- if (num_bits != 0)
- result = (result << num_bits) | (state->current_word >> (32 - num_bits));
-
- state->bits_left = 32 - num_bits;
-
- return result;
-}
+++ /dev/null
-/*
- * bitstream.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/* (stolen from the kernel) */
-#ifdef WORDS_BIGENDIAN
-
-# define swab32(x) (x)
-
-#else
-
-# if 0 && defined (__i386__)
-
-# define swab32(x) __i386_swab32(x)
- static inline const uint32_t __i386_swab32(uint32_t x)
- {
- __asm__("bswap %0" : "=r" (x) : "0" (x));
- return x;
- }
-
-# else
-
-# define swab32(x)\
-((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \
- (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3]))
-
-# endif
-#endif
-
-void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
-uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
-int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
-
-static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
-{
- uint32_t result;
-
- if (num_bits < state->bits_left) {
- result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
- state->bits_left -= num_bits;
- return result;
- }
-
- return a52_bitstream_get_bh (state, num_bits);
-}
-
-static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
-{
- int32_t result;
-
- if (num_bits < state->bits_left) {
- result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
- state->bits_left -= num_bits;
- return result;
- }
-
- return a52_bitstream_get_bh_2 (state, num_bits);
-}
+++ /dev/null
-/*
- * crc.c
- *
- * Copyright (C) Aaron Holtzman - May 1999
- *
- * This file is part of ac3dec, a free Dolby AC-3 stream decoder.
- *
- * ac3dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * ac3dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GNU Make; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <inttypes.h>
-
-static const uint16_t crc_lut[256] =
-{
- 0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011,
- 0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022,
- 0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072,
- 0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041,
- 0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2,
- 0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1,
- 0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1,
- 0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082,
- 0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192,
- 0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1,
- 0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1,
- 0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2,
- 0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151,
- 0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162,
- 0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132,
- 0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101,
- 0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312,
- 0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321,
- 0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371,
- 0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342,
- 0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1,
- 0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2,
- 0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2,
- 0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381,
- 0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291,
- 0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2,
- 0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2,
- 0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1,
- 0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252,
- 0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261,
- 0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231,
- 0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202
-};
-
-uint16_t a52_crc16_block(uint8_t *data,uint32_t num_bytes)
-{
- uint32_t i;
- uint16_t state=0;
-
- for(i=0;i<num_bytes;i++)
- state = crc_lut[data[i] ^ (state>>8)] ^ (state<<8);
-
- return state;
-}
+++ /dev/null
-/*
- * downmix.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "a52.h"
-#include "a52_internal.h"
-
-#define CONVERT(acmod,output) (((output) << 3) + (acmod))
-
-int a52_downmix_init (int input, int flags, level_t * level,
- level_t clev, level_t slev)
-{
- static uint8_t table[11][8] = {
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
- A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
- {A52_MONO, A52_MONO, A52_MONO, A52_MONO,
- A52_MONO, A52_MONO, A52_MONO, A52_MONO},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
- A52_STEREO, A52_STEREO, A52_STEREO, A52_STEREO},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
- A52_STEREO, A52_3F, A52_STEREO, A52_3F},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
- A52_2F1R, A52_2F1R, A52_2F1R, A52_2F1R},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_STEREO,
- A52_2F1R, A52_3F1R, A52_2F1R, A52_3F1R},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
- A52_2F2R, A52_2F2R, A52_2F2R, A52_2F2R},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_3F,
- A52_2F2R, A52_3F2R, A52_2F2R, A52_3F2R},
- {A52_CHANNEL1, A52_MONO, A52_MONO, A52_MONO,
- A52_MONO, A52_MONO, A52_MONO, A52_MONO},
- {A52_CHANNEL2, A52_MONO, A52_MONO, A52_MONO,
- A52_MONO, A52_MONO, A52_MONO, A52_MONO},
- {A52_CHANNEL, A52_DOLBY, A52_STEREO, A52_DOLBY,
- A52_DOLBY, A52_DOLBY, A52_DOLBY, A52_DOLBY}
- };
- int output;
-
- output = flags & A52_CHANNEL_MASK;
- if (output > A52_DOLBY)
- return -1;
-
- output = table[output][input & 7];
-
- if (output == A52_STEREO &&
- (input == A52_DOLBY || (input == A52_3F && clev == LEVEL (LEVEL_3DB))))
- output = A52_DOLBY;
-
- if (flags & A52_ADJUST_LEVEL) {
- level_t adjust;
-
- switch (CONVERT (input & 7, output)) {
-
- case CONVERT (A52_3F, A52_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev);
- break;
-
- case CONVERT (A52_STEREO, A52_MONO):
- case CONVERT (A52_2F2R, A52_2F1R):
- case CONVERT (A52_3F2R, A52_3F1R):
- level_3db:
- adjust = LEVEL (LEVEL_3DB);
- break;
-
- case CONVERT (A52_3F2R, A52_2F1R):
- if (clev < LEVEL (LEVEL_PLUS3DB - 1))
- goto level_3db;
- /* break thru */
- case CONVERT (A52_3F, A52_STEREO):
- case CONVERT (A52_3F1R, A52_2F1R):
- case CONVERT (A52_3F1R, A52_2F2R):
- case CONVERT (A52_3F2R, A52_2F2R):
- adjust = DIV (1, LEVEL (1) + clev);
- break;
-
- case CONVERT (A52_2F1R, A52_MONO):
- adjust = DIV (LEVEL_PLUS3DB, LEVEL (2) + slev);
- break;
-
- case CONVERT (A52_2F1R, A52_STEREO):
- case CONVERT (A52_3F1R, A52_3F):
- adjust = DIV (1, LEVEL (1) + MUL_C (slev, LEVEL_3DB));
- break;
-
- case CONVERT (A52_3F1R, A52_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + MUL_C (slev, 0.5));
- break;
-
- case CONVERT (A52_3F1R, A52_STEREO):
- adjust = DIV (1, LEVEL (1) + clev + MUL_C (slev, LEVEL_3DB));
- break;
-
- case CONVERT (A52_2F2R, A52_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + slev);
- break;
-
- case CONVERT (A52_2F2R, A52_STEREO):
- case CONVERT (A52_3F2R, A52_3F):
- adjust = DIV (1, LEVEL (1) + slev);
- break;
-
- case CONVERT (A52_3F2R, A52_MONO):
- adjust = DIV (LEVEL_3DB, LEVEL (1) + clev + slev);
- break;
-
- case CONVERT (A52_3F2R, A52_STEREO):
- adjust = DIV (1, LEVEL (1) + clev + slev);
- break;
-
- case CONVERT (A52_MONO, A52_DOLBY):
- adjust = LEVEL (LEVEL_PLUS3DB);
- break;
-
- case CONVERT (A52_3F, A52_DOLBY):
- case CONVERT (A52_2F1R, A52_DOLBY):
- adjust = LEVEL (1 / (1 + LEVEL_3DB));
- break;
-
- case CONVERT (A52_3F1R, A52_DOLBY):
- case CONVERT (A52_2F2R, A52_DOLBY):
- adjust = LEVEL (1 / (1 + 2 * LEVEL_3DB));
- break;
-
- case CONVERT (A52_3F2R, A52_DOLBY):
- adjust = LEVEL (1 / (1 + 3 * LEVEL_3DB));
- break;
-
- default:
- return output;
- }
-
- *level = MUL_L (*level, adjust);
- }
-
- return output;
-}
-
-int a52_downmix_coeff (level_t * coeff, int acmod, int output, level_t level,
- level_t clev, level_t slev)
-{
- level_t level_3db;
-
- level_3db = MUL_C (level, LEVEL_3DB);
-
- switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
-
- case CONVERT (A52_CHANNEL, A52_CHANNEL):
- case CONVERT (A52_MONO, A52_MONO):
- case CONVERT (A52_STEREO, A52_STEREO):
- case CONVERT (A52_3F, A52_3F):
- case CONVERT (A52_2F1R, A52_2F1R):
- case CONVERT (A52_3F1R, A52_3F1R):
- case CONVERT (A52_2F2R, A52_2F2R):
- case CONVERT (A52_3F2R, A52_3F2R):
- case CONVERT (A52_STEREO, A52_DOLBY):
- coeff[0] = coeff[1] = coeff[2] = coeff[3] = coeff[4] = level;
- return 0;
-
- case CONVERT (A52_CHANNEL, A52_MONO):
- coeff[0] = coeff[1] = MUL_C (level, LEVEL_6DB);
- return 3;
-
- case CONVERT (A52_STEREO, A52_MONO):
- coeff[0] = coeff[1] = level_3db;
- return 3;
-
- case CONVERT (A52_3F, A52_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- return 7;
-
- case CONVERT (A52_2F1R, A52_MONO):
- coeff[0] = coeff[1] = level_3db;
- coeff[2] = MUL_L (level_3db, slev);
- return 7;
-
- case CONVERT (A52_2F2R, A52_MONO):
- coeff[0] = coeff[1] = level_3db;
- coeff[2] = coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (A52_3F1R, A52_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (A52_3F2R, A52_MONO):
- coeff[0] = coeff[2] = level_3db;
- coeff[1] = MUL_C (MUL_L (level_3db, clev), LEVEL_PLUS6DB);
- coeff[3] = coeff[4] = MUL_L (level_3db, slev);
- return 31;
-
- case CONVERT (A52_MONO, A52_DOLBY):
- coeff[0] = level_3db;
- return 0;
-
- case CONVERT (A52_3F, A52_DOLBY):
- coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
- coeff[1] = level_3db;
- return 7;
-
- case CONVERT (A52_3F, A52_STEREO):
- case CONVERT (A52_3F1R, A52_2F1R):
- case CONVERT (A52_3F2R, A52_2F2R):
- coeff[0] = coeff[2] = coeff[3] = coeff[4] = level;
- coeff[1] = MUL_L (level, clev);
- return 7;
-
- case CONVERT (A52_2F1R, A52_DOLBY):
- coeff[0] = coeff[1] = level;
- coeff[2] = level_3db;
- return 7;
-
- case CONVERT (A52_2F1R, A52_STEREO):
- coeff[0] = coeff[1] = level;
- coeff[2] = MUL_L (level_3db, slev);
- return 7;
-
- case CONVERT (A52_3F1R, A52_DOLBY):
- coeff[0] = coeff[2] = level;
- coeff[1] = coeff[3] = level_3db;
- return 15;
-
- case CONVERT (A52_3F1R, A52_STEREO):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = MUL_L (level_3db, slev);
- return 15;
-
- case CONVERT (A52_2F2R, A52_DOLBY):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = level_3db;
- return 15;
-
- case CONVERT (A52_2F2R, A52_STEREO):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = MUL_L (level, slev);
- return 15;
-
- case CONVERT (A52_3F2R, A52_DOLBY):
- coeff[0] = coeff[2] = level;
- coeff[1] = coeff[3] = coeff[4] = level_3db;
- return 31;
-
- case CONVERT (A52_3F2R, A52_2F1R):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = coeff[4] = level_3db;
- return 31;
-
- case CONVERT (A52_3F2R, A52_STEREO):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = coeff[4] = MUL_L (level, slev);
- return 31;
-
- case CONVERT (A52_3F1R, A52_3F):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = MUL_L (level_3db, slev);
- return 13;
-
- case CONVERT (A52_3F2R, A52_3F):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = coeff[4] = MUL_L (level, slev);
- return 29;
-
- case CONVERT (A52_2F2R, A52_2F1R):
- coeff[0] = coeff[1] = level;
- coeff[2] = coeff[3] = level_3db;
- return 12;
-
- case CONVERT (A52_3F2R, A52_3F1R):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = coeff[4] = level_3db;
- return 24;
-
- case CONVERT (A52_2F1R, A52_2F2R):
- coeff[0] = coeff[1] = level;
- coeff[2] = level_3db;
- return 0;
-
- case CONVERT (A52_3F1R, A52_2F2R):
- coeff[0] = coeff[2] = level;
- coeff[1] = MUL_L (level, clev);
- coeff[3] = level_3db;
- return 7;
-
- case CONVERT (A52_3F1R, A52_3F2R):
- coeff[0] = coeff[1] = coeff[2] = level;
- coeff[3] = level_3db;
- return 0;
-
- case CONVERT (A52_CHANNEL, A52_CHANNEL1):
- coeff[0] = level;
- coeff[1] = 0;
- return 0;
-
- case CONVERT (A52_CHANNEL, A52_CHANNEL2):
- coeff[0] = 0;
- coeff[1] = level;
- return 0;
- }
-
- return -1; /* NOTREACHED */
-}
-
-static void mix2to1 (sample_t * dest, sample_t * src, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- dest[i] += BIAS (src[i]);
-}
-
-static void mix3to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512]);
-}
-
-static void mix4to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
- samples[i + 768]);
-}
-
-static void mix5to1 (sample_t * samples, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] += BIAS (samples[i + 256] + samples[i + 512] +
- samples[i + 768] + samples[i + 1024]);
-}
-
-static void mix3to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i + 256]);
- samples[i] += common;
- samples[i + 256] = samples[i + 512] + common;
- }
-}
-
-static void mix21to2 (sample_t * left, sample_t * right, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (right[i + 256]);
- left[i] += common;
- right[i] += common;
- }
-}
-
-static void mix21toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t surround;
-
- for (i = 0; i < 256; i++) {
- surround = samples[i + 512];
- samples[i] += BIAS (-surround);
- samples[i + 256] += BIAS (surround);
- }
-}
-
-static void mix31to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i + 256] + samples[i + 768]);
- samples[i] += common;
- samples[i + 256] = samples[i + 512] + common;
- }
-}
-
-static void mix31toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common, surround;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i + 256]);
- surround = samples[i + 768];
- samples[i] += common - surround;
- samples[i + 256] = samples[i + 512] + common + surround;
- }
-}
-
-static void mix22toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t surround;
-
- for (i = 0; i < 256; i++) {
- surround = samples[i + 512] + samples[i + 768];
- samples[i] += BIAS (-surround);
- samples[i + 256] += BIAS (surround);
- }
-}
-
-static void mix32to2 (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i + 256]);
- samples[i] += common + samples[i + 768];
- samples[i + 256] = common + samples[i + 512] + samples[i + 1024];
- }
-}
-
-static void mix32toS (sample_t * samples, sample_t bias)
-{
- int i;
- sample_t common, surround;
-
- for (i = 0; i < 256; i++) {
- common = BIAS (samples[i + 256]);
- surround = samples[i + 768] + samples[i + 1024];
- samples[i] += common - surround;
- samples[i + 256] = samples[i + 512] + common + surround;
- }
-}
-
-static void move2to1 (sample_t * src, sample_t * dest, sample_t bias)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- dest[i] = BIAS (src[i] + src[i + 256]);
-}
-
-static void zero (sample_t * samples)
-{
- int i;
-
- for (i = 0; i < 256; i++)
- samples[i] = 0;
-}
-
-void a52_downmix (sample_t * samples, int acmod, int output, sample_t bias,
- level_t clev, level_t slev)
-{
- switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
-
- case CONVERT (A52_CHANNEL, A52_CHANNEL2):
- memcpy (samples, samples + 256, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_CHANNEL, A52_MONO):
- case CONVERT (A52_STEREO, A52_MONO):
- mix_2to1:
- mix2to1 (samples, samples + 256, bias);
- break;
-
- case CONVERT (A52_2F1R, A52_MONO):
- if (slev == 0)
- goto mix_2to1;
- case CONVERT (A52_3F, A52_MONO):
- mix_3to1:
- mix3to1 (samples, bias);
- break;
-
- case CONVERT (A52_3F1R, A52_MONO):
- if (slev == 0)
- goto mix_3to1;
- case CONVERT (A52_2F2R, A52_MONO):
- if (slev == 0)
- goto mix_2to1;
- mix4to1 (samples, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_MONO):
- if (slev == 0)
- goto mix_3to1;
- mix5to1 (samples, bias);
- break;
-
- case CONVERT (A52_MONO, A52_DOLBY):
- memcpy (samples + 256, samples, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_3F, A52_STEREO):
- case CONVERT (A52_3F, A52_DOLBY):
- mix_3to2:
- mix3to2 (samples, bias);
- break;
-
- case CONVERT (A52_2F1R, A52_STEREO):
- if (slev == 0)
- break;
- mix21to2 (samples, samples + 256, bias);
- break;
-
- case CONVERT (A52_2F1R, A52_DOLBY):
- mix21toS (samples, bias);
- break;
-
- case CONVERT (A52_3F1R, A52_STEREO):
- if (slev == 0)
- goto mix_3to2;
- mix31to2 (samples, bias);
- break;
-
- case CONVERT (A52_3F1R, A52_DOLBY):
- mix31toS (samples, bias);
- break;
-
- case CONVERT (A52_2F2R, A52_STEREO):
- if (slev == 0)
- break;
- mix2to1 (samples, samples + 512, bias);
- mix2to1 (samples + 256, samples + 768, bias);
- break;
-
- case CONVERT (A52_2F2R, A52_DOLBY):
- mix22toS (samples, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_STEREO):
- if (slev == 0)
- goto mix_3to2;
- mix32to2 (samples, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_DOLBY):
- mix32toS (samples, bias);
- break;
-
- case CONVERT (A52_3F1R, A52_3F):
- if (slev == 0)
- break;
- mix21to2 (samples, samples + 512, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_3F):
- if (slev == 0)
- break;
- mix2to1 (samples, samples + 768, bias);
- mix2to1 (samples + 512, samples + 1024, bias);
- break;
-
- case CONVERT (A52_3F1R, A52_2F1R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_2F2R, A52_2F1R):
- mix2to1 (samples + 512, samples + 768, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_2F1R):
- mix3to2 (samples, bias);
- move2to1 (samples + 768, samples + 512, bias);
- break;
-
- case CONVERT (A52_3F2R, A52_3F1R):
- mix2to1 (samples + 768, samples + 1024, bias);
- break;
-
- case CONVERT (A52_2F1R, A52_2F2R):
- memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_3F1R, A52_2F2R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_3F2R, A52_2F2R):
- mix3to2 (samples, bias);
- memcpy (samples + 512, samples + 768, 256 * sizeof (sample_t));
- memcpy (samples + 768, samples + 1024, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_3F1R, A52_3F2R):
- memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
- break;
- }
-}
-
-void a52_upmix (sample_t * samples, int acmod, int output)
-{
- switch (CONVERT (acmod, output & A52_CHANNEL_MASK)) {
-
- case CONVERT (A52_CHANNEL, A52_CHANNEL2):
- memcpy (samples + 256, samples, 256 * sizeof (sample_t));
- break;
-
- case CONVERT (A52_3F2R, A52_MONO):
- zero (samples + 1024);
- case CONVERT (A52_3F1R, A52_MONO):
- case CONVERT (A52_2F2R, A52_MONO):
- zero (samples + 768);
- case CONVERT (A52_3F, A52_MONO):
- case CONVERT (A52_2F1R, A52_MONO):
- zero (samples + 512);
- case CONVERT (A52_CHANNEL, A52_MONO):
- case CONVERT (A52_STEREO, A52_MONO):
- zero (samples + 256);
- break;
-
- case CONVERT (A52_3F2R, A52_STEREO):
- case CONVERT (A52_3F2R, A52_DOLBY):
- zero (samples + 1024);
- case CONVERT (A52_3F1R, A52_STEREO):
- case CONVERT (A52_3F1R, A52_DOLBY):
- zero (samples + 768);
- case CONVERT (A52_3F, A52_STEREO):
- case CONVERT (A52_3F, A52_DOLBY):
- mix_3to2:
- memcpy (samples + 512, samples + 256, 256 * sizeof (sample_t));
- zero (samples + 256);
- break;
-
- case CONVERT (A52_2F2R, A52_STEREO):
- case CONVERT (A52_2F2R, A52_DOLBY):
- zero (samples + 768);
- case CONVERT (A52_2F1R, A52_STEREO):
- case CONVERT (A52_2F1R, A52_DOLBY):
- zero (samples + 512);
- break;
-
- case CONVERT (A52_3F2R, A52_3F):
- zero (samples + 1024);
- case CONVERT (A52_3F1R, A52_3F):
- case CONVERT (A52_2F2R, A52_2F1R):
- zero (samples + 768);
- break;
-
- case CONVERT (A52_3F2R, A52_3F1R):
- zero (samples + 1024);
- break;
-
- case CONVERT (A52_3F2R, A52_2F1R):
- zero (samples + 1024);
- case CONVERT (A52_3F1R, A52_2F1R):
- mix_31to21:
- memcpy (samples + 768, samples + 512, 256 * sizeof (sample_t));
- goto mix_3to2;
-
- case CONVERT (A52_3F2R, A52_2F2R):
- memcpy (samples + 1024, samples + 768, 256 * sizeof (sample_t));
- goto mix_31to21;
- }
-}
+++ /dev/null
-/*
- * imdct.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * The ifft algorithms in this file have been largely inspired by Dan
- * Bernstein's work, djbfft, available at http://cr.yp.to/djbfft.html
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "a52.h"
-#include "a52_internal.h"
-#include "mm_accel.h"
-
-typedef struct complex_s {
- sample_t real;
- sample_t imag;
-} complex_t;
-
-static uint8_t fftorder[] = {
- 0,128, 64,192, 32,160,224, 96, 16,144, 80,208,240,112, 48,176,
- 8,136, 72,200, 40,168,232,104,248,120, 56,184, 24,152,216, 88,
- 4,132, 68,196, 36,164,228,100, 20,148, 84,212,244,116, 52,180,
- 252,124, 60,188, 28,156,220, 92, 12,140, 76,204,236,108, 44,172,
- 2,130, 66,194, 34,162,226, 98, 18,146, 82,210,242,114, 50,178,
- 10,138, 74,202, 42,170,234,106,250,122, 58,186, 26,154,218, 90,
- 254,126, 62,190, 30,158,222, 94, 14,142, 78,206,238,110, 46,174,
- 6,134, 70,198, 38,166,230,102,246,118, 54,182, 22,150,214, 86
-};
-
-/* Root values for IFFT */
-static sample_t roots16[3];
-static sample_t roots32[7];
-static sample_t roots64[15];
-static sample_t roots128[31];
-
-/* Twiddle factors for IMDCT */
-static complex_t pre1[128];
-static complex_t post1[64];
-static complex_t pre2[64];
-static complex_t post2[32];
-
-static sample_t a52_imdct_window[256];
-
-static void (* ifft128) (complex_t * buf);
-static void (* ifft64) (complex_t * buf);
-
-static inline void ifft2 (complex_t * buf)
-{
- sample_t r, i;
-
- r = buf[0].real;
- i = buf[0].imag;
- buf[0].real += buf[1].real;
- buf[0].imag += buf[1].imag;
- buf[1].real = r - buf[1].real;
- buf[1].imag = i - buf[1].imag;
-}
-
-static inline void ifft4 (complex_t * buf)
-{
- sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
-
- tmp1 = buf[0].real + buf[1].real;
- tmp2 = buf[3].real + buf[2].real;
- tmp3 = buf[0].imag + buf[1].imag;
- tmp4 = buf[2].imag + buf[3].imag;
- tmp5 = buf[0].real - buf[1].real;
- tmp6 = buf[0].imag - buf[1].imag;
- tmp7 = buf[2].imag - buf[3].imag;
- tmp8 = buf[3].real - buf[2].real;
-
- buf[0].real = tmp1 + tmp2;
- buf[0].imag = tmp3 + tmp4;
- buf[2].real = tmp1 - tmp2;
- buf[2].imag = tmp3 - tmp4;
- buf[1].real = tmp5 + tmp7;
- buf[1].imag = tmp6 + tmp8;
- buf[3].real = tmp5 - tmp7;
- buf[3].imag = tmp6 - tmp8;
-}
-
-/* basic radix-2 ifft butterfly */
-
-#define BUTTERFLY_0(t0,t1,W0,W1,d0,d1) do { \
- t0 = MUL (W1, d1) + MUL (W0, d0); \
- t1 = MUL (W0, d1) - MUL (W1, d0); \
-} while (0)
-
-/* radix-2 ifft butterfly with bias */
-
-#define BUTTERFLY_B(t0,t1,W0,W1,d0,d1) do { \
- t0 = BIAS (MUL (d1, W1) + MUL (d0, W0)); \
- t1 = BIAS (MUL (d1, W0) - MUL (d0, W1)); \
-} while (0)
-
-/* the basic split-radix ifft butterfly */
-
-#define BUTTERFLY(a0,a1,a2,a3,wr,wi) do { \
- BUTTERFLY_0 (tmp5, tmp6, wr, wi, a2.real, a2.imag); \
- BUTTERFLY_0 (tmp8, tmp7, wr, wi, a3.imag, a3.real); \
- tmp1 = tmp5 + tmp7; \
- tmp2 = tmp6 + tmp8; \
- tmp3 = tmp6 - tmp8; \
- tmp4 = tmp7 - tmp5; \
- a2.real = a0.real - tmp1; \
- a2.imag = a0.imag - tmp2; \
- a3.real = a1.real - tmp3; \
- a3.imag = a1.imag - tmp4; \
- a0.real += tmp1; \
- a0.imag += tmp2; \
- a1.real += tmp3; \
- a1.imag += tmp4; \
-} while (0)
-
-/* split-radix ifft butterfly, specialized for wr=1 wi=0 */
-
-#define BUTTERFLY_ZERO(a0,a1,a2,a3) do { \
- tmp1 = a2.real + a3.real; \
- tmp2 = a2.imag + a3.imag; \
- tmp3 = a2.imag - a3.imag; \
- tmp4 = a3.real - a2.real; \
- a2.real = a0.real - tmp1; \
- a2.imag = a0.imag - tmp2; \
- a3.real = a1.real - tmp3; \
- a3.imag = a1.imag - tmp4; \
- a0.real += tmp1; \
- a0.imag += tmp2; \
- a1.real += tmp3; \
- a1.imag += tmp4; \
-} while (0)
-
-/* split-radix ifft butterfly, specialized for wr=wi */
-
-#define BUTTERFLY_HALF(a0,a1,a2,a3,w) do { \
- tmp5 = MUL (a2.real + a2.imag, w); \
- tmp6 = MUL (a2.imag - a2.real, w); \
- tmp7 = MUL (a3.real - a3.imag, w); \
- tmp8 = MUL (a3.imag + a3.real, w); \
- tmp1 = tmp5 + tmp7; \
- tmp2 = tmp6 + tmp8; \
- tmp3 = tmp6 - tmp8; \
- tmp4 = tmp7 - tmp5; \
- a2.real = a0.real - tmp1; \
- a2.imag = a0.imag - tmp2; \
- a3.real = a1.real - tmp3; \
- a3.imag = a1.imag - tmp4; \
- a0.real += tmp1; \
- a0.imag += tmp2; \
- a1.real += tmp3; \
- a1.imag += tmp4; \
-} while (0)
-
-static inline void ifft8 (complex_t * buf)
-{
- sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
-
- ifft4 (buf);
- ifft2 (buf + 4);
- ifft2 (buf + 6);
- BUTTERFLY_ZERO (buf[0], buf[2], buf[4], buf[6]);
- BUTTERFLY_HALF (buf[1], buf[3], buf[5], buf[7], roots16[1]);
-}
-
-static void ifft_pass (complex_t * buf, sample_t * weight, int n)
-{
- complex_t * buf1;
- complex_t * buf2;
- complex_t * buf3;
- sample_t tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
- int i;
-
- buf++;
- buf1 = buf + n;
- buf2 = buf + 2 * n;
- buf3 = buf + 3 * n;
-
- BUTTERFLY_ZERO (buf[-1], buf1[-1], buf2[-1], buf3[-1]);
-
- i = n - 1;
-
- do {
- BUTTERFLY (buf[0], buf1[0], buf2[0], buf3[0],
- weight[0], weight[2*i-n]);
- buf++;
- buf1++;
- buf2++;
- buf3++;
- weight++;
- } while (--i);
-}
-
-static void ifft16 (complex_t * buf)
-{
- ifft8 (buf);
- ifft4 (buf + 8);
- ifft4 (buf + 12);
- ifft_pass (buf, roots16, 4);
-}
-
-static void ifft32 (complex_t * buf)
-{
- ifft16 (buf);
- ifft8 (buf + 16);
- ifft8 (buf + 24);
- ifft_pass (buf, roots32, 8);
-}
-
-static void ifft64_c (complex_t * buf)
-{
- ifft32 (buf);
- ifft16 (buf + 32);
- ifft16 (buf + 48);
- ifft_pass (buf, roots64, 16);
-}
-
-static void ifft128_c (complex_t * buf)
-{
- ifft32 (buf);
- ifft16 (buf + 32);
- ifft16 (buf + 48);
- ifft_pass (buf, roots64, 16);
-
- ifft32 (buf + 64);
- ifft32 (buf + 96);
- ifft_pass (buf, roots128, 32);
-}
-
-void a52_imdct_512 (sample_t * data, sample_t * delay, sample_t bias)
-{
- int i, k;
- sample_t t_r, t_i, a_r, a_i, b_r, b_i, w_1, w_2;
- const sample_t * window = a52_imdct_window;
- complex_t buf[128];
-
- for (i = 0; i < 128; i++) {
- k = fftorder[i];
- t_r = pre1[i].real;
- t_i = pre1[i].imag;
- BUTTERFLY_0 (buf[i].real, buf[i].imag, t_r, t_i, data[k], data[255-k]);
- }
-
- ifft128 (buf);
-
- /* Post IFFT complex multiply plus IFFT complex conjugate*/
- /* Window and convert to real valued signal */
- for (i = 0; i < 64; i++) {
- /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
- t_r = post1[i].real;
- t_i = post1[i].imag;
- BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf[i].imag, buf[i].real);
- BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf[127-i].imag, buf[127-i].real);
-
- w_1 = window[2*i];
- w_2 = window[255-2*i];
- BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
- delay[2*i] = a_i;
-
- w_1 = window[2*i+1];
- w_2 = window[254-2*i];
- BUTTERFLY_B (data[2*i+1], data[254-2*i], w_1, w_2, b_r, delay[2*i+1]);
- delay[2*i+1] = b_i;
- }
-}
-
-void a52_imdct_256 (sample_t * data, sample_t * delay, sample_t bias)
-{
- int i, k;
- sample_t t_r, t_i, a_r, a_i, b_r, b_i, c_r, c_i, d_r, d_i, w_1, w_2;
- const sample_t * window = a52_imdct_window;
- complex_t buf1[64], buf2[64];
-
- /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
- for (i = 0; i < 64; i++) {
- k = fftorder[i];
- t_r = pre2[i].real;
- t_i = pre2[i].imag;
- BUTTERFLY_0 (buf1[i].real, buf1[i].imag, t_r, t_i, data[k], data[254-k]);
- BUTTERFLY_0 (buf2[i].real, buf2[i].imag, t_r, t_i, data[k+1], data[255-k]);
- }
-
- ifft64 (buf1);
- ifft64 (buf2);
-
- /* Post IFFT complex multiply */
- /* Window and convert to real valued signal */
- for (i = 0; i < 32; i++) {
- /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
- t_r = post2[i].real;
- t_i = post2[i].imag;
- BUTTERFLY_0 (a_r, a_i, t_i, t_r, buf1[i].imag, buf1[i].real);
- BUTTERFLY_0 (b_r, b_i, t_r, t_i, buf1[63-i].imag, buf1[63-i].real);
- BUTTERFLY_0 (c_r, c_i, t_i, t_r, buf2[i].imag, buf2[i].real);
- BUTTERFLY_0 (d_r, d_i, t_r, t_i, buf2[63-i].imag, buf2[63-i].real);
-
- w_1 = window[2*i];
- w_2 = window[255-2*i];
- BUTTERFLY_B (data[255-2*i], data[2*i], w_2, w_1, a_r, delay[2*i]);
- delay[2*i] = c_i;
-
- w_1 = window[128+2*i];
- w_2 = window[127-2*i];
- BUTTERFLY_B (data[128+2*i], data[127-2*i], w_1, w_2, a_i, delay[127-2*i]);
- delay[127-2*i] = c_r;
-
- w_1 = window[2*i+1];
- w_2 = window[254-2*i];
- BUTTERFLY_B (data[254-2*i], data[2*i+1], w_2, w_1, b_i, delay[2*i+1]);
- delay[2*i+1] = d_r;
-
- w_1 = window[129+2*i];
- w_2 = window[126-2*i];
- BUTTERFLY_B (data[129+2*i], data[126-2*i], w_1, w_2, b_r, delay[126-2*i]);
- delay[126-2*i] = d_i;
- }
-}
-
-static double besselI0 (double x)
-{
- double bessel = 1;
- int i = 100;
-
- do
- bessel = bessel * x / (i * i) + 1;
- while (--i);
- return bessel;
-}
-
-void a52_imdct_init (uint32_t mm_accel)
-{
- int i, k;
- double sum;
- double local_imdct_window[256];
-
- /* compute imdct window - kaiser-bessel derived window, alpha = 5.0 */
- sum = 0;
- for (i = 0; i < 256; i++) {
- sum += besselI0 (i * (256 - i) * (5 * M_PI / 256) * (5 * M_PI / 256));
- local_imdct_window[i] = sum;
- }
- sum++;
- for (i = 0; i < 256; i++)
- a52_imdct_window[i] = SAMPLE (sqrt (local_imdct_window[i] / sum));
-
- for (i = 0; i < 3; i++)
- roots16[i] = SAMPLE (cos ((M_PI / 8) * (i + 1)));
-
- for (i = 0; i < 7; i++)
- roots32[i] = SAMPLE (cos ((M_PI / 16) * (i + 1)));
-
- for (i = 0; i < 15; i++)
- roots64[i] = SAMPLE (cos ((M_PI / 32) * (i + 1)));
-
- for (i = 0; i < 31; i++)
- roots128[i] = SAMPLE (cos ((M_PI / 64) * (i + 1)));
-
- for (i = 0; i < 64; i++) {
- k = fftorder[i] / 2 + 64;
- pre1[i].real = SAMPLE (cos ((M_PI / 256) * (k - 0.25)));
- pre1[i].imag = SAMPLE (sin ((M_PI / 256) * (k - 0.25)));
- }
-
- for (i = 64; i < 128; i++) {
- k = fftorder[i] / 2 + 64;
- pre1[i].real = SAMPLE (-cos ((M_PI / 256) * (k - 0.25)));
- pre1[i].imag = SAMPLE (-sin ((M_PI / 256) * (k - 0.25)));
- }
-
- for (i = 0; i < 64; i++) {
- post1[i].real = SAMPLE (cos ((M_PI / 256) * (i + 0.5)));
- post1[i].imag = SAMPLE (sin ((M_PI / 256) * (i + 0.5)));
- }
-
- for (i = 0; i < 64; i++) {
- k = fftorder[i] / 4;
- pre2[i].real = SAMPLE (cos ((M_PI / 128) * (k - 0.25)));
- pre2[i].imag = SAMPLE (sin ((M_PI / 128) * (k - 0.25)));
- }
-
- for (i = 0; i < 32; i++) {
- post2[i].real = SAMPLE (cos ((M_PI / 128) * (i + 0.5)));
- post2[i].imag = SAMPLE (sin ((M_PI / 128) * (i + 0.5)));
- }
-
-#ifdef LIBA52_DJBFFT
- if (mm_accel & MM_ACCEL_DJBFFT) {
- ifft128 = (void (*) (complex_t *)) fftc4_un128;
- ifft64 = (void (*) (complex_t *)) fftc4_un64;
- } else
-#endif
- {
- ifft128 = ifft128_c;
- ifft64 = ifft64_c;
- }
-}
+++ /dev/null
-/*
- * mm_accel.h
- * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef MM_ACCEL_H
-#define MM_ACCEL_H
-
-/* generic accelerations */
-#define MM_ACCEL_DJBFFT 0x00000001
-
-/* x86 accelerations */
-#define MM_ACCEL_X86_MMX 0x80000000
-#define MM_ACCEL_X86_3DNOW 0x40000000
-#define MM_ACCEL_X86_MMXEXT 0x20000000
-#define MM_ACCEL_X86_SSE 0x10000000
-#define MM_ACCEL_X86_3DNOWEXT 0x08000000
-
-/* PPC accelerations */
-#define MM_ACCEL_PPC_ALTIVEC 0x00010000
-
-uint32_t mm_accel (void);
-
-#endif /* MM_ACCEL_H */
+++ /dev/null
-/*
- * parse.c
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "a52.h"
-#include "a52_internal.h"
-#include "bitstream.h"
-#include "tables.h"
-
-#if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
-/* some systems have memalign() but no declaration for it */
-void * memalign (size_t align, size_t size);
-#else
-/* assume malloc alignment is sufficient */
-#define memalign(align,size) malloc (size)
-#endif
-
-typedef struct {
- quantizer_t q1[2];
- quantizer_t q2[2];
- quantizer_t q4;
- int q1_ptr;
- int q2_ptr;
- int q4_ptr;
-} quantizer_set_t;
-
-static uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
-
-a52_state_t * a52_init (uint32_t mm_accel)
-{
- a52_state_t * state;
- int i;
-
- state = (a52_state_t *) malloc (sizeof (a52_state_t));
- if (state == NULL)
- return NULL;
-
- state->samples = (sample_t *) memalign (16, 256 * 12 * sizeof (sample_t));
- if (state->samples == NULL) {
- free (state);
- return NULL;
- }
-
- for (i = 0; i < 256 * 12; i++)
- state->samples[i] = 0;
-
- state->downmixed = 1;
-
- state->lfsr_state = 1;
-
- a52_imdct_init (mm_accel);
-
- return state;
-}
-
-sample_t * a52_samples (a52_state_t * state)
-{
- return state->samples;
-}
-
-int a52_syncinfo (uint8_t * buf, int * flags,
- int * sample_rate, int * bit_rate)
-{
- static int rate[] = { 32, 40, 48, 56, 64, 80, 96, 112,
- 128, 160, 192, 224, 256, 320, 384, 448,
- 512, 576, 640};
- static uint8_t lfeon[8] = {0x10, 0x10, 0x04, 0x04, 0x04, 0x01, 0x04, 0x01};
- int frmsizecod;
- int bitrate;
- int half;
- int acmod;
-
- if ((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */
- return 0;
-
- if (buf[5] >= 0x60) /* bsid >= 12 */
- return 0;
- half = halfrate[buf[5] >> 3];
-
- /* acmod, dsurmod and lfeon */
- acmod = buf[6] >> 5;
- *flags = ((((buf[6] & 0xf8) == 0x50) ? A52_DOLBY : acmod) |
- ((buf[6] & lfeon[acmod]) ? A52_LFE : 0));
-
- frmsizecod = buf[4] & 63;
- if (frmsizecod >= 38)
- return 0;
- bitrate = rate [frmsizecod >> 1];
- *bit_rate = (bitrate * 1000) >> half;
-
- switch (buf[4] & 0xc0) {
- case 0:
- *sample_rate = 48000 >> half;
- return 4 * bitrate;
- case 0x40:
- *sample_rate = 44100 >> half;
- return 2 * (320 * bitrate / 147 + (frmsizecod & 1));
- case 0x80:
- *sample_rate = 32000 >> half;
- return 6 * bitrate;
- default:
- return 0;
- }
-}
-
-int a52_frame (a52_state_t * state, uint8_t * buf, int * flags,
- level_t * level, sample_t bias)
-{
- static level_t clev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_45DB),
- LEVEL (LEVEL_6DB), LEVEL (LEVEL_45DB) };
- static level_t slev[4] = { LEVEL (LEVEL_3DB), LEVEL (LEVEL_6DB),
- 0, LEVEL (LEVEL_6DB) };
- int chaninfo;
- int acmod;
-
- state->fscod = buf[4] >> 6;
- state->halfrate = halfrate[buf[5] >> 3];
- state->acmod = acmod = buf[6] >> 5;
-
- a52_bitstream_set_ptr (state, buf + 6);
- bitstream_get (state, 3); /* skip acmod we already parsed */
-
- if ((acmod == 2) && (bitstream_get (state, 2) == 2)) /* dsurmod */
- acmod = A52_DOLBY;
-
- state->clev = state->slev = 0;
-
- if ((acmod & 1) && (acmod != 1))
- state->clev = clev[bitstream_get (state, 2)]; /* cmixlev */
-
- if (acmod & 4)
- state->slev = slev[bitstream_get (state, 2)]; /* surmixlev */
-
- state->lfeon = bitstream_get (state, 1);
-
- state->output = a52_downmix_init (acmod, *flags, level,
- state->clev, state->slev);
- if (state->output < 0)
- return 1;
- if (state->lfeon && (*flags & A52_LFE))
- state->output |= A52_LFE;
- *flags = state->output;
- /* the 2* compensates for differences in imdct */
- state->dynrng = state->level = MUL_C (*level, 2);
- state->bias = bias;
- state->dynrnge = 1;
- state->dynrngcall = NULL;
- state->cplba.deltbae = DELTA_BIT_NONE;
- state->ba[0].deltbae = state->ba[1].deltbae = state->ba[2].deltbae =
- state->ba[3].deltbae = state->ba[4].deltbae = DELTA_BIT_NONE;
-
- chaninfo = !acmod;
- do {
- bitstream_get (state, 5); /* dialnorm */
- if (bitstream_get (state, 1)) /* compre */
- bitstream_get (state, 8); /* compr */
- if (bitstream_get (state, 1)) /* langcode */
- bitstream_get (state, 8); /* langcod */
- if (bitstream_get (state, 1)) /* audprodie */
- bitstream_get (state, 7); /* mixlevel + roomtyp */
- } while (chaninfo--);
-
- bitstream_get (state, 2); /* copyrightb + origbs */
-
- if (bitstream_get (state, 1)) /* timecod1e */
- bitstream_get (state, 14); /* timecod1 */
- if (bitstream_get (state, 1)) /* timecod2e */
- bitstream_get (state, 14); /* timecod2 */
-
- if (bitstream_get (state, 1)) { /* addbsie */
- int addbsil;
-
- addbsil = bitstream_get (state, 6);
- do {
- bitstream_get (state, 8); /* addbsi */
- } while (addbsil--);
- }
-
- return 0;
-}
-
-void a52_dynrng (a52_state_t * state,
- level_t (* call) (level_t, void *), void * data)
-{
- state->dynrnge = 0;
- if (call) {
- state->dynrnge = 1;
- state->dynrngcall = call;
- state->dynrngdata = data;
- }
-}
-
-static int parse_exponents (a52_state_t * state, int expstr, int ngrps,
- uint8_t exponent, uint8_t * dest)
-{
- int exps;
-
- while (ngrps--) {
- exps = bitstream_get (state, 7);
-
- exponent += exp_1[exps];
- if (exponent > 24)
- return 1;
-
- switch (expstr) {
- case EXP_D45:
- *(dest++) = exponent;
- *(dest++) = exponent;
- case EXP_D25:
- *(dest++) = exponent;
- case EXP_D15:
- *(dest++) = exponent;
- }
-
- exponent += exp_2[exps];
- if (exponent > 24)
- return 1;
-
- switch (expstr) {
- case EXP_D45:
- *(dest++) = exponent;
- *(dest++) = exponent;
- case EXP_D25:
- *(dest++) = exponent;
- case EXP_D15:
- *(dest++) = exponent;
- }
-
- exponent += exp_3[exps];
- if (exponent > 24)
- return 1;
-
- switch (expstr) {
- case EXP_D45:
- *(dest++) = exponent;
- *(dest++) = exponent;
- case EXP_D25:
- *(dest++) = exponent;
- case EXP_D15:
- *(dest++) = exponent;
- }
- }
-
- return 0;
-}
-
-static int parse_deltba (a52_state_t * state, int8_t * deltba)
-{
- int deltnseg, deltlen, delta, j;
-
- memset (deltba, 0, 50);
-
- deltnseg = bitstream_get (state, 3);
- j = 0;
- do {
- j += bitstream_get (state, 5);
- deltlen = bitstream_get (state, 4);
- delta = bitstream_get (state, 3);
- delta -= (delta >= 4) ? 3 : 4;
- if (!deltlen)
- continue;
- if (j + deltlen >= 50)
- return 1;
- while (deltlen--)
- deltba[j++] = delta;
- } while (deltnseg--);
-
- return 0;
-}
-
-static inline int zero_snr_offsets (int nfchans, a52_state_t * state)
-{
- int i;
-
- if ((state->csnroffst) ||
- (state->chincpl && state->cplba.bai >> 3) || /* cplinu, fsnroffst */
- (state->lfeon && state->lfeba.bai >> 3)) /* fsnroffst */
- return 0;
- for (i = 0; i < nfchans; i++)
- if (state->ba[i].bai >> 3) /* fsnroffst */
- return 0;
- return 1;
-}
-
-static inline int16_t dither_gen (a52_state_t * state)
-{
- int16_t nstate;
-
- nstate = dither_lut[state->lfsr_state >> 8] ^ (state->lfsr_state << 8);
-
- state->lfsr_state = (uint16_t) nstate;
-
- return (3 * nstate) >> 2;
-}
-
-#ifndef LIBA52_FIXED
-#define COEFF(c,t,l,s,e) (c) = (t) * (s)[e]
-#else
-#define COEFF(c,_t,_l,s,e) do { \
- quantizer_t t = (_t); \
- level_t l = (_l); \
- int shift = e - 5; \
- sample_t tmp = t * (l >> 16) + ((t * (l & 0xffff)) >> 16); \
- if (shift >= 0) \
- (c) = tmp >> shift; \
- else \
- (c) = tmp << -shift; \
-} while (0)
-#endif
-
-static void coeff_get (a52_state_t * state, sample_t * coeff,
- expbap_t * expbap, quantizer_set_t * quant,
- level_t level, int dither, int end)
-{
- int i;
- uint8_t * exp;
- int8_t * bap;
-
-#ifndef LIBA52_FIXED
- sample_t factor[25];
-
- for (i = 0; i <= 24; i++)
- factor[i] = scale_factor[i] * level;
-#endif
-
- exp = expbap->exp;
- bap = expbap->bap;
-
- for (i = 0; i < end; i++) {
- int bapi;
-
- bapi = bap[i];
- switch (bapi) {
- case 0:
- if (dither) {
- COEFF (coeff[i], dither_gen (state), level, factor, exp[i]);
- continue;
- } else {
- coeff[i] = 0;
- continue;
- }
-
- case -1:
- if (quant->q1_ptr >= 0) {
- COEFF (coeff[i], quant->q1[quant->q1_ptr--], level,
- factor, exp[i]);
- continue;
- } else {
- int code;
-
- code = bitstream_get (state, 5);
-
- quant->q1_ptr = 1;
- quant->q1[0] = q_1_2[code];
- quant->q1[1] = q_1_1[code];
- COEFF (coeff[i], q_1_0[code], level, factor, exp[i]);
- continue;
- }
-
- case -2:
- if (quant->q2_ptr >= 0) {
- COEFF (coeff[i], quant->q2[quant->q2_ptr--], level,
- factor, exp[i]);
- continue;
- } else {
- int code;
-
- code = bitstream_get (state, 7);
-
- quant->q2_ptr = 1;
- quant->q2[0] = q_2_2[code];
- quant->q2[1] = q_2_1[code];
- COEFF (coeff[i], q_2_0[code], level, factor, exp[i]);
- continue;
- }
-
- case 3:
- COEFF (coeff[i], q_3[bitstream_get (state, 3)], level,
- factor, exp[i]);
- continue;
-
- case -3:
- if (quant->q4_ptr == 0) {
- quant->q4_ptr = -1;
- COEFF (coeff[i], quant->q4, level, factor, exp[i]);
- continue;
- } else {
- int code;
-
- code = bitstream_get (state, 7);
-
- quant->q4_ptr = 0;
- quant->q4 = q_4_1[code];
- COEFF (coeff[i], q_4_0[code], level, factor, exp[i]);
- continue;
- }
-
- case 4:
- COEFF (coeff[i], q_5[bitstream_get (state, 4)], level,
- factor, exp[i]);
- continue;
-
- default:
- COEFF (coeff[i], bitstream_get_2 (state, bapi) << (16 - bapi),
- level, factor, exp[i]);
- }
- }
-}
-
-static void coeff_get_coupling (a52_state_t * state, int nfchans,
- level_t * coeff, sample_t (* samples)[256],
- quantizer_set_t * quant, uint8_t dithflag[5])
-{
- int cplbndstrc, bnd, i, i_end, ch;
- uint8_t * exp;
- int8_t * bap;
- level_t cplco[5];
-
- exp = state->cpl_expbap.exp;
- bap = state->cpl_expbap.bap;
- bnd = 0;
- cplbndstrc = state->cplbndstrc;
- i = state->cplstrtmant;
- while (i < state->cplendmant) {
- i_end = i + 12;
- while (cplbndstrc & 1) {
- cplbndstrc >>= 1;
- i_end += 12;
- }
- cplbndstrc >>= 1;
- for (ch = 0; ch < nfchans; ch++)
- cplco[ch] = MUL_L (state->cplco[ch][bnd], coeff[ch]);
- bnd++;
-
- while (i < i_end) {
- quantizer_t cplcoeff;
- int bapi;
-
- bapi = bap[i];
- switch (bapi) {
- case 0:
- for (ch = 0; ch < nfchans; ch++)
- if ((state->chincpl >> ch) & 1) {
- if (dithflag[ch])
-#ifndef LIBA52_FIXED
- samples[ch][i] = (scale_factor[exp[i]] *
- cplco[ch] * dither_gen (state));
-#else
- COEFF (samples[ch][i], dither_gen (state),
- cplco[ch], scale_factor, exp[i]);
-#endif
- else
- samples[ch][i] = 0;
- }
- i++;
- continue;
-
- case -1:
- if (quant->q1_ptr >= 0) {
- cplcoeff = quant->q1[quant->q1_ptr--];
- break;
- } else {
- int code;
-
- code = bitstream_get (state, 5);
-
- quant->q1_ptr = 1;
- quant->q1[0] = q_1_2[code];
- quant->q1[1] = q_1_1[code];
- cplcoeff = q_1_0[code];
- break;
- }
-
- case -2:
- if (quant->q2_ptr >= 0) {
- cplcoeff = quant->q2[quant->q2_ptr--];
- break;
- } else {
- int code;
-
- code = bitstream_get (state, 7);
-
- quant->q2_ptr = 1;
- quant->q2[0] = q_2_2[code];
- quant->q2[1] = q_2_1[code];
- cplcoeff = q_2_0[code];
- break;
- }
-
- case 3:
- cplcoeff = q_3[bitstream_get (state, 3)];
- break;
-
- case -3:
- if (quant->q4_ptr == 0) {
- quant->q4_ptr = -1;
- cplcoeff = quant->q4;
- break;
- } else {
- int code;
-
- code = bitstream_get (state, 7);
-
- quant->q4_ptr = 0;
- quant->q4 = q_4_1[code];
- cplcoeff = q_4_0[code];
- break;
- }
-
- case 4:
- cplcoeff = q_5[bitstream_get (state, 4)];
- break;
-
- default:
- cplcoeff = bitstream_get_2 (state, bapi) << (16 - bapi);
- }
-#ifndef LIBA52_FIXED
- cplcoeff *= scale_factor[exp[i]];
-#endif
- for (ch = 0; ch < nfchans; ch++)
- if ((state->chincpl >> ch) & 1)
-#ifndef LIBA52_FIXED
- samples[ch][i] = cplcoeff * cplco[ch];
-#else
- COEFF (samples[ch][i], cplcoeff, cplco[ch],
- scale_factor, exp[i]);
-#endif
- i++;
- }
- }
-}
-
-int a52_block (a52_state_t * state)
-{
- static const uint8_t nfchans_tbl[] = {2, 1, 2, 3, 3, 4, 4, 5, 1, 1, 2};
- static int rematrix_band[4] = {25, 37, 61, 253};
- int i, nfchans, chaninfo;
- uint8_t cplexpstr, chexpstr[5], lfeexpstr, do_bit_alloc, done_cpl;
- uint8_t blksw[5], dithflag[5];
- level_t coeff[5];
- int chanbias;
- quantizer_set_t quant;
- sample_t * samples;
-
- nfchans = nfchans_tbl[state->acmod];
-
- for (i = 0; i < nfchans; i++)
- blksw[i] = bitstream_get (state, 1);
-
- for (i = 0; i < nfchans; i++)
- dithflag[i] = bitstream_get (state, 1);
-
- chaninfo = !state->acmod;
- do {
- if (bitstream_get (state, 1)) { /* dynrnge */
- int dynrng;
-
- dynrng = bitstream_get_2 (state, 8);
- if (state->dynrnge) {
- level_t range;
-
-#if !defined(LIBA52_FIXED)
- range = ((((dynrng & 0x1f) | 0x20) << 13) *
- scale_factor[3 - (dynrng >> 5)]);
-#else
- range = ((dynrng & 0x1f) | 0x20) << (21 + (dynrng >> 5));
-#endif
- if (state->dynrngcall)
- range = state->dynrngcall (range, state->dynrngdata);
- state->dynrng = MUL_L (state->level, range);
- }
- }
- } while (chaninfo--);
-
- if (bitstream_get (state, 1)) { /* cplstre */
- state->chincpl = 0;
- if (bitstream_get (state, 1)) { /* cplinu */
- static uint8_t bndtab[16] = {31, 35, 37, 39, 41, 42, 43, 44,
- 45, 45, 46, 46, 47, 47, 48, 48};
- int cplbegf;
- int cplendf;
- int ncplsubnd;
-
- for (i = 0; i < nfchans; i++)
- state->chincpl |= bitstream_get (state, 1) << i;
- switch (state->acmod) {
- case 0: case 1:
- return 1;
- case 2:
- state->phsflginu = bitstream_get (state, 1);
- }
- cplbegf = bitstream_get (state, 4);
- cplendf = bitstream_get (state, 4);
-
- if (cplendf + 3 - cplbegf < 0)
- return 1;
- state->ncplbnd = ncplsubnd = cplendf + 3 - cplbegf;
- state->cplstrtbnd = bndtab[cplbegf];
- state->cplstrtmant = cplbegf * 12 + 37;
- state->cplendmant = cplendf * 12 + 73;
-
- state->cplbndstrc = 0;
- for (i = 0; i < ncplsubnd - 1; i++)
- if (bitstream_get (state, 1)) {
- state->cplbndstrc |= 1 << i;
- state->ncplbnd--;
- }
- }
- }
-
- if (state->chincpl) { /* cplinu */
- int j, cplcoe;
-
- cplcoe = 0;
- for (i = 0; i < nfchans; i++)
- if ((state->chincpl) >> i & 1)
- if (bitstream_get (state, 1)) { /* cplcoe */
- int mstrcplco, cplcoexp, cplcomant;
-
- cplcoe = 1;
- mstrcplco = 3 * bitstream_get (state, 2);
- for (j = 0; j < state->ncplbnd; j++) {
- cplcoexp = bitstream_get (state, 4);
- cplcomant = bitstream_get (state, 4);
- if (cplcoexp == 15)
- cplcomant <<= 14;
- else
- cplcomant = (cplcomant | 0x10) << 13;
-#ifndef LIBA52_FIXED
- state->cplco[i][j] =
- cplcomant * scale_factor[cplcoexp + mstrcplco];
-#else
- state->cplco[i][j] = (cplcomant << 11) >> (cplcoexp + mstrcplco);
-#endif
-
- }
- }
- if ((state->acmod == 2) && state->phsflginu && cplcoe)
- for (j = 0; j < state->ncplbnd; j++)
- if (bitstream_get (state, 1)) /* phsflg */
- state->cplco[1][j] = -state->cplco[1][j];
- }
-
- if ((state->acmod == 2) && (bitstream_get (state, 1))) { /* rematstr */
- int end;
-
- state->rematflg = 0;
- end = (state->chincpl) ? state->cplstrtmant : 253; /* cplinu */
- i = 0;
- do
- state->rematflg |= bitstream_get (state, 1) << i;
- while (rematrix_band[i++] < end);
- }
-
- cplexpstr = EXP_REUSE;
- lfeexpstr = EXP_REUSE;
- if (state->chincpl) /* cplinu */
- cplexpstr = bitstream_get (state, 2);
- for (i = 0; i < nfchans; i++)
- chexpstr[i] = bitstream_get (state, 2);
- if (state->lfeon)
- lfeexpstr = bitstream_get (state, 1);
-
- for (i = 0; i < nfchans; i++)
- if (chexpstr[i] != EXP_REUSE) {
- if ((state->chincpl >> i) & 1)
- state->endmant[i] = state->cplstrtmant;
- else {
- int chbwcod;
-
- chbwcod = bitstream_get (state, 6);
- if (chbwcod > 60)
- return 1;
- state->endmant[i] = chbwcod * 3 + 73;
- }
- }
-
- do_bit_alloc = 0;
-
- if (cplexpstr != EXP_REUSE) {
- int cplabsexp, ncplgrps;
-
- do_bit_alloc = 64;
- ncplgrps = ((state->cplendmant - state->cplstrtmant) /
- (3 << (cplexpstr - 1)));
- cplabsexp = bitstream_get (state, 4) << 1;
- if (parse_exponents (state, cplexpstr, ncplgrps, cplabsexp,
- state->cpl_expbap.exp + state->cplstrtmant))
- return 1;
- }
- for (i = 0; i < nfchans; i++)
- if (chexpstr[i] != EXP_REUSE) {
- int grp_size, nchgrps;
-
- do_bit_alloc |= 1 << i;
- grp_size = 3 << (chexpstr[i] - 1);
- nchgrps = (state->endmant[i] + grp_size - 4) / grp_size;
- state->fbw_expbap[i].exp[0] = bitstream_get (state, 4);
- if (parse_exponents (state, chexpstr[i], nchgrps,
- state->fbw_expbap[i].exp[0],
- state->fbw_expbap[i].exp + 1))
- return 1;
- bitstream_get (state, 2); /* gainrng */
- }
- if (lfeexpstr != EXP_REUSE) {
- do_bit_alloc |= 32;
- state->lfe_expbap.exp[0] = bitstream_get (state, 4);
- if (parse_exponents (state, lfeexpstr, 2, state->lfe_expbap.exp[0],
- state->lfe_expbap.exp + 1))
- return 1;
- }
-
- if (bitstream_get (state, 1)) { /* baie */
- do_bit_alloc = 127;
- state->bai = bitstream_get (state, 11);
- }
- if (bitstream_get (state, 1)) { /* snroffste */
- do_bit_alloc = 127;
- state->csnroffst = bitstream_get (state, 6);
- if (state->chincpl) /* cplinu */
- state->cplba.bai = bitstream_get (state, 7);
- for (i = 0; i < nfchans; i++)
- state->ba[i].bai = bitstream_get (state, 7);
- if (state->lfeon)
- state->lfeba.bai = bitstream_get (state, 7);
- }
- if ((state->chincpl) && (bitstream_get (state, 1))) { /* cplleake */
- do_bit_alloc |= 64;
- state->cplfleak = 9 - bitstream_get (state, 3);
- state->cplsleak = 9 - bitstream_get (state, 3);
- }
-
- if (bitstream_get (state, 1)) { /* deltbaie */
- do_bit_alloc = 127;
- if (state->chincpl) /* cplinu */
- state->cplba.deltbae = bitstream_get (state, 2);
- for (i = 0; i < nfchans; i++)
- state->ba[i].deltbae = bitstream_get (state, 2);
- if (state->chincpl && /* cplinu */
- (state->cplba.deltbae == DELTA_BIT_NEW) &&
- parse_deltba (state, state->cplba.deltba))
- return 1;
- for (i = 0; i < nfchans; i++)
- if ((state->ba[i].deltbae == DELTA_BIT_NEW) &&
- parse_deltba (state, state->ba[i].deltba))
- return 1;
- }
-
- if (do_bit_alloc) {
- if (zero_snr_offsets (nfchans, state)) {
- memset (state->cpl_expbap.bap, 0, sizeof (state->cpl_expbap.bap));
- for (i = 0; i < nfchans; i++)
- memset (state->fbw_expbap[i].bap, 0,
- sizeof (state->fbw_expbap[i].bap));
- memset (state->lfe_expbap.bap, 0, sizeof (state->lfe_expbap.bap));
- } else {
- if (state->chincpl && (do_bit_alloc & 64)) /* cplinu */
- a52_bit_allocate (state, &state->cplba, state->cplstrtbnd,
- state->cplstrtmant, state->cplendmant,
- state->cplfleak << 8, state->cplsleak << 8,
- &state->cpl_expbap);
- for (i = 0; i < nfchans; i++)
- if (do_bit_alloc & (1 << i))
- a52_bit_allocate (state, state->ba + i, 0, 0,
- state->endmant[i], 0, 0,
- state->fbw_expbap +i);
- if (state->lfeon && (do_bit_alloc & 32)) {
- state->lfeba.deltbae = DELTA_BIT_NONE;
- a52_bit_allocate (state, &state->lfeba, 0, 0, 7, 0, 0,
- &state->lfe_expbap);
- }
- }
- }
-
- if (bitstream_get (state, 1)) { /* skiple */
- i = bitstream_get (state, 9); /* skipl */
- while (i--)
- bitstream_get (state, 8);
- }
-
- samples = state->samples;
- if (state->output & A52_LFE)
- samples += 256; /* shift for LFE channel */
-
- chanbias = a52_downmix_coeff (coeff, state->acmod, state->output,
- state->dynrng, state->clev, state->slev);
-
- quant.q1_ptr = quant.q2_ptr = quant.q4_ptr = -1;
- done_cpl = 0;
-
- for (i = 0; i < nfchans; i++) {
- int j;
-
- coeff_get (state, samples + 256 * i, state->fbw_expbap +i, &quant,
- coeff[i], dithflag[i], state->endmant[i]);
-
- if ((state->chincpl >> i) & 1) {
- if (!done_cpl) {
- done_cpl = 1;
- coeff_get_coupling (state, nfchans, coeff,
- (sample_t (*)[256])samples, &quant,
- dithflag);
- }
- j = state->cplendmant;
- } else
- j = state->endmant[i];
- do
- (samples + 256 * i)[j] = 0;
- while (++j < 256);
- }
-
- if (state->acmod == 2) {
- int j, end, band, rematflg;
-
- end = ((state->endmant[0] < state->endmant[1]) ?
- state->endmant[0] : state->endmant[1]);
-
- i = 0;
- j = 13;
- rematflg = state->rematflg;
- do {
- if (! (rematflg & 1)) {
- rematflg >>= 1;
- j = rematrix_band[i++];
- continue;
- }
- rematflg >>= 1;
- band = rematrix_band[i++];
- if (band > end)
- band = end;
- do {
- sample_t tmp0, tmp1;
-
- tmp0 = samples[j];
- tmp1 = (samples+256)[j];
- samples[j] = tmp0 + tmp1;
- (samples+256)[j] = tmp0 - tmp1;
- } while (++j < band);
- } while (j < end);
- }
-
- if (state->lfeon) {
- if (state->output & A52_LFE) {
- coeff_get (state, samples - 256, &state->lfe_expbap, &quant,
- state->dynrng, 0, 7);
- for (i = 7; i < 256; i++)
- (samples-256)[i] = 0;
- a52_imdct_512 (samples - 256, samples + 1536 - 256, state->bias);
- } else {
- /* just skip the LFE coefficients */
- coeff_get (state, samples + 1280, &state->lfe_expbap, &quant,
- 0, 0, 7);
- }
- }
-
- i = 0;
- if (nfchans_tbl[state->output & A52_CHANNEL_MASK] < nfchans)
- for (i = 1; i < nfchans; i++)
- if (blksw[i] != blksw[0])
- break;
-
- if (i < nfchans) {
- if (state->downmixed) {
- state->downmixed = 0;
- a52_upmix (samples + 1536, state->acmod, state->output);
- }
-
- for (i = 0; i < nfchans; i++) {
- sample_t bias;
-
- bias = 0;
- if (!(chanbias & (1 << i)))
- bias = state->bias;
-
- if (coeff[i]) {
- if (blksw[i])
- a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i,
- bias);
- else
- a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i,
- bias);
- } else {
- int j;
-
- for (j = 0; j < 256; j++)
- (samples + 256 * i)[j] = bias;
- }
- }
-
- a52_downmix (samples, state->acmod, state->output, state->bias,
- state->clev, state->slev);
- } else {
- nfchans = nfchans_tbl[state->output & A52_CHANNEL_MASK];
-
- a52_downmix (samples, state->acmod, state->output, 0,
- state->clev, state->slev);
-
- if (!state->downmixed) {
- state->downmixed = 1;
- a52_downmix (samples + 1536, state->acmod, state->output, 0,
- state->clev, state->slev);
- }
-
- if (blksw[0])
- for (i = 0; i < nfchans; i++)
- a52_imdct_256 (samples + 256 * i, samples + 1536 + 256 * i,
- state->bias);
- else
- for (i = 0; i < nfchans; i++)
- a52_imdct_512 (samples + 256 * i, samples + 1536 + 256 * i,
- state->bias);
- }
-
- return 0;
-}
-
-void a52_free (a52_state_t * state)
-{
- free (state->samples);
- free (state);
-}
+++ /dev/null
-
-// a52_resample_init should find the requested converter (from type flags ->
-// given number of channels) and set up some function pointers...
-
-// a52_resample() should do the conversion.
-
-#include "a52.h"
-#include "mm_accel.h"
-#include "config.h"
-#include "../libpostproc/mangle.h"
-
-int (* a52_resample) (float * _f, int16_t * s16)=NULL;
-
-#include "resample_c.c"
-
-#ifdef ARCH_X86
-#include "resample_mmx.c"
-#endif
-
-void* a52_resample_init(uint32_t mm_accel,int flags,int chans){
-void* tmp;
-
-#ifdef ARCH_X86
- if(mm_accel&MM_ACCEL_X86_MMX){
- tmp=a52_resample_MMX(flags,chans);
- if(tmp){
- if(a52_resample==NULL) fprintf(stderr, "Using MMX optimized resampler\n");
- a52_resample=tmp;
- return tmp;
- }
- }
-#endif
-
- tmp=a52_resample_C(flags,chans);
- if(tmp){
- if(a52_resample==NULL) fprintf(stderr, "No accelerated resampler found\n");
- a52_resample=tmp;
- return tmp;
- }
-
- fprintf(stderr, "Unimplemented resampler for mode 0x%X -> %d channels conversion - Contact MPlayer developers!\n", flags, chans);
- return NULL;
-}
+++ /dev/null
-// this code is based on a52dec/libao/audio_out_oss.c
-
-static inline int16_t convert (int32_t i)
-{
- if (i > 0x43c07fff)
- return 32767;
- else if (i < 0x43bf8000)
- return -32768;
- else
- return i - 0x43c00000;
-}
-
-static int a52_resample_MONO_to_5_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0;
- s16[5*i+4] = convert (f[i]);
- }
- return 5*256;
-}
-
-static int a52_resample_MONO_to_1_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[i] = convert (f[i]);
- }
- return 1*256;
-}
-
-static int a52_resample_STEREO_to_2_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[2*i] = convert (f[i]);
- s16[2*i+1] = convert (f[i+256]);
- }
- return 2*256;
-}
-
-static int a52_resample_3F_to_5_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[5*i] = convert (f[i]);
- s16[5*i+1] = convert (f[i+512]);
- s16[5*i+2] = s16[5*i+3] = 0;
- s16[5*i+4] = convert (f[i+256]);
- }
- return 5*256;
-}
-
-static int a52_resample_2F_2R_to_4_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[4*i] = convert (f[i]);
- s16[4*i+1] = convert (f[i+256]);
- s16[4*i+2] = convert (f[i+512]);
- s16[4*i+3] = convert (f[i+768]);
- }
- return 4*256;
-}
-
-static int a52_resample_3F_2R_to_5_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[5*i] = convert (f[i]);
- s16[5*i+1] = convert (f[i+512]);
- s16[5*i+2] = convert (f[i+768]);
- s16[5*i+3] = convert (f[i+1024]);
- s16[5*i+4] = convert (f[i+256]);
- }
- return 5*256;
-}
-
-static int a52_resample_MONO_LFE_to_6_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0;
- s16[6*i+4] = convert (f[i+256]);
- s16[6*i+5] = convert (f[i]);
- }
- return 6*256;
-}
-
-static int a52_resample_STEREO_LFE_to_6_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+512]);
- s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0;
- s16[6*i+5] = convert (f[i]);
- }
- return 6*256;
-}
-
-static int a52_resample_3F_LFE_to_6_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+768]);
- s16[6*i+2] = s16[6*i+3] = 0;
- s16[6*i+4] = convert (f[i+512]);
- s16[6*i+5] = convert (f[i]);
- }
- return 6*256;
-}
-
-static int a52_resample_2F_2R_LFE_to_6_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+512]);
- s16[6*i+2] = convert (f[i+768]);
- s16[6*i+3] = convert (f[i+1024]);
- s16[6*i+4] = 0;
- s16[6*i+5] = convert (f[i]);
- }
- return 6*256;
-}
-
-static int a52_resample_3F_2R_LFE_to_6_C(float * _f, int16_t * s16){
- int i;
- int32_t * f = (int32_t *) _f;
- for (i = 0; i < 256; i++) {
- s16[6*i] = convert (f[i+256]);
- s16[6*i+1] = convert (f[i+768]);
- s16[6*i+2] = convert (f[i+1024]);
- s16[6*i+3] = convert (f[i+1280]);
- s16[6*i+4] = convert (f[i+512]);
- s16[6*i+5] = convert (f[i]);
- }
- return 6*256;
-}
-
-
-static void* a52_resample_C(int flags, int ch){
- switch (flags) {
- case A52_MONO:
- if(ch==5) return a52_resample_MONO_to_5_C;
- if(ch==1) return a52_resample_MONO_to_1_C;
- break;
- case A52_CHANNEL:
- case A52_STEREO:
- case A52_DOLBY:
- if(ch==2) return a52_resample_STEREO_to_2_C;
- break;
- case A52_3F:
- if(ch==5) return a52_resample_3F_to_5_C;
- break;
- case A52_2F2R:
- if(ch==4) return a52_resample_2F_2R_to_4_C;
- break;
- case A52_3F2R:
- if(ch==5) return a52_resample_3F_2R_to_5_C;
- break;
- case A52_MONO | A52_LFE:
- if(ch==6) return a52_resample_MONO_LFE_to_6_C;
- break;
- case A52_CHANNEL | A52_LFE:
- case A52_STEREO | A52_LFE:
- case A52_DOLBY | A52_LFE:
- if(ch==6) return a52_resample_STEREO_LFE_to_6_C;
- break;
- case A52_3F | A52_LFE:
- if(ch==6) return a52_resample_3F_LFE_to_6_C;
- break;
- case A52_2F2R | A52_LFE:
- if(ch==6) return a52_resample_2F_2R_LFE_to_6_C;
- break;
- case A52_3F2R | A52_LFE:
- if(ch==6) return a52_resample_3F_2R_LFE_to_6_C;
- break;
- }
- return NULL;
-}
+++ /dev/null
-
-// MMX optimizations from Michael Niedermayer (michaelni@gmx.at) (under GPL)
-
-/* optimization TODO / NOTES
- movntq is slightly faster (0.5% with the current test.c benchmark)
- (but thats just test.c so that needs to be testd in reallity)
- and it would mean (C / MMX2 / MMX / 3DNOW) versions
-*/
-
-static uint64_t __attribute__((aligned(8))) magicF2W= 0x43c0000043c00000LL;
-static uint64_t __attribute__((aligned(8))) wm1010= 0xFFFF0000FFFF0000LL;
-static uint64_t __attribute__((aligned(8))) wm0101= 0x0000FFFF0000FFFFLL;
-static uint64_t __attribute__((aligned(8))) wm1100= 0xFFFFFFFF00000000LL;
-
-static int a52_resample_MONO_to_5_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-512, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "movq "MANGLE(wm1100)", %%mm3 \n\t"
- "movq "MANGLE(wm0101)", %%mm4 \n\t"
- "movq "MANGLE(wm1010)", %%mm5 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq (%1, %%esi, 2), %%mm0 \n\t"
- "movq 8(%1, %%esi, 2), %%mm1 \n\t"
- "leal (%%esi, %%esi, 4), %%edi \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "pand %%mm4, %%mm0 \n\t"
- "pand %%mm5, %%mm1 \n\t"
- "movq %%mm6, (%0, %%edi) \n\t" // 0 0 0 0
- "movd %%mm0, 8(%0, %%edi) \n\t" // A 0
- "pand %%mm3, %%mm0 \n\t"
- "movd %%mm6, 12(%0, %%edi) \n\t" // 0 0
- "movd %%mm1, 16(%0, %%edi) \n\t" // 0 B
- "pand %%mm3, %%mm1 \n\t"
- "movd %%mm6, 20(%0, %%edi) \n\t" // 0 0
- "movq %%mm0, 24(%0, %%edi) \n\t" // 0 0 C 0
- "movq %%mm1, 32(%0, %%edi) \n\t" // 0 0 0 B
- "addl $8, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1280), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 5*256;
-}
-
-static int a52_resample_STEREO_to_2_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
-/* benchmark scores are 0.3% better with SSE but we would need to set bias=0 and premultiply it
-#ifdef HAVE_SSE
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "1: \n\t"
- "cvtps2pi (%1, %%esi), %%mm0 \n\t"
- "cvtps2pi 1024(%1, %%esi), %%mm2\n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklwd %%mm2, %%mm0 \n\t"
- "punpckhwd %%mm2, %%mm1 \n\t"
- "movq %%mm0, (%0, %%esi) \n\t"
- "movq %%mm1, 8(%0, %%esi) \n\t"
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+512), "r" (f+256)
- :"%esi", "memory"
- );*/
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "1: \n\t"
- "movq (%1, %%esi), %%mm0 \n\t"
- "movq 8(%1, %%esi), %%mm1 \n\t"
- "movq 1024(%1, %%esi), %%mm2 \n\t"
- "movq 1032(%1, %%esi), %%mm3 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklwd %%mm2, %%mm0 \n\t"
- "punpckhwd %%mm2, %%mm1 \n\t"
- "movq %%mm0, (%0, %%esi) \n\t"
- "movq %%mm1, 8(%0, %%esi) \n\t"
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+512), "r" (f+256)
- :"%esi", "memory"
- );
- return 2*256;
-}
-
-static int a52_resample_3F_to_5_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "movq %%mm7, %%mm5 \n\t"
- "punpckldq %%mm6, %%mm5 \n\t"
- "1: \n\t"
- "movd (%1, %%esi), %%mm0 \n\t"
- "punpckldq 2048(%1, %%esi), %%mm0\n\t"
- "movd 1024(%1, %%esi), %%mm1 \n\t"
- "punpckldq 4(%1, %%esi), %%mm1 \n\t"
- "movd 2052(%1, %%esi), %%mm2 \n\t"
- "movq %%mm7, %%mm3 \n\t"
- "punpckldq 1028(%1, %%esi), %%mm3\n\t"
- "movd 8(%1, %%esi), %%mm4 \n\t"
- "punpckldq 2056(%1, %%esi), %%mm4\n\t"
- "leal (%%esi, %%esi, 4), %%edi \n\t"
- "sarl $1, %%edi \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm5, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "psubd %%mm7, %%mm4 \n\t"
- "packssdw %%mm6, %%mm0 \n\t"
- "packssdw %%mm2, %%mm1 \n\t"
- "packssdw %%mm4, %%mm3 \n\t"
- "movq %%mm0, (%0, %%edi) \n\t"
- "movq %%mm1, 8(%0, %%edi) \n\t"
- "movq %%mm3, 16(%0, %%edi) \n\t"
-
- "movd 1032(%1, %%esi), %%mm1 \n\t"
- "punpckldq 12(%1, %%esi), %%mm1\n\t"
- "movd 2060(%1, %%esi), %%mm2 \n\t"
- "movq %%mm7, %%mm3 \n\t"
- "punpckldq 1036(%1, %%esi), %%mm3\n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm5, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "movq %%mm0, 24(%0, %%edi) \n\t"
- "movq %%mm2, 32(%0, %%edi) \n\t"
-
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1280), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 5*256;
-}
-
-static int a52_resample_2F_2R_to_4_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "1: \n\t"
- "movq (%1, %%esi), %%mm0 \n\t"
- "movq 8(%1, %%esi), %%mm1 \n\t"
- "movq 1024(%1, %%esi), %%mm2 \n\t"
- "movq 1032(%1, %%esi), %%mm3 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "movq 2048(%1, %%esi), %%mm3 \n\t"
- "movq 2056(%1, %%esi), %%mm4 \n\t"
- "movq 3072(%1, %%esi), %%mm5 \n\t"
- "movq 3080(%1, %%esi), %%mm6 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "psubd %%mm7, %%mm4 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "psubd %%mm7, %%mm6 \n\t"
- "packssdw %%mm4, %%mm3 \n\t"
- "packssdw %%mm6, %%mm5 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "movq %%mm3, %%mm4 \n\t"
- "punpcklwd %%mm2, %%mm0 \n\t"
- "punpckhwd %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm5, %%mm3 \n\t"
- "punpckhwd %%mm5, %%mm4 \n\t"
- "movq %%mm0, %%mm2 \n\t"
- "movq %%mm1, %%mm5 \n\t"
- "punpckldq %%mm3, %%mm0 \n\t"
- "punpckhdq %%mm3, %%mm2 \n\t"
- "punpckldq %%mm4, %%mm1 \n\t"
- "punpckhdq %%mm4, %%mm5 \n\t"
- "movq %%mm0, (%0, %%esi,2) \n\t"
- "movq %%mm2, 8(%0, %%esi,2) \n\t"
- "movq %%mm1, 16(%0, %%esi,2) \n\t"
- "movq %%mm5, 24(%0, %%esi,2) \n\t"
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1024), "r" (f+256)
- :"%esi", "memory"
- );
- return 4*256;
-}
-
-static int a52_resample_3F_2R_to_5_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "1: \n\t"
- "movd (%1, %%esi), %%mm0 \n\t"
- "punpckldq 2048(%1, %%esi), %%mm0\n\t"
- "movd 3072(%1, %%esi), %%mm1 \n\t"
- "punpckldq 4096(%1, %%esi), %%mm1\n\t"
- "movd 1024(%1, %%esi), %%mm2 \n\t"
- "punpckldq 4(%1, %%esi), %%mm2 \n\t"
- "movd 2052(%1, %%esi), %%mm3 \n\t"
- "punpckldq 3076(%1, %%esi), %%mm3\n\t"
- "movd 4100(%1, %%esi), %%mm4 \n\t"
- "punpckldq 1028(%1, %%esi), %%mm4\n\t"
- "movd 8(%1, %%esi), %%mm5 \n\t"
- "punpckldq 2056(%1, %%esi), %%mm5\n\t"
- "leal (%%esi, %%esi, 4), %%edi \n\t"
- "sarl $1, %%edi \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "psubd %%mm7, %%mm4 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "packssdw %%mm5, %%mm4 \n\t"
- "movq %%mm0, (%0, %%edi) \n\t"
- "movq %%mm2, 8(%0, %%edi) \n\t"
- "movq %%mm4, 16(%0, %%edi) \n\t"
-
- "movd 3080(%1, %%esi), %%mm0 \n\t"
- "punpckldq 4104(%1, %%esi), %%mm0\n\t"
- "movd 1032(%1, %%esi), %%mm1 \n\t"
- "punpckldq 12(%1, %%esi), %%mm1\n\t"
- "movd 2060(%1, %%esi), %%mm2 \n\t"
- "punpckldq 3084(%1, %%esi), %%mm2\n\t"
- "movd 4108(%1, %%esi), %%mm3 \n\t"
- "punpckldq 1036(%1, %%esi), %%mm3\n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "movq %%mm0, 24(%0, %%edi) \n\t"
- "movq %%mm2, 32(%0, %%edi) \n\t"
-
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1280), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 5*256;
-}
-
-static int a52_resample_MONO_LFE_to_6_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq 1024(%1, %%esi), %%mm0 \n\t"
- "movq 1032(%1, %%esi), %%mm1 \n\t"
- "movq (%1, %%esi), %%mm2 \n\t"
- "movq 8(%1, %%esi), %%mm3 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "packssdw %%mm1, %%mm0 \n\t"
- "packssdw %%mm3, %%mm2 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklwd %%mm2, %%mm0 \n\t"
- "punpckhwd %%mm2, %%mm1 \n\t"
- "leal (%%esi, %%esi, 2), %%edi \n\t"
- "movq %%mm6, (%0, %%edi) \n\t"
- "movd %%mm0, 8(%0, %%edi) \n\t"
- "punpckhdq %%mm0, %%mm0 \n\t"
- "movq %%mm6, 12(%0, %%edi) \n\t"
- "movd %%mm0, 20(%0, %%edi) \n\t"
- "movq %%mm6, 24(%0, %%edi) \n\t"
- "movd %%mm1, 32(%0, %%edi) \n\t"
- "punpckhdq %%mm1, %%mm1 \n\t"
- "movq %%mm6, 36(%0, %%edi) \n\t"
- "movd %%mm1, 44(%0, %%edi) \n\t"
- "addl $16, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1536), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 6*256;
-}
-
-static int a52_resample_STEREO_LFE_to_6_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq 1024(%1, %%esi), %%mm0 \n\t"
- "movq 2048(%1, %%esi), %%mm1 \n\t"
- "movq (%1, %%esi), %%mm5 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "leal (%%esi, %%esi, 2), %%edi \n\t"
-
- "pxor %%mm4, %%mm4 \n\t"
- "packssdw %%mm5, %%mm0 \n\t" // FfAa
- "packssdw %%mm4, %%mm1 \n\t" // 00Bb
- "punpckhwd %%mm0, %%mm4 \n\t" // F0f0
- "punpcklwd %%mm1, %%mm0 \n\t" // BAba
- "movq %%mm0, %%mm1 \n\t" // BAba
- "punpckldq %%mm4, %%mm3 \n\t" // f0XX
- "punpckldq %%mm6, %%mm0 \n\t" // 00ba
- "punpckhdq %%mm1, %%mm3 \n\t" // BAf0
-
- "movq %%mm0, (%0, %%edi) \n\t" // 00ba
- "punpckhdq %%mm4, %%mm0 \n\t" // F000
- "movq %%mm3, 8(%0, %%edi) \n\t" // BAf0
- "movq %%mm0, 16(%0, %%edi) \n\t" // F000
- "addl $8, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1536), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 6*256;
-}
-
-static int a52_resample_3F_LFE_to_6_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
- "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq 1024(%1, %%esi), %%mm0 \n\t"
- "movq 3072(%1, %%esi), %%mm1 \n\t"
- "movq 2048(%1, %%esi), %%mm4 \n\t"
- "movq (%1, %%esi), %%mm5 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm4 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "leal (%%esi, %%esi, 2), %%edi \n\t"
-
- "packssdw %%mm4, %%mm0 \n\t" // EeAa
- "packssdw %%mm5, %%mm1 \n\t" // FfBb
- "movq %%mm0, %%mm2 \n\t" // EeAa
- "punpcklwd %%mm1, %%mm0 \n\t" // BAba
- "punpckhwd %%mm1, %%mm2 \n\t" // FEfe
- "movq %%mm0, %%mm1 \n\t" // BAba
- "punpckldq %%mm6, %%mm0 \n\t" // 00ba
- "punpckhdq %%mm1, %%mm1 \n\t" // BABA
-
- "movq %%mm0, (%0, %%edi) \n\t"
- "punpckhdq %%mm2, %%mm0 \n\t" // FE00
- "punpckldq %%mm1, %%mm2 \n\t" // BAfe
- "movq %%mm2, 8(%0, %%edi) \n\t"
- "movq %%mm0, 16(%0, %%edi) \n\t"
- "addl $8, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1536), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 6*256;
-}
-
-static int a52_resample_2F_2R_LFE_to_6_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
-// "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq 1024(%1, %%esi), %%mm0 \n\t"
- "movq 2048(%1, %%esi), %%mm1 \n\t"
- "movq 3072(%1, %%esi), %%mm2 \n\t"
- "movq 4096(%1, %%esi), %%mm3 \n\t"
- "movq (%1, %%esi), %%mm5 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "leal (%%esi, %%esi, 2), %%edi \n\t"
-
- "packssdw %%mm2, %%mm0 \n\t" // CcAa
- "packssdw %%mm3, %%mm1 \n\t" // DdBb
- "packssdw %%mm5, %%mm5 \n\t" // FfFf
- "movq %%mm0, %%mm2 \n\t" // CcAa
- "punpcklwd %%mm1, %%mm0 \n\t" // BAba
- "punpckhwd %%mm1, %%mm2 \n\t" // DCdc
- "pxor %%mm4, %%mm4 \n\t" // 0000
- "punpcklwd %%mm5, %%mm4 \n\t" // F0f0
- "movq %%mm0, %%mm1 \n\t" // BAba
- "movq %%mm4, %%mm3 \n\t" // F0f0
- "punpckldq %%mm2, %%mm0 \n\t" // dcba
- "punpckhdq %%mm1, %%mm1 \n\t" // BABA
- "punpckldq %%mm1, %%mm4 \n\t" // BAf0
- "punpckhdq %%mm3, %%mm2 \n\t" // F0DC
-
- "movq %%mm0, (%0, %%edi) \n\t"
- "movq %%mm4, 8(%0, %%edi) \n\t"
- "movq %%mm2, 16(%0, %%edi) \n\t"
- "addl $8, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1536), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 6*256;
-}
-
-static int a52_resample_3F_2R_LFE_to_6_MMX(float * _f, int16_t * s16){
- int32_t * f = (int32_t *) _f;
- asm volatile(
- "movl $-1024, %%esi \n\t"
- "movq "MANGLE(magicF2W)", %%mm7 \n\t"
-// "pxor %%mm6, %%mm6 \n\t"
- "1: \n\t"
- "movq 1024(%1, %%esi), %%mm0 \n\t"
- "movq 3072(%1, %%esi), %%mm1 \n\t"
- "movq 4096(%1, %%esi), %%mm2 \n\t"
- "movq 5120(%1, %%esi), %%mm3 \n\t"
- "movq 2048(%1, %%esi), %%mm4 \n\t"
- "movq (%1, %%esi), %%mm5 \n\t"
- "psubd %%mm7, %%mm0 \n\t"
- "psubd %%mm7, %%mm1 \n\t"
- "psubd %%mm7, %%mm2 \n\t"
- "psubd %%mm7, %%mm3 \n\t"
- "psubd %%mm7, %%mm4 \n\t"
- "psubd %%mm7, %%mm5 \n\t"
- "leal (%%esi, %%esi, 2), %%edi \n\t"
-
- "packssdw %%mm2, %%mm0 \n\t" // CcAa
- "packssdw %%mm3, %%mm1 \n\t" // DdBb
- "packssdw %%mm4, %%mm4 \n\t" // EeEe
- "packssdw %%mm5, %%mm5 \n\t" // FfFf
- "movq %%mm0, %%mm2 \n\t" // CcAa
- "punpcklwd %%mm1, %%mm0 \n\t" // BAba
- "punpckhwd %%mm1, %%mm2 \n\t" // DCdc
- "punpcklwd %%mm5, %%mm4 \n\t" // FEfe
- "movq %%mm0, %%mm1 \n\t" // BAba
- "movq %%mm4, %%mm3 \n\t" // FEfe
- "punpckldq %%mm2, %%mm0 \n\t" // dcba
- "punpckhdq %%mm1, %%mm1 \n\t" // BABA
- "punpckldq %%mm1, %%mm4 \n\t" // BAfe
- "punpckhdq %%mm3, %%mm2 \n\t" // FEDC
-
- "movq %%mm0, (%0, %%edi) \n\t"
- "movq %%mm4, 8(%0, %%edi) \n\t"
- "movq %%mm2, 16(%0, %%edi) \n\t"
- "addl $8, %%esi \n\t"
- " jnz 1b \n\t"
- "emms \n\t"
- :: "r" (s16+1536), "r" (f+256)
- :"%esi", "%edi", "memory"
- );
- return 6*256;
-}
-
-
-static void* a52_resample_MMX(int flags, int ch){
- switch (flags) {
- case A52_MONO:
- if(ch==5) return a52_resample_MONO_to_5_MMX;
- break;
- case A52_CHANNEL:
- case A52_STEREO:
- case A52_DOLBY:
- if(ch==2) return a52_resample_STEREO_to_2_MMX;
- break;
- case A52_3F:
- if(ch==5) return a52_resample_3F_to_5_MMX;
- break;
- case A52_2F2R:
- if(ch==4) return a52_resample_2F_2R_to_4_MMX;
- break;
- case A52_3F2R:
- if(ch==5) return a52_resample_3F_2R_to_5_MMX;
- break;
- case A52_MONO | A52_LFE:
- if(ch==6) return a52_resample_MONO_LFE_to_6_MMX;
- break;
- case A52_CHANNEL | A52_LFE:
- case A52_STEREO | A52_LFE:
- case A52_DOLBY | A52_LFE:
- if(ch==6) return a52_resample_STEREO_LFE_to_6_MMX;
- break;
- case A52_3F | A52_LFE:
- if(ch==6) return a52_resample_3F_LFE_to_6_MMX;
- break;
- case A52_2F2R | A52_LFE:
- if(ch==6) return a52_resample_2F_2R_LFE_to_6_MMX;
- break;
- case A52_3F2R | A52_LFE:
- if(ch==6) return a52_resample_3F_2R_LFE_to_6_MMX;
- break;
- }
- return NULL;
-}
-
-
+++ /dev/null
-/*
- * tables.h
- * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
- * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
- *
- * This file is part of a52dec, a free ATSC A-52 stream decoder.
- * See http://liba52.sourceforge.net/ for updates.
- *
- * a52dec is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * a52dec is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-static const int8_t exp_1[128] = {
- -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 25,25,25
-};
-static const int8_t exp_2[128] = {
- -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
- 25,25,25
-};
-static const int8_t exp_3[128] = {
- -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
- -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
- -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
- -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
- -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,
- 25,25,25
-};
-
-#define Q(x) ROUND (32768.0 * x)
-
-#define Q0 Q (-2/3)
-#define Q1 Q (0)
-#define Q2 Q (2/3)
-
-static const quantizer_t q_1_0[32] = {
- Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
- Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
- Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
- 0, 0, 0, 0, 0
-};
-
-static const quantizer_t q_1_1[32] = {
- Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
- Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
- Q0, Q0, Q0, Q1, Q1, Q1, Q2, Q2, Q2,
- 0, 0, 0, 0, 0
-};
-
-static const quantizer_t q_1_2[32] = {
- Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
- Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
- Q0, Q1, Q2, Q0, Q1, Q2, Q0, Q1, Q2,
- 0, 0, 0, 0, 0
-};
-
-#undef Q0
-#undef Q1
-#undef Q2
-
-#define Q0 Q (-4/5)
-#define Q1 Q (-2/5)
-#define Q2 Q (0)
-#define Q3 Q (2/5)
-#define Q4 Q (4/5)
-
-static const quantizer_t q_2_0[128] = {
- Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,Q0,
- Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,Q1,
- Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,Q2,
- Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,Q3,
- Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,Q4,
- 0,0,0
-};
-
-static const quantizer_t q_2_1[128] = {
- Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
- Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
- Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
- Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
- Q0,Q0,Q0,Q0,Q0,Q1,Q1,Q1,Q1,Q1,Q2,Q2,Q2,Q2,Q2,Q3,Q3,Q3,Q3,Q3,Q4,Q4,Q4,Q4,Q4,
- 0,0,0
-};
-
-static const quantizer_t q_2_2[128] = {
- Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
- Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
- Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
- Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
- Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,Q0,Q1,Q2,Q3,Q4,
- 0,0,0
-};
-
-#undef Q0
-#undef Q1
-#undef Q2
-#undef Q3
-#undef Q4
-
-static const quantizer_t q_3[8] = {
- Q (-6/7), Q (-4/7), Q (-2/7), Q (0), Q (2/7), Q (4/7), Q (6/7), 0
-};
-
-#define Q0 Q (-10/11)
-#define Q1 Q (-8/11)
-#define Q2 Q (-6/11)
-#define Q3 Q (-4/11)
-#define Q4 Q (-2/11)
-#define Q5 Q (0)
-#define Q6 Q (2/11)
-#define Q7 Q (4/11)
-#define Q8 Q (6/11)
-#define Q9 Q (8/11)
-#define QA Q (10/11)
-
-static const quantizer_t q_4_0[128] = {
- Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0, Q0,
- Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1, Q1,
- Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2, Q2,
- Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3, Q3,
- Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4, Q4,
- Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5, Q5,
- Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6, Q6,
- Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7, Q7,
- Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8, Q8,
- Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9, Q9,
- QA, QA, QA, QA, QA, QA, QA, QA, QA, QA, QA,
- 0, 0, 0, 0, 0, 0, 0
-};
-
-static const quantizer_t q_4_1[128] = {
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- Q0, Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, QA,
- 0, 0, 0, 0, 0, 0, 0
-};
-
-#undef Q0
-#undef Q1
-#undef Q2
-#undef Q3
-#undef Q4
-#undef Q5
-#undef Q6
-#undef Q7
-#undef Q8
-#undef Q9
-#undef QA
-
-static const quantizer_t q_5[16] = {
- Q (-14/15), Q (-12/15), Q (-10/15), Q (-8/15), Q (-6/15),
- Q (-4/15), Q (-2/15), Q (0), Q (2/15), Q (4/15),
- Q (6/15), Q (8/15), Q (10/15), Q (12/15), Q (14/15), 0
-};
-
-#ifndef LIBA52_FIXED
-static const sample_t scale_factor[25] = {
- 0.000030517578125,
- 0.0000152587890625,
- 0.00000762939453125,
- 0.000003814697265625,
- 0.0000019073486328125,
- 0.00000095367431640625,
- 0.000000476837158203125,
- 0.0000002384185791015625,
- 0.00000011920928955078125,
- 0.000000059604644775390625,
- 0.0000000298023223876953125,
- 0.00000001490116119384765625,
- 0.000000007450580596923828125,
- 0.0000000037252902984619140625,
- 0.00000000186264514923095703125,
- 0.000000000931322574615478515625,
- 0.0000000004656612873077392578125,
- 0.00000000023283064365386962890625,
- 0.000000000116415321826934814453125,
- 0.0000000000582076609134674072265625,
- 0.00000000002910383045673370361328125,
- 0.000000000014551915228366851806640625,
- 0.0000000000072759576141834259033203125,
- 0.00000000000363797880709171295166015625,
- 0.000000000001818989403545856475830078125
-};
-#endif
-
-static const uint16_t dither_lut[256] = {
- 0x0000, 0xa011, 0xe033, 0x4022, 0x6077, 0xc066, 0x8044, 0x2055,
- 0xc0ee, 0x60ff, 0x20dd, 0x80cc, 0xa099, 0x0088, 0x40aa, 0xe0bb,
- 0x21cd, 0x81dc, 0xc1fe, 0x61ef, 0x41ba, 0xe1ab, 0xa189, 0x0198,
- 0xe123, 0x4132, 0x0110, 0xa101, 0x8154, 0x2145, 0x6167, 0xc176,
- 0x439a, 0xe38b, 0xa3a9, 0x03b8, 0x23ed, 0x83fc, 0xc3de, 0x63cf,
- 0x8374, 0x2365, 0x6347, 0xc356, 0xe303, 0x4312, 0x0330, 0xa321,
- 0x6257, 0xc246, 0x8264, 0x2275, 0x0220, 0xa231, 0xe213, 0x4202,
- 0xa2b9, 0x02a8, 0x428a, 0xe29b, 0xc2ce, 0x62df, 0x22fd, 0x82ec,
- 0x8734, 0x2725, 0x6707, 0xc716, 0xe743, 0x4752, 0x0770, 0xa761,
- 0x47da, 0xe7cb, 0xa7e9, 0x07f8, 0x27ad, 0x87bc, 0xc79e, 0x678f,
- 0xa6f9, 0x06e8, 0x46ca, 0xe6db, 0xc68e, 0x669f, 0x26bd, 0x86ac,
- 0x6617, 0xc606, 0x8624, 0x2635, 0x0660, 0xa671, 0xe653, 0x4642,
- 0xc4ae, 0x64bf, 0x249d, 0x848c, 0xa4d9, 0x04c8, 0x44ea, 0xe4fb,
- 0x0440, 0xa451, 0xe473, 0x4462, 0x6437, 0xc426, 0x8404, 0x2415,
- 0xe563, 0x4572, 0x0550, 0xa541, 0x8514, 0x2505, 0x6527, 0xc536,
- 0x258d, 0x859c, 0xc5be, 0x65af, 0x45fa, 0xe5eb, 0xa5c9, 0x05d8,
- 0xae79, 0x0e68, 0x4e4a, 0xee5b, 0xce0e, 0x6e1f, 0x2e3d, 0x8e2c,
- 0x6e97, 0xce86, 0x8ea4, 0x2eb5, 0x0ee0, 0xaef1, 0xeed3, 0x4ec2,
- 0x8fb4, 0x2fa5, 0x6f87, 0xcf96, 0xefc3, 0x4fd2, 0x0ff0, 0xafe1,
- 0x4f5a, 0xef4b, 0xaf69, 0x0f78, 0x2f2d, 0x8f3c, 0xcf1e, 0x6f0f,
- 0xede3, 0x4df2, 0x0dd0, 0xadc1, 0x8d94, 0x2d85, 0x6da7, 0xcdb6,
- 0x2d0d, 0x8d1c, 0xcd3e, 0x6d2f, 0x4d7a, 0xed6b, 0xad49, 0x0d58,
- 0xcc2e, 0x6c3f, 0x2c1d, 0x8c0c, 0xac59, 0x0c48, 0x4c6a, 0xec7b,
- 0x0cc0, 0xacd1, 0xecf3, 0x4ce2, 0x6cb7, 0xcca6, 0x8c84, 0x2c95,
- 0x294d, 0x895c, 0xc97e, 0x696f, 0x493a, 0xe92b, 0xa909, 0x0918,
- 0xe9a3, 0x49b2, 0x0990, 0xa981, 0x89d4, 0x29c5, 0x69e7, 0xc9f6,
- 0x0880, 0xa891, 0xe8b3, 0x48a2, 0x68f7, 0xc8e6, 0x88c4, 0x28d5,
- 0xc86e, 0x687f, 0x285d, 0x884c, 0xa819, 0x0808, 0x482a, 0xe83b,
- 0x6ad7, 0xcac6, 0x8ae4, 0x2af5, 0x0aa0, 0xaab1, 0xea93, 0x4a82,
- 0xaa39, 0x0a28, 0x4a0a, 0xea1b, 0xca4e, 0x6a5f, 0x2a7d, 0x8a6c,
- 0x4b1a, 0xeb0b, 0xab29, 0x0b38, 0x2b6d, 0x8b7c, 0xcb5e, 0x6b4f,
- 0x8bf4, 0x2be5, 0x6bc7, 0xcbd6, 0xeb83, 0x4b92, 0x0bb0, 0xaba1
-};
+++ /dev/null
-
-include ../../config.mak
-
-ifeq ($(SHARED_PP),yes)
-SPPLIB = libpostproc.so
-SPPVERSION = 0.0.1
-endif
-PPLIB = libpostproc.a
-
-PPOBJS=postprocess.o
-SPPOBJS=postprocess_pic.o
-
-CFLAGS = $(OPTFLAGS) $(MLIB_INC) -I. -I.. $(EXTRA_INC)
-# -I/usr/X11R6/include/
-
-.SUFFIXES: .c .o
-
-# .PHONY: all clean
-
-.c.o:
- $(CC) -c $(CFLAGS) -I.. -I../.. -o $@ $<
-
-all: $(SWSLIB) $(PPLIB) $(SPPLIB)
-
-clean:
- rm -f *.o *.a *~ *.so
-
-distclean:
- rm -f Makefile.bak *.o *.a *~ *.so .depend
-
-dep: depend
-
-depend:
- $(CC) -MM $(CFLAGS) postprocess.c 1>.depend
-
-ifeq ($(SHARED_PP),yes)
-postprocess_pic.o: postprocess.c
- $(CC) -c $(CFLAGS) -fomit-frame-pointer -fPIC -DPIC -I.. -I../.. -o $@ $<
-
-$(SPPLIB): $(SPPOBJS)
- $(CC) -shared -Wl,-soname,$(SPPLIB).0 \
- -o $(SPPLIB) $(SPPOBJS)
-endif
-
-$(PPLIB): $(PPOBJS)
- rm -f $@
- $(AR) rc $@ $(PPOBJS)
- $(RANLIB) $@
-
-install: all
-ifeq ($(SHARED_PP),yes)
- install -d $(prefix)/lib
- install -s -m 755 $(SPPLIB) $(prefix)/lib/$(SPPLIB).$(SPPVERSION)
- ln -sf $(SPPLIB).$(SPPVERSION) $(prefix)/lib/$(SPPLIB)
- ldconfig || true
- mkdir -p $(prefix)/include/postproc
- install -m 644 postprocess.h $(prefix)/include/postproc/postprocess.h
-endif
-
-
-#
-# include dependency files if they exist
-#
-ifneq ($(wildcard .depend),)
-include .depend
-endif
+++ /dev/null
-/* mangle.h - This file has some CPP macros to deal with different symbol
- * mangling across binary formats.
- * (c)2002 by Felix Buenemann <atmosfear at users.sourceforge.net>
- * File licensed under the GPL, see http://www.fsf.org/ for more info.
- */
-
-#ifndef __MANGLE_H
-#define __MANGLE_H
-
-/* Feel free to add more to the list, eg. a.out IMO */
-#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || \
- (defined(__OpenBSD__) && !defined(__ELF__))
-#define MANGLE(a) "_" #a
-#else
-#define MANGLE(a) #a
-#endif
-
-#endif /* !__MANGLE_H */
-
+++ /dev/null
-/*
- Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/**
- * @file postprocess.c
- * postprocessing.
- */
-
-/*
- C MMX MMX2 3DNow
-isVertDC Ec Ec
-isVertMinMaxOk Ec Ec
-doVertLowPass E e e
-doVertDefFilter Ec Ec e e
-isHorizDC Ec Ec
-isHorizMinMaxOk a E
-doHorizLowPass E e e
-doHorizDefFilter Ec Ec e e
-deRing E e e*
-Vertical RKAlgo1 E a a
-Horizontal RKAlgo1 a a
-Vertical X1# a E E
-Horizontal X1# a E E
-LinIpolDeinterlace e E E*
-CubicIpolDeinterlace a e e*
-LinBlendDeinterlace e E E*
-MedianDeinterlace# E Ec Ec
-TempDeNoiser# E e e
-
-* i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work
-# more or less selfinvented filters so the exactness isnt too meaningfull
-E = Exact implementation
-e = allmost exact implementation (slightly different rounding,...)
-a = alternative / approximate impl
-c = checked against the other implementations (-vo md5)
-*/
-
-/*
-TODO:
-reduce the time wasted on the mem transfer
-unroll stuff if instructions depend too much on the prior one
-move YScale thing to the end instead of fixing QP
-write a faster and higher quality deblocking filter :)
-make the mainloop more flexible (variable number of blocks at once
- (the if/else stuff per block is slowing things down)
-compare the quality & speed of all filters
-split this huge file
-optimize c versions
-try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
-...
-*/
-
-//Changelog: use the CVS log
-
-#include "config.h"
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-//#undef HAVE_MMX2
-//#define HAVE_3DNOW
-//#undef HAVE_MMX
-//#undef ARCH_X86
-//#define DEBUG_BRIGHTNESS
-#ifdef USE_FASTMEMCPY
-#include "../fastmemcpy.h"
-#endif
-#include "postprocess.h"
-#include "postprocess_internal.h"
-
-#include "mangle.h" //FIXME should be supressed
-
-#ifndef HAVE_MEMALIGN
-#define memalign(a,b) malloc(b)
-#endif
-
-#define MIN(a,b) ((a) > (b) ? (b) : (a))
-#define MAX(a,b) ((a) < (b) ? (b) : (a))
-#define ABS(a) ((a) > 0 ? (a) : (-(a)))
-#define SIGN(a) ((a) > 0 ? 1 : -1)
-
-#define GET_MODE_BUFFER_SIZE 500
-#define OPTIONS_ARRAY_SIZE 10
-#define BLOCK_SIZE 8
-#define TEMP_STRIDE 8
-//#define NUM_BLOCKS_AT_ONCE 16 //not used yet
-
-#ifdef ARCH_X86
-static uint64_t __attribute__((aligned(8))) w05= 0x0005000500050005LL;
-static uint64_t __attribute__((aligned(8))) w20= 0x0020002000200020LL;
-static uint64_t __attribute__((aligned(8))) b00= 0x0000000000000000LL;
-static uint64_t __attribute__((aligned(8))) b01= 0x0101010101010101LL;
-static uint64_t __attribute__((aligned(8))) b02= 0x0202020202020202LL;
-static uint64_t __attribute__((aligned(8))) b08= 0x0808080808080808LL;
-static uint64_t __attribute__((aligned(8))) b80= 0x8080808080808080LL;
-#endif
-
-
-static uint8_t clip_table[3*256];
-static uint8_t * const clip_tab= clip_table + 256;
-
-static int verbose= 0;
-
-static const int deringThreshold= 20;
-
-
-static struct PPFilter filters[]=
-{
- {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
- {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
-/* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER},
- {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/
- {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER},
- {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER},
- {"dr", "dering", 1, 5, 6, DERING},
- {"al", "autolevels", 0, 1, 2, LEVEL_FIX},
- {"lb", "linblenddeint", 1, 1, 4, INTERPOLATION_LINEAR_BLEND_DEINT_FILTER},
- {"li", "linipoldeint", 1, 1, 4, INTERPOLATION_LINEAR_IPOL_DEINT_FILTER},
- {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER},
- {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER},
- {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER},
- {"l5", "lowpass5", 1, 1, 4, LOWPASS5_DEINT_FILTER},
- {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER},
- {"fq", "forcequant", 1, 0, 0, FORCE_QUANT},
- {NULL, NULL,0,0,0,0} //End Marker
-};
-
-static char *replaceTable[]=
-{
- "default", "hdeblock:a,vdeblock:a,dering:a,autolevels,tmpnoise:a:150:200:400",
- "de", "hdeblock:a,vdeblock:a,dering:a,autolevels,tmpnoise:a:150:200:400",
- "fast", "x1hdeblock:a,x1vdeblock:a,dering:a,autolevels,tmpnoise:a:150:200:400",
- "fa", "x1hdeblock:a,x1vdeblock:a,dering:a,autolevels,tmpnoise:a:150:200:400",
- NULL //End Marker
-};
-
-#ifdef ARCH_X86
-static inline void unusedVariableWarningFixer()
-{
- if(w05 + w20 + b00 + b01 + b02 + b08 + b80 == 0) b00=0;
-}
-#endif
-
-
-#ifdef ARCH_X86
-static inline void prefetchnta(void *p)
-{
- asm volatile( "prefetchnta (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht0(void *p)
-{
- asm volatile( "prefetcht0 (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht1(void *p)
-{
- asm volatile( "prefetcht1 (%0)\n\t"
- : : "r" (p)
- );
-}
-
-static inline void prefetcht2(void *p)
-{
- asm volatile( "prefetcht2 (%0)\n\t"
- : : "r" (p)
- );
-}
-#endif
-
-// The horizontal Functions exist only in C cuz the MMX code is faster with vertical filters and transposing
-
-/**
- * Check if the given 8x8 Block is mostly "flat"
- */
-static inline int isHorizDC(uint8_t src[], int stride, PPContext *c)
-{
- int numEq= 0;
- int y;
- const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- const int dcThreshold= dcOffset*2 + 1;
-
- for(y=0; y<BLOCK_SIZE; y++)
- {
- if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[3] - src[4] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[4] - src[5] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[5] - src[6] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[6] - src[7] + dcOffset)) < dcThreshold) numEq++;
- src+= stride;
- }
- return numEq > c->ppMode.flatnessThreshold;
-}
-
-/**
- * Check if the middle 8x8 Block in the given 8x16 block is flat
- */
-static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c){
- int numEq= 0;
- int y;
- const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
- const int dcThreshold= dcOffset*2 + 1;
-
- src+= stride*4; // src points to begin of the 8x8 Block
- for(y=0; y<BLOCK_SIZE-1; y++)
- {
- if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[2] - src[2+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[3] - src[3+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[4] - src[4+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[5] - src[5+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[6] - src[6+stride] + dcOffset)) < dcThreshold) numEq++;
- if(((unsigned)(src[7] - src[7+stride] + dcOffset)) < dcThreshold) numEq++;
- src+= stride;
- }
- return numEq > c->ppMode.flatnessThreshold;
-}
-
-static inline int isHorizMinMaxOk(uint8_t src[], int stride, int QP)
-{
- int i;
-#if 1
- for(i=0; i<2; i++){
- if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[2] - src[7] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[4] - src[1] + 2*QP) > 4*QP) return 0;
- src += stride;
- if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
- src += stride;
- }
-#else
- for(i=0; i<8; i++){
- if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0;
- src += stride;
- }
-#endif
- return 1;
-}
-
-static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
-{
-#if 1
-#if 1
- int x;
- src+= stride*4;
- for(x=0; x<BLOCK_SIZE; x+=4)
- {
- if((unsigned)(src[ x + 0*stride] - src[ x + 5*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[1+x + 2*stride] - src[1+x + 7*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
- if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
- }
-#else
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- if((unsigned)(src[x + stride] - src[x + (stride<<3)] + 2*QP) > 4*QP) return 0;
- }
-#endif
- return 1;
-#else
- int x;
- src+= stride*4;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- int min=255;
- int max=0;
- int y;
- for(y=0; y<8; y++){
- int v= src[x + y*stride];
- if(v>max) max=v;
- if(v<min) min=v;
- }
- if(max-min > 2*QP) return 0;
- }
- return 1;
-#endif
-}
-
-static inline int vertClassify_C(uint8_t src[], int stride, PPContext *c){
- if( isVertDC_C(src, stride, c) ){
- if( isVertMinMaxOk_C(src, stride, c->QP) )
- return 1;
- else
- return 0;
- }else{
- return 2;
- }
-}
-
-static inline void doHorizDefFilter(uint8_t dst[], int stride, int QP)
-{
- int y;
- for(y=0; y<BLOCK_SIZE; y++)
- {
- const int middleEnergy= 5*(dst[4] - dst[5]) + 2*(dst[2] - dst[5]);
-
- if(ABS(middleEnergy) < 8*QP)
- {
- const int q=(dst[3] - dst[4])/2;
- const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
- const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- dst[3]-= d;
- dst[4]+= d;
- }
- dst+= stride;
- }
-}
-
-/**
- * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
- * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
- */
-static inline void doHorizLowPass(uint8_t dst[], int stride, int QP)
-{
-
- int y;
- for(y=0; y<BLOCK_SIZE; y++)
- {
- const int first= ABS(dst[-1] - dst[0]) < QP ? dst[-1] : dst[0];
- const int last= ABS(dst[8] - dst[7]) < QP ? dst[8] : dst[7];
-
- int sums[9];
- sums[0] = first + dst[0];
- sums[1] = dst[0] + dst[1];
- sums[2] = dst[1] + dst[2];
- sums[3] = dst[2] + dst[3];
- sums[4] = dst[3] + dst[4];
- sums[5] = dst[4] + dst[5];
- sums[6] = dst[5] + dst[6];
- sums[7] = dst[6] + dst[7];
- sums[8] = dst[7] + last;
-
- dst[0]= ((sums[0]<<2) + ((first + sums[2])<<1) + sums[4] + 8)>>4;
- dst[1]= ((dst[1]<<2) + ((first + sums[0] + sums[3])<<1) + sums[5] + 8)>>4;
- dst[2]= ((dst[2]<<2) + ((first + sums[1] + sums[4])<<1) + sums[6] + 8)>>4;
- dst[3]= ((dst[3]<<2) + ((sums[2] + sums[5])<<1) + sums[0] + sums[7] + 8)>>4;
- dst[4]= ((dst[4]<<2) + ((sums[3] + sums[6])<<1) + sums[1] + sums[8] + 8)>>4;
- dst[5]= ((dst[5]<<2) + ((last + sums[7] + sums[4])<<1) + sums[2] + 8)>>4;
- dst[6]= (((last + dst[6])<<2) + ((dst[7] + sums[5])<<1) + sums[3] + 8)>>4;
- dst[7]= ((sums[8]<<2) + ((last + sums[6])<<1) + sums[4] + 8)>>4;
-
- dst+= stride;
- }
-}
-
-/**
- * Experimental Filter 1 (Horizontal)
- * will not damage linear gradients
- * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
- * can only smooth blocks at the expected locations (it cant smooth them if they did move)
- * MMX2 version does correct clipping C version doesnt
- * not identical with the vertical one
- */
-static inline void horizX1Filter(uint8_t *src, int stride, int QP)
-{
- int y;
- static uint64_t *lut= NULL;
- if(lut==NULL)
- {
- int i;
- lut= (uint64_t*)memalign(8, 256*8);
- for(i=0; i<256; i++)
- {
- int v= i < 128 ? 2*i : 2*(i-256);
-/*
-//Simulate 112242211 9-Tap filter
- uint64_t a= (v/16) & 0xFF;
- uint64_t b= (v/8) & 0xFF;
- uint64_t c= (v/4) & 0xFF;
- uint64_t d= (3*v/8) & 0xFF;
-*/
-//Simulate piecewise linear interpolation
- uint64_t a= (v/16) & 0xFF;
- uint64_t b= (v*3/16) & 0xFF;
- uint64_t c= (v*5/16) & 0xFF;
- uint64_t d= (7*v/16) & 0xFF;
- uint64_t A= (0x100 - a)&0xFF;
- uint64_t B= (0x100 - b)&0xFF;
- uint64_t C= (0x100 - c)&0xFF;
- uint64_t D= (0x100 - c)&0xFF;
-
- lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |
- (D<<24) | (C<<16) | (B<<8) | (A);
- //lut[i] = (v<<32) | (v<<24);
- }
- }
-
- for(y=0; y<BLOCK_SIZE; y++)
- {
- int a= src[1] - src[2];
- int b= src[3] - src[4];
- int c= src[5] - src[6];
-
- int d= MAX(ABS(b) - (ABS(a) + ABS(c))/2, 0);
-
- if(d < QP)
- {
- int v = d * SIGN(-b);
-
- src[1] +=v/8;
- src[2] +=v/4;
- src[3] +=3*v/8;
- src[4] -=3*v/8;
- src[5] -=v/4;
- src[6] -=v/8;
-
- }
- src+=stride;
- }
-}
-
-
-//Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
-//Plain C versions
-#if !defined (HAVE_MMX) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_C
-#endif
-
-#ifdef ARCH_X86
-
-#if (defined (HAVE_MMX) && !defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_MMX
-#endif
-
-#if defined (HAVE_MMX2) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_MMX2
-#endif
-
-#if (defined (HAVE_3DNOW) && !defined (HAVE_MMX2)) || defined (RUNTIME_CPUDETECT)
-#define COMPILE_3DNOW
-#endif
-#endif //ARCH_X86
-
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#undef ARCH_X86
-
-#ifdef COMPILE_C
-#undef HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#undef ARCH_X86
-#define RENAME(a) a ## _C
-#include "postprocess_template.c"
-#endif
-
-//MMX versions
-#ifdef COMPILE_MMX
-#undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#undef HAVE_3DNOW
-#define ARCH_X86
-#define RENAME(a) a ## _MMX
-#include "postprocess_template.c"
-#endif
-
-//MMX2 versions
-#ifdef COMPILE_MMX2
-#undef RENAME
-#define HAVE_MMX
-#define HAVE_MMX2
-#undef HAVE_3DNOW
-#define ARCH_X86
-#define RENAME(a) a ## _MMX2
-#include "postprocess_template.c"
-#endif
-
-//3DNOW versions
-#ifdef COMPILE_3DNOW
-#undef RENAME
-#define HAVE_MMX
-#undef HAVE_MMX2
-#define HAVE_3DNOW
-#define ARCH_X86
-#define RENAME(a) a ## _3DNow
-#include "postprocess_template.c"
-#endif
-
-// minor note: the HAVE_xyz is messed up after that line so dont use it
-
-static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc)
-{
- PPContext *c= (PPContext *)vc;
- PPMode *ppMode= (PPMode *)vm;
- c->ppMode= *ppMode; //FIXME
-
- // useing ifs here as they are faster than function pointers allthough the
- // difference wouldnt be messureable here but its much better because
- // someone might exchange the cpu whithout restarting mplayer ;)
-#ifdef RUNTIME_CPUDETECT
-#ifdef ARCH_X86
- // ordered per speed fasterst first
- if(c->cpuCaps & PP_CPU_CAPS_MMX2)
- postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else if(c->cpuCaps & PP_CPU_CAPS_3DNOW)
- postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else if(c->cpuCaps & PP_CPU_CAPS_MMX)
- postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
- else
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#else
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#endif
-#else //RUNTIME_CPUDETECT
-#ifdef HAVE_MMX2
- postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_3DNOW)
- postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#elif defined (HAVE_MMX)
- postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#else
- postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
-#endif
-#endif //!RUNTIME_CPUDETECT
-}
-
-//static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
-// QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode);
-
-/* -pp Command line Help
-*/
-char *pp_help=
-"<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n"
-"long form example:\n"
-"vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n"
-"short form example:\n"
-"vb:a/hb:a/lb de,-vb\n"
-"more examples:\n"
-"tn:64:128:256\n"
-"Filters Options\n"
-"short long name short long option Description\n"
-"* * a autoq CPU power dependent enabler\n"
-" c chrom chrominance filtering enabled\n"
-" y nochrom chrominance filtering disabled\n"
-"hb hdeblock (2 threshold) horizontal deblocking filter\n"
-" 1. difference factor: default=32, higher -> more deblocking\n"
-" 2. flatness threshold: default=39, lower -> more deblocking\n"
-" the h & v deblocking filters share these\n"
-" so you can't set different thresholds for h / v\n"
-"vb vdeblock (2 threshold) vertical deblocking filter\n"
-"h1 x1hdeblock experimental h deblock filter 1\n"
-"v1 x1vdeblock experimental v deblock filter 1\n"
-"dr dering deringing filter\n"
-"al autolevels automatic brightness / contrast\n"
-" f fullyrange stretch luminance to (0..255)\n"
-"lb linblenddeint linear blend deinterlacer\n"
-"li linipoldeint linear interpolating deinterlace\n"
-"ci cubicipoldeint cubic interpolating deinterlacer\n"
-"md mediandeint median deinterlacer\n"
-"fd ffmpegdeint ffmpeg deinterlacer\n"
-"de default hb:a,vb:a,dr:a,al\n"
-"fa fast h1:a,v1:a,dr:a,al\n"
-"tn tmpnoise (3 threshold) temporal noise reducer\n"
-" 1. <= 2. <= 3. larger -> stronger filtering\n"
-"fq forceQuant <quantizer> force quantizer\n"
-;
-
-pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality)
-{
- char temp[GET_MODE_BUFFER_SIZE];
- char *p= temp;
- char *filterDelimiters= ",/";
- char *optionDelimiters= ":";
- struct PPMode *ppMode;
- char *filterToken;
-
- ppMode= memalign(8, sizeof(PPMode));
-
- ppMode->lumMode= 0;
- ppMode->chromMode= 0;
- ppMode->maxTmpNoise[0]= 700;
- ppMode->maxTmpNoise[1]= 1500;
- ppMode->maxTmpNoise[2]= 3000;
- ppMode->maxAllowedY= 234;
- ppMode->minAllowedY= 16;
- ppMode->baseDcDiff= 256/8;
- ppMode->flatnessThreshold= 56-16-1;
- ppMode->maxClippedThreshold= 0.01;
- ppMode->error=0;
-
- strncpy(temp, name, GET_MODE_BUFFER_SIZE);
-
- if(verbose>1) printf("pp: %s\n", name);
-
- for(;;){
- char *filterName;
- int q= 1000000; //PP_QUALITY_MAX;
- int chrom=-1;
- char *option;
- char *options[OPTIONS_ARRAY_SIZE];
- int i;
- int filterNameOk=0;
- int numOfUnknownOptions=0;
- int enable=1; //does the user want us to enabled or disabled the filter
-
- filterToken= strtok(p, filterDelimiters);
- if(filterToken == NULL) break;
- p+= strlen(filterToken) + 1; // p points to next filterToken
- filterName= strtok(filterToken, optionDelimiters);
- if(verbose>1) printf("pp: %s::%s\n", filterToken, filterName);
-
- if(*filterName == '-')
- {
- enable=0;
- filterName++;
- }
-
- for(;;){ //for all options
- option= strtok(NULL, optionDelimiters);
- if(option == NULL) break;
-
- if(verbose>1) printf("pp: option: %s\n", option);
- if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
- else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
- else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
- else
- {
- options[numOfUnknownOptions] = option;
- numOfUnknownOptions++;
- }
- if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
- }
- options[numOfUnknownOptions] = NULL;
-
- /* replace stuff from the replace Table */
- for(i=0; replaceTable[2*i]!=NULL; i++)
- {
- if(!strcmp(replaceTable[2*i], filterName))
- {
- int newlen= strlen(replaceTable[2*i + 1]);
- int plen;
- int spaceLeft;
-
- if(p==NULL) p= temp, *p=0; //last filter
- else p--, *p=','; //not last filter
-
- plen= strlen(p);
- spaceLeft= p - temp + plen;
- if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE)
- {
- ppMode->error++;
- break;
- }
- memmove(p + newlen, p, plen+1);
- memcpy(p, replaceTable[2*i + 1], newlen);
- filterNameOk=1;
- }
- }
-
- for(i=0; filters[i].shortName!=NULL; i++)
- {
-// printf("Compareing %s, %s, %s\n", filters[i].shortName,filters[i].longName, filterName);
- if( !strcmp(filters[i].longName, filterName)
- || !strcmp(filters[i].shortName, filterName))
- {
- ppMode->lumMode &= ~filters[i].mask;
- ppMode->chromMode &= ~filters[i].mask;
-
- filterNameOk=1;
- if(!enable) break; // user wants to disable it
-
- if(q >= filters[i].minLumQuality)
- ppMode->lumMode|= filters[i].mask;
- if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
- if(q >= filters[i].minChromQuality)
- ppMode->chromMode|= filters[i].mask;
-
- if(filters[i].mask == LEVEL_FIX)
- {
- int o;
- ppMode->minAllowedY= 16;
- ppMode->maxAllowedY= 234;
- for(o=0; options[o]!=NULL; o++)
- {
- if( !strcmp(options[o],"fullyrange")
- ||!strcmp(options[o],"f"))
- {
- ppMode->minAllowedY= 0;
- ppMode->maxAllowedY= 255;
- numOfUnknownOptions--;
- }
- }
- }
- else if(filters[i].mask == TEMP_NOISE_FILTER)
- {
- int o;
- int numOfNoises=0;
-
- for(o=0; options[o]!=NULL; o++)
- {
- char *tail;
- ppMode->maxTmpNoise[numOfNoises]=
- strtol(options[o], &tail, 0);
- if(tail!=options[o])
- {
- numOfNoises++;
- numOfUnknownOptions--;
- if(numOfNoises >= 3) break;
- }
- }
- }
- else if(filters[i].mask == V_DEBLOCK || filters[i].mask == H_DEBLOCK)
- {
- int o;
-
- for(o=0; options[o]!=NULL && o<2; o++)
- {
- char *tail;
- int val= strtol(options[o], &tail, 0);
- if(tail==options[o]) break;
-
- numOfUnknownOptions--;
- if(o==0) ppMode->baseDcDiff= val;
- else ppMode->flatnessThreshold= val;
- }
- }
- else if(filters[i].mask == FORCE_QUANT)
- {
- int o;
- ppMode->forcedQuant= 15;
-
- for(o=0; options[o]!=NULL && o<1; o++)
- {
- char *tail;
- int val= strtol(options[o], &tail, 0);
- if(tail==options[o]) break;
-
- numOfUnknownOptions--;
- ppMode->forcedQuant= val;
- }
- }
- }
- }
- if(!filterNameOk) ppMode->error++;
- ppMode->error += numOfUnknownOptions;
- }
-
- if(verbose>1) printf("pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
- if(ppMode->error)
- {
- fprintf(stderr, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
- free(ppMode);
- return NULL;
- }
- return ppMode;
-}
-
-void pp_free_mode(pp_mode_t *mode){
- if(mode) free(mode);
-}
-
-static void reallocAlign(void **p, int alignment, int size){
- if(*p) free(*p);
- *p= memalign(alignment, size);
- memset(*p, 0, size);
-}
-
-static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){
- int mbWidth = (width+15)>>4;
- int mbHeight= (height+15)>>4;
- int i;
-
- c->stride= stride;
- c->qpStride= qpStride;
-
- reallocAlign((void **)&c->tempDst, 8, stride*24);
- reallocAlign((void **)&c->tempSrc, 8, stride*24);
- reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
- reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
- for(i=0; i<256; i++)
- c->yHistogram[i]= width*height/64*15/256;
-
- for(i=0; i<3; i++)
- {
- //Note:the +17*1024 is just there so i dont have to worry about r/w over te end
- reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024);
- reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
- }
-
- reallocAlign((void **)&c->deintTemp, 8, 2*width+32);
- reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
- reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
- reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
-}
-
-static void global_init(void){
- int i;
- memset(clip_table, 0, 256);
- for(i=256; i<512; i++)
- clip_table[i]= i;
- memset(clip_table+512, 0, 256);
-}
-
-pp_context_t *pp_get_context(int width, int height, int cpuCaps){
- PPContext *c= memalign(32, sizeof(PPContext));
- int stride= (width+15)&(~15); //assumed / will realloc if needed
- int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
-
- global_init();
-
- memset(c, 0, sizeof(PPContext));
- c->cpuCaps= cpuCaps;
- if(cpuCaps&PP_FORMAT){
- c->hChromaSubSample= cpuCaps&0x3;
- c->vChromaSubSample= (cpuCaps>>4)&0x3;
- }else{
- c->hChromaSubSample= 1;
- c->vChromaSubSample= 1;
- }
-
- reallocBuffers(c, width, height, stride, qpStride);
-
- c->frameNum=-1;
-
- return c;
-}
-
-void pp_free_context(void *vc){
- PPContext *c = (PPContext*)vc;
- int i;
-
- for(i=0; i<3; i++) free(c->tempBlured[i]);
- for(i=0; i<3; i++) free(c->tempBluredPast[i]);
-
- free(c->tempBlocks);
- free(c->yHistogram);
- free(c->tempDst);
- free(c->tempSrc);
- free(c->deintTemp);
- free(c->stdQPTable);
- free(c->nonBQPTable);
- free(c->forcedQPTable);
-
- memset(c, 0, sizeof(PPContext));
-
- free(c);
-}
-
-void pp_postprocess(uint8_t * src[3], int srcStride[3],
- uint8_t * dst[3], int dstStride[3],
- int width, int height,
- QP_STORE_T *QP_store, int QPStride,
- pp_mode_t *vm, void *vc, int pict_type)
-{
- int mbWidth = (width+15)>>4;
- int mbHeight= (height+15)>>4;
- PPMode *mode = (PPMode*)vm;
- PPContext *c = (PPContext*)vc;
- int minStride= MAX(srcStride[0], dstStride[0]);
-
- if(c->stride < minStride || c->qpStride < QPStride)
- reallocBuffers(c, width, height,
- MAX(minStride, c->stride),
- MAX(c->qpStride, QPStride));
-
- if(QP_store==NULL || (mode->lumMode & FORCE_QUANT))
- {
- int i;
- QP_store= c->forcedQPTable;
- QPStride= 0;
- if(mode->lumMode & FORCE_QUANT)
- for(i=0; i<mbWidth; i++) QP_store[i]= mode->forcedQuant;
- else
- for(i=0; i<mbWidth; i++) QP_store[i]= 1;
- }
-//printf("pict_type:%d\n", pict_type);
-
- if(pict_type & PP_PICT_TYPE_QP2){
- int i;
- const int count= mbHeight * QPStride;
- for(i=0; i<(count>>2); i++){
- ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
- }
- for(i<<=2; i<count; i++){
- c->stdQPTable[i] = QP_store[i]>>1;
- }
- QP_store= c->stdQPTable;
- }
-
-if(0){
-int x,y;
-for(y=0; y<mbHeight; y++){
- for(x=0; x<mbWidth; x++){
- printf("%2d ", QP_store[x + y*QPStride]);
- }
- printf("\n");
-}
- printf("\n");
-}
-
- if((pict_type&7)!=3)
- {
- int i;
- const int count= mbHeight * QPStride;
- for(i=0; i<(count>>2); i++){
- ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x1F1F1F1F;
- }
- for(i<<=2; i<count; i++){
- c->nonBQPTable[i] = QP_store[i] & 0x1F;
- }
- }
-
- if(verbose>2)
- {
- printf("using npp filters 0x%X/0x%X\n", mode->lumMode, mode->chromMode);
- }
-
- postProcess(src[0], srcStride[0], dst[0], dstStride[0],
- width, height, QP_store, QPStride, 0, mode, c);
-
- width = (width )>>c->hChromaSubSample;
- height = (height)>>c->vChromaSubSample;
-
- if(mode->chromMode)
- {
- postProcess(src[1], srcStride[1], dst[1], dstStride[1],
- width, height, QP_store, QPStride, 1, mode, c);
- postProcess(src[2], srcStride[2], dst[2], dstStride[2],
- width, height, QP_store, QPStride, 2, mode, c);
- }
- else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2])
- {
- memcpy(dst[1], src[1], srcStride[1]*height);
- memcpy(dst[2], src[2], srcStride[2]*height);
- }
- else
- {
- int y;
- for(y=0; y<height; y++)
- {
- memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
- memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);
- }
- }
-}
-
+++ /dev/null
-/*
- Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#ifndef NEWPOSTPROCESS_H
-#define NEWPOSTPROCESS_H
-
-/**
- * @file postprocess.h
- * @brief
- * external api for the pp stuff
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define PP_QUALITY_MAX 6
-
-#define QP_STORE_T int8_t
-
-typedef void pp_context_t;
-typedef void pp_mode_t;
-
-extern char *pp_help; ///< a simple help text
-
-void pp_postprocess(uint8_t * src[3], int srcStride[3],
- uint8_t * dst[3], int dstStride[3],
- int horizontalSize, int verticalSize,
- QP_STORE_T *QP_store, int QP_stride,
- pp_mode_t *mode, pp_context_t *ppContext, int pict_type);
-
-
-/**
- * returns a pp_mode_t or NULL if an error occured
- * name is the string after "-pp" on the command line
- * quality is a number from 0 to PP_QUALITY_MAX
- */
-pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality);
-void pp_free_mode(pp_mode_t *mode);
-
-pp_context_t *pp_get_context(int width, int height, int flags);
-void pp_free_context(pp_context_t *ppContext);
-
-#define PP_CPU_CAPS_MMX 0x80000000
-#define PP_CPU_CAPS_MMX2 0x20000000
-#define PP_CPU_CAPS_3DNOW 0x40000000
-
-#define PP_FORMAT 0x00000008
-#define PP_FORMAT_420 (0x00000011|PP_FORMAT)
-#define PP_FORMAT_422 (0x00000001|PP_FORMAT)
-#define PP_FORMAT_411 (0x00000002|PP_FORMAT)
-#define PP_FORMAT_444 (0x00000000|PP_FORMAT)
-
-#define PP_PICT_TYPE_QP2 0x00000010 ///< MPEG2 style QScale
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-/*
- Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/**
- * @file postprocess_internal.h
- * internal api header.
- */
-
-#define V_DEBLOCK 0x01
-#define H_DEBLOCK 0x02
-#define DERING 0x04
-#define LEVEL_FIX 0x08 ///< Brightness & Contrast
-
-#define LUM_V_DEBLOCK V_DEBLOCK // 1
-#define LUM_H_DEBLOCK H_DEBLOCK // 2
-#define CHROM_V_DEBLOCK (V_DEBLOCK<<4) // 16
-#define CHROM_H_DEBLOCK (H_DEBLOCK<<4) // 32
-#define LUM_DERING DERING // 4
-#define CHROM_DERING (DERING<<4) // 64
-#define LUM_LEVEL_FIX LEVEL_FIX // 8
-#define CHROM_LEVEL_FIX (LEVEL_FIX<<4) // 128 (not implemented yet)
-
-// Experimental vertical filters
-#define V_X1_FILTER 0x0200 // 512
-
-// Experimental horizontal filters
-#define H_X1_FILTER 0x2000 // 8192
-
-/// select between full y range (255-0) or standart one (234-16)
-#define FULL_Y_RANGE 0x8000 // 32768
-
-//Deinterlacing Filters
-#define INTERPOLATION_LINEAR_IPOL_DEINT_FILTER 0x10000 // 65536
-#define INTERPOLATION_LINEAR_BLEND_DEINT_FILTER 0x20000 // 131072
-#define CUBIC_BLEND_DEINT_FILTER 0x8000 // (not implemented yet)
-#define CUBIC_IPOL_DEINT_FILTER 0x40000 // 262144
-#define MEDIAN_DEINT_FILTER 0x80000 // 524288
-#define FFMPEG_DEINT_FILTER 0x400000
-#define LOWPASS5_DEINT_FILTER 0x800000
-
-#define TEMP_NOISE_FILTER 0x100000
-#define FORCE_QUANT 0x200000
-
-//use if u want a faster postprocessing code
-//cant differentiate between chroma & luma filters (both on or both off)
-//obviosly the -pp option at the commandline has no effect except turning the here selected
-//filters on
-//#define COMPILE_TIME_MODE 0x77
-
-#if 1
-static inline int CLIP(int a){
- if(a&256) return ((a)>>31)^(-1);
- else return a;
-}
-//#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a))
-#elif 0
-#define CLIP(a) clip_tab[a]
-#else
-#define CLIP(a) (a)
-#endif
-/**
- * Postprocessng filter.
- */
-struct PPFilter{
- char *shortName;
- char *longName;
- int chromDefault; ///< is chrominance filtering on by default if this filter is manually activated
- int minLumQuality; ///< minimum quality to turn luminance filtering on
- int minChromQuality; ///< minimum quality to turn chrominance filtering on
- int mask; ///< Bitmask to turn this filter on
-};
-
-/**
- * Postprocessng mode.
- */
-typedef struct PPMode{
- int lumMode; ///< acivates filters for luminance
- int chromMode; ///< acivates filters for chrominance
- int error; ///< non zero on error
-
- int minAllowedY; ///< for brigtness correction
- int maxAllowedY; ///< for brihtness correction
- float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture
-
- int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences)
-
- int baseDcDiff;
- int flatnessThreshold;
-
- int forcedQuant; ///< quantizer if FORCE_QUANT is used
-} PPMode;
-
-/**
- * postprocess context.
- */
-typedef struct PPContext{
- uint8_t *tempBlocks; ///<used for the horizontal code
-
- /**
- * luma histogram.
- * we need 64bit here otherwise we'll going to have a problem
- * after watching a black picture for 5 hours
- */
- uint64_t *yHistogram;
-
- uint64_t __attribute__((aligned(8))) packedYOffset;
- uint64_t __attribute__((aligned(8))) packedYScale;
-
- /** Temporal noise reducing buffers */
- uint8_t *tempBlured[3];
- int32_t *tempBluredPast[3];
-
- /** Temporary buffers for handling the last row(s) */
- uint8_t *tempDst;
- uint8_t *tempSrc;
-
- uint8_t *deintTemp;
-
- uint64_t __attribute__((aligned(8))) pQPb;
- uint64_t __attribute__((aligned(8))) pQPb2;
-
- uint64_t __attribute__((aligned(8))) mmxDcOffset[32];
- uint64_t __attribute__((aligned(8))) mmxDcThreshold[32];
-
- QP_STORE_T *stdQPTable; ///< used to fix MPEG2 style qscale
- QP_STORE_T *nonBQPTable;
- QP_STORE_T *forcedQPTable;
-
- int QP;
- int nonBQP;
-
- int frameNum;
-
- int cpuCaps;
-
- int qpStride; ///<size of qp buffers (needed to realloc them if needed)
- int stride; ///<size of some buffers (needed to realloc them if needed)
-
- int hChromaSubSample;
- int vChromaSubSample;
-
- PPMode ppMode;
-} PPContext;
-
-
+++ /dev/null
-/*
- Copyright (C) 2001-2002 Michael Niedermayer (michaelni@gmx.at)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-/**
- * @file postprocess_template.c
- * mmx/mmx2/3dnow postprocess code.
- */
-
-
-#undef PAVGB
-#undef PMINUB
-#undef PMAXUB
-
-#ifdef HAVE_MMX2
-#define PAVGB(a,b) "pavgb " #a ", " #b " \n\t"
-#elif defined (HAVE_3DNOW)
-#define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t"
-#endif
-
-#ifdef HAVE_MMX2
-#define PMINUB(a,b,t) "pminub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
-#define PMINUB(b,a,t) \
- "movq " #a ", " #t " \n\t"\
- "psubusb " #b ", " #t " \n\t"\
- "psubb " #t ", " #a " \n\t"
-#endif
-
-#ifdef HAVE_MMX2
-#define PMAXUB(a,b) "pmaxub " #a ", " #b " \n\t"
-#elif defined (HAVE_MMX)
-#define PMAXUB(a,b) \
- "psubusb " #a ", " #b " \n\t"\
- "paddb " #a ", " #b " \n\t"
-#endif
-
-//FIXME? |255-0| = 1 (shouldnt be a problem ...)
-#ifdef HAVE_MMX
-/**
- * Check if the middle 8x8 Block in the given 8x16 block is flat
- */
-static inline int RENAME(vertClassify)(uint8_t src[], int stride, PPContext *c){
- int numEq= 0, dcOk;
- src+= stride*4; // src points to begin of the 8x8 Block
-asm volatile(
- "movq %0, %%mm7 \n\t"
- "movq %1, %%mm6 \n\t"
- : : "m" (c->mmxDcOffset[c->nonBQP]), "m" (c->mmxDcThreshold[c->nonBQP])
- );
-
-asm volatile(
- "leal (%2, %3), %%eax \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %1 eax eax+%2 eax+2%2 %1+4%2 ecx ecx+%2 ecx+2%2 %1+8%2 ecx+4%2
-
- "movq (%2), %%mm0 \n\t"
- "movq (%%eax), %%mm1 \n\t"
- "movq %%mm0, %%mm3 \n\t"
- "movq %%mm0, %%mm4 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm0 \n\t" // mm0 = differnece
- "paddb %%mm7, %%mm0 \n\t"
- "pcmpgtb %%mm6, %%mm0 \n\t"
-
- "movq (%%eax,%3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%eax, %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "leal (%%eax, %3, 4), %%eax \n\t"
-
- "movq (%2, %3, 4), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%eax), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
-
- "movq (%%eax, %3), %%mm2 \n\t"
- PMAXUB(%%mm2, %%mm4)
- PMINUB(%%mm2, %%mm3, %%mm5)
- "psubb %%mm2, %%mm1 \n\t"
- "paddb %%mm7, %%mm1 \n\t"
- "pcmpgtb %%mm6, %%mm1 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "movq (%%eax, %3, 2), %%mm1 \n\t"
- PMAXUB(%%mm1, %%mm4)
- PMINUB(%%mm1, %%mm3, %%mm5)
- "psubb %%mm1, %%mm2 \n\t"
- "paddb %%mm7, %%mm2 \n\t"
- "pcmpgtb %%mm6, %%mm2 \n\t"
- "paddb %%mm2, %%mm0 \n\t"
- "psubusb %%mm3, %%mm4 \n\t"
-
- " \n\t"
-#ifdef HAVE_MMX2
- "pxor %%mm7, %%mm7 \n\t"
- "psadbw %%mm7, %%mm0 \n\t"
-#else
- "movq %%mm0, %%mm1 \n\t"
- "psrlw $8, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $16, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-#endif
- "movq %4, %%mm7 \n\t" // QP,..., QP
- "paddusb %%mm7, %%mm7 \n\t" // 2QP ... 2QP
- "psubusb %%mm7, %%mm4 \n\t" // Diff <= 2QP -> 0
- "packssdw %%mm4, %%mm4 \n\t"
- "movd %%mm0, %0 \n\t"
- "movd %%mm4, %1 \n\t"
-
- : "=r" (numEq), "=r" (dcOk)
- : "r" (src), "r" (stride), "m" (c->pQPb)
- : "%eax"
- );
-
- numEq= (-numEq) &0xFF;
- if(numEq > c->ppMode.flatnessThreshold){
- if(dcOk) return 0;
- else return 1;
- }else{
- return 2;
- }
-}
-#endif
-
-/**
- * Do a vertical low pass filter on the 8x16 block (only write to the 8x8 block in the middle)
- * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16
- */
-static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
- asm volatile( //"movv %0 %1 %2\n\t"
- "movq %2, %%mm0 \n\t" // QP,..., QP
- "pxor %%mm4, %%mm4 \n\t"
-
- "movq (%0), %%mm6 \n\t"
- "movq (%0, %1), %%mm5 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm6, %%mm2 \n\t"
- "psubusb %%mm6, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
- "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
-
- "pand %%mm2, %%mm6 \n\t"
- "pandn %%mm1, %%mm2 \n\t"
- "por %%mm2, %%mm6 \n\t"// First Line to Filter
-
- "movq (%0, %1, 8), %%mm5 \n\t"
- "leal (%0, %1, 4), %%eax \n\t"
- "leal (%0, %1, 8), %%ecx \n\t"
- "subl %1, %%ecx \n\t"
- "addl %1, %0 \n\t" // %0 points to line 1 not 0
- "movq (%0, %1, 8), %%mm7 \n\t"
- "movq %%mm5, %%mm1 \n\t"
- "movq %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm5 \n\t"
- "psubusb %%mm1, %%mm2 \n\t"
- "por %%mm5, %%mm2 \n\t" // ABS Diff of lines
- "psubusb %%mm0, %%mm2 \n\t" // diff <= QP -> 0
- "pcmpeqb %%mm4, %%mm2 \n\t" // diff <= QP -> FF
-
- "pand %%mm2, %%mm7 \n\t"
- "pandn %%mm1, %%mm2 \n\t"
- "por %%mm2, %%mm7 \n\t" // First Line to Filter
-
-
- // 1 2 3 4 5 6 7 8
- // %0 %0+%1 %0+2%1 eax %0+4%1 eax+2%1 ecx eax+4%1
- // 6 4 2 2 1 1
- // 6 4 4 2
- // 6 8 2
-
- "movq (%0, %1), %%mm0 \n\t" // 1
- "movq %%mm0, %%mm1 \n\t" // 1
- PAVGB(%%mm6, %%mm0) //1 1 /2
- PAVGB(%%mm6, %%mm0) //3 1 /4
-
- "movq (%0, %1, 4), %%mm2 \n\t" // 1
- "movq %%mm2, %%mm5 \n\t" // 1
- PAVGB((%%eax), %%mm2) // 11 /2
- PAVGB((%0, %1, 2), %%mm2) // 211 /4
- "movq %%mm2, %%mm3 \n\t" // 211 /4
- "movq (%0), %%mm4 \n\t" // 1
- PAVGB(%%mm4, %%mm3) // 4 211 /8
- PAVGB(%%mm0, %%mm3) //642211 /16
- "movq %%mm3, (%0) \n\t" // X
- // mm1=2 mm2=3(211) mm4=1 mm5=5 mm6=0 mm7=9
- "movq %%mm1, %%mm0 \n\t" // 1
- PAVGB(%%mm6, %%mm0) //1 1 /2
- "movq %%mm4, %%mm3 \n\t" // 1
- PAVGB((%0,%1,2), %%mm3) // 1 1 /2
- PAVGB((%%eax,%1,2), %%mm5) // 11 /2
- PAVGB((%%eax), %%mm5) // 211 /4
- PAVGB(%%mm5, %%mm3) // 2 2211 /8
- PAVGB(%%mm0, %%mm3) //4242211 /16
- "movq %%mm3, (%0,%1) \n\t" // X
- // mm1=2 mm2=3(211) mm4=1 mm5=4(211) mm6=0 mm7=9
- PAVGB(%%mm4, %%mm6) //11 /2
- "movq (%%ecx), %%mm0 \n\t" // 1
- PAVGB((%%eax, %1, 2), %%mm0) // 11/2
- "movq %%mm0, %%mm3 \n\t" // 11/2
- PAVGB(%%mm1, %%mm0) // 2 11/4
- PAVGB(%%mm6, %%mm0) //222 11/8
- PAVGB(%%mm2, %%mm0) //22242211/16
- "movq (%0, %1, 2), %%mm2 \n\t" // 1
- "movq %%mm0, (%0, %1, 2) \n\t" // X
- // mm1=2 mm2=3 mm3=6(11) mm4=1 mm5=4(211) mm6=0(11) mm7=9
- "movq (%%eax, %1, 4), %%mm0 \n\t" // 1
- PAVGB((%%ecx), %%mm0) // 11 /2
- PAVGB(%%mm0, %%mm6) //11 11 /4
- PAVGB(%%mm1, %%mm4) // 11 /2
- PAVGB(%%mm2, %%mm1) // 11 /2
- PAVGB(%%mm1, %%mm6) //1122 11 /8
- PAVGB(%%mm5, %%mm6) //112242211 /16
- "movq (%%eax), %%mm5 \n\t" // 1
- "movq %%mm6, (%%eax) \n\t" // X
- // mm0=7(11) mm1=2(11) mm2=3 mm3=6(11) mm4=1(11) mm5=4 mm7=9
- "movq (%%eax, %1, 4), %%mm6 \n\t" // 1
- PAVGB(%%mm7, %%mm6) // 11 /2
- PAVGB(%%mm4, %%mm6) // 11 11 /4
- PAVGB(%%mm3, %%mm6) // 11 2211 /8
- PAVGB(%%mm5, %%mm2) // 11 /2
- "movq (%0, %1, 4), %%mm4 \n\t" // 1
- PAVGB(%%mm4, %%mm2) // 112 /4
- PAVGB(%%mm2, %%mm6) // 112242211 /16
- "movq %%mm6, (%0, %1, 4) \n\t" // X
- // mm0=7(11) mm1=2(11) mm2=3(112) mm3=6(11) mm4=5 mm5=4 mm7=9
- PAVGB(%%mm7, %%mm1) // 11 2 /4
- PAVGB(%%mm4, %%mm5) // 11 /2
- PAVGB(%%mm5, %%mm0) // 11 11 /4
- "movq (%%eax, %1, 2), %%mm6 \n\t" // 1
- PAVGB(%%mm6, %%mm1) // 11 4 2 /8
- PAVGB(%%mm0, %%mm1) // 11224222 /16
- "movq %%mm1, (%%eax, %1, 2) \n\t" // X
- // mm2=3(112) mm3=6(11) mm4=5 mm5=4(11) mm6=6 mm7=9
- PAVGB((%%ecx), %%mm2) // 112 4 /8
- "movq (%%eax, %1, 4), %%mm0 \n\t" // 1
- PAVGB(%%mm0, %%mm6) // 1 1 /2
- PAVGB(%%mm7, %%mm6) // 1 12 /4
- PAVGB(%%mm2, %%mm6) // 1122424 /4
- "movq %%mm6, (%%ecx) \n\t" // X
- // mm0=8 mm3=6(11) mm4=5 mm5=4(11) mm7=9
- PAVGB(%%mm7, %%mm5) // 11 2 /4
- PAVGB(%%mm7, %%mm5) // 11 6 /8
-
- PAVGB(%%mm3, %%mm0) // 112 /4
- PAVGB(%%mm0, %%mm5) // 112246 /16
- "movq %%mm5, (%%eax, %1, 4) \n\t" // X
- "subl %1, %0 \n\t"
-
- :
- : "r" (src), "r" (stride), "m" (c->pQPb)
- : "%eax", "%ecx"
- );
-#else
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
- const int l8= stride + l7;
- const int l9= stride + l8;
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int first= ABS(src[0] - src[l1]) < c->QP ? src[0] : src[l1];
- const int last= ABS(src[l8] - src[l9]) < c->QP ? src[l9] : src[l8];
-
- int sums[9];
- sums[0] = first + src[l1];
- sums[1] = src[l1] + src[l2];
- sums[2] = src[l2] + src[l3];
- sums[3] = src[l3] + src[l4];
- sums[4] = src[l4] + src[l5];
- sums[5] = src[l5] + src[l6];
- sums[6] = src[l6] + src[l7];
- sums[7] = src[l7] + src[l8];
- sums[8] = src[l8] + last;
-
- src[l1]= ((sums[0]<<2) + ((first + sums[2])<<1) + sums[4] + 8)>>4;
- src[l2]= ((src[l2]<<2) + ((first + sums[0] + sums[3])<<1) + sums[5] + 8)>>4;
- src[l3]= ((src[l3]<<2) + ((first + sums[1] + sums[4])<<1) + sums[6] + 8)>>4;
- src[l4]= ((src[l4]<<2) + ((sums[2] + sums[5])<<1) + sums[0] + sums[7] + 8)>>4;
- src[l5]= ((src[l5]<<2) + ((sums[3] + sums[6])<<1) + sums[1] + sums[8] + 8)>>4;
- src[l6]= ((src[l6]<<2) + ((last + sums[7] + sums[4])<<1) + sums[2] + 8)>>4;
- src[l7]= (((last + src[l7])<<2) + ((src[l8] + sums[5])<<1) + sums[3] + 8)>>4;
- src[l8]= ((sums[8]<<2) + ((last + sums[6])<<1) + sums[4] + 8)>>4;
-
- src++;
- }
-#endif
-}
-
-#if 0
-/**
- * Experimental implementation of the filter (Algorithm 1) described in a paper from Ramkishor & Karandikar
- * values are correctly clipped (MMX2)
- * values are wraparound (C)
- * conclusion: its fast, but introduces ugly horizontal patterns if there is a continious gradient
- 0 8 16 24
- x = 8
- x/2 = 4
- x/8 = 1
- 1 12 12 23
- */
-static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
-// FIXME rounding
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t" // 0
- "movq "MANGLE(b80)", %%mm6 \n\t" // MIN_SIGNED_BYTE
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%ecx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
- "movq "MANGLE(pQPb)", %%mm0 \n\t" // QP,..., QP
- "movq %%mm0, %%mm1 \n\t" // QP,..., QP
- "paddusb "MANGLE(b02)", %%mm0 \n\t"
- "psrlw $2, %%mm0 \n\t"
- "pand "MANGLE(b3F)", %%mm0 \n\t" // QP/4,..., QP/4
- "paddusb %%mm1, %%mm0 \n\t" // QP*1.25 ...
- "movq (%0, %1, 4), %%mm2 \n\t" // line 4
- "movq (%%ecx), %%mm3 \n\t" // line 5
- "movq %%mm2, %%mm4 \n\t" // line 4
- "pcmpeqb %%mm5, %%mm5 \n\t" // -1
- "pxor %%mm2, %%mm5 \n\t" // -line 4 - 1
- PAVGB(%%mm3, %%mm5)
- "paddb %%mm6, %%mm5 \n\t" // (l5-l4)/2
- "psubusb %%mm3, %%mm4 \n\t"
- "psubusb %%mm2, %%mm3 \n\t"
- "por %%mm3, %%mm4 \n\t" // |l4 - l5|
- "psubusb %%mm0, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm4 \n\t"
- "pand %%mm4, %%mm5 \n\t" // d/2
-
-// "paddb %%mm6, %%mm2 \n\t" // line 4 + 0x80
- "paddb %%mm5, %%mm2 \n\t"
-// "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%0,%1, 4) \n\t"
-
- "movq (%%ecx), %%mm2 \n\t"
-// "paddb %%mm6, %%mm2 \n\t" // line 5 + 0x80
- "psubb %%mm5, %%mm2 \n\t"
-// "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%ecx) \n\t"
-
- "paddb %%mm6, %%mm5 \n\t"
- "psrlw $2, %%mm5 \n\t"
- "pand "MANGLE(b3F)", %%mm5 \n\t"
- "psubb "MANGLE(b20)", %%mm5 \n\t" // (l5-l4)/8
-
- "movq (%%eax, %1, 2), %%mm2 \n\t"
- "paddb %%mm6, %%mm2 \n\t" // line 3 + 0x80
- "paddsb %%mm5, %%mm2 \n\t"
- "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%eax, %1, 2) \n\t"
-
- "movq (%%ecx, %1), %%mm2 \n\t"
- "paddb %%mm6, %%mm2 \n\t" // line 6 + 0x80
- "psubsb %%mm5, %%mm2 \n\t"
- "psubb %%mm6, %%mm2 \n\t"
- "movq %%mm2, (%%ecx, %1) \n\t"
-
- :
- : "r" (src), "r" (stride)
- : "%eax", "%ecx"
- );
-#else
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
-// const int l7= stride + l6;
-// const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
- const int QP15= QP + (QP>>2);
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int v = (src[x+l5] - src[x+l4]);
- if(ABS(v) < QP15)
- {
- src[x+l3] +=v>>3;
- src[x+l4] +=v>>1;
- src[x+l5] -=v>>1;
- src[x+l6] -=v>>3;
-
- }
- }
-
-#endif
-}
-#endif
-
-/**
- * Experimental Filter 1
- * will not damage linear gradients
- * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
- * can only smooth blocks at the expected locations (it cant smooth them if they did move)
- * MMX2 version does correct clipping C version doesnt
- */
-static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
-
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t" // 0
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%ecx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
- "movq (%%eax, %1, 2), %%mm0 \n\t" // line 3
- "movq (%0, %1, 4), %%mm1 \n\t" // line 4
- "movq %%mm1, %%mm2 \n\t" // line 4
- "psubusb %%mm0, %%mm1 \n\t"
- "psubusb %%mm2, %%mm0 \n\t"
- "por %%mm1, %%mm0 \n\t" // |l2 - l3|
- "movq (%%ecx), %%mm3 \n\t" // line 5
- "movq (%%ecx, %1), %%mm4 \n\t" // line 6
- "movq %%mm3, %%mm5 \n\t" // line 5
- "psubusb %%mm4, %%mm3 \n\t"
- "psubusb %%mm5, %%mm4 \n\t"
- "por %%mm4, %%mm3 \n\t" // |l5 - l6|
- PAVGB(%%mm3, %%mm0) // (|l2 - l3| + |l5 - l6|)/2
- "movq %%mm2, %%mm1 \n\t" // line 4
- "psubusb %%mm5, %%mm2 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm2 \n\t" // (l4 - l5) <= 0 ? -1 : 0
- "psubusb %%mm1, %%mm5 \n\t"
- "por %%mm5, %%mm4 \n\t" // |l4 - l5|
- "psubusb %%mm0, %%mm4 \n\t" //d = MAX(0, |l4-l5| - (|l2-l3| + |l5-l6|)/2)
- "movq %%mm4, %%mm3 \n\t" // d
- "movq %2, %%mm0 \n\t"
- "paddusb %%mm0, %%mm0 \n\t"
- "psubusb %%mm0, %%mm4 \n\t"
- "pcmpeqb %%mm7, %%mm4 \n\t" // d <= QP ? -1 : 0
- "psubusb "MANGLE(b01)", %%mm3 \n\t"
- "pand %%mm4, %%mm3 \n\t" // d <= QP ? d : 0
-
- PAVGB(%%mm7, %%mm3) // d/2
- "movq %%mm3, %%mm1 \n\t" // d/2
- PAVGB(%%mm7, %%mm3) // d/4
- PAVGB(%%mm1, %%mm3) // 3*d/8
-
- "movq (%0, %1, 4), %%mm0 \n\t" // line 4
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
- "psubusb %%mm3, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%0, %1, 4) \n\t" // line 4
-
- "movq (%%ecx), %%mm0 \n\t" // line 5
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
- "paddusb %%mm3, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%ecx) \n\t" // line 5
-
- PAVGB(%%mm7, %%mm1) // d/4
-
- "movq (%%eax, %1, 2), %%mm0 \n\t" // line 3
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l4-1 : l4
- "psubusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%eax, %1, 2) \n\t" // line 3
-
- "movq (%%ecx, %1), %%mm0 \n\t" // line 6
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l5-1 : l5
- "paddusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%ecx, %1) \n\t" // line 6
-
- PAVGB(%%mm7, %%mm1) // d/8
-
- "movq (%%eax, %1), %%mm0 \n\t" // line 2
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l2-1 : l2
- "psubusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%eax, %1) \n\t" // line 2
-
- "movq (%%ecx, %1, 2), %%mm0 \n\t" // line 7
- "pxor %%mm2, %%mm0 \n\t" //(l4 - l5) <= 0 ? -l7-1 : l7
- "paddusb %%mm1, %%mm0 \n\t"
- "pxor %%mm2, %%mm0 \n\t"
- "movq %%mm0, (%%ecx, %1, 2) \n\t" // line 7
-
- :
- : "r" (src), "r" (stride), "m" (co->pQPb)
- : "%eax", "%ecx"
- );
-#else
-
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
-// const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
-
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- int a= src[l3] - src[l4];
- int b= src[l4] - src[l5];
- int c= src[l5] - src[l6];
-
- int d= ABS(b) - ((ABS(a) + ABS(c))>>1);
- d= MAX(d, 0);
-
- if(d < co->QP*2)
- {
- int v = d * SIGN(-b);
-
- src[l2] +=v>>3;
- src[l3] +=v>>2;
- src[l4] +=(3*v)>>3;
- src[l5] -=(3*v)>>3;
- src[l6] -=v>>2;
- src[l7] -=v>>3;
-
- }
- src++;
- }
-#endif
-}
-
-static inline void RENAME(doVertDefFilter)(uint8_t src[], int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
-/*
- uint8_t tmp[16];
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= (int)tmp - (int)src - stride*3;
- const int l5= (int)tmp - (int)src - stride*3 + 8;
- const int l6= stride*3 + l3;
- const int l7= stride + l6;
- const int l8= stride + l7;
-
- memcpy(tmp, src+stride*7, 8);
- memcpy(tmp+8, src+stride*8, 8);
-*/
- src+= stride*4;
- asm volatile(
-
-#if 0 //sligtly more accurate and slightly slower
- "pxor %%mm7, %%mm7 \n\t" // 0
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%ecx \n\t"
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
-
-
- "movq (%0, %1, 2), %%mm0 \n\t" // l2
- "movq (%0), %%mm1 \n\t" // l0
- "movq %%mm0, %%mm2 \n\t" // l2
- PAVGB(%%mm7, %%mm0) // ~l2/2
- PAVGB(%%mm1, %%mm0) // ~(l2 + 2l0)/4
- PAVGB(%%mm2, %%mm0) // ~(5l2 + 2l0)/8
-
- "movq (%%eax), %%mm1 \n\t" // l1
- "movq (%%eax, %1, 2), %%mm3 \n\t" // l3
- "movq %%mm1, %%mm4 \n\t" // l1
- PAVGB(%%mm7, %%mm1) // ~l1/2
- PAVGB(%%mm3, %%mm1) // ~(l1 + 2l3)/4
- PAVGB(%%mm4, %%mm1) // ~(5l1 + 2l3)/8
-
- "movq %%mm0, %%mm4 \n\t" // ~(5l2 + 2l0)/8
- "psubusb %%mm1, %%mm0 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "por %%mm0, %%mm1 \n\t" // ~|2l0 - 5l1 + 5l2 - 2l3|/8
-// mm1= |lenergy|, mm2= l2, mm3= l3, mm7=0
-
- "movq (%0, %1, 4), %%mm0 \n\t" // l4
- "movq %%mm0, %%mm4 \n\t" // l4
- PAVGB(%%mm7, %%mm0) // ~l4/2
- PAVGB(%%mm2, %%mm0) // ~(l4 + 2l2)/4
- PAVGB(%%mm4, %%mm0) // ~(5l4 + 2l2)/8
-
- "movq (%%ecx), %%mm2 \n\t" // l5
- "movq %%mm3, %%mm5 \n\t" // l3
- PAVGB(%%mm7, %%mm3) // ~l3/2
- PAVGB(%%mm2, %%mm3) // ~(l3 + 2l5)/4
- PAVGB(%%mm5, %%mm3) // ~(5l3 + 2l5)/8
-
- "movq %%mm0, %%mm6 \n\t" // ~(5l4 + 2l2)/8
- "psubusb %%mm3, %%mm0 \n\t"
- "psubusb %%mm6, %%mm3 \n\t"
- "por %%mm0, %%mm3 \n\t" // ~|2l2 - 5l3 + 5l4 - 2l5|/8
- "pcmpeqb %%mm7, %%mm0 \n\t" // SIGN(2l2 - 5l3 + 5l4 - 2l5)
-// mm0= SIGN(menergy), mm1= |lenergy|, mm2= l5, mm3= |menergy|, mm4=l4, mm5= l3, mm7=0
-
- "movq (%%ecx, %1), %%mm6 \n\t" // l6
- "movq %%mm6, %%mm5 \n\t" // l6
- PAVGB(%%mm7, %%mm6) // ~l6/2
- PAVGB(%%mm4, %%mm6) // ~(l6 + 2l4)/4
- PAVGB(%%mm5, %%mm6) // ~(5l6 + 2l4)/8
-
- "movq (%%ecx, %1, 2), %%mm5 \n\t" // l7
- "movq %%mm2, %%mm4 \n\t" // l5
- PAVGB(%%mm7, %%mm2) // ~l5/2
- PAVGB(%%mm5, %%mm2) // ~(l5 + 2l7)/4
- PAVGB(%%mm4, %%mm2) // ~(5l5 + 2l7)/8
-
- "movq %%mm6, %%mm4 \n\t" // ~(5l6 + 2l4)/8
- "psubusb %%mm2, %%mm6 \n\t"
- "psubusb %%mm4, %%mm2 \n\t"
- "por %%mm6, %%mm2 \n\t" // ~|2l4 - 5l5 + 5l6 - 2l7|/8
-// mm0= SIGN(menergy), mm1= |lenergy|/8, mm2= |renergy|/8, mm3= |menergy|/8, mm7=0
-
-
- PMINUB(%%mm2, %%mm1, %%mm4) // MIN(|lenergy|,|renergy|)/8
- "movq %2, %%mm4 \n\t" // QP //FIXME QP+1 ?
- "paddusb "MANGLE(b01)", %%mm4 \n\t"
- "pcmpgtb %%mm3, %%mm4 \n\t" // |menergy|/8 < QP
- "psubusb %%mm1, %%mm3 \n\t" // d=|menergy|/8-MIN(|lenergy|,|renergy|)/8
- "pand %%mm4, %%mm3 \n\t"
-
- "movq %%mm3, %%mm1 \n\t"
-// "psubusb "MANGLE(b01)", %%mm3 \n\t"
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm7, %%mm3)
- "paddusb %%mm1, %%mm3 \n\t"
-// "paddusb "MANGLE(b01)", %%mm3 \n\t"
-
- "movq (%%eax, %1, 2), %%mm6 \n\t" //l3
- "movq (%0, %1, 4), %%mm5 \n\t" //l4
- "movq (%0, %1, 4), %%mm4 \n\t" //l4
- "psubusb %%mm6, %%mm5 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "por %%mm6, %%mm5 \n\t" // |l3-l4|
- "pcmpeqb %%mm7, %%mm6 \n\t" // SIGN(l3-l4)
- "pxor %%mm6, %%mm0 \n\t"
- "pand %%mm0, %%mm3 \n\t"
- PMINUB(%%mm5, %%mm3, %%mm0)
-
- "psubusb "MANGLE(b01)", %%mm3 \n\t"
- PAVGB(%%mm7, %%mm3)
-
- "movq (%%eax, %1, 2), %%mm0 \n\t"
- "movq (%0, %1, 4), %%mm2 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "psubb %%mm3, %%mm0 \n\t"
- "paddb %%mm3, %%mm2 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "movq %%mm0, (%%eax, %1, 2) \n\t"
- "movq %%mm2, (%0, %1, 4) \n\t"
-#endif
-
- "leal (%0, %1), %%eax \n\t"
- "pcmpeqb %%mm6, %%mm6 \n\t" // -1
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 ecx+%1 ecx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1
-
-
- "movq (%%eax, %1, 2), %%mm1 \n\t" // l3
- "movq (%0, %1, 4), %%mm0 \n\t" // l4
- "pxor %%mm6, %%mm1 \n\t" // -l3-1
- PAVGB(%%mm1, %%mm0) // -q+128 = (l4-l3+256)/2
-// mm1=-l3-1, mm0=128-q
-
- "movq (%%eax, %1, 4), %%mm2 \n\t" // l5
- "movq (%%eax, %1), %%mm3 \n\t" // l2
- "pxor %%mm6, %%mm2 \n\t" // -l5-1
- "movq %%mm2, %%mm5 \n\t" // -l5-1
- "movq "MANGLE(b80)", %%mm4 \n\t" // 128
- "leal (%%eax, %1, 4), %%ecx \n\t"
- PAVGB(%%mm3, %%mm2) // (l2-l5+256)/2
- PAVGB(%%mm0, %%mm4) // ~(l4-l3)/4 + 128
- PAVGB(%%mm2, %%mm4) // ~(l2-l5)/4 +(l4-l3)/8 + 128
- PAVGB(%%mm0, %%mm4) // ~(l2-l5)/8 +5(l4-l3)/16 + 128
-// mm1=-l3-1, mm0=128-q, mm3=l2, mm4=menergy/16 + 128, mm5= -l5-1
-
- "movq (%%eax), %%mm2 \n\t" // l1
- "pxor %%mm6, %%mm2 \n\t" // -l1-1
- PAVGB(%%mm3, %%mm2) // (l2-l1+256)/2
- PAVGB((%0), %%mm1) // (l0-l3+256)/2
- "movq "MANGLE(b80)", %%mm3 \n\t" // 128
- PAVGB(%%mm2, %%mm3) // ~(l2-l1)/4 + 128
- PAVGB(%%mm1, %%mm3) // ~(l0-l3)/4 +(l2-l1)/8 + 128
- PAVGB(%%mm2, %%mm3) // ~(l0-l3)/8 +5(l2-l1)/16 + 128
-// mm0=128-q, mm3=lenergy/16 + 128, mm4= menergy/16 + 128, mm5= -l5-1
-
- PAVGB((%%ecx, %1), %%mm5) // (l6-l5+256)/2
- "movq (%%ecx, %1, 2), %%mm1 \n\t" // l7
- "pxor %%mm6, %%mm1 \n\t" // -l7-1
- PAVGB((%0, %1, 4), %%mm1) // (l4-l7+256)/2
- "movq "MANGLE(b80)", %%mm2 \n\t" // 128
- PAVGB(%%mm5, %%mm2) // ~(l6-l5)/4 + 128
- PAVGB(%%mm1, %%mm2) // ~(l4-l7)/4 +(l6-l5)/8 + 128
- PAVGB(%%mm5, %%mm2) // ~(l4-l7)/8 +5(l6-l5)/16 + 128
-// mm0=128-q, mm2=renergy/16 + 128, mm3=lenergy/16 + 128, mm4= menergy/16 + 128
-
- "movq "MANGLE(b00)", %%mm1 \n\t" // 0
- "movq "MANGLE(b00)", %%mm5 \n\t" // 0
- "psubb %%mm2, %%mm1 \n\t" // 128 - renergy/16
- "psubb %%mm3, %%mm5 \n\t" // 128 - lenergy/16
- PMAXUB(%%mm1, %%mm2) // 128 + |renergy/16|
- PMAXUB(%%mm5, %%mm3) // 128 + |lenergy/16|
- PMINUB(%%mm2, %%mm3, %%mm1) // 128 + MIN(|lenergy|,|renergy|)/16
-
-// mm0=128-q, mm3=128 + MIN(|lenergy|,|renergy|)/16, mm4= menergy/16 + 128
-
- "movq "MANGLE(b00)", %%mm7 \n\t" // 0
- "movq %2, %%mm2 \n\t" // QP
- PAVGB(%%mm6, %%mm2) // 128 + QP/2
- "psubb %%mm6, %%mm2 \n\t"
-
- "movq %%mm4, %%mm1 \n\t"
- "pcmpgtb %%mm7, %%mm1 \n\t" // SIGN(menergy)
- "pxor %%mm1, %%mm4 \n\t"
- "psubb %%mm1, %%mm4 \n\t" // 128 + |menergy|/16
- "pcmpgtb %%mm4, %%mm2 \n\t" // |menergy|/16 < QP/2
- "psubusb %%mm3, %%mm4 \n\t" //d=|menergy|/16 - MIN(|lenergy|,|renergy|)/16
-// mm0=128-q, mm1= SIGN(menergy), mm2= |menergy|/16 < QP/2, mm4= d/16
-
- "movq %%mm4, %%mm3 \n\t" // d
- "psubusb "MANGLE(b01)", %%mm4 \n\t"
- PAVGB(%%mm7, %%mm4) // d/32
- PAVGB(%%mm7, %%mm4) // (d + 32)/64
- "paddb %%mm3, %%mm4 \n\t" // 5d/64
- "pand %%mm2, %%mm4 \n\t"
-
- "movq "MANGLE(b80)", %%mm5 \n\t" // 128
- "psubb %%mm0, %%mm5 \n\t" // q
- "paddsb %%mm6, %%mm5 \n\t" // fix bad rounding
- "pcmpgtb %%mm5, %%mm7 \n\t" // SIGN(q)
- "pxor %%mm7, %%mm5 \n\t"
-
- PMINUB(%%mm5, %%mm4, %%mm3) // MIN(|q|, 5d/64)
- "pxor %%mm1, %%mm7 \n\t" // SIGN(d*q)
-
- "pand %%mm7, %%mm4 \n\t"
- "movq (%%eax, %1, 2), %%mm0 \n\t"
- "movq (%0, %1, 4), %%mm2 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "pxor %%mm1, %%mm2 \n\t"
- "paddb %%mm4, %%mm0 \n\t"
- "psubb %%mm4, %%mm2 \n\t"
- "pxor %%mm1, %%mm0 \n\t"
- "pxor %%mm1, %%mm2 \n\t"
- "movq %%mm0, (%%eax, %1, 2) \n\t"
- "movq %%mm2, (%0, %1, 4) \n\t"
-
- :
- : "r" (src), "r" (stride), "m" (c->pQPb)
- : "%eax", "%ecx"
- );
-
-/*
- {
- int x;
- src-= stride;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
- if(ABS(middleEnergy)< 8*QP)
- {
- const int q=(src[l4] - src[l5])/2;
- const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
- const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- src[l4]-= d;
- src[l5]+= d;
- }
- src++;
- }
-src-=8;
- for(x=0; x<8; x++)
- {
- int y;
- for(y=4; y<6; y++)
- {
- int d= src[x+y*stride] - tmp[x+(y-4)*8];
- int ad= ABS(d);
- static int max=0;
- static int sum=0;
- static int num=0;
- static int bias=0;
-
- if(max<ad) max=ad;
- sum+= ad>3 ? 1 : 0;
- if(ad>3)
- {
- src[0] = src[7] = src[stride*7] = src[(stride+1)*7]=255;
- }
- if(y==4) bias+=d;
- num++;
- if(num%1000000 == 0)
- {
- printf(" %d %d %d %d\n", num, sum, max, bias);
- }
- }
- }
-}
-*/
-#elif defined (HAVE_MMX)
- src+= stride*4;
- asm volatile(
- "pxor %%mm7, %%mm7 \n\t"
- "leal -40(%%esp), %%ecx \n\t" // make space for 4 8-byte vars
- "andl $0xFFFFFFF8, %%ecx \n\t" // align
-// 0 1 2 3 4 5 6 7
-// %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1
-
- "movq (%0), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // low part of line 0
- "punpckhbw %%mm7, %%mm1 \n\t" // high part of line 0
-
- "movq (%0, %1), %%mm2 \n\t"
- "leal (%0, %1, 2), %%eax \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // low part of line 1
- "punpckhbw %%mm7, %%mm3 \n\t" // high part of line 1
-
- "movq (%%eax), %%mm4 \n\t"
- "movq %%mm4, %%mm5 \n\t"
- "punpcklbw %%mm7, %%mm4 \n\t" // low part of line 2
- "punpckhbw %%mm7, %%mm5 \n\t" // high part of line 2
-
- "paddw %%mm0, %%mm0 \n\t" // 2L0
- "paddw %%mm1, %%mm1 \n\t" // 2H0
- "psubw %%mm4, %%mm2 \n\t" // L1 - L2
- "psubw %%mm5, %%mm3 \n\t" // H1 - H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - L1 + L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - H1 + H2
-
- "psllw $2, %%mm2 \n\t" // 4L1 - 4L2
- "psllw $2, %%mm3 \n\t" // 4H1 - 4H2
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2
-
- "movq (%%eax, %1), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L3
- "punpckhbw %%mm7, %%mm3 \n\t" // H3
-
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3
- "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
- "movq %%mm0, (%%ecx) \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq %%mm1, 8(%%ecx) \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
- "movq (%%eax, %1, 2), %%mm0 \n\t"
- "movq %%mm0, %%mm1 \n\t"
- "punpcklbw %%mm7, %%mm0 \n\t" // L4
- "punpckhbw %%mm7, %%mm1 \n\t" // H4
-
- "psubw %%mm0, %%mm2 \n\t" // L3 - L4
- "psubw %%mm1, %%mm3 \n\t" // H3 - H4
- "movq %%mm2, 16(%%ecx) \n\t" // L3 - L4
- "movq %%mm3, 24(%%ecx) \n\t" // H3 - H4
- "paddw %%mm4, %%mm4 \n\t" // 2L2
- "paddw %%mm5, %%mm5 \n\t" // 2H2
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - H3 + H4
-
- "leal (%%eax, %1), %0 \n\t"
- "psllw $2, %%mm2 \n\t" // 4L3 - 4L4
- "psllw $2, %%mm3 \n\t" // 4H3 - 4H4
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4
-//50 opcodes so far
- "movq (%0, %1, 2), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L5
- "punpckhbw %%mm7, %%mm3 \n\t" // H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - H5
- "psubw %%mm2, %%mm4 \n\t" // 2L2 - 5L3 + 5L4 - 2L5
- "psubw %%mm3, %%mm5 \n\t" // 2H2 - 5H3 + 5H4 - 2H5
-
- "movq (%%eax, %1, 4), %%mm6 \n\t"
- "punpcklbw %%mm7, %%mm6 \n\t" // L6
- "psubw %%mm6, %%mm2 \n\t" // L5 - L6
- "movq (%%eax, %1, 4), %%mm6 \n\t"
- "punpckhbw %%mm7, %%mm6 \n\t" // H6
- "psubw %%mm6, %%mm3 \n\t" // H5 - H6
-
- "paddw %%mm0, %%mm0 \n\t" // 2L4
- "paddw %%mm1, %%mm1 \n\t" // 2H4
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - L5 + L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - H5 + H6
-
- "psllw $2, %%mm2 \n\t" // 4L5 - 4L6
- "psllw $2, %%mm3 \n\t" // 4H5 - 4H6
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6
-
- "movq (%0, %1, 4), %%mm2 \n\t"
- "movq %%mm2, %%mm3 \n\t"
- "punpcklbw %%mm7, %%mm2 \n\t" // L7
- "punpckhbw %%mm7, %%mm3 \n\t" // H7
-
- "paddw %%mm2, %%mm2 \n\t" // 2L7
- "paddw %%mm3, %%mm3 \n\t" // 2H7
- "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7
- "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7
-
- "movq (%%ecx), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3
- "movq 8(%%ecx), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3
-
-#ifdef HAVE_MMX2
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm0, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm1, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm2, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "psubw %%mm3, %%mm6 \n\t"
- "pmaxsw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#else
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm0, %%mm6 \n\t"
- "pxor %%mm6, %%mm0 \n\t"
- "psubw %%mm6, %%mm0 \n\t" // |2L4 - 5L5 + 5L6 - 2L7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm1, %%mm6 \n\t"
- "pxor %%mm6, %%mm1 \n\t"
- "psubw %%mm6, %%mm1 \n\t" // |2H4 - 5H5 + 5H6 - 2H7|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm2, %%mm6 \n\t"
- "pxor %%mm6, %%mm2 \n\t"
- "psubw %%mm6, %%mm2 \n\t" // |2L0 - 5L1 + 5L2 - 2L3|
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm3, %%mm6 \n\t"
- "pxor %%mm6, %%mm3 \n\t"
- "psubw %%mm6, %%mm3 \n\t" // |2H0 - 5H1 + 5H2 - 2H3|
-#endif
-
-#ifdef HAVE_MMX2
- "pminsw %%mm2, %%mm0 \n\t"
- "pminsw %%mm3, %%mm1 \n\t"
-#else
- "movq %%mm0, %%mm6 \n\t"
- "psubusw %%mm2, %%mm6 \n\t"
- "psubw %%mm6, %%mm0 \n\t"
- "movq %%mm1, %%mm6 \n\t"
- "psubusw %%mm3, %%mm6 \n\t"
- "psubw %%mm6, %%mm1 \n\t"
-#endif
-
- "movq %%mm7, %%mm6 \n\t" // 0
- "pcmpgtw %%mm4, %%mm6 \n\t" // sign(2L2 - 5L3 + 5L4 - 2L5)
- "pxor %%mm6, %%mm4 \n\t"
- "psubw %%mm6, %%mm4 \n\t" // |2L2 - 5L3 + 5L4 - 2L5|
- "pcmpgtw %%mm5, %%mm7 \n\t" // sign(2H2 - 5H3 + 5H4 - 2H5)
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm7, %%mm5 \n\t" // |2H2 - 5H3 + 5H4 - 2H5|
-// 100 opcodes
- "movd %2, %%mm2 \n\t" // QP
- "psllw $3, %%mm2 \n\t" // 8QP
- "movq %%mm2, %%mm3 \n\t" // 8QP
- "pcmpgtw %%mm4, %%mm2 \n\t"
- "pcmpgtw %%mm5, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-
- "psubusw %%mm0, %%mm4 \n\t" // hd
- "psubusw %%mm1, %%mm5 \n\t" // ld
-
-
- "movq "MANGLE(w05)", %%mm2 \n\t" // 5
- "pmullw %%mm2, %%mm4 \n\t"
- "pmullw %%mm2, %%mm5 \n\t"
- "movq "MANGLE(w20)", %%mm2 \n\t" // 32
- "paddw %%mm2, %%mm4 \n\t"
- "paddw %%mm2, %%mm5 \n\t"
- "psrlw $6, %%mm4 \n\t"
- "psrlw $6, %%mm5 \n\t"
-
- "movq 16(%%ecx), %%mm0 \n\t" // L3 - L4
- "movq 24(%%ecx), %%mm1 \n\t" // H3 - H4
-
- "pxor %%mm2, %%mm2 \n\t"
- "pxor %%mm3, %%mm3 \n\t"
-
- "pcmpgtw %%mm0, %%mm2 \n\t" // sign (L3-L4)
- "pcmpgtw %%mm1, %%mm3 \n\t" // sign (H3-H4)
- "pxor %%mm2, %%mm0 \n\t"
- "pxor %%mm3, %%mm1 \n\t"
- "psubw %%mm2, %%mm0 \n\t" // |L3-L4|
- "psubw %%mm3, %%mm1 \n\t" // |H3-H4|
- "psrlw $1, %%mm0 \n\t" // |L3 - L4|/2
- "psrlw $1, %%mm1 \n\t" // |H3 - H4|/2
-
- "pxor %%mm6, %%mm2 \n\t"
- "pxor %%mm7, %%mm3 \n\t"
- "pand %%mm2, %%mm4 \n\t"
- "pand %%mm3, %%mm5 \n\t"
-
-#ifdef HAVE_MMX2
- "pminsw %%mm0, %%mm4 \n\t"
- "pminsw %%mm1, %%mm5 \n\t"
-#else
- "movq %%mm4, %%mm2 \n\t"
- "psubusw %%mm0, %%mm2 \n\t"
- "psubw %%mm2, %%mm4 \n\t"
- "movq %%mm5, %%mm2 \n\t"
- "psubusw %%mm1, %%mm2 \n\t"
- "psubw %%mm2, %%mm5 \n\t"
-#endif
- "pxor %%mm6, %%mm4 \n\t"
- "pxor %%mm7, %%mm5 \n\t"
- "psubw %%mm6, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "packsswb %%mm5, %%mm4 \n\t"
- "movq (%0), %%mm0 \n\t"
- "paddb %%mm4, %%mm0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq (%0, %1), %%mm0 \n\t"
- "psubb %%mm4, %%mm0 \n\t"
- "movq %%mm0, (%0, %1) \n\t"
-
- : "+r" (src)
- : "r" (stride), "m" (c->pQPb)
- : "%eax", "%ecx"
- );
-#else
- const int l1= stride;
- const int l2= stride + l1;
- const int l3= stride + l2;
- const int l4= stride + l3;
- const int l5= stride + l4;
- const int l6= stride + l5;
- const int l7= stride + l6;
- const int l8= stride + l7;
-// const int l9= stride + l8;
- int x;
- src+= stride*3;
- for(x=0; x<BLOCK_SIZE; x++)
- {
- const int middleEnergy= 5*(src[l5] - src[l4]) + 2*(src[l3] - src[l6]);
- if(ABS(middleEnergy) < 8*c->QP)
- {
- const int q=(src[l4] - src[l5])/2;
- const int leftEnergy= 5*(src[l3] - src[l2]) + 2*(src[l1] - src[l4]);
- const int rightEnergy= 5*(src[l7] - src[l6]) + 2*(src[l5] - src[l8]);
-
- int d= ABS(middleEnergy) - MIN( ABS(leftEnergy), ABS(rightEnergy) );
- d= MAX(d, 0);
-
- d= (5*d + 32) >> 6;
- d*= SIGN(-middleEnergy);
-
- if(q>0)
- {
- d= d<0 ? 0 : d;
- d= d>q ? q : d;
- }
- else
- {
- d= d>0 ? 0 : d;
- d= d<q ? q : d;
- }
-
- src[l4]-= d;
- src[l5]+= d;
- }
- src++;
- }
-#endif
-}
-
-static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- asm volatile(
- "pxor %%mm6, %%mm6 \n\t"
- "pcmpeqb %%mm7, %%mm7 \n\t"
- "movq %2, %%mm0 \n\t"
- "punpcklbw %%mm6, %%mm0 \n\t"
- "psrlw $1, %%mm0 \n\t"
- "psubw %%mm7, %%mm0 \n\t"
- "packuswb %%mm0, %%mm0 \n\t"
- "movq %%mm0, %3 \n\t"
-
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
-
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
-#undef FIND_MIN_MAX
-#ifdef HAVE_MMX2
-#define FIND_MIN_MAX(addr)\
- "movq " #addr ", %%mm0 \n\t"\
- "pminub %%mm0, %%mm7 \n\t"\
- "pmaxub %%mm0, %%mm6 \n\t"
-#else
-#define FIND_MIN_MAX(addr)\
- "movq " #addr ", %%mm0 \n\t"\
- "movq %%mm7, %%mm1 \n\t"\
- "psubusb %%mm0, %%mm6 \n\t"\
- "paddb %%mm0, %%mm6 \n\t"\
- "psubusb %%mm0, %%mm1 \n\t"\
- "psubb %%mm1, %%mm7 \n\t"
-#endif
-
-FIND_MIN_MAX((%%eax))
-FIND_MIN_MAX((%%eax, %1))
-FIND_MIN_MAX((%%eax, %1, 2))
-FIND_MIN_MAX((%0, %1, 4))
-FIND_MIN_MAX((%%edx))
-FIND_MIN_MAX((%%edx, %1))
-FIND_MIN_MAX((%%edx, %1, 2))
-FIND_MIN_MAX((%0, %1, 8))
-
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $8, %%mm7 \n\t"
-#ifdef HAVE_MMX2
- "pminub %%mm4, %%mm7 \n\t" // min of pixels
- "pshufw $0xF9, %%mm7, %%mm4 \n\t"
- "pminub %%mm4, %%mm7 \n\t" // min of pixels
- "pshufw $0xFE, %%mm7, %%mm4 \n\t"
- "pminub %%mm4, %%mm7 \n\t"
-#else
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $16, %%mm7 \n\t"
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
- "movq %%mm7, %%mm4 \n\t"
- "psrlq $32, %%mm7 \n\t"
- "movq %%mm7, %%mm1 \n\t"
- "psubusb %%mm4, %%mm1 \n\t"
- "psubb %%mm1, %%mm7 \n\t"
-#endif
-
-
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $8, %%mm6 \n\t"
-#ifdef HAVE_MMX2
- "pmaxub %%mm4, %%mm6 \n\t" // max of pixels
- "pshufw $0xF9, %%mm6, %%mm4 \n\t"
- "pmaxub %%mm4, %%mm6 \n\t"
- "pshufw $0xFE, %%mm6, %%mm4 \n\t"
- "pmaxub %%mm4, %%mm6 \n\t"
-#else
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $16, %%mm6 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
- "movq %%mm6, %%mm4 \n\t"
- "psrlq $32, %%mm6 \n\t"
- "psubusb %%mm4, %%mm6 \n\t"
- "paddb %%mm4, %%mm6 \n\t"
-#endif
- "movq %%mm6, %%mm0 \n\t" // max
- "psubb %%mm7, %%mm6 \n\t" // max - min
- "movd %%mm6, %%ecx \n\t"
- "cmpb "MANGLE(deringThreshold)", %%cl \n\t"
- " jb 1f \n\t"
- "leal -24(%%esp), %%ecx \n\t"
- "andl $0xFFFFFFF8, %%ecx \n\t"
- PAVGB(%%mm0, %%mm7) // a=(max + min)/2
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm7, %%mm7 \n\t"
- "movq %%mm7, (%%ecx) \n\t"
-
- "movq (%0), %%mm0 \n\t" // L10
- "movq %%mm0, %%mm1 \n\t" // L10
- "movq %%mm0, %%mm2 \n\t" // L10
- "psllq $8, %%mm1 \n\t"
- "psrlq $8, %%mm2 \n\t"
- "movd -4(%0), %%mm3 \n\t"
- "movd 8(%0), %%mm4 \n\t"
- "psrlq $24, %%mm3 \n\t"
- "psllq $56, %%mm4 \n\t"
- "por %%mm3, %%mm1 \n\t" // L00
- "por %%mm4, %%mm2 \n\t" // L20
- "movq %%mm1, %%mm3 \n\t" // L00
- PAVGB(%%mm2, %%mm1) // (L20 + L00)/2
- PAVGB(%%mm0, %%mm1) // (L20 + L00 + 2L10)/4
- "psubusb %%mm7, %%mm0 \n\t"
- "psubusb %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm3 \n\t"
- "pcmpeqb "MANGLE(b00)", %%mm0 \n\t" // L10 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L20 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm3 \n\t" // L00 > a ? 0 : -1
- "paddb %%mm2, %%mm0 \n\t"
- "paddb %%mm3, %%mm0 \n\t"
-
- "movq (%%eax), %%mm2 \n\t" // L11
- "movq %%mm2, %%mm3 \n\t" // L11
- "movq %%mm2, %%mm4 \n\t" // L11
- "psllq $8, %%mm3 \n\t"
- "psrlq $8, %%mm4 \n\t"
- "movd -4(%%eax), %%mm5 \n\t"
- "movd 8(%%eax), %%mm6 \n\t"
- "psrlq $24, %%mm5 \n\t"
- "psllq $56, %%mm6 \n\t"
- "por %%mm5, %%mm3 \n\t" // L01
- "por %%mm6, %%mm4 \n\t" // L21
- "movq %%mm3, %%mm5 \n\t" // L01
- PAVGB(%%mm4, %%mm3) // (L21 + L01)/2
- PAVGB(%%mm2, %%mm3) // (L21 + L01 + 2L11)/4
- "psubusb %%mm7, %%mm2 \n\t"
- "psubusb %%mm7, %%mm4 \n\t"
- "psubusb %%mm7, %%mm5 \n\t"
- "pcmpeqb "MANGLE(b00)", %%mm2 \n\t" // L11 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm4 \n\t" // L21 > a ? 0 : -1
- "pcmpeqb "MANGLE(b00)", %%mm5 \n\t" // L01 > a ? 0 : -1
- "paddb %%mm4, %%mm2 \n\t"
- "paddb %%mm5, %%mm2 \n\t"
-// 0, 2, 3, 1
-#define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \
- "movq " #src ", " #sx " \n\t" /* src[0] */\
- "movq " #sx ", " #lx " \n\t" /* src[0] */\
- "movq " #sx ", " #t0 " \n\t" /* src[0] */\
- "psllq $8, " #lx " \n\t"\
- "psrlq $8, " #t0 " \n\t"\
- "movd -4" #src ", " #t1 " \n\t"\
- "psrlq $24, " #t1 " \n\t"\
- "por " #t1 ", " #lx " \n\t" /* src[-1] */\
- "movd 8" #src ", " #t1 " \n\t"\
- "psllq $56, " #t1 " \n\t"\
- "por " #t1 ", " #t0 " \n\t" /* src[+1] */\
- "movq " #lx ", " #t1 " \n\t" /* src[-1] */\
- PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\
- PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\
- PAVGB(lx, pplx) \
- "movq " #lx ", 8(%%ecx) \n\t"\
- "movq (%%ecx), " #lx " \n\t"\
- "psubusb " #lx ", " #t1 " \n\t"\
- "psubusb " #lx ", " #t0 " \n\t"\
- "psubusb " #lx ", " #sx " \n\t"\
- "movq "MANGLE(b00)", " #lx " \n\t"\
- "pcmpeqb " #lx ", " #t1 " \n\t" /* src[-1] > a ? 0 : -1*/\
- "pcmpeqb " #lx ", " #t0 " \n\t" /* src[+1] > a ? 0 : -1*/\
- "pcmpeqb " #lx ", " #sx " \n\t" /* src[0] > a ? 0 : -1*/\
- "paddb " #t1 ", " #t0 " \n\t"\
- "paddb " #t0 ", " #sx " \n\t"\
-\
- PAVGB(plx, pplx) /* filtered */\
- "movq " #dst ", " #t0 " \n\t" /* dst */\
- "movq " #t0 ", " #t1 " \n\t" /* dst */\
- "psubusb %3, " #t0 " \n\t"\
- "paddusb %3, " #t1 " \n\t"\
- PMAXUB(t0, pplx)\
- PMINUB(t1, pplx, t0)\
- "paddb " #sx ", " #ppsx " \n\t"\
- "paddb " #psx ", " #ppsx " \n\t"\
- "#paddb "MANGLE(b02)", " #ppsx " \n\t"\
- "pand "MANGLE(b08)", " #ppsx " \n\t"\
- "pcmpeqb " #lx ", " #ppsx " \n\t"\
- "pand " #ppsx ", " #pplx " \n\t"\
- "pandn " #dst ", " #ppsx " \n\t"\
- "por " #pplx ", " #ppsx " \n\t"\
- "movq " #ppsx ", " #dst " \n\t"\
- "movq 8(%%ecx), " #lx " \n\t"
-
-/*
-0000000
-1111111
-
-1111110
-1111101
-1111100
-1111011
-1111010
-1111001
-
-1111000
-1110111
-
-*/
-//DERING_CORE(dst,src ,ppsx ,psx ,sx ,pplx ,plx ,lx ,t0 ,t1)
-DERING_CORE((%%eax),(%%eax, %1) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%%eax, %1),(%%eax, %1, 2) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-DERING_CORE((%%eax, %1, 2),(%0, %1, 4) ,%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
-DERING_CORE((%0, %1, 4),(%%edx) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%%edx),(%%edx, %1) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-DERING_CORE((%%edx, %1), (%%edx, %1, 2),%%mm4,%%mm0,%%mm2,%%mm5,%%mm1,%%mm3,%%mm6,%%mm7)
-DERING_CORE((%%edx, %1, 2),(%0, %1, 8) ,%%mm0,%%mm2,%%mm4,%%mm1,%%mm3,%%mm5,%%mm6,%%mm7)
-DERING_CORE((%0, %1, 8),(%%edx, %1, 4) ,%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7)
-
- "1: \n\t"
- : : "r" (src), "r" (stride), "m" (c->pQPb), "m"(c->pQPb2)
- : "%eax", "%edx", "%ecx"
- );
-#else
- int y;
- int min=255;
- int max=0;
- int avg;
- uint8_t *p;
- int s[10];
- const int QP2= c->QP/2 + 1;
-
- for(y=1; y<9; y++)
- {
- int x;
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- if(*p > max) max= *p;
- if(*p < min) min= *p;
- }
- }
- avg= (min + max + 1)>>1;
-
- if(max - min <deringThreshold) return;
-
- for(y=0; y<10; y++)
- {
- int t = 0;
-
- if(src[stride*y + 0] > avg) t+= 1;
- if(src[stride*y + 1] > avg) t+= 2;
- if(src[stride*y + 2] > avg) t+= 4;
- if(src[stride*y + 3] > avg) t+= 8;
- if(src[stride*y + 4] > avg) t+= 16;
- if(src[stride*y + 5] > avg) t+= 32;
- if(src[stride*y + 6] > avg) t+= 64;
- if(src[stride*y + 7] > avg) t+= 128;
- if(src[stride*y + 8] > avg) t+= 256;
- if(src[stride*y + 9] > avg) t+= 512;
-
- t |= (~t)<<16;
- t &= (t<<1) & (t>>1);
- s[y] = t;
- }
-
- for(y=1; y<9; y++)
- {
- int t = s[y-1] & s[y] & s[y+1];
- t|= t>>16;
- s[y-1]= t;
- }
-
- for(y=1; y<9; y++)
- {
- int x;
- int t = s[y-1];
-
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- if(t & (1<<x))
- {
- int f= (*(p-stride-1)) + 2*(*(p-stride)) + (*(p-stride+1))
- +2*(*(p -1)) + 4*(*p ) + 2*(*(p +1))
- +(*(p+stride-1)) + 2*(*(p+stride)) + (*(p+stride+1));
- f= (f + 8)>>4;
-
-#ifdef DEBUG_DERING_THRESHOLD
- asm volatile("emms\n\t":);
- {
- static long long numPixels=0;
- if(x!=1 && x!=8 && y!=1 && y!=8) numPixels++;
-// if((max-min)<20 || (max-min)*QP<200)
-// if((max-min)*QP < 500)
-// if(max-min<QP/2)
- if(max-min < 20)
- {
- static int numSkiped=0;
- static int errorSum=0;
- static int worstQP=0;
- static int worstRange=0;
- static int worstDiff=0;
- int diff= (f - *p);
- int absDiff= ABS(diff);
- int error= diff*diff;
-
- if(x==1 || x==8 || y==1 || y==8) continue;
-
- numSkiped++;
- if(absDiff > worstDiff)
- {
- worstDiff= absDiff;
- worstQP= QP;
- worstRange= max-min;
- }
- errorSum+= error;
-
- if(1024LL*1024LL*1024LL % numSkiped == 0)
- {
- printf( "sum:%1.3f, skip:%d, wQP:%d, "
- "wRange:%d, wDiff:%d, relSkip:%1.3f\n",
- (float)errorSum/numSkiped, numSkiped, worstQP, worstRange,
- worstDiff, (float)numSkiped/numPixels);
- }
- }
- }
-#endif
- if (*p + QP2 < f) *p= *p + QP2;
- else if(*p - QP2 > f) *p= *p - QP2;
- else *p=f;
- }
- }
- }
-#ifdef DEBUG_DERING_THRESHOLD
- if(max-min < 20)
- {
- for(y=1; y<9; y++)
- {
- int x;
- int t = 0;
- p= src + stride*y;
- for(x=1; x<9; x++)
- {
- p++;
- *p = MIN(*p + 20, 255);
- }
- }
-// src[0] = src[7]=src[stride*7]=src[stride*7 + 7]=255;
- }
-#endif
-#endif
-}
-
-/**
- * Deinterlaces the given block by linearly interpolating every second line.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- */
-static inline void RENAME(deInterlaceInterpolateLinear)(uint8_t src[], int stride)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= 4*stride;
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%ecx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %0+8%1 ecx+4%1
-
- "movq (%0), %%mm0 \n\t"
- "movq (%%eax, %1), %%mm1 \n\t"
- PAVGB(%%mm1, %%mm0)
- "movq %%mm0, (%%eax) \n\t"
- "movq (%0, %1, 4), %%mm0 \n\t"
- PAVGB(%%mm0, %%mm1)
- "movq %%mm1, (%%eax, %1, 2) \n\t"
- "movq (%%ecx, %1), %%mm1 \n\t"
- PAVGB(%%mm1, %%mm0)
- "movq %%mm0, (%%ecx) \n\t"
- "movq (%0, %1, 8), %%mm0 \n\t"
- PAVGB(%%mm0, %%mm1)
- "movq %%mm1, (%%ecx, %1, 2) \n\t"
-
- : : "r" (src), "r" (stride)
- : "%eax", "%ecx"
- );
-#else
- int a, b, x;
- src+= 4*stride;
-
- for(x=0; x<2; x++){
- a= *(uint32_t*)&src[stride*0];
- b= *(uint32_t*)&src[stride*2];
- *(uint32_t*)&src[stride*1]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- a= *(uint32_t*)&src[stride*4];
- *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- b= *(uint32_t*)&src[stride*6];
- *(uint32_t*)&src[stride*5]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- a= *(uint32_t*)&src[stride*8];
- *(uint32_t*)&src[stride*7]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
- src += 4;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by cubic interpolating every second line.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 3-15 and write 7-13
- */
-static inline void RENAME(deInterlaceInterpolateCubic)(uint8_t src[], int stride)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*3;
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
- "leal (%%edx, %1, 4), %%ecx \n\t"
- "addl %1, %%ecx \n\t"
- "pxor %%mm7, %%mm7 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define DEINT_CUBIC(a,b,c,d,e)\
- "movq " #a ", %%mm0 \n\t"\
- "movq " #b ", %%mm1 \n\t"\
- "movq " #d ", %%mm2 \n\t"\
- "movq " #e ", %%mm3 \n\t"\
- PAVGB(%%mm2, %%mm1) /* (b+d) /2 */\
- PAVGB(%%mm3, %%mm0) /* a(a+e) /2 */\
- "movq %%mm0, %%mm2 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm2 \n\t"\
- "movq %%mm1, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "psubw %%mm1, %%mm0 \n\t" /* L(a+e - (b+d))/2 */\
- "psubw %%mm3, %%mm2 \n\t" /* H(a+e - (b+d))/2 */\
- "psraw $3, %%mm0 \n\t" /* L(a+e - (b+d))/16 */\
- "psraw $3, %%mm2 \n\t" /* H(a+e - (b+d))/16 */\
- "psubw %%mm0, %%mm1 \n\t" /* L(9b + 9d - a - e)/16 */\
- "psubw %%mm2, %%mm3 \n\t" /* H(9b + 9d - a - e)/16 */\
- "packuswb %%mm3, %%mm1 \n\t"\
- "movq %%mm1, " #c " \n\t"
-
-DEINT_CUBIC((%0), (%%eax, %1), (%%eax, %1, 2), (%0, %1, 4), (%%edx, %1))
-DEINT_CUBIC((%%eax, %1), (%0, %1, 4), (%%edx), (%%edx, %1), (%0, %1, 8))
-DEINT_CUBIC((%0, %1, 4), (%%edx, %1), (%%edx, %1, 2), (%0, %1, 8), (%%ecx))
-DEINT_CUBIC((%%edx, %1), (%0, %1, 8), (%%edx, %1, 4), (%%ecx), (%%ecx, %1, 2))
-
- : : "r" (src), "r" (stride)
- : "%eax", "%edx", "ecx"
- );
-#else
- int x;
- src+= stride*3;
- for(x=0; x<8; x++)
- {
- src[stride*3] = CLIP((-src[0] + 9*src[stride*2] + 9*src[stride*4] - src[stride*6])>>4);
- src[stride*5] = CLIP((-src[stride*2] + 9*src[stride*4] + 9*src[stride*6] - src[stride*8])>>4);
- src[stride*7] = CLIP((-src[stride*4] + 9*src[stride*6] + 9*src[stride*8] - src[stride*10])>>4);
- src[stride*9] = CLIP((-src[stride*6] + 9*src[stride*8] + 9*src[stride*10] - src[stride*12])>>4);
- src++;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by filtering every second line with a (-1 4 2 4 -1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 4-13 and write 5-11
- */
-static inline void RENAME(deInterlaceFF)(uint8_t src[], int stride, uint8_t *tmp)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*4;
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- "movq (%2), %%mm0 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define DEINT_FF(a,b,c,d)\
- "movq " #a ", %%mm1 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq " #c ", %%mm3 \n\t"\
- "movq " #d ", %%mm4 \n\t"\
- PAVGB(%%mm3, %%mm1) \
- PAVGB(%%mm4, %%mm0) \
- "movq %%mm0, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm0 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "movq %%mm1, %%mm4 \n\t"\
- "punpcklbw %%mm7, %%mm1 \n\t"\
- "punpckhbw %%mm7, %%mm4 \n\t"\
- "psllw $2, %%mm1 \n\t"\
- "psllw $2, %%mm4 \n\t"\
- "psubw %%mm0, %%mm1 \n\t"\
- "psubw %%mm3, %%mm4 \n\t"\
- "movq %%mm2, %%mm5 \n\t"\
- "movq %%mm2, %%mm0 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "paddw %%mm2, %%mm1 \n\t"\
- "paddw %%mm5, %%mm4 \n\t"\
- "psraw $2, %%mm1 \n\t"\
- "psraw $2, %%mm4 \n\t"\
- "packuswb %%mm4, %%mm1 \n\t"\
- "movq %%mm1, " #b " \n\t"\
-
-DEINT_FF((%0) , (%%eax) , (%%eax, %1), (%%eax, %1, 2))
-DEINT_FF((%%eax, %1), (%%eax, %1, 2), (%0, %1, 4), (%%edx) )
-DEINT_FF((%0, %1, 4), (%%edx) , (%%edx, %1), (%%edx, %1, 2))
-DEINT_FF((%%edx, %1), (%%edx, %1, 2), (%0, %1, 8), (%%edx, %1, 4))
-
- "movq %%mm0, (%2) \n\t"
- : : "r" (src), "r" (stride), "r"(tmp)
- : "%eax", "%edx"
- );
-#else
- int x;
- src+= stride*4;
- for(x=0; x<8; x++)
- {
- int t1= tmp[x];
- int t2= src[stride*1];
-
- src[stride*1]= CLIP((-t1 + 4*src[stride*0] + 2*t2 + 4*src[stride*2] - src[stride*3] + 4)>>3);
- t1= src[stride*4];
- src[stride*3]= CLIP((-t2 + 4*src[stride*2] + 2*t1 + 4*src[stride*4] - src[stride*5] + 4)>>3);
- t2= src[stride*6];
- src[stride*5]= CLIP((-t1 + 4*src[stride*4] + 2*t2 + 4*src[stride*6] - src[stride*7] + 4)>>3);
- t1= src[stride*8];
- src[stride*7]= CLIP((-t2 + 4*src[stride*6] + 2*t1 + 4*src[stride*8] - src[stride*9] + 4)>>3);
- tmp[x]= t1;
-
- src++;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by filtering every line with a (-1 2 6 2 -1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * this filter will read lines 4-13 and write 4-11
- */
-static inline void RENAME(deInterlaceL5)(uint8_t src[], int stride, uint8_t *tmp, uint8_t *tmp2)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= stride*4;
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- "movq (%2), %%mm0 \n\t"
- "movq (%3), %%mm1 \n\t"
-// 0 1 2 3 4 5 6 7 8 9 10
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1 ecx
-
-#define DEINT_L5(t1,t2,a,b,c)\
- "movq " #a ", %%mm2 \n\t"\
- "movq " #b ", %%mm3 \n\t"\
- "movq " #c ", %%mm4 \n\t"\
- PAVGB(t2, %%mm3) \
- PAVGB(t1, %%mm4) \
- "movq %%mm2, %%mm5 \n\t"\
- "movq %%mm2, " #t1 " \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm5 \n\t"\
- "movq %%mm2, %%mm6 \n\t"\
- "paddw %%mm2, %%mm2 \n\t"\
- "paddw %%mm6, %%mm2 \n\t"\
- "movq %%mm5, %%mm6 \n\t"\
- "paddw %%mm5, %%mm5 \n\t"\
- "paddw %%mm6, %%mm5 \n\t"\
- "movq %%mm3, %%mm6 \n\t"\
- "punpcklbw %%mm7, %%mm3 \n\t"\
- "punpckhbw %%mm7, %%mm6 \n\t"\
- "paddw %%mm3, %%mm3 \n\t"\
- "paddw %%mm6, %%mm6 \n\t"\
- "paddw %%mm3, %%mm2 \n\t"\
- "paddw %%mm6, %%mm5 \n\t"\
- "movq %%mm4, %%mm6 \n\t"\
- "punpcklbw %%mm7, %%mm4 \n\t"\
- "punpckhbw %%mm7, %%mm6 \n\t"\
- "psubw %%mm4, %%mm2 \n\t"\
- "psubw %%mm6, %%mm5 \n\t"\
- "psraw $2, %%mm2 \n\t"\
- "psraw $2, %%mm5 \n\t"\
- "packuswb %%mm5, %%mm2 \n\t"\
- "movq %%mm2, " #a " \n\t"\
-
-DEINT_L5(%%mm0, %%mm1, (%0) , (%%eax) , (%%eax, %1) )
-DEINT_L5(%%mm1, %%mm0, (%%eax) , (%%eax, %1) , (%%eax, %1, 2))
-DEINT_L5(%%mm0, %%mm1, (%%eax, %1) , (%%eax, %1, 2), (%0, %1, 4) )
-DEINT_L5(%%mm1, %%mm0, (%%eax, %1, 2), (%0, %1, 4) , (%%edx) )
-DEINT_L5(%%mm0, %%mm1, (%0, %1, 4) , (%%edx) , (%%edx, %1) )
-DEINT_L5(%%mm1, %%mm0, (%%edx) , (%%edx, %1) , (%%edx, %1, 2))
-DEINT_L5(%%mm0, %%mm1, (%%edx, %1) , (%%edx, %1, 2), (%0, %1, 8) )
-DEINT_L5(%%mm1, %%mm0, (%%edx, %1, 2), (%0, %1, 8) , (%%edx, %1, 4))
-
- "movq %%mm0, (%2) \n\t"
- "movq %%mm1, (%3) \n\t"
- : : "r" (src), "r" (stride), "r"(tmp), "r"(tmp2)
- : "%eax", "%edx"
- );
-#else
- int x;
- src+= stride*4;
- for(x=0; x<8; x++)
- {
- int t1= tmp[x];
- int t2= tmp2[x];
- int t3= src[0];
-
- src[stride*0]= CLIP((-(t1 + src[stride*2]) + 2*(t2 + src[stride*1]) + 6*t3 + 4)>>3);
- t1= src[stride*1];
- src[stride*1]= CLIP((-(t2 + src[stride*3]) + 2*(t3 + src[stride*2]) + 6*t1 + 4)>>3);
- t2= src[stride*2];
- src[stride*2]= CLIP((-(t3 + src[stride*4]) + 2*(t1 + src[stride*3]) + 6*t2 + 4)>>3);
- t3= src[stride*3];
- src[stride*3]= CLIP((-(t1 + src[stride*5]) + 2*(t2 + src[stride*4]) + 6*t3 + 4)>>3);
- t1= src[stride*4];
- src[stride*4]= CLIP((-(t2 + src[stride*6]) + 2*(t3 + src[stride*5]) + 6*t1 + 4)>>3);
- t2= src[stride*5];
- src[stride*5]= CLIP((-(t3 + src[stride*7]) + 2*(t1 + src[stride*6]) + 6*t2 + 4)>>3);
- t3= src[stride*6];
- src[stride*6]= CLIP((-(t1 + src[stride*8]) + 2*(t2 + src[stride*7]) + 6*t3 + 4)>>3);
- t1= src[stride*7];
- src[stride*7]= CLIP((-(t2 + src[stride*9]) + 2*(t3 + src[stride*8]) + 6*t1 + 4)>>3);
-
- tmp[x]= t3;
- tmp2[x]= t1;
-
- src++;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by filtering all lines with a (1 2 1) filter.
- * will be called for every 8x8 block and can read & write from line 4-15
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- * will shift the image up by 1 line (FIXME if this is a problem)
- * this filter will read lines 4-13 and write 4-11
- */
-static inline void RENAME(deInterlaceBlendLinear)(uint8_t src[], int stride)
-{
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- src+= 4*stride;
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%%eax, %1), %%mm1 \n\t" // L2
- PAVGB(%%mm1, %%mm0) // L0+L2
- "movq (%%eax), %%mm2 \n\t" // L1
- PAVGB(%%mm2, %%mm0)
- "movq %%mm0, (%0) \n\t"
- "movq (%%eax, %1, 2), %%mm0 \n\t" // L3
- PAVGB(%%mm0, %%mm2) // L1+L3
- PAVGB(%%mm1, %%mm2) // 2L2 + L1 + L3
- "movq %%mm2, (%%eax) \n\t"
- "movq (%0, %1, 4), %%mm2 \n\t" // L4
- PAVGB(%%mm2, %%mm1) // L2+L4
- PAVGB(%%mm0, %%mm1) // 2L3 + L2 + L4
- "movq %%mm1, (%%eax, %1) \n\t"
- "movq (%%edx), %%mm1 \n\t" // L5
- PAVGB(%%mm1, %%mm0) // L3+L5
- PAVGB(%%mm2, %%mm0) // 2L4 + L3 + L5
- "movq %%mm0, (%%eax, %1, 2) \n\t"
- "movq (%%edx, %1), %%mm0 \n\t" // L6
- PAVGB(%%mm0, %%mm2) // L4+L6
- PAVGB(%%mm1, %%mm2) // 2L5 + L4 + L6
- "movq %%mm2, (%0, %1, 4) \n\t"
- "movq (%%edx, %1, 2), %%mm2 \n\t" // L7
- PAVGB(%%mm2, %%mm1) // L5+L7
- PAVGB(%%mm0, %%mm1) // 2L6 + L5 + L7
- "movq %%mm1, (%%edx) \n\t"
- "movq (%0, %1, 8), %%mm1 \n\t" // L8
- PAVGB(%%mm1, %%mm0) // L6+L8
- PAVGB(%%mm2, %%mm0) // 2L7 + L6 + L8
- "movq %%mm0, (%%edx, %1) \n\t"
- "movq (%%edx, %1, 4), %%mm0 \n\t" // L9
- PAVGB(%%mm0, %%mm2) // L7+L9
- PAVGB(%%mm1, %%mm2) // 2L8 + L7 + L9
- "movq %%mm2, (%%edx, %1, 2) \n\t"
-
-
- : : "r" (src), "r" (stride)
- : "%eax", "%edx"
- );
-#else
- int a, b, c, x;
- src+= 4*stride;
-
- for(x=0; x<2; x++){
- a= *(uint32_t*)&src[stride*0];
- b= *(uint32_t*)&src[stride*1];
- c= *(uint32_t*)&src[stride*2];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*0]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*3];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*1]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- b= *(uint32_t*)&src[stride*4];
- c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*2]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
-
- c= *(uint32_t*)&src[stride*5];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*3]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*6];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*4]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- b= *(uint32_t*)&src[stride*7];
- c= (b&c) + (((b^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*5]= (c|a) - (((c^a)&0xFEFEFEFEUL)>>1);
-
- c= *(uint32_t*)&src[stride*8];
- a= (a&c) + (((a^c)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*6]= (a|b) - (((a^b)&0xFEFEFEFEUL)>>1);
-
- a= *(uint32_t*)&src[stride*9];
- b= (a&b) + (((a^b)&0xFEFEFEFEUL)>>1);
- *(uint32_t*)&src[stride*7]= (c|b) - (((c^b)&0xFEFEFEFEUL)>>1);
-
- src += 4;
- }
-#endif
-}
-
-/**
- * Deinterlaces the given block by applying a median filter to every second line.
- * will be called for every 8x8 block and can read & write from line 4-15,
- * lines 0-3 have been passed through the deblock / dering filters allready, but can be read too
- * lines 4-12 will be read into the deblocking filter and should be deinterlaced
- */
-static inline void RENAME(deInterlaceMedian)(uint8_t src[], int stride)
-{
-#ifdef HAVE_MMX
- src+= 4*stride;
-#ifdef HAVE_MMX2
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
-
- "movq (%0), %%mm0 \n\t" //
- "movq (%%eax, %1), %%mm2 \n\t" //
- "movq (%%eax), %%mm1 \n\t" //
- "movq %%mm0, %%mm3 \n\t"
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm3, %%mm1 \n\t" //
- "pmaxub %%mm2, %%mm1 \n\t" //
- "pminub %%mm1, %%mm0 \n\t"
- "movq %%mm0, (%%eax) \n\t"
-
- "movq (%0, %1, 4), %%mm0 \n\t" //
- "movq (%%eax, %1, 2), %%mm1 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm1, %%mm2 \n\t" //
- "pminub %%mm3, %%mm1 \n\t" //
- "pmaxub %%mm0, %%mm1 \n\t" //
- "pminub %%mm1, %%mm2 \n\t"
- "movq %%mm2, (%%eax, %1, 2) \n\t"
-
- "movq (%%edx), %%mm2 \n\t" //
- "movq (%%edx, %1), %%mm1 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm0, %%mm2 \n\t" //
- "pminub %%mm3, %%mm0 \n\t" //
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm0, %%mm2 \n\t"
- "movq %%mm2, (%%edx) \n\t"
-
- "movq (%%edx, %1, 2), %%mm2 \n\t" //
- "movq (%0, %1, 8), %%mm0 \n\t" //
- "movq %%mm2, %%mm3 \n\t"
- "pmaxub %%mm0, %%mm2 \n\t" //
- "pminub %%mm3, %%mm0 \n\t" //
- "pmaxub %%mm1, %%mm0 \n\t" //
- "pminub %%mm0, %%mm2 \n\t"
- "movq %%mm2, (%%edx, %1, 2) \n\t"
-
-
- : : "r" (src), "r" (stride)
- : "%eax", "%edx"
- );
-
-#else // MMX without MMX2
- asm volatile(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "pxor %%mm7, %%mm7 \n\t"
-
-#define MEDIAN(a,b,c)\
- "movq " #a ", %%mm0 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq " #c ", %%mm1 \n\t"\
- "movq %%mm0, %%mm3 \n\t"\
- "movq %%mm1, %%mm4 \n\t"\
- "movq %%mm2, %%mm5 \n\t"\
- "psubusb %%mm1, %%mm3 \n\t"\
- "psubusb %%mm2, %%mm4 \n\t"\
- "psubusb %%mm0, %%mm5 \n\t"\
- "pcmpeqb %%mm7, %%mm3 \n\t"\
- "pcmpeqb %%mm7, %%mm4 \n\t"\
- "pcmpeqb %%mm7, %%mm5 \n\t"\
- "movq %%mm3, %%mm6 \n\t"\
- "pxor %%mm4, %%mm3 \n\t"\
- "pxor %%mm5, %%mm4 \n\t"\
- "pxor %%mm6, %%mm5 \n\t"\
- "por %%mm3, %%mm1 \n\t"\
- "por %%mm4, %%mm2 \n\t"\
- "por %%mm5, %%mm0 \n\t"\
- "pand %%mm2, %%mm0 \n\t"\
- "pand %%mm1, %%mm0 \n\t"\
- "movq %%mm0, " #b " \n\t"
-
-MEDIAN((%0), (%%eax), (%%eax, %1))
-MEDIAN((%%eax, %1), (%%eax, %1, 2), (%0, %1, 4))
-MEDIAN((%0, %1, 4), (%%edx), (%%edx, %1))
-MEDIAN((%%edx, %1), (%%edx, %1, 2), (%0, %1, 8))
-
- : : "r" (src), "r" (stride)
- : "%eax", "%edx"
- );
-#endif // MMX
-#else
- int x, y;
- src+= 4*stride;
- // FIXME - there should be a way to do a few columns in parallel like w/mmx
- for(x=0; x<8; x++)
- {
- uint8_t *colsrc = src;
- for (y=0; y<4; y++)
- {
- int a, b, c, d, e, f;
- a = colsrc[0 ];
- b = colsrc[stride ];
- c = colsrc[stride*2];
- d = (a-b)>>31;
- e = (b-c)>>31;
- f = (c-a)>>31;
- colsrc[stride ] = (a|(d^f)) & (b|(d^e)) & (c|(e^f));
- colsrc += stride*2;
- }
- src++;
- }
-#endif
-}
-
-#ifdef HAVE_MMX
-/**
- * transposes and shift the given 8x8 Block into dst1 and dst2
- */
-static inline void RENAME(transpose1)(uint8_t *dst1, uint8_t *dst2, uint8_t *src, int srcStride)
-{
- asm(
- "leal (%0, %1), %%eax \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "movq (%0), %%mm0 \n\t" // 12345678
- "movq (%%eax), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq (%%eax, %1), %%mm1 \n\t"
- "movq (%%eax, %1, 2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 128(%2) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 144(%2) \n\t"
- "movd %%mm3, 160(%2) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 176(%2) \n\t"
- "movd %%mm3, 48(%3) \n\t"
- "movd %%mm2, 192(%2) \n\t"
- "movd %%mm2, 64(%3) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 80(%3) \n\t"
- "movd %%mm1, 96(%3) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 112(%3) \n\t"
-
- "leal (%%eax, %1, 4), %%eax \n\t"
-
- "movq (%0, %1, 4), %%mm0 \n\t" // 12345678
- "movq (%%eax), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq (%%eax, %1), %%mm1 \n\t"
- "movq (%%eax, %1, 2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 132(%2) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 148(%2) \n\t"
- "movd %%mm3, 164(%2) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 180(%2) \n\t"
- "movd %%mm3, 52(%3) \n\t"
- "movd %%mm2, 196(%2) \n\t"
- "movd %%mm2, 68(%3) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 84(%3) \n\t"
- "movd %%mm1, 100(%3) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 116(%3) \n\t"
-
-
- :: "r" (src), "r" (srcStride), "r" (dst1), "r" (dst2)
- : "%eax"
- );
-}
-
-/**
- * transposes the given 8x8 block
- */
-static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, uint8_t *src)
-{
- asm(
- "leal (%0, %1), %%eax \n\t"
- "leal (%%eax, %1, 4), %%edx \n\t"
-// 0 1 2 3 4 5 6 7 8 9
-// %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 %0+8%1 edx+4%1
- "movq (%2), %%mm0 \n\t" // 12345678
- "movq 16(%2), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq 32(%2), %%mm1 \n\t"
- "movq 48(%2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, (%0) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, (%%eax) \n\t"
- "movd %%mm3, (%%eax, %1) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, (%%eax, %1, 2) \n\t"
- "movd %%mm2, (%0, %1, 4) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, (%%edx) \n\t"
- "movd %%mm1, (%%edx, %1) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, (%%edx, %1, 2) \n\t"
-
-
- "movq 64(%2), %%mm0 \n\t" // 12345678
- "movq 80(%2), %%mm1 \n\t" // abcdefgh
- "movq %%mm0, %%mm2 \n\t" // 12345678
- "punpcklbw %%mm1, %%mm0 \n\t" // 1a2b3c4d
- "punpckhbw %%mm1, %%mm2 \n\t" // 5e6f7g8h
-
- "movq 96(%2), %%mm1 \n\t"
- "movq 112(%2), %%mm3 \n\t"
- "movq %%mm1, %%mm4 \n\t"
- "punpcklbw %%mm3, %%mm1 \n\t"
- "punpckhbw %%mm3, %%mm4 \n\t"
-
- "movq %%mm0, %%mm3 \n\t"
- "punpcklwd %%mm1, %%mm0 \n\t"
- "punpckhwd %%mm1, %%mm3 \n\t"
- "movq %%mm2, %%mm1 \n\t"
- "punpcklwd %%mm4, %%mm2 \n\t"
- "punpckhwd %%mm4, %%mm1 \n\t"
-
- "movd %%mm0, 4(%0) \n\t"
- "psrlq $32, %%mm0 \n\t"
- "movd %%mm0, 4(%%eax) \n\t"
- "movd %%mm3, 4(%%eax, %1) \n\t"
- "psrlq $32, %%mm3 \n\t"
- "movd %%mm3, 4(%%eax, %1, 2) \n\t"
- "movd %%mm2, 4(%0, %1, 4) \n\t"
- "psrlq $32, %%mm2 \n\t"
- "movd %%mm2, 4(%%edx) \n\t"
- "movd %%mm1, 4(%%edx, %1) \n\t"
- "psrlq $32, %%mm1 \n\t"
- "movd %%mm1, 4(%%edx, %1, 2) \n\t"
-
- :: "r" (dst), "r" (dstStride), "r" (src)
- : "%eax", "%edx"
- );
-}
-#endif
-//static int test=0;
-
-static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride,
- uint8_t *tempBlured, uint32_t *tempBluredPast, int *maxNoise)
-{
- // to save a register (FIXME do this outside of the loops)
- tempBluredPast[127]= maxNoise[0];
- tempBluredPast[128]= maxNoise[1];
- tempBluredPast[129]= maxNoise[2];
-
-#define FAST_L2_DIFF
-//#define L1_DIFF //u should change the thresholds too if u try that one
-#if defined (HAVE_MMX2) || defined (HAVE_3DNOW)
- asm volatile(
- "leal (%2, %2, 2), %%eax \n\t" // 3*stride
- "leal (%2, %2, 4), %%edx \n\t" // 5*stride
- "leal (%%edx, %2, 2), %%ecx \n\t" // 7*stride
-// 0 1 2 3 4 5 6 7 8 9
-// %x %x+%2 %x+2%2 %x+eax %x+4%2 %x+edx %x+2eax %x+ecx %x+8%2
-//FIXME reorder?
-#ifdef L1_DIFF //needs mmx2
- "movq (%0), %%mm0 \n\t" // L0
- "psadbw (%1), %%mm0 \n\t" // |L0-R0|
- "movq (%0, %2), %%mm1 \n\t" // L1
- "psadbw (%1, %2), %%mm1 \n\t" // |L1-R1|
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "psadbw (%1, %2, 2), %%mm2 \n\t" // |L2-R2|
- "movq (%0, %%eax), %%mm3 \n\t" // L3
- "psadbw (%1, %%eax), %%mm3 \n\t" // |L3-R3|
-
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- "paddw %%mm1, %%mm0 \n\t"
- "psadbw (%1, %2, 4), %%mm4 \n\t" // |L4-R4|
- "movq (%0, %%edx), %%mm5 \n\t" // L5
- "paddw %%mm2, %%mm0 \n\t"
- "psadbw (%1, %%edx), %%mm5 \n\t" // |L5-R5|
- "movq (%0, %%eax, 2), %%mm6 \n\t" // L6
- "paddw %%mm3, %%mm0 \n\t"
- "psadbw (%1, %%eax, 2), %%mm6 \n\t" // |L6-R6|
- "movq (%0, %%ecx), %%mm7 \n\t" // L7
- "paddw %%mm4, %%mm0 \n\t"
- "psadbw (%1, %%ecx), %%mm7 \n\t" // |L7-R7|
- "paddw %%mm5, %%mm6 \n\t"
- "paddw %%mm7, %%mm6 \n\t"
- "paddw %%mm6, %%mm0 \n\t"
-#elif defined (FAST_L2_DIFF)
- "pcmpeqb %%mm7, %%mm7 \n\t"
- "movq "MANGLE(b80)", %%mm6 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
-#define L2_DIFF_CORE(a, b)\
- "movq " #a ", %%mm5 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "pxor %%mm7, %%mm2 \n\t"\
- PAVGB(%%mm2, %%mm5)\
- "paddb %%mm6, %%mm5 \n\t"\
- "movq %%mm5, %%mm2 \n\t"\
- "psllw $8, %%mm5 \n\t"\
- "pmaddwd %%mm5, %%mm5 \n\t"\
- "pmaddwd %%mm2, %%mm2 \n\t"\
- "paddd %%mm2, %%mm5 \n\t"\
- "psrld $14, %%mm5 \n\t"\
- "paddd %%mm5, %%mm0 \n\t"
-
-L2_DIFF_CORE((%0), (%1))
-L2_DIFF_CORE((%0, %2), (%1, %2))
-L2_DIFF_CORE((%0, %2, 2), (%1, %2, 2))
-L2_DIFF_CORE((%0, %%eax), (%1, %%eax))
-L2_DIFF_CORE((%0, %2, 4), (%1, %2, 4))
-L2_DIFF_CORE((%0, %%edx), (%1, %%edx))
-L2_DIFF_CORE((%0, %%eax,2), (%1, %%eax,2))
-L2_DIFF_CORE((%0, %%ecx), (%1, %%ecx))
-
-#else
- "pxor %%mm7, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
-#define L2_DIFF_CORE(a, b)\
- "movq " #a ", %%mm5 \n\t"\
- "movq " #b ", %%mm2 \n\t"\
- "movq %%mm5, %%mm1 \n\t"\
- "movq %%mm2, %%mm3 \n\t"\
- "punpcklbw %%mm7, %%mm5 \n\t"\
- "punpckhbw %%mm7, %%mm1 \n\t"\
- "punpcklbw %%mm7, %%mm2 \n\t"\
- "punpckhbw %%mm7, %%mm3 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "psubw %%mm3, %%mm1 \n\t"\
- "pmaddwd %%mm5, %%mm5 \n\t"\
- "pmaddwd %%mm1, %%mm1 \n\t"\
- "paddd %%mm1, %%mm5 \n\t"\
- "paddd %%mm5, %%mm0 \n\t"
-
-L2_DIFF_CORE((%0), (%1))
-L2_DIFF_CORE((%0, %2), (%1, %2))
-L2_DIFF_CORE((%0, %2, 2), (%1, %2, 2))
-L2_DIFF_CORE((%0, %%eax), (%1, %%eax))
-L2_DIFF_CORE((%0, %2, 4), (%1, %2, 4))
-L2_DIFF_CORE((%0, %%edx), (%1, %%edx))
-L2_DIFF_CORE((%0, %%eax,2), (%1, %%eax,2))
-L2_DIFF_CORE((%0, %%ecx), (%1, %%ecx))
-
-#endif
-
- "movq %%mm0, %%mm4 \n\t"
- "psrlq $32, %%mm0 \n\t"
- "paddd %%mm0, %%mm4 \n\t"
- "movd %%mm4, %%ecx \n\t"
- "shll $2, %%ecx \n\t"
- "movl %3, %%edx \n\t"
- "addl -4(%%edx), %%ecx \n\t"
- "addl 4(%%edx), %%ecx \n\t"
- "addl -1024(%%edx), %%ecx \n\t"
- "addl $4, %%ecx \n\t"
- "addl 1024(%%edx), %%ecx \n\t"
- "shrl $3, %%ecx \n\t"
- "movl %%ecx, (%%edx) \n\t"
-
-// "movl %3, %%ecx \n\t"
-// "movl %%ecx, test \n\t"
-// "jmp 4f \n\t"
- "cmpl 512(%%edx), %%ecx \n\t"
- " jb 2f \n\t"
- "cmpl 516(%%edx), %%ecx \n\t"
- " jb 1f \n\t"
-
- "leal (%%eax, %2, 2), %%edx \n\t" // 5*stride
- "leal (%%edx, %2, 2), %%ecx \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%eax), %%mm3 \n\t" // L3
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- "movq (%0, %%edx), %%mm5 \n\t" // L5
- "movq (%0, %%eax, 2), %%mm6 \n\t" // L6
- "movq (%0, %%ecx), %%mm7 \n\t" // L7
- "movq %%mm0, (%1) \n\t" // L0
- "movq %%mm1, (%1, %2) \n\t" // L1
- "movq %%mm2, (%1, %2, 2) \n\t" // L2
- "movq %%mm3, (%1, %%eax) \n\t" // L3
- "movq %%mm4, (%1, %2, 4) \n\t" // L4
- "movq %%mm5, (%1, %%edx) \n\t" // L5
- "movq %%mm6, (%1, %%eax, 2) \n\t" // L6
- "movq %%mm7, (%1, %%ecx) \n\t" // L7
- "jmp 4f \n\t"
-
- "1: \n\t"
- "leal (%%eax, %2, 2), %%edx \n\t" // 5*stride
- "leal (%%edx, %2, 2), %%ecx \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- PAVGB((%1), %%mm0) // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- PAVGB((%1, %2), %%mm1) // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- PAVGB((%1, %2, 2), %%mm2) // L2
- "movq (%0, %%eax), %%mm3 \n\t" // L3
- PAVGB((%1, %%eax), %%mm3) // L3
- "movq (%0, %2, 4), %%mm4 \n\t" // L4
- PAVGB((%1, %2, 4), %%mm4) // L4
- "movq (%0, %%edx), %%mm5 \n\t" // L5
- PAVGB((%1, %%edx), %%mm5) // L5
- "movq (%0, %%eax, 2), %%mm6 \n\t" // L6
- PAVGB((%1, %%eax, 2), %%mm6) // L6
- "movq (%0, %%ecx), %%mm7 \n\t" // L7
- PAVGB((%1, %%ecx), %%mm7) // L7
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%eax) \n\t" // R3
- "movq %%mm4, (%1, %2, 4) \n\t" // R4
- "movq %%mm5, (%1, %%edx) \n\t" // R5
- "movq %%mm6, (%1, %%eax, 2) \n\t" // R6
- "movq %%mm7, (%1, %%ecx) \n\t" // R7
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%eax) \n\t" // L3
- "movq %%mm4, (%0, %2, 4) \n\t" // L4
- "movq %%mm5, (%0, %%edx) \n\t" // L5
- "movq %%mm6, (%0, %%eax, 2) \n\t" // L6
- "movq %%mm7, (%0, %%ecx) \n\t" // L7
- "jmp 4f \n\t"
-
- "2: \n\t"
- "cmpl 508(%%edx), %%ecx \n\t"
- " jb 3f \n\t"
-
- "leal (%%eax, %2, 2), %%edx \n\t" // 5*stride
- "leal (%%edx, %2, 2), %%ecx \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%eax), %%mm3 \n\t" // L3
- "movq (%1), %%mm4 \n\t" // R0
- "movq (%1, %2), %%mm5 \n\t" // R1
- "movq (%1, %2, 2), %%mm6 \n\t" // R2
- "movq (%1, %%eax), %%mm7 \n\t" // R3
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%eax) \n\t" // R3
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%eax) \n\t" // L3
-
- "movq (%0, %2, 4), %%mm0 \n\t" // L4
- "movq (%0, %%edx), %%mm1 \n\t" // L5
- "movq (%0, %%eax, 2), %%mm2 \n\t" // L6
- "movq (%0, %%ecx), %%mm3 \n\t" // L7
- "movq (%1, %2, 4), %%mm4 \n\t" // R4
- "movq (%1, %%edx), %%mm5 \n\t" // R5
- "movq (%1, %%eax, 2), %%mm6 \n\t" // R6
- "movq (%1, %%ecx), %%mm7 \n\t" // R7
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1, %2, 4) \n\t" // R4
- "movq %%mm1, (%1, %%edx) \n\t" // R5
- "movq %%mm2, (%1, %%eax, 2) \n\t" // R6
- "movq %%mm3, (%1, %%ecx) \n\t" // R7
- "movq %%mm0, (%0, %2, 4) \n\t" // L4
- "movq %%mm1, (%0, %%edx) \n\t" // L5
- "movq %%mm2, (%0, %%eax, 2) \n\t" // L6
- "movq %%mm3, (%0, %%ecx) \n\t" // L7
- "jmp 4f \n\t"
-
- "3: \n\t"
- "leal (%%eax, %2, 2), %%edx \n\t" // 5*stride
- "leal (%%edx, %2, 2), %%ecx \n\t" // 7*stride
- "movq (%0), %%mm0 \n\t" // L0
- "movq (%0, %2), %%mm1 \n\t" // L1
- "movq (%0, %2, 2), %%mm2 \n\t" // L2
- "movq (%0, %%eax), %%mm3 \n\t" // L3
- "movq (%1), %%mm4 \n\t" // R0
- "movq (%1, %2), %%mm5 \n\t" // R1
- "movq (%1, %2, 2), %%mm6 \n\t" // R2
- "movq (%1, %%eax), %%mm7 \n\t" // R3
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1) \n\t" // R0
- "movq %%mm1, (%1, %2) \n\t" // R1
- "movq %%mm2, (%1, %2, 2) \n\t" // R2
- "movq %%mm3, (%1, %%eax) \n\t" // R3
- "movq %%mm0, (%0) \n\t" // L0
- "movq %%mm1, (%0, %2) \n\t" // L1
- "movq %%mm2, (%0, %2, 2) \n\t" // L2
- "movq %%mm3, (%0, %%eax) \n\t" // L3
-
- "movq (%0, %2, 4), %%mm0 \n\t" // L4
- "movq (%0, %%edx), %%mm1 \n\t" // L5
- "movq (%0, %%eax, 2), %%mm2 \n\t" // L6
- "movq (%0, %%ecx), %%mm3 \n\t" // L7
- "movq (%1, %2, 4), %%mm4 \n\t" // R4
- "movq (%1, %%edx), %%mm5 \n\t" // R5
- "movq (%1, %%eax, 2), %%mm6 \n\t" // R6
- "movq (%1, %%ecx), %%mm7 \n\t" // R7
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- PAVGB(%%mm4, %%mm0)
- PAVGB(%%mm5, %%mm1)
- PAVGB(%%mm6, %%mm2)
- PAVGB(%%mm7, %%mm3)
- "movq %%mm0, (%1, %2, 4) \n\t" // R4
- "movq %%mm1, (%1, %%edx) \n\t" // R5
- "movq %%mm2, (%1, %%eax, 2) \n\t" // R6
- "movq %%mm3, (%1, %%ecx) \n\t" // R7
- "movq %%mm0, (%0, %2, 4) \n\t" // L4
- "movq %%mm1, (%0, %%edx) \n\t" // L5
- "movq %%mm2, (%0, %%eax, 2) \n\t" // L6
- "movq %%mm3, (%0, %%ecx) \n\t" // L7
-
- "4: \n\t"
-
- :: "r" (src), "r" (tempBlured), "r"(stride), "m" (tempBluredPast)
- : "%eax", "%edx", "%ecx", "memory"
- );
-//printf("%d\n", test);
-#else
-{
- int y;
- int d=0;
- int sysd=0;
- int i;
-
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- int d1=ref - cur;
-// if(x==0 || x==7) d1+= d1>>1;
-// if(y==0 || y==7) d1+= d1>>1;
-// d+= ABS(d1);
- d+= d1*d1;
- sysd+= d1;
- }
- }
- i=d;
- d= (
- 4*d
- +(*(tempBluredPast-256))
- +(*(tempBluredPast-1))+ (*(tempBluredPast+1))
- +(*(tempBluredPast+256))
- +4)>>3;
- *tempBluredPast=i;
-// ((*tempBluredPast)*3 + d + 2)>>2;
-
-//printf("%d %d %d\n", maxNoise[0], maxNoise[1], maxNoise[2]);
-/*
-Switch between
- 1 0 0 0 0 0 0 (0)
-64 32 16 8 4 2 1 (1)
-64 48 36 27 20 15 11 (33) (approx)
-64 56 49 43 37 33 29 (200) (approx)
-*/
- if(d > maxNoise[1])
- {
- if(d < maxNoise[2])
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref + cur + 1)>>1;
- }
- }
- }
- else
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- tempBlured[ x + y*stride ]= src[ x + y*stride ];
- }
- }
- }
- }
- else
- {
- if(d < maxNoise[0])
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref*7 + cur + 4)>>3;
- }
- }
- }
- else
- {
- for(y=0; y<8; y++)
- {
- int x;
- for(x=0; x<8; x++)
- {
- int ref= tempBlured[ x + y*stride ];
- int cur= src[ x + y*stride ];
- tempBlured[ x + y*stride ]=
- src[ x + y*stride ]=
- (ref*3 + cur + 2)>>2;
- }
- }
- }
- }
-}
-#endif
-}
-
-static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c);
-
-/**
- * Copies a block from src to dst and fixes the blacklevel
- * levelFix == 0 -> dont touch the brighness & contrast
- */
-#undef SCALED_CPY
-
-static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, uint8_t src[], int srcStride,
- int levelFix, int64_t *packedOffsetAndScale)
-{
-#ifndef HAVE_MMX
- int i;
-#endif
- if(levelFix)
- {
-#ifdef HAVE_MMX
- asm volatile(
- "movq (%%eax), %%mm2 \n\t" // packedYOffset
- "movq 8(%%eax), %%mm3 \n\t" // packedYScale
- "leal (%2,%4), %%eax \n\t"
- "leal (%3,%5), %%edx \n\t"
- "pxor %%mm4, %%mm4 \n\t"
-#ifdef HAVE_MMX2
-#define SCALED_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src1 ", %%mm5 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "movq " #src2 ", %%mm6 \n\t"\
- "punpcklbw %%mm0, %%mm0 \n\t"\
- "punpckhbw %%mm5, %%mm5 \n\t"\
- "punpcklbw %%mm1, %%mm1 \n\t"\
- "punpckhbw %%mm6, %%mm6 \n\t"\
- "pmulhuw %%mm3, %%mm0 \n\t"\
- "pmulhuw %%mm3, %%mm5 \n\t"\
- "pmulhuw %%mm3, %%mm1 \n\t"\
- "pmulhuw %%mm3, %%mm6 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "psubw %%mm2, %%mm1 \n\t"\
- "psubw %%mm2, %%mm6 \n\t"\
- "packuswb %%mm5, %%mm0 \n\t"\
- "packuswb %%mm6, %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-#else //HAVE_MMX2
-#define SCALED_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src1 ", %%mm5 \n\t"\
- "punpcklbw %%mm4, %%mm0 \n\t"\
- "punpckhbw %%mm4, %%mm5 \n\t"\
- "psubw %%mm2, %%mm0 \n\t"\
- "psubw %%mm2, %%mm5 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "psllw $6, %%mm0 \n\t"\
- "psllw $6, %%mm5 \n\t"\
- "pmulhw %%mm3, %%mm0 \n\t"\
- "movq " #src2 ", %%mm6 \n\t"\
- "pmulhw %%mm3, %%mm5 \n\t"\
- "punpcklbw %%mm4, %%mm1 \n\t"\
- "punpckhbw %%mm4, %%mm6 \n\t"\
- "psubw %%mm2, %%mm1 \n\t"\
- "psubw %%mm2, %%mm6 \n\t"\
- "psllw $6, %%mm1 \n\t"\
- "psllw $6, %%mm6 \n\t"\
- "pmulhw %%mm3, %%mm1 \n\t"\
- "pmulhw %%mm3, %%mm6 \n\t"\
- "packuswb %%mm5, %%mm0 \n\t"\
- "packuswb %%mm6, %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-#endif //!HAVE_MMX2
-
-SCALED_CPY((%2) , (%2, %4) , (%3) , (%3, %5))
-SCALED_CPY((%2, %4, 2), (%%eax, %4, 2), (%3, %5, 2), (%%edx, %5, 2))
-SCALED_CPY((%2, %4, 4), (%%eax, %4, 4), (%3, %5, 4), (%%edx, %5, 4))
- "leal (%%eax,%4,4), %%eax \n\t"
- "leal (%%edx,%5,4), %%edx \n\t"
-SCALED_CPY((%%eax, %4), (%%eax, %4, 2), (%%edx, %5), (%%edx, %5, 2))
-
-
- : "=&a" (packedOffsetAndScale)
- : "0" (packedOffsetAndScale),
- "r"(src),
- "r"(dst),
- "r" (srcStride),
- "r" (dstStride)
- : "%edx"
- );
-#else
- for(i=0; i<8; i++)
- memcpy( &(dst[dstStride*i]),
- &(src[srcStride*i]), BLOCK_SIZE);
-#endif
- }
- else
- {
-#ifdef HAVE_MMX
- asm volatile(
- "leal (%0,%2), %%eax \n\t"
- "leal (%1,%3), %%edx \n\t"
-
-#define SIMPLE_CPY(src1, src2, dst1, dst2) \
- "movq " #src1 ", %%mm0 \n\t"\
- "movq " #src2 ", %%mm1 \n\t"\
- "movq %%mm0, " #dst1 " \n\t"\
- "movq %%mm1, " #dst2 " \n\t"\
-
-SIMPLE_CPY((%0) , (%0, %2) , (%1) , (%1, %3))
-SIMPLE_CPY((%0, %2, 2), (%%eax, %2, 2), (%1, %3, 2), (%%edx, %3, 2))
-SIMPLE_CPY((%0, %2, 4), (%%eax, %2, 4), (%1, %3, 4), (%%edx, %3, 4))
- "leal (%%eax,%2,4), %%eax \n\t"
- "leal (%%edx,%3,4), %%edx \n\t"
-SIMPLE_CPY((%%eax, %2), (%%eax, %2, 2), (%%edx, %3), (%%edx, %3, 2))
-
- : : "r" (src),
- "r" (dst),
- "r" (srcStride),
- "r" (dstStride)
- : "%eax", "%edx"
- );
-#else
- for(i=0; i<8; i++)
- memcpy( &(dst[dstStride*i]),
- &(src[srcStride*i]), BLOCK_SIZE);
-#endif
- }
-}
-
-/**
- * Duplicates the given 8 src pixels ? times upward
- */
-static inline void RENAME(duplicate)(uint8_t src[], int stride)
-{
-#ifdef HAVE_MMX
- asm volatile(
- "movq (%0), %%mm0 \n\t"
- "addl %1, %0 \n\t"
- "movq %%mm0, (%0) \n\t"
- "movq %%mm0, (%0, %1) \n\t"
- "movq %%mm0, (%0, %1, 2) \n\t"
- : "+r" (src)
- : "r" (-stride)
- );
-#else
- int i;
- uint8_t *p=src;
- for(i=0; i<3; i++)
- {
- p-= stride;
- memcpy(p, src, 8);
- }
-#endif
-}
-
-/**
- * Filters array of bytes (Y or U or V values)
- */
-static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
- QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2)
-{
- PPContext __attribute__((aligned(8))) c= *c2; //copy to stack for faster access
- int x,y;
-#ifdef COMPILE_TIME_MODE
- const int mode= COMPILE_TIME_MODE;
-#else
- const int mode= isColor ? c.ppMode.chromMode : c.ppMode.lumMode;
-#endif
- int black=0, white=255; // blackest black and whitest white in the picture
- int QPCorrecture= 256*256;
-
- int copyAhead;
-#ifdef HAVE_MMX
- int i;
-#endif
-
- const int qpHShift= isColor ? 4-c.hChromaSubSample : 4;
- const int qpVShift= isColor ? 4-c.vChromaSubSample : 4;
-
- //FIXME remove
- uint64_t * const yHistogram= c.yHistogram;
- uint8_t * const tempSrc= c.tempSrc;
- uint8_t * const tempDst= c.tempDst;
- const int mbWidth= isColor ? (width+7)>>3 : (width+15)>>4;
-
-#ifdef HAVE_MMX
- for(i=0; i<32; i++){
- int offset= ((i*c.ppMode.baseDcDiff)>>8) + 1;
- int threshold= offset*2 + 1;
- c.mmxDcOffset[i]= 0x7F - offset;
- c.mmxDcThreshold[i]= 0x7F - threshold;
- c.mmxDcOffset[i]*= 0x0101010101010101LL;
- c.mmxDcThreshold[i]*= 0x0101010101010101LL;
- }
-#endif
-
- if(mode & CUBIC_IPOL_DEINT_FILTER) copyAhead=16;
- else if( (mode & INTERPOLATION_LINEAR_BLEND_DEINT_FILTER)
- || (mode & FFMPEG_DEINT_FILTER)
- || (mode & LOWPASS5_DEINT_FILTER)) copyAhead=14;
- else if( (mode & V_DEBLOCK)
- || (mode & INTERPOLATION_LINEAR_IPOL_DEINT_FILTER)
- || (mode & MEDIAN_DEINT_FILTER)) copyAhead=13;
- else if(mode & V_X1_FILTER) copyAhead=11;
-// else if(mode & V_RK1_FILTER) copyAhead=10;
- else if(mode & DERING) copyAhead=9;
- else copyAhead=8;
-
- copyAhead-= 8;
-
- if(!isColor)
- {
- uint64_t sum= 0;
- int i;
- uint64_t maxClipped;
- uint64_t clipped;
- double scale;
-
- c.frameNum++;
- // first frame is fscked so we ignore it
- if(c.frameNum == 1) yHistogram[0]= width*height/64*15/256;
-
- for(i=0; i<256; i++)
- {
- sum+= yHistogram[i];
-// printf("%d ", yHistogram[i]);
- }
-// printf("\n\n");
-
- /* we allways get a completly black picture first */
- maxClipped= (uint64_t)(sum * c.ppMode.maxClippedThreshold);
-
- clipped= sum;
- for(black=255; black>0; black--)
- {
- if(clipped < maxClipped) break;
- clipped-= yHistogram[black];
- }
-
- clipped= sum;
- for(white=0; white<256; white++)
- {
- if(clipped < maxClipped) break;
- clipped-= yHistogram[white];
- }
-
- scale= (double)(c.ppMode.maxAllowedY - c.ppMode.minAllowedY) / (double)(white-black);
-
-#ifdef HAVE_MMX2
- c.packedYScale= (uint16_t)(scale*256.0 + 0.5);
- c.packedYOffset= (((black*c.packedYScale)>>8) - c.ppMode.minAllowedY) & 0xFFFF;
-#else
- c.packedYScale= (uint16_t)(scale*1024.0 + 0.5);
- c.packedYOffset= (black - c.ppMode.minAllowedY) & 0xFFFF;
-#endif
-
- c.packedYOffset|= c.packedYOffset<<32;
- c.packedYOffset|= c.packedYOffset<<16;
-
- c.packedYScale|= c.packedYScale<<32;
- c.packedYScale|= c.packedYScale<<16;
-
- if(mode & LEVEL_FIX) QPCorrecture= (int)(scale*256*256 + 0.5);
- else QPCorrecture= 256*256;
- }
- else
- {
- c.packedYScale= 0x0100010001000100LL;
- c.packedYOffset= 0;
- QPCorrecture= 256*256;
- }
-
- /* copy & deinterlace first row of blocks */
- y=-BLOCK_SIZE;
- {
- uint8_t *srcBlock= &(src[y*srcStride]);
- uint8_t *dstBlock= tempDst + dstStride;
-
- // From this point on it is guranteed that we can read and write 16 lines downward
- // finish 1 block before the next otherwise we´ll might have a problem
- // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
- for(x=0; x<width; x+=BLOCK_SIZE)
- {
-
-#ifdef HAVE_MMX2
-/*
- prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
- prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
-*/
-
- asm(
- "movl %4, %%eax \n\t"
- "shrl $2, %%eax \n\t"
- "andl $6, %%eax \n\t"
- "addl %5, %%eax \n\t"
- "movl %%eax, %%edx \n\t"
- "imul %1, %%eax \n\t"
- "imul %3, %%edx \n\t"
- "prefetchnta 32(%%eax, %0) \n\t"
- "prefetcht0 32(%%edx, %2) \n\t"
- "addl %1, %%eax \n\t"
- "addl %3, %%edx \n\t"
- "prefetchnta 32(%%eax, %0) \n\t"
- "prefetcht0 32(%%edx, %2) \n\t"
- :: "r" (srcBlock), "r" (srcStride), "r" (dstBlock), "r" (dstStride),
- "m" (x), "m" (copyAhead)
- : "%eax", "%edx"
- );
-
-#elif defined(HAVE_3DNOW)
-//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
-/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
- prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
-*/
-#endif
-
- RENAME(blockCopy)(dstBlock + dstStride*8, dstStride,
- srcBlock + srcStride*8, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
-
- RENAME(duplicate)(dstBlock + dstStride*8, dstStride);
-
- if(mode & INTERPOLATION_LINEAR_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
- else if(mode & INTERPOLATION_LINEAR_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendLinear)(dstBlock, dstStride);
- else if(mode & MEDIAN_DEINT_FILTER)
- RENAME(deInterlaceMedian)(dstBlock, dstStride);
- else if(mode & CUBIC_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
- else if(mode & FFMPEG_DEINT_FILTER)
- RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & LOWPASS5_DEINT_FILTER)
- RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
-/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
-*/
- dstBlock+=8;
- srcBlock+=8;
- }
- if(width==dstStride)
- memcpy(dst, tempDst + 9*dstStride, copyAhead*dstStride);
- else
- {
- int i;
- for(i=0; i<copyAhead; i++)
- {
- memcpy(dst + i*dstStride, tempDst + (9+i)*dstStride, width);
- }
- }
- }
-
-//printf("\n");
- for(y=0; y<height; y+=BLOCK_SIZE)
- {
- //1% speedup if these are here instead of the inner loop
- uint8_t *srcBlock= &(src[y*srcStride]);
- uint8_t *dstBlock= &(dst[y*dstStride]);
-#ifdef HAVE_MMX
- uint8_t *tempBlock1= c.tempBlocks;
- uint8_t *tempBlock2= c.tempBlocks + 8;
-#endif
- int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride];
- int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*QPStride];
- int QP=0;
- /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards
- if not than use a temporary buffer */
- if(y+15 >= height)
- {
- int i;
- /* copy from line (copyAhead) to (copyAhead+7) of src, these will be copied with
- blockcopy to dst later */
- memcpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead,
- srcStride*MAX(height-y-copyAhead, 0) );
-
- /* duplicate last line of src to fill the void upto line (copyAhead+7) */
- for(i=MAX(height-y, 8); i<copyAhead+8; i++)
- memcpy(tempSrc + srcStride*i, src + srcStride*(height-1), srcStride);
-
- /* copy up to (copyAhead+1) lines of dst (line -1 to (copyAhead-1))*/
- memcpy(tempDst, dstBlock - dstStride, dstStride*MIN(height-y+1, copyAhead+1) );
-
- /* duplicate last line of dst to fill the void upto line (copyAhead) */
- for(i=height-y+1; i<=copyAhead; i++)
- memcpy(tempDst + dstStride*i, dst + dstStride*(height-1), dstStride);
-
- dstBlock= tempDst + dstStride;
- srcBlock= tempSrc;
- }
-//printf("\n");
-
- // From this point on it is guranteed that we can read and write 16 lines downward
- // finish 1 block before the next otherwise we´ll might have a problem
- // with the L1 Cache of the P4 ... or only a few blocks at a time or soemthing
- for(x=0; x<width; x+=BLOCK_SIZE)
- {
- const int stride= dstStride;
-#ifdef HAVE_MMX
- uint8_t *tmpXchg;
-#endif
- if(isColor)
- {
- QP= QPptr[x>>qpHShift];
- c.nonBQP= nonBQPptr[x>>qpHShift];
- }
- else
- {
- QP= QPptr[x>>4];
- QP= (QP* QPCorrecture + 256*128)>>16;
- c.nonBQP= nonBQPptr[x>>4];
- c.nonBQP= (c.nonBQP* QPCorrecture + 256*128)>>16;
- yHistogram[ srcBlock[srcStride*12 + 4] ]++;
- }
- c.QP= QP;
-#ifdef HAVE_MMX
- asm volatile(
- "movd %1, %%mm7 \n\t"
- "packuswb %%mm7, %%mm7 \n\t" // 0, 0, 0, QP, 0, 0, 0, QP
- "packuswb %%mm7, %%mm7 \n\t" // 0,QP, 0, QP, 0,QP, 0, QP
- "packuswb %%mm7, %%mm7 \n\t" // QP,..., QP
- "movq %%mm7, %0 \n\t"
- : "=m" (c.pQPb)
- : "r" (QP)
- );
-#endif
-
-
-#ifdef HAVE_MMX2
-/*
- prefetchnta(srcBlock + (((x>>2)&6) + 5)*srcStride + 32);
- prefetchnta(srcBlock + (((x>>2)&6) + 6)*srcStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 5)*dstStride + 32);
- prefetcht0(dstBlock + (((x>>2)&6) + 6)*dstStride + 32);
-*/
-
- asm(
- "movl %4, %%eax \n\t"
- "shrl $2, %%eax \n\t"
- "andl $6, %%eax \n\t"
- "addl %5, %%eax \n\t"
- "movl %%eax, %%edx \n\t"
- "imul %1, %%eax \n\t"
- "imul %3, %%edx \n\t"
- "prefetchnta 32(%%eax, %0) \n\t"
- "prefetcht0 32(%%edx, %2) \n\t"
- "addl %1, %%eax \n\t"
- "addl %3, %%edx \n\t"
- "prefetchnta 32(%%eax, %0) \n\t"
- "prefetcht0 32(%%edx, %2) \n\t"
- :: "r" (srcBlock), "r" (srcStride), "r" (dstBlock), "r" (dstStride),
- "m" (x), "m" (copyAhead)
- : "%eax", "%edx"
- );
-
-#elif defined(HAVE_3DNOW)
-//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ...
-/* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32);
- prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32);
- prefetchw(dstBlock + (((x>>3)&3) + 9)*dstStride + 32);
-*/
-#endif
-
- RENAME(blockCopy)(dstBlock + dstStride*copyAhead, dstStride,
- srcBlock + srcStride*copyAhead, srcStride, mode & LEVEL_FIX, &c.packedYOffset);
-
- if(mode & INTERPOLATION_LINEAR_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateLinear)(dstBlock, dstStride);
- else if(mode & INTERPOLATION_LINEAR_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendLinear)(dstBlock, dstStride);
- else if(mode & MEDIAN_DEINT_FILTER)
- RENAME(deInterlaceMedian)(dstBlock, dstStride);
- else if(mode & CUBIC_IPOL_DEINT_FILTER)
- RENAME(deInterlaceInterpolateCubic)(dstBlock, dstStride);
- else if(mode & FFMPEG_DEINT_FILTER)
- RENAME(deInterlaceFF)(dstBlock, dstStride, c.deintTemp + x);
- else if(mode & LOWPASS5_DEINT_FILTER)
- RENAME(deInterlaceL5)(dstBlock, dstStride, c.deintTemp + x, c.deintTemp + width + x);
-/* else if(mode & CUBIC_BLEND_DEINT_FILTER)
- RENAME(deInterlaceBlendCubic)(dstBlock, dstStride);
-*/
-
- /* only deblock if we have 2 blocks */
- if(y + 8 < height)
- {
- if(mode & V_X1_FILTER)
- RENAME(vertX1Filter)(dstBlock, stride, &c);
- else if(mode & V_DEBLOCK)
- {
- const int t= RENAME(vertClassify)(dstBlock, stride, &c);
-
- if(t==1)
- RENAME(doVertLowPass)(dstBlock, stride, &c);
- else if(t==2)
- RENAME(doVertDefFilter)(dstBlock, stride, &c);
- }
- }
-
-#ifdef HAVE_MMX
- RENAME(transpose1)(tempBlock1, tempBlock2, dstBlock, dstStride);
-#endif
- /* check if we have a previous block to deblock it with dstBlock */
- if(x - 8 >= 0)
- {
-#ifdef HAVE_MMX
- if(mode & H_X1_FILTER)
- RENAME(vertX1Filter)(tempBlock1, 16, &c);
- else if(mode & H_DEBLOCK)
- {
-//START_TIMER
- const int t= RENAME(vertClassify)(tempBlock1, 16, &c);
-//STOP_TIMER("dc & minmax")
- if(t==1)
- RENAME(doVertLowPass)(tempBlock1, 16, &c);
- else if(t==2)
- RENAME(doVertDefFilter)(tempBlock1, 16, &c);
- }
-
- RENAME(transpose2)(dstBlock-4, dstStride, tempBlock1 + 4*16);
-
-#else
- if(mode & H_X1_FILTER)
- horizX1Filter(dstBlock-4, stride, QP);
- else if(mode & H_DEBLOCK)
- {
- if( isHorizDC(dstBlock-4, stride, &c))
- {
- if(isHorizMinMaxOk(dstBlock-4, stride, QP))
- doHorizLowPass(dstBlock-4, stride, QP);
- }
- else
- doHorizDefFilter(dstBlock-4, stride, QP);
- }
-#endif
- if(mode & DERING)
- {
- //FIXME filter first line
- if(y>0) RENAME(dering)(dstBlock - stride - 8, stride, &c);
- }
-
- if(mode & TEMP_NOISE_FILTER)
- {
- RENAME(tempNoiseReducer)(dstBlock-8, stride,
- c.tempBlured[isColor] + y*dstStride + x,
- c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
- c.ppMode.maxTmpNoise);
- }
- }
-
- dstBlock+=8;
- srcBlock+=8;
-
-#ifdef HAVE_MMX
- tmpXchg= tempBlock1;
- tempBlock1= tempBlock2;
- tempBlock2 = tmpXchg;
-#endif
- }
-
- if(mode & DERING)
- {
- if(y > 0) RENAME(dering)(dstBlock - dstStride - 8, dstStride, &c);
- }
-
- if((mode & TEMP_NOISE_FILTER))
- {
- RENAME(tempNoiseReducer)(dstBlock-8, dstStride,
- c.tempBlured[isColor] + y*dstStride + x,
- c.tempBluredPast[isColor] + (y>>3)*256 + (x>>3),
- c.ppMode.maxTmpNoise);
- }
-
- /* did we use a tmp buffer for the last lines*/
- if(y+15 >= height)
- {
- uint8_t *dstBlock= &(dst[y*dstStride]);
- if(width==dstStride)
- memcpy(dstBlock, tempDst + dstStride, dstStride*(height-y));
- else
- {
- int i;
- for(i=0; i<height-y; i++)
- {
- memcpy(dstBlock + i*dstStride, tempDst + (i+1)*dstStride, width);
- }
- }
- }
-/*
- for(x=0; x<width; x+=32)
- {
- volatile int i;
- i+= + dstBlock[x + 7*dstStride] + dstBlock[x + 8*dstStride]
- + dstBlock[x + 9*dstStride] + dstBlock[x +10*dstStride]
- + dstBlock[x +11*dstStride] + dstBlock[x +12*dstStride];
-// + dstBlock[x +13*dstStride]
-// + dstBlock[x +14*dstStride] + dstBlock[x +15*dstStride];
- }*/
- }
-#ifdef HAVE_3DNOW
- asm volatile("femms");
-#elif defined (HAVE_MMX)
- asm volatile("emms");
-#endif
-
-#ifdef DEBUG_BRIGHTNESS
- if(!isColor)
- {
- int max=1;
- int i;
- for(i=0; i<256; i++)
- if(yHistogram[i] > max) max=yHistogram[i];
-
- for(i=1; i<256; i++)
- {
- int x;
- int start=yHistogram[i-1]/(max/256+1);
- int end=yHistogram[i]/(max/256+1);
- int inc= end > start ? 1 : -1;
- for(x=start; x!=end+inc; x+=inc)
- dst[ i*dstStride + x]+=128;
- }
-
- for(i=0; i<100; i+=2)
- {
- dst[ (white)*dstStride + i]+=128;
- dst[ (black)*dstStride + i]+=128;
- }
-
- }
-#endif
-
- *c2= c; //copy local context back
-
-}
+++ /dev/null
-/*
- * MACE decoder
- * Copyright (c) 2002 Laszlo Torok <torokl@alpha.dfmk.hu>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mace.c
- * MACE decoder.
- */
-
-#include "avcodec.h"
-
-/*
- * Adapted to ffmpeg by Francois Revol <revol@free.fr>
- * (removed 68k REG stuff, changed types, added some statics and consts,
- * libavcodec api, context stuff, interlaced stereo out).
- */
-
-static const uint16_t MACEtab1[] = { 0xfff3, 0x0008, 0x004c, 0x00de, 0x00de, 0x004c, 0x0008, 0xfff3 };
-
-static const uint16_t MACEtab3[] = { 0xffee, 0x008c, 0x008c, 0xffee };
-
-static const uint16_t MACEtab2[][8] = {
- { 0x0025, 0x0074, 0x00CE, 0x014A, 0xFEB5, 0xFF31, 0xFF8B, 0xFFDA },
- { 0x0027, 0x0079, 0x00D8, 0x015A, 0xFEA5, 0xFF27, 0xFF86, 0xFFD8 },
- { 0x0029, 0x007F, 0x00E1, 0x0169, 0xFE96, 0xFF1E, 0xFF80, 0xFFD6 },
- { 0x002A, 0x0084, 0x00EB, 0x0179, 0xFE86, 0xFF14, 0xFF7B, 0xFFD5 },
- { 0x002C, 0x0089, 0x00F5, 0x0188, 0xFE77, 0xFF0A, 0xFF76, 0xFFD3 },
- { 0x002E, 0x0090, 0x0100, 0x019A, 0xFE65, 0xFEFF, 0xFF6F, 0xFFD1 },
- { 0x0030, 0x0096, 0x010B, 0x01AC, 0xFE53, 0xFEF4, 0xFF69, 0xFFCF },
- { 0x0033, 0x009D, 0x0118, 0x01C1, 0xFE3E, 0xFEE7, 0xFF62, 0xFFCC },
- { 0x0035, 0x00A5, 0x0125, 0x01D6, 0xFE29, 0xFEDA, 0xFF5A, 0xFFCA },
- { 0x0037, 0x00AC, 0x0132, 0x01EA, 0xFE15, 0xFECD, 0xFF53, 0xFFC8 },
- { 0x003A, 0x00B3, 0x013F, 0x01FF, 0xFE00, 0xFEC0, 0xFF4C, 0xFFC5 },
- { 0x003C, 0x00BB, 0x014D, 0x0216, 0xFDE9, 0xFEB2, 0xFF44, 0xFFC3 },
- { 0x003F, 0x00C3, 0x015C, 0x022D, 0xFDD2, 0xFEA3, 0xFF3C, 0xFFC0 },
- { 0x0042, 0x00CD, 0x016C, 0x0247, 0xFDB8, 0xFE93, 0xFF32, 0xFFBD },
- { 0x0045, 0x00D6, 0x017C, 0x0261, 0xFD9E, 0xFE83, 0xFF29, 0xFFBA },
- { 0x0048, 0x00DF, 0x018C, 0x027B, 0xFD84, 0xFE73, 0xFF20, 0xFFB7 },
- { 0x004B, 0x00E9, 0x019E, 0x0297, 0xFD68, 0xFE61, 0xFF16, 0xFFB4 },
- { 0x004F, 0x00F4, 0x01B1, 0x02B6, 0xFD49, 0xFE4E, 0xFF0B, 0xFFB0 },
- { 0x0052, 0x00FE, 0x01C5, 0x02D5, 0xFD2A, 0xFE3A, 0xFF01, 0xFFAD },
- { 0x0056, 0x0109, 0x01D8, 0x02F4, 0xFD0B, 0xFE27, 0xFEF6, 0xFFA9 },
- { 0x005A, 0x0116, 0x01EF, 0x0318, 0xFCE7, 0xFE10, 0xFEE9, 0xFFA5 },
- { 0x005E, 0x0122, 0x0204, 0x033A, 0xFCC5, 0xFDFB, 0xFEDD, 0xFFA1 },
- { 0x0062, 0x012F, 0x021A, 0x035E, 0xFCA1, 0xFDE5, 0xFED0, 0xFF9D },
- { 0x0066, 0x013C, 0x0232, 0x0385, 0xFC7A, 0xFDCD, 0xFEC3, 0xFF99 },
- { 0x006B, 0x014B, 0x024C, 0x03AE, 0xFC51, 0xFDB3, 0xFEB4, 0xFF94 },
- { 0x0070, 0x0159, 0x0266, 0x03D7, 0xFC28, 0xFD99, 0xFEA6, 0xFF8F },
- { 0x0075, 0x0169, 0x0281, 0x0403, 0xFBFC, 0xFD7E, 0xFE96, 0xFF8A },
- { 0x007A, 0x0179, 0x029E, 0x0432, 0xFBCD, 0xFD61, 0xFE86, 0xFF85 },
- { 0x007F, 0x018A, 0x02BD, 0x0463, 0xFB9C, 0xFD42, 0xFE75, 0xFF80 },
- { 0x0085, 0x019B, 0x02DC, 0x0494, 0xFB6B, 0xFD23, 0xFE64, 0xFF7A },
- { 0x008B, 0x01AE, 0x02FC, 0x04C8, 0xFB37, 0xFD03, 0xFE51, 0xFF74 },
- { 0x0091, 0x01C1, 0x031F, 0x0500, 0xFAFF, 0xFCE0, 0xFE3E, 0xFF6E },
- { 0x0098, 0x01D5, 0x0343, 0x0539, 0xFAC6, 0xFCBC, 0xFE2A, 0xFF67 },
- { 0x009F, 0x01EA, 0x0368, 0x0575, 0xFA8A, 0xFC97, 0xFE15, 0xFF60 },
- { 0x00A6, 0x0200, 0x038F, 0x05B3, 0xFA4C, 0xFC70, 0xFDFF, 0xFF59 },
- { 0x00AD, 0x0217, 0x03B7, 0x05F3, 0xFA0C, 0xFC48, 0xFDE8, 0xFF52 },
- { 0x00B5, 0x022E, 0x03E1, 0x0636, 0xF9C9, 0xFC1E, 0xFDD1, 0xFF4A },
- { 0x00BD, 0x0248, 0x040E, 0x067F, 0xF980, 0xFBF1, 0xFDB7, 0xFF42 },
- { 0x00C5, 0x0262, 0x043D, 0x06CA, 0xF935, 0xFBC2, 0xFD9D, 0xFF3A },
- { 0x00CE, 0x027D, 0x046D, 0x0717, 0xF8E8, 0xFB92, 0xFD82, 0xFF31 },
- { 0x00D7, 0x0299, 0x049F, 0x0767, 0xF898, 0xFB60, 0xFD66, 0xFF28 },
- { 0x00E1, 0x02B7, 0x04D5, 0x07BC, 0xF843, 0xFB2A, 0xFD48, 0xFF1E },
- { 0x00EB, 0x02D6, 0x050B, 0x0814, 0xF7EB, 0xFAF4, 0xFD29, 0xFF14 },
- { 0x00F6, 0x02F7, 0x0545, 0x0871, 0xF78E, 0xFABA, 0xFD08, 0xFF09 },
- { 0x0101, 0x0318, 0x0581, 0x08D1, 0xF72E, 0xFA7E, 0xFCE7, 0xFEFE },
- { 0x010C, 0x033C, 0x05C0, 0x0935, 0xF6CA, 0xFA3F, 0xFCC3, 0xFEF3 },
- { 0x0118, 0x0361, 0x0602, 0x099F, 0xF660, 0xF9FD, 0xFC9E, 0xFEE7 },
- { 0x0125, 0x0387, 0x0646, 0x0A0C, 0xF5F3, 0xF9B9, 0xFC78, 0xFEDA },
- { 0x0132, 0x03B0, 0x068E, 0x0A80, 0xF57F, 0xF971, 0xFC4F, 0xFECD },
- { 0x013F, 0x03DA, 0x06D9, 0x0AF7, 0xF508, 0xF926, 0xFC25, 0xFEC0 },
- { 0x014E, 0x0406, 0x0728, 0x0B75, 0xF48A, 0xF8D7, 0xFBF9, 0xFEB1 },
- { 0x015D, 0x0434, 0x077A, 0x0BF9, 0xF406, 0xF885, 0xFBCB, 0xFEA2 },
- { 0x016C, 0x0464, 0x07CF, 0x0C82, 0xF37D, 0xF830, 0xFB9B, 0xFE93 },
- { 0x017C, 0x0496, 0x0828, 0x0D10, 0xF2EF, 0xF7D7, 0xFB69, 0xFE83 },
- { 0x018E, 0x04CB, 0x0886, 0x0DA6, 0xF259, 0xF779, 0xFB34, 0xFE71 },
- { 0x019F, 0x0501, 0x08E6, 0x0E41, 0xF1BE, 0xF719, 0xFAFE, 0xFE60 },
- { 0x01B2, 0x053B, 0x094C, 0x0EE3, 0xF11C, 0xF6B3, 0xFAC4, 0xFE4D },
- { 0x01C5, 0x0576, 0x09B6, 0x0F8E, 0xF071, 0xF649, 0xFA89, 0xFE3A },
- { 0x01D9, 0x05B5, 0x0A26, 0x1040, 0xEFBF, 0xF5D9, 0xFA4A, 0xFE26 },
- { 0x01EF, 0x05F6, 0x0A9A, 0x10FA, 0xEF05, 0xF565, 0xFA09, 0xFE10 },
- { 0x0205, 0x063A, 0x0B13, 0x11BC, 0xEE43, 0xF4EC, 0xF9C5, 0xFDFA },
- { 0x021C, 0x0681, 0x0B91, 0x1285, 0xED7A, 0xF46E, 0xF97E, 0xFDE3 },
- { 0x0234, 0x06CC, 0x0C15, 0x1359, 0xECA6, 0xF3EA, 0xF933, 0xFDCB },
- { 0x024D, 0x071A, 0x0CA0, 0x1437, 0xEBC8, 0xF35F, 0xF8E5, 0xFDB2 },
- { 0x0267, 0x076A, 0x0D2F, 0x151D, 0xEAE2, 0xF2D0, 0xF895, 0xFD98 },
- { 0x0283, 0x07C0, 0x0DC7, 0x160F, 0xE9F0, 0xF238, 0xF83F, 0xFD7C },
- { 0x029F, 0x0818, 0x0E63, 0x170A, 0xE8F5, 0xF19C, 0xF7E7, 0xFD60 },
- { 0x02BD, 0x0874, 0x0F08, 0x1811, 0xE7EE, 0xF0F7, 0xF78B, 0xFD42 },
- { 0x02DD, 0x08D5, 0x0FB4, 0x1926, 0xE6D9, 0xF04B, 0xF72A, 0xFD22 },
- { 0x02FE, 0x093A, 0x1067, 0x1A44, 0xE5BB, 0xEF98, 0xF6C5, 0xFD01 },
- { 0x0320, 0x09A3, 0x1122, 0x1B70, 0xE48F, 0xEEDD, 0xF65C, 0xFCDF },
- { 0x0344, 0x0A12, 0x11E7, 0x1CAB, 0xE354, 0xEE18, 0xF5ED, 0xFCBB },
- { 0x0369, 0x0A84, 0x12B2, 0x1DF0, 0xE20F, 0xED4D, 0xF57B, 0xFC96 },
- { 0x0390, 0x0AFD, 0x1389, 0x1F48, 0xE0B7, 0xEC76, 0xF502, 0xFC6F },
- { 0x03B8, 0x0B7A, 0x1467, 0x20AC, 0xDF53, 0xEB98, 0xF485, 0xFC47 },
- { 0x03E3, 0x0BFE, 0x1551, 0x2223, 0xDDDC, 0xEAAE, 0xF401, 0xFC1C },
- { 0x040F, 0x0C87, 0x1645, 0x23A9, 0xDC56, 0xE9BA, 0xF378, 0xFBF0 },
- { 0x043E, 0x0D16, 0x1744, 0x2541, 0xDABE, 0xE8BB, 0xF2E9, 0xFBC1 },
- { 0x046E, 0x0DAB, 0x184C, 0x26E8, 0xD917, 0xE7B3, 0xF254, 0xFB91 },
- { 0x04A1, 0x0E47, 0x1961, 0x28A4, 0xD75B, 0xE69E, 0xF1B8, 0xFB5E },
- { 0x04D6, 0x0EEA, 0x1A84, 0x2A75, 0xD58A, 0xE57B, 0xF115, 0xFB29 },
- { 0x050D, 0x0F95, 0x1BB3, 0x2C5B, 0xD3A4, 0xE44C, 0xF06A, 0xFAF2 },
- { 0x0547, 0x1046, 0x1CEF, 0x2E55, 0xD1AA, 0xE310, 0xEFB9, 0xFAB8 },
- { 0x0583, 0x1100, 0x1E3A, 0x3066, 0xCF99, 0xE1C5, 0xEEFF, 0xFA7C },
- { 0x05C2, 0x11C3, 0x1F94, 0x3292, 0xCD6D, 0xE06B, 0xEE3C, 0xFA3D },
- { 0x0604, 0x128E, 0x20FC, 0x34D2, 0xCB2D, 0xDF03, 0xED71, 0xF9FB },
- { 0x0649, 0x1362, 0x2275, 0x372E, 0xC8D1, 0xDD8A, 0xEC9D, 0xF9B6 },
- { 0x0690, 0x143F, 0x23FF, 0x39A4, 0xC65B, 0xDC00, 0xEBC0, 0xF96F },
- { 0x06DC, 0x1527, 0x259A, 0x3C37, 0xC3C8, 0xDA65, 0xEAD8, 0xF923 },
- { 0x072A, 0x1619, 0x2749, 0x3EE8, 0xC117, 0xD8B6, 0xE9E6, 0xF8D5 },
- { 0x077C, 0x1715, 0x2909, 0x41B6, 0xBE49, 0xD6F6, 0xE8EA, 0xF883 },
- { 0x07D1, 0x181D, 0x2ADF, 0x44A6, 0xBB59, 0xD520, 0xE7E2, 0xF82E },
- { 0x082B, 0x1930, 0x2CC7, 0x47B4, 0xB84B, 0xD338, 0xE6CF, 0xF7D4 },
- { 0x0888, 0x1A50, 0x2EC6, 0x4AE7, 0xB518, 0xD139, 0xE5AF, 0xF777 },
- { 0x08EA, 0x1B7D, 0x30DE, 0x4E40, 0xB1BF, 0xCF21, 0xE482, 0xF715 },
- { 0x094F, 0x1CB7, 0x330C, 0x51BE, 0xAE41, 0xCCF3, 0xE348, 0xF6B0 },
- { 0x09BA, 0x1DFF, 0x3554, 0x5565, 0xAA9A, 0xCAAB, 0xE200, 0xF645 },
- { 0x0A29, 0x1F55, 0x37B4, 0x5932, 0xA6CD, 0xC84B, 0xE0AA, 0xF5D6 },
- { 0x0A9D, 0x20BC, 0x3A31, 0x5D2E, 0xA2D1, 0xC5CE, 0xDF43, 0xF562 },
- { 0x0B16, 0x2231, 0x3CC9, 0x6156, 0x9EA9, 0xC336, 0xDDCE, 0xF4E9 },
- { 0x0B95, 0x23B8, 0x3F80, 0x65AF, 0x9A50, 0xC07F, 0xDC47, 0xF46A },
- { 0x0C19, 0x2551, 0x4256, 0x6A39, 0x95C6, 0xBDA9, 0xDAAE, 0xF3E6 },
- { 0x0CA4, 0x26FB, 0x454C, 0x6EF7, 0x9108, 0xBAB3, 0xD904, 0xF35B },
- { 0x0D34, 0x28B8, 0x4864, 0x73EB, 0x8C14, 0xB79B, 0xD747, 0xF2CB },
- { 0x0DCB, 0x2A8A, 0x4B9F, 0x7918, 0x86E7, 0xB460, 0xD575, 0xF234 },
- { 0x0E68, 0x2C6F, 0x4EFE, 0x7E7E, 0x8181, 0xB101, 0xD390, 0xF197 },
- { 0x0F0D, 0x2E6B, 0x5285, 0x7FFF, 0x8000, 0xAD7A, 0xD194, 0xF0F2 },
- { 0x0FB9, 0x307E, 0x5635, 0x7FFF, 0x8000, 0xA9CA, 0xCF81, 0xF046 },
- { 0x106D, 0x32A7, 0x5A0D, 0x7FFF, 0x8000, 0xA5F2, 0xCD58, 0xEF92 },
- { 0x1128, 0x34EA, 0x5E12, 0x7FFF, 0x8000, 0xA1ED, 0xCB15, 0xEED7 },
- { 0x11ED, 0x3747, 0x6245, 0x7FFF, 0x8000, 0x9DBA, 0xC8B8, 0xEE12 },
- { 0x12B9, 0x39BF, 0x66A8, 0x7FFF, 0x8000, 0x9957, 0xC640, 0xED46 },
- { 0x138F, 0x3C52, 0x6B3C, 0x7FFF, 0x8000, 0x94C3, 0xC3AD, 0xEC70 },
- { 0x146F, 0x3F04, 0x7006, 0x7FFF, 0x8000, 0x8FF9, 0xC0FB, 0xEB90 },
- { 0x1558, 0x41D3, 0x7505, 0x7FFF, 0x8000, 0x8AFA, 0xBE2C, 0xEAA7 },
- { 0x164C, 0x44C3, 0x7A3E, 0x7FFF, 0x8000, 0x85C1, 0xBB3C, 0xE9B3 },
- { 0x174B, 0x47D5, 0x7FB3, 0x7FFF, 0x8000, 0x804C, 0xB82A, 0xE8B4 },
- { 0x1855, 0x4B0A, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xB4F5, 0xE7AA },
- { 0x196B, 0x4E63, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xB19C, 0xE694 },
- { 0x1A8D, 0x51E3, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xAE1C, 0xE572 },
- { 0x1BBD, 0x558B, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xAA74, 0xE442 },
- { 0x1CFA, 0x595C, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xA6A3, 0xE305 },
- { 0x1E45, 0x5D59, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0xA2A6, 0xE1BA },
- { 0x1F9F, 0x6184, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0x9E7B, 0xE060 },
- { 0x2108, 0x65DE, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0x9A21, 0xDEF7 },
- { 0x2281, 0x6A6A, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0x9595, 0xDD7E },
- { 0x240C, 0x6F29, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0x90D6, 0xDBF3 },
- { 0x25A7, 0x741F, 0x7FFF, 0x7FFF, 0x8000, 0x8000, 0x8BE0, 0xDA58 },
-};
-
-static const uint16_t MACEtab4[][8] = {
- { 0x0040, 0x00D8, 0xFF27, 0xFFBF, 0, 0, 0, 0 }, { 0x0043, 0x00E2, 0xFF1D, 0xFFBC, 0, 0, 0, 0 },
- { 0x0046, 0x00EC, 0xFF13, 0xFFB9, 0, 0, 0, 0 }, { 0x004A, 0x00F6, 0xFF09, 0xFFB5, 0, 0, 0, 0 },
- { 0x004D, 0x0101, 0xFEFE, 0xFFB2, 0, 0, 0, 0 }, { 0x0050, 0x010C, 0xFEF3, 0xFFAF, 0, 0, 0, 0 },
- { 0x0054, 0x0118, 0xFEE7, 0xFFAB, 0, 0, 0, 0 }, { 0x0058, 0x0126, 0xFED9, 0xFFA7, 0, 0, 0, 0 },
- { 0x005C, 0x0133, 0xFECC, 0xFFA3, 0, 0, 0, 0 }, { 0x0060, 0x0141, 0xFEBE, 0xFF9F, 0, 0, 0, 0 },
- { 0x0064, 0x014E, 0xFEB1, 0xFF9B, 0, 0, 0, 0 }, { 0x0068, 0x015E, 0xFEA1, 0xFF97, 0, 0, 0, 0 },
- { 0x006D, 0x016D, 0xFE92, 0xFF92, 0, 0, 0, 0 }, { 0x0072, 0x017E, 0xFE81, 0xFF8D, 0, 0, 0, 0 },
- { 0x0077, 0x018F, 0xFE70, 0xFF88, 0, 0, 0, 0 }, { 0x007C, 0x01A0, 0xFE5F, 0xFF83, 0, 0, 0, 0 },
- { 0x0082, 0x01B2, 0xFE4D, 0xFF7D, 0, 0, 0, 0 }, { 0x0088, 0x01C6, 0xFE39, 0xFF77, 0, 0, 0, 0 },
- { 0x008E, 0x01DB, 0xFE24, 0xFF71, 0, 0, 0, 0 }, { 0x0094, 0x01EF, 0xFE10, 0xFF6B, 0, 0, 0, 0 },
- { 0x009B, 0x0207, 0xFDF8, 0xFF64, 0, 0, 0, 0 }, { 0x00A2, 0x021D, 0xFDE2, 0xFF5D, 0, 0, 0, 0 },
- { 0x00A9, 0x0234, 0xFDCB, 0xFF56, 0, 0, 0, 0 }, { 0x00B0, 0x024E, 0xFDB1, 0xFF4F, 0, 0, 0, 0 },
- { 0x00B9, 0x0269, 0xFD96, 0xFF46, 0, 0, 0, 0 }, { 0x00C1, 0x0284, 0xFD7B, 0xFF3E, 0, 0, 0, 0 },
- { 0x00C9, 0x02A1, 0xFD5E, 0xFF36, 0, 0, 0, 0 }, { 0x00D2, 0x02BF, 0xFD40, 0xFF2D, 0, 0, 0, 0 },
- { 0x00DC, 0x02DF, 0xFD20, 0xFF23, 0, 0, 0, 0 }, { 0x00E6, 0x02FF, 0xFD00, 0xFF19, 0, 0, 0, 0 },
- { 0x00F0, 0x0321, 0xFCDE, 0xFF0F, 0, 0, 0, 0 }, { 0x00FB, 0x0346, 0xFCB9, 0xFF04, 0, 0, 0, 0 },
- { 0x0106, 0x036C, 0xFC93, 0xFEF9, 0, 0, 0, 0 }, { 0x0112, 0x0392, 0xFC6D, 0xFEED, 0, 0, 0, 0 },
- { 0x011E, 0x03BB, 0xFC44, 0xFEE1, 0, 0, 0, 0 }, { 0x012B, 0x03E5, 0xFC1A, 0xFED4, 0, 0, 0, 0 },
- { 0x0138, 0x0411, 0xFBEE, 0xFEC7, 0, 0, 0, 0 }, { 0x0146, 0x0441, 0xFBBE, 0xFEB9, 0, 0, 0, 0 },
- { 0x0155, 0x0472, 0xFB8D, 0xFEAA, 0, 0, 0, 0 }, { 0x0164, 0x04A4, 0xFB5B, 0xFE9B, 0, 0, 0, 0 },
- { 0x0174, 0x04D9, 0xFB26, 0xFE8B, 0, 0, 0, 0 }, { 0x0184, 0x0511, 0xFAEE, 0xFE7B, 0, 0, 0, 0 },
- { 0x0196, 0x054A, 0xFAB5, 0xFE69, 0, 0, 0, 0 }, { 0x01A8, 0x0587, 0xFA78, 0xFE57, 0, 0, 0, 0 },
- { 0x01BB, 0x05C6, 0xFA39, 0xFE44, 0, 0, 0, 0 }, { 0x01CE, 0x0608, 0xF9F7, 0xFE31, 0, 0, 0, 0 },
- { 0x01E3, 0x064D, 0xF9B2, 0xFE1C, 0, 0, 0, 0 }, { 0x01F9, 0x0694, 0xF96B, 0xFE06, 0, 0, 0, 0 },
- { 0x020F, 0x06E0, 0xF91F, 0xFDF0, 0, 0, 0, 0 }, { 0x0227, 0x072E, 0xF8D1, 0xFDD8, 0, 0, 0, 0 },
- { 0x0240, 0x0781, 0xF87E, 0xFDBF, 0, 0, 0, 0 }, { 0x0259, 0x07D7, 0xF828, 0xFDA6, 0, 0, 0, 0 },
- { 0x0274, 0x0831, 0xF7CE, 0xFD8B, 0, 0, 0, 0 }, { 0x0290, 0x088E, 0xF771, 0xFD6F, 0, 0, 0, 0 },
- { 0x02AE, 0x08F0, 0xF70F, 0xFD51, 0, 0, 0, 0 }, { 0x02CC, 0x0955, 0xF6AA, 0xFD33, 0, 0, 0, 0 },
- { 0x02EC, 0x09C0, 0xF63F, 0xFD13, 0, 0, 0, 0 }, { 0x030D, 0x0A2F, 0xF5D0, 0xFCF2, 0, 0, 0, 0 },
- { 0x0330, 0x0AA4, 0xF55B, 0xFCCF, 0, 0, 0, 0 }, { 0x0355, 0x0B1E, 0xF4E1, 0xFCAA, 0, 0, 0, 0 },
- { 0x037B, 0x0B9D, 0xF462, 0xFC84, 0, 0, 0, 0 }, { 0x03A2, 0x0C20, 0xF3DF, 0xFC5D, 0, 0, 0, 0 },
- { 0x03CC, 0x0CAB, 0xF354, 0xFC33, 0, 0, 0, 0 }, { 0x03F8, 0x0D3D, 0xF2C2, 0xFC07, 0, 0, 0, 0 },
- { 0x0425, 0x0DD3, 0xF22C, 0xFBDA, 0, 0, 0, 0 }, { 0x0454, 0x0E72, 0xF18D, 0xFBAB, 0, 0, 0, 0 },
- { 0x0486, 0x0F16, 0xF0E9, 0xFB79, 0, 0, 0, 0 }, { 0x04B9, 0x0FC3, 0xF03C, 0xFB46, 0, 0, 0, 0 },
- { 0x04F0, 0x1078, 0xEF87, 0xFB0F, 0, 0, 0, 0 }, { 0x0528, 0x1133, 0xEECC, 0xFAD7, 0, 0, 0, 0 },
- { 0x0563, 0x11F7, 0xEE08, 0xFA9C, 0, 0, 0, 0 }, { 0x05A1, 0x12C6, 0xED39, 0xFA5E, 0, 0, 0, 0 },
- { 0x05E1, 0x139B, 0xEC64, 0xFA1E, 0, 0, 0, 0 }, { 0x0624, 0x147C, 0xEB83, 0xF9DB, 0, 0, 0, 0 },
- { 0x066A, 0x1565, 0xEA9A, 0xF995, 0, 0, 0, 0 }, { 0x06B3, 0x165A, 0xE9A5, 0xF94C, 0, 0, 0, 0 },
- { 0x0700, 0x175A, 0xE8A5, 0xF8FF, 0, 0, 0, 0 }, { 0x0750, 0x1865, 0xE79A, 0xF8AF, 0, 0, 0, 0 },
- { 0x07A3, 0x197A, 0xE685, 0xF85C, 0, 0, 0, 0 }, { 0x07FB, 0x1A9D, 0xE562, 0xF804, 0, 0, 0, 0 },
- { 0x0856, 0x1BCE, 0xE431, 0xF7A9, 0, 0, 0, 0 }, { 0x08B5, 0x1D0C, 0xE2F3, 0xF74A, 0, 0, 0, 0 },
- { 0x0919, 0x1E57, 0xE1A8, 0xF6E6, 0, 0, 0, 0 }, { 0x0980, 0x1FB2, 0xE04D, 0xF67F, 0, 0, 0, 0 },
- { 0x09ED, 0x211D, 0xDEE2, 0xF612, 0, 0, 0, 0 }, { 0x0A5F, 0x2296, 0xDD69, 0xF5A0, 0, 0, 0, 0 },
- { 0x0AD5, 0x2422, 0xDBDD, 0xF52A, 0, 0, 0, 0 }, { 0x0B51, 0x25BF, 0xDA40, 0xF4AE, 0, 0, 0, 0 },
- { 0x0BD2, 0x276E, 0xD891, 0xF42D, 0, 0, 0, 0 }, { 0x0C5A, 0x2932, 0xD6CD, 0xF3A5, 0, 0, 0, 0 },
- { 0x0CE7, 0x2B08, 0xD4F7, 0xF318, 0, 0, 0, 0 }, { 0x0D7A, 0x2CF4, 0xD30B, 0xF285, 0, 0, 0, 0 },
- { 0x0E14, 0x2EF4, 0xD10B, 0xF1EB, 0, 0, 0, 0 }, { 0x0EB5, 0x310C, 0xCEF3, 0xF14A, 0, 0, 0, 0 },
- { 0x0F5D, 0x333E, 0xCCC1, 0xF0A2, 0, 0, 0, 0 }, { 0x100C, 0x3587, 0xCA78, 0xEFF3, 0, 0, 0, 0 },
- { 0x10C4, 0x37EB, 0xC814, 0xEF3B, 0, 0, 0, 0 }, { 0x1183, 0x3A69, 0xC596, 0xEE7C, 0, 0, 0, 0 },
- { 0x124B, 0x3D05, 0xC2FA, 0xEDB4, 0, 0, 0, 0 }, { 0x131C, 0x3FBE, 0xC041, 0xECE3, 0, 0, 0, 0 },
- { 0x13F7, 0x4296, 0xBD69, 0xEC08, 0, 0, 0, 0 }, { 0x14DB, 0x458F, 0xBA70, 0xEB24, 0, 0, 0, 0 },
- { 0x15C9, 0x48AA, 0xB755, 0xEA36, 0, 0, 0, 0 }, { 0x16C2, 0x4BE9, 0xB416, 0xE93D, 0, 0, 0, 0 },
- { 0x17C6, 0x4F4C, 0xB0B3, 0xE839, 0, 0, 0, 0 }, { 0x18D6, 0x52D5, 0xAD2A, 0xE729, 0, 0, 0, 0 },
- { 0x19F2, 0x5688, 0xA977, 0xE60D, 0, 0, 0, 0 }, { 0x1B1A, 0x5A65, 0xA59A, 0xE4E5, 0, 0, 0, 0 },
- { 0x1C50, 0x5E6D, 0xA192, 0xE3AF, 0, 0, 0, 0 }, { 0x1D93, 0x62A4, 0x9D5B, 0xE26C, 0, 0, 0, 0 },
- { 0x1EE5, 0x670C, 0x98F3, 0xE11A, 0, 0, 0, 0 }, { 0x2046, 0x6BA5, 0x945A, 0xDFB9, 0, 0, 0, 0 },
- { 0x21B7, 0x7072, 0x8F8D, 0xDE48, 0, 0, 0, 0 }, { 0x2338, 0x7578, 0x8A87, 0xDCC7, 0, 0, 0, 0 },
- { 0x24CB, 0x7AB5, 0x854A, 0xDB34, 0, 0, 0, 0 }, { 0x266F, 0x7FFF, 0x8000, 0xD990, 0, 0, 0, 0 },
- { 0x2826, 0x7FFF, 0x8000, 0xD7D9, 0, 0, 0, 0 }, { 0x29F1, 0x7FFF, 0x8000, 0xD60E, 0, 0, 0, 0 },
- { 0x2BD0, 0x7FFF, 0x8000, 0xD42F, 0, 0, 0, 0 }, { 0x2DC5, 0x7FFF, 0x8000, 0xD23A, 0, 0, 0, 0 },
- { 0x2FD0, 0x7FFF, 0x8000, 0xD02F, 0, 0, 0, 0 }, { 0x31F2, 0x7FFF, 0x8000, 0xCE0D, 0, 0, 0, 0 },
- { 0x342C, 0x7FFF, 0x8000, 0xCBD3, 0, 0, 0, 0 }, { 0x3681, 0x7FFF, 0x8000, 0xC97E, 0, 0, 0, 0 },
- { 0x38F0, 0x7FFF, 0x8000, 0xC70F, 0, 0, 0, 0 }, { 0x3B7A, 0x7FFF, 0x8000, 0xC485, 0, 0, 0, 0 },
- { 0x3E22, 0x7FFF, 0x8000, 0xC1DD, 0, 0, 0, 0 }, { 0x40E7, 0x7FFF, 0x8000, 0xBF18, 0, 0, 0, 0 },
-};
-/* end of constants */
-
-typedef struct MACEContext {
- short index, lev, factor, prev2, previous, level;
- short *outPtr;
-} MACEContext;
-
-/* /// "chomp3()" */
-static void chomp3(MACEContext *ctx,
- uint8_t val,
- const uint16_t tab1[],
- const uint16_t tab2[][8])
-{
- short current;
-
- current=(short)tab2[(ctx->index & 0x7f0) >> 4][val];
- if (current+ctx->lev > 32767) current=32767;
- else if (current+ctx->lev < -32768) current=-32767;
- else current+=ctx->lev;
- ctx->lev=current-(current >> 3);
-// *ctx->outPtr++=current >> 8;
- *ctx->outPtr++=current;
- if ( ( ctx->index += tab1[val]-(ctx->index>>5) ) < 0 ) ctx->index = 0;
-}
-/* \\\ */
-
-/* /// "Exp1to3()" */
-static void Exp1to3(MACEContext *ctx,
- uint8_t *inBuffer,
- void *outBuffer,
- uint32_t cnt,
- uint32_t numChannels,
- uint32_t whichChannel)
-{
- uint8_t pkt;
-
-/*
- if (inState) {
- ctx->index=inState[0];
- ctx->lev=inState[1];
- } else
-*/
- ctx->index=ctx->lev=0;
-
- inBuffer+=(whichChannel-1)*2;
-
- ctx->outPtr=outBuffer;
-
- while (cnt>0) {
- pkt=inBuffer[0];
- chomp3(ctx, pkt & 7, MACEtab1, MACEtab2);
- chomp3(ctx,(pkt >> 3) & 3, MACEtab3, MACEtab4);
- chomp3(ctx, pkt >> 5 , MACEtab1, MACEtab2);
- pkt=inBuffer[1];
- chomp3(ctx, pkt & 7, MACEtab1, MACEtab2);
- chomp3(ctx,(pkt >> 3) & 3, MACEtab3, MACEtab4);
- chomp3(ctx, pkt >> 5 , MACEtab1, MACEtab2);
-
- inBuffer+=numChannels*2;
- --cnt;
- }
-
-/*
- if (outState) {
- outState[0]=ctx->index;
- outState[1]=ctx->lev;
- }
-*/
-}
-/* \\\ */
-
-/* /// "chomp6()" */
-static void chomp6(MACEContext *ctx,
- uint8_t val,
- const uint16_t tab1[],
- const uint16_t tab2[][8])
-{
- short current;
-
- current=(short)tab2[(ctx->index & 0x7f0) >> 4][val];
-
- if ((ctx->previous^current)>=0) {
- if (ctx->factor+506>32767) ctx->factor=32767;
- else ctx->factor+=506;
- } else {
- if (ctx->factor-314<-32768) ctx->factor=-32767;
- else ctx->factor-=314;
- }
-
- if (current+ctx->level>32767) current=32767;
- else if (current+ctx->level<-32768) current=-32767;
- else current+=ctx->level;
-
- ctx->level=((current*ctx->factor) >> 15);
- current>>=1;
-
-// *ctx->outPtr++=(ctx->previous+ctx->prev2-((ctx->prev2-current) >> 2)) >> 8;
-// *ctx->outPtr++=(ctx->previous+current+((ctx->prev2-current) >> 2)) >> 8;
- *ctx->outPtr++=(ctx->previous+ctx->prev2-((ctx->prev2-current) >> 2));
- *ctx->outPtr++=(ctx->previous+current+((ctx->prev2-current) >> 2));
-
- ctx->prev2=ctx->previous;
- ctx->previous=current;
-
- if( ( ctx->index += tab1[val]-(ctx->index>>5) ) < 0 ) ctx->index = 0;
-}
-/* \\\ */
-
-/* /// "Exp1to6()" */
-static void Exp1to6(MACEContext *ctx,
- uint8_t *inBuffer,
- void *outBuffer,
- uint32_t cnt,
- uint32_t numChannels,
- uint32_t whichChannel)
-{
- uint8_t pkt;
-
-/*
- if (inState) {
- ctx->previous=inState[0];
- ctx->prev2=inState[1];
- ctx->index=inState[2];
- ctx->level=inState[3];
- ctx->factor=inState[4];
- } else
-*/
- ctx->previous=ctx->prev2=ctx->index=ctx->level=ctx->factor=0;
-
- inBuffer+=(whichChannel-1);
- ctx->outPtr=outBuffer;
-
- while (cnt>0) {
- pkt=*inBuffer;
-
- chomp6(ctx, pkt >> 5 , MACEtab1, MACEtab2);
- chomp6(ctx,(pkt >> 3) & 3, MACEtab3, MACEtab4);
- chomp6(ctx, pkt & 7, MACEtab1, MACEtab2);
-
- inBuffer+=numChannels;
- --cnt;
- }
-
-/*
- if (outState) {
- outState[0]=ctx->previous;
- outState[1]=ctx->prev2;
- outState[2]=ctx->index;
- outState[3]=ctx->level;
- outState[4]=ctx->factor;
- }
-*/
-}
-/* \\\ */
-
-static int mace_decode_init(AVCodecContext * avctx)
-{
- if (avctx->channels > 2)
- return -1;
- return 0;
-}
-
-static int mace_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- short *samples;
- MACEContext *c = avctx->priv_data;
-
- samples = (short *)data;
- switch (avctx->codec->id) {
- case CODEC_ID_MACE3:
-#ifdef DEBUG
-puts("mace_decode_frame[3]()");
-#endif
- Exp1to3(c, buf, samples, buf_size / 2, avctx->channels, 1);
- if (avctx->channels == 2)
- Exp1to3(c, buf, samples+1, buf_size / 2, 2, 2);
- *data_size = 2 * 3 * buf_size;
- break;
- case CODEC_ID_MACE6:
-#ifdef DEBUG
-puts("mace_decode_frame[6]()");
-#endif
- Exp1to6(c, buf, samples, buf_size, avctx->channels, 1);
- if (avctx->channels == 2)
- Exp1to6(c, buf, samples+1, buf_size, 2, 2);
- *data_size = 2 * 6 * buf_size;
- break;
- default:
- *data_size = 0;
- return -1;
- }
- return buf_size;
-}
-
-AVCodec mace3_decoder = {
- "mace3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MACE3,
- sizeof(MACEContext),
- mace_decode_init,
- NULL,
- NULL,
- mace_decode_frame,
-};
-
-AVCodec mace6_decoder = {
- "mace6",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MACE6,
- sizeof(MACEContext),
- mace_decode_init,
- NULL,
- NULL,
- mace_decode_frame,
-};
-
+++ /dev/null
-/*
- * MDCT/IMDCT transforms
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "dsputil.h"
-
-/**
- * @file mdct.c
- * MDCT/IMDCT transforms.
- */
-
-/**
- * init MDCT or IMDCT computation.
- */
-int ff_mdct_init(MDCTContext *s, int nbits, int inverse)
-{
- int n, n4, i;
- float alpha;
-
- memset(s, 0, sizeof(*s));
- n = 1 << nbits;
- s->nbits = nbits;
- s->n = n;
- n4 = n >> 2;
- s->tcos = av_malloc(n4 * sizeof(FFTSample));
- if (!s->tcos)
- goto fail;
- s->tsin = av_malloc(n4 * sizeof(FFTSample));
- if (!s->tsin)
- goto fail;
-
- for(i=0;i<n4;i++) {
- alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;
- s->tcos[i] = -cos(alpha);
- s->tsin[i] = -sin(alpha);
- }
- if (fft_init(&s->fft, s->nbits - 2, inverse) < 0)
- goto fail;
- return 0;
- fail:
- av_freep(&s->tcos);
- av_freep(&s->tsin);
- return -1;
-}
-
-/* complex multiplication: p = a * b */
-#define CMUL(pre, pim, are, aim, bre, bim) \
-{\
- float _are = (are);\
- float _aim = (aim);\
- float _bre = (bre);\
- float _bim = (bim);\
- (pre) = _are * _bre - _aim * _bim;\
- (pim) = _are * _bim + _aim * _bre;\
-}
-
-/**
- * Compute inverse MDCT of size N = 2^nbits
- * @param output N samples
- * @param input N/2 samples
- * @param tmp N/2 samples
- */
-void ff_imdct_calc(MDCTContext *s, FFTSample *output,
- const FFTSample *input, FFTSample *tmp)
-{
- int k, n8, n4, n2, n, j;
- const uint16_t *revtab = s->fft.revtab;
- const FFTSample *tcos = s->tcos;
- const FFTSample *tsin = s->tsin;
- const FFTSample *in1, *in2;
- FFTComplex *z = (FFTComplex *)tmp;
-
- n = 1 << s->nbits;
- n2 = n >> 1;
- n4 = n >> 2;
- n8 = n >> 3;
-
- /* pre rotation */
- in1 = input;
- in2 = input + n2 - 1;
- for(k = 0; k < n4; k++) {
- j=revtab[k];
- CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]);
- in1 += 2;
- in2 -= 2;
- }
- fft_calc(&s->fft, z);
-
- /* post rotation + reordering */
- /* XXX: optimize */
- for(k = 0; k < n4; k++) {
- CMUL(z[k].re, z[k].im, z[k].re, z[k].im, tcos[k], tsin[k]);
- }
- for(k = 0; k < n8; k++) {
- output[2*k] = -z[n8 + k].im;
- output[n2-1-2*k] = z[n8 + k].im;
-
- output[2*k+1] = z[n8-1-k].re;
- output[n2-1-2*k-1] = -z[n8-1-k].re;
-
- output[n2 + 2*k]=-z[k+n8].re;
- output[n-1- 2*k]=-z[k+n8].re;
-
- output[n2 + 2*k+1]=z[n8-k-1].im;
- output[n-2 - 2 * k] = z[n8-k-1].im;
- }
-}
-
-/**
- * Compute MDCT of size N = 2^nbits
- * @param input N samples
- * @param out N/2 samples
- * @param tmp temporary storage of N/2 samples
- */
-void ff_mdct_calc(MDCTContext *s, FFTSample *out,
- const FFTSample *input, FFTSample *tmp)
-{
- int i, j, n, n8, n4, n2, n3;
- FFTSample re, im, re1, im1;
- const uint16_t *revtab = s->fft.revtab;
- const FFTSample *tcos = s->tcos;
- const FFTSample *tsin = s->tsin;
- FFTComplex *x = (FFTComplex *)tmp;
-
- n = 1 << s->nbits;
- n2 = n >> 1;
- n4 = n >> 2;
- n8 = n >> 3;
- n3 = 3 * n4;
-
- /* pre rotation */
- for(i=0;i<n8;i++) {
- re = -input[2*i+3*n4] - input[n3-1-2*i];
- im = -input[n4+2*i] + input[n4-1-2*i];
- j = revtab[i];
- CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]);
-
- re = input[2*i] - input[n2-1-2*i];
- im = -(input[n2+2*i] + input[n-1-2*i]);
- j = revtab[n8 + i];
- CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]);
- }
-
- fft_calc(&s->fft, x);
-
- /* post rotation */
- for(i=0;i<n4;i++) {
- re = x[i].re;
- im = x[i].im;
- CMUL(re1, im1, re, im, -tsin[i], -tcos[i]);
- out[2*i] = im1;
- out[n2-1-2*i] = re1;
- }
-}
-
-void ff_mdct_end(MDCTContext *s)
-{
- av_freep(&s->tcos);
- av_freep(&s->tsin);
- fft_end(&s->fft);
-}
+++ /dev/null
-/*
- * PSX MDEC codec
- * Copyright (c) 2003 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * based upon code from Sebastian Jedruszkiewicz <elf@frogger.rules.pl>
- */
-
-/**
- * @file mdec.c
- * PSX MDEC codec.
- * This is very similar to intra only MPEG1.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-typedef struct MDECContext{
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame picture;
- PutBitContext pb;
- GetBitContext gb;
- ScanTable scantable;
- int version;
- int qscale;
- int last_dc[3];
- int mb_width;
- int mb_height;
- int mb_x, mb_y;
- DCTELEM __align8 block[6][64];
- uint16_t __align8 intra_matrix[64];
- int __align8 q_intra_matrix[64];
- uint8_t *bitstream_buffer;
- int bitstream_buffer_size;
- int block_last_index[6];
-} MDECContext;
-
-//very similar to mpeg1
-static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n)
-{
- int level, diff, i, j, run;
- int component;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= a->scantable.permutated;
- const uint16_t *quant_matrix= ff_mpeg1_default_intra_matrix;
- const int qscale= a->qscale;
-
- /* DC coef */
- if(a->version==2){
- block[0]= 2*get_sbits(&a->gb, 10) + 1024;
- }else{
- component = (n <= 3 ? 0 : n - 4 + 1);
- diff = decode_dc(&a->gb, component);
- if (diff >= 0xffff)
- return -1;
- a->last_dc[component]+= diff;
- block[0] = a->last_dc[component]<<3;
- }
-
- i = 0;
- {
- OPEN_READER(re, &a->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &a->gb);
- GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>3;
-// level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1);
- LAST_SKIP_BITS(re, &a->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6);
- UPDATE_CACHE(re, &a->gb);
- level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10);
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= (level*qscale*quant_matrix[j])>>3;
- level= (level-1)|1;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>3;
- level= (level-1)|1;
- }
- }
- if (i > 63){
- fprintf(stderr, "ac-tex damaged at %d %d\n", a->mb_x, a->mb_y);
- return -1;
- }
-
- block[j] = level;
- }
- CLOSE_READER(re, &a->gb);
- }
- a->block_last_index[n] = i;
- return 0;
-}
-
-static inline int decode_mb(MDECContext *a, DCTELEM block[6][64]){
- int i;
- const int block_index[6]= {5,4,0,1,2,3};
-
- a->dsp.clear_blocks(block[0]);
-
- for(i=0; i<6; i++){
- if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0)
- return -1;
- }
- return 0;
-}
-
-static inline void idct_put(MDECContext *a, int mb_x, int mb_y){
- DCTELEM (*block)[64]= a->block;
- int linesize= a->picture.linesize[0];
-
- uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16;
- uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8;
- uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8;
-
- a->dsp.idct_put(dest_y , linesize, block[0]);
- a->dsp.idct_put(dest_y + 8, linesize, block[1]);
- a->dsp.idct_put(dest_y + 8*linesize , linesize, block[2]);
- a->dsp.idct_put(dest_y + 8*linesize + 8, linesize, block[3]);
-
- if(!(a->avctx->flags&CODEC_FLAG_GRAY)){
- a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]);
- a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]);
- }
-}
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MDECContext * const a = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int i;
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
- p->pict_type= I_TYPE;
- p->key_frame= 1;
- a->last_dc[0]=
- a->last_dc[1]=
- a->last_dc[2]= 0;
-
- a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
- for(i=0; i<buf_size; i+=2){
- a->bitstream_buffer[i] = buf[i+1];
- a->bitstream_buffer[i+1]= buf[i ];
- }
- init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8);
-
- /* skip over 4 preamble bytes in stream (typically 0xXX 0xXX 0x00 0x38) */
- skip_bits(&a->gb, 32);
-
- a->qscale= get_bits(&a->gb, 16);
- a->version= get_bits(&a->gb, 16);
-
- printf("qscale:%d (0x%X), version:%d (0x%X)\n", a->qscale, a->qscale, a->version, a->version);
-
- for(a->mb_x=0; a->mb_x<a->mb_width; a->mb_x++){
- for(a->mb_y=0; a->mb_y<a->mb_height; a->mb_y++){
- if( decode_mb(a, a->block) <0)
- return -1;
-
- idct_put(a, a->mb_x, a->mb_y);
- }
- }
-
-// p->quality= (32 + a->inv_qscale/2)/a->inv_qscale;
-// memset(p->qscale_table, p->quality, p->qstride*a->mb_height);
-
- *picture= *(AVFrame*)&a->picture;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return (get_bits_count(&a->gb)+31)/32*4;
-}
-
-static void mdec_common_init(AVCodecContext *avctx){
- MDECContext * const a = avctx->priv_data;
-
- dsputil_init(&a->dsp, avctx);
-
- a->mb_width = (avctx->width + 15) / 16;
- a->mb_height = (avctx->height + 15) / 16;
-
- avctx->coded_frame= (AVFrame*)&a->picture;
- a->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
- MDECContext * const a = avctx->priv_data;
- AVFrame *p= (AVFrame*)&a->picture;
-
- mdec_common_init(avctx);
- init_vlcs();
- ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct);
-/*
- for(i=0; i<64; i++){
- int index= ff_zigzag_direct[i];
- a->intra_matrix[i]= 64*ff_mpeg1_default_intra_matrix[index] / a->inv_qscale;
- }
-*/
- p->qstride= a->mb_width;
- p->qscale_table= av_mallocz( p->qstride * a->mb_height);
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
- MDECContext * const a = avctx->priv_data;
-
- av_freep(&a->bitstream_buffer);
- av_freep(&a->picture.qscale_table);
- a->bitstream_buffer_size=0;
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec mdec_decoder = {
- "mdec",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MDEC,
- sizeof(MDECContext),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-
+++ /dev/null
-/*
- * default memory allocator for libavcodec
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mem.c
- * default memory allocator for libavcodec.
- */
-
-#include "avcodec.h"
-
-/* here we can use OS dependant allocation functions */
-#undef malloc
-#undef free
-#undef realloc
-
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#endif
-
-/* you can redefine av_malloc and av_free in your project to use your
- memory allocator. You do not need to suppress this file because the
- linker will do it automatically */
-
-/**
- * Memory allocation of size byte with alignment suitable for all
- * memory accesses (including vectors if available on the
- * CPU). av_malloc(0) must return a non NULL pointer.
- */
-void *av_malloc(unsigned int size)
-{
- void *ptr;
-
-#if defined (HAVE_MEMALIGN)
- ptr = memalign(16,size);
- /* Why 64?
- Indeed, we should align it:
- on 4 for 386
- on 16 for 486
- on 32 for 586, PPro - k6-III
- on 64 for K7 (maybe for P3 too).
- Because L1 and L2 caches are aligned on those values.
- But I don't want to code such logic here!
- */
- /* Why 16?
- because some cpus need alignment, for example SSE2 on P4, & most RISC cpus
- it will just trigger an exception and the unaligned load will be done in the
- exception handler or it will just segfault (SSE2 on P4)
- Why not larger? because i didnt see a difference in benchmarks ...
- */
- /* benchmarks with p3
- memalign(64)+1 3071,3051,3032
- memalign(64)+2 3051,3032,3041
- memalign(64)+4 2911,2896,2915
- memalign(64)+8 2545,2554,2550
- memalign(64)+16 2543,2572,2563
- memalign(64)+32 2546,2545,2571
- memalign(64)+64 2570,2533,2558
-
- btw, malloc seems to do 8 byte alignment by default here
- */
-#else
- ptr = malloc(size);
-#endif
- return ptr;
-}
-
-/**
- * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
- * identical to malloc(size). If size is zero, it is identical to
- * free(ptr) and NULL is returned.
- */
-void *av_realloc(void *ptr, unsigned int size)
-{
- return realloc(ptr, size);
-}
-
-/* NOTE: ptr = NULL is explicetly allowed */
-void av_free(void *ptr)
-{
- /* XXX: this test should not be needed on most libcs */
- if (ptr)
- free(ptr);
-}
-
+++ /dev/null
-/*
- * MJPEG encoder and decoder
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Support for external huffman table, various fixes (AVID workaround),
- * aspecting, new decode_frame mechanism and apple mjpeg-b support
- * by Alex Beregszaszi <alex@naxine.org>
- */
-
-/**
- * @file mjpeg.c
- * MJPEG encoder and decoder.
- */
-
-//#define DEBUG
-#include <assert.h>
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-/* use two quantizer tables (one for luminance and one for chrominance) */
-/* not yet working */
-#undef TWOMATRIXES
-
-typedef struct MJpegContext {
- uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chrom, for easier addressing
- uint16_t huff_code_dc_luminance[12];
- uint8_t huff_size_dc_chrominance[12];
- uint16_t huff_code_dc_chrominance[12];
-
- uint8_t huff_size_ac_luminance[256];
- uint16_t huff_code_ac_luminance[256];
- uint8_t huff_size_ac_chrominance[256];
- uint16_t huff_code_ac_chrominance[256];
-} MJpegContext;
-
-/* JPEG marker codes */
-typedef enum {
- /* start of frame */
- SOF0 = 0xc0, /* baseline */
- SOF1 = 0xc1, /* extended sequential, huffman */
- SOF2 = 0xc2, /* progressive, huffman */
- SOF3 = 0xc3, /* lossless, huffman */
-
- SOF5 = 0xc5, /* differential sequential, huffman */
- SOF6 = 0xc6, /* differential progressive, huffman */
- SOF7 = 0xc7, /* differential lossless, huffman */
- JPG = 0xc8, /* reserved for JPEG extension */
- SOF9 = 0xc9, /* extended sequential, arithmetic */
- SOF10 = 0xca, /* progressive, arithmetic */
- SOF11 = 0xcb, /* lossless, arithmetic */
-
- SOF13 = 0xcd, /* differential sequential, arithmetic */
- SOF14 = 0xce, /* differential progressive, arithmetic */
- SOF15 = 0xcf, /* differential lossless, arithmetic */
-
- DHT = 0xc4, /* define huffman tables */
-
- DAC = 0xcc, /* define arithmetic-coding conditioning */
-
- /* restart with modulo 8 count "m" */
- RST0 = 0xd0,
- RST1 = 0xd1,
- RST2 = 0xd2,
- RST3 = 0xd3,
- RST4 = 0xd4,
- RST5 = 0xd5,
- RST6 = 0xd6,
- RST7 = 0xd7,
-
- SOI = 0xd8, /* start of image */
- EOI = 0xd9, /* end of image */
- SOS = 0xda, /* start of scan */
- DQT = 0xdb, /* define quantization tables */
- DNL = 0xdc, /* define number of lines */
- DRI = 0xdd, /* define restart interval */
- DHP = 0xde, /* define hierarchical progression */
- EXP = 0xdf, /* expand reference components */
-
- APP0 = 0xe0,
- APP1 = 0xe1,
- APP2 = 0xe2,
- APP3 = 0xe3,
- APP4 = 0xe4,
- APP5 = 0xe5,
- APP6 = 0xe6,
- APP7 = 0xe7,
- APP8 = 0xe8,
- APP9 = 0xe9,
- APP10 = 0xea,
- APP11 = 0xeb,
- APP12 = 0xec,
- APP13 = 0xed,
- APP14 = 0xee,
- APP15 = 0xef,
-
- JPG0 = 0xf0,
- JPG1 = 0xf1,
- JPG2 = 0xf2,
- JPG3 = 0xf3,
- JPG4 = 0xf4,
- JPG5 = 0xf5,
- JPG6 = 0xf6,
- JPG7 = 0xf7,
- JPG8 = 0xf8,
- JPG9 = 0xf9,
- JPG10 = 0xfa,
- JPG11 = 0xfb,
- JPG12 = 0xfc,
- JPG13 = 0xfd,
-
- COM = 0xfe, /* comment */
-
- TEM = 0x01, /* temporary private use for arithmetic coding */
-
- /* 0x02 -> 0xbf reserved */
-} JPEG_MARKER;
-
-#if 0
-/* These are the sample quantization tables given in JPEG spec section K.1.
- * The spec says that the values given produce "good" quality, and
- * when divided by 2, "very good" quality.
- */
-static const unsigned char std_luminance_quant_tbl[64] = {
- 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 56, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99
-};
-static const unsigned char std_chrominance_quant_tbl[64] = {
- 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
-};
-#endif
-
-/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
-/* IMPORTANT: these are only valid for 8-bit data precision! */
-static const uint8_t bits_dc_luminance[17] =
-{ /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
-static const uint8_t val_dc_luminance[] =
-{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
-static const uint8_t bits_dc_chrominance[17] =
-{ /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
-static const uint8_t val_dc_chrominance[] =
-{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
-static const uint8_t bits_ac_luminance[17] =
-{ /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
-static const uint8_t val_ac_luminance[] =
-{ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
- 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
- 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
- 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
- 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
- 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
- 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
- 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
- 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
- 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
- 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
- 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
- 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
- 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
- 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
- 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa
-};
-
-static const uint8_t bits_ac_chrominance[17] =
-{ /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
-
-static const uint8_t val_ac_chrominance[] =
-{ 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
- 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
- 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
- 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
- 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
- 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
- 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
- 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
- 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
- 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
- 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
- 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
- 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
- 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
- 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
- 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa
-};
-
-/* isn't this function nicer than the one in the libjpeg ? */
-static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
- const uint8_t *bits_table, const uint8_t *val_table)
-{
- int i, j, k,nb, code, sym;
-
- code = 0;
- k = 0;
- for(i=1;i<=16;i++) {
- nb = bits_table[i];
- for(j=0;j<nb;j++) {
- sym = val_table[k++];
- huff_size[sym] = i;
- huff_code[sym] = code;
- code++;
- }
- code <<= 1;
- }
-}
-
-int mjpeg_init(MpegEncContext *s)
-{
- MJpegContext *m;
-
- m = av_malloc(sizeof(MJpegContext));
- if (!m)
- return -1;
-
- s->min_qcoeff=-1023;
- s->max_qcoeff= 1023;
-
- /* build all the huffman tables */
- build_huffman_codes(m->huff_size_dc_luminance,
- m->huff_code_dc_luminance,
- bits_dc_luminance,
- val_dc_luminance);
- build_huffman_codes(m->huff_size_dc_chrominance,
- m->huff_code_dc_chrominance,
- bits_dc_chrominance,
- val_dc_chrominance);
- build_huffman_codes(m->huff_size_ac_luminance,
- m->huff_code_ac_luminance,
- bits_ac_luminance,
- val_ac_luminance);
- build_huffman_codes(m->huff_size_ac_chrominance,
- m->huff_code_ac_chrominance,
- bits_ac_chrominance,
- val_ac_chrominance);
-
- s->mjpeg_ctx = m;
- return 0;
-}
-
-void mjpeg_close(MpegEncContext *s)
-{
- av_free(s->mjpeg_ctx);
-}
-
-#define PREDICT(ret, topleft, top, left, predictor)\
- switch(predictor){\
- case 1: ret= left; break;\
- case 2: ret= top; break;\
- case 3: ret= topleft; break;\
- case 4: ret= left + top - topleft; break;\
- case 5: ret= left + ((top - topleft)>>1); break;\
- case 6: ret= top + ((left - topleft)>>1); break;\
- default:\
- case 7: ret= (left + top)>>1; break;\
- }
-
-#ifdef CONFIG_ENCODERS
-static inline void put_marker(PutBitContext *p, int code)
-{
- put_bits(p, 8, 0xff);
- put_bits(p, 8, code);
-}
-
-/* table_class: 0 = DC coef, 1 = AC coefs */
-static int put_huffman_table(MpegEncContext *s, int table_class, int table_id,
- const uint8_t *bits_table, const uint8_t *value_table)
-{
- PutBitContext *p = &s->pb;
- int n, i;
-
- put_bits(p, 4, table_class);
- put_bits(p, 4, table_id);
-
- n = 0;
- for(i=1;i<=16;i++) {
- n += bits_table[i];
- put_bits(p, 8, bits_table[i]);
- }
-
- for(i=0;i<n;i++)
- put_bits(p, 8, value_table[i]);
-
- return n + 17;
-}
-
-static void jpeg_table_header(MpegEncContext *s)
-{
- PutBitContext *p = &s->pb;
- int i, j, size;
- uint8_t *ptr;
-
- /* quant matrixes */
- put_marker(p, DQT);
-#ifdef TWOMATRIXES
- put_bits(p, 16, 2 + 2 * (1 + 64));
-#else
- put_bits(p, 16, 2 + 1 * (1 + 64));
-#endif
- put_bits(p, 4, 0); /* 8 bit precision */
- put_bits(p, 4, 0); /* table 0 */
- for(i=0;i<64;i++) {
- j = s->intra_scantable.permutated[i];
- put_bits(p, 8, s->intra_matrix[j]);
- }
-#ifdef TWOMATRIXES
- put_bits(p, 4, 0); /* 8 bit precision */
- put_bits(p, 4, 1); /* table 1 */
- for(i=0;i<64;i++) {
- j = s->intra_scantable.permutated[i];
- put_bits(p, 8, s->chroma_intra_matrix[j]);
- }
-#endif
-
- /* huffman table */
- put_marker(p, DHT);
- flush_put_bits(p);
- ptr = pbBufPtr(p);
- put_bits(p, 16, 0); /* patched later */
- size = 2;
- size += put_huffman_table(s, 0, 0, bits_dc_luminance, val_dc_luminance);
- size += put_huffman_table(s, 0, 1, bits_dc_chrominance, val_dc_chrominance);
-
- size += put_huffman_table(s, 1, 0, bits_ac_luminance, val_ac_luminance);
- size += put_huffman_table(s, 1, 1, bits_ac_chrominance, val_ac_chrominance);
- ptr[0] = size >> 8;
- ptr[1] = size;
-}
-
-static void jpeg_put_comments(MpegEncContext *s)
-{
- PutBitContext *p = &s->pb;
- int size;
- uint8_t *ptr;
-
- if (s->aspect_ratio_info /* && !lossless */)
- {
- /* JFIF header */
- put_marker(p, APP0);
- put_bits(p, 16, 16);
- put_string(p, "JFIF"); /* this puts the trailing zero-byte too */
- put_bits(p, 16, 0x0201); /* v 1.02 */
- put_bits(p, 8, 0); /* units type: 0 - aspect ratio */
- switch(s->aspect_ratio_info)
- {
- case FF_ASPECT_4_3_625:
- case FF_ASPECT_4_3_525:
- put_bits(p, 16, 4);
- put_bits(p, 16, 3);
- break;
- case FF_ASPECT_16_9_625:
- case FF_ASPECT_16_9_525:
- put_bits(p, 16, 16);
- put_bits(p, 16, 9);
- break;
- case FF_ASPECT_EXTENDED:
- put_bits(p, 16, s->aspected_width);
- put_bits(p, 16, s->aspected_height);
- break;
- case FF_ASPECT_SQUARE:
- default:
- put_bits(p, 16, 1); /* aspect: 1:1 */
- put_bits(p, 16, 1);
- break;
- }
- put_bits(p, 8, 0); /* thumbnail width */
- put_bits(p, 8, 0); /* thumbnail height */
- }
-
- /* comment */
- if(!(s->flags & CODEC_FLAG_BITEXACT)){
- put_marker(p, COM);
- flush_put_bits(p);
- ptr = pbBufPtr(p);
- put_bits(p, 16, 0); /* patched later */
- put_string(p, LIBAVCODEC_IDENT);
- size = strlen(LIBAVCODEC_IDENT)+3;
- ptr[0] = size >> 8;
- ptr[1] = size;
- }
-}
-
-void mjpeg_picture_header(MpegEncContext *s)
-{
- const int lossless= s->avctx->codec_id == CODEC_ID_LJPEG;
-
- put_marker(&s->pb, SOI);
-
- if (!s->mjpeg_data_only_frames)
- {
- jpeg_put_comments(s);
-
- if (s->mjpeg_write_tables) jpeg_table_header(s);
-
- put_marker(&s->pb, lossless ? SOF3 : SOF0);
-
- put_bits(&s->pb, 16, 17);
- if(lossless && s->avctx->pix_fmt == PIX_FMT_RGBA32)
- put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */
- else
- put_bits(&s->pb, 8, 8); /* 8 bits/component */
- put_bits(&s->pb, 16, s->height);
- put_bits(&s->pb, 16, s->width);
- put_bits(&s->pb, 8, 3); /* 3 components */
-
- /* Y component */
- put_bits(&s->pb, 8, 1); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */
- put_bits(&s->pb, 8, 0); /* select matrix */
-
- /* Cb component */
- put_bits(&s->pb, 8, 2); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */
-#ifdef TWOMATRIXES
- put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
-#else
- put_bits(&s->pb, 8, 0); /* select matrix */
-#endif
-
- /* Cr component */
- put_bits(&s->pb, 8, 3); /* component number */
- put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */
- put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */
-#ifdef TWOMATRIXES
- put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */
-#else
- put_bits(&s->pb, 8, 0); /* select matrix */
-#endif
- }
-
- /* scan header */
- put_marker(&s->pb, SOS);
- put_bits(&s->pb, 16, 12); /* length */
- put_bits(&s->pb, 8, 3); /* 3 components */
-
- /* Y component */
- put_bits(&s->pb, 8, 1); /* index */
- put_bits(&s->pb, 4, 0); /* DC huffman table index */
- put_bits(&s->pb, 4, 0); /* AC huffman table index */
-
- /* Cb component */
- put_bits(&s->pb, 8, 2); /* index */
- put_bits(&s->pb, 4, 1); /* DC huffman table index */
- put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
-
- /* Cr component */
- put_bits(&s->pb, 8, 3); /* index */
- put_bits(&s->pb, 4, 1); /* DC huffman table index */
- put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */
-
- put_bits(&s->pb, 8, lossless ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */
- put_bits(&s->pb, 8, lossless ? 0 : 63); /* Se (not used) */
- put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
-}
-
-static void escape_FF(MpegEncContext *s, int start)
-{
- int size= get_bit_count(&s->pb) - start*8;
- int i, ff_count;
- uint8_t *buf= s->pb.buf + start;
- int align= (-(size_t)(buf))&3;
-
- assert((size&7) == 0);
- size >>= 3;
-
- ff_count=0;
- for(i=0; i<size && i<align; i++){
- if(buf[i]==0xFF) ff_count++;
- }
- for(; i<size-15; i+=16){
- int acc, v;
-
- v= *(uint32_t*)(&buf[i]);
- acc= (((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+4]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+8]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
- v= *(uint32_t*)(&buf[i+12]);
- acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010;
-
- acc>>=4;
- acc+= (acc>>16);
- acc+= (acc>>8);
- ff_count+= acc&0xFF;
- }
- for(; i<size; i++){
- if(buf[i]==0xFF) ff_count++;
- }
-
- if(ff_count==0) return;
-
- /* skip put bits */
- for(i=0; i<ff_count-3; i+=4)
- put_bits(&s->pb, 32, 0);
- put_bits(&s->pb, (ff_count-i)*8, 0);
- flush_put_bits(&s->pb);
-
- for(i=size-1; ff_count; i--){
- int v= buf[i];
-
- if(v==0xFF){
-//printf("%d %d\n", i, ff_count);
- buf[i+ff_count]= 0;
- ff_count--;
- }
-
- buf[i+ff_count]= v;
- }
-}
-
-void mjpeg_picture_trailer(MpegEncContext *s)
-{
- int pad= (-get_bit_count(&s->pb))&7;
-
- put_bits(&s->pb, pad,0xFF>>(8-pad));
- flush_put_bits(&s->pb);
-
- assert((s->header_bits&7)==0);
-
- escape_FF(s, s->header_bits>>3);
-
- put_marker(&s->pb, EOI);
-}
-
-static inline void mjpeg_encode_dc(MpegEncContext *s, int val,
- uint8_t *huff_size, uint16_t *huff_code)
-{
- int mant, nbits;
-
- if (val == 0) {
- put_bits(&s->pb, huff_size[0], huff_code[0]);
- } else {
- mant = val;
- if (val < 0) {
- val = -val;
- mant--;
- }
-
- nbits= av_log2_16bit(val) + 1;
-
- put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
-
- put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
- }
-}
-
-static void encode_block(MpegEncContext *s, DCTELEM *block, int n)
-{
- int mant, nbits, code, i, j;
- int component, dc, run, last_index, val;
- MJpegContext *m = s->mjpeg_ctx;
- uint8_t *huff_size_ac;
- uint16_t *huff_code_ac;
-
- /* DC coef */
- component = (n <= 3 ? 0 : n - 4 + 1);
- dc = block[0]; /* overflow is impossible */
- val = dc - s->last_dc[component];
- if (n < 4) {
- mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance);
- huff_size_ac = m->huff_size_ac_luminance;
- huff_code_ac = m->huff_code_ac_luminance;
- } else {
- mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- huff_size_ac = m->huff_size_ac_chrominance;
- huff_code_ac = m->huff_code_ac_chrominance;
- }
- s->last_dc[component] = dc;
-
- /* AC coefs */
-
- run = 0;
- last_index = s->block_last_index[n];
- for(i=1;i<=last_index;i++) {
- j = s->intra_scantable.permutated[i];
- val = block[j];
- if (val == 0) {
- run++;
- } else {
- while (run >= 16) {
- put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]);
- run -= 16;
- }
- mant = val;
- if (val < 0) {
- val = -val;
- mant--;
- }
-
- nbits= av_log2(val) + 1;
- code = (run << 4) | nbits;
-
- put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
-
- put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
- run = 0;
- }
- }
-
- /* output EOB only if not already 64 values */
- if (last_index < 63 || run != 0)
- put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]);
-}
-
-void mjpeg_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64])
-{
- int i;
- for(i=0;i<6;i++) {
- encode_block(s, block[i], i);
- }
-}
-
-static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- MpegEncContext * const s = avctx->priv_data;
- MJpegContext * const m = s->mjpeg_ctx;
- AVFrame *pict = data;
- const int width= s->width;
- const int height= s->height;
- AVFrame * const p= (AVFrame*)&s->current_picture;
- const int predictor= avctx->prediction_method+1;
-
- init_put_bits(&s->pb, buf, buf_size, NULL, NULL);
-
- *p = *pict;
- p->pict_type= FF_I_TYPE;
- p->key_frame= 1;
-
- mjpeg_picture_header(s);
-
- s->header_bits= get_bit_count(&s->pb);
-
- if(avctx->pix_fmt == PIX_FMT_RGBA32){
- int x, y, i;
- const int linesize= p->linesize[0];
- uint16_t buffer[2048][4];
- int left[3], top[3], topleft[3];
-
- for(i=0; i<3; i++){
- buffer[0][i]= 1 << (9 - 1);
- }
-
- for(y = 0; y < height; y++) {
- const int modified_predictor= y ? predictor : 1;
- uint8_t *ptr = p->data[0] + (linesize * y);
-
- for(i=0; i<3; i++){
- top[i]= left[i]= topleft[i]= buffer[0][i];
- }
- for(x = 0; x < width; x++) {
- buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100;
- buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100;
- buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2;
-
- for(i=0;i<3;i++) {
- int pred, diff;
-
- PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
-
- topleft[i]= top[i];
- top[i]= buffer[x+1][i];
-
- left[i]= buffer[x][i];
-
- diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100;
-
- if(i==0)
- mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }else{
- int mb_x, mb_y, i;
- const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0];
- const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0];
-
- for(mb_y = 0; mb_y < mb_height; mb_y++) {
- for(mb_x = 0; mb_x < mb_width; mb_x++) {
- if(mb_x==0 || mb_y==0){
- for(i=0;i<3;i++) {
- uint8_t *ptr;
- int x, y, h, v, linesize;
- h = s->mjpeg_hsample[i];
- v = s->mjpeg_vsample[i];
- linesize= p->linesize[i];
-
- for(y=0; y<v; y++){
- for(x=0; x<h; x++){
- int pred;
-
- ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- if(y==0 && mb_y==0){
- if(x==0 && mb_x==0){
- pred= 128;
- }else{
- pred= ptr[-1];
- }
- }else{
- if(x==0 && mb_x==0){
- pred= ptr[-linesize];
- }else{
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- }
- }
-
- if(i==0)
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }else{
- for(i=0;i<3;i++) {
- uint8_t *ptr;
- int x, y, h, v, linesize;
- h = s->mjpeg_hsample[i];
- v = s->mjpeg_vsample[i];
- linesize= p->linesize[i];
-
- for(y=0; y<v; y++){
- for(x=0; x<h; x++){
- int pred;
-
- ptr = p->data[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
-//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr);
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
-
- if(i==0)
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly
- else
- mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance);
- }
- }
- }
- }
- }
- }
- }
-
- emms_c();
-
- mjpeg_picture_trailer(s);
- s->picture_number++;
-
- flush_put_bits(&s->pb);
- return pbBufPtr(&s->pb) - s->pb.buf;
-// return (get_bit_count(&f->pb)+7)/8;
-}
-
-#endif //CONFIG_ENCODERS
-
-/******************************************/
-/* decoding */
-
-#define MAX_COMPONENTS 4
-
-typedef struct MJpegDecodeContext {
- AVCodecContext *avctx;
- GetBitContext gb;
- int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
-
- int start_code; /* current start code */
- int buffer_size;
- uint8_t *buffer;
-
- int16_t quant_matrixes[4][64];
- VLC vlcs[2][4];
- int qscale[4]; ///< quantizer scale calculated from quant_matrixes
-
- int org_width, org_height; /* size given at codec init */
- int first_picture; /* true if decoding first picture */
- int interlaced; /* true if interlaced */
- int bottom_field; /* true if bottom field */
- int lossless;
- int rgb;
- int rct; /* standard rct */
- int pegasus_rct; /* pegasus reversible colorspace transform */
- int bits; /* bits per component */
-
- int width, height;
- int mb_width, mb_height;
- int nb_components;
- int component_id[MAX_COMPONENTS];
- int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
- int v_count[MAX_COMPONENTS];
- int comp_index[MAX_COMPONENTS];
- int dc_index[MAX_COMPONENTS];
- int ac_index[MAX_COMPONENTS];
- int nb_blocks[MAX_COMPONENTS];
- int h_scount[MAX_COMPONENTS];
- int v_scount[MAX_COMPONENTS];
- int h_max, v_max; /* maximum h and v counts */
- int quant_index[4]; /* quant table index for each component */
- int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
- uint8_t *current_picture[MAX_COMPONENTS]; /* picture structure */
- int linesize[MAX_COMPONENTS];
- uint8_t *qscale_table;
- DCTELEM block[64] __align8;
- ScanTable scantable;
- void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
-
- int restart_interval;
- int restart_count;
-
- int buggy_avid;
- int interlace_polarity;
-} MJpegDecodeContext;
-
-static int mjpeg_decode_dht(MJpegDecodeContext *s);
-
-static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
- int nb_codes)
-{
- uint8_t huff_size[256];
- uint16_t huff_code[256];
-
- memset(huff_size, 0, sizeof(huff_size));
- build_huffman_codes(huff_size, huff_code, bits_table, val_table);
-
- return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2);
-}
-
-static int mjpeg_decode_init(AVCodecContext *avctx)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- MpegEncContext s2;
-
- s->avctx = avctx;
-
- /* ugly way to get the idct & scantable FIXME */
- memset(&s2, 0, sizeof(MpegEncContext));
- s2.flags= avctx->flags;
- s2.avctx= avctx;
-// s2->out_format = FMT_MJPEG;
- s2.width = 8;
- s2.height = 8;
- if (MPV_common_init(&s2) < 0)
- return -1;
- s->scantable= s2.intra_scantable;
- s->idct_put= s2.dsp.idct_put;
- MPV_common_end(&s2);
-
- s->mpeg_enc_ctx_allocated = 0;
- s->buffer_size = 102400; /* smaller buffer should be enough,
- but photojpg files could ahive bigger sizes */
- s->buffer = av_malloc(s->buffer_size);
- if (!s->buffer)
- return -1;
- s->start_code = -1;
- s->first_picture = 1;
- s->org_width = avctx->width;
- s->org_height = avctx->height;
-
- build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12);
- build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12);
- build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251);
- build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251);
-
- if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
- {
- printf("mjpeg: using external huffman table\n");
- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
- mjpeg_decode_dht(s);
- /* should check for error - but dunno */
- }
-
- return 0;
-}
-
-/* quantize tables */
-static int mjpeg_decode_dqt(MJpegDecodeContext *s)
-{
- int len, index, i, j;
-
- len = get_bits(&s->gb, 16) - 2;
-
- while (len >= 65) {
- /* only 8 bit precision handled */
- if (get_bits(&s->gb, 4) != 0)
- {
- dprintf("dqt: 16bit precision\n");
- return -1;
- }
- index = get_bits(&s->gb, 4);
- if (index >= 4)
- return -1;
- dprintf("index=%d\n", index);
- /* read quant table */
- for(i=0;i<64;i++) {
- j = s->scantable.permutated[i];
- s->quant_matrixes[index][j] = get_bits(&s->gb, 8);
- }
-
- //XXX FIXME finetune, and perhaps add dc too
- s->qscale[index]= FFMAX(
- s->quant_matrixes[index][s->scantable.permutated[1]],
- s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
- len -= 65;
- }
-
- return 0;
-}
-
-/* decode huffman tables and build VLC decoders */
-static int mjpeg_decode_dht(MJpegDecodeContext *s)
-{
- int len, index, i, class, n, v, code_max;
- uint8_t bits_table[17];
- uint8_t val_table[256];
-
- len = get_bits(&s->gb, 16) - 2;
-
- while (len > 0) {
- if (len < 17)
- return -1;
- class = get_bits(&s->gb, 4);
- if (class >= 2)
- return -1;
- index = get_bits(&s->gb, 4);
- if (index >= 4)
- return -1;
- n = 0;
- for(i=1;i<=16;i++) {
- bits_table[i] = get_bits(&s->gb, 8);
- n += bits_table[i];
- }
- len -= 17;
- if (len < n || n > 256)
- return -1;
-
- code_max = 0;
- for(i=0;i<n;i++) {
- v = get_bits(&s->gb, 8);
- if (v > code_max)
- code_max = v;
- val_table[i] = v;
- }
- len -= n;
-
- /* build VLC and flush previous vlc if present */
- free_vlc(&s->vlcs[class][index]);
- dprintf("class=%d index=%d nb_codes=%d\n",
- class, index, code_max + 1);
- if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1) < 0){
- return -1;
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_sof(MJpegDecodeContext *s)
-{
- int len, nb_components, i, width, height;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- s->bits= get_bits(&s->gb, 8);
-
- if(s->pegasus_rct) s->bits=9;
- if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly
-
- if (s->bits != 8 && !s->lossless){
- printf("only 8 bits/component accepted\n");
- return -1;
- }
- height = get_bits(&s->gb, 16);
- width = get_bits(&s->gb, 16);
- dprintf("sof0: picture: %dx%d\n", width, height);
-
- nb_components = get_bits(&s->gb, 8);
- if (nb_components <= 0 ||
- nb_components > MAX_COMPONENTS)
- return -1;
- s->nb_components = nb_components;
- s->h_max = 1;
- s->v_max = 1;
- for(i=0;i<nb_components;i++) {
- /* component id */
- s->component_id[i] = get_bits(&s->gb, 8) - 1;
- s->h_count[i] = get_bits(&s->gb, 4);
- s->v_count[i] = get_bits(&s->gb, 4);
- /* compute hmax and vmax (only used in interleaved case) */
- if (s->h_count[i] > s->h_max)
- s->h_max = s->h_count[i];
- if (s->v_count[i] > s->v_max)
- s->v_max = s->v_count[i];
- s->quant_index[i] = get_bits(&s->gb, 8);
- if (s->quant_index[i] >= 4)
- return -1;
- dprintf("component %d %d:%d id: %d quant:%d\n", i, s->h_count[i],
- s->v_count[i], s->component_id[i], s->quant_index[i]);
- }
-
- if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1;
-
- /* if different size, realloc/alloc picture */
- /* XXX: also check h_count and v_count */
- if (width != s->width || height != s->height) {
- for(i=0;i<MAX_COMPONENTS;i++)
- av_freep(&s->current_picture[i]);
-
- av_freep(&s->qscale_table);
-
- s->width = width;
- s->height = height;
- /* test interlaced mode */
- if (s->first_picture &&
- s->org_height != 0 &&
- s->height < ((s->org_height * 3) / 4)) {
- s->interlaced = 1;
-// s->bottom_field = (s->interlace_polarity) ? 1 : 0;
- s->bottom_field = 0;
- }
-
- if(s->rgb){
- int w, h;
- w = s->width;
- h = s->height;
- if (s->interlaced)
- w *= 2;
- s->linesize[0] = 4*w;
- s->current_picture[0] = av_mallocz(4*w * h);
- s->current_picture[1] = s->current_picture[2] = NULL;
- }else{
- for(i=0;i<nb_components;i++) {
- int w, h;
- w = (s->width + 8 * s->h_max - 1) / (8 * s->h_max);
- h = (s->height + 8 * s->v_max - 1) / (8 * s->v_max);
- w = w * 8 * s->h_count[i];
- h = h * 8 * s->v_count[i];
- if (s->interlaced)
- w *= 2;
- s->linesize[i] = w;
- s->current_picture[i] = av_mallocz(w * h);
- if (!s->current_picture[i])
- {
- dprintf("error: no picture buffers allocated\n");
- return -1;
- }
- }
- }
- s->qscale_table= av_mallocz((s->width+15)/16);
-
- s->first_picture = 0;
- }
-
- if (len != (8+(3*nb_components)))
- {
- dprintf("decode_sof0: error, len(%d) mismatch\n", len);
- }
-
- return 0;
-}
-
-static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
-{
- int code;
- code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
- if (code < 0)
- {
- dprintf("mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index,
- &s->vlcs[0][dc_index]);
- return 0xffff;
- }
-
- if(code)
- return get_xbits(&s->gb, code);
- else
- return 0;
-}
-
-/* decode block and dequantize */
-static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
- int component, int dc_index, int ac_index, int quant_index)
-{
- int code, i, j, level, val;
- VLC *ac_vlc;
- int16_t *quant_matrix;
-
- /* DC coef */
- val = mjpeg_decode_dc(s, dc_index);
- if (val == 0xffff) {
- dprintf("error dc\n");
- return -1;
- }
- quant_matrix = s->quant_matrixes[quant_index];
- val = val * quant_matrix[0] + s->last_dc[component];
- s->last_dc[component] = val;
- block[0] = val;
- /* AC coefs */
- ac_vlc = &s->vlcs[1][ac_index];
- i = 1;
- for(;;) {
- code = get_vlc2(&s->gb, s->vlcs[1][ac_index].table, 9, 2);
-
- if (code < 0) {
- dprintf("error ac\n");
- return -1;
- }
- /* EOB */
- if (code == 0)
- break;
- if (code == 0xf0) {
- i += 16;
- } else {
- level = get_xbits(&s->gb, code & 0xf);
- i += code >> 4;
- if (i >= 64) {
- dprintf("error count: %d\n", i);
- return -1;
- }
- j = s->scantable.permutated[i];
- block[j] = level * quant_matrix[j];
- i++;
- if (i >= 64)
- break;
- }
- }
- return 0;
-}
-
-static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
- int i, mb_x, mb_y;
- uint16_t buffer[2048][4];
- int left[3], top[3], topleft[3];
- const int linesize= s->linesize[0];
- const int mask= (1<<s->bits)-1;
-
- for(i=0; i<3; i++){
- buffer[0][i]= 1 << (s->bits + point_transform - 1);
- }
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- const int modified_predictor= mb_y ? predictor : 1;
- uint8_t *ptr = s->current_picture[0] + (linesize * mb_y);
-
- if (s->interlaced && s->bottom_field)
- ptr += linesize >> 1;
-
- for(i=0; i<3; i++){
- top[i]= left[i]= topleft[i]= buffer[0][i];
- }
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- for(i=0;i<3;i++) {
- int pred;
-
- topleft[i]= top[i];
- top[i]= buffer[mb_x][i];
-
- PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
-
- left[i]=
- buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));
- }
-
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
-
- if(s->rct){
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);
- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
- }
- }else if(s->pegasus_rct){
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);
- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
- }
- }else{
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- ptr[4*mb_x+0] = buffer[mb_x][0];
- ptr[4*mb_x+1] = buffer[mb_x][1];
- ptr[4*mb_x+2] = buffer[mb_x][2];
- }
- }
- }
- return 0;
-}
-
-static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){
- int i, mb_x, mb_y;
- const int nb_components=3;
-
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- if(mb_x==0 || mb_y==0 || s->interlaced){
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j, linesize;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- linesize= s->linesize[c];
-
- for(j=0; j<n; j++) {
- int pred;
-
- ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- if(y==0 && mb_y==0){
- if(x==0 && mb_x==0){
- pred= 128 << point_transform;
- }else{
- pred= ptr[-1];
- }
- }else{
- if(x==0 && mb_x==0){
- pred= ptr[-linesize];
- }else{
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- }
- }
-
- if (s->interlaced && s->bottom_field)
- ptr += linesize >> 1;
- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
-
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- }else{
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j, linesize;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- linesize= s->linesize[c];
-
- for(j=0; j<n; j++) {
- int pred;
-
- ptr = s->current_picture[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- }
- if (s->restart_interval && !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- }
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_scan(MJpegDecodeContext *s){
- int i, mb_x, mb_y;
- const int nb_components=3;
-
- for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
- for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (s->restart_interval && !s->restart_count)
- s->restart_count = s->restart_interval;
-
- for(i=0;i<nb_components;i++) {
- uint8_t *ptr;
- int n, h, v, x, y, c, j;
- n = s->nb_blocks[i];
- c = s->comp_index[i];
- h = s->h_scount[i];
- v = s->v_scount[i];
- x = 0;
- y = 0;
- for(j=0;j<n;j++) {
- memset(s->block, 0, sizeof(s->block));
- if (decode_block(s, s->block, i,
- s->dc_index[i], s->ac_index[i],
- s->quant_index[c]) < 0) {
- dprintf("error y=%d x=%d\n", mb_y, mb_x);
- return -1;
- }
-// dprintf("mb: %d %d processed\n", mb_y, mb_x);
- ptr = s->current_picture[c] +
- (s->linesize[c] * (v * mb_y + y) * 8) +
- (h * mb_x + x) * 8;
- if (s->interlaced && s->bottom_field)
- ptr += s->linesize[c] >> 1;
- s->idct_put(ptr, s->linesize[c], s->block);
- if (++x == h) {
- x = 0;
- y++;
- }
- }
- }
- /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */
- if (s->restart_interval && (s->restart_interval < 1350) &&
- !--s->restart_count) {
- align_get_bits(&s->gb);
- skip_bits(&s->gb, 16); /* skip RSTn */
- for (i=0; i<nb_components; i++) /* reset dc */
- s->last_dc[i] = 1024;
- }
- }
- }
- return 0;
-}
-
-static int mjpeg_decode_sos(MJpegDecodeContext *s)
-{
- int len, nb_components, i, h, v, predictor, point_transform;
- int vmax, hmax, index, id;
- const int block_size= s->lossless ? 1 : 8;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- nb_components = get_bits(&s->gb, 8);
- if (len != 6+2*nb_components)
- {
- dprintf("decode_sos: invalid len (%d)\n", len);
- return -1;
- }
- /* XXX: only interleaved scan accepted */
- if (nb_components != 3)
- {
- dprintf("decode_sos: components(%d) mismatch\n", nb_components);
- return -1;
- }
- vmax = 0;
- hmax = 0;
- for(i=0;i<nb_components;i++) {
- id = get_bits(&s->gb, 8) - 1;
- dprintf("component: %d\n", id);
- /* find component index */
- for(index=0;index<s->nb_components;index++)
- if (id == s->component_id[index])
- break;
- if (index == s->nb_components)
- {
- dprintf("decode_sos: index(%d) out of components\n", index);
- return -1;
- }
-
- s->comp_index[i] = index;
-
- s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
- s->h_scount[i] = s->h_count[index];
- s->v_scount[i] = s->v_count[index];
-
- s->dc_index[i] = get_bits(&s->gb, 4);
- s->ac_index[i] = get_bits(&s->gb, 4);
-
- if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
- s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
- goto out_of_range;
-#if 0 //buggy
- switch(s->start_code)
- {
- case SOF0:
- if (dc_index[i] > 1 || ac_index[i] > 1)
- goto out_of_range;
- break;
- case SOF1:
- case SOF2:
- if (dc_index[i] > 3 || ac_index[i] > 3)
- goto out_of_range;
- break;
- case SOF3:
- if (dc_index[i] > 3 || ac_index[i] != 0)
- goto out_of_range;
- break;
- }
-#endif
- }
-
- predictor= get_bits(&s->gb, 8); /* lossless predictor or start of spectral (Ss) */
- skip_bits(&s->gb, 8); /* Se */
- skip_bits(&s->gb, 4); /* Ah */
- point_transform= get_bits(&s->gb, 4); /* Al */
-
- for(i=0;i<nb_components;i++)
- s->last_dc[i] = 1024;
-
- if (nb_components > 1) {
- /* interleaved stream */
- s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
- s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
- } else {
- h = s->h_max / s->h_scount[s->comp_index[0]];
- v = s->v_max / s->v_scount[s->comp_index[0]];
- s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
- s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
- s->nb_blocks[0] = 1;
- s->h_scount[0] = 1;
- s->v_scount[0] = 1;
- }
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- printf("%s %s p:%d >>:%d\n", s->lossless ? "lossless" : "sequencial DCT", s->rgb ? "RGB" : "", predictor, point_transform);
-
- if(s->lossless){
- if(s->rgb){
- if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
- return -1;
- }else{
- if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0)
- return -1;
- }
- }else{
- if(mjpeg_decode_scan(s) < 0)
- return -1;
- }
- emms_c();
- return 0;
- out_of_range:
- dprintf("decode_sos: ac/dc index out of range\n");
- return -1;
-}
-
-static int mjpeg_decode_dri(MJpegDecodeContext *s)
-{
- if (get_bits(&s->gb, 16) != 4)
- return -1;
- s->restart_interval = get_bits(&s->gb, 16);
- dprintf("restart interval: %d\n", s->restart_interval);
-
- return 0;
-}
-
-static int mjpeg_decode_app(MJpegDecodeContext *s)
-{
- int len, id;
-
- /* XXX: verify len field validity */
- len = get_bits(&s->gb, 16);
- if (len < 5)
- return -1;
-
- id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
- id = be2me_32(id);
- len -= 6;
-
- if(s->avctx->debug & FF_DEBUG_STARTCODE){
- printf("APPx %8X\n", id);
- }
-
- /* buggy AVID, it puts EOI only at every 10th frame */
- /* also this fourcc is used by non-avid files too, it holds some
- informations, but it's always present in AVID creates files */
- if (id == ff_get_fourcc("AVI1"))
- {
- /* structure:
- 4bytes AVI1
- 1bytes polarity
- 1bytes always zero
- 4bytes field_size
- 4bytes field_size_less_padding
- */
- s->buggy_avid = 1;
-// if (s->first_picture)
-// printf("mjpeg: workarounding buggy AVID\n");
- s->interlace_polarity = get_bits(&s->gb, 8);
-#if 0
- skip_bits(&s->gb, 8);
- skip_bits(&s->gb, 32);
- skip_bits(&s->gb, 32);
- len -= 10;
-#endif
-// if (s->interlace_polarity)
-// printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity);
- goto out;
- }
-
-// len -= 2;
-
- if (id == ff_get_fourcc("JFIF"))
- {
- int t_w, t_h;
- skip_bits(&s->gb, 8); /* the trailing zero-byte */
- printf("mjpeg: JFIF header found (version: %x.%x)\n",
- get_bits(&s->gb, 8), get_bits(&s->gb, 8));
- if (get_bits(&s->gb, 8) == 0)
- {
- int x_density, y_density;
- x_density = get_bits(&s->gb, 16);
- y_density = get_bits(&s->gb, 16);
-
- dprintf("x/y density: %d (%f), %d (%f)\n", x_density,
- (float)x_density, y_density, (float)y_density);
-#if 0
- //MN: needs to be checked
- if(x_density)
-// s->avctx->aspect_ratio= s->width*y_density/((float)s->height*x_density);
- s->avctx->aspect_ratio = (float)x_density/y_density;
- /* it's better, but every JFIF I have seen stores 1:1 */
- else
- s->avctx->aspect_ratio= 0.0;
-#endif
- }
- else
- {
- skip_bits(&s->gb, 16);
- skip_bits(&s->gb, 16);
- }
-
- t_w = get_bits(&s->gb, 8);
- t_h = get_bits(&s->gb, 8);
- if (t_w && t_h)
- {
- /* skip thumbnail */
- if (len-10-(t_w*t_h*3) > 0)
- len -= t_w*t_h*3;
- }
- len -= 10;
- goto out;
- }
-
- if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e'))
- {
- printf("mjpeg: Adobe header found\n");
- skip_bits(&s->gb, 16); /* version */
- skip_bits(&s->gb, 16); /* flags0 */
- skip_bits(&s->gb, 16); /* flags1 */
- skip_bits(&s->gb, 8); /* transform */
- len -= 7;
- goto out;
- }
-
- if (id == ff_get_fourcc("LJIF")){
- printf("Pegasus lossless jpeg header found\n");
- skip_bits(&s->gb, 16); /* version ? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- skip_bits(&s->gb, 16); /* unknwon always 0? */
- switch( get_bits(&s->gb, 8)){
- case 1:
- s->rgb= 1;
- s->pegasus_rct=0;
- break;
- case 2:
- s->rgb= 1;
- s->pegasus_rct=1;
- break;
- default:
- printf("unknown colorspace\n");
- }
- len -= 9;
- goto out;
- }
-
- /* Apple MJPEG-A */
- if ((s->start_code == APP1) && (len > (0x28 - 8)))
- {
- id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
- id = be2me_32(id);
- len -= 4;
- if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */
- {
-#if 0
- skip_bits(&s->gb, 32); /* field size */
- skip_bits(&s->gb, 32); /* pad field size */
- skip_bits(&s->gb, 32); /* next off */
- skip_bits(&s->gb, 32); /* quant off */
- skip_bits(&s->gb, 32); /* huff off */
- skip_bits(&s->gb, 32); /* image off */
- skip_bits(&s->gb, 32); /* scan off */
- skip_bits(&s->gb, 32); /* data off */
-#endif
- if (s->first_picture)
- printf("mjpeg: Apple MJPEG-A header found\n");
- }
- }
-
-out:
- /* slow but needed for extreme adobe jpegs */
- if (len < 0)
- printf("mjpeg: error, decode_app parser read over the end\n");
- while(--len > 0)
- skip_bits(&s->gb, 8);
-
- return 0;
-}
-
-static int mjpeg_decode_com(MJpegDecodeContext *s)
-{
- /* XXX: verify len field validity */
- int len = get_bits(&s->gb, 16);
- if (len >= 2 && len < 32768) {
- /* XXX: any better upper bound */
- uint8_t *cbuf = av_malloc(len - 1);
- if (cbuf) {
- int i;
- for (i = 0; i < len - 2; i++)
- cbuf[i] = get_bits(&s->gb, 8);
- if (i > 0 && cbuf[i-1] == '\n')
- cbuf[i-1] = 0;
- else
- cbuf[i] = 0;
-
- printf("mjpeg comment: '%s'\n", cbuf);
-
- /* buggy avid, it puts EOI only at every 10th frame */
- if (!strcmp(cbuf, "AVID"))
- {
- s->buggy_avid = 1;
- // if (s->first_picture)
- // printf("mjpeg: workarounding buggy AVID\n");
- }
-
- av_free(cbuf);
- }
- }
-
- return 0;
-}
-
-#if 0
-static int valid_marker_list[] =
-{
- /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
-/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
-}
-#endif
-
-/* return the 8 bit start code value and update the search
- state. Return -1 if no start code found */
-static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end)
-{
- uint8_t *buf_ptr;
- unsigned int v, v2;
- int val;
-#ifdef DEBUG
- int skipped=0;
-#endif
-
- buf_ptr = *pbuf_ptr;
- while (buf_ptr < buf_end) {
- v = *buf_ptr++;
- v2 = *buf_ptr;
- if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe)) {
- val = *buf_ptr++;
- goto found;
- }
-#ifdef DEBUG
- skipped++;
-#endif
- }
- val = -1;
-found:
-#ifdef DEBUG
- dprintf("find_marker skipped %d bytes\n", skipped);
-#endif
- *pbuf_ptr = buf_ptr;
- return val;
-}
-
-static int mjpeg_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- uint8_t *buf_end, *buf_ptr;
- int i, start_code;
- AVFrame *picture = data;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
- while (buf_ptr < buf_end) {
- /* find start next marker */
- start_code = find_marker(&buf_ptr, buf_end);
- {
- /* EOF */
- if (start_code < 0) {
- goto the_end;
- } else {
- dprintf("marker=%x avail_size_in_buf=%d\n", start_code, buf_end - buf_ptr);
-
- if ((buf_end - buf_ptr) > s->buffer_size)
- {
- av_free(s->buffer);
- s->buffer_size = buf_end-buf_ptr;
- s->buffer = av_malloc(s->buffer_size);
- dprintf("buffer too small, expanding to %d bytes\n",
- s->buffer_size);
- }
-
- /* unescape buffer of SOS */
- if (start_code == SOS)
- {
- uint8_t *src = buf_ptr;
- uint8_t *dst = s->buffer;
-
- while (src<buf_end)
- {
- uint8_t x = *(src++);
-
- *(dst++) = x;
- if (x == 0xff)
- {
- while(*src == 0xff) src++;
-
- x = *(src++);
- if (x >= 0xd0 && x <= 0xd7)
- *(dst++) = x;
- else if (x)
- break;
- }
- }
- init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
-
- dprintf("escaping removed %d bytes\n",
- (buf_end - buf_ptr) - (dst - s->buffer));
- }
- else
- init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
-
- s->start_code = start_code;
- if(s->avctx->debug & FF_DEBUG_STARTCODE){
- printf("startcode: %X\n", start_code);
- }
-
- /* process markers */
- if (start_code >= 0xd0 && start_code <= 0xd7) {
- dprintf("restart marker: %d\n", start_code&0x0f);
- } else if (s->first_picture) {
- /* APP fields */
- if (start_code >= 0xe0 && start_code <= 0xef)
- mjpeg_decode_app(s);
- /* Comment */
- else if (start_code == COM)
- mjpeg_decode_com(s);
- }
-
- switch(start_code) {
- case SOI:
- s->restart_interval = 0;
- /* nothing to do on SOI */
- break;
- case DQT:
- mjpeg_decode_dqt(s);
- break;
- case DHT:
- if(mjpeg_decode_dht(s) < 0){
- fprintf(stderr, "huffman table decode error\n");
- return -1;
- }
- break;
- case SOF0:
- s->lossless=0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case SOF3:
- s->lossless=1;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- break;
- case EOI:
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- break;
-eoi_parser:
- {
- if (s->interlaced) {
- s->bottom_field ^= 1;
- /* if not bottom field, do not output image yet */
- if (s->bottom_field)
- goto not_the_end;
- }
- for(i=0;i<3;i++) {
- picture->data[i] = s->current_picture[i];
- picture->linesize[i] = (s->interlaced) ?
- s->linesize[i] >> 1 : s->linesize[i];
- }
- *data_size = sizeof(AVFrame);
- avctx->height = s->height;
- if (s->interlaced)
- avctx->height *= 2;
- avctx->width = s->width;
- /* XXX: not complete test ! */
- switch((s->h_count[0] << 4) | s->v_count[0]) {
- case 0x11:
- if(s->rgb){
- avctx->pix_fmt = PIX_FMT_RGBA32;
- }else
- avctx->pix_fmt = PIX_FMT_YUV444P;
- break;
- case 0x21:
- avctx->pix_fmt = PIX_FMT_YUV422P;
- break;
- default:
- case 0x22:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- }
-
- if(!s->lossless){
- picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
- picture->qstride= 0;
- picture->qscale_table= s->qscale_table;
- memset(picture->qscale_table, picture->quality, (s->width+15)/16);
- if(avctx->debug & FF_DEBUG_QP)
- printf("QP: %d\n", (int)picture->quality);
- }
-
- goto the_end;
- }
- break;
- case SOS:
- mjpeg_decode_sos(s);
- /* buggy avid puts EOI every 10-20th frame */
- /* if restart period is over process EOI */
- if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
- goto eoi_parser;
- break;
- case DRI:
- mjpeg_decode_dri(s);
- break;
- case SOF1:
- case SOF2:
- case SOF5:
- case SOF6:
- case SOF7:
- case SOF9:
- case SOF10:
- case SOF11:
- case SOF13:
- case SOF14:
- case SOF15:
- case JPG:
- printf("mjpeg: unsupported coding type (%x)\n", start_code);
- break;
-// default:
-// printf("mjpeg: unsupported marker (%x)\n", start_code);
-// break;
- }
-
-not_the_end:
- /* eof process start code */
- buf_ptr += (get_bits_count(&s->gb)+7)/8;
- dprintf("marker parser used %d bytes (%d bits)\n",
- (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb));
- }
- }
- }
-the_end:
- dprintf("mjpeg decode frame unused %d bytes\n", buf_end - buf_ptr);
-// return buf_end - buf_ptr;
- return buf_ptr - buf;
-}
-
-static int mjpegb_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- uint8_t *buf_end, *buf_ptr;
- int i;
- AVFrame *picture = data;
- GetBitContext hgb; /* for the header */
- uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
- uint32_t field_size;
-
- *data_size = 0;
-
- /* no supplementary picture */
- if (buf_size == 0)
- return 0;
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
-
-read_header:
- /* reset on every SOI */
- s->restart_interval = 0;
-
- init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8);
-
- skip_bits(&hgb, 32); /* reserved zeros */
-
- if (get_bits(&hgb, 32) != be2me_32(ff_get_fourcc("mjpg")))
- {
- dprintf("not mjpeg-b (bad fourcc)\n");
- return 0;
- }
-
- field_size = get_bits(&hgb, 32); /* field size */
- dprintf("field size: 0x%x\n", field_size);
- skip_bits(&hgb, 32); /* padded field size */
- second_field_offs = get_bits(&hgb, 32);
- dprintf("second field offs: 0x%x\n", second_field_offs);
- if (second_field_offs)
- s->interlaced = 1;
-
- dqt_offs = get_bits(&hgb, 32);
- dprintf("dqt offs: 0x%x\n", dqt_offs);
- if (dqt_offs)
- {
- init_get_bits(&s->gb, buf+dqt_offs, (buf_end - (buf+dqt_offs))*8);
- s->start_code = DQT;
- mjpeg_decode_dqt(s);
- }
-
- dht_offs = get_bits(&hgb, 32);
- dprintf("dht offs: 0x%x\n", dht_offs);
- if (dht_offs)
- {
- init_get_bits(&s->gb, buf+dht_offs, (buf_end - (buf+dht_offs))*8);
- s->start_code = DHT;
- mjpeg_decode_dht(s);
- }
-
- sof_offs = get_bits(&hgb, 32);
- dprintf("sof offs: 0x%x\n", sof_offs);
- if (sof_offs)
- {
- init_get_bits(&s->gb, buf+sof_offs, (buf_end - (buf+sof_offs))*8);
- s->start_code = SOF0;
- if (mjpeg_decode_sof(s) < 0)
- return -1;
- }
-
- sos_offs = get_bits(&hgb, 32);
- dprintf("sos offs: 0x%x\n", sos_offs);
- if (sos_offs)
- {
-// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8);
- init_get_bits(&s->gb, buf+sos_offs, field_size*8);
- s->start_code = SOS;
- mjpeg_decode_sos(s);
- }
-
- skip_bits(&hgb, 32); /* start of data offset */
-
- if (s->interlaced) {
- s->bottom_field ^= 1;
- /* if not bottom field, do not output image yet */
- if (s->bottom_field && second_field_offs)
- {
- buf_ptr = buf + second_field_offs;
- second_field_offs = 0;
- goto read_header;
- }
- }
-
- //XXX FIXME factorize, this looks very similar to the EOI code
-
- for(i=0;i<3;i++) {
- picture->data[i] = s->current_picture[i];
- picture->linesize[i] = (s->interlaced) ?
- s->linesize[i] >> 1 : s->linesize[i];
- }
- *data_size = sizeof(AVFrame);
- avctx->height = s->height;
- if (s->interlaced)
- avctx->height *= 2;
- avctx->width = s->width;
- /* XXX: not complete test ! */
- switch((s->h_count[0] << 4) | s->v_count[0]) {
- case 0x11:
- avctx->pix_fmt = PIX_FMT_YUV444P;
- break;
- case 0x21:
- avctx->pix_fmt = PIX_FMT_YUV422P;
- break;
- default:
- case 0x22:
- avctx->pix_fmt = PIX_FMT_YUV420P;
- break;
- }
-
- if(!s->lossless){
- picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]);
- picture->qstride= 0;
- picture->qscale_table= s->qscale_table;
- memset(picture->qscale_table, picture->quality, (s->width+15)/16);
- if(avctx->debug & FF_DEBUG_QP)
- printf("QP: %f\n", picture->quality);
- }
-
- return buf_ptr - buf;
-}
-
-
-static int mjpeg_decode_end(AVCodecContext *avctx)
-{
- MJpegDecodeContext *s = avctx->priv_data;
- int i, j;
-
- av_free(s->buffer);
- av_free(s->qscale_table);
- for(i=0;i<MAX_COMPONENTS;i++)
- av_free(s->current_picture[i]);
- for(i=0;i<2;i++) {
- for(j=0;j<4;j++)
- free_vlc(&s->vlcs[i][j]);
- }
- return 0;
-}
-
-AVCodec mjpeg_decoder = {
- "mjpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MJpegDecodeContext),
- mjpeg_decode_init,
- NULL,
- mjpeg_decode_end,
- mjpeg_decode_frame,
- 0,
- NULL
-};
-
-AVCodec mjpegb_decoder = {
- "mjpegb",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEGB,
- sizeof(MJpegDecodeContext),
- mjpeg_decode_init,
- NULL,
- mjpeg_decode_end,
- mjpegb_decode_frame,
- 0,
- NULL
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them
- "ljpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_LJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- encode_picture_lossless,
- MPV_encode_end,
-};
-#endif
+++ /dev/null
-/*
- * Motion estimation
- * Copyright (c) 2000,2001 Fabrice Bellard.
- * Copyright (c) 2002-2003 Michael Niedermayer
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file motion_est.c
- * Motion estimation.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#define SQ(a) ((a)*(a))
-
-#define P_LEFT P[1]
-#define P_TOP P[2]
-#define P_TOPRIGHT P[3]
-#define P_MEDIAN P[4]
-#define P_MV1 P[9]
-
-static inline int sad_hpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *picture,
- int n, int size, uint8_t * const mv_penalty);
-
-static inline int update_map_generation(MpegEncContext * s)
-{
- s->me.map_generation+= 1<<(ME_MAP_MV_BITS*2);
- if(s->me.map_generation==0){
- s->me.map_generation= 1<<(ME_MAP_MV_BITS*2);
- memset(s->me.map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
- }
- return s->me.map_generation;
-}
-
-/* shape adaptive search stuff */
-typedef struct Minima{
- int height;
- int x, y;
- int checked;
-}Minima;
-
-static int minima_cmp(const void *a, const void *b){
- const Minima *da = (const Minima *) a;
- const Minima *db = (const Minima *) b;
-
- return da->height - db->height;
-}
-
-/* SIMPLE */
-#define RENAME(a) simple_ ## a
-
-#define CMP(d, x, y, size)\
-d = cmp(s, src_y, (ref_y) + (x) + (y)*(stride), stride);
-
-#define CMP_HPEL(d, dx, dy, x, y, size)\
-{\
- const int dxy= (dx) + 2*(dy);\
- hpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride, (16>>size));\
- d = cmp_sub(s, s->me.scratchpad, src_y, stride);\
-}
-
-#define CMP_QPEL(d, dx, dy, x, y, size)\
-{\
- const int dxy= (dx) + 4*(dy);\
- qpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride);\
- d = cmp_sub(s, s->me.scratchpad, src_y, stride);\
-}
-
-#include "motion_est_template.c"
-#undef RENAME
-#undef CMP
-#undef CMP_HPEL
-#undef CMP_QPEL
-#undef INIT
-
-/* SIMPLE CHROMA */
-#define RENAME(a) simple_chroma_ ## a
-
-#define CMP(d, x, y, size)\
-d = cmp(s, src_y, (ref_y) + (x) + (y)*(stride), stride);\
-if(chroma_cmp){\
- int dxy= ((x)&1) + 2*((y)&1);\
- int c= ((x)>>1) + ((y)>>1)*uvstride;\
-\
- chroma_hpel_put[0][dxy](s->me.scratchpad, ref_u + c, uvstride, 8);\
- d += chroma_cmp(s, s->me.scratchpad, src_u, uvstride);\
- chroma_hpel_put[0][dxy](s->me.scratchpad, ref_v + c, uvstride, 8);\
- d += chroma_cmp(s, s->me.scratchpad, src_v, uvstride);\
-}
-
-#define CMP_HPEL(d, dx, dy, x, y, size)\
-{\
- const int dxy= (dx) + 2*(dy);\
- hpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride, (16>>size));\
- d = cmp_sub(s, s->me.scratchpad, src_y, stride);\
- if(chroma_cmp_sub){\
- int cxy= (dxy) | ((x)&1) | (2*((y)&1));\
- int c= ((x)>>1) + ((y)>>1)*uvstride;\
- chroma_hpel_put[0][cxy](s->me.scratchpad, ref_u + c, uvstride, 8);\
- d += chroma_cmp_sub(s, s->me.scratchpad, src_u, uvstride);\
- chroma_hpel_put[0][cxy](s->me.scratchpad, ref_v + c, uvstride, 8);\
- d += chroma_cmp_sub(s, s->me.scratchpad, src_v, uvstride);\
- }\
-}
-
-#define CMP_QPEL(d, dx, dy, x, y, size)\
-{\
- const int dxy= (dx) + 4*(dy);\
- qpel_put[0][dxy](s->me.scratchpad, (ref_y) + (x) + (y)*(stride), stride);\
- d = cmp_sub(s, s->me.scratchpad, src_y, stride);\
- if(chroma_cmp_sub){\
- int cxy, c;\
- int cx= (4*(x) + (dx))/2;\
- int cy= (4*(y) + (dy))/2;\
- cx= (cx>>1)|(cx&1);\
- cy= (cy>>1)|(cy&1);\
- cxy= (cx&1) + 2*(cy&1);\
- c= ((cx)>>1) + ((cy)>>1)*uvstride;\
- chroma_hpel_put[0][cxy](s->me.scratchpad, ref_u + c, uvstride, 8);\
- d += chroma_cmp_sub(s, s->me.scratchpad, src_u, uvstride);\
- chroma_hpel_put[0][cxy](s->me.scratchpad, ref_v + c, uvstride, 8);\
- d += chroma_cmp_sub(s, s->me.scratchpad, src_v, uvstride);\
- }\
-}
-
-#include "motion_est_template.c"
-#undef RENAME
-#undef CMP
-#undef CMP_HPEL
-#undef CMP_QPEL
-#undef INIT
-
-/* SIMPLE DIRECT HPEL */
-#define RENAME(a) simple_direct_hpel_ ## a
-//FIXME precalc divisions stuff
-
-#define CMP_DIRECT(d, dx, dy, x, y, size, cmp_func)\
-if((x) >= xmin && 2*(x) + (dx) <= 2*xmax && (y) >= ymin && 2*(y) + (dy) <= 2*ymax){\
- const int hx= 2*(x) + (dx);\
- const int hy= 2*(y) + (dy);\
- if(s->mv_type==MV_TYPE_8X8){\
- int i;\
- for(i=0; i<4; i++){\
- int fx = s->me.direct_basis_mv[i][0] + hx;\
- int fy = s->me.direct_basis_mv[i][1] + hy;\
- int bx = hx ? fx - s->me.co_located_mv[i][0] : s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + (i &1)*16;\
- int by = hy ? fy - s->me.co_located_mv[i][1] : s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + (i>>1)*16;\
- int fxy= (fx&1) + 2*(fy&1);\
- int bxy= (bx&1) + 2*(by&1);\
-\
- uint8_t *dst= s->me.scratchpad + 8*(i&1) + 8*stride*(i>>1);\
- hpel_put[1][fxy](dst, (ref_y ) + (fx>>1) + (fy>>1)*(stride), stride, 8);\
- hpel_avg[1][bxy](dst, (ref2_y) + (bx>>1) + (by>>1)*(stride), stride, 8);\
- }\
- }else{\
- int fx = s->me.direct_basis_mv[0][0] + hx;\
- int fy = s->me.direct_basis_mv[0][1] + hy;\
- int bx = hx ? fx - s->me.co_located_mv[0][0] : (s->me.co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\
- int by = hy ? fy - s->me.co_located_mv[0][1] : (s->me.co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\
- int fxy= (fx&1) + 2*(fy&1);\
- int bxy= (bx&1) + 2*(by&1);\
- \
- assert((fx>>1) + 16*s->mb_x >= -16);\
- assert((fy>>1) + 16*s->mb_y >= -16);\
- assert((fx>>1) + 16*s->mb_x <= s->width);\
- assert((fy>>1) + 16*s->mb_y <= s->height);\
- assert((bx>>1) + 16*s->mb_x >= -16);\
- assert((by>>1) + 16*s->mb_y >= -16);\
- assert((bx>>1) + 16*s->mb_x <= s->width);\
- assert((by>>1) + 16*s->mb_y <= s->height);\
-\
- hpel_put[0][fxy](s->me.scratchpad, (ref_y ) + (fx>>1) + (fy>>1)*(stride), stride, 16);\
- hpel_avg[0][bxy](s->me.scratchpad, (ref2_y) + (bx>>1) + (by>>1)*(stride), stride, 16);\
- }\
- d = cmp_func(s, s->me.scratchpad, src_y, stride);\
-}else\
- d= 256*256*256*32;
-
-
-#define CMP_HPEL(d, dx, dy, x, y, size)\
- CMP_DIRECT(d, dx, dy, x, y, size, cmp_sub)
-
-#define CMP(d, x, y, size)\
- CMP_DIRECT(d, 0, 0, x, y, size, cmp)
-
-#include "motion_est_template.c"
-#undef RENAME
-#undef CMP
-#undef CMP_HPEL
-#undef CMP_QPEL
-#undef INIT
-#undef CMP_DIRECT
-
-/* SIMPLE DIRECT QPEL */
-#define RENAME(a) simple_direct_qpel_ ## a
-
-#define CMP_DIRECT(d, dx, dy, x, y, size, cmp_func)\
-if((x) >= xmin && 4*(x) + (dx) <= 4*xmax && (y) >= ymin && 4*(y) + (dy) <= 4*ymax){\
- const int qx= 4*(x) + (dx);\
- const int qy= 4*(y) + (dy);\
- if(s->mv_type==MV_TYPE_8X8){\
- int i;\
- for(i=0; i<4; i++){\
- int fx = s->me.direct_basis_mv[i][0] + qx;\
- int fy = s->me.direct_basis_mv[i][1] + qy;\
- int bx = qx ? fx - s->me.co_located_mv[i][0] : s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + (i &1)*16;\
- int by = qy ? fy - s->me.co_located_mv[i][1] : s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + (i>>1)*16;\
- int fxy= (fx&3) + 4*(fy&3);\
- int bxy= (bx&3) + 4*(by&3);\
-\
- uint8_t *dst= s->me.scratchpad + 8*(i&1) + 8*stride*(i>>1);\
- qpel_put[1][fxy](dst, (ref_y ) + (fx>>2) + (fy>>2)*(stride), stride);\
- qpel_avg[1][bxy](dst, (ref2_y) + (bx>>2) + (by>>2)*(stride), stride);\
- }\
- }else{\
- int fx = s->me.direct_basis_mv[0][0] + qx;\
- int fy = s->me.direct_basis_mv[0][1] + qy;\
- int bx = qx ? fx - s->me.co_located_mv[0][0] : s->me.co_located_mv[0][0]*(time_pb - time_pp)/time_pp;\
- int by = qy ? fy - s->me.co_located_mv[0][1] : s->me.co_located_mv[0][1]*(time_pb - time_pp)/time_pp;\
- int fxy= (fx&3) + 4*(fy&3);\
- int bxy= (bx&3) + 4*(by&3);\
-\
- qpel_put[1][fxy](s->me.scratchpad , (ref_y ) + (fx>>2) + (fy>>2)*(stride) , stride);\
- qpel_put[1][fxy](s->me.scratchpad + 8 , (ref_y ) + (fx>>2) + (fy>>2)*(stride) + 8 , stride);\
- qpel_put[1][fxy](s->me.scratchpad + 8*stride, (ref_y ) + (fx>>2) + (fy>>2)*(stride) + 8*stride, stride);\
- qpel_put[1][fxy](s->me.scratchpad + 8 + 8*stride, (ref_y ) + (fx>>2) + (fy>>2)*(stride) + 8 + 8*stride, stride);\
- qpel_avg[1][bxy](s->me.scratchpad , (ref2_y) + (bx>>2) + (by>>2)*(stride) , stride);\
- qpel_avg[1][bxy](s->me.scratchpad + 8 , (ref2_y) + (bx>>2) + (by>>2)*(stride) + 8 , stride);\
- qpel_avg[1][bxy](s->me.scratchpad + 8*stride, (ref2_y) + (bx>>2) + (by>>2)*(stride) + 8*stride, stride);\
- qpel_avg[1][bxy](s->me.scratchpad + 8 + 8*stride, (ref2_y) + (bx>>2) + (by>>2)*(stride) + 8 + 8*stride, stride);\
- }\
- d = cmp_func(s, s->me.scratchpad, src_y, stride);\
-}else\
- d= 256*256*256*32;
-
-
-#define CMP_QPEL(d, dx, dy, x, y, size)\
- CMP_DIRECT(d, dx, dy, x, y, size, cmp_sub)
-
-#define CMP(d, x, y, size)\
- CMP_DIRECT(d, 0, 0, x, y, size, cmp)
-
-#include "motion_est_template.c"
-#undef RENAME
-#undef CMP
-#undef CMP_HPEL
-#undef CMP_QPEL
-#undef INIT
-#undef CMP__DIRECT
-
-
-static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride){
- return 0;
-}
-
-static void set_cmp(MpegEncContext *s, me_cmp_func *cmp, int type){
- DSPContext* c= &s->dsp;
- int i;
-
- memset(cmp, 0, sizeof(void*)*11);
-
- switch(type&0xFF){
- case FF_CMP_SAD:
- cmp[0]= c->sad[0];
- cmp[1]= c->sad[1];
- break;
- case FF_CMP_SATD:
- cmp[0]= c->hadamard8_diff[0];
- cmp[1]= c->hadamard8_diff[1];
- break;
- case FF_CMP_SSE:
- cmp[0]= c->sse[0];
- cmp[1]= c->sse[1];
- break;
- case FF_CMP_DCT:
- cmp[0]= c->dct_sad[0];
- cmp[1]= c->dct_sad[1];
- break;
- case FF_CMP_PSNR:
- cmp[0]= c->quant_psnr[0];
- cmp[1]= c->quant_psnr[1];
- break;
- case FF_CMP_BIT:
- cmp[0]= c->bit[0];
- cmp[1]= c->bit[1];
- break;
- case FF_CMP_RD:
- cmp[0]= c->rd[0];
- cmp[1]= c->rd[1];
- break;
- case FF_CMP_ZERO:
- for(i=0; i<7; i++){
- cmp[i]= zero_cmp;
- }
- break;
- default:
- fprintf(stderr,"internal error in cmp function selection\n");
- }
-}
-
-static inline int get_penalty_factor(MpegEncContext *s, int type){
- switch(type&0xFF){
- default:
- case FF_CMP_SAD:
- return s->qscale*2;
- case FF_CMP_DCT:
- return s->qscale*3;
- case FF_CMP_SATD:
- return s->qscale*6;
- case FF_CMP_SSE:
- return s->qscale*s->qscale*2;
- case FF_CMP_BIT:
- return 1;
- case FF_CMP_RD:
- case FF_CMP_PSNR:
- return (s->qscale*s->qscale*185 + 64)>>7;
- }
-}
-
-void ff_init_me(MpegEncContext *s){
- set_cmp(s, s->dsp.me_pre_cmp, s->avctx->me_pre_cmp);
- set_cmp(s, s->dsp.me_cmp, s->avctx->me_cmp);
- set_cmp(s, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp);
- set_cmp(s, s->dsp.mb_cmp, s->avctx->mb_cmp);
-
- if(s->flags&CODEC_FLAG_QPEL){
- if(s->avctx->me_sub_cmp&FF_CMP_CHROMA)
- s->me.sub_motion_search= simple_chroma_qpel_motion_search;
- else
- s->me.sub_motion_search= simple_qpel_motion_search;
- }else{
- if(s->avctx->me_sub_cmp&FF_CMP_CHROMA)
- s->me.sub_motion_search= simple_chroma_hpel_motion_search;
- else if( s->avctx->me_sub_cmp == FF_CMP_SAD
- && s->avctx-> me_cmp == FF_CMP_SAD
- && s->avctx-> mb_cmp == FF_CMP_SAD)
- s->me.sub_motion_search= sad_hpel_motion_search;
- else
- s->me.sub_motion_search= simple_hpel_motion_search;
- }
-
- if(s->avctx->me_cmp&FF_CMP_CHROMA){
- s->me.motion_search[0]= simple_chroma_epzs_motion_search;
- s->me.motion_search[1]= simple_chroma_epzs_motion_search4;
- }else{
- s->me.motion_search[0]= simple_epzs_motion_search;
- s->me.motion_search[1]= simple_epzs_motion_search4;
- }
-
- if(s->avctx->me_pre_cmp&FF_CMP_CHROMA){
- s->me.pre_motion_search= simple_chroma_epzs_motion_search;
- }else{
- s->me.pre_motion_search= simple_epzs_motion_search;
- }
-
- if(s->flags&CODEC_FLAG_QPEL){
- if(s->avctx->mb_cmp&FF_CMP_CHROMA)
- s->me.get_mb_score= simple_chroma_qpel_get_mb_score;
- else
- s->me.get_mb_score= simple_qpel_get_mb_score;
- }else{
- if(s->avctx->mb_cmp&FF_CMP_CHROMA)
- s->me.get_mb_score= simple_chroma_hpel_get_mb_score;
- else
- s->me.get_mb_score= simple_hpel_get_mb_score;
- }
-}
-
-#if 0
-static int pix_dev(uint8_t * pix, int line_size, int mean)
-{
- int s, i, j;
-
- s = 0;
- for (i = 0; i < 16; i++) {
- for (j = 0; j < 16; j += 8) {
- s += ABS(pix[0]-mean);
- s += ABS(pix[1]-mean);
- s += ABS(pix[2]-mean);
- s += ABS(pix[3]-mean);
- s += ABS(pix[4]-mean);
- s += ABS(pix[5]-mean);
- s += ABS(pix[6]-mean);
- s += ABS(pix[7]-mean);
- pix += 8;
- }
- pix += line_size - 16;
- }
- return s;
-}
-#endif
-
-static inline void no_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr)
-{
- *mx_ptr = 16 * s->mb_x;
- *my_ptr = 16 * s->mb_y;
-}
-
-static int full_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y;
- int mx, my, dmin, d;
- uint8_t *pix;
-
- xx = 16 * s->mb_x;
- yy = 16 * s->mb_y;
- x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */
- if (x1 < xmin)
- x1 = xmin;
- x2 = xx + range - 1;
- if (x2 > xmax)
- x2 = xmax;
- y1 = yy - range + 1;
- if (y1 < ymin)
- y1 = ymin;
- y2 = yy + range - 1;
- if (y2 > ymax)
- y2 = ymax;
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- dmin = 0x7fffffff;
- mx = 0;
- my = 0;
- for (y = y1; y <= y2; y++) {
- for (x = x1; x <= x2; x++) {
- d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x,
- s->linesize);
- if (d < dmin ||
- (d == dmin &&
- (abs(x - xx) + abs(y - yy)) <
- (abs(mx - xx) + abs(my - yy)))) {
- dmin = d;
- mx = x;
- my = y;
- }
- }
- }
-
- *mx_ptr = mx;
- *my_ptr = my;
-
-#if 0
- if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) ||
- *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) {
- fprintf(stderr, "error %d %d\n", *mx_ptr, *my_ptr);
- }
-#endif
- return dmin;
-}
-
-
-static int log_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y;
- int mx, my, dmin, d;
- uint8_t *pix;
-
- xx = s->mb_x << 4;
- yy = s->mb_y << 4;
-
- /* Left limit */
- x1 = xx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- /* Right limit */
- x2 = xx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- /* Upper limit */
- y1 = yy - range;
- if (y1 < ymin)
- y1 = ymin;
-
- /* Lower limit */
- y2 = yy + range;
- if (y2 > ymax)
- y2 = ymax;
-
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- dmin = 0x7fffffff;
- mx = 0;
- my = 0;
-
- do {
- for (y = y1; y <= y2; y += range) {
- for (x = x1; x <= x2; x += range) {
- d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize);
- if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dmin = d;
- mx = x;
- my = y;
- }
- }
- }
-
- range = range >> 1;
-
- x1 = mx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- x2 = mx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- y1 = my - range;
- if (y1 < ymin)
- y1 = ymin;
-
- y2 = my + range;
- if (y2 > ymax)
- y2 = ymax;
-
- } while (range >= 1);
-
-#ifdef DEBUG
- fprintf(stderr, "log - MX: %d\tMY: %d\n", mx, my);
-#endif
- *mx_ptr = mx;
- *my_ptr = my;
- return dmin;
-}
-
-static int phods_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int range,
- int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture)
-{
- int x1, y1, x2, y2, xx, yy, x, y, lastx, d;
- int mx, my, dminx, dminy;
- uint8_t *pix;
-
- xx = s->mb_x << 4;
- yy = s->mb_y << 4;
-
- /* Left limit */
- x1 = xx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- /* Right limit */
- x2 = xx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- /* Upper limit */
- y1 = yy - range;
- if (y1 < ymin)
- y1 = ymin;
-
- /* Lower limit */
- y2 = yy + range;
- if (y2 > ymax)
- y2 = ymax;
-
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- mx = 0;
- my = 0;
-
- x = xx;
- y = yy;
- do {
- dminx = 0x7fffffff;
- dminy = 0x7fffffff;
-
- lastx = x;
- for (x = x1; x <= x2; x += range) {
- d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize);
- if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dminx = d;
- mx = x;
- }
- }
-
- x = lastx;
- for (y = y1; y <= y2; y += range) {
- d = s->dsp.pix_abs16x16(pix, ref_picture + (y * s->linesize) + x, s->linesize);
- if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
- dminy = d;
- my = y;
- }
- }
-
- range = range >> 1;
-
- x = mx;
- y = my;
- x1 = mx - range;
- if (x1 < xmin)
- x1 = xmin;
-
- x2 = mx + range;
- if (x2 > xmax)
- x2 = xmax;
-
- y1 = my - range;
- if (y1 < ymin)
- y1 = ymin;
-
- y2 = my + range;
- if (y2 > ymax)
- y2 = ymax;
-
- } while (range >= 1);
-
-#ifdef DEBUG
- fprintf(stderr, "phods - MX: %d\tMY: %d\n", mx, my);
-#endif
-
- /* half pixel search */
- *mx_ptr = mx;
- *my_ptr = my;
- return dminy;
-}
-
-
-#define Z_THRESHOLD 256
-
-#define CHECK_SAD_HALF_MV(suffix, x, y) \
-{\
- d= pix_abs_ ## suffix(pix, ptr+((x)>>1), s->linesize);\
- d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
- COPY3_IF_LT(dminh, d, dx, x, dy, y)\
-}
-
-static inline int sad_hpel_motion_search(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *picture,
- int n, int size, uint8_t * const mv_penalty)
-{
- uint8_t *ref_picture= picture->data[0];
- uint32_t *score_map= s->me.score_map;
- const int penalty_factor= s->me.sub_penalty_factor;
- int mx, my, xx, yy, dminh;
- uint8_t *pix, *ptr;
- op_pixels_abs_func pix_abs_x2;
- op_pixels_abs_func pix_abs_y2;
- op_pixels_abs_func pix_abs_xy2;
-
- if(size==0){
- pix_abs_x2 = s->dsp.pix_abs16x16_x2;
- pix_abs_y2 = s->dsp.pix_abs16x16_y2;
- pix_abs_xy2= s->dsp.pix_abs16x16_xy2;
- }else{
- pix_abs_x2 = s->dsp.pix_abs8x8_x2;
- pix_abs_y2 = s->dsp.pix_abs8x8_y2;
- pix_abs_xy2= s->dsp.pix_abs8x8_xy2;
- }
-
- if(s->me.skip){
-// printf("S");
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-// printf("N");
-
- xx = 16 * s->mb_x + 8*(n&1);
- yy = 16 * s->mb_y + 8*(n>>1);
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
-
- mx = *mx_ptr;
- my = *my_ptr;
- ptr = ref_picture + ((yy + my) * s->linesize) + (xx + mx);
-
- dminh = dmin;
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int dx=0, dy=0;
- int d, pen_x, pen_y;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
- const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)];
- mx<<=1;
- my<<=1;
-
-
- pen_x= pred_x + mx;
- pen_y= pred_y + my;
-
- ptr-= s->linesize;
- if(t<=b){
- CHECK_SAD_HALF_MV(y2 , 0, -1)
- if(l<=r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- if(t+r<=b+l){
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- ptr+= s->linesize;
- }else{
- ptr+= s->linesize;
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , -1, 0)
- }else{
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- if(t+l<=b+r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- ptr+= s->linesize;
- }else{
- ptr+= s->linesize;
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , +1, 0)
- }
- }else{
- if(l<=r){
- if(t+l<=b+r){
- CHECK_SAD_HALF_MV(xy2, -1, -1)
- ptr+= s->linesize;
- }else{
- ptr+= s->linesize;
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , -1, 0)
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }else{
- if(t+r<=b+l){
- CHECK_SAD_HALF_MV(xy2, +1, -1)
- ptr+= s->linesize;
- }else{
- ptr+= s->linesize;
- CHECK_SAD_HALF_MV(xy2, -1, +1)
- }
- CHECK_SAD_HALF_MV(x2 , +1, 0)
- CHECK_SAD_HALF_MV(xy2, +1, +1)
- }
- CHECK_SAD_HALF_MV(y2 , 0, +1)
- }
- mx+=dx;
- my+=dy;
-
- }else{
- mx<<=1;
- my<<=1;
- }
-
- *mx_ptr = mx;
- *my_ptr = my;
- return dminh;
-}
-
-static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
-{
- const int xy= s->mb_x + s->mb_y*s->mb_stride;
-
- s->p_mv_table[xy][0] = mx;
- s->p_mv_table[xy][1] = my;
-
- /* has allready been set to the 4 MV if 4MV is done */
- if(mv4){
- int mot_xy= s->block_index[0];
-
- s->motion_val[mot_xy ][0]= mx;
- s->motion_val[mot_xy ][1]= my;
- s->motion_val[mot_xy+1][0]= mx;
- s->motion_val[mot_xy+1][1]= my;
-
- mot_xy += s->block_wrap[0];
- s->motion_val[mot_xy ][0]= mx;
- s->motion_val[mot_xy ][1]= my;
- s->motion_val[mot_xy+1][0]= mx;
- s->motion_val[mot_xy+1][1]= my;
- }
-}
-
-/**
- * get fullpel ME search limits.
- * @param range the approximate search range for the old ME code, unused for EPZS and newer
- */
-static inline void get_limits(MpegEncContext *s, int *range, int *xmin, int *ymin, int *xmax, int *ymax)
-{
- if(s->avctx->me_range) *range= s->avctx->me_range >> 1;
- else *range= 16;
-
- if (s->unrestricted_mv) {
- *xmin = -16;
- *ymin = -16;
- *xmax = s->mb_width*16;
- *ymax = s->mb_height*16;
- } else {
- *xmin = 0;
- *ymin = 0;
- *xmax = s->mb_width*16 - 16;
- *ymax = s->mb_height*16 - 16;
- }
-
- //FIXME try to limit x/y min/max if me_range is set
-}
-
-static inline int h263_mv4_search(MpegEncContext *s, int xmin, int ymin, int xmax, int ymax, int mx, int my, int shift)
-{
- int block;
- int P[10][2];
- int dmin_sum=0, mx4_sum=0, my4_sum=0;
- uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
-
- for(block=0; block<4; block++){
- int mx4, my4;
- int pred_x4, pred_y4;
- int dmin4;
- static const int off[4]= {2, 1, 1, -1};
- const int mot_stride = s->block_wrap[0];
- const int mot_xy = s->block_index[block];
-// const int block_x= (block&1);
-// const int block_y= (block>>1);
-#if 1 // this saves us a bit of cliping work and shouldnt affect compression in a negative way
- const int rel_xmin4= xmin;
- const int rel_xmax4= xmax;
- const int rel_ymin4= ymin;
- const int rel_ymax4= ymax;
-#else
- const int rel_xmin4= xmin - block_x*8;
- const int rel_xmax4= xmax - block_x*8 + 8;
- const int rel_ymin4= ymin - block_y*8;
- const int rel_ymax4= ymax - block_y*8 + 8;
-#endif
- P_LEFT[0] = s->motion_val[mot_xy - 1][0];
- P_LEFT[1] = s->motion_val[mot_xy - 1][1];
-
- if(P_LEFT[0] > (rel_xmax4<<shift)) P_LEFT[0] = (rel_xmax4<<shift);
-
- /* special case for first line */
- if (s->mb_y == 0 && block<2) {
- pred_x4= P_LEFT[0];
- pred_y4= P_LEFT[1];
- } else {
- P_TOP[0] = s->motion_val[mot_xy - mot_stride ][0];
- P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + off[block]][0];
- P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + off[block]][1];
- if(P_TOP[1] > (rel_ymax4<<shift)) P_TOP[1] = (rel_ymax4<<shift);
- if(P_TOPRIGHT[0] < (rel_xmin4<<shift)) P_TOPRIGHT[0]= (rel_xmin4<<shift);
- if(P_TOPRIGHT[0] > (rel_xmax4<<shift)) P_TOPRIGHT[0]= (rel_xmax4<<shift);
- if(P_TOPRIGHT[1] > (rel_ymax4<<shift)) P_TOPRIGHT[1]= (rel_ymax4<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
-// if(s->out_format == FMT_H263){
- pred_x4 = P_MEDIAN[0];
- pred_y4 = P_MEDIAN[1];
-#if 0
- }else { /* mpeg1 at least */
- pred_x4= P_LEFT[0];
- pred_y4= P_LEFT[1];
- }
-#endif
- }
- P_MV1[0]= mx;
- P_MV1[1]= my;
-
- dmin4 = s->me.motion_search[1](s, block, &mx4, &my4, P, pred_x4, pred_y4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4,
- &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);
-
- dmin4= s->me.sub_motion_search(s, &mx4, &my4, dmin4, rel_xmin4, rel_ymin4, rel_xmax4, rel_ymax4,
- pred_x4, pred_y4, &s->last_picture, block, 1, mv_penalty);
-
- if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- int dxy;
- const int offset= ((block&1) + (block>>1)*s->linesize)*8;
- uint8_t *dest_y = s->me.scratchpad + offset;
-
- if(s->quarter_sample){
- uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>2)) + (s->mb_y*16 + (my4>>2))*s->linesize + offset;
- dxy = ((my4 & 3) << 2) | (mx4 & 3);
-
- if(s->no_rounding)
- s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y , ref , s->linesize);
- else
- s->dsp.put_qpel_pixels_tab [1][dxy](dest_y , ref , s->linesize);
- }else{
- uint8_t *ref= s->last_picture.data[0] + (s->mb_x*16 + (mx4>>1)) + (s->mb_y*16 + (my4>>1))*s->linesize + offset;
- dxy = ((my4 & 1) << 1) | (mx4 & 1);
-
- if(s->no_rounding)
- s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , s->linesize, 8);
- else
- s->dsp.put_pixels_tab [1][dxy](dest_y , ref , s->linesize, 8);
- }
- dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*s->me.mb_penalty_factor;
- }else
- dmin_sum+= dmin4;
-
- if(s->quarter_sample){
- mx4_sum+= mx4/2;
- my4_sum+= my4/2;
- }else{
- mx4_sum+= mx4;
- my4_sum+= my4;
- }
-
- s->motion_val[ s->block_index[block] ][0]= mx4;
- s->motion_val[ s->block_index[block] ][1]= my4;
- }
-
- if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
- dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*s->linesize, s->me.scratchpad, s->linesize);
- }
-
- if(s->avctx->mb_cmp&FF_CMP_CHROMA){
- int dxy;
- int mx, my;
- int offset;
-
- mx= ff_h263_round_chroma(mx4_sum);
- my= ff_h263_round_chroma(my4_sum);
- dxy = ((my & 1) << 1) | (mx & 1);
-
- offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
-
- if(s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
- }else{
- s->dsp.put_pixels_tab [1][dxy](s->me.scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8);
- s->dsp.put_pixels_tab [1][dxy](s->me.scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8);
- }
-
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad , s->uvlinesize);
- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad+8, s->uvlinesize);
- }
-
- switch(s->avctx->mb_cmp&0xFF){
- /*case FF_CMP_SSE:
- return dmin_sum+ 32*s->qscale*s->qscale;*/
- case FF_CMP_RD:
- return dmin_sum;
- default:
- return dmin_sum+ 11*s->me.mb_penalty_factor;
- }
-}
-
-void ff_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- uint8_t *pix, *ppix;
- int sum, varc, vard, mx, my, range, dmin, xx, yy;
- int xmin, ymin, xmax, ymax;
- int rel_xmin, rel_ymin, rel_xmax, rel_ymax;
- int pred_x=0, pred_y=0;
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- int mb_type=0;
- uint8_t *ref_picture= s->last_picture.data[0];
- Picture * const pic= &s->current_picture;
- uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
-
- assert(s->quarter_sample==0 || s->quarter_sample==1);
-
- s->me.penalty_factor = get_penalty_factor(s, s->avctx->me_cmp);
- s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
- s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
-
- get_limits(s, &range, &xmin, &ymin, &xmax, &ymax);
- rel_xmin= xmin - mb_x*16;
- rel_xmax= xmax - mb_x*16;
- rel_ymin= ymin - mb_y*16;
- rel_ymax= ymax - mb_y*16;
- s->me.skip=0;
-
- switch(s->me_method) {
- case ME_ZERO:
- default:
- no_motion_search(s, &mx, &my);
- mx-= mb_x*16;
- my-= mb_y*16;
- dmin = 0;
- break;
- case ME_FULL:
- dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_LOG:
- dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_PHODS:
- dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_X1:
- case ME_EPZS:
- {
- const int mot_stride = s->block_wrap[0];
- const int mot_xy = s->block_index[0];
-
- P_LEFT[0] = s->motion_val[mot_xy - 1][0];
- P_LEFT[1] = s->motion_val[mot_xy - 1][1];
-
- if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift);
-
- if(mb_y) {
- P_TOP[0] = s->motion_val[mot_xy - mot_stride ][0];
- P_TOP[1] = s->motion_val[mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + 2][0];
- P_TOPRIGHT[1] = s->motion_val[mot_xy - mot_stride + 2][1];
- if(P_TOP[1] > (rel_ymax<<shift)) P_TOP[1] = (rel_ymax<<shift);
- if(P_TOPRIGHT[0] < (rel_xmin<<shift)) P_TOPRIGHT[0]= (rel_xmin<<shift);
- if(P_TOPRIGHT[1] > (rel_ymax<<shift)) P_TOPRIGHT[1]= (rel_ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- if(s->out_format == FMT_H263){
- pred_x = P_MEDIAN[0];
- pred_y = P_MEDIAN[1];
- }else { /* mpeg1 at least */
- pred_x= P_LEFT[0];
- pred_y= P_LEFT[1];
- }
- }else{
- pred_x= P_LEFT[0];
- pred_y= P_LEFT[1];
- }
-
- }
- dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);
-
- break;
- }
-
- /* intra / predictive decision */
- xx = mb_x * 16;
- yy = mb_y * 16;
-
- pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- /* At this point (mx,my) are full-pell and the relative displacement */
- ppix = ref_picture + ((yy+my) * s->linesize) + (xx+mx);
-
- sum = s->dsp.pix_sum(pix, s->linesize);
-
- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
- vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize)+128)>>8;
-
-//printf("%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
- pic->mb_var [s->mb_stride * mb_y + mb_x] = varc;
- pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard;
- pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
-// pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
- pic->mb_var_sum += varc;
- pic->mc_mb_var_sum += vard;
-//printf("E%d %d %d %X %X %X\n", s->mb_width, mb_x, mb_y,(int)s, (int)s->mb_var, (int)s->mc_mb_var); fflush(stdout);
-
-#if 0
- printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n",
- varc, s->avg_mb_var, sum, vard, mx - xx, my - yy);
-#endif
- if(s->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
- if (vard <= 64 || vard < varc)
- s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
- else
- s->scene_change_score+= s->qscale;
-
- if (vard*2 + 200 > varc)
- mb_type|= MB_TYPE_INTRA;
- if (varc*2 + 200 > vard){
- mb_type|= MB_TYPE_INTER;
- s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- pred_x, pred_y, &s->last_picture, 0, 0, mv_penalty);
- }else{
- mx <<=shift;
- my <<=shift;
- }
- if((s->flags&CODEC_FLAG_4MV)
- && !s->me.skip && varc>50 && vard>10){
- h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift);
- mb_type|=MB_TYPE_INTER4V;
-
- set_p_mv_tables(s, mx, my, 0);
- }else
- set_p_mv_tables(s, mx, my, 1);
- }else{
- mb_type= MB_TYPE_INTER;
-
- dmin= s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- pred_x, pred_y, &s->last_picture, 0, 0, mv_penalty);
-
- if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
- dmin= s->me.get_mb_score(s, mx, my, pred_x, pred_y, &s->last_picture, mv_penalty);
-
- if((s->flags&CODEC_FLAG_4MV)
- && !s->me.skip && varc>50 && vard>10){
- int dmin4= h263_mv4_search(s, rel_xmin, rel_ymin, rel_xmax, rel_ymax, mx, my, shift);
- if(dmin4 < dmin){
- mb_type= MB_TYPE_INTER4V;
- dmin=dmin4;
- }
- }
- pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin;
- set_p_mv_tables(s, mx, my, mb_type!=MB_TYPE_INTER4V);
-
- if (vard <= 64 || vard < varc) {
- s->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc);
- }else{
- s->scene_change_score+= s->qscale;
- }
- }
-
- s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type;
-}
-
-int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- int mx, my, range, dmin;
- int xmin, ymin, xmax, ymax;
- int rel_xmin, rel_ymin, rel_xmax, rel_ymax;
- int pred_x=0, pred_y=0;
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
- const int xy= mb_x + mb_y*s->mb_stride;
-
- assert(s->quarter_sample==0 || s->quarter_sample==1);
-
- s->me.pre_penalty_factor = get_penalty_factor(s, s->avctx->me_pre_cmp);
-
- get_limits(s, &range, &xmin, &ymin, &xmax, &ymax);
- rel_xmin= xmin - mb_x*16;
- rel_xmax= xmax - mb_x*16;
- rel_ymin= ymin - mb_y*16;
- rel_ymax= ymax - mb_y*16;
- s->me.skip=0;
-
- P_LEFT[0] = s->p_mv_table[xy + 1][0];
- P_LEFT[1] = s->p_mv_table[xy + 1][1];
-
- if(P_LEFT[0] < (rel_xmin<<shift)) P_LEFT[0] = (rel_xmin<<shift);
-
- /* special case for first line */
- if (mb_y == s->mb_height-1) {
- pred_x= P_LEFT[0];
- pred_y= P_LEFT[1];
- P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
- P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME
- } else {
- P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];
- P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];
- P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
- P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
- if(P_TOP[1] < (rel_ymin<<shift)) P_TOP[1] = (rel_ymin<<shift);
- if(P_TOPRIGHT[0] > (rel_xmax<<shift)) P_TOPRIGHT[0]= (rel_xmax<<shift);
- if(P_TOPRIGHT[1] < (rel_ymin<<shift)) P_TOPRIGHT[1]= (rel_ymin<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
-
- pred_x = P_MEDIAN[0];
- pred_y = P_MEDIAN[1];
- }
- dmin = s->me.pre_motion_search(s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);
-
- s->p_mv_table[xy][0] = mx<<shift;
- s->p_mv_table[xy][1] = my<<shift;
-
- return dmin;
-}
-
-static int ff_estimate_motion_b(MpegEncContext * s,
- int mb_x, int mb_y, int16_t (*mv_table)[2], Picture *picture, int f_code)
-{
- int mx, my, range, dmin;
- int xmin, ymin, xmax, ymax;
- int rel_xmin, rel_ymin, rel_xmax, rel_ymax;
- int pred_x=0, pred_y=0;
- int P[10][2];
- const int shift= 1+s->quarter_sample;
- const int mot_stride = s->mb_stride;
- const int mot_xy = mb_y*mot_stride + mb_x;
- uint8_t * const ref_picture= picture->data[0];
- uint8_t * const mv_penalty= s->me.mv_penalty[f_code] + MAX_MV;
- int mv_scale;
-
- s->me.penalty_factor = get_penalty_factor(s, s->avctx->me_cmp);
- s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
- s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
-
- get_limits(s, &range, &xmin, &ymin, &xmax, &ymax);
- rel_xmin= xmin - mb_x*16;
- rel_xmax= xmax - mb_x*16;
- rel_ymin= ymin - mb_y*16;
- rel_ymax= ymax - mb_y*16;
-
- switch(s->me_method) {
- case ME_ZERO:
- default:
- no_motion_search(s, &mx, &my);
- dmin = 0;
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_FULL:
- dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_LOG:
- dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_PHODS:
- dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax, ref_picture);
- mx-= mb_x*16;
- my-= mb_y*16;
- break;
- case ME_X1:
- case ME_EPZS:
- {
- P_LEFT[0] = mv_table[mot_xy - 1][0];
- P_LEFT[1] = mv_table[mot_xy - 1][1];
-
- if(P_LEFT[0] > (rel_xmax<<shift)) P_LEFT[0] = (rel_xmax<<shift);
-
- /* special case for first line */
- if (mb_y) {
- P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
- P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
- P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0];
- P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1];
- if(P_TOP[1] > (rel_ymax<<shift)) P_TOP[1]= (rel_ymax<<shift);
- if(P_TOPRIGHT[0] < (rel_xmin<<shift)) P_TOPRIGHT[0]= (rel_xmin<<shift);
- if(P_TOPRIGHT[1] > (rel_ymax<<shift)) P_TOPRIGHT[1]= (rel_ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
- }
- pred_x= P_LEFT[0];
- pred_y= P_LEFT[1];
- }
-
- if(mv_table == s->b_forw_mv_table){
- mv_scale= (s->pb_time<<16) / (s->pp_time<<shift);
- }else{
- mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift);
- }
-
- dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- picture, s->p_mv_table, mv_scale, mv_penalty);
-
- break;
- }
-
- dmin= s->me.sub_motion_search(s, &mx, &my, dmin, rel_xmin, rel_ymin, rel_xmax, rel_ymax,
- pred_x, pred_y, picture, 0, 0, mv_penalty);
-
- if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
- dmin= s->me.get_mb_score(s, mx, my, pred_x, pred_y, picture, mv_penalty);
-
-//printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my);
-// s->mb_type[mb_y*s->mb_width + mb_x]= mb_type;
- mv_table[mot_xy][0]= mx;
- mv_table[mot_xy][1]= my;
-
- return dmin;
-}
-
-static inline int check_bidir_mv(MpegEncContext * s,
- int mb_x, int mb_y,
- int motion_fx, int motion_fy,
- int motion_bx, int motion_by,
- int pred_fx, int pred_fy,
- int pred_bx, int pred_by)
-{
- //FIXME optimize?
- //FIXME move into template?
- //FIXME better f_code prediction (max mv & distance)
- uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
- uint8_t *dest_y = s->me.scratchpad;
- uint8_t *ptr;
- int dxy;
- int src_x, src_y;
- int fbmin;
-
- if(s->quarter_sample){
- dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
- src_x = mb_x * 16 + (motion_fx >> 2);
- src_y = mb_y * 16 + (motion_fy >> 2);
- assert(src_x >=-16 && src_x<=s->h_edge_pos);
- assert(src_y >=-16 && src_y<=s->v_edge_pos);
-
- ptr = s->last_picture.data[0] + (src_y * s->linesize) + src_x;
- s->dsp.put_qpel_pixels_tab[0][dxy](dest_y , ptr , s->linesize);
-
- dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
- src_x = mb_x * 16 + (motion_bx >> 2);
- src_y = mb_y * 16 + (motion_by >> 2);
- assert(src_x >=-16 && src_x<=s->h_edge_pos);
- assert(src_y >=-16 && src_y<=s->v_edge_pos);
-
- ptr = s->next_picture.data[0] + (src_y * s->linesize) + src_x;
- s->dsp.avg_qpel_pixels_tab[0][dxy](dest_y , ptr , s->linesize);
- }else{
- dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
- src_x = mb_x * 16 + (motion_fx >> 1);
- src_y = mb_y * 16 + (motion_fy >> 1);
- assert(src_x >=-16 && src_x<=s->h_edge_pos);
- assert(src_y >=-16 && src_y<=s->v_edge_pos);
-
- ptr = s->last_picture.data[0] + (src_y * s->linesize) + src_x;
- s->dsp.put_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16);
-
- dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
- src_x = mb_x * 16 + (motion_bx >> 1);
- src_y = mb_y * 16 + (motion_by >> 1);
- assert(src_x >=-16 && src_x<=s->h_edge_pos);
- assert(src_y >=-16 && src_y<=s->v_edge_pos);
-
- ptr = s->next_picture.data[0] + (src_y * s->linesize) + src_x;
- s->dsp.avg_pixels_tab[0][dxy](dest_y , ptr , s->linesize, 16);
- }
-
- fbmin = (mv_penalty[motion_fx-pred_fx] + mv_penalty[motion_fy-pred_fy])*s->me.mb_penalty_factor
- +(mv_penalty[motion_bx-pred_bx] + mv_penalty[motion_by-pred_by])*s->me.mb_penalty_factor
- + s->dsp.mb_cmp[0](s, s->new_picture.data[0] + mb_x*16 + mb_y*16*s->linesize, dest_y, s->linesize);
-
- if(s->avctx->mb_cmp&FF_CMP_CHROMA){
- }
- //FIXME CHROMA !!!
-
- return fbmin;
-}
-
-/* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/
-static inline int bidir_refine(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- const int mot_stride = s->mb_stride;
- const int xy = mb_y *mot_stride + mb_x;
- int fbmin;
- int pred_fx= s->b_bidir_forw_mv_table[xy-1][0];
- int pred_fy= s->b_bidir_forw_mv_table[xy-1][1];
- int pred_bx= s->b_bidir_back_mv_table[xy-1][0];
- int pred_by= s->b_bidir_back_mv_table[xy-1][1];
- int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0];
- int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1];
- int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0];
- int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1];
-
- //FIXME do refinement and add flag
-
- fbmin= check_bidir_mv(s, mb_x, mb_y,
- motion_fx, motion_fy,
- motion_bx, motion_by,
- pred_fx, pred_fy,
- pred_bx, pred_by);
-
- return fbmin;
-}
-
-static inline int direct_search(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- int P[10][2];
- const int mot_stride = s->mb_stride;
- const int mot_xy = mb_y*mot_stride + mb_x;
- const int shift= 1+s->quarter_sample;
- int dmin, i;
- const int time_pp= s->pp_time;
- const int time_pb= s->pb_time;
- int mx, my, xmin, xmax, ymin, ymax;
- int16_t (*mv_table)[2]= s->b_direct_mv_table;
- uint8_t * const mv_penalty= s->me.mv_penalty[1] + MAX_MV;
-
- ymin= xmin=(-32)>>shift;
- ymax= xmax= 31>>shift;
-
- if(IS_8X8(s->next_picture.mb_type[mot_xy])){
- s->mv_type= MV_TYPE_8X8;
- }else{
- s->mv_type= MV_TYPE_16X16;
- }
-
- for(i=0; i<4; i++){
- int index= s->block_index[i];
- int min, max;
-
- s->me.co_located_mv[i][0]= s->motion_val[index][0];
- s->me.co_located_mv[i][1]= s->motion_val[index][1];
- s->me.direct_basis_mv[i][0]= s->me.co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
- s->me.direct_basis_mv[i][1]= s->me.co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
-// s->me.direct_basis_mv[1][i][0]= s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
-// s->me.direct_basis_mv[1][i][1]= s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
-
- max= FFMAX(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;
- min= FFMIN(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;
- max+= (2*mb_x + (i& 1))*8 + 1; // +-1 is for the simpler rounding
- min+= (2*mb_x + (i& 1))*8 - 1;
- xmax= FFMIN(xmax, s->width - max);
- xmin= FFMAX(xmin, - 16 - min);
-
- max= FFMAX(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;
- min= FFMIN(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;
- max+= (2*mb_y + (i>>1))*8 + 1; // +-1 is for the simpler rounding
- min+= (2*mb_y + (i>>1))*8 - 1;
- ymax= FFMIN(ymax, s->height - max);
- ymin= FFMAX(ymin, - 16 - min);
-
- if(s->mv_type == MV_TYPE_16X16) break;
- }
-
- assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
-
- if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
- s->b_direct_mv_table[mot_xy][0]= 0;
- s->b_direct_mv_table[mot_xy][1]= 0;
-
- return 256*256*256*64;
- }
-
- P_LEFT[0] = clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
- P_LEFT[1] = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
-
- /* special case for first line */
- if (mb_y) {
- P_TOP[0] = clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);
- P_TOP[1] = clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);
- P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);
- P_TOPRIGHT[1] = clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);
-
- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
- }
-
- //FIXME direct_search ptr in context!!! (needed for chroma anyway or this will get messy)
- if(s->flags&CODEC_FLAG_QPEL){
- dmin = simple_direct_qpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax,
- &s->last_picture, mv_table, 1<<14, mv_penalty);
- dmin = simple_direct_qpel_qpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax,
- 0, 0, &s->last_picture, 0, 0, mv_penalty);
-
- if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
- dmin= simple_direct_qpel_qpel_get_mb_score(s, mx, my, 0, 0, &s->last_picture, mv_penalty);
- }else{
- dmin = simple_direct_hpel_epzs_motion_search(s, 0, &mx, &my, P, 0, 0, xmin, ymin, xmax, ymax,
- &s->last_picture, mv_table, 1<<15, mv_penalty);
- dmin = simple_direct_hpel_hpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax,
- 0, 0, &s->last_picture, 0, 0, mv_penalty);
-
- if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
- dmin= simple_direct_hpel_hpel_get_mb_score(s, mx, my, 0, 0, &s->last_picture, mv_penalty);
- }
-
- s->b_direct_mv_table[mot_xy][0]= mx;
- s->b_direct_mv_table[mot_xy][1]= my;
- return dmin;
-}
-
-void ff_estimate_b_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y)
-{
- const int penalty_factor= s->me.mb_penalty_factor;
- int fmin, bmin, dmin, fbmin;
- int type=0;
-
- s->me.skip=0;
- if (s->codec_id == CODEC_ID_MPEG4)
- dmin= direct_search(s, mb_x, mb_y);
- else
- dmin= INT_MAX;
-
- s->me.skip=0;
- fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, &s->last_picture, s->f_code) + 3*penalty_factor;
-
- s->me.skip=0;
- bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, &s->next_picture, s->b_code) + 2*penalty_factor;
-//printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
-
- s->me.skip=0;
- fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
-//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);
- {
- int score= fmin;
- type = MB_TYPE_FORWARD;
-
- if (dmin <= score){
- score = dmin;
- type = MB_TYPE_DIRECT;
- }
- if(bmin<score){
- score=bmin;
- type= MB_TYPE_BACKWARD;
- }
- if(fbmin<score){
- score=fbmin;
- type= MB_TYPE_BIDIR;
- }
-
- score= ((unsigned)(score*score + 128*256))>>16;
- s->current_picture.mc_mb_var_sum += score;
- s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE
- }
-
- if(s->avctx->mb_decision > FF_MB_DECISION_SIMPLE){
- type= MB_TYPE_FORWARD | MB_TYPE_BACKWARD | MB_TYPE_BIDIR | MB_TYPE_DIRECT; //FIXME something smarter
- if(dmin>256*256*16) type&= ~MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB
- }
-
- s->mb_type[mb_y*s->mb_stride + mb_x]= type;
-}
-
-/* find best f_code for ME which do unlimited searches */
-int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type)
-{
- if(s->me_method>=ME_EPZS){
- int score[8];
- int i, y;
- uint8_t * fcode_tab= s->fcode_tab;
- int best_fcode=-1;
- int best_score=-10000000;
-
- for(i=0; i<8; i++) score[i]= s->mb_num*(8-i);
-
- for(y=0; y<s->mb_height; y++){
- int x;
- int xy= y*s->mb_stride;
- for(x=0; x<s->mb_width; x++){
- if(s->mb_type[xy] & type){
- int fcode= FFMAX(fcode_tab[mv_table[xy][0] + MAX_MV],
- fcode_tab[mv_table[xy][1] + MAX_MV]);
- int j;
-
- for(j=0; j<fcode && j<8; j++){
- if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy])
- score[j]-= 170;
- }
- }
- xy++;
- }
- }
-
- for(i=1; i<8; i++){
- if(score[i] > best_score){
- best_score= score[i];
- best_fcode= i;
- }
-// printf("%d %d\n", i, score[i]);
- }
-
-// printf("fcode: %d type: %d\n", i, s->pict_type);
- return best_fcode;
-/* for(i=0; i<=MAX_FCODE; i++){
- printf("%d ", mv_num[i]);
- }
- printf("\n");*/
- }else{
- return 1;
- }
-}
-
-void ff_fix_long_p_mvs(MpegEncContext * s)
-{
- const int f_code= s->f_code;
- int y, range;
- assert(s->pict_type==P_TYPE);
-
- range = (((s->out_format == FMT_MPEG1) ? 8 : 16) << f_code);
-
- if(s->msmpeg4_version) range= 16;
-
- if(s->avctx->me_range && range > s->avctx->me_range) range= s->avctx->me_range;
-
- /* clip / convert to intra 16x16 type MVs */
- for(y=0; y<s->mb_height; y++){
- int x;
- int xy= y*s->mb_stride;
- for(x=0; x<s->mb_width; x++){
- if(s->mb_type[xy]&MB_TYPE_INTER){
- if( s->p_mv_table[xy][0] >=range || s->p_mv_table[xy][0] <-range
- || s->p_mv_table[xy][1] >=range || s->p_mv_table[xy][1] <-range){
- s->mb_type[xy] &= ~MB_TYPE_INTER;
- s->mb_type[xy] |= MB_TYPE_INTRA;
- s->p_mv_table[xy][0] = 0;
- s->p_mv_table[xy][1] = 0;
- }
- }
- xy++;
- }
- }
-//printf("%d no:%d %d//\n", clip, noclip, f_code);
- if(s->flags&CODEC_FLAG_4MV){
- const int wrap= 2+ s->mb_width*2;
-
- /* clip / convert to intra 8x8 type MVs */
- for(y=0; y<s->mb_height; y++){
- int xy= (y*2 + 1)*wrap + 1;
- int i= y*s->mb_stride;
- int x;
-
- for(x=0; x<s->mb_width; x++){
- if(s->mb_type[i]&MB_TYPE_INTER4V){
- int block;
- for(block=0; block<4; block++){
- int off= (block& 1) + (block>>1)*wrap;
- int mx= s->motion_val[ xy + off ][0];
- int my= s->motion_val[ xy + off ][1];
-
- if( mx >=range || mx <-range
- || my >=range || my <-range){
- s->mb_type[i] &= ~MB_TYPE_INTER4V;
- s->mb_type[i] |= MB_TYPE_INTRA;
- }
- }
- }
- xy+=2;
- i++;
- }
- }
- }
-}
-
-void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type)
-{
- int y;
-
- // RAL: 8 in MPEG-1, 16 in MPEG-4
- int range = (((s->out_format == FMT_MPEG1) ? 8 : 16) << f_code);
-
- if(s->avctx->me_range && range > s->avctx->me_range) range= s->avctx->me_range;
-
- /* clip / convert to intra 16x16 type MVs */
- for(y=0; y<s->mb_height; y++){
- int x;
- int xy= y*s->mb_stride;
- for(x=0; x<s->mb_width; x++){
- if (s->mb_type[xy] & type){ // RAL: "type" test added...
- if( mv_table[xy][0] >=range || mv_table[xy][0] <-range
- || mv_table[xy][1] >=range || mv_table[xy][1] <-range){
-
- if(s->codec_id == CODEC_ID_MPEG1VIDEO && 0){
- }else{
- if (mv_table[xy][0] > range-1) mv_table[xy][0]= range-1;
- else if(mv_table[xy][0] < -range ) mv_table[xy][0]= -range;
- if (mv_table[xy][1] > range-1) mv_table[xy][1]= range-1;
- else if(mv_table[xy][1] < -range ) mv_table[xy][1]= -range;
- }
- }
- }
- xy++;
- }
- }
-}
+++ /dev/null
-/*
- * Motion estimation
- * Copyright (c) 2002 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file motion_est_template.c
- * Motion estimation template.
- */
-
-//lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
-//Note, the last line is there to kill these ugly unused var warnings
-#define LOAD_COMMON(x, y)\
- uint32_t * const score_map= s->me.score_map;\
- const int stride= s->linesize;\
- const int uvstride= s->uvlinesize;\
- const int time_pp= s->pp_time;\
- const int time_pb= s->pb_time;\
- uint8_t * const src_y= s->new_picture.data[0] + ((y) * stride) + (x);\
- uint8_t * const src_u= s->new_picture.data[1] + (((y)>>1) * uvstride) + ((x)>>1);\
- uint8_t * const src_v= s->new_picture.data[2] + (((y)>>1) * uvstride) + ((x)>>1);\
- uint8_t * const ref_y= ref_picture->data[0] + ((y) * stride) + (x);\
- uint8_t * const ref_u= ref_picture->data[1] + (((y)>>1) * uvstride) + ((x)>>1);\
- uint8_t * const ref_v= ref_picture->data[2] + (((y)>>1) * uvstride) + ((x)>>1);\
- uint8_t * const ref2_y= s->next_picture.data[0] + ((y) * stride) + (x);\
- op_pixels_func (*hpel_put)[4];\
- op_pixels_func (*hpel_avg)[4]= &s->dsp.avg_pixels_tab[size];\
- op_pixels_func (*chroma_hpel_put)[4];\
- qpel_mc_func (*qpel_put)[16];\
- qpel_mc_func (*qpel_avg)[16]= &s->dsp.avg_qpel_pixels_tab[size];\
- const __attribute__((unused)) int unu= time_pp + time_pb + (size_t)src_u + (size_t)src_v + (size_t)ref_u + (size_t)ref_v\
- + (size_t)ref2_y + (size_t)hpel_avg + (size_t)qpel_avg + (size_t)score_map;\
- if(s->no_rounding /*FIXME b_type*/){\
- hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];\
- chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];\
- qpel_put= &s->dsp.put_no_rnd_qpel_pixels_tab[size];\
- }else{\
- hpel_put=& s->dsp.put_pixels_tab[size];\
- chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];\
- qpel_put= &s->dsp.put_qpel_pixels_tab[size];\
- }
-
-
-#ifdef CMP_HPEL
-
-#define CHECK_HALF_MV(dx, dy, x, y)\
-{\
- const int hx= 2*(x)+(dx);\
- const int hy= 2*(y)+(dy);\
- CMP_HPEL(d, dx, dy, x, y, size);\
- d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
- COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
-}
-
-#if 0
-static int RENAME(hpel_motion_search)(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *ref_picture,
- int n, int size, uint8_t * const mv_penalty)
-{
- const int xx = 16 * s->mb_x + 8*(n&1);
- const int yy = 16 * s->mb_y + 8*(n>>1);
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= s->me.sub_penalty_factor;
-
- LOAD_COMMON(xx, yy);
-
- // INIT;
- //FIXME factorize
- me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
-
- if(s->no_rounding /*FIXME b_type*/){
- hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
- }else{
- hpel_put=& s->dsp.put_pixels_tab[size];
- chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
- }
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(s->me.skip){ //FIXME somehow move up (benchmark)
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
- CMP_HPEL(dmin, 0, 0, mx, my, size);
- if(mx || my)
- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int bx=2*mx, by=2*my;
- int d= dmin;
-
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- CHECK_HALF_MV(0, 1, mx , my-1)
- CHECK_HALF_MV(1, 1, mx , my-1)
- CHECK_HALF_MV(1, 0, mx-1, my )
- CHECK_HALF_MV(1, 0, mx , my )
- CHECK_HALF_MV(1, 1, mx-1, my )
- CHECK_HALF_MV(0, 1, mx , my )
- CHECK_HALF_MV(1, 1, mx , my )
-
- assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
-
- *mx_ptr = bx;
- *my_ptr = by;
- }else{
- *mx_ptr =2*mx;
- *my_ptr =2*my;
- }
-
- return dmin;
-}
-
-#else
-static int RENAME(hpel_motion_search)(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *ref_picture,
- int n, int size, uint8_t * const mv_penalty)
-{
- const int xx = 16 * s->mb_x + 8*(n&1);
- const int yy = 16 * s->mb_y + 8*(n>>1);
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= s->me.sub_penalty_factor;
- me_cmp_func cmp_sub, chroma_cmp_sub;
- int bx=2*mx, by=2*my;
-
- LOAD_COMMON(xx, yy);
-
- //FIXME factorize
-
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(s->me.skip){ //FIXME move out of hpel?
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
- CMP_HPEL(dmin, 0, 0, mx, my, size);
- if(mx || my || size>0)
- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int d= dmin;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*s->me.penalty_factor;
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor;
- const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
- + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*s->me.penalty_factor;
-
-#if 1
- int key;
- int map_generation= s->me.map_generation;
-#ifndef NDEBUG
- uint32_t *map= s->me.map;
-#endif
- key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
- assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
- key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
- assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
- key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
- assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
- key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
- assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
-#endif
- if(t<=b){
- CHECK_HALF_MV(0, 1, mx ,my-1)
- if(l<=r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- if(t+r<=b+l){
- CHECK_HALF_MV(1, 1, mx , my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx-1, my )
- }
- CHECK_HALF_MV(1, 0, mx-1, my )
- }else{
- CHECK_HALF_MV(1, 1, mx , my-1)
- if(t+l<=b+r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx , my )
- }
- CHECK_HALF_MV(1, 0, mx , my )
- }
- }else{
- if(l<=r){
- if(t+l<=b+r){
- CHECK_HALF_MV(1, 1, mx-1, my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx , my )
- }
- CHECK_HALF_MV(1, 0, mx-1, my)
- CHECK_HALF_MV(1, 1, mx-1, my)
- }else{
- if(t+r<=b+l){
- CHECK_HALF_MV(1, 1, mx , my-1)
- }else{
- CHECK_HALF_MV(1, 1, mx-1, my)
- }
- CHECK_HALF_MV(1, 0, mx , my)
- CHECK_HALF_MV(1, 1, mx , my)
- }
- CHECK_HALF_MV(0, 1, mx , my)
- }
- assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);
- }
-
- *mx_ptr = bx;
- *my_ptr = by;
-
- return dmin;
-}
-#endif
-
-static int RENAME(hpel_get_mb_score)(MpegEncContext * s, int mx, int my, int pred_x, int pred_y, Picture *ref_picture,
- uint8_t * const mv_penalty)
-{
-// const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
- const int size= 0;
- const int xx = 16 * s->mb_x;
- const int yy = 16 * s->mb_y;
- const int penalty_factor= s->me.mb_penalty_factor;
- const int xmin= -256*256, ymin= -256*256, xmax= 256*256, ymax= 256*256; //assume that the caller checked these
- const __attribute__((unused)) int unu2= xmin + xmax +ymin + ymax; //no unused warning shit
- me_cmp_func cmp_sub, chroma_cmp_sub;
- int d;
-
- LOAD_COMMON(xx, yy);
-
- //FIXME factorize
-
- cmp_sub= s->dsp.mb_cmp[size];
- chroma_cmp_sub= s->dsp.mb_cmp[size+1];
-
- assert(!s->me.skip);
- assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
-
- CMP_HPEL(d, mx&1, my&1, mx>>1, my>>1, size);
- //FIXME check cbp before adding penalty for (0,0) vector
- if(mx || my || size>0)
- d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
-
- return d;
-}
-
-#endif /* CMP_HPEL */
-
-
-
-#ifdef CMP_QPEL
-
-#define CHECK_QUARTER_MV(dx, dy, x, y)\
-{\
- const int hx= 4*(x)+(dx);\
- const int hy= 4*(y)+(dy);\
- CMP_QPEL(d, dx, dy, x, y, size);\
- d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
- COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
-}
-
-static int RENAME(qpel_motion_search)(MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *ref_picture,
- int n, int size, uint8_t * const mv_penalty)
-{
- const int xx = 16 * s->mb_x + 8*(n&1);
- const int yy = 16 * s->mb_y + 8*(n>>1);
- const int mx = *mx_ptr;
- const int my = *my_ptr;
- const int penalty_factor= s->me.sub_penalty_factor;
- const int map_generation= s->me.map_generation;
- const int subpel_quality= s->avctx->me_subpel_quality;
- uint32_t *map= s->me.map;
- me_cmp_func cmp, chroma_cmp;
- me_cmp_func cmp_sub, chroma_cmp_sub;
-
- LOAD_COMMON(xx, yy);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1]; //factorize FIXME
- //FIXME factorize
-
- cmp_sub= s->dsp.me_sub_cmp[size];
- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
-
- if(s->me.skip){ //FIXME somehow move up (benchmark)
- *mx_ptr = 0;
- *my_ptr = 0;
- return dmin;
- }
-
- if(s->avctx->me_cmp != s->avctx->me_sub_cmp){
- CMP_QPEL(dmin, 0, 0, mx, my, size);
- if(mx || my || size>0)
- dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
- }
-
- if (mx > xmin && mx < xmax &&
- my > ymin && my < ymax) {
- int bx=4*mx, by=4*my;
- int d= dmin;
- int i, nx, ny;
- const int index= (my<<ME_MAP_SHIFT) + mx;
- const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
- const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
- const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
- const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
- const int c= score_map[(index )&(ME_MAP_SIZE-1)];
- int best[8];
- int best_pos[8][2];
-
- memset(best, 64, sizeof(int)*8);
-#if 1
- if(s->me.dia_size>=2){
- const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
- const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
-
- for(ny= -3; ny <= 3; ny++){
- for(nx= -3; nx <= 3; nx++){
- const int t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
- const int c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
- const int b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
- int score= ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2;
- int i;
-
- if((nx&3)==0 && (ny&3)==0) continue;
-
- score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
-
-// if(nx&1) score-=1024*s->me.penalty_factor;
-// if(ny&1) score-=1024*s->me.penalty_factor;
-
- for(i=0; i<8; i++){
- if(score < best[i]){
- memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
- memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
- best[i]= score;
- best_pos[i][0]= nx + 4*mx;
- best_pos[i][1]= ny + 4*my;
- break;
- }
- }
- }
- }
- }else{
- int tl;
- const int cx = 4*(r - l);
- const int cx2= r + l - 2*c;
- const int cy = 4*(b - t);
- const int cy2= b + t - 2*c;
- int cxy;
-
- if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){ //FIXME
- tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- }else{
- CMP(tl, mx-1, my-1, size); //FIXME wrong if chroma me is different
- }
-
- cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
-
- assert(16*cx2 + 4*cx + 32*c == 32*r);
- assert(16*cx2 - 4*cx + 32*c == 32*l);
- assert(16*cy2 + 4*cy + 32*c == 32*b);
- assert(16*cy2 - 4*cy + 32*c == 32*t);
- assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
-
- for(ny= -3; ny <= 3; ny++){
- for(nx= -3; nx <= 3; nx++){
- int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor
- int i;
-
- if((nx&3)==0 && (ny&3)==0) continue;
-
- score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
-// if(nx&1) score-=32*s->me.penalty_factor;
- // if(ny&1) score-=32*s->me.penalty_factor;
-
- for(i=0; i<8; i++){
- if(score < best[i]){
- memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
- memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
- best[i]= score;
- best_pos[i][0]= nx + 4*mx;
- best_pos[i][1]= ny + 4*my;
- break;
- }
- }
- }
- }
- }
- for(i=0; i<subpel_quality; i++){
- nx= best_pos[i][0];
- ny= best_pos[i][1];
- CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
- }
-
-#if 0
- const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
- const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
- const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
-// if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
- if(tl<br){
-
-// nx= FFMAX(4*mx - bx, bx - 4*mx);
-// ny= FFMAX(4*my - by, by - 4*my);
-
- static int stats[7][7], count;
- count++;
- stats[4*mx - bx + 3][4*my - by + 3]++;
- if(256*256*256*64 % count ==0){
- for(i=0; i<49; i++){
- if((i%7)==0) printf("\n");
- printf("%6d ", stats[0][i]);
- }
- printf("\n");
- }
- }
-#endif
-#else
-
- CHECK_QUARTER_MV(2, 2, mx-1, my-1)
- CHECK_QUARTER_MV(0, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 2, mx , my-1)
- CHECK_QUARTER_MV(2, 0, mx , my )
- CHECK_QUARTER_MV(2, 2, mx , my )
- CHECK_QUARTER_MV(0, 2, mx , my )
- CHECK_QUARTER_MV(2, 2, mx-1, my )
- CHECK_QUARTER_MV(2, 0, mx-1, my )
-
- nx= bx;
- ny= by;
-
- for(i=0; i<8; i++){
- int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
- int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
- CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
- }
-#endif
-#if 0
- //outer ring
- CHECK_QUARTER_MV(1, 3, mx-1, my-1)
- CHECK_QUARTER_MV(1, 2, mx-1, my-1)
- CHECK_QUARTER_MV(1, 1, mx-1, my-1)
- CHECK_QUARTER_MV(2, 1, mx-1, my-1)
- CHECK_QUARTER_MV(3, 1, mx-1, my-1)
- CHECK_QUARTER_MV(0, 1, mx , my-1)
- CHECK_QUARTER_MV(1, 1, mx , my-1)
- CHECK_QUARTER_MV(2, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 1, mx , my-1)
- CHECK_QUARTER_MV(3, 2, mx , my-1)
- CHECK_QUARTER_MV(3, 3, mx , my-1)
- CHECK_QUARTER_MV(3, 0, mx , my )
- CHECK_QUARTER_MV(3, 1, mx , my )
- CHECK_QUARTER_MV(3, 2, mx , my )
- CHECK_QUARTER_MV(3, 3, mx , my )
- CHECK_QUARTER_MV(2, 3, mx , my )
- CHECK_QUARTER_MV(1, 3, mx , my )
- CHECK_QUARTER_MV(0, 3, mx , my )
- CHECK_QUARTER_MV(3, 3, mx-1, my )
- CHECK_QUARTER_MV(2, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 3, mx-1, my )
- CHECK_QUARTER_MV(1, 2, mx-1, my )
- CHECK_QUARTER_MV(1, 1, mx-1, my )
- CHECK_QUARTER_MV(1, 0, mx-1, my )
-#endif
- assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
-
- *mx_ptr = bx;
- *my_ptr = by;
- }else{
- *mx_ptr =4*mx;
- *my_ptr =4*my;
- }
-
- return dmin;
-}
-
-static int RENAME(qpel_get_mb_score)(MpegEncContext * s, int mx, int my, int pred_x, int pred_y, Picture *ref_picture,
- uint8_t * const mv_penalty)
-{
- const int size= 0;
- const int xx = 16 * s->mb_x;
- const int yy = 16 * s->mb_y;
- const int penalty_factor= s->me.mb_penalty_factor;
- const int xmin= -256*256, ymin= -256*256, xmax= 256*256, ymax= 256*256; //assume that the caller checked these
- const __attribute__((unused)) int unu2= xmin + xmax +ymin + ymax; //no unused warning shit
- me_cmp_func cmp_sub, chroma_cmp_sub;
- int d;
-
- LOAD_COMMON(xx, yy);
-
- //FIXME factorize
-
- cmp_sub= s->dsp.mb_cmp[size];
- chroma_cmp_sub= s->dsp.mb_cmp[size+1];
-
- assert(!s->me.skip);
- assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
-
- CMP_QPEL(d, mx&3, my&3, mx>>2, my>>2, size);
- //FIXME check cbp before adding penalty for (0,0) vector
- if(mx || my || size>0)
- d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
-
- return d;
-}
-
-
-#endif /* CMP_QPEL */
-
-#define CHECK_MV(x,y)\
-{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
- const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
-/*printf("check_mv %d %d\n", x, y);*/\
- if(map[index]!=key){\
- CMP(d, x, y, size);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
-/*printf("score:%d\n", d);*/\
- COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
- }\
-}
-
-#define CHECK_CLIPED_MV(ax,ay)\
-{\
- const int x= FFMAX(xmin, FFMIN(ax, xmax));\
- const int y= FFMAX(ymin, FFMIN(ay, ymax));\
- CHECK_MV(x, y)\
-}
-
-#define CHECK_MV_DIR(x,y,new_dir)\
-{\
- const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
- const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
-/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
- if(map[index]!=key){\
- CMP(d, x, y, size);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
-/*printf("score:%d\n", d);*/\
- if(d<dmin){\
- best[0]=x;\
- best[1]=y;\
- dmin=d;\
- next_dir= new_dir;\
- }\
- }\
-}
-
-#define check(x,y,S,v)\
-if( (x)<(xmin<<(S)) ) printf("%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
-if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
-if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
-if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
-
-
-static inline int RENAME(small_diamond_search)(MpegEncContext * s, int *best, int dmin,
- Picture *ref_picture,
- int const pred_x, int const pred_y, int const penalty_factor,
- int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
- uint32_t *map, int map_generation, int size, uint8_t * const mv_penalty
- )
-{
- me_cmp_func cmp, chroma_cmp;
- int next_dir=-1;
- LOAD_COMMON(s->mb_x*16, s->mb_y*16);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
- const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
- const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
- if(map[index]!=key){ //this will be executed only very rarey
- CMP(score_map[index], best[0], best[1], size);
- map[index]= key;
- }
- }
-
- for(;;){
- int d;
- const int dir= next_dir;
- const int x= best[0];
- const int y= best[1];
- next_dir=-1;
-
-//printf("%d", dir);
- if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
- if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
- if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
- if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
-
- if(next_dir==-1){
- return dmin;
- }
- }
-}
-
-static inline int RENAME(funny_diamond_search)(MpegEncContext * s, int *best, int dmin,
- Picture *ref_picture,
- int const pred_x, int const pred_y, int const penalty_factor,
- int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
- uint32_t *map, int map_generation, int size, uint8_t * const mv_penalty
- )
-{
- me_cmp_func cmp, chroma_cmp;
- int dia_size;
- LOAD_COMMON(s->mb_x*16, s->mb_y*16);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- for(dia_size=1; dia_size<=4; dia_size++){
- int dir;
- const int x= best[0];
- const int y= best[1];
-
- if(dia_size&(dia_size-1)) continue;
-
- if( x + dia_size > xmax
- || x - dia_size < xmin
- || y + dia_size > ymax
- || y - dia_size < ymin)
- continue;
-
- for(dir= 0; dir<dia_size; dir+=2){
- int d;
-
- CHECK_MV(x + dir , y + dia_size - dir);
- CHECK_MV(x + dia_size - dir, y - dir );
- CHECK_MV(x - dir , y - dia_size + dir);
- CHECK_MV(x - dia_size + dir, y + dir );
- }
-
- if(x!=best[0] || y!=best[1])
- dia_size=0;
-#if 0
-{
-int dx, dy, i;
-static int stats[8*8];
-dx= ABS(x-best[0]);
-dy= ABS(y-best[1]);
-if(dy>dx){
- dx^=dy; dy^=dx; dx^=dy;
-}
-stats[dy*8 + dx] ++;
-if(256*256*256*64 % (stats[0]+1)==0){
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%8d ", stats[i]);
- }
- printf("\n");
-}
-}
-#endif
- }
- return dmin;
-}
-
-#define SAB_CHECK_MV(ax,ay)\
-{\
- const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
- const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
-/*printf("sab check %d %d\n", ax, ay);*/\
- if(map[index]!=key){\
- CMP(d, ax, ay, size);\
- map[index]= key;\
- score_map[index]= d;\
- d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
-/*printf("score: %d\n", d);*/\
- if(d < minima[minima_count-1].height){\
- int j=0;\
- \
- while(d >= minima[j].height) j++;\
-\
- memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
-\
- minima[j].checked= 0;\
- minima[j].height= d;\
- minima[j].x= ax;\
- minima[j].y= ay;\
- \
- i=-1;\
- continue;\
- }\
- }\
-}
-
-#define MAX_SAB_SIZE 16
-static inline int RENAME(sab_diamond_search)(MpegEncContext * s, int *best, int dmin,
- Picture *ref_picture,
- int const pred_x, int const pred_y, int const penalty_factor,
- int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
- uint32_t *map, int map_generation, int size, uint8_t * const mv_penalty
- )
-{
- me_cmp_func cmp, chroma_cmp;
- Minima minima[MAX_SAB_SIZE];
- const int minima_count= ABS(s->me.dia_size);
- int i, j;
- LOAD_COMMON(s->mb_x*16, s->mb_y*16);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- for(j=i=0; i<ME_MAP_SIZE; i++){
- uint32_t key= map[i];
-
- key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
-
- if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
-
- assert(j<MAX_SAB_SIZE); //max j = number of predictors
-
- minima[j].height= score_map[i];
- minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
- minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
- minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
- minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
- minima[j].checked=0;
- if(minima[j].x || minima[j].y)
- minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
-
- j++;
- }
-
- qsort(minima, j, sizeof(Minima), minima_cmp);
-
- for(; j<minima_count; j++){
- minima[j].height=256*256*256*64;
- minima[j].checked=0;
- minima[j].x= minima[j].y=0;
- }
-
- for(i=0; i<minima_count; i++){
- const int x= minima[i].x;
- const int y= minima[i].y;
- int d;
-
- if(minima[i].checked) continue;
-
- if( x >= xmax || x <= xmin
- || y >= ymax || y <= ymin)
- continue;
-
- SAB_CHECK_MV(x-1, y)
- SAB_CHECK_MV(x+1, y)
- SAB_CHECK_MV(x , y-1)
- SAB_CHECK_MV(x , y+1)
-
- minima[i].checked= 1;
- }
-
- best[0]= minima[0].x;
- best[1]= minima[0].y;
- dmin= minima[0].height;
-
- if( best[0] < xmax && best[0] > xmin
- && best[1] < ymax && best[1] > ymin){
- int d;
- //ensure that the refernece samples for hpel refinement are in the map
- CHECK_MV(best[0]-1, best[1])
- CHECK_MV(best[0]+1, best[1])
- CHECK_MV(best[0], best[1]-1)
- CHECK_MV(best[0], best[1]+1)
- }
- return dmin;
-}
-
-static inline int RENAME(var_diamond_search)(MpegEncContext * s, int *best, int dmin,
- Picture *ref_picture,
- int const pred_x, int const pred_y, int const penalty_factor,
- int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
- uint32_t *map, int map_generation, int size, uint8_t * const mv_penalty
- )
-{
- me_cmp_func cmp, chroma_cmp;
- int dia_size;
- LOAD_COMMON(s->mb_x*16, s->mb_y*16);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- for(dia_size=1; dia_size<=s->me.dia_size; dia_size++){
- int dir, start, end;
- const int x= best[0];
- const int y= best[1];
-
- start= FFMAX(0, y + dia_size - ymax);
- end = FFMIN(dia_size, xmax - x + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x + dir,y + dia_size - dir,0, a0)
- CHECK_MV(x + dir , y + dia_size - dir);
- }
-
- start= FFMAX(0, x + dia_size - xmax);
- end = FFMIN(dia_size, y - ymin + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x + dia_size - dir, y - dir,0, a1)
- CHECK_MV(x + dia_size - dir, y - dir );
- }
-
- start= FFMAX(0, -y + dia_size + ymin );
- end = FFMIN(dia_size, x - xmin + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x - dir,y - dia_size + dir,0, a2)
- CHECK_MV(x - dir , y - dia_size + dir);
- }
-
- start= FFMAX(0, -x + dia_size + xmin );
- end = FFMIN(dia_size, ymax - y + 1);
- for(dir= start; dir<end; dir++){
- int d;
-
-//check(x - dia_size + dir, y + dir,0, a3)
- CHECK_MV(x - dia_size + dir, y + dir );
- }
-
- if(x!=best[0] || y!=best[1])
- dia_size=0;
-#if 0
-{
-int dx, dy, i;
-static int stats[8*8];
-dx= ABS(x-best[0]);
-dy= ABS(y-best[1]);
-stats[dy*8 + dx] ++;
-if(256*256*256*64 % (stats[0]+1)==0){
- for(i=0; i<64; i++){
- if((i&7)==0) printf("\n");
- printf("%6d ", stats[i]);
- }
- printf("\n");
-}
-}
-#endif
- }
- return dmin;
-}
-
-static int RENAME(epzs_motion_search)(MpegEncContext * s, int block,
- int *mx_ptr, int *my_ptr,
- int P[10][2], int pred_x, int pred_y,
- int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2],
- int ref_mv_scale, uint8_t * const mv_penalty)
-{
- int best[2]={0, 0};
- int d, dmin;
- const int shift= 1+s->quarter_sample;
- uint32_t *map= s->me.map;
- int map_generation;
- const int penalty_factor= s->me.penalty_factor;
- const int size=0;
- const int ref_mv_stride= s->mb_stride;
- const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;
- me_cmp_func cmp, chroma_cmp;
- LOAD_COMMON(s->mb_x*16, s->mb_y*16);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- map_generation= update_map_generation(s);
-
- CMP(dmin, 0, 0, size);
- map[0]= map_generation;
- score_map[0]= dmin;
-
- /* first line */
- if (s->mb_y == 0) {
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- }else{
- if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
- |P_TOP[0] |P_TOP[1]
- |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
- *mx_ptr= 0;
- *my_ptr= 0;
- s->me.skip=1;
- return dmin;
- }
- CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
- if(dmin>256*2){
- CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
- CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
- CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
- }
- }
- if(dmin>256*4){
- if(s->me.pre_pass){
- CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }else{
- CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }
- }
-
- if(s->avctx->last_predictor_count){
- const int count= s->avctx->last_predictor_count;
- const int xstart= FFMAX(0, s->mb_x - count);
- const int ystart= FFMAX(0, s->mb_y - count);
- const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
- const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
- int mb_y;
-
- for(mb_y=ystart; mb_y<yend; mb_y++){
- int mb_x;
- for(mb_x=xstart; mb_x<xend; mb_x++){
- const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
- int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
- int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
-
- if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
- CHECK_MV(mx,my)
- }
- }
- }
-
-//check(best[0],best[1],0, b0)
- if(s->me.dia_size==-1)
- dmin= RENAME(funny_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else if(s->me.dia_size<-1)
- dmin= RENAME(sab_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else if(s->me.dia_size<2)
- dmin= RENAME(small_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else
- dmin= RENAME(var_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
-
-//check(best[0],best[1],0, b1)
- *mx_ptr= best[0];
- *my_ptr= best[1];
-
-// printf("%d %d %d \n", best[0], best[1], dmin);
- return dmin;
-}
-
-#ifndef CMP_DIRECT /* no 4mv search needed in direct mode */
-static int RENAME(epzs_motion_search4)(MpegEncContext * s, int block,
- int *mx_ptr, int *my_ptr,
- int P[10][2], int pred_x, int pred_y,
- int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2],
- int ref_mv_scale, uint8_t * const mv_penalty)
-{
- int best[2]={0, 0};
- int d, dmin;
- const int shift= 1+s->quarter_sample;
- uint32_t *map= s->me.map;
- int map_generation;
- const int penalty_factor= s->me.penalty_factor;
- const int size=1;
- const int ref_mv_stride= s->mb_stride;
- const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
- me_cmp_func cmp, chroma_cmp;
- LOAD_COMMON((s->mb_x*2 + (block&1))*8, (s->mb_y*2 + (block>>1))*8);
-
- cmp= s->dsp.me_cmp[size];
- chroma_cmp= s->dsp.me_cmp[size+1];
-
- map_generation= update_map_generation(s);
-
- dmin = 1000000;
-//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
- /* first line */
- if (s->mb_y == 0 && block<2) {
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- }else{
- CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
- //FIXME try some early stop
- if(dmin>64*2){
- CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
- CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
- CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
- CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
- }
- }
- if(dmin>64*4){
- CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
- CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
- (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
- }
-
- if(s->me.dia_size==-1)
- dmin= RENAME(funny_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else if(s->me.dia_size<-1)
- dmin= RENAME(sab_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else if(s->me.dia_size<2)
- dmin= RENAME(small_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
- else
- dmin= RENAME(var_diamond_search)(s, best, dmin, ref_picture,
- pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax,
- shift, map, map_generation, size, mv_penalty);
-
- *mx_ptr= best[0];
- *my_ptr= best[1];
-
-// printf("%d %d %d \n", best[0], best[1], dmin);
- return dmin;
-}
-#endif /* !CMP_DIRECT */
+++ /dev/null
-/* motion test. (c) 2001 Fabrice Bellard. */
-
-/**
- * @file motion_test.c
- * motion test.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
-
-#include "dsputil.h"
-
-#include "i386/mmx.h"
-
-int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx);
-int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx);
-
-typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx);
-
-#define WIDTH 64
-#define HEIGHT 64
-
-uint8_t img1[WIDTH * HEIGHT];
-uint8_t img2[WIDTH * HEIGHT];
-
-void fill_random(uint8_t *tab, int size)
-{
- int i;
- for(i=0;i<size;i++) {
-#if 1
- tab[i] = random() % 256;
-#else
- tab[i] = i;
-#endif
- }
-}
-
-void help(void)
-{
- printf("motion-test [-h]\n"
- "test motion implementations\n");
- exit(1);
-}
-
-int64_t gettime(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-}
-
-#define NB_ITS 500
-
-int dummy;
-
-void test_motion(const char *name,
- motion_func *test_func, motion_func *ref_func)
-{
- int x, y, d1, d2, it;
- uint8_t *ptr;
- int64_t ti;
- printf("testing '%s'\n", name);
-
- /* test correctness */
- for(it=0;it<20;it++) {
-
- fill_random(img1, WIDTH * HEIGHT);
- fill_random(img2, WIDTH * HEIGHT);
-
- for(y=0;y<HEIGHT-17;y++) {
- for(x=0;x<WIDTH-17;x++) {
- ptr = img2 + y * WIDTH + x;
- d1 = test_func(img1, ptr, WIDTH);
- d2 = ref_func(img1, ptr, WIDTH);
- if (d1 != d2) {
- printf("error: mmx=%d c=%d\n", d1, d2);
- }
- }
- }
- }
- emms();
-
- /* speed test */
- ti = gettime();
- d1 = 0;
- for(it=0;it<NB_ITS;it++) {
- for(y=0;y<HEIGHT-17;y++) {
- for(x=0;x<WIDTH-17;x++) {
- ptr = img2 + y * WIDTH + x;
- d1 += test_func(img1, ptr, WIDTH);
- }
- }
- }
- emms();
- dummy = d1; /* avoid optimisation */
- ti = gettime() - ti;
-
- printf(" %0.0f kop/s\n",
- (double)NB_ITS * (WIDTH - 16) * (HEIGHT - 16) /
- (double)(ti / 1000.0));
-}
-
-
-int main(int argc, char **argv)
-{
- int c;
-
- for(;;) {
- c = getopt(argc, argv, "h");
- if (c == -1)
- break;
- switch(c) {
- case 'h':
- help();
- break;
- }
- }
-
- printf("ffmpeg motion test\n");
-
- test_motion("mmx", pix_abs16x16_mmx, pix_abs16x16_c);
- test_motion("mmx_x2", pix_abs16x16_x2_mmx, pix_abs16x16_x2_c);
- test_motion("mmx_y2", pix_abs16x16_y2_mmx, pix_abs16x16_y2_c);
- test_motion("mmx_xy2", pix_abs16x16_xy2_mmx, pix_abs16x16_xy2_c);
- return 0;
-}
+++ /dev/null
-/*
- * Interface to libmp3lame for mp3 encoding
- * Copyright (c) 2002 Lennert Buytenhek <buytenh@gnu.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mp3lameaudio.c
- * Interface to libmp3lame for mp3 encoding.
- */
-
-#include "avcodec.h"
-#include "mpegaudio.h"
-#include <lame/lame.h>
-
-typedef struct Mp3AudioContext {
- lame_global_flags *gfp;
- int stereo;
-} Mp3AudioContext;
-
-
-static int MP3lame_encode_init(AVCodecContext *avctx)
-{
- Mp3AudioContext *s = avctx->priv_data;
-
- if (avctx->channels > 2)
- return -1;
-
- s->stereo = avctx->channels > 1 ? 1 : 0;
-
- if ((s->gfp = lame_init()) == NULL)
- goto err;
- lame_set_in_samplerate(s->gfp, avctx->sample_rate);
- lame_set_out_samplerate(s->gfp, avctx->sample_rate);
- lame_set_num_channels(s->gfp, avctx->channels);
- /* lame 3.91 dies on quality != 5 */
- lame_set_quality(s->gfp, 5);
- /* lame 3.91 doesn't work in mono */
- lame_set_mode(s->gfp, JOINT_STEREO);
- lame_set_brate(s->gfp, avctx->bit_rate/1000);
- if (lame_init_params(s->gfp) < 0)
- goto err_close;
-
- avctx->frame_size = MPA_FRAME_SIZE;
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-
-err_close:
- lame_close(s->gfp);
-err:
- return -1;
-}
-
-int MP3lame_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- Mp3AudioContext *s = avctx->priv_data;
- int num;
-
- /* lame 3.91 dies on '1-channel interleaved' data */
- if (s->stereo) {
- num = lame_encode_buffer_interleaved(s->gfp, data,
- MPA_FRAME_SIZE, frame, buf_size);
- } else {
- num = lame_encode_buffer(s->gfp, data, data, MPA_FRAME_SIZE,
- frame, buf_size);
- }
-
- return num;
-}
-
-int MP3lame_encode_close(AVCodecContext *avctx)
-{
- Mp3AudioContext *s = avctx->priv_data;
-
- av_freep(&avctx->coded_frame);
-
- lame_close(s->gfp);
- return 0;
-}
-
-
-AVCodec mp3lame_encoder = {
- "mp3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(Mp3AudioContext),
- MP3lame_encode_init,
- MP3lame_encode_frame,
- MP3lame_encode_close
-};
+++ /dev/null
-/*
- * MPEG1 codec / MPEG2 decoder
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mpeg12.c
- * MPEG1/2 codec
- */
-
-//#define DEBUG
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#include "mpeg12data.h"
-
-
-/* Start codes. */
-#define SEQ_END_CODE 0x000001b7
-#define SEQ_START_CODE 0x000001b3
-#define GOP_START_CODE 0x000001b8
-#define PICTURE_START_CODE 0x00000100
-#define SLICE_MIN_START_CODE 0x00000101
-#define SLICE_MAX_START_CODE 0x000001af
-#define EXT_START_CODE 0x000001b5
-#define USER_START_CODE 0x000001b2
-
-#define DC_VLC_BITS 9
-#define MV_VLC_BITS 9
-#define MBINCR_VLC_BITS 9
-#define MB_PAT_VLC_BITS 9
-#define MB_PTYPE_VLC_BITS 6
-#define MB_BTYPE_VLC_BITS 6
-#define TEX_VLC_BITS 9
-
-static void mpeg1_encode_block(MpegEncContext *s,
- DCTELEM *block,
- int component);
-static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added
-static void mpeg1_skip_picture(MpegEncContext *s, int pict_num);
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n);
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
-
-#ifdef HAVE_XVMC
-extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx);
-extern int XVMC_field_end(MpegEncContext *s);
-#endif
-
-#ifdef CONFIG_ENCODERS
-static uint8_t (*mv_penalty)[MAX_MV*2+1]= NULL;
-static uint8_t fcode_tab[MAX_MV*2+1];
-
-static uint32_t uni_mpeg1_ac_vlc_bits[64*64*2];
-static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
-
-/* simple include everything table for dc, first byte is bits number next 3 are code*/
-static uint32_t mpeg1_lum_dc_uni[512];
-static uint32_t mpeg1_chr_dc_uni[512];
-
-static uint8_t mpeg1_index_run[2][64];
-static int8_t mpeg1_max_level[2][64];
-#endif
-
-static void init_2d_vlc_rl(RLTable *rl)
-{
- int i;
-
- init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2,
- &rl->table_vlc[0][1], 4, 2,
- &rl->table_vlc[0][0], 4, 2);
-
-
- rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
- for(i=0; i<rl->vlc.table_size; i++){
- int code= rl->vlc.table[i][0];
- int len = rl->vlc.table[i][1];
- int level, run;
-
- if(len==0){ // illegal code
- run= 65;
- level= MAX_LEVEL;
- }else if(len<0){ //more bits needed
- run= 0;
- level= code;
- }else{
- if(code==rl->n){ //esc
- run= 65;
- level= 0;
- }else if(code==rl->n+1){ //eob
- run= 0;
- level= 127;
- }else{
- run= rl->table_run [code] + 1;
- level= rl->table_level[code];
- }
- }
- rl->rl_vlc[0][i].len= len;
- rl->rl_vlc[0][i].level= level;
- rl->rl_vlc[0][i].run= run;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-static void init_uni_ac_vlc(RLTable *rl, uint32_t *uni_ac_vlc_bits, uint8_t *uni_ac_vlc_len){
- int i;
-
- for(i=0; i<128; i++){
- int level= i-64;
- int run;
- for(run=0; run<64; run++){
- int len, bits, code;
-
- int alevel= ABS(level);
- int sign= (level>>31)&1;
-
- if (alevel > rl->max_level[0][run])
- code= 111; /*rl->n*/
- else
- code= rl->index_run[0][run] + alevel - 1;
-
- if (code < 111 /* rl->n */) {
- /* store the vlc & sign at once */
- len= mpeg1_vlc[code][1]+1;
- bits= (mpeg1_vlc[code][0]<<1) + sign;
- } else {
- len= mpeg1_vlc[111/*rl->n*/][1]+6;
- bits= mpeg1_vlc[111/*rl->n*/][0]<<6;
-
- bits|= run;
- if (alevel < 128) {
- bits<<=8; len+=8;
- bits|= level & 0xff;
- } else {
- bits<<=16; len+=16;
- bits|= level & 0xff;
- if (level < 0) {
- bits|= 0x8001 + level + 255;
- } else {
- bits|= level & 0xffff;
- }
- }
- }
-
- uni_ac_vlc_bits[UNI_AC_ENC_INDEX(run, i)]= bits;
- uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len;
- }
- }
-}
-
-static void put_header(MpegEncContext *s, int header)
-{
- align_put_bits(&s->pb);
- put_bits(&s->pb, 16, header>>16);
- put_bits(&s->pb, 16, header&0xFFFF);
-}
-
-/* put sequence header if needed */
-static void mpeg1_encode_sequence_header(MpegEncContext *s)
-{
- unsigned int vbv_buffer_size;
- unsigned int fps, v;
- int n, i;
- uint64_t time_code;
- float best_aspect_error= 1E10;
- float aspect_ratio= s->avctx->aspect_ratio;
- int constraint_parameter_flag;
-
- if(aspect_ratio==0.0) aspect_ratio= s->width / (float)s->height; //pixel aspect 1:1 (VGA)
-
- if (s->current_picture.key_frame) {
- /* mpeg1 header repeated every gop */
- put_header(s, SEQ_START_CODE);
-
- /* search closest frame rate */
- {
- int i, dmin, d;
- s->frame_rate_index = 0;
- dmin = 0x7fffffff;
- for(i=1;i<14;i++) {
- if(s->avctx->strict_std_compliance >= 0 && i>=9) break;
-
- d = abs(MPEG1_FRAME_RATE_BASE*(int64_t)s->avctx->frame_rate/s->avctx->frame_rate_base - frame_rate_tab[i]);
- if (d < dmin) {
- dmin = d;
- s->frame_rate_index = i;
- }
- }
- }
-
- put_bits(&s->pb, 12, s->width);
- put_bits(&s->pb, 12, s->height);
-
- for(i=1; i<15; i++){
- float error= mpeg1_aspect[i] - s->width/(s->height*aspect_ratio);
- error= ABS(error);
-
- if(error < best_aspect_error){
- best_aspect_error= error;
- s->aspect_ratio_info= i;
- }
- }
-
- put_bits(&s->pb, 4, s->aspect_ratio_info);
- put_bits(&s->pb, 4, s->frame_rate_index);
-
- if(s->avctx->rc_max_rate){
- v = (s->avctx->rc_max_rate + 399) / 400;
- if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO)
- v = 0x3ffff;
- }else{
- v= 0x3FFFF;
- }
-
- if(s->avctx->rc_buffer_size)
- vbv_buffer_size = s->avctx->rc_buffer_size;
- else
- /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */
- vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;
- vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
-
- put_bits(&s->pb, 18, v & 0x3FFFF);
- put_bits(&s->pb, 1, 1); /* marker */
- put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF);
-
- constraint_parameter_flag=
- s->width <= 768 && s->height <= 576 &&
- s->mb_width * s->mb_height <= 396 &&
- s->mb_width * s->mb_height * frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*396*25 &&
- frame_rate_tab[s->frame_rate_index] <= MPEG1_FRAME_RATE_BASE*30 &&
- vbv_buffer_size <= 20 &&
- v <= 1856000/400 &&
- s->codec_id == CODEC_ID_MPEG1VIDEO;
-
- put_bits(&s->pb, 1, constraint_parameter_flag);
-
- ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
- ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
-
- if(s->codec_id == CODEC_ID_MPEG2VIDEO){
- put_header(s, EXT_START_CODE);
- put_bits(&s->pb, 4, 1); //seq ext
- put_bits(&s->pb, 1, 0); //esc
- put_bits(&s->pb, 3, 4); //profile
- put_bits(&s->pb, 4, 8); //level
- put_bits(&s->pb, 1, s->progressive_sequence=1);
- put_bits(&s->pb, 2, 1); //chroma format 4:2:0
- put_bits(&s->pb, 2, 0); //horizontal size ext
- put_bits(&s->pb, 2, 0); //vertical size ext
- put_bits(&s->pb, 12, v>>18); //bitrate ext
- put_bits(&s->pb, 1, 1); //marker
- put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
- put_bits(&s->pb, 1, s->low_delay);
- put_bits(&s->pb, 2, 0); // frame_rate_ext_n
- put_bits(&s->pb, 5, 0); // frame_rate_ext_d
- }
-
- put_header(s, GOP_START_CODE);
- put_bits(&s->pb, 1, 0); /* do drop frame */
- /* time code : we must convert from the real frame rate to a
- fake mpeg frame rate in case of low frame rate */
- fps = frame_rate_tab[s->frame_rate_index];
- time_code = (int64_t)s->fake_picture_number * MPEG1_FRAME_RATE_BASE;
- s->gop_picture_number = s->fake_picture_number;
- put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
- put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
- put_bits(&s->pb, 6, (uint32_t)((time_code % fps) / MPEG1_FRAME_RATE_BASE));
- put_bits(&s->pb, 1, 0); /* closed gop */
- put_bits(&s->pb, 1, 0); /* broken link */
- }
-
- if (s->avctx->frame_rate < (24 * s->avctx->frame_rate_base) && s->picture_number > 0) {
- /* insert empty P pictures to slow down to the desired
- frame rate. Each fake pictures takes about 20 bytes */
- fps = frame_rate_tab[s->frame_rate_index];
- n = av_rescale((int64_t)s->picture_number * s->avctx->frame_rate_base, fps, s->avctx->frame_rate) / MPEG1_FRAME_RATE_BASE - 1;
- while (s->fake_picture_number < n) {
- mpeg1_skip_picture(s, s->fake_picture_number -
- s->gop_picture_number);
- s->fake_picture_number++;
- }
-
- }
-}
-
-static inline void encode_mb_skip_run(MpegEncContext *s, int run){
- while (run >= 33) {
- put_bits(&s->pb, 11, 0x008);
- run -= 33;
- }
- put_bits(&s->pb, mbAddrIncrTable[run][1],
- mbAddrIncrTable[run][0]);
-}
-
-/* insert a fake P picture */
-static void mpeg1_skip_picture(MpegEncContext *s, int pict_num)
-{
- assert(s->codec_id == CODEC_ID_MPEG1VIDEO); // mpeg2 can do these repeat things
-
- /* mpeg1 picture header */
- put_header(s, PICTURE_START_CODE);
- /* temporal reference */
- put_bits(&s->pb, 10, pict_num & 0x3ff);
-
- put_bits(&s->pb, 3, P_TYPE);
- put_bits(&s->pb, 16, 0xffff); /* non constant bit rate */
-
- put_bits(&s->pb, 1, 1); /* integer coordinates */
- put_bits(&s->pb, 3, 1); /* forward_f_code */
-
- put_bits(&s->pb, 1, 0); /* extra bit picture */
-
- /* only one slice */
- put_header(s, SLICE_MIN_START_CODE);
- put_bits(&s->pb, 5, 1); /* quantizer scale */
- put_bits(&s->pb, 1, 0); /* slice extra information */
-
- encode_mb_skip_run(s, 0);
-
- /* empty macroblock */
- put_bits(&s->pb, 3, 1); /* motion only */
-
- /* zero motion x & y */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 1, 1);
-
- /* output a number of empty slice */
- encode_mb_skip_run(s, s->mb_width * s->mb_height - 2);
-
- /* empty macroblock */
- put_bits(&s->pb, 3, 1); /* motion only */
-
- /* zero motion x & y */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, 1, 1);
-}
-#endif
-
-static void common_init(MpegEncContext *s)
-{
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
-}
-
-void ff_mpeg1_clean_buffers(MpegEncContext *s){
- s->last_dc[0] = 1 << (7 + s->intra_dc_precision);
- s->last_dc[1] = s->last_dc[0];
- s->last_dc[2] = s->last_dc[0];
- memset(s->last_mv, 0, sizeof(s->last_mv));
-}
-
-#ifdef CONFIG_ENCODERS
-
-void ff_mpeg1_encode_slice_header(MpegEncContext *s){
- put_header(s, SLICE_MIN_START_CODE + s->mb_y);
- put_bits(&s->pb, 5, s->qscale); /* quantizer scale */
- put_bits(&s->pb, 1, 0); /* slice extra information */
-}
-
-void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
-{
- mpeg1_encode_sequence_header(s);
-
- /* mpeg1 picture header */
- put_header(s, PICTURE_START_CODE);
- /* temporal reference */
-
- // RAL: s->picture_number instead of s->fake_picture_number
- put_bits(&s->pb, 10, (s->picture_number -
- s->gop_picture_number) & 0x3ff);
- s->fake_picture_number++;
-
- put_bits(&s->pb, 3, s->pict_type);
- put_bits(&s->pb, 16, 0xffff); /* non constant bit rate */
-
- // RAL: Forward f_code also needed for B frames
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- put_bits(&s->pb, 1, 0); /* half pel coordinates */
- if(s->codec_id == CODEC_ID_MPEG1VIDEO)
- put_bits(&s->pb, 3, s->f_code); /* forward_f_code */
- else
- put_bits(&s->pb, 3, 7); /* forward_f_code */
- }
-
- // RAL: Backward f_code necessary for B frames
- if (s->pict_type == B_TYPE) {
- put_bits(&s->pb, 1, 0); /* half pel coordinates */
- if(s->codec_id == CODEC_ID_MPEG1VIDEO)
- put_bits(&s->pb, 3, s->b_code); /* backward_f_code */
- else
- put_bits(&s->pb, 3, 7); /* backward_f_code */
- }
-
- put_bits(&s->pb, 1, 0); /* extra bit picture */
-
- if(s->codec_id == CODEC_ID_MPEG2VIDEO){
- put_header(s, EXT_START_CODE);
- put_bits(&s->pb, 4, 8); //pic ext
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- put_bits(&s->pb, 4, s->f_code);
- put_bits(&s->pb, 4, s->f_code);
- }else{
- put_bits(&s->pb, 8, 255);
- }
- if (s->pict_type == B_TYPE) {
- put_bits(&s->pb, 4, s->b_code);
- put_bits(&s->pb, 4, s->b_code);
- }else{
- put_bits(&s->pb, 8, 255);
- }
- put_bits(&s->pb, 2, s->intra_dc_precision);
- put_bits(&s->pb, 2, s->picture_structure= PICT_FRAME);
- put_bits(&s->pb, 1, s->top_field_first);
- put_bits(&s->pb, 1, s->frame_pred_frame_dct= 1);
- put_bits(&s->pb, 1, s->concealment_motion_vectors);
- put_bits(&s->pb, 1, s->q_scale_type);
- put_bits(&s->pb, 1, s->intra_vlc_format);
- put_bits(&s->pb, 1, s->alternate_scan);
- put_bits(&s->pb, 1, s->repeat_first_field);
- put_bits(&s->pb, 1, s->chroma_420_type=1);
- put_bits(&s->pb, 1, s->progressive_frame=1);
- put_bits(&s->pb, 1, 0); //composite_display_flag
- }
-
- s->mb_y=0;
- ff_mpeg1_encode_slice_header(s);
-}
-
-void mpeg1_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int i, cbp;
- const int mb_x = s->mb_x;
- const int mb_y = s->mb_y;
- const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;
-
- /* compute cbp */
- cbp = 0;
- for(i=0;i<6;i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
-
- if (cbp == 0 && !first_mb && (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) &&
- ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) ||
- (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |
- ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {
- s->mb_skip_run++;
- s->qscale -= s->dquant;
- s->skip_count++;
- s->misc_bits++;
- s->last_bits++;
- } else {
- if(first_mb){
- assert(s->mb_skip_run == 0);
- encode_mb_skip_run(s, s->mb_x);
- }else{
- encode_mb_skip_run(s, s->mb_skip_run);
- }
-
- if (s->pict_type == I_TYPE) {
- if(s->dquant && cbp){
- put_bits(&s->pb, 2, 1); /* macroblock_type : macroblock_quant = 1 */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_bits(&s->pb, 1, 1); /* macroblock_type : macroblock_quant = 0 */
- s->qscale -= s->dquant;
- }
- s->misc_bits+= get_bits_diff(s);
- s->i_count++;
- } else if (s->mb_intra) {
- if(s->dquant && cbp){
- put_bits(&s->pb, 6, 0x01);
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_bits(&s->pb, 5, 0x03);
- s->qscale -= s->dquant;
- }
- s->misc_bits+= get_bits_diff(s);
- s->i_count++;
- s->last_mv[0][0][0] =
- s->last_mv[0][0][1] = 0;
- } else if (s->pict_type == P_TYPE) {
- if (cbp != 0) {
- if (motion_x == 0 && motion_y == 0) {
- if(s->dquant){
- put_bits(&s->pb, 5, 1); /* macroblock_pattern & quant */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_bits(&s->pb, 2, 1); /* macroblock_pattern only */
- }
- s->misc_bits+= get_bits_diff(s);
- put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]);
- } else {
- if(s->dquant){
- put_bits(&s->pb, 5, 2); /* motion + cbp */
- put_bits(&s->pb, 5, s->qscale);
- }else{
- put_bits(&s->pb, 1, 1); /* motion + cbp */
- }
- s->misc_bits+= get_bits_diff(s);
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
- s->mv_bits+= get_bits_diff(s);
- put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]);
- }
- } else {
- put_bits(&s->pb, 3, 1); /* motion only */
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
- s->qscale -= s->dquant;
- s->mv_bits+= get_bits_diff(s);
- }
- s->f_count++;
- } else
- { // RAL: All the following bloc added for B frames:
- if (cbp != 0)
- { // With coded bloc pattern
- if (s->mv_dir == (MV_DIR_FORWARD | MV_DIR_BACKWARD))
- { // Bi-directional motion
- if (s->dquant)
- { // With QScale
- put_bits(&s->pb, 5, 2);
- put_bits(&s->pb, 5, s->qscale);
- }
- else // Without QScale
- put_bits(&s->pb, 2, 3);
- s->misc_bits += get_bits_diff(s);
- mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
- mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
- mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
- mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
- s->b_count++;
- s->f_count++;
- s->mv_bits += get_bits_diff(s);
- put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]);
- }
- else if (s->mv_dir == MV_DIR_BACKWARD)
- { // Backward motion
- if (s->dquant)
- { // With QScale
- put_bits(&s->pb, 6, 2);
- put_bits(&s->pb, 5, s->qscale);
- }
- else // Without QScale
- put_bits(&s->pb, 3, 3);
- s->misc_bits += get_bits_diff(s);
- mpeg1_encode_motion(s, motion_x - s->last_mv[1][0][0], s->b_code);
- mpeg1_encode_motion(s, motion_y - s->last_mv[1][0][1], s->b_code);
- s->b_count++;
- s->mv_bits += get_bits_diff(s);
- put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]);
- }
- else if (s->mv_dir == MV_DIR_FORWARD)
- { // Forward motion
- if (s->dquant)
- { // With QScale
- put_bits(&s->pb, 6, 3);
- put_bits(&s->pb, 5, s->qscale);
- }
- else // Without QScale
- put_bits(&s->pb, 4, 3);
- s->misc_bits += get_bits_diff(s);
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code);
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code);
- s->f_count++;
- s->mv_bits += get_bits_diff(s);
- put_bits(&s->pb, mbPatTable[cbp - 1][1], mbPatTable[cbp - 1][0]);
- }
- }
- else
- { // No coded bloc pattern
- if (s->mv_dir == (MV_DIR_FORWARD | MV_DIR_BACKWARD))
- { // Bi-directional motion
- put_bits(&s->pb, 2, 2); /* backward & forward motion */
- mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
- mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
- mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
- mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
- s->b_count++;
- s->f_count++;
- }
- else if (s->mv_dir == MV_DIR_BACKWARD)
- { // Backward motion
- put_bits(&s->pb, 3, 2); /* backward motion only */
- mpeg1_encode_motion(s, motion_x - s->last_mv[1][0][0], s->b_code);
- mpeg1_encode_motion(s, motion_y - s->last_mv[1][0][1], s->b_code);
- s->b_count++;
- }
- else if (s->mv_dir == MV_DIR_FORWARD)
- { // Forward motion
- put_bits(&s->pb, 4, 2); /* forward motion only */
- mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code);
- mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code);
- s->f_count++;
- }
- s->qscale -= s->dquant;
- s->mv_bits += get_bits_diff(s);
- }
- // End of bloc from RAL
- }
- for(i=0;i<6;i++) {
- if (cbp & (1 << (5 - i))) {
- mpeg1_encode_block(s, block[i], i);
- }
- }
- s->mb_skip_run = 0;
- if(s->mb_intra)
- s->i_tex_bits+= get_bits_diff(s);
- else
- s->p_tex_bits+= get_bits_diff(s);
- }
-
- // RAL: By this:
- if (s->mv_dir & MV_DIR_FORWARD)
- {
- s->last_mv[0][0][0]= s->mv[0][0][0];
- s->last_mv[0][0][1]= s->mv[0][0][1];
- }
- if (s->mv_dir & MV_DIR_BACKWARD)
- {
- s->last_mv[1][0][0]= s->mv[1][0][0];
- s->last_mv[1][0][1]= s->mv[1][0][1];
- }
-}
-
-// RAL: Parameter added: f_or_b_code
-static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
-{
- int code, bit_size, l, m, bits, range, sign;
-
- if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(&s->pb,
- mbMotionVectorTable[0][1],
- mbMotionVectorTable[0][0]);
- } else {
- bit_size = f_or_b_code - 1;
- range = 1 << bit_size;
- /* modulo encoding */
- l = 16 * range;
- m = 2 * l;
- if (val < -l) {
- val += m;
- } else if (val >= l) {
- val -= m;
- }
-
- if (val >= 0) {
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
- sign = 0;
- } else {
- val = -val;
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
- sign = 1;
- }
-
- assert(code > 0 && code <= 16);
-
- put_bits(&s->pb,
- mbMotionVectorTable[code][1],
- mbMotionVectorTable[code][0]);
-
- put_bits(&s->pb, 1, sign);
- if (bit_size > 0) {
- put_bits(&s->pb, bit_size, bits);
- }
- }
-}
-
-void ff_mpeg1_encode_init(MpegEncContext *s)
-{
- static int done=0;
-
- common_init(s);
-
- if(!done){
- int f_code;
- int mv;
- int i;
-
- done=1;
- init_rl(&rl_mpeg1);
-
- for(i=0; i<64; i++)
- {
- mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i];
- mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i];
- }
-
- init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_bits, uni_mpeg1_ac_vlc_len);
-
- /* build unified dc encoding tables */
- for(i=-255; i<256; i++)
- {
- int adiff, index;
- int bits, code;
- int diff=i;
-
- adiff = ABS(diff);
- if(diff<0) diff--;
- index = vlc_dc_table[adiff];
-
- bits= vlc_dc_lum_bits[index] + index;
- code= (vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1));
- mpeg1_lum_dc_uni[i+255]= bits + (code<<8);
-
- bits= vlc_dc_chroma_bits[index] + index;
- code= (vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1));
- mpeg1_chr_dc_uni[i+255]= bits + (code<<8);
- }
-
- mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
-
- for(f_code=1; f_code<=MAX_FCODE; f_code++){
- for(mv=-MAX_MV; mv<=MAX_MV; mv++){
- int len;
-
- if(mv==0) len= mbMotionVectorTable[0][1];
- else{
- int val, bit_size, range, code;
-
- bit_size = s->f_code - 1;
- range = 1 << bit_size;
-
- val=mv;
- if (val < 0)
- val = -val;
- val--;
- code = (val >> bit_size) + 1;
- if(code<17){
- len= mbMotionVectorTable[code][1] + 1 + bit_size;
- }else{
- len= mbMotionVectorTable[16][1] + 2 + bit_size;
- }
- }
-
- mv_penalty[f_code][mv+MAX_MV]= len;
- }
- }
-
-
- for(f_code=MAX_FCODE; f_code>0; f_code--){
- for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
- fcode_tab[mv+MAX_MV]= f_code;
- }
- }
- }
- s->me.mv_penalty= mv_penalty;
- s->fcode_tab= fcode_tab;
- if(s->codec_id == CODEC_ID_MPEG1VIDEO){
- s->min_qcoeff=-255;
- s->max_qcoeff= 255;
- }else{
- s->min_qcoeff=-2047;
- s->max_qcoeff= 2047;
- }
- s->intra_ac_vlc_length=
- s->inter_ac_vlc_length= uni_mpeg1_ac_vlc_len;
-}
-
-static inline void encode_dc(MpegEncContext *s, int diff, int component)
-{
- if (component == 0) {
- put_bits(
- &s->pb,
- mpeg1_lum_dc_uni[diff+255]&0xFF,
- mpeg1_lum_dc_uni[diff+255]>>8);
- } else {
- put_bits(
- &s->pb,
- mpeg1_chr_dc_uni[diff+255]&0xFF,
- mpeg1_chr_dc_uni[diff+255]>>8);
- }
-}
-
-static void mpeg1_encode_block(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
- int code, component;
-// RLTable *rl = &rl_mpeg1;
-
- last_index = s->block_last_index[n];
-
- /* DC coef */
- if (s->mb_intra) {
- component = (n <= 3 ? 0 : n - 4 + 1);
- dc = block[0]; /* overflow is impossible */
- diff = dc - s->last_dc[component];
- encode_dc(s, diff, component);
- s->last_dc[component] = dc;
- i = 1;
-/*
- if (s->intra_vlc_format)
- rl = &rl_mpeg2;
- else
- rl = &rl_mpeg1;
-*/
- } else {
- /* encode the first coefficient : needs to be done here because
- it is handled slightly differently */
- level = block[0];
- if (abs(level) == 1) {
- code = ((uint32_t)level >> 31); /* the sign bit */
- put_bits(&s->pb, 2, code | 0x02);
- i = 1;
- } else {
- i = 0;
- last_non_zero = -1;
- goto next_coef;
- }
- }
-
- /* now quantify & encode AC coefs */
- last_non_zero = i - 1;
-
- for(;i<=last_index;i++) {
- j = s->intra_scantable.permutated[i];
- level = block[j];
- next_coef:
-#if 0
- if (level != 0)
- dprintf("level[%d]=%d\n", i, level);
-#endif
- /* encode using VLC */
- if (level != 0) {
- run = i - last_non_zero - 1;
-
- alevel= level;
- MASK_ABS(sign, alevel)
- sign&=1;
-
-// code = get_rl_index(rl, 0, run, alevel);
- if (alevel <= mpeg1_max_level[0][run]){
- code= mpeg1_index_run[0][run] + alevel - 1;
- /* store the vlc & sign at once */
- put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign);
- } else {
- /* escape seems to be pretty rare <5% so i dont optimize it */
- put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]);
- /* escape: only clip in this case */
- put_bits(&s->pb, 6, run);
- if(s->codec_id == CODEC_ID_MPEG1VIDEO){
- if (alevel < 128) {
- put_bits(&s->pb, 8, level & 0xff);
- } else {
- if (level < 0) {
- put_bits(&s->pb, 16, 0x8001 + level + 255);
- } else {
- put_bits(&s->pb, 16, level & 0xffff);
- }
- }
- }else{
- put_bits(&s->pb, 12, level & 0xfff);
- }
- }
- last_non_zero = i;
- }
- }
- /* end of block */
- put_bits(&s->pb, 2, 0x2);
-}
-#endif //CONFIG_ENCODERS
-
-/******************************************/
-/* decoding */
-
-static VLC dc_lum_vlc;
-static VLC dc_chroma_vlc;
-static VLC mv_vlc;
-static VLC mbincr_vlc;
-static VLC mb_ptype_vlc;
-static VLC mb_btype_vlc;
-static VLC mb_pat_vlc;
-
-static void init_vlcs()
-{
- static int done = 0;
-
- if (!done) {
- done = 1;
-
- init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12,
- vlc_dc_lum_bits, 1, 1,
- vlc_dc_lum_code, 2, 2);
- init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12,
- vlc_dc_chroma_bits, 1, 1,
- vlc_dc_chroma_code, 2, 2);
- init_vlc(&mv_vlc, MV_VLC_BITS, 17,
- &mbMotionVectorTable[0][1], 2, 1,
- &mbMotionVectorTable[0][0], 2, 1);
- init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36,
- &mbAddrIncrTable[0][1], 2, 1,
- &mbAddrIncrTable[0][0], 2, 1);
- init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 63,
- &mbPatTable[0][1], 2, 1,
- &mbPatTable[0][0], 2, 1);
-
- init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
- &table_mb_ptype[0][1], 2, 1,
- &table_mb_ptype[0][0], 2, 1);
- init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
- &table_mb_btype[0][1], 2, 1,
- &table_mb_btype[0][0], 2, 1);
- init_rl(&rl_mpeg1);
- init_rl(&rl_mpeg2);
-
- init_2d_vlc_rl(&rl_mpeg1);
- init_2d_vlc_rl(&rl_mpeg2);
- }
-}
-
-static inline int get_dmv(MpegEncContext *s)
-{
- if(get_bits1(&s->gb))
- return 1 - (get_bits1(&s->gb) << 1);
- else
- return 0;
-}
-
-static inline int get_qscale(MpegEncContext *s)
-{
- int qscale = get_bits(&s->gb, 5);
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- if (s->q_scale_type) {
- return non_linear_qscale[qscale];
- } else {
- return qscale << 1;
- }
- }
- return qscale;
-}
-
-/* motion type (for mpeg2) */
-#define MT_FIELD 1
-#define MT_FRAME 2
-#define MT_16X8 2
-#define MT_DMV 3
-
-static int mpeg_decode_mb(MpegEncContext *s,
- DCTELEM block[6][64])
-{
- int i, j, k, cbp, val, mb_type, motion_type;
-
- dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
-
- assert(s->mb_skiped==0);
-
- if (s->mb_skip_run-- != 0) {
- if(s->pict_type == I_TYPE){
- fprintf(stderr, "skiped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_type = MV_TYPE_16X16;
- if (s->pict_type == P_TYPE) {
- /* if P type, zero motion vector is implied */
- s->mv_dir = MV_DIR_FORWARD;
- s->mv[0][0][0] = s->mv[0][0][1] = 0;
- s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
- s->mb_skiped = 1;
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
- } else {
- /* if B type, reuse previous vectors and directions */
- s->mv[0][0][0] = s->last_mv[0][0][0];
- s->mv[0][0][1] = s->last_mv[0][0][1];
- s->mv[1][0][0] = s->last_mv[1][0][0];
- s->mv[1][0][1] = s->last_mv[1][0][1];
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1] | MB_TYPE_SKIP;
-// assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8));
-
- if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0)
- s->mb_skiped = 1;
- }
-
- return 0;
- }
-
- switch(s->pict_type) {
- default:
- case I_TYPE:
- if (get_bits1(&s->gb) == 0) {
- if (get_bits1(&s->gb) == 0){
- fprintf(stderr, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
- } else {
- mb_type = MB_TYPE_INTRA;
- }
- break;
- case P_TYPE:
- mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- fprintf(stderr, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = ptype2mb_type[ mb_type ];
- break;
- case B_TYPE:
- mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
- if (mb_type < 0){
- fprintf(stderr, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_type = btype2mb_type[ mb_type ];
- break;
- }
- dprintf("mb_type=%x\n", mb_type);
-// motion_type = 0; /* avoid warning */
- if (IS_INTRA(mb_type)) {
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- if (s->concealment_motion_vectors) {
- /* just parse them */
- if (s->picture_structure != PICT_FRAME)
- skip_bits1(&s->gb); /* field select */
-
- s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]);
- s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]);
-
- skip_bits1(&s->gb); /* marker */
- }else
- memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */
- s->mb_intra = 1;
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- for(i=0;i<6;i++) {
- if (mpeg2_decode_block_intra(s, block[i], i) < 0)
- return -1;
- }
- } else {
- for(i=0;i<6;i++) {
- if (mpeg1_decode_block_intra(s, block[i], i) < 0)
- return -1;
- }
- }
- } else {
- if (mb_type & MB_TYPE_ZERO_MV){
- assert(mb_type & MB_TYPE_PAT);
-
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->last_mv[0][0][0] = 0;
- s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = 0;
- s->last_mv[0][1][1] = 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- }else{
- assert(mb_type & MB_TYPE_L0L1);
-//FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
- /* get additionnal motion vector type */
- if (s->frame_pred_frame_dct)
- motion_type = MT_FRAME;
- else{
- motion_type = get_bits(&s->gb, 2);
- }
-
- /* compute dct type */
- if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var?
- !s->frame_pred_frame_dct && IS_PAT(mb_type)) {
- s->interlaced_dct = get_bits1(&s->gb);
- }
-
- if (IS_QUANT(mb_type))
- s->qscale = get_qscale(s);
-
- /* motion vectors */
- s->mv_dir = 0;
- for(i=0;i<2;i++) {
- if (USES_LIST(mb_type, i)) {
- s->mv_dir |= (MV_DIR_FORWARD >> i);
- dprintf("motion_type=%d\n", motion_type);
- switch(motion_type) {
- case MT_FRAME: /* or MT_16X8 */
- if (s->picture_structure == PICT_FRAME) {
- /* MT_FRAME */
- mb_type |= MB_TYPE_16x16;
- s->mv_type = MV_TYPE_16X16;
- s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]);
- s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
- /* full_pel: only for mpeg1 */
- if (s->full_pel[i]){
- s->mv[i][0][0] <<= 1;
- s->mv[i][0][1] <<= 1;
- }
- } else {
- /* MT_16X8 */
- mb_type |= MB_TYPE_16x8;
- s->mv_type = MV_TYPE_16X8;
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][j][k]);
- s->last_mv[i][j][k] = val;
- s->mv[i][j][k] = val;
- }
- }
- }
- break;
- case MT_FIELD:
- s->mv_type = MV_TYPE_FIELD;
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- for(j=0;j<2;j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][j][0]);
- s->last_mv[i][j][0] = val;
- s->mv[i][j][0] = val;
- dprintf("fmx=%d\n", val);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][j][1] >> 1);
- s->last_mv[i][j][1] = val << 1;
- s->mv[i][j][1] = val;
- dprintf("fmy=%d\n", val);
- }
- } else {
- mb_type |= MB_TYPE_16x16;
- s->field_select[i][0] = get_bits1(&s->gb);
- for(k=0;k<2;k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][0][k]);
- s->last_mv[i][0][k] = val;
- s->last_mv[i][1][k] = val;
- s->mv[i][0][k] = val;
- }
- }
- break;
- case MT_DMV:
- {
- int dmx, dmy, mx, my, m;
-
- mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][0][0]);
- s->last_mv[i][0][0] = mx;
- s->last_mv[i][1][0] = mx;
- dmx = get_dmv(s);
- my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][0][1] >> 1);
- dmy = get_dmv(s);
- s->mv_type = MV_TYPE_DMV;
-
-
- s->last_mv[i][0][1] = my<<1;
- s->last_mv[i][1][1] = my<<1;
-
- s->mv[i][0][0] = mx;
- s->mv[i][0][1] = my;
- s->mv[i][1][0] = mx;//not used
- s->mv[i][1][1] = my;//not used
-
- if (s->picture_structure == PICT_FRAME) {
- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
-
- //m = 1 + 2 * s->top_field_first;
- m = s->top_field_first ? 1 : 3;
-
- /* top -> top pred */
- s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
- m = 4 - m;
- s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
- } else {
- mb_type |= MB_TYPE_16x16;
-
- s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
- if(s->picture_structure == PICT_TOP_FIELD)
- s->mv[i][2][1]--;
- else
- s->mv[i][2][1]++;
- }
- }
- break;
- }
- }
- }
- }
-
- s->mb_intra = 0;
-
- if (IS_PAT(mb_type)) {
- cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
- if (cbp < 0){
- fprintf(stderr, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- cbp++;
-
- if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- if (mpeg2_decode_block_non_intra(s, block[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- } else {
- for(i=0;i<6;i++) {
- if (cbp & 32) {
- if (mpeg1_decode_block_inter(s, block[i], i) < 0)
- return -1;
- } else {
- s->block_last_index[i] = -1;
- }
- cbp+=cbp;
- }
- }
- }else{
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- }
- }
-
- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type;
-
- return 0;
-}
-
-/* as h263, but only 17 codes */
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
-{
- int code, sign, val, l, shift;
-
- code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
- if (code == 0) {
- return pred;
- }
- if (code < 0) {
- return 0xffff;
- }
-
- sign = get_bits1(&s->gb);
- shift = fcode - 1;
- val = code;
- if (shift) {
- val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
- val++;
- }
- if (sign)
- val = -val;
- val += pred;
-
- /* modulo decoding */
- l = 1 << (shift+4);
- val = ((val + l)&(l*2-1)) - l;
- return val;
-}
-
-static inline int decode_dc(GetBitContext *gb, int component)
-{
- int code, diff;
-
- if (component == 0) {
- code = get_vlc2(gb, dc_lum_vlc.table, DC_VLC_BITS, 2);
- } else {
- code = get_vlc2(gb, dc_chroma_vlc.table, DC_VLC_BITS, 2);
- }
- if (code < 0){
- fprintf(stderr, "invalid dc code at\n");
- return 0xffff;
- }
- if (code == 0) {
- diff = 0;
- } else {
- diff = get_xbits(gb, code);
- }
- return diff;
-}
-
-static inline int mpeg1_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, dc, diff, i, j, run;
- int component;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->intra_matrix;
- const int qscale= s->qscale;
-
- /* DC coef */
- component = (n <= 3 ? 0 : n - 4 + 1);
- diff = decode_dc(&s->gb, component);
- if (diff >= 0xffff)
- return -1;
- dc = s->last_dc[component];
- dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc<<3;
- dprintf("dc=%d diff=%d\n", dc, diff);
- i = 0;
- {
- OPEN_READER(re, &s->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>3;
- level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
- if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);
- } else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
- }
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= (level*qscale*quant_matrix[j])>>3;
- level= (level-1)|1;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>3;
- level= (level-1)|1;
- }
- }
- if (i > 63){
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix= s->inter_matrix;
- const int qscale= s->qscale;
-
- {
- int v;
- OPEN_READER(re, &s->gb);
- i = -1;
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- v= SHOW_UBITS(re, &s->gb, 2);
- if (v & 2) {
- LAST_SKIP_BITS(re, &s->gb, 2);
- level= (3*qscale*quant_matrix[0])>>4;
- level= (level-1)|1;
- if(v&1)
- level= -level;
- block[0] = level;
- i++;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);
- if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8);
- } else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8);
- }
- i += run;
- j = scantable[i];
- if(level<0){
- level= -level;
- level= ((level*2+1)*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>4;
- level= (level-1)|1;
- }
- }
- if (i > 63){
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- s->block_last_index[n] = i;
- return 0;
-}
-
-/* Also does unquantization here, since I will never support mpeg2
- encoding */
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, i, j, run;
- RLTable *rl = &rl_mpeg1;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix;
- const int qscale= s->qscale;
- int mismatch;
-
- mismatch = 1;
-
- {
- int v;
- OPEN_READER(re, &s->gb);
- i = -1;
- if (n < 4)
- quant_matrix = s->inter_matrix;
- else
- quant_matrix = s->chroma_inter_matrix;
-
- /* special case for the first coef. no need to add a second vlc table */
- UPDATE_CACHE(re, &s->gb);
- v= SHOW_UBITS(re, &s->gb, 2);
- if (v & 2) {
- LAST_SKIP_BITS(re, &s->gb, 2);
- level= (3*qscale*quant_matrix[0])>>5;
- if(v&1)
- level= -level;
- block[0] = level;
- mismatch ^= level;
- i++;
- }
-
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
-
- i += run;
- j = scantable[i];
- if(level<0){
- level= ((-level*2+1)*qscale*quant_matrix[j])>>5;
- level= -level;
- }else{
- level= ((level*2+1)*qscale*quant_matrix[j])>>5;
- }
- }
- if (i > 63){
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- mismatch ^= level;
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- block[63] ^= (mismatch & 1);
-
- s->block_last_index[n] = i;
- return 0;
-}
-
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
- DCTELEM *block,
- int n)
-{
- int level, dc, diff, i, j, run;
- int component;
- RLTable *rl;
- uint8_t * const scantable= s->intra_scantable.permutated;
- const uint16_t *quant_matrix;
- const int qscale= s->qscale;
- int mismatch;
-
- /* DC coef */
- if (n < 4){
- quant_matrix = s->intra_matrix;
- component = 0;
- }else{
- quant_matrix = s->chroma_intra_matrix;
- component = n - 3;
- }
- diff = decode_dc(&s->gb, component);
- if (diff >= 0xffff)
- return -1;
- dc = s->last_dc[component];
- dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc << (3 - s->intra_dc_precision);
- dprintf("dc=%d\n", block[0]);
- mismatch = block[0] ^ 1;
- i = 0;
- if (s->intra_vlc_format)
- rl = &rl_mpeg2;
- else
- rl = &rl_mpeg1;
-
- {
- OPEN_READER(re, &s->gb);
- /* now quantify & encode AC coefs */
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
-
- if(level == 127){
- break;
- } else if(level != 0) {
- i += run;
- j = scantable[i];
- level= (level*qscale*quant_matrix[j])>>4;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
- } else {
- /* escape */
- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
- i += run;
- j = scantable[i];
- if(level<0){
- level= (-level*qscale*quant_matrix[j])>>4;
- level= -level;
- }else{
- level= (level*qscale*quant_matrix[j])>>4;
- }
- }
- if (i > 63){
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- mismatch^= level;
- block[j] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- block[63]^= mismatch&1;
-
- s->block_last_index[n] = i;
- return 0;
-}
-
-typedef struct Mpeg1Context {
- MpegEncContext mpeg_enc_ctx;
- int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
- int repeat_field; /* true if we must repeat the field */
-} Mpeg1Context;
-
-static int mpeg_decode_init(AVCodecContext *avctx)
-{
- Mpeg1Context *s = avctx->priv_data;
-
- s->mpeg_enc_ctx.flags= avctx->flags;
- common_init(&s->mpeg_enc_ctx);
- init_vlcs();
-
- s->mpeg_enc_ctx_allocated = 0;
- s->mpeg_enc_ctx.picture_number = 0;
- s->repeat_field = 0;
- s->mpeg_enc_ctx.codec_id= avctx->codec->id;
- return 0;
-}
-
-/* return the 8 bit start code value and update the search
- state. Return -1 if no start code found */
-static int find_start_code(uint8_t **pbuf_ptr, uint8_t *buf_end)
-{
- uint8_t *buf_ptr;
- unsigned int state=0xFFFFFFFF, v;
- int val;
-
- buf_ptr = *pbuf_ptr;
- while (buf_ptr < buf_end) {
- v = *buf_ptr++;
- if (state == 0x000001) {
- state = ((state << 8) | v) & 0xffffff;
- val = state;
- goto found;
- }
- state = ((state << 8) | v) & 0xffffff;
- }
- val = -1;
- found:
- *pbuf_ptr = buf_ptr;
- return val;
-}
-
-static int mpeg1_decode_picture(AVCodecContext *avctx,
- uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int ref, f_code;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- ref = get_bits(&s->gb, 10); /* temporal ref */
- s->pict_type = get_bits(&s->gb, 3);
- dprintf("pict_type=%d number=%d\n", s->pict_type, s->picture_number);
-
- skip_bits(&s->gb, 16);
- if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) {
- s->full_pel[0] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
- if (f_code == 0)
- return -1;
- s->mpeg_f_code[0][0] = f_code;
- s->mpeg_f_code[0][1] = f_code;
- }
- if (s->pict_type == B_TYPE) {
- s->full_pel[1] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
- if (f_code == 0)
- return -1;
- s->mpeg_f_code[1][0] = f_code;
- s->mpeg_f_code[1][1] = f_code;
- }
- s->current_picture.pict_type= s->pict_type;
- s->current_picture.key_frame= s->pict_type == I_TYPE;
-
- s->y_dc_scale = 8;
- s->c_dc_scale = 8;
- s->first_slice = 1;
- return 0;
-}
-
-static void mpeg_decode_sequence_extension(MpegEncContext *s)
-{
- int horiz_size_ext, vert_size_ext;
- int bit_rate_ext, vbv_buf_ext;
- int frame_rate_ext_n, frame_rate_ext_d;
- int level, profile;
- float aspect;
-
- skip_bits(&s->gb, 1); /* profil and level esc*/
- profile= get_bits(&s->gb, 3);
- level= get_bits(&s->gb, 4);
- s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
- skip_bits(&s->gb, 2); /* chroma_format */
- horiz_size_ext = get_bits(&s->gb, 2);
- vert_size_ext = get_bits(&s->gb, 2);
- s->width |= (horiz_size_ext << 12);
- s->height |= (vert_size_ext << 12);
- bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
- s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400;
- skip_bits1(&s->gb); /* marker */
- vbv_buf_ext = get_bits(&s->gb, 8);
-
- s->low_delay = get_bits1(&s->gb);
- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
-
- frame_rate_ext_n = get_bits(&s->gb, 2);
- frame_rate_ext_d = get_bits(&s->gb, 5);
- av_reduce(
- &s->avctx->frame_rate,
- &s->avctx->frame_rate_base,
- frame_rate_tab[s->frame_rate_index] * (frame_rate_ext_n+1),
- MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d+1),
- 1<<30);
-
- dprintf("sequence extension\n");
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
- s->avctx->sub_id = 2; /* indicates mpeg2 found */
-
- aspect= mpeg2_aspect[s->aspect_ratio_info];
- if(aspect>0.0) s->avctx->aspect_ratio= s->width/(aspect*s->height);
- else if(aspect<0.0) s->avctx->aspect_ratio= -1.0/aspect;
-
- if(s->avctx->debug & FF_DEBUG_PICT_INFO)
- printf("profile: %d, level: %d \n", profile, level);
-}
-
-static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
-{
- int i, v, j;
-
- dprintf("matrix extension\n");
-
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
- s->chroma_inter_matrix[j] = v;
- }
- }
-}
-
-static void mpeg_decode_picture_coding_extension(MpegEncContext *s)
-{
- s->full_pel[0] = s->full_pel[1] = 0;
- s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
- s->intra_dc_precision = get_bits(&s->gb, 2);
- s->picture_structure = get_bits(&s->gb, 2);
- s->top_field_first = get_bits1(&s->gb);
- s->frame_pred_frame_dct = get_bits1(&s->gb);
- s->concealment_motion_vectors = get_bits1(&s->gb);
- s->q_scale_type = get_bits1(&s->gb);
- s->intra_vlc_format = get_bits1(&s->gb);
- s->alternate_scan = get_bits1(&s->gb);
- s->repeat_first_field = get_bits1(&s->gb);
- s->chroma_420_type = get_bits1(&s->gb);
- s->progressive_frame = get_bits1(&s->gb);
-
- if(s->picture_structure == PICT_FRAME)
- s->first_field=0;
- else{
- s->first_field ^= 1;
- memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
- }
-
- if(s->alternate_scan){
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
- }else{
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
- }
-
- /* composite display not parsed */
- dprintf("intra_dc_precision=%d\n", s->intra_dc_precision);
- dprintf("picture_structure=%d\n", s->picture_structure);
- dprintf("top field first=%d\n", s->top_field_first);
- dprintf("repeat first field=%d\n", s->repeat_first_field);
- dprintf("conceal=%d\n", s->concealment_motion_vectors);
- dprintf("intra_vlc_format=%d\n", s->intra_vlc_format);
- dprintf("alternate_scan=%d\n", s->alternate_scan);
- dprintf("frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
- dprintf("progressive_frame=%d\n", s->progressive_frame);
-}
-
-static void mpeg_decode_extension(AVCodecContext *avctx,
- uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int ext_type;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- ext_type = get_bits(&s->gb, 4);
- switch(ext_type) {
- case 0x1:
- /* sequence ext */
- mpeg_decode_sequence_extension(s);
- break;
- case 0x3:
- /* quant matrix extension */
- mpeg_decode_quant_matrix_extension(s);
- break;
- case 0x8:
- /* picture extension */
- mpeg_decode_picture_coding_extension(s);
- break;
- }
-}
-
-static void exchange_uv(AVFrame *f){
- uint8_t *t= f->data[1];
- f->data[1]= f->data[2];
- f->data[2]= t;
-}
-
-#define DECODE_SLICE_FATAL_ERROR -2
-#define DECODE_SLICE_ERROR -1
-#define DECODE_SLICE_OK 0
-
-/**
- * decodes a slice.
- * @return DECODE_SLICE_FATAL_ERROR if a non recoverable error occured<br>
- * DECODE_SLICE_ERROR if the slice is damaged<br>
- * DECODE_SLICE_OK if this slice is ok<br>
- */
-static int mpeg_decode_slice(AVCodecContext *avctx,
- AVFrame *pict,
- int start_code,
- uint8_t **buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int ret;
- const int field_pic= s->picture_structure != PICT_FRAME;
-
- s->resync_mb_x= s->mb_x =
- s->resync_mb_y= s->mb_y = -1;
-
- start_code = (start_code - 1) & 0xff;
- if (start_code >= s->mb_height){
- fprintf(stderr, "slice below image (%d >= %d)\n", start_code, s->mb_height);
- return -1;
- }
-
- ff_mpeg1_clean_buffers(s);
- s->interlaced_dct = 0;
-
- /* start frame decoding */
- if (s->first_slice) {
- if(s->first_field || s->picture_structure==PICT_FRAME){
- if(MPV_frame_start(s, avctx) < 0)
- return DECODE_SLICE_FATAL_ERROR;
-
- ff_er_frame_start(s);
-
- /* first check if we must repeat the frame */
- s->current_picture_ptr->repeat_pict = 0;
- if (s->repeat_first_field) {
- if (s->progressive_sequence) {
- if (s->top_field_first)
- s->current_picture_ptr->repeat_pict = 4;
- else
- s->current_picture_ptr->repeat_pict = 2;
- } else if (s->progressive_frame) {
- s->current_picture_ptr->repeat_pict = 1;
- }
- }
- //printf("%d\n", s->current_picture_ptr->repeat_pict);
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("qp:%d fc:%2d%2d%2d%2d %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
- s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1],
- s->pict_type == I_TYPE ? "I" : (s->pict_type == P_TYPE ? "P" : (s->pict_type == B_TYPE ? "B" : "S")),
- s->progressive_sequence ? "pro" :"", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"",
- s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
- s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
- }
- }else{ //second field
- int i;
-
- if(!s->current_picture_ptr){
- fprintf(stderr, "first field missing\n");
- return -1;
- }
-
- for(i=0; i<4; i++){
- s->current_picture.data[i] = s->current_picture_ptr->data[i];
- if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
- }
- }
- }
-#ifdef HAVE_XVMC
-// MPV_frame_start will call this function too,
-// but we need to call it on every field
- if(s->avctx->xvmc_acceleration)
- XVMC_field_start(s,avctx);
-#endif
- }//fi(s->first_slice)
- s->first_slice = 0;
-
- init_get_bits(&s->gb, *buf, buf_size*8);
-
- s->qscale = get_qscale(s);
- if(s->qscale == 0){
- fprintf(stderr, "qscale == 0\n");
- return -1;
- }
-
- /* extra slice info */
- while (get_bits1(&s->gb) != 0) {
- skip_bits(&s->gb, 8);
- }
-
- s->mb_x=0;
-
- for(;;) {
- int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
- if (code < 0){
- fprintf(stderr, "first mb_incr damaged\n");
- return -1;
- }
- if (code >= 33) {
- if (code == 33) {
- s->mb_x += 33;
- }
- /* otherwise, stuffing, nothing to do */
- } else {
- s->mb_x += code;
- break;
- }
- }
-
- s->resync_mb_x= s->mb_x;
- s->resync_mb_y= s->mb_y = start_code;
- s->mb_skip_run= 0;
- ff_init_block_index(s);
-
- for(;;) {
- s->dsp.clear_blocks(s->block[0]);
-
- ret = mpeg_decode_mb(s, s->block);
-
- dprintf("ret=%d\n", ret);
- if (ret < 0)
- return -1;
-
- if(s->motion_val && s->pict_type != B_TYPE){ //note motion_val is normally NULL unless we want to extract the MVs
- const int wrap = s->block_wrap[0];
- const int xy = s->mb_x*2 + 1 + (s->mb_y*2 +1)*wrap;
- int motion_x, motion_y;
-
- if (s->mb_intra) {
- motion_x = motion_y = 0;
- }else if (s->mv_type == MV_TYPE_16X16) {
- motion_x = s->mv[0][0][0];
- motion_y = s->mv[0][0][1];
- } else /*if (s->mv_type == MV_TYPE_FIELD)*/ {
- motion_x = s->mv[0][0][0] + s->mv[0][1][0];
- motion_y = s->mv[0][0][1] + s->mv[0][1][1];
- motion_x = (motion_x>>1) | (motion_x&1);
- }
- s->motion_val[xy][0] = motion_x;
- s->motion_val[xy][1] = motion_y;
- s->motion_val[xy + 1][0] = motion_x;
- s->motion_val[xy + 1][1] = motion_y;
- s->motion_val[xy + wrap][0] = motion_x;
- s->motion_val[xy + wrap][1] = motion_y;
- s->motion_val[xy + 1 + wrap][0] = motion_x;
- s->motion_val[xy + 1 + wrap][1] = motion_y;
- }
-
- s->dest[0] += 16;
- s->dest[1] += 8;
- s->dest[2] += 8;
-
- MPV_decode_mb(s, s->block);
-
- if (++s->mb_x >= s->mb_width) {
- if(s->avctx->codec_tag == ff_get_fourcc("VCR2"))
- exchange_uv((AVFrame*)s->current_picture_ptr);
-
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
-
- if(s->avctx->codec_tag == ff_get_fourcc("VCR2"))
- exchange_uv((AVFrame*)s->current_picture_ptr);
-
- s->mb_x = 0;
- s->mb_y++;
-
- if(s->mb_y<<field_pic >= s->mb_height){
- int left= s->gb.size_in_bits - get_bits_count(&s->gb);
-
- if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)))
- || (avctx->error_resilience >= FF_ER_AGGRESSIVE && left>8)){
- fprintf(stderr, "end missmatch left=%d\n", left);
- return -1;
- }else
- goto eos;
- }
-
- ff_init_block_index(s);
- }
-
- /* skip mb handling */
- if (s->mb_skip_run == -1) {
- /* read again increment */
- s->mb_skip_run = 0;
- for(;;) {
- int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
- if (code < 0){
- fprintf(stderr, "mb incr damaged\n");
- return -1;
- }
- if (code >= 33) {
- if (code == 33) {
- s->mb_skip_run += 33;
- }else if(code == 35){
- if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){
- fprintf(stderr, "slice missmatch\n");
- return -1;
- }
- goto eos; /* end of slice */
- }
- /* otherwise, stuffing, nothing to do */
- } else {
- s->mb_skip_run += code;
- break;
- }
- }
- }
- }
-eos: // end of slice
- *buf += get_bits_count(&s->gb)/8 - 1;
-//printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
- return 0;
-}
-
-/**
- * handles slice ends.
- * @return 1 if it seems to be the last slice of
- */
-static int slice_end(AVCodecContext *avctx, AVFrame *pict)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
-
- if (!s1->mpeg_enc_ctx_allocated || !s->current_picture_ptr)
- return 0;
-
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration)
- XVMC_field_end(s);
-#endif
- /* end of slice reached */
- if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
- /* end of image */
-
- if(s->codec_id == CODEC_ID_MPEG2VIDEO){
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
- }else
- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG1;
-
- ff_er_frame_end(s);
-
- MPV_frame_end(s);
-
- if (s->pict_type == B_TYPE || s->low_delay) {
- *pict= *(AVFrame*)s->current_picture_ptr;
- ff_print_debug_info(s, s->current_picture_ptr);
- } else {
- s->picture_number++;
- /* latency of 1 frame for I and P frames */
- /* XXX: use another variable than picture_number */
- if (s->last_picture_ptr != NULL) {
- *pict= *(AVFrame*)s->last_picture_ptr;
- ff_print_debug_info(s, s->last_picture_ptr);
- }
- }
- if(s->avctx->codec_tag == ff_get_fourcc("VCR2"))
- exchange_uv(pict);
-
- return 1;
- } else {
- return 0;
- }
-}
-
-static int mpeg1_decode_sequence(AVCodecContext *avctx,
- uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int width, height, i, v, j;
- float aspect;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- width = get_bits(&s->gb, 12);
- height = get_bits(&s->gb, 12);
- s->aspect_ratio_info= get_bits(&s->gb, 4);
- if(s->codec_id == CODEC_ID_MPEG1VIDEO){
- aspect= mpeg1_aspect[s->aspect_ratio_info];
- if(aspect!=0.0) avctx->aspect_ratio= width/(aspect*height);
- }
-
- s->frame_rate_index = get_bits(&s->gb, 4);
- if (s->frame_rate_index == 0)
- return -1;
- s->bit_rate = get_bits(&s->gb, 18) * 400;
- if (get_bits1(&s->gb) == 0) /* marker */
- return -1;
- if (width <= 0 || height <= 0 ||
- (width % 2) != 0 || (height % 2) != 0)
- return -1;
- if (width != s->width ||
- height != s->height) {
- /* start new mpeg1 context decoding */
- s->out_format = FMT_MPEG1;
- if (s1->mpeg_enc_ctx_allocated) {
- MPV_common_end(s);
- }
- s->width = width;
- s->height = height;
- avctx->has_b_frames= 1;
- s->avctx = avctx;
- avctx->width = width;
- avctx->height = height;
- av_reduce(
- &avctx->frame_rate,
- &avctx->frame_rate_base,
- frame_rate_tab[s->frame_rate_index],
- MPEG1_FRAME_RATE_BASE, //FIXME store in allready reduced form
- 1<<30
- );
- avctx->bit_rate = s->bit_rate;
-
- //get_format() or set_video(width,height,aspect,pix_fmt);
- //until then pix_fmt may be changed right after codec init
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
- avctx->idct_algo = FF_IDCT_SIMPLE;
-
- if (MPV_common_init(s) < 0)
- return -1;
- s1->mpeg_enc_ctx_allocated = 1;
- }
-
- skip_bits(&s->gb, 10); /* vbv_buffer_size */
- skip_bits(&s->gb, 1);
-
- /* get matrix */
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j = s->intra_scantable.permutated[i];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
-#ifdef DEBUG
- dprintf("intra matrix present\n");
- for(i=0;i<64;i++)
- dprintf(" %d", s->intra_matrix[s->intra_scantable.permutated[i]]);
- printf("\n");
-#endif
- } else {
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
- }
- }
- if (get_bits1(&s->gb)) {
- for(i=0;i<64;i++) {
- v = get_bits(&s->gb, 8);
- j = s->intra_scantable.permutated[i];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
-#ifdef DEBUG
- dprintf("non intra matrix present\n");
- for(i=0;i<64;i++)
- dprintf(" %d", s->inter_matrix[s->intra_scantable.permutated[i]]);
- printf("\n");
-#endif
- } else {
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
- }
-
- /* we set mpeg2 parameters so that it emulates mpeg1 */
- s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
- s->frame_pred_frame_dct = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
- avctx->sub_id = 1; /* indicates mpeg1 */
- return 0;
-}
-
-static int vcr2_init_sequence(AVCodecContext *avctx)
-{
- Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
- int i, v;
-
- /* start new mpeg1 context decoding */
- s->out_format = FMT_MPEG1;
- if (s1->mpeg_enc_ctx_allocated) {
- MPV_common_end(s);
- }
- s->width = avctx->width;
- s->height = avctx->height;
- avctx->has_b_frames= 0; //true?
- s->low_delay= 1;
- s->avctx = avctx;
-
- //get_format() or set_video(width,height,aspect,pix_fmt);
- //until then pix_fmt may be changed right after codec init
- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT )
- avctx->idct_algo = FF_IDCT_SIMPLE;
-
- if (MPV_common_init(s) < 0)
- return -1;
- s1->mpeg_enc_ctx_allocated = 1;
-
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
- v = ff_mpeg1_default_intra_matrix[i];
- s->intra_matrix[j] = v;
- s->chroma_intra_matrix[j] = v;
-
- v = ff_mpeg1_default_non_intra_matrix[i];
- s->inter_matrix[j] = v;
- s->chroma_inter_matrix[j] = v;
- }
-
- s->progressive_sequence = 1;
- s->progressive_frame = 1;
- s->picture_structure = PICT_FRAME;
- s->frame_pred_frame_dct = 1;
- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
- avctx->sub_id = 2; /* indicates mpeg2 */
- return 0;
-}
-
-
-static void mpeg_decode_user_data(AVCodecContext *avctx,
- const uint8_t *buf, int buf_size)
-{
- const uint8_t *p;
- int len, flags;
- p = buf;
- len = buf_size;
-
- /* we parse the DTG active format information */
- if (len >= 5 &&
- p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
- flags = p[4];
- p += 5;
- len -= 5;
- if (flags & 0x80) {
- /* skip event id */
- if (len < 2)
- return;
- p += 2;
- len -= 2;
- }
- if (flags & 0x40) {
- if (len < 1)
- return;
- avctx->dtg_active_format = p[0] & 0x0f;
- }
- }
-}
-
-/**
- * finds the end of the current frame in the bitstream.
- * @return the position of the first byte of the next frame, or -1
- */
-static int mpeg1_find_frame_end(MpegEncContext *s, uint8_t *buf, int buf_size){
- ParseContext *pc= &s->parse_context;
- int i;
- uint32_t state;
-
- state= pc->state;
-
- i=0;
- if(!pc->frame_start_found){
- for(i=0; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
- i++;
- pc->frame_start_found=1;
- break;
- }
- }
- }
-
- if(pc->frame_start_found){
- for(; i<buf_size; i++){
- state= (state<<8) | buf[i];
- if((state&0xFFFFFF00) == 0x100){
- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){
- pc->frame_start_found=0;
- pc->state=-1;
- return i-3;
- }
- }
- }
- }
- pc->state= state;
- return END_NOT_FOUND;
-}
-
-/* handle buffering and image synchronisation */
-static int mpeg_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- Mpeg1Context *s = avctx->priv_data;
- uint8_t *buf_end, *buf_ptr;
- int ret, start_code, input_size;
- AVFrame *picture = data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
- dprintf("fill_buffer\n");
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0 && s2->low_delay==0 && s2->next_picture_ptr) {
- *picture= *(AVFrame*)s2->next_picture_ptr;
- s2->next_picture_ptr= NULL;
-
- *data_size = sizeof(AVFrame);
- return 0;
- }
-
- if(s2->flags&CODEC_FLAG_TRUNCATED){
- int next= mpeg1_find_frame_end(s2, buf, buf_size);
-
- if( ff_combine_frame(s2, next, &buf, &buf_size) < 0 )
- return buf_size;
- }
-
- buf_ptr = buf;
- buf_end = buf + buf_size;
-
-#if 0
- if (s->repeat_field % 2 == 1) {
- s->repeat_field++;
- //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number,
- // s2->picture_number, s->repeat_field);
- if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) {
- *data_size = sizeof(AVPicture);
- goto the_end;
- }
- }
-#endif
-
- if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == ff_get_fourcc("VCR2"))
- vcr2_init_sequence(avctx);
-
- for(;;) {
- /* find start next code */
- start_code = find_start_code(&buf_ptr, buf_end);
- if (start_code < 0){
- if(s2->pict_type != B_TYPE || avctx->hurry_up==0){
- if (slice_end(avctx, picture)) {
- if(s2->last_picture_ptr) //FIXME merge with the stuff in mpeg_decode_slice
- *data_size = sizeof(AVPicture);
- }
- }
- return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
- }
-
- input_size = buf_end - buf_ptr;
-
- if(avctx->debug & FF_DEBUG_STARTCODE){
- printf("%3X at %d left %d\n", start_code, buf_ptr-buf, input_size);
- }
-
- /* prepare data for next start code */
- switch(start_code) {
- case SEQ_START_CODE:
- mpeg1_decode_sequence(avctx, buf_ptr,
- input_size);
- break;
-
- case PICTURE_START_CODE:
- /* we have a complete image : we try to decompress it */
- mpeg1_decode_picture(avctx,
- buf_ptr, input_size);
- break;
- case EXT_START_CODE:
- mpeg_decode_extension(avctx,
- buf_ptr, input_size);
- break;
- case USER_START_CODE:
- mpeg_decode_user_data(avctx,
- buf_ptr, input_size);
- break;
- case GOP_START_CODE:
- s2->first_field=0;
- break;
- default:
- if (start_code >= SLICE_MIN_START_CODE &&
- start_code <= SLICE_MAX_START_CODE) {
-
- /* skip b frames if we dont have reference frames */
- if(s2->last_picture_ptr==NULL && s2->pict_type==B_TYPE) break;
- /* skip b frames if we are in a hurry */
- if(avctx->hurry_up && s2->pict_type==B_TYPE) break;
- /* skip everything if we are in a hurry>=5 */
- if(avctx->hurry_up>=5) break;
-
- if (!s->mpeg_enc_ctx_allocated) break;
-
- ret = mpeg_decode_slice(avctx, picture,
- start_code, &buf_ptr, input_size);
- emms_c();
-
- if(ret < 0){
- if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0)
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR);
- if(ret==DECODE_SLICE_FATAL_ERROR) return -1;
- }else{
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END);
- }
- }
- break;
- }
- }
-}
-
-static int mpeg_decode_end(AVCodecContext *avctx)
-{
- Mpeg1Context *s = avctx->priv_data;
-
- if (s->mpeg_enc_ctx_allocated)
- MPV_common_end(&s->mpeg_enc_ctx);
- return 0;
-}
-
-AVCodec mpeg1video_decoder = {
- "mpeg1video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
- .flush= ff_mpeg_flush,
-};
-
-AVCodec mpeg2video_decoder = {
- "mpeg2video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(Mpeg1Context),
- mpeg_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
- .flush= ff_mpeg_flush,
-};
-
-#ifdef HAVE_XVMC
-static int mpeg_mc_decode_init(AVCodecContext *avctx){
- Mpeg1Context *s;
-
- if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
- return -1;
- if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) )
- dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
-
- mpeg_decode_init(avctx);
- s = avctx->priv_data;
-
- avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
- avctx->xvmc_acceleration = 1;
-
- return 0;
-}
-
-AVCodec mpeg_xvmc_decoder = {
- "mpegvideo_xvmc",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO_XVMC,
- sizeof(Mpeg1Context),
- mpeg_mc_decode_init,
- NULL,
- mpeg_decode_end,
- mpeg_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED,
-};
-
-#endif
-
-/* this is ugly i know, but the alternative is too make
- hundreds of vars global and prefix them with ff_mpeg1_
- which is far uglier. */
-#include "mdec.c"
+++ /dev/null
-/**
- * @file mpeg12data.h
- * MPEG1/2 tables.
- */
-
-const int16_t ff_mpeg1_default_intra_matrix[64] = {
- 8, 16, 19, 22, 26, 27, 29, 34,
- 16, 16, 22, 24, 27, 29, 34, 37,
- 19, 22, 26, 27, 29, 34, 34, 38,
- 22, 22, 26, 27, 29, 34, 37, 40,
- 22, 26, 27, 29, 32, 35, 40, 48,
- 26, 27, 29, 32, 35, 40, 48, 58,
- 26, 27, 29, 34, 38, 46, 56, 69,
- 27, 29, 35, 38, 46, 56, 69, 83
-};
-
-const int16_t ff_mpeg1_default_non_intra_matrix[64] = {
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
-};
-
-static const unsigned char vlc_dc_table[256] = {
- 0, 1, 2, 2,
- 3, 3, 3, 3,
- 4, 4, 4, 4, 4, 4, 4, 4,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-};
-
-static const uint16_t vlc_dc_lum_code[12] = {
- 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff,
-};
-static const unsigned char vlc_dc_lum_bits[12] = {
- 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9,
-};
-
-const uint16_t vlc_dc_chroma_code[12] = {
- 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff,
-};
-const unsigned char vlc_dc_chroma_bits[12] = {
- 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10,
-};
-
-static const uint16_t mpeg1_vlc[113][2] = {
- { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 },
- { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 },
- { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 },
- { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 },
- { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 },
- { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 },
- { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 },
- { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 },
- { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 },
- { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 },
- { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 },
- { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 },
- { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 },
- { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 },
- { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 },
- { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 },
- { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 },
- { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 },
- { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 },
- { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 },
- { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
- { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 },
- { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 },
- { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 },
- { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 },
- { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 },
- { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 },
- { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 },
- { 0x1, 6 }, /* escape */
- { 0x2, 2 }, /* EOB */
-};
-
-static const uint16_t mpeg2_vlc[113][2] = {
- {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
- {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
- {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
- {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
- {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
- {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
- {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
- {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
- {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
- {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15},
- {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
- {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
- {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
- {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
- {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7},
- {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5},
- {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6},
- {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9},
- {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16},
- {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12},
- {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13},
- {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16},
- {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16},
- {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16},
- {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12},
- {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13},
- {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16},
- {0x1d,16}, {0x1c,16}, {0x1b,16},
- {0x01,6}, /* escape */
- {0x06,4}, /* EOB */
-};
-
-static const int8_t mpeg1_level[111] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32,
- 33, 34, 35, 36, 37, 38, 39, 40,
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 1, 2, 3, 4, 5, 1,
- 2, 3, 4, 1, 2, 3, 1, 2,
- 3, 1, 2, 3, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const int8_t mpeg1_run[111] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 2, 3,
- 3, 3, 3, 4, 4, 4, 5, 5,
- 5, 6, 6, 6, 7, 7, 8, 8,
- 9, 9, 10, 10, 11, 11, 12, 12,
- 13, 13, 14, 14, 15, 15, 16, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31,
-};
-
-static RLTable rl_mpeg1 = {
- 111,
- 111,
- mpeg1_vlc,
- mpeg1_run,
- mpeg1_level,
-};
-
-static RLTable rl_mpeg2 = {
- 111,
- 111,
- mpeg2_vlc,
- mpeg1_run,
- mpeg1_level,
-};
-
-static const uint8_t mbAddrIncrTable[36][2] = {
- {0x1, 1},
- {0x3, 3},
- {0x2, 3},
- {0x3, 4},
- {0x2, 4},
- {0x3, 5},
- {0x2, 5},
- {0x7, 7},
- {0x6, 7},
- {0xb, 8},
- {0xa, 8},
- {0x9, 8},
- {0x8, 8},
- {0x7, 8},
- {0x6, 8},
- {0x17, 10},
- {0x16, 10},
- {0x15, 10},
- {0x14, 10},
- {0x13, 10},
- {0x12, 10},
- {0x23, 11},
- {0x22, 11},
- {0x21, 11},
- {0x20, 11},
- {0x1f, 11},
- {0x1e, 11},
- {0x1d, 11},
- {0x1c, 11},
- {0x1b, 11},
- {0x1a, 11},
- {0x19, 11},
- {0x18, 11},
- {0x8, 11}, /* escape */
- {0xf, 11}, /* stuffing */
- {0x0, 8}, /* end (and 15 more 0 bits should follow) */
-};
-
-static const uint8_t mbPatTable[63][2] = {
- {0xb, 5},
- {0x9, 5},
- {0xd, 6},
- {0xd, 4},
- {0x17, 7},
- {0x13, 7},
- {0x1f, 8},
- {0xc, 4},
- {0x16, 7},
- {0x12, 7},
- {0x1e, 8},
- {0x13, 5},
- {0x1b, 8},
- {0x17, 8},
- {0x13, 8},
- {0xb, 4},
- {0x15, 7},
- {0x11, 7},
- {0x1d, 8},
- {0x11, 5},
- {0x19, 8},
- {0x15, 8},
- {0x11, 8},
- {0xf, 6},
- {0xf, 8},
- {0xd, 8},
- {0x3, 9},
- {0xf, 5},
- {0xb, 8},
- {0x7, 8},
- {0x7, 9},
- {0xa, 4},
- {0x14, 7},
- {0x10, 7},
- {0x1c, 8},
- {0xe, 6},
- {0xe, 8},
- {0xc, 8},
- {0x2, 9},
- {0x10, 5},
- {0x18, 8},
- {0x14, 8},
- {0x10, 8},
- {0xe, 5},
- {0xa, 8},
- {0x6, 8},
- {0x6, 9},
- {0x12, 5},
- {0x1a, 8},
- {0x16, 8},
- {0x12, 8},
- {0xd, 5},
- {0x9, 8},
- {0x5, 8},
- {0x5, 9},
- {0xc, 5},
- {0x8, 8},
- {0x4, 8},
- {0x4, 9},
- {0x7, 3},
- {0xa, 5},
- {0x8, 5},
- {0xc, 6}
-};
-
-#define MB_TYPE_PAT 0x40000000
-#define MB_TYPE_ZERO_MV 0x20000000
-#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV)
-#define IS_PAT(a) ((a)&MB_TYPE_PAT)
-
-static const uint8_t table_mb_ptype[7][2] = {
- { 3, 5 }, // 0x01 MB_INTRA
- { 1, 2 }, // 0x02 MB_PAT
- { 1, 3 }, // 0x08 MB_FOR
- { 1, 1 }, // 0x0A MB_FOR|MB_PAT
- { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
- { 1, 5 }, // 0x12 MB_QUANT|MB_PAT
- { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
-};
-
-static const uint32_t ptype2mb_type[7] = {
- MB_TYPE_INTRA,
- MB_TYPE_L0 | MB_TYPE_PAT | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_PAT,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT,
-};
-
-static const uint8_t table_mb_btype[11][2] = {
- { 3, 5 }, // 0x01 MB_INTRA
- { 2, 3 }, // 0x04 MB_BACK
- { 3, 3 }, // 0x06 MB_BACK|MB_PAT
- { 2, 4 }, // 0x08 MB_FOR
- { 3, 4 }, // 0x0A MB_FOR|MB_PAT
- { 2, 2 }, // 0x0C MB_FOR|MB_BACK
- { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT
- { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA
- { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT
- { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT
- { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT
-};
-
-static const uint32_t btype2mb_type[11] = {
- MB_TYPE_INTRA,
- MB_TYPE_L1,
- MB_TYPE_L1 | MB_TYPE_PAT,
- MB_TYPE_L0,
- MB_TYPE_L0 | MB_TYPE_PAT,
- MB_TYPE_L0L1,
- MB_TYPE_L0L1 | MB_TYPE_PAT,
- MB_TYPE_QUANT | MB_TYPE_INTRA,
- MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_PAT,
- MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_PAT,
- MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_PAT,
-};
-
-static const uint8_t mbMotionVectorTable[17][2] = {
-{ 0x1, 1 },
-{ 0x1, 2 },
-{ 0x1, 3 },
-{ 0x1, 4 },
-{ 0x3, 6 },
-{ 0x5, 7 },
-{ 0x4, 7 },
-{ 0x3, 7 },
-{ 0xb, 9 },
-{ 0xa, 9 },
-{ 0x9, 9 },
-{ 0x11, 10 },
-{ 0x10, 10 },
-{ 0xf, 10 },
-{ 0xe, 10 },
-{ 0xd, 10 },
-{ 0xc, 10 },
-};
-
-#define MPEG1_FRAME_RATE_BASE 1001
-
-static const int frame_rate_tab[16] = {
- 0,
- 24000,
- 24024,
- 25025,
- 30000,
- 30030,
- 50050,
- 60000,
- 60060,
- // Xing's 15fps: (9)
- 15015,
- // libmpeg3's "Unofficial economy rates": (10-13)
- 5005,
- 10010,
- 12012,
- 15015,
- // random, just to avoid segfault !never encode these
- 25025,
- 25025,
-};
-
-static const uint8_t non_linear_qscale[32] = {
- 0, 1, 2, 3, 4, 5, 6, 7,
- 8,10,12,14,16,18,20,22,
- 24,28,32,36,40,44,48,52,
- 56,64,72,80,88,96,104,112,
-};
-
-uint8_t ff_mpeg1_dc_scale_table[128]={ // MN: mpeg2 really can have such large qscales?
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
-};
-
-static const float mpeg1_aspect[16]={
- 0.0000,
- 1.0000,
- 0.6735,
- 0.7031,
-
- 0.7615,
- 0.8055,
- 0.8437,
- 0.8935,
-
- 0.9157,
- 0.9815,
- 1.0255,
- 1.0695,
-
- 1.0950,
- 1.1575,
- 1.2015,
-};
-
-static const float mpeg2_aspect[16]={
- 0,
- 1.0,
- -3.0/4.0,
- -9.0/16.0,
- -1.0/2.21,
-};
-
+++ /dev/null
-/**
- * @file mpeg4data.h
- * mpeg4 tables.
- */
-
-// shapes
-#define RECT_SHAPE 0
-#define BIN_SHAPE 1
-#define BIN_ONLY_SHAPE 2
-#define GRAY_SHAPE 3
-
-#define SIMPLE_VO_TYPE 1
-#define CORE_VO_TYPE 3
-#define MAIN_VO_TYPE 4
-#define NBIT_VO_TYPE 5
-#define ARTS_VO_TYPE 10
-#define ACE_VO_TYPE 12
-#define ADV_SIMPLE_VO_TYPE 17
-
-// aspect_ratio_info
-#define EXTENDED_PAR 15
-
-//vol_sprite_usage / sprite_enable
-#define STATIC_SPRITE 1
-#define GMC_SPRITE 2
-
-#define MOTION_MARKER 0x1F001
-#define DC_MARKER 0x6B001
-
-static const int mb_type_b_map[4]= {
- MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
- MB_TYPE_L0L1 | MB_TYPE_16x16,
- MB_TYPE_L1 | MB_TYPE_16x16,
- MB_TYPE_L0 | MB_TYPE_16x16,
-};
-
-#define VOS_STARTCODE 0x1B0
-#define USER_DATA_STARTCODE 0x1B2
-#define GOP_STARTCODE 0x1B3
-#define VISUAL_OBJ_STARTCODE 0x1B5
-#define VOP_STARTCODE 0x1B6
-
-/* dc encoding for mpeg4 */
-const uint8_t DCtab_lum[13][2] =
-{
- {3,3}, {3,2}, {2,2}, {2,3}, {1,3}, {1,4}, {1,5}, {1,6}, {1,7},
- {1,8}, {1,9}, {1,10}, {1,11},
-};
-
-const uint8_t DCtab_chrom[13][2] =
-{
- {3,2}, {2,2}, {1,2}, {1,3}, {1,4}, {1,5}, {1,6}, {1,7}, {1,8},
- {1,9}, {1,10}, {1,11}, {1,12},
-};
-
-const uint16_t intra_vlc[103][2] = {
-{ 0x2, 2 },
-{ 0x6, 3 },{ 0xf, 4 },{ 0xd, 5 },{ 0xc, 5 },
-{ 0x15, 6 },{ 0x13, 6 },{ 0x12, 6 },{ 0x17, 7 },
-{ 0x1f, 8 },{ 0x1e, 8 },{ 0x1d, 8 },{ 0x25, 9 },
-{ 0x24, 9 },{ 0x23, 9 },{ 0x21, 9 },{ 0x21, 10 },
-{ 0x20, 10 },{ 0xf, 10 },{ 0xe, 10 },{ 0x7, 11 },
-{ 0x6, 11 },{ 0x20, 11 },{ 0x21, 11 },{ 0x50, 12 },
-{ 0x51, 12 },{ 0x52, 12 },{ 0xe, 4 },{ 0x14, 6 },
-{ 0x16, 7 },{ 0x1c, 8 },{ 0x20, 9 },{ 0x1f, 9 },
-{ 0xd, 10 },{ 0x22, 11 },{ 0x53, 12 },{ 0x55, 12 },
-{ 0xb, 5 },{ 0x15, 7 },{ 0x1e, 9 },{ 0xc, 10 },
-{ 0x56, 12 },{ 0x11, 6 },{ 0x1b, 8 },{ 0x1d, 9 },
-{ 0xb, 10 },{ 0x10, 6 },{ 0x22, 9 },{ 0xa, 10 },
-{ 0xd, 6 },{ 0x1c, 9 },{ 0x8, 10 },{ 0x12, 7 },
-{ 0x1b, 9 },{ 0x54, 12 },{ 0x14, 7 },{ 0x1a, 9 },
-{ 0x57, 12 },{ 0x19, 8 },{ 0x9, 10 },{ 0x18, 8 },
-{ 0x23, 11 },{ 0x17, 8 },{ 0x19, 9 },{ 0x18, 9 },
-{ 0x7, 10 },{ 0x58, 12 },{ 0x7, 4 },{ 0xc, 6 },
-{ 0x16, 8 },{ 0x17, 9 },{ 0x6, 10 },{ 0x5, 11 },
-{ 0x4, 11 },{ 0x59, 12 },{ 0xf, 6 },{ 0x16, 9 },
-{ 0x5, 10 },{ 0xe, 6 },{ 0x4, 10 },{ 0x11, 7 },
-{ 0x24, 11 },{ 0x10, 7 },{ 0x25, 11 },{ 0x13, 7 },
-{ 0x5a, 12 },{ 0x15, 8 },{ 0x5b, 12 },{ 0x14, 8 },
-{ 0x13, 8 },{ 0x1a, 8 },{ 0x15, 9 },{ 0x14, 9 },
-{ 0x13, 9 },{ 0x12, 9 },{ 0x11, 9 },{ 0x26, 11 },
-{ 0x27, 11 },{ 0x5c, 12 },{ 0x5d, 12 },{ 0x5e, 12 },
-{ 0x5f, 12 },{ 0x3, 7 },
-};
-
-const int8_t intra_level[102] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 1, 2, 3,
- 4, 5, 1, 2, 3, 4, 1, 2,
- 3, 1, 2, 3, 1, 2, 3, 1,
- 2, 3, 1, 2, 1, 2, 1, 1,
- 1, 1, 1, 1, 2, 3, 4, 5,
- 6, 7, 8, 1, 2, 3, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
-};
-
-const int8_t intra_run[102] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 2, 2, 2,
- 2, 2, 3, 3, 3, 3, 4, 4,
- 4, 5, 5, 5, 6, 6, 6, 7,
- 7, 7, 8, 8, 9, 9, 10, 11,
- 12, 13, 14, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 2, 2,
- 3, 3, 4, 4, 5, 5, 6, 6,
- 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20,
-};
-
-static RLTable rl_intra = {
- 102,
- 67,
- intra_vlc,
- intra_run,
- intra_level,
-};
-
-static const uint16_t inter_rvlc[170][2]={ //note this is identical to the intra rvlc except that its reordered
-{0x0006, 3},{0x0001, 4},{0x0004, 5},{0x001C, 7},
-{0x003C, 8},{0x003D, 8},{0x007C, 9},{0x00FC, 10},
-{0x00FD, 10},{0x01FC, 11},{0x01FD, 11},{0x03FC, 12},
-{0x07FC, 13},{0x07FD, 13},{0x0BFC, 13},{0x0BFD, 13},
-{0x0FFC, 14},{0x0FFD, 14},{0x1FFC, 15},{0x0007, 3},
-{0x000C, 6},{0x005C, 8},{0x007D, 9},{0x017C, 10},
-{0x02FC, 11},{0x03FD, 12},{0x0DFC, 13},{0x17FC, 14},
-{0x17FD, 14},{0x000A, 4},{0x001D, 7},{0x00BC, 9},
-{0x02FD, 11},{0x05FC, 12},{0x1BFC, 14},{0x1BFD, 14},
-{0x0005, 5},{0x005D, 8},{0x017D, 10},{0x05FD, 12},
-{0x0DFD, 13},{0x1DFC, 14},{0x1FFD, 15},{0x0008, 5},
-{0x006C, 8},{0x037C, 11},{0x0EFC, 13},{0x2FFC, 15},
-{0x0009, 5},{0x00BD, 9},{0x037D, 11},{0x0EFD, 13},
-{0x000D, 6},{0x01BC, 10},{0x06FC, 12},{0x1DFD, 14},
-{0x0014, 6},{0x01BD, 10},{0x06FD, 12},{0x2FFD, 15},
-{0x0015, 6},{0x01DC, 10},{0x0F7C, 13},{0x002C, 7},
-{0x01DD, 10},{0x1EFC, 14},{0x002D, 7},{0x03BC, 11},
-{0x0034, 7},{0x077C, 12},{0x006D, 8},{0x0F7D, 13},
-{0x0074, 8},{0x1EFD, 14},{0x0075, 8},{0x1F7C, 14},
-{0x00DC, 9},{0x1F7D, 14},{0x00DD, 9},{0x1FBC, 14},
-{0x00EC, 9},{0x37FC, 15},{0x01EC, 10},{0x01ED, 10},
-{0x01F4, 10},{0x03BD, 11},{0x03DC, 11},{0x03DD, 11},
-{0x03EC, 11},{0x03ED, 11},{0x03F4, 11},{0x077D, 12},
-{0x07BC, 12},{0x07BD, 12},{0x0FBC, 13},{0x0FBD, 13},
-{0x0FDC, 13},{0x0FDD, 13},{0x1FBD, 14},{0x1FDC, 14},
-{0x1FDD, 14},{0x37FD, 15},{0x3BFC, 15},
-{0x000B, 4},{0x0078, 8},{0x03F5, 11},{0x0FEC, 13},
-{0x1FEC, 14},{0x0012, 5},{0x00ED, 9},{0x07DC, 12},
-{0x1FED, 14},{0x3BFD, 15},{0x0013, 5},{0x03F8, 11},
-{0x3DFC, 15},{0x0018, 6},{0x07DD, 12},{0x0019, 6},
-{0x07EC, 12},{0x0022, 6},{0x0FED, 13},{0x0023, 6},
-{0x0FF4, 13},{0x0035, 7},{0x0FF5, 13},{0x0038, 7},
-{0x0FF8, 13},{0x0039, 7},{0x0FF9, 13},{0x0042, 7},
-{0x1FF4, 14},{0x0043, 7},{0x1FF5, 14},{0x0079, 8},
-{0x1FF8, 14},{0x0082, 8},{0x3DFD, 15},{0x0083, 8},
-{0x00F4, 9},{0x00F5, 9},{0x00F8, 9},{0x00F9, 9},
-{0x0102, 9},{0x0103, 9},{0x01F5, 10},{0x01F8, 10},
-{0x01F9, 10},{0x0202, 10},{0x0203, 10},{0x03F9, 11},
-{0x0402, 11},{0x0403, 11},{0x07ED, 12},{0x07F4, 12},
-{0x07F5, 12},{0x07F8, 12},{0x07F9, 12},{0x0802, 12},
-{0x0803, 12},{0x1002, 13},{0x1003, 13},{0x1FF9, 14},
-{0x2002, 14},{0x2003, 14},{0x3EFC, 15},{0x3EFD, 15},
-{0x3F7C, 15},{0x3F7D, 15},{0x0000, 4}
-};
-
-static const uint8_t inter_rvlc_run[169]={
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 2, 2, 2,
- 2, 2, 2, 2, 3, 3, 3, 3,
- 3, 3, 3, 4, 4, 4, 4, 4,
- 5, 5, 5, 5, 6, 6, 6, 6,
- 7, 7, 7, 7, 8, 8, 8, 9,
- 9, 9, 10, 10, 11, 11, 12, 12,
-13, 13, 14, 14, 15, 15, 16, 16,
-17, 17, 18, 19, 20, 21, 22, 23,
-24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38,
- 0, 0, 0, 0, 0, 1, 1, 1,
- 1, 1, 2, 2, 2, 3, 3, 4,
- 4, 5, 5, 6, 6, 7, 7, 8,
- 8, 9, 9, 10, 10, 11, 11, 12,
-12, 13, 13, 14, 15, 16, 17, 18,
-19, 20, 21, 22, 23, 24, 25, 26,
-27, 28, 29, 30, 31, 32, 33, 34,
-35, 36, 37, 38, 39, 40, 41, 42,
-43, 44,
-};
-
-static const uint8_t inter_rvlc_level[169]={
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
-17, 18, 19, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 1, 2, 3,
- 4, 5, 6, 7, 1, 2, 3, 4,
- 5, 6, 7, 1, 2, 3, 4, 5,
- 1, 2, 3, 4, 1, 2, 3, 4,
- 1, 2, 3, 4, 1, 2, 3, 1,
- 2, 3, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 3, 4, 5, 1, 2, 3,
- 4, 5, 1, 2, 3, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1,
-};
-
-static RLTable rvlc_rl_inter = {
- 169,
- 103,
- inter_rvlc,
- inter_rvlc_run,
- inter_rvlc_level,
-};
-
-static const uint16_t intra_rvlc[170][2]={
-{0x0006, 3},{0x0007, 3},{0x000A, 4},{0x0009, 5},
-{0x0014, 6},{0x0015, 6},{0x0034, 7},{0x0074, 8},
-{0x0075, 8},{0x00DD, 9},{0x00EC, 9},{0x01EC, 10},
-{0x01ED, 10},{0x01F4, 10},{0x03EC, 11},{0x03ED, 11},
-{0x03F4, 11},{0x077D, 12},{0x07BC, 12},{0x0FBD, 13},
-{0x0FDC, 13},{0x07BD, 12},{0x0FDD, 13},{0x1FBD, 14},
-{0x1FDC, 14},{0x1FDD, 14},{0x1FFC, 15},{0x0001, 4},
-{0x0008, 5},{0x002D, 7},{0x006C, 8},{0x006D, 8},
-{0x00DC, 9},{0x01DD, 10},{0x03DC, 11},{0x03DD, 11},
-{0x077C, 12},{0x0FBC, 13},{0x1F7D, 14},{0x1FBC, 14},
-{0x0004, 5},{0x002C, 7},{0x00BC, 9},{0x01DC, 10},
-{0x03BC, 11},{0x03BD, 11},{0x0EFD, 13},{0x0F7C, 13},
-{0x0F7D, 13},{0x1EFD, 14},{0x1F7C, 14},{0x0005, 5},
-{0x005C, 8},{0x00BD, 9},{0x037D, 11},{0x06FC, 12},
-{0x0EFC, 13},{0x1DFD, 14},{0x1EFC, 14},{0x1FFD, 15},
-{0x000C, 6},{0x005D, 8},{0x01BD, 10},{0x03FD, 12},
-{0x06FD, 12},{0x1BFD, 14},{0x000D, 6},{0x007D, 9},
-{0x02FC, 11},{0x05FC, 12},{0x1BFC, 14},{0x1DFC, 14},
-{0x001C, 7},{0x017C, 10},{0x02FD, 11},{0x05FD, 12},
-{0x2FFC, 15},{0x001D, 7},{0x017D, 10},{0x037C, 11},
-{0x0DFD, 13},{0x2FFD, 15},{0x003C, 8},{0x01BC, 10},
-{0x0BFD, 13},{0x17FD, 14},{0x003D, 8},{0x01FD, 11},
-{0x0DFC, 13},{0x37FC, 15},{0x007C, 9},{0x03FC, 12},
-{0x00FC, 10},{0x0BFC, 13},{0x00FD, 10},{0x37FD, 15},
-{0x01FC, 11},{0x07FC, 13},{0x07FD, 13},{0x0FFC, 14},
-{0x0FFD, 14},{0x17FC, 14},{0x3BFC, 15},
-{0x000B, 4},{0x0078, 8},{0x03F5, 11},{0x0FEC, 13},
-{0x1FEC, 14},{0x0012, 5},{0x00ED, 9},{0x07DC, 12},
-{0x1FED, 14},{0x3BFD, 15},{0x0013, 5},{0x03F8, 11},
-{0x3DFC, 15},{0x0018, 6},{0x07DD, 12},{0x0019, 6},
-{0x07EC, 12},{0x0022, 6},{0x0FED, 13},{0x0023, 6},
-{0x0FF4, 13},{0x0035, 7},{0x0FF5, 13},{0x0038, 7},
-{0x0FF8, 13},{0x0039, 7},{0x0FF9, 13},{0x0042, 7},
-{0x1FF4, 14},{0x0043, 7},{0x1FF5, 14},{0x0079, 8},
-{0x1FF8, 14},{0x0082, 8},{0x3DFD, 15},{0x0083, 8},
-{0x00F4, 9},{0x00F5, 9},{0x00F8, 9},{0x00F9, 9},
-{0x0102, 9},{0x0103, 9},{0x01F5, 10},{0x01F8, 10},
-{0x01F9, 10},{0x0202, 10},{0x0203, 10},{0x03F9, 11},
-{0x0402, 11},{0x0403, 11},{0x07ED, 12},{0x07F4, 12},
-{0x07F5, 12},{0x07F8, 12},{0x07F9, 12},{0x0802, 12},
-{0x0803, 12},{0x1002, 13},{0x1003, 13},{0x1FF9, 14},
-{0x2002, 14},{0x2003, 14},{0x3EFC, 15},{0x3EFD, 15},
-{0x3F7C, 15},{0x3F7D, 15},{0x0000, 4}
-};
-
-static const uint8_t intra_rvlc_run[169]={
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 4, 4, 4, 4,
- 4, 4, 5, 5, 5, 5, 5, 5,
- 6, 6, 6, 6, 6, 7, 7, 7,
- 7, 7, 8, 8, 8, 8, 9, 9,
- 9, 9, 10, 10, 11, 11, 12, 12,
-13, 14, 15, 16, 17, 18, 19,
- 0, 0, 0, 0, 0, 1, 1, 1,
- 1, 1, 2, 2, 2, 3, 3, 4,
- 4, 5, 5, 6, 6, 7, 7, 8,
- 8, 9, 9, 10, 10, 11, 11, 12,
-12, 13, 13, 14, 15, 16, 17, 18,
-19, 20, 21, 22, 23, 24, 25, 26,
-27, 28, 29, 30, 31, 32, 33, 34,
-35, 36, 37, 38, 39, 40, 41, 42,
-43, 44,
-};
-
-static const uint8_t intra_rvlc_level[169]={
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
-17, 18, 19, 20, 21, 22, 23, 24,
-25, 26, 27, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 11, 12, 13,
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 1, 2, 3, 4,
- 5, 6, 1, 2, 3, 4, 5, 6,
- 1, 2, 3, 4, 5, 1, 2, 3,
- 4, 5, 1, 2, 3, 4, 1, 2,
- 3, 4, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 3, 4, 5, 1, 2, 3,
- 4, 5, 1, 2, 3, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1,
-};
-
-static RLTable rvlc_rl_intra = {
- 169,
- 103,
- intra_rvlc,
- intra_rvlc_run,
- intra_rvlc_level,
-};
-
-static const uint16_t sprite_trajectory_tab[15][2] = {
- {0x00, 2}, {0x02, 3}, {0x03, 3}, {0x04, 3}, {0x05, 3}, {0x06, 3},
- {0x0E, 4}, {0x1E, 5}, {0x3E, 6}, {0x7E, 7}, {0xFE, 8},
- {0x1FE, 9},{0x3FE, 10},{0x7FE, 11},{0xFFE, 12},
-};
-
-static const uint8_t mb_type_b_tab[4][2] = {
- {1, 1}, {1, 2}, {1, 3}, {1, 4},
-};
-
-static const uint16_t pixel_aspect[16][2]={
- {0, 0},
- {1, 1},
- {12, 11},
- {10, 11},
- {16, 11},
- {40, 33},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
- {0, 0},
-};
-
-/* these matrixes will be permuted for the idct */
-const int16_t ff_mpeg4_default_intra_matrix[64] = {
- 8, 17, 18, 19, 21, 23, 25, 27,
- 17, 18, 19, 21, 23, 25, 27, 28,
- 20, 21, 22, 23, 24, 26, 28, 30,
- 21, 22, 23, 24, 26, 28, 30, 32,
- 22, 23, 24, 26, 28, 30, 32, 35,
- 23, 24, 26, 28, 30, 32, 35, 38,
- 25, 26, 28, 30, 32, 35, 38, 41,
- 27, 28, 30, 32, 35, 38, 41, 45,
-};
-
-const int16_t ff_mpeg4_default_non_intra_matrix[64] = {
- 16, 17, 18, 19, 20, 21, 22, 23,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 18, 19, 20, 21, 22, 23, 24, 25,
- 19, 20, 21, 22, 23, 24, 26, 27,
- 20, 21, 22, 23, 25, 26, 27, 28,
- 21, 22, 23, 24, 26, 27, 28, 30,
- 22, 23, 24, 26, 27, 28, 30, 31,
- 23, 24, 25, 27, 28, 30, 31, 33,
-};
-
-uint8_t ff_mpeg4_y_dc_scale_table[32]={
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,40,42,44,46
-};
-uint8_t ff_mpeg4_c_dc_scale_table[32]={
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,20,21,22,23,24,25
-};
-
-const uint16_t ff_mpeg4_resync_prefix[8]={
- 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
-};
+++ /dev/null
-/*
- * The simplest mpeg audio layer 2 encoder
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mpegaudio.c
- * The simplest mpeg audio layer 2 encoder.
- */
-
-#include "avcodec.h"
-#include "mpegaudio.h"
-
-/* currently, cannot change these constants (need to modify
- quantization stage) */
-#define FRAC_BITS 15
-#define WFRAC_BITS 14
-#define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
-#define FIX(a) ((int)((a) * (1 << FRAC_BITS)))
-
-#define SAMPLES_BUF_SIZE 4096
-
-typedef struct MpegAudioContext {
- PutBitContext pb;
- int nb_channels;
- int freq, bit_rate;
- int lsf; /* 1 if mpeg2 low bitrate selected */
- int bitrate_index; /* bit rate */
- int freq_index;
- int frame_size; /* frame size, in bits, without padding */
- int64_t nb_samples; /* total number of samples encoded */
- /* padding computation */
- int frame_frac, frame_frac_incr, do_padding;
- short samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */
- int samples_offset[MPA_MAX_CHANNELS]; /* offset in samples_buf */
- int sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT];
- unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3]; /* scale factors */
- /* code to group 3 scale factors */
- unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
- int sblimit; /* number of used subbands */
- const unsigned char *alloc_table;
-} MpegAudioContext;
-
-/* define it to use floats in quantization (I don't like floats !) */
-//#define USE_FLOATS
-
-#include "mpegaudiotab.h"
-
-static int MPA_encode_init(AVCodecContext *avctx)
-{
- MpegAudioContext *s = avctx->priv_data;
- int freq = avctx->sample_rate;
- int bitrate = avctx->bit_rate;
- int channels = avctx->channels;
- int i, v, table;
- float a;
-
- if (channels > 2)
- return -1;
- bitrate = bitrate / 1000;
- s->nb_channels = channels;
- s->freq = freq;
- s->bit_rate = bitrate * 1000;
- avctx->frame_size = MPA_FRAME_SIZE;
-
- /* encoding freq */
- s->lsf = 0;
- for(i=0;i<3;i++) {
- if (mpa_freq_tab[i] == freq)
- break;
- if ((mpa_freq_tab[i] / 2) == freq) {
- s->lsf = 1;
- break;
- }
- }
- if (i == 3)
- return -1;
- s->freq_index = i;
-
- /* encoding bitrate & frequency */
- for(i=0;i<15;i++) {
- if (mpa_bitrate_tab[s->lsf][1][i] == bitrate)
- break;
- }
- if (i == 15)
- return -1;
- s->bitrate_index = i;
-
- /* compute total header size & pad bit */
-
- a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0);
- s->frame_size = ((int)a) * 8;
-
- /* frame fractional size to compute padding */
- s->frame_frac = 0;
- s->frame_frac_incr = (int)((a - floor(a)) * 65536.0);
-
- /* select the right allocation table */
- table = l2_select_table(bitrate, s->nb_channels, freq, s->lsf);
-
- /* number of used subbands */
- s->sblimit = sblimit_table[table];
- s->alloc_table = alloc_tables[table];
-
-#ifdef DEBUG
- printf("%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n",
- bitrate, freq, s->frame_size, table, s->frame_frac_incr);
-#endif
-
- for(i=0;i<s->nb_channels;i++)
- s->samples_offset[i] = 0;
-
- for(i=0;i<257;i++) {
- int v;
- v = mpa_enwindow[i];
-#if WFRAC_BITS != 16
- v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
-#endif
- filter_bank[i] = v;
- if ((i & 63) != 0)
- v = -v;
- if (i != 0)
- filter_bank[512 - i] = v;
- }
-
- for(i=0;i<64;i++) {
- v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20));
- if (v <= 0)
- v = 1;
- scale_factor_table[i] = v;
-#ifdef USE_FLOATS
- scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20);
-#else
-#define P 15
- scale_factor_shift[i] = 21 - P - (i / 3);
- scale_factor_mult[i] = (1 << P) * pow(2.0, (i % 3) / 3.0);
-#endif
- }
- for(i=0;i<128;i++) {
- v = i - 64;
- if (v <= -3)
- v = 0;
- else if (v < 0)
- v = 1;
- else if (v == 0)
- v = 2;
- else if (v < 3)
- v = 3;
- else
- v = 4;
- scale_diff_table[i] = v;
- }
-
- for(i=0;i<17;i++) {
- v = quant_bits[i];
- if (v < 0)
- v = -v;
- else
- v = v * 3;
- total_quant_bits[i] = 12 * v;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-/* 32 point floating point IDCT without 1/sqrt(2) coef zero scaling */
-static void idct32(int *out, int *tab)
-{
- int i, j;
- int *t, *t1, xr;
- const int *xp = costab32;
-
- for(j=31;j>=3;j-=2) tab[j] += tab[j - 2];
-
- t = tab + 30;
- t1 = tab + 2;
- do {
- t[0] += t[-4];
- t[1] += t[1 - 4];
- t -= 4;
- } while (t != t1);
-
- t = tab + 28;
- t1 = tab + 4;
- do {
- t[0] += t[-8];
- t[1] += t[1-8];
- t[2] += t[2-8];
- t[3] += t[3-8];
- t -= 8;
- } while (t != t1);
-
- t = tab;
- t1 = tab + 32;
- do {
- t[ 3] = -t[ 3];
- t[ 6] = -t[ 6];
-
- t[11] = -t[11];
- t[12] = -t[12];
- t[13] = -t[13];
- t[15] = -t[15];
- t += 16;
- } while (t != t1);
-
-
- t = tab;
- t1 = tab + 8;
- do {
- int x1, x2, x3, x4;
-
- x3 = MUL(t[16], FIX(SQRT2*0.5));
- x4 = t[0] - x3;
- x3 = t[0] + x3;
-
- x2 = MUL(-(t[24] + t[8]), FIX(SQRT2*0.5));
- x1 = MUL((t[8] - x2), xp[0]);
- x2 = MUL((t[8] + x2), xp[1]);
-
- t[ 0] = x3 + x1;
- t[ 8] = x4 - x2;
- t[16] = x4 + x2;
- t[24] = x3 - x1;
- t++;
- } while (t != t1);
-
- xp += 2;
- t = tab;
- t1 = tab + 4;
- do {
- xr = MUL(t[28],xp[0]);
- t[28] = (t[0] - xr);
- t[0] = (t[0] + xr);
-
- xr = MUL(t[4],xp[1]);
- t[ 4] = (t[24] - xr);
- t[24] = (t[24] + xr);
-
- xr = MUL(t[20],xp[2]);
- t[20] = (t[8] - xr);
- t[ 8] = (t[8] + xr);
-
- xr = MUL(t[12],xp[3]);
- t[12] = (t[16] - xr);
- t[16] = (t[16] + xr);
- t++;
- } while (t != t1);
- xp += 4;
-
- for (i = 0; i < 4; i++) {
- xr = MUL(tab[30-i*4],xp[0]);
- tab[30-i*4] = (tab[i*4] - xr);
- tab[ i*4] = (tab[i*4] + xr);
-
- xr = MUL(tab[ 2+i*4],xp[1]);
- tab[ 2+i*4] = (tab[28-i*4] - xr);
- tab[28-i*4] = (tab[28-i*4] + xr);
-
- xr = MUL(tab[31-i*4],xp[0]);
- tab[31-i*4] = (tab[1+i*4] - xr);
- tab[ 1+i*4] = (tab[1+i*4] + xr);
-
- xr = MUL(tab[ 3+i*4],xp[1]);
- tab[ 3+i*4] = (tab[29-i*4] - xr);
- tab[29-i*4] = (tab[29-i*4] + xr);
-
- xp += 2;
- }
-
- t = tab + 30;
- t1 = tab + 1;
- do {
- xr = MUL(t1[0], *xp);
- t1[0] = (t[0] - xr);
- t[0] = (t[0] + xr);
- t -= 2;
- t1 += 2;
- xp++;
- } while (t >= tab);
-
- for(i=0;i<32;i++) {
- out[i] = tab[bitinv32[i]];
- }
-}
-
-#define WSHIFT (WFRAC_BITS + 15 - FRAC_BITS)
-
-static void filter(MpegAudioContext *s, int ch, short *samples, int incr)
-{
- short *p, *q;
- int sum, offset, i, j;
- int tmp[64];
- int tmp1[32];
- int *out;
-
- // print_pow1(samples, 1152);
-
- offset = s->samples_offset[ch];
- out = &s->sb_samples[ch][0][0][0];
- for(j=0;j<36;j++) {
- /* 32 samples at once */
- for(i=0;i<32;i++) {
- s->samples_buf[ch][offset + (31 - i)] = samples[0];
- samples += incr;
- }
-
- /* filter */
- p = s->samples_buf[ch] + offset;
- q = filter_bank;
- /* maxsum = 23169 */
- for(i=0;i<64;i++) {
- sum = p[0*64] * q[0*64];
- sum += p[1*64] * q[1*64];
- sum += p[2*64] * q[2*64];
- sum += p[3*64] * q[3*64];
- sum += p[4*64] * q[4*64];
- sum += p[5*64] * q[5*64];
- sum += p[6*64] * q[6*64];
- sum += p[7*64] * q[7*64];
- tmp[i] = sum;
- p++;
- q++;
- }
- tmp1[0] = tmp[16] >> WSHIFT;
- for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >> WSHIFT;
- for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >> WSHIFT;
-
- idct32(out, tmp1);
-
- /* advance of 32 samples */
- offset -= 32;
- out += 32;
- /* handle the wrap around */
- if (offset < 0) {
- memmove(s->samples_buf[ch] + SAMPLES_BUF_SIZE - (512 - 32),
- s->samples_buf[ch], (512 - 32) * 2);
- offset = SAMPLES_BUF_SIZE - 512;
- }
- }
- s->samples_offset[ch] = offset;
-
- // print_pow(s->sb_samples, 1152);
-}
-
-static void compute_scale_factors(unsigned char scale_code[SBLIMIT],
- unsigned char scale_factors[SBLIMIT][3],
- int sb_samples[3][12][SBLIMIT],
- int sblimit)
-{
- int *p, vmax, v, n, i, j, k, code;
- int index, d1, d2;
- unsigned char *sf = &scale_factors[0][0];
-
- for(j=0;j<sblimit;j++) {
- for(i=0;i<3;i++) {
- /* find the max absolute value */
- p = &sb_samples[i][0][j];
- vmax = abs(*p);
- for(k=1;k<12;k++) {
- p += SBLIMIT;
- v = abs(*p);
- if (v > vmax)
- vmax = v;
- }
- /* compute the scale factor index using log 2 computations */
- if (vmax > 0) {
- n = av_log2(vmax);
- /* n is the position of the MSB of vmax. now
- use at most 2 compares to find the index */
- index = (21 - n) * 3 - 3;
- if (index >= 0) {
- while (vmax <= scale_factor_table[index+1])
- index++;
- } else {
- index = 0; /* very unlikely case of overflow */
- }
- } else {
- index = 62; /* value 63 is not allowed */
- }
-
-#if 0
- printf("%2d:%d in=%x %x %d\n",
- j, i, vmax, scale_factor_table[index], index);
-#endif
- /* store the scale factor */
- assert(index >=0 && index <= 63);
- sf[i] = index;
- }
-
- /* compute the transmission factor : look if the scale factors
- are close enough to each other */
- d1 = scale_diff_table[sf[0] - sf[1] + 64];
- d2 = scale_diff_table[sf[1] - sf[2] + 64];
-
- /* handle the 25 cases */
- switch(d1 * 5 + d2) {
- case 0*5+0:
- case 0*5+4:
- case 3*5+4:
- case 4*5+0:
- case 4*5+4:
- code = 0;
- break;
- case 0*5+1:
- case 0*5+2:
- case 4*5+1:
- case 4*5+2:
- code = 3;
- sf[2] = sf[1];
- break;
- case 0*5+3:
- case 4*5+3:
- code = 3;
- sf[1] = sf[2];
- break;
- case 1*5+0:
- case 1*5+4:
- case 2*5+4:
- code = 1;
- sf[1] = sf[0];
- break;
- case 1*5+1:
- case 1*5+2:
- case 2*5+0:
- case 2*5+1:
- case 2*5+2:
- code = 2;
- sf[1] = sf[2] = sf[0];
- break;
- case 2*5+3:
- case 3*5+3:
- code = 2;
- sf[0] = sf[1] = sf[2];
- break;
- case 3*5+0:
- case 3*5+1:
- case 3*5+2:
- code = 2;
- sf[0] = sf[2] = sf[1];
- break;
- case 1*5+3:
- code = 2;
- if (sf[0] > sf[2])
- sf[0] = sf[2];
- sf[1] = sf[2] = sf[0];
- break;
- default:
- av_abort();
- }
-
-#if 0
- printf("%d: %2d %2d %2d %d %d -> %d\n", j,
- sf[0], sf[1], sf[2], d1, d2, code);
-#endif
- scale_code[j] = code;
- sf += 3;
- }
-}
-
-/* The most important function : psycho acoustic module. In this
- encoder there is basically none, so this is the worst you can do,
- but also this is the simpler. */
-static void psycho_acoustic_model(MpegAudioContext *s, short smr[SBLIMIT])
-{
- int i;
-
- for(i=0;i<s->sblimit;i++) {
- smr[i] = (int)(fixed_smr[i] * 10);
- }
-}
-
-
-#define SB_NOTALLOCATED 0
-#define SB_ALLOCATED 1
-#define SB_NOMORE 2
-
-/* Try to maximize the smr while using a number of bits inferior to
- the frame size. I tried to make the code simpler, faster and
- smaller than other encoders :-) */
-static void compute_bit_allocation(MpegAudioContext *s,
- short smr1[MPA_MAX_CHANNELS][SBLIMIT],
- unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
- int *padding)
-{
- int i, ch, b, max_smr, max_ch, max_sb, current_frame_size, max_frame_size;
- int incr;
- short smr[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char subband_status[MPA_MAX_CHANNELS][SBLIMIT];
- const unsigned char *alloc;
-
- memcpy(smr, smr1, s->nb_channels * sizeof(short) * SBLIMIT);
- memset(subband_status, SB_NOTALLOCATED, s->nb_channels * SBLIMIT);
- memset(bit_alloc, 0, s->nb_channels * SBLIMIT);
-
- /* compute frame size and padding */
- max_frame_size = s->frame_size;
- s->frame_frac += s->frame_frac_incr;
- if (s->frame_frac >= 65536) {
- s->frame_frac -= 65536;
- s->do_padding = 1;
- max_frame_size += 8;
- } else {
- s->do_padding = 0;
- }
-
- /* compute the header + bit alloc size */
- current_frame_size = 32;
- alloc = s->alloc_table;
- for(i=0;i<s->sblimit;i++) {
- incr = alloc[0];
- current_frame_size += incr * s->nb_channels;
- alloc += 1 << incr;
- }
- for(;;) {
- /* look for the subband with the largest signal to mask ratio */
- max_sb = -1;
- max_ch = -1;
- max_smr = 0x80000000;
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<s->sblimit;i++) {
- if (smr[ch][i] > max_smr && subband_status[ch][i] != SB_NOMORE) {
- max_smr = smr[ch][i];
- max_sb = i;
- max_ch = ch;
- }
- }
- }
-#if 0
- printf("current=%d max=%d max_sb=%d alloc=%d\n",
- current_frame_size, max_frame_size, max_sb,
- bit_alloc[max_sb]);
-#endif
- if (max_sb < 0)
- break;
-
- /* find alloc table entry (XXX: not optimal, should use
- pointer table) */
- alloc = s->alloc_table;
- for(i=0;i<max_sb;i++) {
- alloc += 1 << alloc[0];
- }
-
- if (subband_status[max_ch][max_sb] == SB_NOTALLOCATED) {
- /* nothing was coded for this band: add the necessary bits */
- incr = 2 + nb_scale_factors[s->scale_code[max_ch][max_sb]] * 6;
- incr += total_quant_bits[alloc[1]];
- } else {
- /* increments bit allocation */
- b = bit_alloc[max_ch][max_sb];
- incr = total_quant_bits[alloc[b + 1]] -
- total_quant_bits[alloc[b]];
- }
-
- if (current_frame_size + incr <= max_frame_size) {
- /* can increase size */
- b = ++bit_alloc[max_ch][max_sb];
- current_frame_size += incr;
- /* decrease smr by the resolution we added */
- smr[max_ch][max_sb] = smr1[max_ch][max_sb] - quant_snr[alloc[b]];
- /* max allocation size reached ? */
- if (b == ((1 << alloc[0]) - 1))
- subband_status[max_ch][max_sb] = SB_NOMORE;
- else
- subband_status[max_ch][max_sb] = SB_ALLOCATED;
- } else {
- /* cannot increase the size of this subband */
- subband_status[max_ch][max_sb] = SB_NOMORE;
- }
- }
- *padding = max_frame_size - current_frame_size;
- assert(*padding >= 0);
-
-#if 0
- for(i=0;i<s->sblimit;i++) {
- printf("%d ", bit_alloc[i]);
- }
- printf("\n");
-#endif
-}
-
-/*
- * Output the mpeg audio layer 2 frame. Note how the code is small
- * compared to other encoders :-)
- */
-static void encode_frame(MpegAudioContext *s,
- unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT],
- int padding)
-{
- int i, j, k, l, bit_alloc_bits, b, ch;
- unsigned char *sf;
- int q[3];
- PutBitContext *p = &s->pb;
-
- /* header */
-
- put_bits(p, 12, 0xfff);
- put_bits(p, 1, 1 - s->lsf); /* 1 = mpeg1 ID, 0 = mpeg2 lsf ID */
- put_bits(p, 2, 4-2); /* layer 2 */
- put_bits(p, 1, 1); /* no error protection */
- put_bits(p, 4, s->bitrate_index);
- put_bits(p, 2, s->freq_index);
- put_bits(p, 1, s->do_padding); /* use padding */
- put_bits(p, 1, 0); /* private_bit */
- put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO);
- put_bits(p, 2, 0); /* mode_ext */
- put_bits(p, 1, 0); /* no copyright */
- put_bits(p, 1, 1); /* original */
- put_bits(p, 2, 0); /* no emphasis */
-
- /* bit allocation */
- j = 0;
- for(i=0;i<s->sblimit;i++) {
- bit_alloc_bits = s->alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- put_bits(p, bit_alloc_bits, bit_alloc[ch][i]);
- }
- j += 1 << bit_alloc_bits;
- }
-
- /* scale codes */
- for(i=0;i<s->sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i])
- put_bits(p, 2, s->scale_code[ch][i]);
- }
- }
-
- /* scale factors */
- for(i=0;i<s->sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i]) {
- sf = &s->scale_factors[ch][i][0];
- switch(s->scale_code[ch][i]) {
- case 0:
- put_bits(p, 6, sf[0]);
- put_bits(p, 6, sf[1]);
- put_bits(p, 6, sf[2]);
- break;
- case 3:
- case 1:
- put_bits(p, 6, sf[0]);
- put_bits(p, 6, sf[2]);
- break;
- case 2:
- put_bits(p, 6, sf[0]);
- break;
- }
- }
- }
- }
-
- /* quantization & write sub band samples */
-
- for(k=0;k<3;k++) {
- for(l=0;l<12;l+=3) {
- j = 0;
- for(i=0;i<s->sblimit;i++) {
- bit_alloc_bits = s->alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- b = bit_alloc[ch][i];
- if (b) {
- int qindex, steps, m, sample, bits;
- /* we encode 3 sub band samples of the same sub band at a time */
- qindex = s->alloc_table[j+b];
- steps = quant_steps[qindex];
- for(m=0;m<3;m++) {
- sample = s->sb_samples[ch][k][l + m][i];
- /* divide by scale factor */
-#ifdef USE_FLOATS
- {
- float a;
- a = (float)sample * scale_factor_inv_table[s->scale_factors[ch][i][k]];
- q[m] = (int)((a + 1.0) * steps * 0.5);
- }
-#else
- {
- int q1, e, shift, mult;
- e = s->scale_factors[ch][i][k];
- shift = scale_factor_shift[e];
- mult = scale_factor_mult[e];
-
- /* normalize to P bits */
- if (shift < 0)
- q1 = sample << (-shift);
- else
- q1 = sample >> shift;
- q1 = (q1 * mult) >> P;
- q[m] = ((q1 + (1 << P)) * steps) >> (P + 1);
- }
-#endif
- if (q[m] >= steps)
- q[m] = steps - 1;
- assert(q[m] >= 0 && q[m] < steps);
- }
- bits = quant_bits[qindex];
- if (bits < 0) {
- /* group the 3 values to save bits */
- put_bits(p, -bits,
- q[0] + steps * (q[1] + steps * q[2]));
-#if 0
- printf("%d: gr1 %d\n",
- i, q[0] + steps * (q[1] + steps * q[2]));
-#endif
- } else {
-#if 0
- printf("%d: gr3 %d %d %d\n",
- i, q[0], q[1], q[2]);
-#endif
- put_bits(p, bits, q[0]);
- put_bits(p, bits, q[1]);
- put_bits(p, bits, q[2]);
- }
- }
- }
- /* next subband in alloc table */
- j += 1 << bit_alloc_bits;
- }
- }
- }
-
- /* padding */
- for(i=0;i<padding;i++)
- put_bits(p, 1, 0);
-
- /* flush */
- flush_put_bits(p);
-}
-
-static int MPA_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- MpegAudioContext *s = avctx->priv_data;
- short *samples = data;
- short smr[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
- int padding, i;
-
- for(i=0;i<s->nb_channels;i++) {
- filter(s, i, samples + i, s->nb_channels);
- }
-
- for(i=0;i<s->nb_channels;i++) {
- compute_scale_factors(s->scale_code[i], s->scale_factors[i],
- s->sb_samples[i], s->sblimit);
- }
- for(i=0;i<s->nb_channels;i++) {
- psycho_acoustic_model(s, smr[i]);
- }
- compute_bit_allocation(s, smr, bit_alloc, &padding);
-
- init_put_bits(&s->pb, frame, MPA_MAX_CODED_FRAME_SIZE, NULL, NULL);
-
- encode_frame(s, bit_alloc, padding);
-
- s->nb_samples += MPA_FRAME_SIZE;
- return pbBufPtr(&s->pb) - s->pb.buf;
-}
-
-static int MPA_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
- return 0;
-}
-
-AVCodec mp2_encoder = {
- "mp2",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MpegAudioContext),
- MPA_encode_init,
- MPA_encode_frame,
- MPA_encode_close,
- NULL,
-};
-
-#undef FIX
+++ /dev/null
-/**
- * @file mpegaudio.h
- * mpeg audio declarations for both encoder and decoder.
- */
-
-/* max frame size, in samples */
-#define MPA_FRAME_SIZE 1152
-
-/* max compressed frame size */
-#define MPA_MAX_CODED_FRAME_SIZE 1792
-
-#define MPA_MAX_CHANNELS 2
-
-#define SBLIMIT 32 /* number of subbands */
-
-#define MPA_STEREO 0
-#define MPA_JSTEREO 1
-#define MPA_DUAL 2
-#define MPA_MONO 3
-
-int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
-
-extern const uint16_t mpa_bitrate_tab[2][3][15];
-extern const uint16_t mpa_freq_tab[3];
-extern const unsigned char *alloc_tables[5];
-extern const double enwindow[512];
-extern const int sblimit_table[5];
-extern const int quant_steps[17];
-extern const int quant_bits[17];
-extern const int32_t mpa_enwindow[257];
+++ /dev/null
-/*
- * MPEG Audio decoder
- * Copyright (c) 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mpegaudiodec.c
- * MPEG Audio decoder.
- */
-
-//#define DEBUG
-#include "avcodec.h"
-#include "mpegaudio.h"
-
-/*
- * TODO:
- * - in low precision mode, use more 16 bit multiplies in synth filter
- * - test lsf / mpeg25 extensively.
- */
-
-/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
- audio decoder */
-#ifdef CONFIG_MPEGAUDIO_HP
-#define USE_HIGHPRECISION
-#endif
-
-#ifdef USE_HIGHPRECISION
-#define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
-#define WFRAC_BITS 16 /* fractional bits for window */
-#else
-#define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
-#define WFRAC_BITS 14 /* fractional bits for window */
-#endif
-
-#define FRAC_ONE (1 << FRAC_BITS)
-
-#define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
-#define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
-#define FIX(a) ((int)((a) * FRAC_ONE))
-/* WARNING: only correct for posititive numbers */
-#define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
-#define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
-
-#if FRAC_BITS <= 15
-typedef int16_t MPA_INT;
-#else
-typedef int32_t MPA_INT;
-#endif
-
-/****************/
-
-#define HEADER_SIZE 4
-#define BACKSTEP_SIZE 512
-
-typedef struct MPADecodeContext {
- uint8_t inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */
- int inbuf_index;
- uint8_t *inbuf_ptr, *inbuf;
- int frame_size;
- int free_format_frame_size; /* frame size in case of free format
- (zero if currently unknown) */
- /* next header (used in free format parsing) */
- uint32_t free_format_next_header;
- int error_protection;
- int layer;
- int sample_rate;
- int sample_rate_index; /* between 0 and 8 */
- int bit_rate;
- int old_frame_size;
- GetBitContext gb;
- int nb_channels;
- int mode;
- int mode_ext;
- int lsf;
- MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2] __attribute__((aligned(16)));
- int synth_buf_offset[MPA_MAX_CHANNELS];
- int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT] __attribute__((aligned(16)));
- int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
-#ifdef DEBUG
- int frame_count;
-#endif
-} MPADecodeContext;
-
-/* layer 3 "granule" */
-typedef struct GranuleDef {
- uint8_t scfsi;
- int part2_3_length;
- int big_values;
- int global_gain;
- int scalefac_compress;
- uint8_t block_type;
- uint8_t switch_point;
- int table_select[3];
- int subblock_gain[3];
- uint8_t scalefac_scale;
- uint8_t count1table_select;
- int region_size[3]; /* number of huffman codes in each region */
- int preflag;
- int short_start, long_end; /* long/short band indexes */
- uint8_t scale_factors[40];
- int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */
-} GranuleDef;
-
-#define MODE_EXT_MS_STEREO 2
-#define MODE_EXT_I_STEREO 1
-
-/* layer 3 huffman tables */
-typedef struct HuffTable {
- int xsize;
- const uint8_t *bits;
- const uint16_t *codes;
-} HuffTable;
-
-#include "mpegaudiodectab.h"
-
-/* vlc structure for decoding layer 3 huffman tables */
-static VLC huff_vlc[16];
-static uint8_t *huff_code_table[16];
-static VLC huff_quad_vlc[2];
-/* computed from band_size_long */
-static uint16_t band_index_long[9][23];
-/* XXX: free when all decoders are closed */
-#define TABLE_4_3_SIZE (8191 + 16)
-static int8_t *table_4_3_exp;
-#if FRAC_BITS <= 15
-static uint16_t *table_4_3_value;
-#else
-static uint32_t *table_4_3_value;
-#endif
-/* intensity stereo coef table */
-static int32_t is_table[2][16];
-static int32_t is_table_lsf[2][2][16];
-static int32_t csa_table[8][2];
-static int32_t mdct_win[8][36];
-
-/* lower 2 bits: modulo 3, higher bits: shift */
-static uint16_t scale_factor_modshift[64];
-/* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
-static int32_t scale_factor_mult[15][3];
-/* mult table for layer 2 group quantization */
-
-#define SCALE_GEN(v) \
-{ FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) }
-
-static int32_t scale_factor_mult2[3][3] = {
- SCALE_GEN(4.0 / 3.0), /* 3 steps */
- SCALE_GEN(4.0 / 5.0), /* 5 steps */
- SCALE_GEN(4.0 / 9.0), /* 9 steps */
-};
-
-/* 2^(n/4) */
-static uint32_t scale_factor_mult3[4] = {
- FIXR(1.0),
- FIXR(1.18920711500272106671),
- FIXR(1.41421356237309504880),
- FIXR(1.68179283050742908605),
-};
-
-static MPA_INT window[512] __attribute__((aligned(16)));
-
-/* layer 1 unscaling */
-/* n = number of bits of the mantissa minus 1 */
-static inline int l1_unscale(int n, int mant, int scale_factor)
-{
- int shift, mod;
- int64_t val;
-
- shift = scale_factor_modshift[scale_factor];
- mod = shift & 3;
- shift >>= 2;
- val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
- shift += n;
- /* NOTE: at this point, 1 <= shift >= 21 + 15 */
- return (int)((val + (1LL << (shift - 1))) >> shift);
-}
-
-static inline int l2_unscale_group(int steps, int mant, int scale_factor)
-{
- int shift, mod, val;
-
- shift = scale_factor_modshift[scale_factor];
- mod = shift & 3;
- shift >>= 2;
-
- val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
- /* NOTE: at this point, 0 <= shift <= 21 */
- if (shift > 0)
- val = (val + (1 << (shift - 1))) >> shift;
- return val;
-}
-
-/* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
-static inline int l3_unscale(int value, int exponent)
-{
-#if FRAC_BITS <= 15
- unsigned int m;
-#else
- uint64_t m;
-#endif
- int e;
-
- e = table_4_3_exp[value];
- e += (exponent >> 2);
- e = FRAC_BITS - e;
-#if FRAC_BITS <= 15
- if (e > 31)
- e = 31;
-#endif
- m = table_4_3_value[value];
-#if FRAC_BITS <= 15
- m = (m * scale_factor_mult3[exponent & 3]);
- m = (m + (1 << (e-1))) >> e;
- return m;
-#else
- m = MUL64(m, scale_factor_mult3[exponent & 3]);
- m = (m + (uint64_t_C(1) << (e-1))) >> e;
- return m;
-#endif
-}
-
-/* all integer n^(4/3) computation code */
-#define DEV_ORDER 13
-
-#define POW_FRAC_BITS 24
-#define POW_FRAC_ONE (1 << POW_FRAC_BITS)
-#define POW_FIX(a) ((int)((a) * POW_FRAC_ONE))
-#define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS)
-
-static int dev_4_3_coefs[DEV_ORDER];
-
-static int pow_mult3[3] = {
- POW_FIX(1.0),
- POW_FIX(1.25992104989487316476),
- POW_FIX(1.58740105196819947474),
-};
-
-static void int_pow_init(void)
-{
- int i, a;
-
- a = POW_FIX(1.0);
- for(i=0;i<DEV_ORDER;i++) {
- a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1);
- dev_4_3_coefs[i] = a;
- }
-}
-
-/* return the mantissa and the binary exponent */
-static int int_pow(int i, int *exp_ptr)
-{
- int e, er, eq, j;
- int a, a1;
-
- /* renormalize */
- a = i;
- e = POW_FRAC_BITS;
- while (a < (1 << (POW_FRAC_BITS - 1))) {
- a = a << 1;
- e--;
- }
- a -= (1 << POW_FRAC_BITS);
- a1 = 0;
- for(j = DEV_ORDER - 1; j >= 0; j--)
- a1 = POW_MULL(a, dev_4_3_coefs[j] + a1);
- a = (1 << POW_FRAC_BITS) + a1;
- /* exponent compute (exact) */
- e = e * 4;
- er = e % 3;
- eq = e / 3;
- a = POW_MULL(a, pow_mult3[er]);
- while (a >= 2 * POW_FRAC_ONE) {
- a = a >> 1;
- eq++;
- }
- /* convert to float */
- while (a < POW_FRAC_ONE) {
- a = a << 1;
- eq--;
- }
- /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */
-#if POW_FRAC_BITS > FRAC_BITS
- a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS);
- /* correct overflow */
- if (a >= 2 * (1 << FRAC_BITS)) {
- a = a >> 1;
- eq++;
- }
-#endif
- *exp_ptr = eq;
- return a;
-}
-
-static int decode_init(AVCodecContext * avctx)
-{
- MPADecodeContext *s = avctx->priv_data;
- static int init=0;
- int i, j, k;
-
- if (!init && !avctx->parse_only) {
- /* scale factors table for layer 1/2 */
- for(i=0;i<64;i++) {
- int shift, mod;
- /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
- shift = (i / 3);
- mod = i % 3;
- scale_factor_modshift[i] = mod | (shift << 2);
- }
-
- /* scale factor multiply for layer 1 */
- for(i=0;i<15;i++) {
- int n, norm;
- n = i + 2;
- norm = ((int64_t_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
- scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
- scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
- scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
- dprintf("%d: norm=%x s=%x %x %x\n",
- i, norm,
- scale_factor_mult[i][0],
- scale_factor_mult[i][1],
- scale_factor_mult[i][2]);
- }
-
- /* window */
- /* max = 18760, max sum over all 16 coefs : 44736 */
- for(i=0;i<257;i++) {
- int v;
- v = mpa_enwindow[i];
-#if WFRAC_BITS < 16
- v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
-#endif
- window[i] = v;
- if ((i & 63) != 0)
- v = -v;
- if (i != 0)
- window[512 - i] = v;
- }
-
- /* huffman decode tables */
- huff_code_table[0] = NULL;
- for(i=1;i<16;i++) {
- const HuffTable *h = &mpa_huff_tables[i];
- int xsize, x, y;
- unsigned int n;
- uint8_t *code_table;
-
- xsize = h->xsize;
- n = xsize * xsize;
- /* XXX: fail test */
- init_vlc(&huff_vlc[i], 8, n,
- h->bits, 1, 1, h->codes, 2, 2);
-
- code_table = av_mallocz(n);
- j = 0;
- for(x=0;x<xsize;x++) {
- for(y=0;y<xsize;y++)
- code_table[j++] = (x << 4) | y;
- }
- huff_code_table[i] = code_table;
- }
- for(i=0;i<2;i++) {
- init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
- mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1);
- }
-
- for(i=0;i<9;i++) {
- k = 0;
- for(j=0;j<22;j++) {
- band_index_long[i][j] = k;
- k += band_size_long[i][j];
- }
- band_index_long[i][22] = k;
- }
-
- /* compute n ^ (4/3) and store it in mantissa/exp format */
- if (!av_mallocz_static(&table_4_3_exp,
- TABLE_4_3_SIZE * sizeof(table_4_3_exp[0])))
- return -1;
- if (!av_mallocz_static(&table_4_3_value,
- TABLE_4_3_SIZE * sizeof(table_4_3_value[0])))
- return -1;
-
- int_pow_init();
- for(i=1;i<TABLE_4_3_SIZE;i++) {
- int e, m;
- m = int_pow(i, &e);
-#if 0
- /* test code */
- {
- double f, fm;
- int e1, m1;
- f = pow((double)i, 4.0 / 3.0);
- fm = frexp(f, &e1);
- m1 = FIXR(2 * fm);
-#if FRAC_BITS <= 15
- if ((unsigned short)m1 != m1) {
- m1 = m1 >> 1;
- e1++;
- }
-#endif
- e1--;
- if (m != m1 || e != e1) {
- printf("%4d: m=%x m1=%x e=%d e1=%d\n",
- i, m, m1, e, e1);
- }
- }
-#endif
- /* normalized to FRAC_BITS */
- table_4_3_value[i] = m;
- table_4_3_exp[i] = e;
- }
-
- for(i=0;i<7;i++) {
- float f;
- int v;
- if (i != 6) {
- f = tan((double)i * M_PI / 12.0);
- v = FIXR(f / (1.0 + f));
- } else {
- v = FIXR(1.0);
- }
- is_table[0][i] = v;
- is_table[1][6 - i] = v;
- }
- /* invalid values */
- for(i=7;i<16;i++)
- is_table[0][i] = is_table[1][i] = 0.0;
-
- for(i=0;i<16;i++) {
- double f;
- int e, k;
-
- for(j=0;j<2;j++) {
- e = -(j + 1) * ((i + 1) >> 1);
- f = pow(2.0, e / 4.0);
- k = i & 1;
- is_table_lsf[j][k ^ 1][i] = FIXR(f);
- is_table_lsf[j][k][i] = FIXR(1.0);
- dprintf("is_table_lsf %d %d: %x %x\n",
- i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]);
- }
- }
-
- for(i=0;i<8;i++) {
- float ci, cs, ca;
- ci = ci_table[i];
- cs = 1.0 / sqrt(1.0 + ci * ci);
- ca = cs * ci;
- csa_table[i][0] = FIX(cs);
- csa_table[i][1] = FIX(ca);
- }
-
- /* compute mdct windows */
- for(i=0;i<36;i++) {
- int v;
- v = FIXR(sin(M_PI * (i + 0.5) / 36.0));
- mdct_win[0][i] = v;
- mdct_win[1][i] = v;
- mdct_win[3][i] = v;
- }
- for(i=0;i<6;i++) {
- mdct_win[1][18 + i] = FIXR(1.0);
- mdct_win[1][24 + i] = FIXR(sin(M_PI * ((i + 6) + 0.5) / 12.0));
- mdct_win[1][30 + i] = FIXR(0.0);
-
- mdct_win[3][i] = FIXR(0.0);
- mdct_win[3][6 + i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));
- mdct_win[3][12 + i] = FIXR(1.0);
- }
-
- for(i=0;i<12;i++)
- mdct_win[2][i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));
-
- /* NOTE: we do frequency inversion adter the MDCT by changing
- the sign of the right window coefs */
- for(j=0;j<4;j++) {
- for(i=0;i<36;i+=2) {
- mdct_win[j + 4][i] = mdct_win[j][i];
- mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
- }
- }
-
-#if defined(DEBUG)
- for(j=0;j<8;j++) {
- printf("win%d=\n", j);
- for(i=0;i<36;i++)
- printf("%f, ", (double)mdct_win[j][i] / FRAC_ONE);
- printf("\n");
- }
-#endif
- init = 1;
- }
-
- s->inbuf_index = 0;
- s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];
- s->inbuf_ptr = s->inbuf;
-#ifdef DEBUG
- s->frame_count = 0;
-#endif
- return 0;
-}
-
-/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
-
-/* cos(i*pi/64) */
-
-#define COS0_0 FIXR(0.50060299823519630134)
-#define COS0_1 FIXR(0.50547095989754365998)
-#define COS0_2 FIXR(0.51544730992262454697)
-#define COS0_3 FIXR(0.53104259108978417447)
-#define COS0_4 FIXR(0.55310389603444452782)
-#define COS0_5 FIXR(0.58293496820613387367)
-#define COS0_6 FIXR(0.62250412303566481615)
-#define COS0_7 FIXR(0.67480834145500574602)
-#define COS0_8 FIXR(0.74453627100229844977)
-#define COS0_9 FIXR(0.83934964541552703873)
-#define COS0_10 FIXR(0.97256823786196069369)
-#define COS0_11 FIXR(1.16943993343288495515)
-#define COS0_12 FIXR(1.48416461631416627724)
-#define COS0_13 FIXR(2.05778100995341155085)
-#define COS0_14 FIXR(3.40760841846871878570)
-#define COS0_15 FIXR(10.19000812354805681150)
-
-#define COS1_0 FIXR(0.50241928618815570551)
-#define COS1_1 FIXR(0.52249861493968888062)
-#define COS1_2 FIXR(0.56694403481635770368)
-#define COS1_3 FIXR(0.64682178335999012954)
-#define COS1_4 FIXR(0.78815462345125022473)
-#define COS1_5 FIXR(1.06067768599034747134)
-#define COS1_6 FIXR(1.72244709823833392782)
-#define COS1_7 FIXR(5.10114861868916385802)
-
-#define COS2_0 FIXR(0.50979557910415916894)
-#define COS2_1 FIXR(0.60134488693504528054)
-#define COS2_2 FIXR(0.89997622313641570463)
-#define COS2_3 FIXR(2.56291544774150617881)
-
-#define COS3_0 FIXR(0.54119610014619698439)
-#define COS3_1 FIXR(1.30656296487637652785)
-
-#define COS4_0 FIXR(0.70710678118654752439)
-
-/* butterfly operator */
-#define BF(a, b, c)\
-{\
- tmp0 = tab[a] + tab[b];\
- tmp1 = tab[a] - tab[b];\
- tab[a] = tmp0;\
- tab[b] = MULL(tmp1, c);\
-}
-
-#define BF1(a, b, c, d)\
-{\
- BF(a, b, COS4_0);\
- BF(c, d, -COS4_0);\
- tab[c] += tab[d];\
-}
-
-#define BF2(a, b, c, d)\
-{\
- BF(a, b, COS4_0);\
- BF(c, d, -COS4_0);\
- tab[c] += tab[d];\
- tab[a] += tab[c];\
- tab[c] += tab[b];\
- tab[b] += tab[d];\
-}
-
-#define ADD(a, b) tab[a] += tab[b]
-
-/* DCT32 without 1/sqrt(2) coef zero scaling. */
-static void dct32(int32_t *out, int32_t *tab)
-{
- int tmp0, tmp1;
-
- /* pass 1 */
- BF(0, 31, COS0_0);
- BF(1, 30, COS0_1);
- BF(2, 29, COS0_2);
- BF(3, 28, COS0_3);
- BF(4, 27, COS0_4);
- BF(5, 26, COS0_5);
- BF(6, 25, COS0_6);
- BF(7, 24, COS0_7);
- BF(8, 23, COS0_8);
- BF(9, 22, COS0_9);
- BF(10, 21, COS0_10);
- BF(11, 20, COS0_11);
- BF(12, 19, COS0_12);
- BF(13, 18, COS0_13);
- BF(14, 17, COS0_14);
- BF(15, 16, COS0_15);
-
- /* pass 2 */
- BF(0, 15, COS1_0);
- BF(1, 14, COS1_1);
- BF(2, 13, COS1_2);
- BF(3, 12, COS1_3);
- BF(4, 11, COS1_4);
- BF(5, 10, COS1_5);
- BF(6, 9, COS1_6);
- BF(7, 8, COS1_7);
-
- BF(16, 31, -COS1_0);
- BF(17, 30, -COS1_1);
- BF(18, 29, -COS1_2);
- BF(19, 28, -COS1_3);
- BF(20, 27, -COS1_4);
- BF(21, 26, -COS1_5);
- BF(22, 25, -COS1_6);
- BF(23, 24, -COS1_7);
-
- /* pass 3 */
- BF(0, 7, COS2_0);
- BF(1, 6, COS2_1);
- BF(2, 5, COS2_2);
- BF(3, 4, COS2_3);
-
- BF(8, 15, -COS2_0);
- BF(9, 14, -COS2_1);
- BF(10, 13, -COS2_2);
- BF(11, 12, -COS2_3);
-
- BF(16, 23, COS2_0);
- BF(17, 22, COS2_1);
- BF(18, 21, COS2_2);
- BF(19, 20, COS2_3);
-
- BF(24, 31, -COS2_0);
- BF(25, 30, -COS2_1);
- BF(26, 29, -COS2_2);
- BF(27, 28, -COS2_3);
-
- /* pass 4 */
- BF(0, 3, COS3_0);
- BF(1, 2, COS3_1);
-
- BF(4, 7, -COS3_0);
- BF(5, 6, -COS3_1);
-
- BF(8, 11, COS3_0);
- BF(9, 10, COS3_1);
-
- BF(12, 15, -COS3_0);
- BF(13, 14, -COS3_1);
-
- BF(16, 19, COS3_0);
- BF(17, 18, COS3_1);
-
- BF(20, 23, -COS3_0);
- BF(21, 22, -COS3_1);
-
- BF(24, 27, COS3_0);
- BF(25, 26, COS3_1);
-
- BF(28, 31, -COS3_0);
- BF(29, 30, -COS3_1);
-
- /* pass 5 */
- BF1(0, 1, 2, 3);
- BF2(4, 5, 6, 7);
- BF1(8, 9, 10, 11);
- BF2(12, 13, 14, 15);
- BF1(16, 17, 18, 19);
- BF2(20, 21, 22, 23);
- BF1(24, 25, 26, 27);
- BF2(28, 29, 30, 31);
-
- /* pass 6 */
-
- ADD( 8, 12);
- ADD(12, 10);
- ADD(10, 14);
- ADD(14, 9);
- ADD( 9, 13);
- ADD(13, 11);
- ADD(11, 15);
-
- out[ 0] = tab[0];
- out[16] = tab[1];
- out[ 8] = tab[2];
- out[24] = tab[3];
- out[ 4] = tab[4];
- out[20] = tab[5];
- out[12] = tab[6];
- out[28] = tab[7];
- out[ 2] = tab[8];
- out[18] = tab[9];
- out[10] = tab[10];
- out[26] = tab[11];
- out[ 6] = tab[12];
- out[22] = tab[13];
- out[14] = tab[14];
- out[30] = tab[15];
-
- ADD(24, 28);
- ADD(28, 26);
- ADD(26, 30);
- ADD(30, 25);
- ADD(25, 29);
- ADD(29, 27);
- ADD(27, 31);
-
- out[ 1] = tab[16] + tab[24];
- out[17] = tab[17] + tab[25];
- out[ 9] = tab[18] + tab[26];
- out[25] = tab[19] + tab[27];
- out[ 5] = tab[20] + tab[28];
- out[21] = tab[21] + tab[29];
- out[13] = tab[22] + tab[30];
- out[29] = tab[23] + tab[31];
- out[ 3] = tab[24] + tab[20];
- out[19] = tab[25] + tab[21];
- out[11] = tab[26] + tab[22];
- out[27] = tab[27] + tab[23];
- out[ 7] = tab[28] + tab[18];
- out[23] = tab[29] + tab[19];
- out[15] = tab[30] + tab[17];
- out[31] = tab[31];
-}
-
-#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
-
-#if FRAC_BITS <= 15
-
-static inline int round_sample(int sum)
-{
- int sum1;
- sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;
- if (sum1 < -32768)
- sum1 = -32768;
- else if (sum1 > 32767)
- sum1 = 32767;
- return sum1;
-}
-
-#if defined(ARCH_POWERPC_405)
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MACS(rt, ra, rb) \
- asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
-
-/* signed 16x16 -> 32 multiply */
-#define MULS(ra, rb) \
- ({ int __rt; asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; })
-
-#else
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MACS(rt, ra, rb) rt += (ra) * (rb)
-
-/* signed 16x16 -> 32 multiply */
-#define MULS(ra, rb) ((ra) * (rb))
-
-#endif
-
-#else
-
-static inline int round_sample(int64_t sum)
-{
- int sum1;
- sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);
- if (sum1 < -32768)
- sum1 = -32768;
- else if (sum1 > 32767)
- sum1 = 32767;
- return sum1;
-}
-
-#define MULS(ra, rb) MUL64(ra, rb)
-
-#endif
-
-#define SUM8(sum, op, w, p) \
-{ \
- sum op MULS((w)[0 * 64], p[0 * 64]);\
- sum op MULS((w)[1 * 64], p[1 * 64]);\
- sum op MULS((w)[2 * 64], p[2 * 64]);\
- sum op MULS((w)[3 * 64], p[3 * 64]);\
- sum op MULS((w)[4 * 64], p[4 * 64]);\
- sum op MULS((w)[5 * 64], p[5 * 64]);\
- sum op MULS((w)[6 * 64], p[6 * 64]);\
- sum op MULS((w)[7 * 64], p[7 * 64]);\
-}
-
-#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \
-{ \
- int tmp;\
- tmp = p[0 * 64];\
- sum1 op1 MULS((w1)[0 * 64], tmp);\
- sum2 op2 MULS((w2)[0 * 64], tmp);\
- tmp = p[1 * 64];\
- sum1 op1 MULS((w1)[1 * 64], tmp);\
- sum2 op2 MULS((w2)[1 * 64], tmp);\
- tmp = p[2 * 64];\
- sum1 op1 MULS((w1)[2 * 64], tmp);\
- sum2 op2 MULS((w2)[2 * 64], tmp);\
- tmp = p[3 * 64];\
- sum1 op1 MULS((w1)[3 * 64], tmp);\
- sum2 op2 MULS((w2)[3 * 64], tmp);\
- tmp = p[4 * 64];\
- sum1 op1 MULS((w1)[4 * 64], tmp);\
- sum2 op2 MULS((w2)[4 * 64], tmp);\
- tmp = p[5 * 64];\
- sum1 op1 MULS((w1)[5 * 64], tmp);\
- sum2 op2 MULS((w2)[5 * 64], tmp);\
- tmp = p[6 * 64];\
- sum1 op1 MULS((w1)[6 * 64], tmp);\
- sum2 op2 MULS((w2)[6 * 64], tmp);\
- tmp = p[7 * 64];\
- sum1 op1 MULS((w1)[7 * 64], tmp);\
- sum2 op2 MULS((w2)[7 * 64], tmp);\
-}
-
-
-/* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
- 32 samples. */
-/* XXX: optimize by avoiding ring buffer usage */
-static void synth_filter(MPADecodeContext *s1,
- int ch, int16_t *samples, int incr,
- int32_t sb_samples[SBLIMIT])
-{
- int32_t tmp[32];
- register MPA_INT *synth_buf;
- const register MPA_INT *w, *w2, *p;
- int j, offset, v;
- int16_t *samples2;
-#if FRAC_BITS <= 15
- int sum, sum2;
-#else
- int64_t sum, sum2;
-#endif
-
- dct32(tmp, sb_samples);
-
- offset = s1->synth_buf_offset[ch];
- synth_buf = s1->synth_buf[ch] + offset;
-
- for(j=0;j<32;j++) {
- v = tmp[j];
-#if FRAC_BITS <= 15
- /* NOTE: can cause a loss in precision if very high amplitude
- sound */
- if (v > 32767)
- v = 32767;
- else if (v < -32768)
- v = -32768;
-#endif
- synth_buf[j] = v;
- }
- /* copy to avoid wrap */
- memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
-
- samples2 = samples + 31 * incr;
- w = window;
- w2 = window + 31;
-
- sum = 0;
- p = synth_buf + 16;
- SUM8(sum, +=, w, p);
- p = synth_buf + 48;
- SUM8(sum, -=, w + 32, p);
- *samples = round_sample(sum);
- samples += incr;
- w++;
-
- /* we calculate two samples at the same time to avoid one memory
- access per two sample */
- for(j=1;j<16;j++) {
- sum = 0;
- sum2 = 0;
- p = synth_buf + 16 + j;
- SUM8P2(sum, +=, sum2, -=, w, w2, p);
- p = synth_buf + 48 - j;
- SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
-
- *samples = round_sample(sum);
- samples += incr;
- *samples2 = round_sample(sum2);
- samples2 -= incr;
- w++;
- w2--;
- }
-
- p = synth_buf + 32;
- sum = 0;
- SUM8(sum, -=, w + 32, p);
- *samples = round_sample(sum);
-
- offset = (offset - 32) & 511;
- s1->synth_buf_offset[ch] = offset;
-}
-
-/* cos(pi*i/24) */
-#define C1 FIXR(0.99144486137381041114)
-#define C3 FIXR(0.92387953251128675612)
-#define C5 FIXR(0.79335334029123516458)
-#define C7 FIXR(0.60876142900872063941)
-#define C9 FIXR(0.38268343236508977173)
-#define C11 FIXR(0.13052619222005159154)
-
-/* 12 points IMDCT. We compute it "by hand" by factorizing obvious
- cases. */
-static void imdct12(int *out, int *in)
-{
- int tmp;
- int64_t in1_3, in1_9, in4_3, in4_9;
-
- in1_3 = MUL64(in[1], C3);
- in1_9 = MUL64(in[1], C9);
- in4_3 = MUL64(in[4], C3);
- in4_9 = MUL64(in[4], C9);
-
- tmp = FRAC_RND(MUL64(in[0], C7) - in1_3 - MUL64(in[2], C11) +
- MUL64(in[3], C1) - in4_9 - MUL64(in[5], C5));
- out[0] = tmp;
- out[5] = -tmp;
- tmp = FRAC_RND(MUL64(in[0] - in[3], C9) - in1_3 +
- MUL64(in[2] + in[5], C3) - in4_9);
- out[1] = tmp;
- out[4] = -tmp;
- tmp = FRAC_RND(MUL64(in[0], C11) - in1_9 + MUL64(in[2], C7) -
- MUL64(in[3], C5) + in4_3 - MUL64(in[5], C1));
- out[2] = tmp;
- out[3] = -tmp;
- tmp = FRAC_RND(MUL64(-in[0], C5) + in1_9 + MUL64(in[2], C1) +
- MUL64(in[3], C11) - in4_3 - MUL64(in[5], C7));
- out[6] = tmp;
- out[11] = tmp;
- tmp = FRAC_RND(MUL64(-in[0] + in[3], C3) - in1_9 +
- MUL64(in[2] + in[5], C9) + in4_3);
- out[7] = tmp;
- out[10] = tmp;
- tmp = FRAC_RND(-MUL64(in[0], C1) - in1_3 - MUL64(in[2], C5) -
- MUL64(in[3], C7) - in4_9 - MUL64(in[5], C11));
- out[8] = tmp;
- out[9] = tmp;
-}
-
-#undef C1
-#undef C3
-#undef C5
-#undef C7
-#undef C9
-#undef C11
-
-/* cos(pi*i/18) */
-#define C1 FIXR(0.98480775301220805936)
-#define C2 FIXR(0.93969262078590838405)
-#define C3 FIXR(0.86602540378443864676)
-#define C4 FIXR(0.76604444311897803520)
-#define C5 FIXR(0.64278760968653932632)
-#define C6 FIXR(0.5)
-#define C7 FIXR(0.34202014332566873304)
-#define C8 FIXR(0.17364817766693034885)
-
-/* 0.5 / cos(pi*(2*i+1)/36) */
-static const int icos36[9] = {
- FIXR(0.50190991877167369479),
- FIXR(0.51763809020504152469),
- FIXR(0.55168895948124587824),
- FIXR(0.61038729438072803416),
- FIXR(0.70710678118654752439),
- FIXR(0.87172339781054900991),
- FIXR(1.18310079157624925896),
- FIXR(1.93185165257813657349),
- FIXR(5.73685662283492756461),
-};
-
-static const int icos72[18] = {
- /* 0.5 / cos(pi*(2*i+19)/72) */
- FIXR(0.74009361646113053152),
- FIXR(0.82133981585229078570),
- FIXR(0.93057949835178895673),
- FIXR(1.08284028510010010928),
- FIXR(1.30656296487637652785),
- FIXR(1.66275476171152078719),
- FIXR(2.31011315767264929558),
- FIXR(3.83064878777019433457),
- FIXR(11.46279281302667383546),
-
- /* 0.5 / cos(pi*(2*(i + 18) +19)/72) */
- FIXR(-0.67817085245462840086),
- FIXR(-0.63023620700513223342),
- FIXR(-0.59284452371708034528),
- FIXR(-0.56369097343317117734),
- FIXR(-0.54119610014619698439),
- FIXR(-0.52426456257040533932),
- FIXR(-0.51213975715725461845),
- FIXR(-0.50431448029007636036),
- FIXR(-0.50047634258165998492),
-};
-
-/* using Lee like decomposition followed by hand coded 9 points DCT */
-static void imdct36(int *out, int *in)
-{
- int i, j, t0, t1, t2, t3, s0, s1, s2, s3;
- int tmp[18], *tmp1, *in1;
- int64_t in3_3, in6_6;
-
- for(i=17;i>=1;i--)
- in[i] += in[i-1];
- for(i=17;i>=3;i-=2)
- in[i] += in[i-2];
-
- for(j=0;j<2;j++) {
- tmp1 = tmp + j;
- in1 = in + j;
-
- in3_3 = MUL64(in1[2*3], C3);
- in6_6 = MUL64(in1[2*6], C6);
-
- tmp1[0] = FRAC_RND(MUL64(in1[2*1], C1) + in3_3 +
- MUL64(in1[2*5], C5) + MUL64(in1[2*7], C7));
- tmp1[2] = in1[2*0] + FRAC_RND(MUL64(in1[2*2], C2) +
- MUL64(in1[2*4], C4) + in6_6 +
- MUL64(in1[2*8], C8));
- tmp1[4] = FRAC_RND(MUL64(in1[2*1] - in1[2*5] - in1[2*7], C3));
- tmp1[6] = FRAC_RND(MUL64(in1[2*2] - in1[2*4] - in1[2*8], C6)) -
- in1[2*6] + in1[2*0];
- tmp1[8] = FRAC_RND(MUL64(in1[2*1], C5) - in3_3 -
- MUL64(in1[2*5], C7) + MUL64(in1[2*7], C1));
- tmp1[10] = in1[2*0] + FRAC_RND(MUL64(-in1[2*2], C8) -
- MUL64(in1[2*4], C2) + in6_6 +
- MUL64(in1[2*8], C4));
- tmp1[12] = FRAC_RND(MUL64(in1[2*1], C7) - in3_3 +
- MUL64(in1[2*5], C1) -
- MUL64(in1[2*7], C5));
- tmp1[14] = in1[2*0] + FRAC_RND(MUL64(-in1[2*2], C4) +
- MUL64(in1[2*4], C8) + in6_6 -
- MUL64(in1[2*8], C2));
- tmp1[16] = in1[2*0] - in1[2*2] + in1[2*4] - in1[2*6] + in1[2*8];
- }
-
- i = 0;
- for(j=0;j<4;j++) {
- t0 = tmp[i];
- t1 = tmp[i + 2];
- s0 = t1 + t0;
- s2 = t1 - t0;
-
- t2 = tmp[i + 1];
- t3 = tmp[i + 3];
- s1 = MULL(t3 + t2, icos36[j]);
- s3 = MULL(t3 - t2, icos36[8 - j]);
-
- t0 = MULL(s0 + s1, icos72[9 + 8 - j]);
- t1 = MULL(s0 - s1, icos72[8 - j]);
- out[18 + 9 + j] = t0;
- out[18 + 8 - j] = t0;
- out[9 + j] = -t1;
- out[8 - j] = t1;
-
- t0 = MULL(s2 + s3, icos72[9+j]);
- t1 = MULL(s2 - s3, icos72[j]);
- out[18 + 9 + (8 - j)] = t0;
- out[18 + j] = t0;
- out[9 + (8 - j)] = -t1;
- out[j] = t1;
- i += 4;
- }
-
- s0 = tmp[16];
- s1 = MULL(tmp[17], icos36[4]);
- t0 = MULL(s0 + s1, icos72[9 + 4]);
- t1 = MULL(s0 - s1, icos72[4]);
- out[18 + 9 + 4] = t0;
- out[18 + 8 - 4] = t0;
- out[9 + 4] = -t1;
- out[8 - 4] = t1;
-}
-
-/* fast header check for resync */
-static int check_header(uint32_t header)
-{
- /* header */
- if ((header & 0xffe00000) != 0xffe00000)
- return -1;
- /* layer check */
- if (((header >> 17) & 3) == 0)
- return -1;
- /* bit rate */
- if (((header >> 12) & 0xf) == 0xf)
- return -1;
- /* frequency */
- if (((header >> 10) & 3) == 3)
- return -1;
- return 0;
-}
-
-/* header + layer + bitrate + freq + lsf/mpeg25 */
-#define SAME_HEADER_MASK \
- (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
-
-/* header decoding. MUST check the header before because no
- consistency check is done there. Return 1 if free format found and
- that the frame size must be computed externally */
-static int decode_header(MPADecodeContext *s, uint32_t header)
-{
- int sample_rate, frame_size, mpeg25, padding;
- int sample_rate_index, bitrate_index;
- if (header & (1<<20)) {
- s->lsf = (header & (1<<19)) ? 0 : 1;
- mpeg25 = 0;
- } else {
- s->lsf = 1;
- mpeg25 = 1;
- }
-
- s->layer = 4 - ((header >> 17) & 3);
- /* extract frequency */
- sample_rate_index = (header >> 10) & 3;
- sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
- sample_rate_index += 3 * (s->lsf + mpeg25);
- s->sample_rate_index = sample_rate_index;
- s->error_protection = ((header >> 16) & 1) ^ 1;
- s->sample_rate = sample_rate;
-
- bitrate_index = (header >> 12) & 0xf;
- padding = (header >> 9) & 1;
- //extension = (header >> 8) & 1;
- s->mode = (header >> 6) & 3;
- s->mode_ext = (header >> 4) & 3;
- //copyright = (header >> 3) & 1;
- //original = (header >> 2) & 1;
- //emphasis = header & 3;
-
- if (s->mode == MPA_MONO)
- s->nb_channels = 1;
- else
- s->nb_channels = 2;
-
- if (bitrate_index != 0) {
- frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
- s->bit_rate = frame_size * 1000;
- switch(s->layer) {
- case 1:
- frame_size = (frame_size * 12000) / sample_rate;
- frame_size = (frame_size + padding) * 4;
- break;
- case 2:
- frame_size = (frame_size * 144000) / sample_rate;
- frame_size += padding;
- break;
- default:
- case 3:
- frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
- frame_size += padding;
- break;
- }
- s->frame_size = frame_size;
- } else {
- /* if no frame size computed, signal it */
- if (!s->free_format_frame_size)
- return 1;
- /* free format: compute bitrate and real frame size from the
- frame size we extracted by reading the bitstream */
- s->frame_size = s->free_format_frame_size;
- switch(s->layer) {
- case 1:
- s->frame_size += padding * 4;
- s->bit_rate = (s->frame_size * sample_rate) / 48000;
- break;
- case 2:
- s->frame_size += padding;
- s->bit_rate = (s->frame_size * sample_rate) / 144000;
- break;
- default:
- case 3:
- s->frame_size += padding;
- s->bit_rate = (s->frame_size * (sample_rate << s->lsf)) / 144000;
- break;
- }
- }
-
-#if defined(DEBUG)
- printf("layer%d, %d Hz, %d kbits/s, ",
- s->layer, s->sample_rate, s->bit_rate);
- if (s->nb_channels == 2) {
- if (s->layer == 3) {
- if (s->mode_ext & MODE_EXT_MS_STEREO)
- printf("ms-");
- if (s->mode_ext & MODE_EXT_I_STEREO)
- printf("i-");
- }
- printf("stereo");
- } else {
- printf("mono");
- }
- printf("\n");
-#endif
- return 0;
-}
-
-/* useful helper to get mpeg audio stream infos. Return -1 if error in
- header */
-int mp_decode_header(int *sample_rate_ptr,
- int *nb_channels_ptr,
- int *coded_frame_size_ptr,
- int *decoded_frame_size_ptr,
- uint32_t head)
-{
- MPADecodeContext s1, *s = &s1;
- int decoded_frame_size;
-
- if (check_header(head) != 0)
- return -1;
-
- if (decode_header(s, head) != 0) {
- return -1;
- }
-
- switch(s->layer) {
- case 1:
- decoded_frame_size = 384;
- break;
- case 2:
- decoded_frame_size = 1152;
- break;
- default:
- case 3:
- if (s->lsf)
- decoded_frame_size = 576;
- else
- decoded_frame_size = 1152;
- break;
- }
-
- *sample_rate_ptr = s->sample_rate;
- *nb_channels_ptr = s->nb_channels;
- *coded_frame_size_ptr = s->frame_size;
- *decoded_frame_size_ptr = decoded_frame_size * 2 * s->nb_channels;
- return 0;
-}
-
-/* return the number of decoded frames */
-static int mp_decode_layer1(MPADecodeContext *s)
-{
- int bound, i, v, n, ch, j, mant;
- uint8_t allocation[MPA_MAX_CHANNELS][SBLIMIT];
- uint8_t scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
-
- if (s->mode == MPA_JSTEREO)
- bound = (s->mode_ext + 1) * 4;
- else
- bound = SBLIMIT;
-
- /* allocation bits */
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- allocation[ch][i] = get_bits(&s->gb, 4);
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- allocation[0][i] = get_bits(&s->gb, 4);
- }
-
- /* scale factors */
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (allocation[ch][i])
- scale_factors[ch][i] = get_bits(&s->gb, 6);
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- if (allocation[0][i]) {
- scale_factors[0][i] = get_bits(&s->gb, 6);
- scale_factors[1][i] = get_bits(&s->gb, 6);
- }
- }
-
- /* compute samples */
- for(j=0;j<12;j++) {
- for(i=0;i<bound;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- n = allocation[ch][i];
- if (n) {
- mant = get_bits(&s->gb, n + 1);
- v = l1_unscale(n, mant, scale_factors[ch][i]);
- } else {
- v = 0;
- }
- s->sb_samples[ch][j][i] = v;
- }
- }
- for(i=bound;i<SBLIMIT;i++) {
- n = allocation[0][i];
- if (n) {
- mant = get_bits(&s->gb, n + 1);
- v = l1_unscale(n, mant, scale_factors[0][i]);
- s->sb_samples[0][j][i] = v;
- v = l1_unscale(n, mant, scale_factors[1][i]);
- s->sb_samples[1][j][i] = v;
- } else {
- s->sb_samples[0][j][i] = 0;
- s->sb_samples[1][j][i] = 0;
- }
- }
- }
- return 12;
-}
-
-/* bitrate is in kb/s */
-int l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
-{
- int ch_bitrate, table;
-
- ch_bitrate = bitrate / nb_channels;
- if (!lsf) {
- if ((freq == 48000 && ch_bitrate >= 56) ||
- (ch_bitrate >= 56 && ch_bitrate <= 80))
- table = 0;
- else if (freq != 48000 && ch_bitrate >= 96)
- table = 1;
- else if (freq != 32000 && ch_bitrate <= 48)
- table = 2;
- else
- table = 3;
- } else {
- table = 4;
- }
- return table;
-}
-
-static int mp_decode_layer2(MPADecodeContext *s)
-{
- int sblimit; /* number of used subbands */
- const unsigned char *alloc_table;
- int table, bit_alloc_bits, i, j, ch, bound, v;
- unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
- unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
- int scale, qindex, bits, steps, k, l, m, b;
-
- /* select decoding table */
- table = l2_select_table(s->bit_rate / 1000, s->nb_channels,
- s->sample_rate, s->lsf);
- sblimit = sblimit_table[table];
- alloc_table = alloc_tables[table];
-
- if (s->mode == MPA_JSTEREO)
- bound = (s->mode_ext + 1) * 4;
- else
- bound = sblimit;
-
- dprintf("bound=%d sblimit=%d\n", bound, sblimit);
- /* parse bit allocation */
- j = 0;
- for(i=0;i<bound;i++) {
- bit_alloc_bits = alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
- }
- j += 1 << bit_alloc_bits;
- }
- for(i=bound;i<sblimit;i++) {
- bit_alloc_bits = alloc_table[j];
- v = get_bits(&s->gb, bit_alloc_bits);
- bit_alloc[0][i] = v;
- bit_alloc[1][i] = v;
- j += 1 << bit_alloc_bits;
- }
-
-#ifdef DEBUG
- {
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++)
- printf(" %d", bit_alloc[ch][i]);
- printf("\n");
- }
- }
-#endif
-
- /* scale codes */
- for(i=0;i<sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i])
- scale_code[ch][i] = get_bits(&s->gb, 2);
- }
- }
-
- /* scale factors */
- for(i=0;i<sblimit;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- if (bit_alloc[ch][i]) {
- sf = scale_factors[ch][i];
- switch(scale_code[ch][i]) {
- default:
- case 0:
- sf[0] = get_bits(&s->gb, 6);
- sf[1] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- break;
- case 2:
- sf[0] = get_bits(&s->gb, 6);
- sf[1] = sf[0];
- sf[2] = sf[0];
- break;
- case 1:
- sf[0] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- sf[1] = sf[0];
- break;
- case 3:
- sf[0] = get_bits(&s->gb, 6);
- sf[2] = get_bits(&s->gb, 6);
- sf[1] = sf[2];
- break;
- }
- }
- }
- }
-
-#ifdef DEBUG
- for(ch=0;ch<s->nb_channels;ch++) {
- for(i=0;i<sblimit;i++) {
- if (bit_alloc[ch][i]) {
- sf = scale_factors[ch][i];
- printf(" %d %d %d", sf[0], sf[1], sf[2]);
- } else {
- printf(" -");
- }
- }
- printf("\n");
- }
-#endif
-
- /* samples */
- for(k=0;k<3;k++) {
- for(l=0;l<12;l+=3) {
- j = 0;
- for(i=0;i<bound;i++) {
- bit_alloc_bits = alloc_table[j];
- for(ch=0;ch<s->nb_channels;ch++) {
- b = bit_alloc[ch][i];
- if (b) {
- scale = scale_factors[ch][i][k];
- qindex = alloc_table[j+b];
- bits = quant_bits[qindex];
- if (bits < 0) {
- /* 3 values at the same time */
- v = get_bits(&s->gb, -bits);
- steps = quant_steps[qindex];
- s->sb_samples[ch][k * 12 + l + 0][i] =
- l2_unscale_group(steps, v % steps, scale);
- v = v / steps;
- s->sb_samples[ch][k * 12 + l + 1][i] =
- l2_unscale_group(steps, v % steps, scale);
- v = v / steps;
- s->sb_samples[ch][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale);
- } else {
- for(m=0;m<3;m++) {
- v = get_bits(&s->gb, bits);
- v = l1_unscale(bits - 1, v, scale);
- s->sb_samples[ch][k * 12 + l + m][i] = v;
- }
- }
- } else {
- s->sb_samples[ch][k * 12 + l + 0][i] = 0;
- s->sb_samples[ch][k * 12 + l + 1][i] = 0;
- s->sb_samples[ch][k * 12 + l + 2][i] = 0;
- }
- }
- /* next subband in alloc table */
- j += 1 << bit_alloc_bits;
- }
- /* XXX: find a way to avoid this duplication of code */
- for(i=bound;i<sblimit;i++) {
- bit_alloc_bits = alloc_table[j];
- b = bit_alloc[0][i];
- if (b) {
- int mant, scale0, scale1;
- scale0 = scale_factors[0][i][k];
- scale1 = scale_factors[1][i][k];
- qindex = alloc_table[j+b];
- bits = quant_bits[qindex];
- if (bits < 0) {
- /* 3 values at the same time */
- v = get_bits(&s->gb, -bits);
- steps = quant_steps[qindex];
- mant = v % steps;
- v = v / steps;
- s->sb_samples[0][k * 12 + l + 0][i] =
- l2_unscale_group(steps, mant, scale0);
- s->sb_samples[1][k * 12 + l + 0][i] =
- l2_unscale_group(steps, mant, scale1);
- mant = v % steps;
- v = v / steps;
- s->sb_samples[0][k * 12 + l + 1][i] =
- l2_unscale_group(steps, mant, scale0);
- s->sb_samples[1][k * 12 + l + 1][i] =
- l2_unscale_group(steps, mant, scale1);
- s->sb_samples[0][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale0);
- s->sb_samples[1][k * 12 + l + 2][i] =
- l2_unscale_group(steps, v, scale1);
- } else {
- for(m=0;m<3;m++) {
- mant = get_bits(&s->gb, bits);
- s->sb_samples[0][k * 12 + l + m][i] =
- l1_unscale(bits - 1, mant, scale0);
- s->sb_samples[1][k * 12 + l + m][i] =
- l1_unscale(bits - 1, mant, scale1);
- }
- }
- } else {
- s->sb_samples[0][k * 12 + l + 0][i] = 0;
- s->sb_samples[0][k * 12 + l + 1][i] = 0;
- s->sb_samples[0][k * 12 + l + 2][i] = 0;
- s->sb_samples[1][k * 12 + l + 0][i] = 0;
- s->sb_samples[1][k * 12 + l + 1][i] = 0;
- s->sb_samples[1][k * 12 + l + 2][i] = 0;
- }
- /* next subband in alloc table */
- j += 1 << bit_alloc_bits;
- }
- /* fill remaining samples to zero */
- for(i=sblimit;i<SBLIMIT;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- s->sb_samples[ch][k * 12 + l + 0][i] = 0;
- s->sb_samples[ch][k * 12 + l + 1][i] = 0;
- s->sb_samples[ch][k * 12 + l + 2][i] = 0;
- }
- }
- }
- }
- return 3 * 12;
-}
-
-/*
- * Seek back in the stream for backstep bytes (at most 511 bytes)
- */
-static void seek_to_maindata(MPADecodeContext *s, unsigned int backstep)
-{
- uint8_t *ptr;
-
- /* compute current position in stream */
- ptr = (uint8_t *)(s->gb.buffer + (get_bits_count(&s->gb)>>3));
-
- /* copy old data before current one */
- ptr -= backstep;
- memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] +
- BACKSTEP_SIZE + s->old_frame_size - backstep, backstep);
- /* init get bits again */
- init_get_bits(&s->gb, ptr, (s->frame_size + backstep)*8);
-
- /* prepare next buffer */
- s->inbuf_index ^= 1;
- s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];
- s->old_frame_size = s->frame_size;
-}
-
-static inline void lsf_sf_expand(int *slen,
- int sf, int n1, int n2, int n3)
-{
- if (n3) {
- slen[3] = sf % n3;
- sf /= n3;
- } else {
- slen[3] = 0;
- }
- if (n2) {
- slen[2] = sf % n2;
- sf /= n2;
- } else {
- slen[2] = 0;
- }
- slen[1] = sf % n1;
- sf /= n1;
- slen[0] = sf;
-}
-
-static void exponents_from_scale_factors(MPADecodeContext *s,
- GranuleDef *g,
- int16_t *exponents)
-{
- const uint8_t *bstab, *pretab;
- int len, i, j, k, l, v0, shift, gain, gains[3];
- int16_t *exp_ptr;
-
- exp_ptr = exponents;
- gain = g->global_gain - 210;
- shift = g->scalefac_scale + 1;
-
- bstab = band_size_long[s->sample_rate_index];
- pretab = mpa_pretab[g->preflag];
- for(i=0;i<g->long_end;i++) {
- v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift);
- len = bstab[i];
- for(j=len;j>0;j--)
- *exp_ptr++ = v0;
- }
-
- if (g->short_start < 13) {
- bstab = band_size_short[s->sample_rate_index];
- gains[0] = gain - (g->subblock_gain[0] << 3);
- gains[1] = gain - (g->subblock_gain[1] << 3);
- gains[2] = gain - (g->subblock_gain[2] << 3);
- k = g->long_end;
- for(i=g->short_start;i<13;i++) {
- len = bstab[i];
- for(l=0;l<3;l++) {
- v0 = gains[l] - (g->scale_factors[k++] << shift);
- for(j=len;j>0;j--)
- *exp_ptr++ = v0;
- }
- }
- }
-}
-
-/* handle n = 0 too */
-static inline int get_bitsz(GetBitContext *s, int n)
-{
- if (n == 0)
- return 0;
- else
- return get_bits(s, n);
-}
-
-static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
- int16_t *exponents, int end_pos)
-{
- int s_index;
- int linbits, code, x, y, l, v, i, j, k, pos;
- GetBitContext last_gb;
- VLC *vlc;
- uint8_t *code_table;
-
- /* low frequencies (called big values) */
- s_index = 0;
- for(i=0;i<3;i++) {
- j = g->region_size[i];
- if (j == 0)
- continue;
- /* select vlc table */
- k = g->table_select[i];
- l = mpa_huff_data[k][0];
- linbits = mpa_huff_data[k][1];
- vlc = &huff_vlc[l];
- code_table = huff_code_table[l];
-
- /* read huffcode and compute each couple */
- for(;j>0;j--) {
- if (get_bits_count(&s->gb) >= end_pos)
- break;
- if (code_table) {
- code = get_vlc(&s->gb, vlc);
- if (code < 0)
- return -1;
- y = code_table[code];
- x = y >> 4;
- y = y & 0x0f;
- } else {
- x = 0;
- y = 0;
- }
- dprintf("region=%d n=%d x=%d y=%d exp=%d\n",
- i, g->region_size[i] - j, x, y, exponents[s_index]);
- if (x) {
- if (x == 15)
- x += get_bitsz(&s->gb, linbits);
- v = l3_unscale(x, exponents[s_index]);
- if (get_bits1(&s->gb))
- v = -v;
- } else {
- v = 0;
- }
- g->sb_hybrid[s_index++] = v;
- if (y) {
- if (y == 15)
- y += get_bitsz(&s->gb, linbits);
- v = l3_unscale(y, exponents[s_index]);
- if (get_bits1(&s->gb))
- v = -v;
- } else {
- v = 0;
- }
- g->sb_hybrid[s_index++] = v;
- }
- }
-
- /* high frequencies */
- vlc = &huff_quad_vlc[g->count1table_select];
- last_gb.buffer = NULL;
- while (s_index <= 572) {
- pos = get_bits_count(&s->gb);
- if (pos >= end_pos) {
- if (pos > end_pos && last_gb.buffer != NULL) {
- /* some encoders generate an incorrect size for this
- part. We must go back into the data */
- s_index -= 4;
- s->gb = last_gb;
- }
- break;
- }
- last_gb= s->gb;
-
- code = get_vlc(&s->gb, vlc);
- dprintf("t=%d code=%d\n", g->count1table_select, code);
- if (code < 0)
- return -1;
- for(i=0;i<4;i++) {
- if (code & (8 >> i)) {
- /* non zero value. Could use a hand coded function for
- 'one' value */
- v = l3_unscale(1, exponents[s_index]);
- if(get_bits1(&s->gb))
- v = -v;
- } else {
- v = 0;
- }
- g->sb_hybrid[s_index++] = v;
- }
- }
- while (s_index < 576)
- g->sb_hybrid[s_index++] = 0;
- return 0;
-}
-
-/* Reorder short blocks from bitstream order to interleaved order. It
- would be faster to do it in parsing, but the code would be far more
- complicated */
-static void reorder_block(MPADecodeContext *s, GranuleDef *g)
-{
- int i, j, k, len;
- int32_t *ptr, *dst, *ptr1;
- int32_t tmp[576];
-
- if (g->block_type != 2)
- return;
-
- if (g->switch_point) {
- if (s->sample_rate_index != 8) {
- ptr = g->sb_hybrid + 36;
- } else {
- ptr = g->sb_hybrid + 48;
- }
- } else {
- ptr = g->sb_hybrid;
- }
-
- for(i=g->short_start;i<13;i++) {
- len = band_size_short[s->sample_rate_index][i];
- ptr1 = ptr;
- for(k=0;k<3;k++) {
- dst = tmp + k;
- for(j=len;j>0;j--) {
- *dst = *ptr++;
- dst += 3;
- }
- }
- memcpy(ptr1, tmp, len * 3 * sizeof(int32_t));
- }
-}
-
-#define ISQRT2 FIXR(0.70710678118654752440)
-
-static void compute_stereo(MPADecodeContext *s,
- GranuleDef *g0, GranuleDef *g1)
-{
- int i, j, k, l;
- int32_t v1, v2;
- int sf_max, tmp0, tmp1, sf, len, non_zero_found;
- int32_t (*is_tab)[16];
- int32_t *tab0, *tab1;
- int non_zero_found_short[3];
-
- /* intensity stereo */
- if (s->mode_ext & MODE_EXT_I_STEREO) {
- if (!s->lsf) {
- is_tab = is_table;
- sf_max = 7;
- } else {
- is_tab = is_table_lsf[g1->scalefac_compress & 1];
- sf_max = 16;
- }
-
- tab0 = g0->sb_hybrid + 576;
- tab1 = g1->sb_hybrid + 576;
-
- non_zero_found_short[0] = 0;
- non_zero_found_short[1] = 0;
- non_zero_found_short[2] = 0;
- k = (13 - g1->short_start) * 3 + g1->long_end - 3;
- for(i = 12;i >= g1->short_start;i--) {
- /* for last band, use previous scale factor */
- if (i != 11)
- k -= 3;
- len = band_size_short[s->sample_rate_index][i];
- for(l=2;l>=0;l--) {
- tab0 -= len;
- tab1 -= len;
- if (!non_zero_found_short[l]) {
- /* test if non zero band. if so, stop doing i-stereo */
- for(j=0;j<len;j++) {
- if (tab1[j] != 0) {
- non_zero_found_short[l] = 1;
- goto found1;
- }
- }
- sf = g1->scale_factors[k + l];
- if (sf >= sf_max)
- goto found1;
-
- v1 = is_tab[0][sf];
- v2 = is_tab[1][sf];
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
- }
- } else {
- found1:
- if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* lower part of the spectrum : do ms stereo
- if enabled */
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
- }
- }
- }
- }
- }
-
- non_zero_found = non_zero_found_short[0] |
- non_zero_found_short[1] |
- non_zero_found_short[2];
-
- for(i = g1->long_end - 1;i >= 0;i--) {
- len = band_size_long[s->sample_rate_index][i];
- tab0 -= len;
- tab1 -= len;
- /* test if non zero band. if so, stop doing i-stereo */
- if (!non_zero_found) {
- for(j=0;j<len;j++) {
- if (tab1[j] != 0) {
- non_zero_found = 1;
- goto found2;
- }
- }
- /* for last band, use previous scale factor */
- k = (i == 21) ? 20 : i;
- sf = g1->scale_factors[k];
- if (sf >= sf_max)
- goto found2;
- v1 = is_tab[0][sf];
- v2 = is_tab[1][sf];
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tab0[j] = MULL(tmp0, v1);
- tab1[j] = MULL(tmp0, v2);
- }
- } else {
- found2:
- if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* lower part of the spectrum : do ms stereo
- if enabled */
- for(j=0;j<len;j++) {
- tmp0 = tab0[j];
- tmp1 = tab1[j];
- tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
- tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
- }
- }
- }
- }
- } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
- /* ms stereo ONLY */
- /* NOTE: the 1/sqrt(2) normalization factor is included in the
- global gain */
- tab0 = g0->sb_hybrid;
- tab1 = g1->sb_hybrid;
- for(i=0;i<576;i++) {
- tmp0 = tab0[i];
- tmp1 = tab1[i];
- tab0[i] = tmp0 + tmp1;
- tab1[i] = tmp0 - tmp1;
- }
- }
-}
-
-static void compute_antialias(MPADecodeContext *s,
- GranuleDef *g)
-{
- int32_t *ptr, *p0, *p1, *csa;
- int n, tmp0, tmp1, i, j;
-
- /* we antialias only "long" bands */
- if (g->block_type == 2) {
- if (!g->switch_point)
- return;
- /* XXX: check this for 8000Hz case */
- n = 1;
- } else {
- n = SBLIMIT - 1;
- }
-
- ptr = g->sb_hybrid + 18;
- for(i = n;i > 0;i--) {
- p0 = ptr - 1;
- p1 = ptr;
- csa = &csa_table[0][0];
- for(j=0;j<8;j++) {
- tmp0 = *p0;
- tmp1 = *p1;
- *p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1]));
- *p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0]));
- p0--;
- p1++;
- csa += 2;
- }
- ptr += 18;
- }
-}
-
-static void compute_imdct(MPADecodeContext *s,
- GranuleDef *g,
- int32_t *sb_samples,
- int32_t *mdct_buf)
-{
- int32_t *ptr, *win, *win1, *buf, *buf2, *out_ptr, *ptr1;
- int32_t in[6];
- int32_t out[36];
- int32_t out2[12];
- int i, j, k, mdct_long_end, v, sblimit;
-
- /* find last non zero block */
- ptr = g->sb_hybrid + 576;
- ptr1 = g->sb_hybrid + 2 * 18;
- while (ptr >= ptr1) {
- ptr -= 6;
- v = ptr[0] | ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5];
- if (v != 0)
- break;
- }
- sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
-
- if (g->block_type == 2) {
- /* XXX: check for 8000 Hz */
- if (g->switch_point)
- mdct_long_end = 2;
- else
- mdct_long_end = 0;
- } else {
- mdct_long_end = sblimit;
- }
-
- buf = mdct_buf;
- ptr = g->sb_hybrid;
- for(j=0;j<mdct_long_end;j++) {
- imdct36(out, ptr);
- /* apply window & overlap with previous buffer */
- out_ptr = sb_samples + j;
- /* select window */
- if (g->switch_point && j < 2)
- win1 = mdct_win[0];
- else
- win1 = mdct_win[g->block_type];
- /* select frequency inversion */
- win = win1 + ((4 * 36) & -(j & 1));
- for(i=0;i<18;i++) {
- *out_ptr = MULL(out[i], win[i]) + buf[i];
- buf[i] = MULL(out[i + 18], win[i + 18]);
- out_ptr += SBLIMIT;
- }
- ptr += 18;
- buf += 18;
- }
- for(j=mdct_long_end;j<sblimit;j++) {
- for(i=0;i<6;i++) {
- out[i] = 0;
- out[6 + i] = 0;
- out[30+i] = 0;
- }
- /* select frequency inversion */
- win = mdct_win[2] + ((4 * 36) & -(j & 1));
- buf2 = out + 6;
- for(k=0;k<3;k++) {
- /* reorder input for short mdct */
- ptr1 = ptr + k;
- for(i=0;i<6;i++) {
- in[i] = *ptr1;
- ptr1 += 3;
- }
- imdct12(out2, in);
- /* apply 12 point window and do small overlap */
- for(i=0;i<6;i++) {
- buf2[i] = MULL(out2[i], win[i]) + buf2[i];
- buf2[i + 6] = MULL(out2[i + 6], win[i + 6]);
- }
- buf2 += 6;
- }
- /* overlap */
- out_ptr = sb_samples + j;
- for(i=0;i<18;i++) {
- *out_ptr = out[i] + buf[i];
- buf[i] = out[i + 18];
- out_ptr += SBLIMIT;
- }
- ptr += 18;
- buf += 18;
- }
- /* zero bands */
- for(j=sblimit;j<SBLIMIT;j++) {
- /* overlap */
- out_ptr = sb_samples + j;
- for(i=0;i<18;i++) {
- *out_ptr = buf[i];
- buf[i] = 0;
- out_ptr += SBLIMIT;
- }
- buf += 18;
- }
-}
-
-#if defined(DEBUG)
-void sample_dump(int fnum, int32_t *tab, int n)
-{
- static FILE *files[16], *f;
- char buf[512];
- int i;
- int32_t v;
-
- f = files[fnum];
- if (!f) {
- sprintf(buf, "/tmp/out%d.%s.pcm",
- fnum,
-#ifdef USE_HIGHPRECISION
- "hp"
-#else
- "lp"
-#endif
- );
- f = fopen(buf, "w");
- if (!f)
- return;
- files[fnum] = f;
- }
-
- if (fnum == 0) {
- static int pos = 0;
- printf("pos=%d\n", pos);
- for(i=0;i<n;i++) {
- printf(" %0.4f", (double)tab[i] / FRAC_ONE);
- if ((i % 18) == 17)
- printf("\n");
- }
- pos += n;
- }
- for(i=0;i<n;i++) {
- /* normalize to 23 frac bits */
- v = tab[i] << (23 - FRAC_BITS);
- fwrite(&v, 1, sizeof(int32_t), f);
- }
-}
-#endif
-
-
-/* main layer3 decoding function */
-static int mp_decode_layer3(MPADecodeContext *s)
-{
- int nb_granules, main_data_begin, private_bits;
- int gr, ch, blocksplit_flag, i, j, k, n, bits_pos, bits_left;
- GranuleDef granules[2][2], *g;
- int16_t exponents[576];
-
- /* read side info */
- if (s->lsf) {
- main_data_begin = get_bits(&s->gb, 8);
- if (s->nb_channels == 2)
- private_bits = get_bits(&s->gb, 2);
- else
- private_bits = get_bits(&s->gb, 1);
- nb_granules = 1;
- } else {
- main_data_begin = get_bits(&s->gb, 9);
- if (s->nb_channels == 2)
- private_bits = get_bits(&s->gb, 3);
- else
- private_bits = get_bits(&s->gb, 5);
- nb_granules = 2;
- for(ch=0;ch<s->nb_channels;ch++) {
- granules[ch][0].scfsi = 0; /* all scale factors are transmitted */
- granules[ch][1].scfsi = get_bits(&s->gb, 4);
- }
- }
-
- for(gr=0;gr<nb_granules;gr++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- dprintf("gr=%d ch=%d: side_info\n", gr, ch);
- g = &granules[ch][gr];
- g->part2_3_length = get_bits(&s->gb, 12);
- g->big_values = get_bits(&s->gb, 9);
- g->global_gain = get_bits(&s->gb, 8);
- /* if MS stereo only is selected, we precompute the
- 1/sqrt(2) renormalization factor */
- if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
- MODE_EXT_MS_STEREO)
- g->global_gain -= 2;
- if (s->lsf)
- g->scalefac_compress = get_bits(&s->gb, 9);
- else
- g->scalefac_compress = get_bits(&s->gb, 4);
- blocksplit_flag = get_bits(&s->gb, 1);
- if (blocksplit_flag) {
- g->block_type = get_bits(&s->gb, 2);
- if (g->block_type == 0)
- return -1;
- g->switch_point = get_bits(&s->gb, 1);
- for(i=0;i<2;i++)
- g->table_select[i] = get_bits(&s->gb, 5);
- for(i=0;i<3;i++)
- g->subblock_gain[i] = get_bits(&s->gb, 3);
- /* compute huffman coded region sizes */
- if (g->block_type == 2)
- g->region_size[0] = (36 / 2);
- else {
- if (s->sample_rate_index <= 2)
- g->region_size[0] = (36 / 2);
- else if (s->sample_rate_index != 8)
- g->region_size[0] = (54 / 2);
- else
- g->region_size[0] = (108 / 2);
- }
- g->region_size[1] = (576 / 2);
- } else {
- int region_address1, region_address2, l;
- g->block_type = 0;
- g->switch_point = 0;
- for(i=0;i<3;i++)
- g->table_select[i] = get_bits(&s->gb, 5);
- /* compute huffman coded region sizes */
- region_address1 = get_bits(&s->gb, 4);
- region_address2 = get_bits(&s->gb, 3);
- dprintf("region1=%d region2=%d\n",
- region_address1, region_address2);
- g->region_size[0] =
- band_index_long[s->sample_rate_index][region_address1 + 1] >> 1;
- l = region_address1 + region_address2 + 2;
- /* should not overflow */
- if (l > 22)
- l = 22;
- g->region_size[1] =
- band_index_long[s->sample_rate_index][l] >> 1;
- }
- /* convert region offsets to region sizes and truncate
- size to big_values */
- g->region_size[2] = (576 / 2);
- j = 0;
- for(i=0;i<3;i++) {
- k = g->region_size[i];
- if (k > g->big_values)
- k = g->big_values;
- g->region_size[i] = k - j;
- j = k;
- }
-
- /* compute band indexes */
- if (g->block_type == 2) {
- if (g->switch_point) {
- /* if switched mode, we handle the 36 first samples as
- long blocks. For 8000Hz, we handle the 48 first
- exponents as long blocks (XXX: check this!) */
- if (s->sample_rate_index <= 2)
- g->long_end = 8;
- else if (s->sample_rate_index != 8)
- g->long_end = 6;
- else
- g->long_end = 4; /* 8000 Hz */
-
- if (s->sample_rate_index != 8)
- g->short_start = 3;
- else
- g->short_start = 2;
- } else {
- g->long_end = 0;
- g->short_start = 0;
- }
- } else {
- g->short_start = 13;
- g->long_end = 22;
- }
-
- g->preflag = 0;
- if (!s->lsf)
- g->preflag = get_bits(&s->gb, 1);
- g->scalefac_scale = get_bits(&s->gb, 1);
- g->count1table_select = get_bits(&s->gb, 1);
- dprintf("block_type=%d switch_point=%d\n",
- g->block_type, g->switch_point);
- }
- }
-
- /* now we get bits from the main_data_begin offset */
- dprintf("seekback: %d\n", main_data_begin);
- seek_to_maindata(s, main_data_begin);
-
- for(gr=0;gr<nb_granules;gr++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
-
- bits_pos = get_bits_count(&s->gb);
-
- if (!s->lsf) {
- uint8_t *sc;
- int slen, slen1, slen2;
-
- /* MPEG1 scale factors */
- slen1 = slen_table[0][g->scalefac_compress];
- slen2 = slen_table[1][g->scalefac_compress];
- dprintf("slen1=%d slen2=%d\n", slen1, slen2);
- if (g->block_type == 2) {
- n = g->switch_point ? 17 : 18;
- j = 0;
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bitsz(&s->gb, slen1);
- for(i=0;i<18;i++)
- g->scale_factors[j++] = get_bitsz(&s->gb, slen2);
- for(i=0;i<3;i++)
- g->scale_factors[j++] = 0;
- } else {
- sc = granules[ch][0].scale_factors;
- j = 0;
- for(k=0;k<4;k++) {
- n = (k == 0 ? 6 : 5);
- if ((g->scfsi & (0x8 >> k)) == 0) {
- slen = (k < 2) ? slen1 : slen2;
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bitsz(&s->gb, slen);
- } else {
- /* simply copy from last granule */
- for(i=0;i<n;i++) {
- g->scale_factors[j] = sc[j];
- j++;
- }
- }
- }
- g->scale_factors[j++] = 0;
- }
-#if defined(DEBUG)
- {
- printf("scfsi=%x gr=%d ch=%d scale_factors:\n",
- g->scfsi, gr, ch);
- for(i=0;i<j;i++)
- printf(" %d", g->scale_factors[i]);
- printf("\n");
- }
-#endif
- } else {
- int tindex, tindex2, slen[4], sl, sf;
-
- /* LSF scale factors */
- if (g->block_type == 2) {
- tindex = g->switch_point ? 2 : 1;
- } else {
- tindex = 0;
- }
- sf = g->scalefac_compress;
- if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
- /* intensity stereo case */
- sf >>= 1;
- if (sf < 180) {
- lsf_sf_expand(slen, sf, 6, 6, 0);
- tindex2 = 3;
- } else if (sf < 244) {
- lsf_sf_expand(slen, sf - 180, 4, 4, 0);
- tindex2 = 4;
- } else {
- lsf_sf_expand(slen, sf - 244, 3, 0, 0);
- tindex2 = 5;
- }
- } else {
- /* normal case */
- if (sf < 400) {
- lsf_sf_expand(slen, sf, 5, 4, 4);
- tindex2 = 0;
- } else if (sf < 500) {
- lsf_sf_expand(slen, sf - 400, 5, 4, 0);
- tindex2 = 1;
- } else {
- lsf_sf_expand(slen, sf - 500, 3, 0, 0);
- tindex2 = 2;
- g->preflag = 1;
- }
- }
-
- j = 0;
- for(k=0;k<4;k++) {
- n = lsf_nsf_table[tindex2][tindex][k];
- sl = slen[k];
- for(i=0;i<n;i++)
- g->scale_factors[j++] = get_bitsz(&s->gb, sl);
- }
- /* XXX: should compute exact size */
- for(;j<40;j++)
- g->scale_factors[j] = 0;
-#if defined(DEBUG)
- {
- printf("gr=%d ch=%d scale_factors:\n",
- gr, ch);
- for(i=0;i<40;i++)
- printf(" %d", g->scale_factors[i]);
- printf("\n");
- }
-#endif
- }
-
- exponents_from_scale_factors(s, g, exponents);
-
- /* read Huffman coded residue */
- if (huffman_decode(s, g, exponents,
- bits_pos + g->part2_3_length) < 0)
- return -1;
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
-
- /* skip extension bits */
- bits_left = g->part2_3_length - (get_bits_count(&s->gb) - bits_pos);
- if (bits_left < 0) {
- dprintf("bits_left=%d\n", bits_left);
- return -1;
- }
- while (bits_left >= 16) {
- skip_bits(&s->gb, 16);
- bits_left -= 16;
- }
- if (bits_left > 0)
- skip_bits(&s->gb, bits_left);
- } /* ch */
-
- if (s->nb_channels == 2)
- compute_stereo(s, &granules[0][gr], &granules[1][gr]);
-
- for(ch=0;ch<s->nb_channels;ch++) {
- g = &granules[ch][gr];
-
- reorder_block(s, g);
-#if defined(DEBUG)
- sample_dump(0, g->sb_hybrid, 576);
-#endif
- compute_antialias(s, g);
-#if defined(DEBUG)
- sample_dump(1, g->sb_hybrid, 576);
-#endif
- compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
-#if defined(DEBUG)
- sample_dump(2, &s->sb_samples[ch][18 * gr][0], 576);
-#endif
- }
- } /* gr */
- return nb_granules * 18;
-}
-
-static int mp_decode_frame(MPADecodeContext *s,
- short *samples)
-{
- int i, nb_frames, ch;
- short *samples_ptr;
-
- init_get_bits(&s->gb, s->inbuf + HEADER_SIZE,
- (s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8);
-
- /* skip error protection field */
- if (s->error_protection)
- get_bits(&s->gb, 16);
-
- dprintf("frame %d:\n", s->frame_count);
- switch(s->layer) {
- case 1:
- nb_frames = mp_decode_layer1(s);
- break;
- case 2:
- nb_frames = mp_decode_layer2(s);
- break;
- case 3:
- default:
- nb_frames = mp_decode_layer3(s);
- break;
- }
-#if defined(DEBUG)
- for(i=0;i<nb_frames;i++) {
- for(ch=0;ch<s->nb_channels;ch++) {
- int j;
- printf("%d-%d:", i, ch);
- for(j=0;j<SBLIMIT;j++)
- printf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
- printf("\n");
- }
- }
-#endif
- /* apply the synthesis filter */
- for(ch=0;ch<s->nb_channels;ch++) {
- samples_ptr = samples + ch;
- for(i=0;i<nb_frames;i++) {
- synth_filter(s, ch, samples_ptr, s->nb_channels,
- s->sb_samples[ch][i]);
- samples_ptr += 32 * s->nb_channels;
- }
- }
-#ifdef DEBUG
- s->frame_count++;
-#endif
- return nb_frames * 32 * sizeof(short) * s->nb_channels;
-}
-
-static int decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- MPADecodeContext *s = avctx->priv_data;
- uint32_t header;
- uint8_t *buf_ptr;
- int len, out_size;
- short *out_samples = data;
-
- *data_size = 0;
- buf_ptr = buf;
- while (buf_size > 0) {
- len = s->inbuf_ptr - s->inbuf;
- if (s->frame_size == 0) {
- /* special case for next header for first frame in free
- format case (XXX: find a simpler method) */
- if (s->free_format_next_header != 0) {
- s->inbuf[0] = s->free_format_next_header >> 24;
- s->inbuf[1] = s->free_format_next_header >> 16;
- s->inbuf[2] = s->free_format_next_header >> 8;
- s->inbuf[3] = s->free_format_next_header;
- s->inbuf_ptr = s->inbuf + 4;
- s->free_format_next_header = 0;
- goto got_header;
- }
- /* no header seen : find one. We need at least HEADER_SIZE
- bytes to parse it */
- len = HEADER_SIZE - len;
- if (len > buf_size)
- len = buf_size;
- if (len > 0) {
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- buf_size -= len;
- s->inbuf_ptr += len;
- }
- if ((s->inbuf_ptr - s->inbuf) >= HEADER_SIZE) {
- got_header:
- header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
- (s->inbuf[2] << 8) | s->inbuf[3];
-
- if (check_header(header) < 0) {
- /* no sync found : move by one byte (inefficient, but simple!) */
- memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
- s->inbuf_ptr--;
- dprintf("skip %x\n", header);
- /* reset free format frame size to give a chance
- to get a new bitrate */
- s->free_format_frame_size = 0;
- } else {
- if (decode_header(s, header) == 1) {
- /* free format: prepare to compute frame size */
- s->frame_size = -1;
- }
- /* update codec info */
- avctx->sample_rate = s->sample_rate;
- avctx->channels = s->nb_channels;
- avctx->bit_rate = s->bit_rate;
- avctx->sub_id = s->layer;
- switch(s->layer) {
- case 1:
- avctx->frame_size = 384;
- break;
- case 2:
- avctx->frame_size = 1152;
- break;
- case 3:
- if (s->lsf)
- avctx->frame_size = 576;
- else
- avctx->frame_size = 1152;
- break;
- }
- }
- }
- } else if (s->frame_size == -1) {
- /* free format : find next sync to compute frame size */
- len = MPA_MAX_CODED_FRAME_SIZE - len;
- if (len > buf_size)
- len = buf_size;
- if (len == 0) {
- /* frame too long: resync */
- s->frame_size = 0;
- memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
- s->inbuf_ptr--;
- } else {
- uint8_t *p, *pend;
- uint32_t header1;
- int padding;
-
- memcpy(s->inbuf_ptr, buf_ptr, len);
- /* check for header */
- p = s->inbuf_ptr - 3;
- pend = s->inbuf_ptr + len - 4;
- while (p <= pend) {
- header = (p[0] << 24) | (p[1] << 16) |
- (p[2] << 8) | p[3];
- header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
- (s->inbuf[2] << 8) | s->inbuf[3];
- /* check with high probability that we have a
- valid header */
- if ((header & SAME_HEADER_MASK) ==
- (header1 & SAME_HEADER_MASK)) {
- /* header found: update pointers */
- len = (p + 4) - s->inbuf_ptr;
- buf_ptr += len;
- buf_size -= len;
- s->inbuf_ptr = p;
- /* compute frame size */
- s->free_format_next_header = header;
- s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
- padding = (header1 >> 9) & 1;
- if (s->layer == 1)
- s->free_format_frame_size -= padding * 4;
- else
- s->free_format_frame_size -= padding;
- dprintf("free frame size=%d padding=%d\n",
- s->free_format_frame_size, padding);
- decode_header(s, header1);
- goto next_data;
- }
- p++;
- }
- /* not found: simply increase pointers */
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- }
- } else if (len < s->frame_size) {
- if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
- s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
- len = s->frame_size - len;
- if (len > buf_size)
- len = buf_size;
- memcpy(s->inbuf_ptr, buf_ptr, len);
- buf_ptr += len;
- s->inbuf_ptr += len;
- buf_size -= len;
- }
- next_data:
- if (s->frame_size > 0 &&
- (s->inbuf_ptr - s->inbuf) >= s->frame_size) {
- if (avctx->parse_only) {
- /* simply return the frame data */
- *(uint8_t **)data = s->inbuf;
- out_size = s->inbuf_ptr - s->inbuf;
- } else {
- out_size = mp_decode_frame(s, out_samples);
- }
- s->inbuf_ptr = s->inbuf;
- s->frame_size = 0;
- *data_size = out_size;
- break;
- }
- }
- return buf_ptr - buf;
-}
-
-AVCodec mp2_decoder =
-{
- "mp2",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP2,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
-};
-
-AVCodec mp3_decoder =
-{
- "mp3",
- CODEC_TYPE_AUDIO,
- CODEC_ID_MP3,
- sizeof(MPADecodeContext),
- decode_init,
- NULL,
- NULL,
- decode_frame,
- CODEC_CAP_PARSE_ONLY,
-};
+++ /dev/null
-/**
- * @file mpegaudiodectab.h
- * mpeg audio layer decoder tables.
- */
-
-const uint16_t mpa_bitrate_tab[2][3][15] = {
- { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 },
- {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 },
- {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } },
- { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256},
- {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160},
- {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}
- }
-};
-
-const uint16_t mpa_freq_tab[3] = { 44100, 48000, 32000 };
-
-/*******************************************************/
-/* half mpeg encoding window (full precision) */
-const int32_t mpa_enwindow[257] = {
- 0, -1, -1, -1, -1, -1, -1, -2,
- -2, -2, -2, -3, -3, -4, -4, -5,
- -5, -6, -7, -7, -8, -9, -10, -11,
- -13, -14, -16, -17, -19, -21, -24, -26,
- -29, -31, -35, -38, -41, -45, -49, -53,
- -58, -63, -68, -73, -79, -85, -91, -97,
- -104, -111, -117, -125, -132, -139, -147, -154,
- -161, -169, -176, -183, -190, -196, -202, -208,
- 213, 218, 222, 225, 227, 228, 228, 227,
- 224, 221, 215, 208, 200, 189, 177, 163,
- 146, 127, 106, 83, 57, 29, -2, -36,
- -72, -111, -153, -197, -244, -294, -347, -401,
- -459, -519, -581, -645, -711, -779, -848, -919,
- -991, -1064, -1137, -1210, -1283, -1356, -1428, -1498,
- -1567, -1634, -1698, -1759, -1817, -1870, -1919, -1962,
- -2001, -2032, -2057, -2075, -2085, -2087, -2080, -2063,
- 2037, 2000, 1952, 1893, 1822, 1739, 1644, 1535,
- 1414, 1280, 1131, 970, 794, 605, 402, 185,
- -45, -288, -545, -814, -1095, -1388, -1692, -2006,
- -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
- -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597,
- -7910, -8209, -8491, -8755, -8998, -9219, -9416, -9585,
- -9727, -9838, -9916, -9959, -9966, -9935, -9863, -9750,
- -9592, -9389, -9139, -8840, -8492, -8092, -7640, -7134,
- 6574, 5959, 5288, 4561, 3776, 2935, 2037, 1082,
- 70, -998, -2122, -3300, -4533, -5818, -7154, -8540,
- -9975,-11455,-12980,-14548,-16155,-17799,-19478,-21189,
--22929,-24694,-26482,-28289,-30112,-31947,-33791,-35640,
--37489,-39336,-41176,-43006,-44821,-46617,-48390,-50137,
--51853,-53534,-55178,-56778,-58333,-59838,-61289,-62684,
--64019,-65290,-66494,-67629,-68692,-69679,-70590,-71420,
--72169,-72835,-73415,-73908,-74313,-74630,-74856,-74992,
- 75038,
-};
-
-/*******************************************************/
-/* layer 2 tables */
-
-const int sblimit_table[5] = { 27 , 30 , 8, 12 , 30 };
-
-const int quant_steps[17] = {
- 3, 5, 7, 9, 15,
- 31, 63, 127, 255, 511,
- 1023, 2047, 4095, 8191, 16383,
- 32767, 65535
-};
-
-/* we use a negative value if grouped */
-const int quant_bits[17] = {
- -5, -7, 3, -10, 4,
- 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14,
- 15, 16
-};
-
-/* encoding tables which give the quantization index. Note how it is
- possible to store them efficiently ! */
-static const unsigned char alloc_table_0[] = {
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
-};
-
-static const unsigned char alloc_table_1[] = {
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 3, 0, 1, 2, 3, 4, 5, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
- 2, 0, 1, 16,
-};
-
-static const unsigned char alloc_table_2[] = {
- 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
-};
-
-static const unsigned char alloc_table_3[] = {
- 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
-};
-
-static const unsigned char alloc_table_4[] = {
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 3, 0, 1, 3, 4, 5, 6, 7,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
- 2, 0, 1, 3,
-};
-
-const unsigned char *alloc_tables[5] =
-{ alloc_table_0, alloc_table_1, alloc_table_2, alloc_table_3, alloc_table_4, };
-
-/*******************************************************/
-/* layer 3 tables */
-
-/* layer3 scale factor size */
-static const uint8_t slen_table[2][16] = {
- { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
- { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 },
-};
-
-/* number of lsf scale factors for a given size */
-static const uint8_t lsf_nsf_table[6][3][4] = {
- { { 6, 5, 5, 5 }, { 9, 9, 9, 9 }, { 6, 9, 9, 9 } },
- { { 6, 5, 7, 3 }, { 9, 9, 12, 6 }, { 6, 9, 12, 6 } },
- { { 11, 10, 0, 0 }, { 18, 18, 0, 0 }, { 15, 18, 0, 0 } },
- { { 7, 7, 7, 0 }, { 12, 12, 12, 0 }, { 6, 15, 12, 0 } },
- { { 6, 6, 6, 3 }, { 12, 9, 9, 6 }, { 6, 12, 9, 6 } },
- { { 8, 8, 5, 0 }, { 15, 12, 9, 0 }, { 6, 18, 9, 0 } },
-};
-
-/* mpegaudio layer 3 huffman tables */
-
-const uint16_t mpa_huffcodes_1[4] = {
- 0x0001, 0x0001, 0x0001, 0x0000,
-};
-
-const uint8_t mpa_huffbits_1[4] = {
- 1, 3, 2, 3,
-};
-
-const uint16_t mpa_huffcodes_2[9] = {
- 0x0001, 0x0002, 0x0001, 0x0003, 0x0001, 0x0001, 0x0003, 0x0002,
- 0x0000,
-};
-
-const uint8_t mpa_huffbits_2[9] = {
- 1, 3, 6, 3, 3, 5, 5, 5,
- 6,
-};
-
-const uint16_t mpa_huffcodes_3[9] = {
- 0x0003, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0003, 0x0002,
- 0x0000,
-};
-
-const uint8_t mpa_huffbits_3[9] = {
- 2, 2, 6, 3, 2, 5, 5, 5,
- 6,
-};
-
-const uint16_t mpa_huffcodes_5[16] = {
- 0x0001, 0x0002, 0x0006, 0x0005, 0x0003, 0x0001, 0x0004, 0x0004,
- 0x0007, 0x0005, 0x0007, 0x0001, 0x0006, 0x0001, 0x0001, 0x0000,
-};
-
-const uint8_t mpa_huffbits_5[16] = {
- 1, 3, 6, 7, 3, 3, 6, 7,
- 6, 6, 7, 8, 7, 6, 7, 8,
-};
-
-const uint16_t mpa_huffcodes_6[16] = {
- 0x0007, 0x0003, 0x0005, 0x0001, 0x0006, 0x0002, 0x0003, 0x0002,
- 0x0005, 0x0004, 0x0004, 0x0001, 0x0003, 0x0003, 0x0002, 0x0000,
-};
-
-const uint8_t mpa_huffbits_6[16] = {
- 3, 3, 5, 7, 3, 2, 4, 5,
- 4, 4, 5, 6, 6, 5, 6, 7,
-};
-
-const uint16_t mpa_huffcodes_7[36] = {
- 0x0001, 0x0002, 0x000a, 0x0013, 0x0010, 0x000a, 0x0003, 0x0003,
- 0x0007, 0x000a, 0x0005, 0x0003, 0x000b, 0x0004, 0x000d, 0x0011,
- 0x0008, 0x0004, 0x000c, 0x000b, 0x0012, 0x000f, 0x000b, 0x0002,
- 0x0007, 0x0006, 0x0009, 0x000e, 0x0003, 0x0001, 0x0006, 0x0004,
- 0x0005, 0x0003, 0x0002, 0x0000,
-};
-
-const uint8_t mpa_huffbits_7[36] = {
- 1, 3, 6, 8, 8, 9, 3, 4,
- 6, 7, 7, 8, 6, 5, 7, 8,
- 8, 9, 7, 7, 8, 9, 9, 9,
- 7, 7, 8, 9, 9, 10, 8, 8,
- 9, 10, 10, 10,
-};
-
-const uint16_t mpa_huffcodes_8[36] = {
- 0x0003, 0x0004, 0x0006, 0x0012, 0x000c, 0x0005, 0x0005, 0x0001,
- 0x0002, 0x0010, 0x0009, 0x0003, 0x0007, 0x0003, 0x0005, 0x000e,
- 0x0007, 0x0003, 0x0013, 0x0011, 0x000f, 0x000d, 0x000a, 0x0004,
- 0x000d, 0x0005, 0x0008, 0x000b, 0x0005, 0x0001, 0x000c, 0x0004,
- 0x0004, 0x0001, 0x0001, 0x0000,
-};
-
-const uint8_t mpa_huffbits_8[36] = {
- 2, 3, 6, 8, 8, 9, 3, 2,
- 4, 8, 8, 8, 6, 4, 6, 8,
- 8, 9, 8, 8, 8, 9, 9, 10,
- 8, 7, 8, 9, 10, 10, 9, 8,
- 9, 9, 11, 11,
-};
-
-const uint16_t mpa_huffcodes_9[36] = {
- 0x0007, 0x0005, 0x0009, 0x000e, 0x000f, 0x0007, 0x0006, 0x0004,
- 0x0005, 0x0005, 0x0006, 0x0007, 0x0007, 0x0006, 0x0008, 0x0008,
- 0x0008, 0x0005, 0x000f, 0x0006, 0x0009, 0x000a, 0x0005, 0x0001,
- 0x000b, 0x0007, 0x0009, 0x0006, 0x0004, 0x0001, 0x000e, 0x0004,
- 0x0006, 0x0002, 0x0006, 0x0000,
-};
-
-const uint8_t mpa_huffbits_9[36] = {
- 3, 3, 5, 6, 8, 9, 3, 3,
- 4, 5, 6, 8, 4, 4, 5, 6,
- 7, 8, 6, 5, 6, 7, 7, 8,
- 7, 6, 7, 7, 8, 9, 8, 7,
- 8, 8, 9, 9,
-};
-
-const uint16_t mpa_huffcodes_10[64] = {
- 0x0001, 0x0002, 0x000a, 0x0017, 0x0023, 0x001e, 0x000c, 0x0011,
- 0x0003, 0x0003, 0x0008, 0x000c, 0x0012, 0x0015, 0x000c, 0x0007,
- 0x000b, 0x0009, 0x000f, 0x0015, 0x0020, 0x0028, 0x0013, 0x0006,
- 0x000e, 0x000d, 0x0016, 0x0022, 0x002e, 0x0017, 0x0012, 0x0007,
- 0x0014, 0x0013, 0x0021, 0x002f, 0x001b, 0x0016, 0x0009, 0x0003,
- 0x001f, 0x0016, 0x0029, 0x001a, 0x0015, 0x0014, 0x0005, 0x0003,
- 0x000e, 0x000d, 0x000a, 0x000b, 0x0010, 0x0006, 0x0005, 0x0001,
- 0x0009, 0x0008, 0x0007, 0x0008, 0x0004, 0x0004, 0x0002, 0x0000,
-};
-
-const uint8_t mpa_huffbits_10[64] = {
- 1, 3, 6, 8, 9, 9, 9, 10,
- 3, 4, 6, 7, 8, 9, 8, 8,
- 6, 6, 7, 8, 9, 10, 9, 9,
- 7, 7, 8, 9, 10, 10, 9, 10,
- 8, 8, 9, 10, 10, 10, 10, 10,
- 9, 9, 10, 10, 11, 11, 10, 11,
- 8, 8, 9, 10, 10, 10, 11, 11,
- 9, 8, 9, 10, 10, 11, 11, 11,
-};
-
-const uint16_t mpa_huffcodes_11[64] = {
- 0x0003, 0x0004, 0x000a, 0x0018, 0x0022, 0x0021, 0x0015, 0x000f,
- 0x0005, 0x0003, 0x0004, 0x000a, 0x0020, 0x0011, 0x000b, 0x000a,
- 0x000b, 0x0007, 0x000d, 0x0012, 0x001e, 0x001f, 0x0014, 0x0005,
- 0x0019, 0x000b, 0x0013, 0x003b, 0x001b, 0x0012, 0x000c, 0x0005,
- 0x0023, 0x0021, 0x001f, 0x003a, 0x001e, 0x0010, 0x0007, 0x0005,
- 0x001c, 0x001a, 0x0020, 0x0013, 0x0011, 0x000f, 0x0008, 0x000e,
- 0x000e, 0x000c, 0x0009, 0x000d, 0x000e, 0x0009, 0x0004, 0x0001,
- 0x000b, 0x0004, 0x0006, 0x0006, 0x0006, 0x0003, 0x0002, 0x0000,
-};
-
-const uint8_t mpa_huffbits_11[64] = {
- 2, 3, 5, 7, 8, 9, 8, 9,
- 3, 3, 4, 6, 8, 8, 7, 8,
- 5, 5, 6, 7, 8, 9, 8, 8,
- 7, 6, 7, 9, 8, 10, 8, 9,
- 8, 8, 8, 9, 9, 10, 9, 10,
- 8, 8, 9, 10, 10, 11, 10, 11,
- 8, 7, 7, 8, 9, 10, 10, 10,
- 8, 7, 8, 9, 10, 10, 10, 10,
-};
-
-const uint16_t mpa_huffcodes_12[64] = {
- 0x0009, 0x0006, 0x0010, 0x0021, 0x0029, 0x0027, 0x0026, 0x001a,
- 0x0007, 0x0005, 0x0006, 0x0009, 0x0017, 0x0010, 0x001a, 0x000b,
- 0x0011, 0x0007, 0x000b, 0x000e, 0x0015, 0x001e, 0x000a, 0x0007,
- 0x0011, 0x000a, 0x000f, 0x000c, 0x0012, 0x001c, 0x000e, 0x0005,
- 0x0020, 0x000d, 0x0016, 0x0013, 0x0012, 0x0010, 0x0009, 0x0005,
- 0x0028, 0x0011, 0x001f, 0x001d, 0x0011, 0x000d, 0x0004, 0x0002,
- 0x001b, 0x000c, 0x000b, 0x000f, 0x000a, 0x0007, 0x0004, 0x0001,
- 0x001b, 0x000c, 0x0008, 0x000c, 0x0006, 0x0003, 0x0001, 0x0000,
-};
-
-const uint8_t mpa_huffbits_12[64] = {
- 4, 3, 5, 7, 8, 9, 9, 9,
- 3, 3, 4, 5, 7, 7, 8, 8,
- 5, 4, 5, 6, 7, 8, 7, 8,
- 6, 5, 6, 6, 7, 8, 8, 8,
- 7, 6, 7, 7, 8, 8, 8, 9,
- 8, 7, 8, 8, 8, 9, 8, 9,
- 8, 7, 7, 8, 8, 9, 9, 10,
- 9, 8, 8, 9, 9, 9, 9, 10,
-};
-
-const uint16_t mpa_huffcodes_13[256] = {
- 0x0001, 0x0005, 0x000e, 0x0015, 0x0022, 0x0033, 0x002e, 0x0047,
- 0x002a, 0x0034, 0x0044, 0x0034, 0x0043, 0x002c, 0x002b, 0x0013,
- 0x0003, 0x0004, 0x000c, 0x0013, 0x001f, 0x001a, 0x002c, 0x0021,
- 0x001f, 0x0018, 0x0020, 0x0018, 0x001f, 0x0023, 0x0016, 0x000e,
- 0x000f, 0x000d, 0x0017, 0x0024, 0x003b, 0x0031, 0x004d, 0x0041,
- 0x001d, 0x0028, 0x001e, 0x0028, 0x001b, 0x0021, 0x002a, 0x0010,
- 0x0016, 0x0014, 0x0025, 0x003d, 0x0038, 0x004f, 0x0049, 0x0040,
- 0x002b, 0x004c, 0x0038, 0x0025, 0x001a, 0x001f, 0x0019, 0x000e,
- 0x0023, 0x0010, 0x003c, 0x0039, 0x0061, 0x004b, 0x0072, 0x005b,
- 0x0036, 0x0049, 0x0037, 0x0029, 0x0030, 0x0035, 0x0017, 0x0018,
- 0x003a, 0x001b, 0x0032, 0x0060, 0x004c, 0x0046, 0x005d, 0x0054,
- 0x004d, 0x003a, 0x004f, 0x001d, 0x004a, 0x0031, 0x0029, 0x0011,
- 0x002f, 0x002d, 0x004e, 0x004a, 0x0073, 0x005e, 0x005a, 0x004f,
- 0x0045, 0x0053, 0x0047, 0x0032, 0x003b, 0x0026, 0x0024, 0x000f,
- 0x0048, 0x0022, 0x0038, 0x005f, 0x005c, 0x0055, 0x005b, 0x005a,
- 0x0056, 0x0049, 0x004d, 0x0041, 0x0033, 0x002c, 0x002b, 0x002a,
- 0x002b, 0x0014, 0x001e, 0x002c, 0x0037, 0x004e, 0x0048, 0x0057,
- 0x004e, 0x003d, 0x002e, 0x0036, 0x0025, 0x001e, 0x0014, 0x0010,
- 0x0035, 0x0019, 0x0029, 0x0025, 0x002c, 0x003b, 0x0036, 0x0051,
- 0x0042, 0x004c, 0x0039, 0x0036, 0x0025, 0x0012, 0x0027, 0x000b,
- 0x0023, 0x0021, 0x001f, 0x0039, 0x002a, 0x0052, 0x0048, 0x0050,
- 0x002f, 0x003a, 0x0037, 0x0015, 0x0016, 0x001a, 0x0026, 0x0016,
- 0x0035, 0x0019, 0x0017, 0x0026, 0x0046, 0x003c, 0x0033, 0x0024,
- 0x0037, 0x001a, 0x0022, 0x0017, 0x001b, 0x000e, 0x0009, 0x0007,
- 0x0022, 0x0020, 0x001c, 0x0027, 0x0031, 0x004b, 0x001e, 0x0034,
- 0x0030, 0x0028, 0x0034, 0x001c, 0x0012, 0x0011, 0x0009, 0x0005,
- 0x002d, 0x0015, 0x0022, 0x0040, 0x0038, 0x0032, 0x0031, 0x002d,
- 0x001f, 0x0013, 0x000c, 0x000f, 0x000a, 0x0007, 0x0006, 0x0003,
- 0x0030, 0x0017, 0x0014, 0x0027, 0x0024, 0x0023, 0x0035, 0x0015,
- 0x0010, 0x0017, 0x000d, 0x000a, 0x0006, 0x0001, 0x0004, 0x0002,
- 0x0010, 0x000f, 0x0011, 0x001b, 0x0019, 0x0014, 0x001d, 0x000b,
- 0x0011, 0x000c, 0x0010, 0x0008, 0x0001, 0x0001, 0x0000, 0x0001,
-};
-
-const uint8_t mpa_huffbits_13[256] = {
- 1, 4, 6, 7, 8, 9, 9, 10,
- 9, 10, 11, 11, 12, 12, 13, 13,
- 3, 4, 6, 7, 8, 8, 9, 9,
- 9, 9, 10, 10, 11, 12, 12, 12,
- 6, 6, 7, 8, 9, 9, 10, 10,
- 9, 10, 10, 11, 11, 12, 13, 13,
- 7, 7, 8, 9, 9, 10, 10, 10,
- 10, 11, 11, 11, 11, 12, 13, 13,
- 8, 7, 9, 9, 10, 10, 11, 11,
- 10, 11, 11, 12, 12, 13, 13, 14,
- 9, 8, 9, 10, 10, 10, 11, 11,
- 11, 11, 12, 11, 13, 13, 14, 14,
- 9, 9, 10, 10, 11, 11, 11, 11,
- 11, 12, 12, 12, 13, 13, 14, 14,
- 10, 9, 10, 11, 11, 11, 12, 12,
- 12, 12, 13, 13, 13, 14, 16, 16,
- 9, 8, 9, 10, 10, 11, 11, 12,
- 12, 12, 12, 13, 13, 14, 15, 15,
- 10, 9, 10, 10, 11, 11, 11, 13,
- 12, 13, 13, 14, 14, 14, 16, 15,
- 10, 10, 10, 11, 11, 12, 12, 13,
- 12, 13, 14, 13, 14, 15, 16, 17,
- 11, 10, 10, 11, 12, 12, 12, 12,
- 13, 13, 13, 14, 15, 15, 15, 16,
- 11, 11, 11, 12, 12, 13, 12, 13,
- 14, 14, 15, 15, 15, 16, 16, 16,
- 12, 11, 12, 13, 13, 13, 14, 14,
- 14, 14, 14, 15, 16, 15, 16, 16,
- 13, 12, 12, 13, 13, 13, 15, 14,
- 14, 17, 15, 15, 15, 17, 16, 16,
- 12, 12, 13, 14, 14, 14, 15, 14,
- 15, 15, 16, 16, 19, 18, 19, 16,
-};
-
-const uint16_t mpa_huffcodes_15[256] = {
- 0x0007, 0x000c, 0x0012, 0x0035, 0x002f, 0x004c, 0x007c, 0x006c,
- 0x0059, 0x007b, 0x006c, 0x0077, 0x006b, 0x0051, 0x007a, 0x003f,
- 0x000d, 0x0005, 0x0010, 0x001b, 0x002e, 0x0024, 0x003d, 0x0033,
- 0x002a, 0x0046, 0x0034, 0x0053, 0x0041, 0x0029, 0x003b, 0x0024,
- 0x0013, 0x0011, 0x000f, 0x0018, 0x0029, 0x0022, 0x003b, 0x0030,
- 0x0028, 0x0040, 0x0032, 0x004e, 0x003e, 0x0050, 0x0038, 0x0021,
- 0x001d, 0x001c, 0x0019, 0x002b, 0x0027, 0x003f, 0x0037, 0x005d,
- 0x004c, 0x003b, 0x005d, 0x0048, 0x0036, 0x004b, 0x0032, 0x001d,
- 0x0034, 0x0016, 0x002a, 0x0028, 0x0043, 0x0039, 0x005f, 0x004f,
- 0x0048, 0x0039, 0x0059, 0x0045, 0x0031, 0x0042, 0x002e, 0x001b,
- 0x004d, 0x0025, 0x0023, 0x0042, 0x003a, 0x0034, 0x005b, 0x004a,
- 0x003e, 0x0030, 0x004f, 0x003f, 0x005a, 0x003e, 0x0028, 0x0026,
- 0x007d, 0x0020, 0x003c, 0x0038, 0x0032, 0x005c, 0x004e, 0x0041,
- 0x0037, 0x0057, 0x0047, 0x0033, 0x0049, 0x0033, 0x0046, 0x001e,
- 0x006d, 0x0035, 0x0031, 0x005e, 0x0058, 0x004b, 0x0042, 0x007a,
- 0x005b, 0x0049, 0x0038, 0x002a, 0x0040, 0x002c, 0x0015, 0x0019,
- 0x005a, 0x002b, 0x0029, 0x004d, 0x0049, 0x003f, 0x0038, 0x005c,
- 0x004d, 0x0042, 0x002f, 0x0043, 0x0030, 0x0035, 0x0024, 0x0014,
- 0x0047, 0x0022, 0x0043, 0x003c, 0x003a, 0x0031, 0x0058, 0x004c,
- 0x0043, 0x006a, 0x0047, 0x0036, 0x0026, 0x0027, 0x0017, 0x000f,
- 0x006d, 0x0035, 0x0033, 0x002f, 0x005a, 0x0052, 0x003a, 0x0039,
- 0x0030, 0x0048, 0x0039, 0x0029, 0x0017, 0x001b, 0x003e, 0x0009,
- 0x0056, 0x002a, 0x0028, 0x0025, 0x0046, 0x0040, 0x0034, 0x002b,
- 0x0046, 0x0037, 0x002a, 0x0019, 0x001d, 0x0012, 0x000b, 0x000b,
- 0x0076, 0x0044, 0x001e, 0x0037, 0x0032, 0x002e, 0x004a, 0x0041,
- 0x0031, 0x0027, 0x0018, 0x0010, 0x0016, 0x000d, 0x000e, 0x0007,
- 0x005b, 0x002c, 0x0027, 0x0026, 0x0022, 0x003f, 0x0034, 0x002d,
- 0x001f, 0x0034, 0x001c, 0x0013, 0x000e, 0x0008, 0x0009, 0x0003,
- 0x007b, 0x003c, 0x003a, 0x0035, 0x002f, 0x002b, 0x0020, 0x0016,
- 0x0025, 0x0018, 0x0011, 0x000c, 0x000f, 0x000a, 0x0002, 0x0001,
- 0x0047, 0x0025, 0x0022, 0x001e, 0x001c, 0x0014, 0x0011, 0x001a,
- 0x0015, 0x0010, 0x000a, 0x0006, 0x0008, 0x0006, 0x0002, 0x0000,
-};
-
-const uint8_t mpa_huffbits_15[256] = {
- 3, 4, 5, 7, 7, 8, 9, 9,
- 9, 10, 10, 11, 11, 11, 12, 13,
- 4, 3, 5, 6, 7, 7, 8, 8,
- 8, 9, 9, 10, 10, 10, 11, 11,
- 5, 5, 5, 6, 7, 7, 8, 8,
- 8, 9, 9, 10, 10, 11, 11, 11,
- 6, 6, 6, 7, 7, 8, 8, 9,
- 9, 9, 10, 10, 10, 11, 11, 11,
- 7, 6, 7, 7, 8, 8, 9, 9,
- 9, 9, 10, 10, 10, 11, 11, 11,
- 8, 7, 7, 8, 8, 8, 9, 9,
- 9, 9, 10, 10, 11, 11, 11, 12,
- 9, 7, 8, 8, 8, 9, 9, 9,
- 9, 10, 10, 10, 11, 11, 12, 12,
- 9, 8, 8, 9, 9, 9, 9, 10,
- 10, 10, 10, 10, 11, 11, 11, 12,
- 9, 8, 8, 9, 9, 9, 9, 10,
- 10, 10, 10, 11, 11, 12, 12, 12,
- 9, 8, 9, 9, 9, 9, 10, 10,
- 10, 11, 11, 11, 11, 12, 12, 12,
- 10, 9, 9, 9, 10, 10, 10, 10,
- 10, 11, 11, 11, 11, 12, 13, 12,
- 10, 9, 9, 9, 10, 10, 10, 10,
- 11, 11, 11, 11, 12, 12, 12, 13,
- 11, 10, 9, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 12, 12, 13, 13,
- 11, 10, 10, 10, 10, 11, 11, 11,
- 11, 12, 12, 12, 12, 12, 13, 13,
- 12, 11, 11, 11, 11, 11, 11, 11,
- 12, 12, 12, 12, 13, 13, 12, 13,
- 12, 11, 11, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 13, 13, 13, 13,
-};
-
-const uint16_t mpa_huffcodes_16[256] = {
- 0x0001, 0x0005, 0x000e, 0x002c, 0x004a, 0x003f, 0x006e, 0x005d,
- 0x00ac, 0x0095, 0x008a, 0x00f2, 0x00e1, 0x00c3, 0x0178, 0x0011,
- 0x0003, 0x0004, 0x000c, 0x0014, 0x0023, 0x003e, 0x0035, 0x002f,
- 0x0053, 0x004b, 0x0044, 0x0077, 0x00c9, 0x006b, 0x00cf, 0x0009,
- 0x000f, 0x000d, 0x0017, 0x0026, 0x0043, 0x003a, 0x0067, 0x005a,
- 0x00a1, 0x0048, 0x007f, 0x0075, 0x006e, 0x00d1, 0x00ce, 0x0010,
- 0x002d, 0x0015, 0x0027, 0x0045, 0x0040, 0x0072, 0x0063, 0x0057,
- 0x009e, 0x008c, 0x00fc, 0x00d4, 0x00c7, 0x0183, 0x016d, 0x001a,
- 0x004b, 0x0024, 0x0044, 0x0041, 0x0073, 0x0065, 0x00b3, 0x00a4,
- 0x009b, 0x0108, 0x00f6, 0x00e2, 0x018b, 0x017e, 0x016a, 0x0009,
- 0x0042, 0x001e, 0x003b, 0x0038, 0x0066, 0x00b9, 0x00ad, 0x0109,
- 0x008e, 0x00fd, 0x00e8, 0x0190, 0x0184, 0x017a, 0x01bd, 0x0010,
- 0x006f, 0x0036, 0x0034, 0x0064, 0x00b8, 0x00b2, 0x00a0, 0x0085,
- 0x0101, 0x00f4, 0x00e4, 0x00d9, 0x0181, 0x016e, 0x02cb, 0x000a,
- 0x0062, 0x0030, 0x005b, 0x0058, 0x00a5, 0x009d, 0x0094, 0x0105,
- 0x00f8, 0x0197, 0x018d, 0x0174, 0x017c, 0x0379, 0x0374, 0x0008,
- 0x0055, 0x0054, 0x0051, 0x009f, 0x009c, 0x008f, 0x0104, 0x00f9,
- 0x01ab, 0x0191, 0x0188, 0x017f, 0x02d7, 0x02c9, 0x02c4, 0x0007,
- 0x009a, 0x004c, 0x0049, 0x008d, 0x0083, 0x0100, 0x00f5, 0x01aa,
- 0x0196, 0x018a, 0x0180, 0x02df, 0x0167, 0x02c6, 0x0160, 0x000b,
- 0x008b, 0x0081, 0x0043, 0x007d, 0x00f7, 0x00e9, 0x00e5, 0x00db,
- 0x0189, 0x02e7, 0x02e1, 0x02d0, 0x0375, 0x0372, 0x01b7, 0x0004,
- 0x00f3, 0x0078, 0x0076, 0x0073, 0x00e3, 0x00df, 0x018c, 0x02ea,
- 0x02e6, 0x02e0, 0x02d1, 0x02c8, 0x02c2, 0x00df, 0x01b4, 0x0006,
- 0x00ca, 0x00e0, 0x00de, 0x00da, 0x00d8, 0x0185, 0x0182, 0x017d,
- 0x016c, 0x0378, 0x01bb, 0x02c3, 0x01b8, 0x01b5, 0x06c0, 0x0004,
- 0x02eb, 0x00d3, 0x00d2, 0x00d0, 0x0172, 0x017b, 0x02de, 0x02d3,
- 0x02ca, 0x06c7, 0x0373, 0x036d, 0x036c, 0x0d83, 0x0361, 0x0002,
- 0x0179, 0x0171, 0x0066, 0x00bb, 0x02d6, 0x02d2, 0x0166, 0x02c7,
- 0x02c5, 0x0362, 0x06c6, 0x0367, 0x0d82, 0x0366, 0x01b2, 0x0000,
- 0x000c, 0x000a, 0x0007, 0x000b, 0x000a, 0x0011, 0x000b, 0x0009,
- 0x000d, 0x000c, 0x000a, 0x0007, 0x0005, 0x0003, 0x0001, 0x0003,
-};
-
-const uint8_t mpa_huffbits_16[256] = {
- 1, 4, 6, 8, 9, 9, 10, 10,
- 11, 11, 11, 12, 12, 12, 13, 9,
- 3, 4, 6, 7, 8, 9, 9, 9,
- 10, 10, 10, 11, 12, 11, 12, 8,
- 6, 6, 7, 8, 9, 9, 10, 10,
- 11, 10, 11, 11, 11, 12, 12, 9,
- 8, 7, 8, 9, 9, 10, 10, 10,
- 11, 11, 12, 12, 12, 13, 13, 10,
- 9, 8, 9, 9, 10, 10, 11, 11,
- 11, 12, 12, 12, 13, 13, 13, 9,
- 9, 8, 9, 9, 10, 11, 11, 12,
- 11, 12, 12, 13, 13, 13, 14, 10,
- 10, 9, 9, 10, 11, 11, 11, 11,
- 12, 12, 12, 12, 13, 13, 14, 10,
- 10, 9, 10, 10, 11, 11, 11, 12,
- 12, 13, 13, 13, 13, 15, 15, 10,
- 10, 10, 10, 11, 11, 11, 12, 12,
- 13, 13, 13, 13, 14, 14, 14, 10,
- 11, 10, 10, 11, 11, 12, 12, 13,
- 13, 13, 13, 14, 13, 14, 13, 11,
- 11, 11, 10, 11, 12, 12, 12, 12,
- 13, 14, 14, 14, 15, 15, 14, 10,
- 12, 11, 11, 11, 12, 12, 13, 14,
- 14, 14, 14, 14, 14, 13, 14, 11,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 15, 14, 14, 14, 14, 16, 11,
- 14, 12, 12, 12, 13, 13, 14, 14,
- 14, 16, 15, 15, 15, 17, 15, 11,
- 13, 13, 11, 12, 14, 14, 13, 14,
- 14, 15, 16, 15, 17, 15, 14, 11,
- 9, 8, 8, 9, 9, 10, 10, 10,
- 11, 11, 11, 11, 11, 11, 11, 8,
-};
-
-const uint16_t mpa_huffcodes_24[256] = {
- 0x000f, 0x000d, 0x002e, 0x0050, 0x0092, 0x0106, 0x00f8, 0x01b2,
- 0x01aa, 0x029d, 0x028d, 0x0289, 0x026d, 0x0205, 0x0408, 0x0058,
- 0x000e, 0x000c, 0x0015, 0x0026, 0x0047, 0x0082, 0x007a, 0x00d8,
- 0x00d1, 0x00c6, 0x0147, 0x0159, 0x013f, 0x0129, 0x0117, 0x002a,
- 0x002f, 0x0016, 0x0029, 0x004a, 0x0044, 0x0080, 0x0078, 0x00dd,
- 0x00cf, 0x00c2, 0x00b6, 0x0154, 0x013b, 0x0127, 0x021d, 0x0012,
- 0x0051, 0x0027, 0x004b, 0x0046, 0x0086, 0x007d, 0x0074, 0x00dc,
- 0x00cc, 0x00be, 0x00b2, 0x0145, 0x0137, 0x0125, 0x010f, 0x0010,
- 0x0093, 0x0048, 0x0045, 0x0087, 0x007f, 0x0076, 0x0070, 0x00d2,
- 0x00c8, 0x00bc, 0x0160, 0x0143, 0x0132, 0x011d, 0x021c, 0x000e,
- 0x0107, 0x0042, 0x0081, 0x007e, 0x0077, 0x0072, 0x00d6, 0x00ca,
- 0x00c0, 0x00b4, 0x0155, 0x013d, 0x012d, 0x0119, 0x0106, 0x000c,
- 0x00f9, 0x007b, 0x0079, 0x0075, 0x0071, 0x00d7, 0x00ce, 0x00c3,
- 0x00b9, 0x015b, 0x014a, 0x0134, 0x0123, 0x0110, 0x0208, 0x000a,
- 0x01b3, 0x0073, 0x006f, 0x006d, 0x00d3, 0x00cb, 0x00c4, 0x00bb,
- 0x0161, 0x014c, 0x0139, 0x012a, 0x011b, 0x0213, 0x017d, 0x0011,
- 0x01ab, 0x00d4, 0x00d0, 0x00cd, 0x00c9, 0x00c1, 0x00ba, 0x00b1,
- 0x00a9, 0x0140, 0x012f, 0x011e, 0x010c, 0x0202, 0x0179, 0x0010,
- 0x014f, 0x00c7, 0x00c5, 0x00bf, 0x00bd, 0x00b5, 0x00ae, 0x014d,
- 0x0141, 0x0131, 0x0121, 0x0113, 0x0209, 0x017b, 0x0173, 0x000b,
- 0x029c, 0x00b8, 0x00b7, 0x00b3, 0x00af, 0x0158, 0x014b, 0x013a,
- 0x0130, 0x0122, 0x0115, 0x0212, 0x017f, 0x0175, 0x016e, 0x000a,
- 0x028c, 0x015a, 0x00ab, 0x00a8, 0x00a4, 0x013e, 0x0135, 0x012b,
- 0x011f, 0x0114, 0x0107, 0x0201, 0x0177, 0x0170, 0x016a, 0x0006,
- 0x0288, 0x0142, 0x013c, 0x0138, 0x0133, 0x012e, 0x0124, 0x011c,
- 0x010d, 0x0105, 0x0200, 0x0178, 0x0172, 0x016c, 0x0167, 0x0004,
- 0x026c, 0x012c, 0x0128, 0x0126, 0x0120, 0x011a, 0x0111, 0x010a,
- 0x0203, 0x017c, 0x0176, 0x0171, 0x016d, 0x0169, 0x0165, 0x0002,
- 0x0409, 0x0118, 0x0116, 0x0112, 0x010b, 0x0108, 0x0103, 0x017e,
- 0x017a, 0x0174, 0x016f, 0x016b, 0x0168, 0x0166, 0x0164, 0x0000,
- 0x002b, 0x0014, 0x0013, 0x0011, 0x000f, 0x000d, 0x000b, 0x0009,
- 0x0007, 0x0006, 0x0004, 0x0007, 0x0005, 0x0003, 0x0001, 0x0003,
-};
-
-const uint8_t mpa_huffbits_24[256] = {
- 4, 4, 6, 7, 8, 9, 9, 10,
- 10, 11, 11, 11, 11, 11, 12, 9,
- 4, 4, 5, 6, 7, 8, 8, 9,
- 9, 9, 10, 10, 10, 10, 10, 8,
- 6, 5, 6, 7, 7, 8, 8, 9,
- 9, 9, 9, 10, 10, 10, 11, 7,
- 7, 6, 7, 7, 8, 8, 8, 9,
- 9, 9, 9, 10, 10, 10, 10, 7,
- 8, 7, 7, 8, 8, 8, 8, 9,
- 9, 9, 10, 10, 10, 10, 11, 7,
- 9, 7, 8, 8, 8, 8, 9, 9,
- 9, 9, 10, 10, 10, 10, 10, 7,
- 9, 8, 8, 8, 8, 9, 9, 9,
- 9, 10, 10, 10, 10, 10, 11, 7,
- 10, 8, 8, 8, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 11, 11, 8,
- 10, 9, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 10, 11, 11, 8,
- 10, 9, 9, 9, 9, 9, 9, 10,
- 10, 10, 10, 10, 11, 11, 11, 8,
- 11, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 11, 8,
- 11, 10, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 11, 8,
- 11, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 11, 11, 11, 11, 11, 8,
- 11, 10, 10, 10, 10, 10, 10, 10,
- 11, 11, 11, 11, 11, 11, 11, 8,
- 12, 10, 10, 10, 10, 10, 10, 11,
- 11, 11, 11, 11, 11, 11, 11, 8,
- 8, 7, 7, 7, 7, 7, 7, 7,
- 7, 7, 7, 8, 8, 8, 8, 4,
-};
-
-const HuffTable mpa_huff_tables[16] = {
-{ 1, NULL, NULL },
-{ 2, mpa_huffbits_1, mpa_huffcodes_1 },
-{ 3, mpa_huffbits_2, mpa_huffcodes_2 },
-{ 3, mpa_huffbits_3, mpa_huffcodes_3 },
-{ 4, mpa_huffbits_5, mpa_huffcodes_5 },
-{ 4, mpa_huffbits_6, mpa_huffcodes_6 },
-{ 6, mpa_huffbits_7, mpa_huffcodes_7 },
-{ 6, mpa_huffbits_8, mpa_huffcodes_8 },
-{ 6, mpa_huffbits_9, mpa_huffcodes_9 },
-{ 8, mpa_huffbits_10, mpa_huffcodes_10 },
-{ 8, mpa_huffbits_11, mpa_huffcodes_11 },
-{ 8, mpa_huffbits_12, mpa_huffcodes_12 },
-{ 16, mpa_huffbits_13, mpa_huffcodes_13 },
-{ 16, mpa_huffbits_15, mpa_huffcodes_15 },
-{ 16, mpa_huffbits_16, mpa_huffcodes_16 },
-{ 16, mpa_huffbits_24, mpa_huffcodes_24 },
-};
-
-const uint8_t mpa_huff_data[32][2] = {
-{ 0, 0 },
-{ 1, 0 },
-{ 2, 0 },
-{ 3, 0 },
-{ 0, 0 },
-{ 4, 0 },
-{ 5, 0 },
-{ 6, 0 },
-{ 7, 0 },
-{ 8, 0 },
-{ 9, 0 },
-{ 10, 0 },
-{ 11, 0 },
-{ 12, 0 },
-{ 0, 0 },
-{ 13, 0 },
-{ 14, 1 },
-{ 14, 2 },
-{ 14, 3 },
-{ 14, 4 },
-{ 14, 6 },
-{ 14, 8 },
-{ 14, 10 },
-{ 14, 13 },
-{ 15, 4 },
-{ 15, 5 },
-{ 15, 6 },
-{ 15, 7 },
-{ 15, 8 },
-{ 15, 9 },
-{ 15, 11 },
-{ 15, 13 },
-};
-
-
-/* huffman tables for quadrules */
-static uint8_t mpa_quad_codes[2][16] = {
- { 1, 5, 4, 5, 6, 5, 4, 4, 7, 3, 6, 0, 7, 2, 3, 1, },
- { 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, },
-};
-
-static uint8_t mpa_quad_bits[2][16] = {
- { 1, 4, 4, 5, 4, 6, 5, 6, 4, 5, 5, 6, 5, 6, 6, 6, },
- { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, },
-};
-
-/* band size tables */
-const uint8_t band_size_long[9][22] = {
-{ 4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
- 12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158, }, /* 44100 */
-{ 4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
- 12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192, }, /* 48000 */
-{ 4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
- 16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26, }, /* 32000 */
-{ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 22050 */
-{ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 18, 22, 26, 32, 38, 46, 52, 64, 70, 76, 36, }, /* 24000 */
-{ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 16000 */
-{ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 11025 */
-{ 6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
- 20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54, }, /* 12000 */
-{ 12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
- 40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2, }, /* 8000 */
-};
-
-const uint8_t band_size_short[9][13] = {
-{ 4, 4, 4, 4, 6, 8, 10, 12, 14, 18, 22, 30, 56, }, /* 44100 */
-{ 4, 4, 4, 4, 6, 6, 10, 12, 14, 16, 20, 26, 66, }, /* 48000 */
-{ 4, 4, 4, 4, 6, 8, 12, 16, 20, 26, 34, 42, 12, }, /* 32000 */
-{ 4, 4, 4, 6, 6, 8, 10, 14, 18, 26, 32, 42, 18, }, /* 22050 */
-{ 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 32, 44, 12, }, /* 24000 */
-{ 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 16000 */
-{ 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 11025 */
-{ 4, 4, 4, 6, 8, 10, 12, 14, 18, 24, 30, 40, 18, }, /* 12000 */
-{ 8, 8, 8, 12, 16, 20, 24, 28, 36, 2, 2, 2, 26, }, /* 8000 */
-};
-
-const uint8_t mpa_pretab[2][22] = {
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0 },
-};
-
-/* table for alias reduction (XXX: store it as integer !) */
-const float ci_table[8] = {
- -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037,
-};
+++ /dev/null
-/*
- * mpeg audio layer 2 tables. Most of them come from the mpeg audio
- * specification.
- *
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * The licence of this code is contained in file LICENCE found in the
- * same archive
- */
-
-/**
- * @file mpegaudiotab.h
- * mpeg audio layer 2 tables.
- * Most of them come from the mpeg audio specification.
- */
-
-#define SQRT2 1.41421356237309514547
-
-static const int costab32[30] = {
- FIX(0.54119610014619701222),
- FIX(1.3065629648763763537),
-
- FIX(0.50979557910415917998),
- FIX(2.5629154477415054814),
- FIX(0.89997622313641556513),
- FIX(0.60134488693504528634),
-
- FIX(0.5024192861881556782),
- FIX(5.1011486186891552563),
- FIX(0.78815462345125020249),
- FIX(0.64682178335999007679),
- FIX(0.56694403481635768927),
- FIX(1.0606776859903470633),
- FIX(1.7224470982383341955),
- FIX(0.52249861493968885462),
-
- FIX(10.19000812354803287),
- FIX(0.674808341455005678),
- FIX(1.1694399334328846596),
- FIX(0.53104259108978413284),
- FIX(2.0577810099534108446),
- FIX(0.58293496820613388554),
- FIX(0.83934964541552681272),
- FIX(0.50547095989754364798),
- FIX(3.4076084184687189804),
- FIX(0.62250412303566482475),
- FIX(0.97256823786196078263),
- FIX(0.51544730992262455249),
- FIX(1.4841646163141661852),
- FIX(0.5531038960344445421),
- FIX(0.74453627100229857749),
- FIX(0.5006029982351962726),
-};
-
-static const int bitinv32[32] = {
- 0, 16, 8, 24, 4, 20, 12, 28,
- 2, 18, 10, 26, 6, 22, 14, 30,
- 1, 17, 9, 25, 5, 21, 13, 29,
- 3, 19, 11, 27, 7, 23, 15, 31
-};
-
-
-static int16_t filter_bank[512];
-
-static int scale_factor_table[64];
-#ifdef USE_FLOATS
-static float scale_factor_inv_table[64];
-#else
-static int8_t scale_factor_shift[64];
-static unsigned short scale_factor_mult[64];
-#endif
-static unsigned char scale_diff_table[128];
-
-/* total number of bits per allocation group */
-static unsigned short total_quant_bits[17];
-
-/* signal to noise ratio of each quantification step (could be
- computed from quant_steps[]). The values are dB multiplied by 10
-*/
-static unsigned short quant_snr[17] = {
- 70, 110, 160, 208,
- 253, 316, 378, 439,
- 499, 559, 620, 680,
- 740, 800, 861, 920,
- 980
-};
-
-/* fixed psycho acoustic model. ValueBases of SNR taken from the 'toolame'
- project */
-static const float fixed_smr[SBLIMIT] = {
- 30, 17, 16, 10, 3, 12, 8, 2.5,
- 5, 5, 6, 6, 5, 6, 10, 6,
- -4, -10, -21, -30, -42, -55, -68, -75,
- -75, -75, -75, -75, -91, -107, -110, -108
-};
-
-static const unsigned char nb_scale_factors[4] = { 3, 2, 1, 2 };
-
+++ /dev/null
-/*
- * The simplest mpeg encoder (well, it was the simplest!)
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file mpegvideo.c
- * The simplest mpeg encoder (well, it was the simplest!).
- */
-
-#include <limits.h>
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-
-//#undef NDEBUG
-//#include <assert.h>
-
-#ifdef CONFIG_ENCODERS
-static void encode_picture(MpegEncContext *s, int picture_number);
-#endif //CONFIG_ENCODERS
-static void dct_unquantize_mpeg1_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_mpeg2_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void dct_unquantize_h263_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale);
-static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
-#ifdef CONFIG_ENCODERS
-static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-static int sse_mb(MpegEncContext *s);
-#endif //CONFIG_ENCODERS
-
-#ifdef HAVE_XVMC
-extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx);
-extern void XVMC_field_end(MpegEncContext *s);
-extern void XVMC_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-#endif
-
-void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c;
-
-
-/* enable all paranoid tests for rounding, overflows, etc... */
-//#define PARANOID
-
-//#define DEBUG
-
-
-/* for jpeg fast DCT */
-#define CONST_BITS 14
-
-static const uint16_t aanscales[64] = {
- /* precomputed values scaled up by 14 bits */
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
- 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
- 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
- 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
- 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
- 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446,
- 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247
-};
-
-static const uint8_t h263_chroma_roundtab[16] = {
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
-};
-
-#ifdef CONFIG_ENCODERS
-static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL;
-static uint8_t default_fcode_tab[MAX_MV*2+1];
-
-enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1};
-
-static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64],
- const uint16_t *quant_matrix, int bias, int qmin, int qmax)
-{
- int qscale;
-
- for(qscale=qmin; qscale<=qmax; qscale++){
- int i;
- if (s->dsp.fdct == ff_jpeg_fdct_islow) {
- for(i=0;i<64;i++) {
- const int j= s->dsp.idct_permutation[i];
- /* 16 <= qscale * quant_matrix[i] <= 7905 */
- /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
- /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
- /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
-
- qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) /
- (qscale * quant_matrix[j]));
- }
- } else if (s->dsp.fdct == fdct_ifast) {
- for(i=0;i<64;i++) {
- const int j= s->dsp.idct_permutation[i];
- /* 16 <= qscale * quant_matrix[i] <= 7905 */
- /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */
- /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */
- /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */
-
- qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) /
- (aanscales[i] * qscale * quant_matrix[j]));
- }
- } else {
- for(i=0;i<64;i++) {
- const int j= s->dsp.idct_permutation[i];
- /* We can safely suppose that 16 <= quant_matrix[i] <= 255
- So 16 <= qscale * quant_matrix[i] <= 7905
- so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905
- so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67
- */
- qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j]));
-// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]);
- qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]);
-
- if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1;
- qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]);
- }
- }
- }
-}
-#endif //CONFIG_ENCODERS
-
-void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){
- int i;
- int end;
-
- st->scantable= src_scantable;
-
- for(i=0; i<64; i++){
- int j;
- j = src_scantable[i];
- st->permutated[i] = permutation[j];
-#ifdef ARCH_POWERPC
- st->inverse[j] = i;
-#endif
- }
-
- end=-1;
- for(i=0; i<64; i++){
- int j;
- j = st->permutated[i];
- if(j>end) end=j;
- st->raster_end[i]= end;
- }
-}
-
-void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix){
- int i;
-
- if(matrix){
- put_bits(pb, 1, 1);
- for(i=0;i<64;i++) {
- put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
- }
- }else
- put_bits(pb, 1, 0);
-}
-
-/* init common dct for both encoder and decoder */
-int DCT_common_init(MpegEncContext *s)
-{
- s->dct_unquantize_h263 = dct_unquantize_h263_c;
- s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c;
- s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c;
-
-#ifdef CONFIG_ENCODERS
- s->dct_quantize= dct_quantize_c;
-#endif
-
-#ifdef HAVE_MMX
- MPV_common_init_mmx(s);
-#endif
-#ifdef ARCH_ALPHA
- MPV_common_init_axp(s);
-#endif
-#ifdef HAVE_MLIB
- MPV_common_init_mlib(s);
-#endif
-#ifdef HAVE_MMI
- MPV_common_init_mmi(s);
-#endif
-#ifdef ARCH_ARMV4L
- MPV_common_init_armv4l(s);
-#endif
-#ifdef ARCH_POWERPC
- MPV_common_init_ppc(s);
-#endif
-
-#ifdef CONFIG_ENCODERS
- s->fast_dct_quantize= s->dct_quantize;
-
- if(s->flags&CODEC_FLAG_TRELLIS_QUANT){
- s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_*
- }
-
-#endif //CONFIG_ENCODERS
-
- /* load & permutate scantables
- note: only wmv uses differnt ones
- */
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
-
- s->picture_structure= PICT_FRAME;
-
- return 0;
-}
-
-/**
- * allocates a Picture
- * The pixels are allocated/set by calling get_buffer() if shared=0
- */
-static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){
- const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11
- const int mb_array_size= s->mb_stride*s->mb_height;
- int i;
-
- if(shared){
- assert(pic->data[0]);
- assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED);
- pic->type= FF_BUFFER_TYPE_SHARED;
- }else{
- int r;
-
- assert(!pic->data[0]);
-
- r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
-
- if(r<0 || !pic->age || !pic->type || !pic->data[0]){
- fprintf(stderr, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]);
- return -1;
- }
-
- if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
- fprintf(stderr, "get_buffer() failed (stride changed)\n");
- return -1;
- }
-
- if(pic->linesize[1] != pic->linesize[2]){
- fprintf(stderr, "get_buffer() failed (uv stride missmatch)\n");
- return -1;
- }
-
- s->linesize = pic->linesize[0];
- s->uvlinesize= pic->linesize[1];
- }
-
- if(pic->qscale_table==NULL){
- if (s->encoding) {
- CHECKED_ALLOCZ(pic->mb_var , mb_array_size * sizeof(int16_t))
- CHECKED_ALLOCZ(pic->mc_mb_var, mb_array_size * sizeof(int16_t))
- CHECKED_ALLOCZ(pic->mb_mean , mb_array_size * sizeof(int8_t))
- CHECKED_ALLOCZ(pic->mb_cmp_score, mb_array_size * sizeof(int32_t))
- }
-
- CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check
- CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t))
- CHECKED_ALLOCZ(pic->mb_type_base , big_mb_num * sizeof(int))
- pic->mb_type= pic->mb_type_base + s->mb_stride+1;
- if(s->out_format == FMT_H264){
- for(i=0; i<2; i++){
- CHECKED_ALLOCZ(pic->motion_val[i], 2 * 16 * s->mb_num * sizeof(uint16_t))
- CHECKED_ALLOCZ(pic->ref_index[i] , 4 * s->mb_num * sizeof(uint8_t))
- }
- }
- pic->qstride= s->mb_stride;
- }
-
- //it might be nicer if the application would keep track of these but it would require a API change
- memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1);
- s->prev_pict_types[0]= s->pict_type;
- if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE)
- pic->age= INT_MAX; // skiped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway
-
- return 0;
-fail: //for the CHECKED_ALLOCZ macro
- return -1;
-}
-
-/**
- * deallocates a picture
- */
-static void free_picture(MpegEncContext *s, Picture *pic){
- int i;
-
- if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){
- s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
- }
-
- av_freep(&pic->mb_var);
- av_freep(&pic->mc_mb_var);
- av_freep(&pic->mb_mean);
- av_freep(&pic->mb_cmp_score);
- av_freep(&pic->mbskip_table);
- av_freep(&pic->qscale_table);
- av_freep(&pic->mb_type_base);
- pic->mb_type= NULL;
- for(i=0; i<2; i++){
- av_freep(&pic->motion_val[i]);
- av_freep(&pic->ref_index[i]);
- }
-
- if(pic->type == FF_BUFFER_TYPE_SHARED){
- for(i=0; i<4; i++){
- pic->base[i]=
- pic->data[i]= NULL;
- }
- pic->type= 0;
- }
-}
-
-/* init common structure for both encoder and decoder */
-int MPV_common_init(MpegEncContext *s)
-{
- int y_size, c_size, yc_size, i, mb_array_size, x, y;
-
- dsputil_init(&s->dsp, s->avctx);
- DCT_common_init(s);
-
- s->flags= s->avctx->flags;
-
- s->mb_width = (s->width + 15) / 16;
- s->mb_height = (s->height + 15) / 16;
- s->mb_stride = s->mb_width + 1;
- mb_array_size= s->mb_height * s->mb_stride;
-
- /* set default edge pos, will be overriden in decode_header if needed */
- s->h_edge_pos= s->mb_width*16;
- s->v_edge_pos= s->mb_height*16;
-
- s->mb_num = s->mb_width * s->mb_height;
-
- s->block_wrap[0]=
- s->block_wrap[1]=
- s->block_wrap[2]=
- s->block_wrap[3]= s->mb_width*2 + 2;
- s->block_wrap[4]=
- s->block_wrap[5]= s->mb_width + 2;
-
- y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
- c_size = (s->mb_width + 2) * (s->mb_height + 2);
- yc_size = y_size + 2 * c_size;
-
- /* convert fourcc to upper case */
- s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF)
- + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 )
- + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16)
- + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24);
-
- s->avctx->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF)
- + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 )
- + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16)
- + (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24);
-
- CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance
- s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17;
-
- s->avctx->coded_frame= (AVFrame*)&s->current_picture;
-
- CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;
- }
- }
- s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed?
-
- if (s->encoding) {
- int mv_table_size= s->mb_stride * (s->mb_height+2) + 1;
-
- /* Allocate MV tables */
- CHECKED_ALLOCZ(s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t))
- s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
- s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
- s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
- s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;
- s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;
- s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
-
- //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer()
- CHECKED_ALLOCZ(s->me.scratchpad, s->width*2*16*3*sizeof(uint8_t))
-
- CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t))
- CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t))
-
- if(s->codec_id==CODEC_ID_MPEG4){
- CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE);
- CHECKED_ALLOCZ( s->pb2_buffer, PB_BUFFER_SIZE);
- }
-
- if(s->msmpeg4_version){
- CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int));
- }
- CHECKED_ALLOCZ(s->avctx->stats_out, 256);
-
- /* Allocate MB type table */
- CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint8_t)) //needed for encoding
- }
-
- CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
-
- if (s->out_format == FMT_H263 || s->encoding) {
- int size;
-
- /* MV prediction */
- size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
- CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(int16_t));
- }
-
- if(s->codec_id==CODEC_ID_MPEG4){
- /* interlaced direct mode decoding tables */
- CHECKED_ALLOCZ(s->field_mv_table, mb_array_size*2*2 * sizeof(int16_t))
- CHECKED_ALLOCZ(s->field_select_table, mb_array_size*2* sizeof(int8_t))
- }
- if (s->out_format == FMT_H263) {
- /* ac values */
- CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16);
- s->ac_val[1] = s->ac_val[0] + y_size;
- s->ac_val[2] = s->ac_val[1] + c_size;
-
- /* cbp values */
- CHECKED_ALLOCZ(s->coded_block, y_size);
-
- /* divx501 bitstream reorder buffer */
- CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);
-
- /* cbp, ac_pred, pred_dir */
- CHECKED_ALLOCZ(s->cbp_table , mb_array_size * sizeof(uint8_t))
- CHECKED_ALLOCZ(s->pred_dir_table, mb_array_size * sizeof(uint8_t))
- }
-
- if (s->h263_pred || s->h263_plus || !s->encoding) {
- /* dc values */
- //MN: we need these for error resilience of intra-frames
- CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t));
- s->dc_val[1] = s->dc_val[0] + y_size;
- s->dc_val[2] = s->dc_val[1] + c_size;
- for(i=0;i<yc_size;i++)
- s->dc_val[0][i] = 1024;
- }
-
- /* which mb is a intra block */
- CHECKED_ALLOCZ(s->mbintra_table, mb_array_size);
- memset(s->mbintra_table, 1, mb_array_size);
-
- /* default structure is frame */
- s->picture_structure = PICT_FRAME;
-
- /* init macroblock skip table */
- CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2);
- //Note the +1 is for a quicker mpeg4 slice_end detection
- CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE);
-
- s->block= s->blocks[0];
-
- s->parse_context.state= -1;
-
- s->context_initialized = 1;
- return 0;
- fail:
- MPV_common_end(s);
- return -1;
-}
-
-
-//extern int sads;
-
-/* init common structure for both encoder and decoder */
-void MPV_common_end(MpegEncContext *s)
-{
- int i;
-
- av_freep(&s->parse_context.buffer);
- s->parse_context.buffer_size=0;
-
- av_freep(&s->mb_type);
- av_freep(&s->p_mv_table_base);
- av_freep(&s->b_forw_mv_table_base);
- av_freep(&s->b_back_mv_table_base);
- av_freep(&s->b_bidir_forw_mv_table_base);
- av_freep(&s->b_bidir_back_mv_table_base);
- av_freep(&s->b_direct_mv_table_base);
- s->p_mv_table= NULL;
- s->b_forw_mv_table= NULL;
- s->b_back_mv_table= NULL;
- s->b_bidir_forw_mv_table= NULL;
- s->b_bidir_back_mv_table= NULL;
- s->b_direct_mv_table= NULL;
-
- av_freep(&s->motion_val);
- av_freep(&s->dc_val[0]);
- av_freep(&s->ac_val[0]);
- av_freep(&s->coded_block);
- av_freep(&s->mbintra_table);
- av_freep(&s->cbp_table);
- av_freep(&s->pred_dir_table);
- av_freep(&s->me.scratchpad);
- av_freep(&s->me.map);
- av_freep(&s->me.score_map);
-
- av_freep(&s->mbskip_table);
- av_freep(&s->prev_pict_types);
- av_freep(&s->bitstream_buffer);
- av_freep(&s->tex_pb_buffer);
- av_freep(&s->pb2_buffer);
- av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL;
- av_freep(&s->field_mv_table);
- av_freep(&s->field_select_table);
- av_freep(&s->avctx->stats_out);
- av_freep(&s->ac_stats);
- av_freep(&s->error_status_table);
- av_freep(&s->mb_index2xy);
-
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- free_picture(s, &s->picture[i]);
- }
- avcodec_default_free_buffers(s->avctx);
- s->context_initialized = 0;
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* init video encoder */
-int MPV_encode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- int i, dummy;
- int chroma_h_shift, chroma_v_shift;
-
- avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME
-
- s->bit_rate = avctx->bit_rate;
- s->bit_rate_tolerance = avctx->bit_rate_tolerance;
- s->width = avctx->width;
- s->height = avctx->height;
- if(avctx->gop_size > 600){
- fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n");
- avctx->gop_size=600;
- }
- s->gop_size = avctx->gop_size;
- s->rtp_mode = avctx->rtp_mode;
- s->rtp_payload_size = avctx->rtp_payload_size;
- if (avctx->rtp_callback)
- s->rtp_callback = avctx->rtp_callback;
- s->max_qdiff= avctx->max_qdiff;
- s->qcompress= avctx->qcompress;
- s->qblur= avctx->qblur;
- s->avctx = avctx;
- s->flags= avctx->flags;
- s->max_b_frames= avctx->max_b_frames;
- s->b_frame_strategy= avctx->b_frame_strategy;
- s->codec_id= avctx->codec->id;
- s->luma_elim_threshold = avctx->luma_elim_threshold;
- s->chroma_elim_threshold= avctx->chroma_elim_threshold;
- s->strict_std_compliance= avctx->strict_std_compliance;
- s->data_partitioning= avctx->flags & CODEC_FLAG_PART;
- s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0;
- s->mpeg_quant= avctx->mpeg_quant;
-
- if (s->gop_size <= 1) {
- s->intra_only = 1;
- s->gop_size = 12;
- } else {
- s->intra_only = 0;
- }
-
- s->me_method = avctx->me_method;
-
- /* Fixed QSCALE */
- s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE);
-
- s->adaptive_quant= ( s->avctx->lumi_masking
- || s->avctx->dark_masking
- || s->avctx->temporal_cplx_masking
- || s->avctx->spatial_cplx_masking
- || s->avctx->p_masking)
- && !s->fixed_qscale;
-
- s->progressive_sequence= !(avctx->flags & CODEC_FLAG_INTERLACED_DCT);
-
- if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4){
- fprintf(stderr, "4MV not supporetd by codec\n");
- return -1;
- }
-
- if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){
- fprintf(stderr, "qpel not supporetd by codec\n");
- return -1;
- }
-
- if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){
- fprintf(stderr, "data partitioning not supporetd by codec\n");
- return -1;
- }
-
- if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){
- fprintf(stderr, "b frames not supporetd by codec\n");
- return -1;
- }
-
- if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too
- fprintf(stderr, "mpeg2 style quantization not supporetd by codec\n");
- return -1;
- }
-
- if(s->codec_id==CODEC_ID_MJPEG){
- s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x
- s->inter_quant_bias= 0;
- }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){
- s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x
- s->inter_quant_bias= 0;
- }else{
- s->intra_quant_bias=0;
- s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x
- }
-
- if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
- s->intra_quant_bias= avctx->intra_quant_bias;
- if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS)
- s->inter_quant_bias= avctx->inter_quant_bias;
-
- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift);
-
- av_reduce(&s->time_increment_resolution, &dummy, s->avctx->frame_rate, s->avctx->frame_rate_base, (1<<16)-1);
- s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1;
-
- switch(avctx->codec->id) {
- case CODEC_ID_MPEG1VIDEO:
- s->out_format = FMT_MPEG1;
- s->low_delay= 0; //s->max_b_frames ? 0 : 1;
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- break;
- case CODEC_ID_MPEG2VIDEO:
- s->out_format = FMT_MPEG1;
- s->low_delay= 0; //s->max_b_frames ? 0 : 1;
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- s->rtp_mode= 1; // mpeg2 must have slices
- if(s->rtp_payload_size == 0) s->rtp_payload_size= 256*256*256;
- break;
- case CODEC_ID_LJPEG:
- case CODEC_ID_MJPEG:
- s->out_format = FMT_MJPEG;
- s->intra_only = 1; /* force intra only for jpeg */
- s->mjpeg_write_tables = 1; /* write all tables */
- s->mjpeg_data_only_frames = 0; /* write all the needed headers */
- s->mjpeg_vsample[0] = 1<<chroma_v_shift;
- s->mjpeg_vsample[1] = 1;
- s->mjpeg_vsample[2] = 1;
- s->mjpeg_hsample[0] = 1<<chroma_h_shift;
- s->mjpeg_hsample[1] = 1;
- s->mjpeg_hsample[2] = 1;
- if (mjpeg_init(s) < 0)
- return -1;
- avctx->delay=0;
- s->low_delay=1;
- break;
-#ifdef CONFIG_RISKY
- case CODEC_ID_H263:
- if (h263_get_picture_format(s->width, s->height) == 7) {
- printf("Input picture size isn't suitable for h263 codec! try h263+\n");
- return -1;
- }
- s->out_format = FMT_H263;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_H263P:
- s->out_format = FMT_H263;
- s->h263_plus = 1;
- /* Fx */
- s->unrestricted_mv=(avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0;
- s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0;
- /* /Fx */
- /* These are just to be sure */
- s->umvplus = 1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_FLV1:
- s->out_format = FMT_H263;
- s->h263_flv = 2; /* format = 1; 11-bit codes */
- s->unrestricted_mv = 1;
- s->rtp_mode=0; /* don't allow GOB */
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_RV10:
- s->out_format = FMT_H263;
- s->h263_rv10 = 1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_MPEG4:
- s->out_format = FMT_H263;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->low_delay= s->max_b_frames ? 0 : 1;
- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1);
- break;
- case CODEC_ID_MSMPEG4V1:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_MSMPEG4V2:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 2;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_MSMPEG4V3:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 3;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_WMV1:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 4;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
- case CODEC_ID_WMV2:
- s->out_format = FMT_H263;
- s->h263_msmpeg4 = 1;
- s->h263_pred = 1;
- s->unrestricted_mv = 1;
- s->msmpeg4_version= 5;
- s->flipflop_rounding=1;
- avctx->delay=0;
- s->low_delay=1;
- break;
-#endif
- default:
- return -1;
- }
-
- { /* set up some save defaults, some codecs might override them later */
- static int done=0;
- if(!done){
- int i;
- done=1;
-
- default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) );
- memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1));
- memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1));
-
- for(i=-16; i<16; i++){
- default_fcode_tab[i + MAX_MV]= 1;
- }
- }
- }
- s->me.mv_penalty= default_mv_penalty;
- s->fcode_tab= default_fcode_tab;
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
-
- /* dont use mv_penalty table for crap MV as it would be confused */
- //FIXME remove after fixing / removing old ME
- if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty;
-
- s->encoding = 1;
-
- /* init */
- if (MPV_common_init(s) < 0)
- return -1;
-
- ff_init_me(s);
-
-#ifdef CONFIG_ENCODERS
-#ifdef CONFIG_RISKY
- if (s->out_format == FMT_H263)
- h263_encode_init(s);
- if(s->msmpeg4_version)
- ff_msmpeg4_encode_init(s);
-#endif
- if (s->out_format == FMT_MPEG1)
- ff_mpeg1_encode_init(s);
-#endif
-
- /* init default q matrix */
- for(i=0;i<64;i++) {
- int j= s->dsp.idct_permutation[i];
-#ifdef CONFIG_RISKY
- if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){
- s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
- s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
- }else if(s->out_format == FMT_H263){
- s->intra_matrix[j] =
- s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }else
-#endif
- { /* mpeg1/2 */
- s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
- s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
- }
- if(s->avctx->intra_matrix)
- s->intra_matrix[j] = s->avctx->intra_matrix[i];
- if(s->avctx->inter_matrix)
- s->inter_matrix[j] = s->avctx->inter_matrix[i];
- }
-
- /* precompute matrix */
- /* for mjpeg, we do include qscale in the matrix */
- if (s->out_format != FMT_MJPEG) {
- convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias,
- s->intra_matrix, s->intra_quant_bias, 1, 31);
- convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias,
- s->inter_matrix, s->inter_quant_bias, 1, 31);
- }
-
- if(ff_rate_control_init(s) < 0)
- return -1;
-
- s->picture_number = 0;
- s->picture_in_gop_number = 0;
- s->fake_picture_number = 0;
- /* motion detector init */
- s->f_code = 1;
- s->b_code = 1;
-
- return 0;
-}
-
-int MPV_encode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
-#ifdef STATS
- print_stats();
-#endif
-
- ff_rate_control_uninit(s);
-
- MPV_common_end(s);
- if (s->out_format == FMT_MJPEG)
- mjpeg_close(s);
-
- av_freep(&avctx->extradata);
-
- return 0;
-}
-
-#endif //CONFIG_ENCODERS
-
-void init_rl(RLTable *rl)
-{
- int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1];
- uint8_t index_run[MAX_RUN+1];
- int last, run, level, start, end, i;
-
- /* compute max_level[], max_run[] and index_run[] */
- for(last=0;last<2;last++) {
- if (last == 0) {
- start = 0;
- end = rl->last;
- } else {
- start = rl->last;
- end = rl->n;
- }
-
- memset(max_level, 0, MAX_RUN + 1);
- memset(max_run, 0, MAX_LEVEL + 1);
- memset(index_run, rl->n, MAX_RUN + 1);
- for(i=start;i<end;i++) {
- run = rl->table_run[i];
- level = rl->table_level[i];
- if (index_run[run] == rl->n)
- index_run[run] = i;
- if (level > max_level[run])
- max_level[run] = level;
- if (run > max_run[level])
- max_run[level] = run;
- }
- rl->max_level[last] = av_malloc(MAX_RUN + 1);
- memcpy(rl->max_level[last], max_level, MAX_RUN + 1);
- rl->max_run[last] = av_malloc(MAX_LEVEL + 1);
- memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1);
- rl->index_run[last] = av_malloc(MAX_RUN + 1);
- memcpy(rl->index_run[last], index_run, MAX_RUN + 1);
- }
-}
-
-/* draw the edges of width 'w' of an image of size width, height */
-//FIXME check that this is ok for mpeg4 interlaced
-static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
-{
- uint8_t *ptr, *last_line;
- int i;
-
- last_line = buf + (height - 1) * wrap;
- for(i=0;i<w;i++) {
- /* top and bottom */
- memcpy(buf - (i + 1) * wrap, buf, width);
- memcpy(last_line + (i + 1) * wrap, last_line, width);
- }
- /* left and right */
- ptr = buf;
- for(i=0;i<height;i++) {
- memset(ptr - w, ptr[0], w);
- memset(ptr + width, ptr[width-1], w);
- ptr += wrap;
- }
- /* corners */
- for(i=0;i<w;i++) {
- memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
- memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
- memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
- memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
- }
-}
-
-static int find_unused_picture(MpegEncContext *s, int shared){
- int i;
-
- if(shared){
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type==0) break;
- }
- }else{
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) break; //FIXME
- }
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0]==NULL) break;
- }
- }
-
- assert(i<MAX_PICTURE_COUNT);
- return i;
-}
-
-/* generic function for encode/decode called before a frame is coded/decoded */
-int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
-{
- int i;
- AVFrame *pic;
-
- s->mb_skiped = 0;
-
- assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3);
-
- /* mark&release old frames */
- if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr->data[0]) {
- avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr);
-
- /* release forgotten pictures */
- /* if(mpeg124/h263) */
- if(!s->encoding){
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){
- fprintf(stderr, "releasing zombie picture\n");
- avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
- }
- }
- }
- }
-alloc:
- if(!s->encoding){
- /* release non refernce frames */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
- s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
- }
- }
-
- i= find_unused_picture(s, 0);
-
- pic= (AVFrame*)&s->picture[i];
- pic->reference= s->pict_type != B_TYPE ? 3 : 0;
-
- if(s->current_picture_ptr)
- pic->coded_picture_number= s->current_picture_ptr->coded_picture_number+1;
-
- if( alloc_picture(s, (Picture*)pic, 0) < 0)
- return -1;
-
- s->current_picture_ptr= &s->picture[i];
- }
-
- s->current_picture_ptr->pict_type= s->pict_type;
- s->current_picture_ptr->quality= s->qscale;
- s->current_picture_ptr->key_frame= s->pict_type == I_TYPE;
-
- s->current_picture= *s->current_picture_ptr;
-
- if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){
- if (s->pict_type != B_TYPE) {
- s->last_picture_ptr= s->next_picture_ptr;
- s->next_picture_ptr= s->current_picture_ptr;
- }
-
- if(s->last_picture_ptr) s->last_picture= *s->last_picture_ptr;
- if(s->next_picture_ptr) s->next_picture= *s->next_picture_ptr;
- if(s->new_picture_ptr ) s->new_picture = *s->new_picture_ptr;
-
- if(s->pict_type != I_TYPE && s->last_picture_ptr==NULL){
- fprintf(stderr, "warning: first frame is no keyframe\n");
- assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference
- goto alloc;
- }
-
- assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0]));
-
- if(s->picture_structure!=PICT_FRAME){
- int i;
- for(i=0; i<4; i++){
- if(s->picture_structure == PICT_BOTTOM_FIELD){
- s->current_picture.data[i] += s->current_picture.linesize[i];
- }
- s->current_picture.linesize[i] *= 2;
- s->last_picture.linesize[i] *=2;
- s->next_picture.linesize[i] *=2;
- }
- }
- }
-
- s->hurry_up= s->avctx->hurry_up;
- s->error_resilience= avctx->error_resilience;
-
- /* set dequantizer, we cant do it during init as it might change for mpeg4
- and we cant do it in the header decode as init isnt called for mpeg4 there yet */
- if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO)
- s->dct_unquantize = s->dct_unquantize_mpeg2;
- else if(s->out_format == FMT_H263)
- s->dct_unquantize = s->dct_unquantize_h263;
- else
- s->dct_unquantize = s->dct_unquantize_mpeg1;
-
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration)
- return XVMC_field_start(s, avctx);
-#endif
- return 0;
-}
-
-/* generic function for encode/decode called after a frame has been coded/decoded */
-void MPV_frame_end(MpegEncContext *s)
-{
- int i;
- /* draw edge for correct motion prediction if outside */
-#ifdef HAVE_XVMC
-//just to make sure that all data is rendered.
- if(s->avctx->xvmc_acceleration){
- XVMC_field_end(s);
- }else
-#endif
- if(s->codec_id!=CODEC_ID_SVQ1 && s->out_format != FMT_MPEG1){
- if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
- draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH );
- draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
- draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2);
- }
- }
- emms_c();
-
- s->last_pict_type = s->pict_type;
- if(s->pict_type!=B_TYPE){
- s->last_non_b_pict_type= s->pict_type;
- }
-#if 0
- /* copy back current_picture variables */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] == s->current_picture.data[0]){
- s->picture[i]= s->current_picture;
- break;
- }
- }
- assert(i<MAX_PICTURE_COUNT);
-#endif
-
- if(s->encoding){
- /* release non refernce frames */
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){
- s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]);
- }
- }
- }
- // clear copies, to avoid confusion
-#if 0
- memset(&s->last_picture, 0, sizeof(Picture));
- memset(&s->next_picture, 0, sizeof(Picture));
- memset(&s->current_picture, 0, sizeof(Picture));
-#endif
-}
-
-/**
- * draws an line from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
- int t, x, y, f;
-
- sx= clip(sx, 0, w-1);
- sy= clip(sy, 0, h-1);
- ex= clip(ex, 0, w-1);
- ey= clip(ey, 0, h-1);
-
- buf[sy*stride + sx]+= color;
-
- if(ABS(ex - sx) > ABS(ey - sy)){
- if(sx > ex){
- t=sx; sx=ex; ex=t;
- t=sy; sy=ey; ey=t;
- }
- buf+= sx + sy*stride;
- ex-= sx;
- f= ((ey-sy)<<16)/ex;
- for(x= 0; x <= ex; x++){
- y= ((x*f) + (1<<15))>>16;
- buf[y*stride + x]+= color;
- }
- }else{
- if(sy > ey){
- t=sx; sx=ex; ex=t;
- t=sy; sy=ey; ey=t;
- }
- buf+= sx + sy*stride;
- ey-= sy;
- if(ey) f= ((ex-sx)<<16)/ey;
- else f= 0;
- for(y= 0; y <= ey; y++){
- x= ((y*f) + (1<<15))>>16;
- buf[y*stride + x]+= color;
- }
- }
-}
-
-/**
- * draws an arrow from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){
- int dx,dy;
-
- sx= clip(sx, -100, w+100);
- sy= clip(sy, -100, h+100);
- ex= clip(ex, -100, w+100);
- ey= clip(ey, -100, h+100);
-
- dx= ex - sx;
- dy= ey - sy;
-
- if(dx*dx + dy*dy > 3*3){
- int rx= dx + dy;
- int ry= -dx + dy;
- int length= ff_sqrt((rx*rx + ry*ry)<<8);
-
- //FIXME subpixel accuracy
- rx= ROUNDED_DIV(rx*3<<4, length);
- ry= ROUNDED_DIV(ry*3<<4, length);
-
- draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
- draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
- }
- draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
-}
-
-/**
- * prints debuging info for the given picture.
- */
-void ff_print_debug_info(MpegEncContext *s, Picture *pict){
-
- if(!pict || !pict->mb_type) return;
-
- if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){
- int x,y;
-
- for(y=0; y<s->mb_height; y++){
- for(x=0; x<s->mb_width; x++){
- if(s->avctx->debug&FF_DEBUG_SKIP){
- int count= s->mbskip_table[x + y*s->mb_stride];
- if(count>9) count=9;
- printf("%1d", count);
- }
- if(s->avctx->debug&FF_DEBUG_QP){
- printf("%2d", pict->qscale_table[x + y*s->mb_stride]);
- }
- if(s->avctx->debug&FF_DEBUG_MB_TYPE){
- int mb_type= pict->mb_type[x + y*s->mb_stride];
-
- //Type & MV direction
- if(IS_PCM(mb_type))
- printf("P");
- else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type))
- printf("A");
- else if(IS_INTRA4x4(mb_type))
- printf("i");
- else if(IS_INTRA16x16(mb_type))
- printf("I");
- else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type))
- printf("d");
- else if(IS_DIRECT(mb_type))
- printf("D");
- else if(IS_GMC(mb_type) && IS_SKIP(mb_type))
- printf("g");
- else if(IS_GMC(mb_type))
- printf("G");
- else if(IS_SKIP(mb_type))
- printf("S");
- else if(!USES_LIST(mb_type, 1))
- printf(">");
- else if(!USES_LIST(mb_type, 0))
- printf("<");
- else{
- assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
- printf("X");
- }
-
- //segmentation
- if(IS_8X8(mb_type))
- printf("+");
- else if(IS_16X8(mb_type))
- printf("-");
- else if(IS_8X16(mb_type))
- printf("¦");
- else if(IS_INTRA(mb_type) || IS_16X16(mb_type))
- printf(" ");
- else
- printf("?");
-
-
- if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264)
- printf("=");
- else
- printf(" ");
- }
-// printf(" ");
- }
- printf("\n");
- }
- }
-
- if((s->avctx->debug&FF_DEBUG_VIS_MV) && s->motion_val){
- const int shift= 1 + s->quarter_sample;
- int mb_y;
- uint8_t *ptr= pict->data[0];
- s->low_delay=0; //needed to see the vectors without trashing the buffers
-
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- int mb_x;
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- const int mb_index= mb_x + mb_y*s->mb_stride;
- if(IS_8X8(s->current_picture.mb_type[mb_index])){
- int i;
- for(i=0; i<4; i++){
- int sx= mb_x*16 + 4 + 8*(i&1);
- int sy= mb_y*16 + 4 + 8*(i>>1);
- int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2);
- int mx= (s->motion_val[xy][0]>>shift) + sx;
- int my= (s->motion_val[xy][1]>>shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
- }
- }else{
- int sx= mb_x*16 + 8;
- int sy= mb_y*16 + 8;
- int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
- int mx= (s->motion_val[xy][0]>>shift) + sx;
- int my= (s->motion_val[xy][1]>>shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
- }
- s->mbskip_table[mb_index]=0;
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-static int get_sae(uint8_t *src, int ref, int stride){
- int x,y;
- int acc=0;
-
- for(y=0; y<16; y++){
- for(x=0; x<16; x++){
- acc+= ABS(src[x+y*stride] - ref);
- }
- }
-
- return acc;
-}
-
-static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){
- int x, y, w, h;
- int acc=0;
-
- w= s->width &~15;
- h= s->height&~15;
-
- for(y=0; y<h; y+=16){
- for(x=0; x<w; x+=16){
- int offset= x + y*stride;
- int sad = s->dsp.pix_abs16x16(src + offset, ref + offset, stride);
- int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8;
- int sae = get_sae(src + offset, mean, stride);
-
- acc+= sae + 500 < sad;
- }
- }
- return acc;
-}
-
-
-static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){
- AVFrame *pic=NULL;
- int i;
- const int encoding_delay= s->max_b_frames;
- int direct=1;
-
- if(pic_arg){
- if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0;
- if(pic_arg->linesize[0] != s->linesize) direct=0;
- if(pic_arg->linesize[1] != s->uvlinesize) direct=0;
- if(pic_arg->linesize[2] != s->uvlinesize) direct=0;
-
-// printf("%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize);
-
- if(direct){
- i= find_unused_picture(s, 1);
-
- pic= (AVFrame*)&s->picture[i];
- pic->reference= 3;
-
- for(i=0; i<4; i++){
- pic->data[i]= pic_arg->data[i];
- pic->linesize[i]= pic_arg->linesize[i];
- }
- alloc_picture(s, (Picture*)pic, 1);
- }else{
- i= find_unused_picture(s, 0);
-
- pic= (AVFrame*)&s->picture[i];
- pic->reference= 3;
-
- alloc_picture(s, (Picture*)pic, 0);
- for(i=0; i<4; i++){
- /* the input will be 16 pixels to the right relative to the actual buffer start
- * and the current_pic, so the buffer can be reused, yes its not beatifull
- */
- pic->data[i]+= 16;
- }
-
- if( pic->data[0] == pic_arg->data[0]
- && pic->data[1] == pic_arg->data[1]
- && pic->data[2] == pic_arg->data[2]){
- // empty
- }else{
- int h_chroma_shift, v_chroma_shift;
- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
-
- for(i=0; i<3; i++){
- int src_stride= pic_arg->linesize[i];
- int dst_stride= i ? s->uvlinesize : s->linesize;
- int h_shift= i ? h_chroma_shift : 0;
- int v_shift= i ? v_chroma_shift : 0;
- int w= s->width >>h_shift;
- int h= s->height>>v_shift;
- uint8_t *src= pic_arg->data[i];
- uint8_t *dst= pic->data[i];
-
- if(src_stride==dst_stride)
- memcpy(dst, src, src_stride*h);
- else{
- while(h--){
- memcpy(dst, src, w);
- dst += dst_stride;
- src += src_stride;
- }
- }
- }
- }
- }
- pic->quality= pic_arg->quality;
- pic->pict_type= pic_arg->pict_type;
- pic->pts = pic_arg->pts;
-
- if(s->input_picture[encoding_delay])
- pic->display_picture_number= s->input_picture[encoding_delay]->display_picture_number + 1;
-
- }
-
- /* shift buffer entries */
- for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++)
- s->input_picture[i-1]= s->input_picture[i];
-
- s->input_picture[encoding_delay]= (Picture*)pic;
-
- return 0;
-}
-
-static void select_input_picture(MpegEncContext *s){
- int i;
- int coded_pic_num=0;
-
- if(s->reordered_input_picture[0])
- coded_pic_num= s->reordered_input_picture[0]->coded_picture_number + 1;
-
- for(i=1; i<MAX_PICTURE_COUNT; i++)
- s->reordered_input_picture[i-1]= s->reordered_input_picture[i];
- s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL;
-
- /* set next picture types & ordering */
- if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){
- if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){
- s->reordered_input_picture[0]= s->input_picture[0];
- s->reordered_input_picture[0]->pict_type= I_TYPE;
- s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;
- }else{
- int b_frames;
-
- if(s->flags&CODEC_FLAG_PASS2){
- for(i=0; i<s->max_b_frames+1; i++){
- int pict_num= s->input_picture[0]->display_picture_number + i;
- int pict_type= s->rc_context.entry[pict_num].new_pict_type;
- s->input_picture[i]->pict_type= pict_type;
-
- if(i + 1 >= s->rc_context.num_entries) break;
- }
- }
-
- if(s->input_picture[0]->pict_type){
- /* user selected pict_type */
- for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){
- if(s->input_picture[b_frames]->pict_type!=B_TYPE) break;
- }
-
- if(b_frames > s->max_b_frames){
- fprintf(stderr, "warning, too many bframes in a row\n");
- b_frames = s->max_b_frames;
- }
- }else if(s->b_frame_strategy==0){
- b_frames= s->max_b_frames;
- while(b_frames && !s->input_picture[b_frames]) b_frames--;
- }else if(s->b_frame_strategy==1){
- for(i=1; i<s->max_b_frames+1; i++){
- if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){
- s->input_picture[i]->b_frame_score=
- get_intra_count(s, s->input_picture[i ]->data[0],
- s->input_picture[i-1]->data[0], s->linesize) + 1;
- }
- }
- for(i=0; i<s->max_b_frames; i++){
- if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break;
- }
-
- b_frames= FFMAX(0, i-1);
-
- /* reset scores */
- for(i=0; i<b_frames+1; i++){
- s->input_picture[i]->b_frame_score=0;
- }
- }else{
- fprintf(stderr, "illegal b frame strategy\n");
- b_frames=0;
- }
-
- emms_c();
-//static int b_count=0;
-//b_count+= b_frames;
-//printf("b_frames: %d\n", b_count);
-
- s->reordered_input_picture[0]= s->input_picture[b_frames];
- if( s->picture_in_gop_number + b_frames >= s->gop_size
- || s->reordered_input_picture[0]->pict_type== I_TYPE)
- s->reordered_input_picture[0]->pict_type= I_TYPE;
- else
- s->reordered_input_picture[0]->pict_type= P_TYPE;
- s->reordered_input_picture[0]->coded_picture_number= coded_pic_num;
- for(i=0; i<b_frames; i++){
- coded_pic_num++;
- s->reordered_input_picture[i+1]= s->input_picture[i];
- s->reordered_input_picture[i+1]->pict_type= B_TYPE;
- s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num;
- }
- }
- }
-
- if(s->reordered_input_picture[0]){
- s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0;
-
- s->new_picture= *s->reordered_input_picture[0];
-
- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED){
- // input is a shared pix, so we cant modifiy it -> alloc a new one & ensure that the shared one is reuseable
-
- int i= find_unused_picture(s, 0);
- Picture *pic= &s->picture[i];
-
- /* mark us unused / free shared pic */
- for(i=0; i<4; i++)
- s->reordered_input_picture[0]->data[i]= NULL;
- s->reordered_input_picture[0]->type= 0;
-
- //FIXME bad, copy * except
- pic->pict_type = s->reordered_input_picture[0]->pict_type;
- pic->quality = s->reordered_input_picture[0]->quality;
- pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number;
- pic->reference = s->reordered_input_picture[0]->reference;
- pic->pts = s->reordered_input_picture[0]->pts;
-
- alloc_picture(s, pic, 0);
-
- s->current_picture_ptr= pic;
- }else{
- // input is not a shared pix -> reuse buffer for current_pix
-
- assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER
- || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL);
-
- s->current_picture_ptr= s->reordered_input_picture[0];
- for(i=0; i<4; i++){
- //reverse the +16 we did before storing the input
- s->current_picture_ptr->data[i]-=16;
- }
- }
- s->current_picture= *s->current_picture_ptr;
-
- s->picture_number= s->new_picture.display_picture_number;
-//printf("dpn:%d\n", s->picture_number);
- }else{
- memset(&s->new_picture, 0, sizeof(Picture));
- }
-}
-
-int MPV_encode_picture(AVCodecContext *avctx,
- unsigned char *buf, int buf_size, void *data)
-{
- MpegEncContext *s = avctx->priv_data;
- AVFrame *pic_arg = data;
- int i;
-
- if(avctx->pix_fmt != PIX_FMT_YUV420P){
- fprintf(stderr, "this codec supports only YUV420P\n");
- return -1;
- }
-
- init_put_bits(&s->pb, buf, buf_size, NULL, NULL);
-
- s->picture_in_gop_number++;
-
- load_input_picture(s, pic_arg);
-
- select_input_picture(s);
-
- /* output? */
- if(s->new_picture.data[0]){
-
- s->pict_type= s->new_picture.pict_type;
- if (s->fixed_qscale){ /* the ratecontrol needs the last qscale so we dont touch it for CBR */
- s->qscale= (int)(s->new_picture.quality+0.5);
- assert(s->qscale);
- }
-//emms_c();
-//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale);
- MPV_frame_start(s, avctx);
-
- encode_picture(s, s->picture_number);
-
- avctx->real_pict_num = s->picture_number;
- avctx->header_bits = s->header_bits;
- avctx->mv_bits = s->mv_bits;
- avctx->misc_bits = s->misc_bits;
- avctx->i_tex_bits = s->i_tex_bits;
- avctx->p_tex_bits = s->p_tex_bits;
- avctx->i_count = s->i_count;
- avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx
- avctx->skip_count = s->skip_count;
-
- MPV_frame_end(s);
-
- if (s->out_format == FMT_MJPEG)
- mjpeg_picture_trailer(s);
-
- if(s->flags&CODEC_FLAG_PASS1)
- ff_write_pass1_stats(s);
-
- for(i=0; i<4; i++){
- avctx->error[i] += s->current_picture_ptr->error[i];
- }
- }
-
- s->input_picture_number++;
-
- flush_put_bits(&s->pb);
- s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8;
-
- s->total_bits += s->frame_bits;
- avctx->frame_bits = s->frame_bits;
-
- return pbBufPtr(&s->pb) - s->pb.buf;
-}
-
-#endif //CONFIG_ENCODERS
-
-static inline void gmc1_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dest_offset,
- uint8_t **ref_picture, int src_offset)
-{
- uint8_t *ptr;
- int offset, src_x, src_y, linesize, uvlinesize;
- int motion_x, motion_y;
- int emu=0;
-
- motion_x= s->sprite_offset[0][0];
- motion_y= s->sprite_offset[0][1];
- src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1));
- src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1));
- motion_x<<=(3-s->sprite_warping_accuracy);
- motion_y<<=(3-s->sprite_warping_accuracy);
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- motion_x =0;
- src_y = clip(src_y, -16, s->height);
- if (src_y == s->height)
- motion_y =0;
-
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
-
- ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset;
-
- dest_y+=dest_offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + 17 >= s->h_edge_pos
- || src_y + 17 >= s->v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer;
- }
- }
-
- if((motion_x|motion_y)&7){
- s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
- s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding);
- }else{
- int dxy;
-
- dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
- if (s->no_rounding){
- s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
- }else{
- s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16);
- }
- }
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- motion_x= s->sprite_offset[1][0];
- motion_y= s->sprite_offset[1][1];
- src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1));
- src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1));
- motion_x<<=(3-s->sprite_warping_accuracy);
- motion_y<<=(3-s->sprite_warping_accuracy);
- src_x = clip(src_x, -8, s->width>>1);
- if (src_x == s->width>>1)
- motion_x =0;
- src_y = clip(src_y, -8, s->height>>1);
- if (src_y == s->height>>1)
- motion_y =0;
-
- offset = (src_y * uvlinesize) + src_x + (src_offset>>1);
- ptr = ref_picture[1] + offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + 9 >= s->h_edge_pos>>1
- || src_y + 9 >= s->v_edge_pos>>1){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- emu=1;
- }
- }
- s->dsp.gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- s->dsp.gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
-
- return;
-}
-
-static inline void gmc_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dest_offset,
- uint8_t **ref_picture, int src_offset)
-{
- uint8_t *ptr;
- int linesize, uvlinesize;
- const int a= s->sprite_warping_accuracy;
- int ox, oy;
-
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
-
- ptr = ref_picture[0] + src_offset;
-
- dest_y+=dest_offset;
-
- ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16;
- oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16;
-
- s->dsp.gmc(dest_y, ptr, linesize, 16,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos, s->v_edge_pos);
- s->dsp.gmc(dest_y+8, ptr, linesize, 16,
- ox + s->sprite_delta[0][0]*8,
- oy + s->sprite_delta[1][0]*8,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos, s->v_edge_pos);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
-
- dest_cb+=dest_offset>>1;
- dest_cr+=dest_offset>>1;
-
- ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
- oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
-
- ptr = ref_picture[1] + (src_offset>>1);
- s->dsp.gmc(dest_cb, ptr, uvlinesize, 8,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos>>1, s->v_edge_pos>>1);
-
- ptr = ref_picture[2] + (src_offset>>1);
- s->dsp.gmc(dest_cr, ptr, uvlinesize, 8,
- ox,
- oy,
- s->sprite_delta[0][0], s->sprite_delta[0][1],
- s->sprite_delta[1][0], s->sprite_delta[1][1],
- a+1, (1<<(2*a+1)) - s->no_rounding,
- s->h_edge_pos>>1, s->v_edge_pos>>1);
-}
-
-/**
- * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples.
- * @param buf destination buffer
- * @param src source buffer
- * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers
- * @param block_w width of block
- * @param block_h height of block
- * @param src_x x coordinate of the top left sample of the block in the source buffer
- * @param src_y y coordinate of the top left sample of the block in the source buffer
- * @param w width of the source buffer
- * @param h height of the source buffer
- */
-void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
- int src_x, int src_y, int w, int h){
- int x, y;
- int start_y, start_x, end_y, end_x;
-
- if(src_y>= h){
- src+= (h-1-src_y)*linesize;
- src_y=h-1;
- }else if(src_y<=-block_h){
- src+= (1-block_h-src_y)*linesize;
- src_y=1-block_h;
- }
- if(src_x>= w){
- src+= (w-1-src_x);
- src_x=w-1;
- }else if(src_x<=-block_w){
- src+= (1-block_w-src_x);
- src_x=1-block_w;
- }
-
- start_y= FFMAX(0, -src_y);
- start_x= FFMAX(0, -src_x);
- end_y= FFMIN(block_h, h-src_y);
- end_x= FFMIN(block_w, w-src_x);
-
- // copy existing part
- for(y=start_y; y<end_y; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= src[x + y*linesize];
- }
- }
-
- //top
- for(y=0; y<start_y; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= buf[x + start_y*linesize];
- }
- }
-
- //bottom
- for(y=end_y; y<block_h; y++){
- for(x=start_x; x<end_x; x++){
- buf[x + y*linesize]= buf[x + (end_y-1)*linesize];
- }
- }
-
- for(y=0; y<block_h; y++){
- //left
- for(x=0; x<start_x; x++){
- buf[x + y*linesize]= buf[start_x + y*linesize];
- }
-
- //right
- for(x=end_x; x<block_w; x++){
- buf[x + y*linesize]= buf[end_x - 1 + y*linesize];
- }
- }
-}
-
-
-/* apply one mpeg motion vector to the three components */
-static inline void mpeg_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dest_offset,
- uint8_t **ref_picture, int src_offset,
- int field_based, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h)
-{
- uint8_t *ptr;
- int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
- int emu=0;
-#if 0
-if(s->quarter_sample)
-{
- motion_x>>=1;
- motion_y>>=1;
-}
-#endif
- dxy = ((motion_y & 1) << 1) | (motion_x & 1);
- src_x = s->mb_x * 16 + (motion_x >> 1);
- src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1);
-
- /* WARNING: do no forget half pels */
- height = s->height >> field_based;
- v_edge_pos = s->v_edge_pos >> field_based;
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- dxy &= ~1;
- src_y = clip(src_y, -16, height);
- if (src_y == height)
- dxy &= ~2;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
- ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset;
- dest_y += dest_offset;
-
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->h_edge_pos
- || src_y + (motion_y&1) + h > v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - src_offset, s->linesize, 17, 17+field_based, //FIXME linesize? and uv below
- src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer + src_offset;
- emu=1;
- }
- }
- pix_op[0][dxy](dest_y, ptr, linesize, h);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if (s->out_format == FMT_H263) {
- dxy = 0;
- if ((motion_x & 3) != 0)
- dxy |= 1;
- if ((motion_y & 3) != 0)
- dxy |= 2;
- mx = motion_x >> 2;
- my = motion_y >> 2;
- } else {
- mx = motion_x / 2;
- my = motion_y / 2;
- dxy = ((my & 1) << 1) | (mx & 1);
- mx >>= 1;
- my >>= 1;
- }
-
- src_x = s->mb_x * 8 + mx;
- src_y = s->mb_y * (8 >> field_based) + my;
- src_x = clip(src_x, -8, s->width >> 1);
- if (src_x == (s->width >> 1))
- dxy &= ~1;
- src_y = clip(src_y, -8, height >> 1);
- if (src_y == (height >> 1))
- dxy &= ~2;
- offset = (src_y * uvlinesize) + src_x + (src_offset >> 1);
- ptr = ref_picture[1] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based,
- src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer + (src_offset >> 1);
- }
- pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based,
- src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer + (src_offset >> 1);
- }
- pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
-}
-
-static inline void qpel_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dest_offset,
- uint8_t **ref_picture, int src_offset,
- int field_based, op_pixels_func (*pix_op)[4],
- qpel_mc_func (*qpix_op)[16],
- int motion_x, int motion_y, int h)
-{
- uint8_t *ptr;
- int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize;
- int emu=0;
-
- dxy = ((motion_y & 3) << 2) | (motion_x & 3);
- src_x = s->mb_x * 16 + (motion_x >> 2);
- src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2);
-
- height = s->height >> field_based;
- v_edge_pos = s->v_edge_pos >> field_based;
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- dxy &= ~3;
- src_y = clip(src_y, -16, height);
- if (src_y == height)
- dxy &= ~12;
- linesize = s->linesize << field_based;
- uvlinesize = s->uvlinesize << field_based;
- ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset;
- dest_y += dest_offset;
-//printf("%d %d %d\n", src_x, src_y, dxy);
-
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->h_edge_pos
- || src_y + (motion_y&3) + h > v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - src_offset, s->linesize, 17, 17+field_based,
- src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer + src_offset;
- emu=1;
- }
- }
- if(!field_based)
- qpix_op[0][dxy](dest_y, ptr, linesize);
- else{
- //damn interlaced mode
- //FIXME boundary mirroring is not exactly correct here
- qpix_op[1][dxy](dest_y , ptr , linesize);
- qpix_op[1][dxy](dest_y+8, ptr+8, linesize);
- }
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if(field_based){
- mx= motion_x/2;
- my= motion_y>>1;
- }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){
- static const int rtab[8]= {0,0,1,1,0,0,0,1};
- mx= (motion_x>>1) + rtab[motion_x&7];
- my= (motion_y>>1) + rtab[motion_y&7];
- }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){
- mx= (motion_x>>1)|(motion_x&1);
- my= (motion_y>>1)|(motion_y&1);
- }else{
- mx= motion_x/2;
- my= motion_y/2;
- }
- mx= (mx>>1)|(mx&1);
- my= (my>>1)|(my&1);
-
- dxy= (mx&1) | ((my&1)<<1);
- mx>>=1;
- my>>=1;
-
- src_x = s->mb_x * 8 + mx;
- src_y = s->mb_y * (8 >> field_based) + my;
- src_x = clip(src_x, -8, s->width >> 1);
- if (src_x == (s->width >> 1))
- dxy &= ~1;
- src_y = clip(src_y, -8, height >> 1);
- if (src_y == (height >> 1))
- dxy &= ~2;
-
- offset = (src_y * uvlinesize) + src_x + (src_offset >> 1);
- ptr = ref_picture[1] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based,
- src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer + (src_offset >> 1);
- }
- pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based,
- src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer + (src_offset >> 1);
- }
- pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1);
-}
-
-inline int ff_h263_round_chroma(int x){
- if (x >= 0)
- return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
- else {
- x = -x;
- return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1));
- }
-}
-
-/**
- * motion compesation of a single macroblock
- * @param s context
- * @param dest_y luma destination pointer
- * @param dest_cb chroma cb/u destination pointer
- * @param dest_cr chroma cr/v destination pointer
- * @param dir direction (0->forward, 1->backward)
- * @param ref_picture array[3] of pointers to the 3 planes of the reference picture
- * @param pic_op halfpel motion compensation function (average or put normally)
- * @param pic_op qpel motion compensation function (average or put normally)
- * the motion vectors are taken from s->mv and the MV type from s->mv_type
- */
-static inline void MPV_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dir, uint8_t **ref_picture,
- op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
-{
- int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y;
- int mb_x, mb_y, i;
- uint8_t *ptr, *dest;
- int emu=0;
-
- mb_x = s->mb_x;
- mb_y = s->mb_y;
-
- switch(s->mv_type) {
- case MV_TYPE_16X16:
-#ifdef CONFIG_RISKY
- if(s->mcsel){
- if(s->real_sprite_warping_points==1){
- gmc1_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, 0);
- }else{
- gmc_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, 0);
- }
- }else if(s->quarter_sample){
- qpel_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, 0,
- 0, pix_op, qpix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else if(s->mspel){
- ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
- ref_picture, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else
-#endif
- {
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, 0,
- 0, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }
- break;
- case MV_TYPE_8X8:
- mx = 0;
- my = 0;
- if(s->quarter_sample){
- for(i=0;i<4;i++) {
- motion_x = s->mv[dir][i][0];
- motion_y = s->mv[dir][i][1];
-
- dxy = ((motion_y & 3) << 2) | (motion_x & 3);
- src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
- src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
-
- /* WARNING: do no forget half pels */
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- dxy &= ~3;
- src_y = clip(src_y, -16, s->height);
- if (src_y == s->height)
- dxy &= ~12;
-
- ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 8 > s->h_edge_pos
- || src_y + (motion_y&3) + 8 > s->v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer;
- }
- }
- dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
- qpix_op[1][dxy](dest, ptr, s->linesize);
-
- mx += s->mv[dir][i][0]/2;
- my += s->mv[dir][i][1]/2;
- }
- }else{
- for(i=0;i<4;i++) {
- motion_x = s->mv[dir][i][0];
- motion_y = s->mv[dir][i][1];
-
- dxy = ((motion_y & 1) << 1) | (motion_x & 1);
- src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8;
- src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8;
-
- /* WARNING: do no forget half pels */
- src_x = clip(src_x, -16, s->width);
- if (src_x == s->width)
- dxy &= ~1;
- src_y = clip(src_y, -16, s->height);
- if (src_y == s->height)
- dxy &= ~2;
-
- ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos
- || src_y + (motion_y&1) + 8 > s->v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer;
- }
- }
- dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
- pix_op[1][dxy](dest, ptr, s->linesize, 8);
-
- mx += s->mv[dir][i][0];
- my += s->mv[dir][i][1];
- }
- }
-
- if(s->flags&CODEC_FLAG_GRAY) break;
- /* In case of 8X8, we construct a single chroma motion vector
- with a special rounding */
- mx= ff_h263_round_chroma(mx);
- my= ff_h263_round_chroma(my);
- dxy = ((my & 1) << 1) | (mx & 1);
- mx >>= 1;
- my >>= 1;
-
- src_x = mb_x * 8 + mx;
- src_y = mb_y * 8 + my;
- src_x = clip(src_x, -8, s->width/2);
- if (src_x == s->width/2)
- dxy &= ~1;
- src_y = clip(src_y, -8, s->height/2);
- if (src_y == s->height/2)
- dxy &= ~2;
-
- offset = (src_y * (s->uvlinesize)) + src_x;
- ptr = ref_picture[1] + offset;
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->h_edge_pos>>1
- || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- emu=1;
- }
- }
- pix_op[1][dxy](dest_cb, ptr, s->uvlinesize, 8);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[1][dxy](dest_cr, ptr, s->uvlinesize, 8);
- break;
- case MV_TYPE_FIELD:
- if (s->picture_structure == PICT_FRAME) {
- if(s->quarter_sample){
- /* top field */
- qpel_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, s->field_select[dir][0] ? s->linesize : 0,
- 1, pix_op, qpix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
- /* bottom field */
- qpel_motion(s, dest_y, dest_cb, dest_cr, s->linesize,
- ref_picture, s->field_select[dir][1] ? s->linesize : 0,
- 1, pix_op, qpix_op,
- s->mv[dir][1][0], s->mv[dir][1][1], 8);
- }else{
- /* top field */
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, s->field_select[dir][0] ? s->linesize : 0,
- 1, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
- /* bottom field */
- mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize,
- ref_picture, s->field_select[dir][1] ? s->linesize : 0,
- 1, pix_op,
- s->mv[dir][1][0], s->mv[dir][1][1], 8);
- }
- } else {
- int offset;
- if(s->picture_structure == s->field_select[dir][0] + 1 || s->pict_type == B_TYPE || s->first_field){
- offset= s->field_select[dir][0] ? s->linesize : 0;
- }else{
- ref_picture= s->current_picture.data;
- offset= s->field_select[dir][0] ? s->linesize : -s->linesize;
- }
-
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, offset,
- 0, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }
- break;
- case MV_TYPE_16X8:{
- int offset;
- uint8_t ** ref2picture;
-
- if(s->picture_structure == s->field_select[dir][0] + 1 || s->pict_type == B_TYPE || s->first_field){
- ref2picture= ref_picture;
- offset= s->field_select[dir][0] ? s->linesize : 0;
- }else{
- ref2picture= s->current_picture.data;
- offset= s->field_select[dir][0] ? s->linesize : -s->linesize;
- }
-
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref2picture, offset,
- 0, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
-
-
- if(s->picture_structure == s->field_select[dir][1] + 1 || s->pict_type == B_TYPE || s->first_field){
- ref2picture= ref_picture;
- offset= s->field_select[dir][1] ? s->linesize : 0;
- }else{
- ref2picture= s->current_picture.data;
- offset= s->field_select[dir][1] ? s->linesize : -s->linesize;
- }
- // I know it is ugly but this is the only way to fool emu_edge without rewrite mpeg_motion
- mpeg_motion(s, dest_y+16*s->linesize, dest_cb+8*s->uvlinesize, dest_cr+8*s->uvlinesize,
- 0,
- ref2picture, offset,
- 0, pix_op,
- s->mv[dir][1][0], s->mv[dir][1][1]+16, 8);
- }
-
- break;
- case MV_TYPE_DMV:
- {
- op_pixels_func (*dmv_pix_op)[4];
- int offset;
-
- dmv_pix_op = s->dsp.put_pixels_tab;
-
- if(s->picture_structure == PICT_FRAME){
- //put top field from top field
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, 0,
- 1, dmv_pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
- //put bottom field from bottom field
- mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize,
- ref_picture, s->linesize,
- 1, dmv_pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
-
- dmv_pix_op = s->dsp.avg_pixels_tab;
-
- //avg top field from bottom field
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture, s->linesize,
- 1, dmv_pix_op,
- s->mv[dir][2][0], s->mv[dir][2][1], 8);
- //avg bottom field from top field
- mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize,
- ref_picture, 0,
- 1, dmv_pix_op,
- s->mv[dir][3][0], s->mv[dir][3][1], 8);
-
- }else{
- offset=(s->picture_structure == PICT_BOTTOM_FIELD)?
- s->linesize : 0;
-
- //put field from the same parity
- //same parity is never in the same frame
- mpeg_motion(s, dest_y, dest_cb, dest_cr, 0,
- ref_picture,offset,
- 0,dmv_pix_op,
- s->mv[dir][0][0],s->mv[dir][0][1],16);
-
- // after put we make avg of the same block
- dmv_pix_op=s->dsp.avg_pixels_tab;
-
- //opposite parity is always in the same frame if this is second field
- if(!s->first_field){
- ref_picture = s->current_picture.data;
- //top field is one linesize from frame beginig
- offset=(s->picture_structure == PICT_BOTTOM_FIELD)?
- -s->linesize : s->linesize;
- }else
- offset=(s->picture_structure == PICT_BOTTOM_FIELD)?
- 0 : s->linesize;
-
- //avg field from the opposite parity
- mpeg_motion(s, dest_y, dest_cb, dest_cr,0,
- ref_picture, offset,
- 0,dmv_pix_op,
- s->mv[dir][2][0],s->mv[dir][2][1],16);
- }
- }
- break;
-
- }
-}
-
-
-/* put block[] to dest[] */
-static inline void put_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size)
-{
- s->dct_unquantize(s, block, i, s->qscale);
- s->dsp.idct_put (dest, line_size, block);
-}
-
-/* add block[] to dest[] */
-static inline void add_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size)
-{
- if (s->block_last_index[i] >= 0) {
- s->dsp.idct_add (dest, line_size, block);
- }
-}
-
-static inline void add_dequant_dct(MpegEncContext *s,
- DCTELEM *block, int i, uint8_t *dest, int line_size)
-{
- if (s->block_last_index[i] >= 0) {
- s->dct_unquantize(s, block, i, s->qscale);
-
- s->dsp.idct_add (dest, line_size, block);
- }
-}
-
-/**
- * cleans dc, ac, coded_block for the current non intra MB
- */
-void ff_clean_intra_table_entries(MpegEncContext *s)
-{
- int wrap = s->block_wrap[0];
- int xy = s->block_index[0];
-
- s->dc_val[0][xy ] =
- s->dc_val[0][xy + 1 ] =
- s->dc_val[0][xy + wrap] =
- s->dc_val[0][xy + 1 + wrap] = 1024;
- /* ac pred */
- memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
- memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
- if (s->msmpeg4_version>=3) {
- s->coded_block[xy ] =
- s->coded_block[xy + 1 ] =
- s->coded_block[xy + wrap] =
- s->coded_block[xy + 1 + wrap] = 0;
- }
- /* chroma */
- wrap = s->block_wrap[4];
- xy = s->mb_x + 1 + (s->mb_y + 1) * wrap;
- s->dc_val[1][xy] =
- s->dc_val[2][xy] = 1024;
- /* ac pred */
- memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
- memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
-
- s->mbintra_table[s->mb_x + s->mb_y*s->mb_stride]= 0;
-}
-
-/* generic function called after a macroblock has been parsed by the
- decoder or after it has been encoded by the encoder.
-
- Important variables used:
- s->mb_intra : true if intra macroblock
- s->mv_dir : motion vector direction
- s->mv_type : motion vector type
- s->mv : motion vector
- s->interlaced_dct : true if interlaced dct used (mpeg2)
- */
-void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- int mb_x, mb_y;
- const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-#ifdef HAVE_XVMC
- if(s->avctx->xvmc_acceleration){
- XVMC_decode_mb(s,block);
- return;
- }
-#endif
-
- mb_x = s->mb_x;
- mb_y = s->mb_y;
-
- s->current_picture.qscale_table[mb_xy]= s->qscale;
-
- /* update DC predictors for P macroblocks */
- if (!s->mb_intra) {
- if (s->h263_pred || s->h263_aic) {
- if(s->mbintra_table[mb_xy])
- ff_clean_intra_table_entries(s);
- } else {
- s->last_dc[0] =
- s->last_dc[1] =
- s->last_dc[2] = 128 << s->intra_dc_precision;
- }
- }
- else if (s->h263_pred || s->h263_aic)
- s->mbintra_table[mb_xy]=1;
-
- if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { //FIXME precalc
- uint8_t *dest_y, *dest_cb, *dest_cr;
- int dct_linesize, dct_offset;
- op_pixels_func (*op_pix)[4];
- qpel_mc_func (*op_qpix)[16];
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
-
- /* avoid copy if macroblock skipped in last frame too */
- /* skip only during decoding as we might trash the buffers during encoding a bit */
- if(!s->encoding){
- uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
- const int age= s->current_picture.age;
-
- assert(age);
-
- if (s->mb_skiped) {
- s->mb_skiped= 0;
- assert(s->pict_type!=I_TYPE);
-
- (*mbskip_ptr) ++; /* indicate that this time we skiped it */
- if(*mbskip_ptr >99) *mbskip_ptr= 99;
-
- /* if previous was skipped too, then nothing to do ! */
- if (*mbskip_ptr >= age && s->current_picture.reference){
- return;
- }
- } else if(!s->current_picture.reference){
- (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */
- if(*mbskip_ptr >99) *mbskip_ptr= 99;
- } else{
- *mbskip_ptr = 0; /* not skipped */
- }
- }
-
- if (s->interlaced_dct) {
- dct_linesize = linesize * 2;
- dct_offset = linesize;
- } else {
- dct_linesize = linesize;
- dct_offset = linesize * 8;
- }
-
- dest_y= s->dest[0];
- dest_cb= s->dest[1];
- dest_cr= s->dest[2];
-
- if (!s->mb_intra) {
- /* motion handling */
- /* decoding or more than one mb_type (MC was allready done otherwise) */
- if(!s->encoding){
- if ((!s->no_rounding) || s->pict_type==B_TYPE){
- op_pix = s->dsp.put_pixels_tab;
- op_qpix= s->dsp.put_qpel_pixels_tab;
- }else{
- op_pix = s->dsp.put_no_rnd_pixels_tab;
- op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab;
- }
-
- if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
- op_pix = s->dsp.avg_pixels_tab;
- op_qpix= s->dsp.avg_qpel_pixels_tab;
- }
- if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
- }
- }
-
- /* skip dequant / idct if we are really late ;) */
- if(s->hurry_up>1) return;
-
- /* add dct residue */
- if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
- || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){
- add_dequant_dct(s, block[0], 0, dest_y, dct_linesize);
- add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize);
- add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
- add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize);
- add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize);
- }
- } else if(s->codec_id != CODEC_ID_WMV2){
- add_dct(s, block[0], 0, dest_y, dct_linesize);
- add_dct(s, block[1], 1, dest_y + 8, dct_linesize);
- add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
- add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- add_dct(s, block[4], 4, dest_cb, uvlinesize);
- add_dct(s, block[5], 5, dest_cr, uvlinesize);
- }
- }
-#ifdef CONFIG_RISKY
- else{
- ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
- }
-#endif
- } else {
- /* dct only in intra block */
- if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){
- put_dct(s, block[0], 0, dest_y, dct_linesize);
- put_dct(s, block[1], 1, dest_y + 8, dct_linesize);
- put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
- put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- put_dct(s, block[4], 4, dest_cb, uvlinesize);
- put_dct(s, block[5], 5, dest_cr, uvlinesize);
- }
- }else{
- s->dsp.idct_put(dest_y , dct_linesize, block[0]);
- s->dsp.idct_put(dest_y + 8, dct_linesize, block[1]);
- s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
- s->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]);
-
- if(!(s->flags&CODEC_FLAG_GRAY)){
- s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
- s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
- }
- }
- }
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold)
-{
- static const char tab[64]=
- {3,2,2,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0};
- int score=0;
- int run=0;
- int i;
- DCTELEM *block= s->block[n];
- const int last_index= s->block_last_index[n];
- int skip_dc;
-
- if(threshold<0){
- skip_dc=0;
- threshold= -threshold;
- }else
- skip_dc=1;
-
- /* are all which we could set to zero are allready zero? */
- if(last_index<=skip_dc - 1) return;
-
- for(i=0; i<=last_index; i++){
- const int j = s->intra_scantable.permutated[i];
- const int level = ABS(block[j]);
- if(level==1){
- if(skip_dc && i==0) continue;
- score+= tab[run];
- run=0;
- }else if(level>1){
- return;
- }else{
- run++;
- }
- }
- if(score >= threshold) return;
- for(i=skip_dc; i<=last_index; i++){
- const int j = s->intra_scantable.permutated[i];
- block[j]=0;
- }
- if(block[0]) s->block_last_index[n]= 0;
- else s->block_last_index[n]= -1;
-}
-
-static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index)
-{
- int i;
- const int maxlevel= s->max_qcoeff;
- const int minlevel= s->min_qcoeff;
-
- if(s->mb_intra){
- i=1; //skip clipping of intra dc
- }else
- i=0;
-
- for(;i<=last_index; i++){
- const int j= s->intra_scantable.permutated[i];
- int level = block[j];
-
- if (level>maxlevel) level=maxlevel;
- else if(level<minlevel) level=minlevel;
-
- block[j]= level;
- }
-}
-
-#if 0
-static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize
- int score=0;
- int x,y;
-
- for(y=0; y<7; y++){
- for(x=0; x<16; x+=4){
- score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride])
- +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]);
- }
- s+= stride;
- }
-
- return score;
-}
-
-static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize
- int score=0;
- int x,y;
-
- for(y=0; y<7; y++){
- for(x=0; x<16; x++){
- score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
- }
- s1+= stride;
- s2+= stride;
- }
-
- return score;
-}
-#else
-#define SQ(a) ((a)*(a))
-
-static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize
- int score=0;
- int x,y;
-
- for(y=0; y<7; y++){
- for(x=0; x<16; x+=4){
- score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride])
- +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]);
- }
- s+= stride;
- }
-
- return score;
-}
-
-static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize
- int score=0;
- int x,y;
-
- for(y=0; y<7; y++){
- for(x=0; x<16; x++){
- score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
- }
- s1+= stride;
- s2+= stride;
- }
-
- return score;
-}
-
-#endif
-
-#endif //CONFIG_ENCODERS
-
-/**
- *
- * @param h is the normal height, this will be reduced automatically if needed for the last row
- */
-void ff_draw_horiz_band(MpegEncContext *s, int y, int h){
- if (s->avctx->draw_horiz_band) {
- AVFrame *src;
- int offset[4];
-
- if(s->picture_structure != PICT_FRAME){
- h <<= 1;
- y <<= 1;
- if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
- }
-
- h= FFMIN(h, s->height - y);
-
- if(s->pict_type==B_TYPE || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER))
- src= (AVFrame*)s->current_picture_ptr;
- else if(s->last_picture_ptr)
- src= (AVFrame*)s->last_picture_ptr;
- else
- return;
-
- if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){
- offset[0]=
- offset[1]=
- offset[2]=
- offset[3]= 0;
- }else{
- offset[0]= y * s->linesize;;
- offset[1]=
- offset[2]= (y>>1) * s->uvlinesize;;
- offset[3]= 0;
- }
-
- emms_c();
-
- s->avctx->draw_horiz_band(s->avctx, src, offset,
- y, s->picture_structure, h);
- }
-}
-
-void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics
- const int uvlinesize= s->current_picture.linesize[1];
-
- s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
- s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1) + s->mb_x*2;
- s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2;
- s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2) + s->mb_x*2;
- s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
- s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
-
- if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){
- s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16;
- s->dest[1] = s->current_picture.data[1] + s->mb_x * 8 - 8;
- s->dest[2] = s->current_picture.data[2] + s->mb_x * 8 - 8;
- }else{
- s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* linesize ) + s->mb_x * 16 - 16;
- s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * uvlinesize) + s->mb_x * 8 - 8;
- s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * uvlinesize) + s->mb_x * 8 - 8;
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void encode_mb(MpegEncContext *s, int motion_x, int motion_y)
-{
- const int mb_x= s->mb_x;
- const int mb_y= s->mb_y;
- int i;
- int skip_dct[6];
- int dct_offset = s->linesize*8; //default for progressive frames
-
- for(i=0; i<6; i++) skip_dct[i]=0;
-
- if(s->adaptive_quant){
- s->dquant= s->current_picture.qscale_table[mb_x + mb_y*s->mb_stride] - s->qscale;
-
- if(s->out_format==FMT_H263){
- if (s->dquant> 2) s->dquant= 2;
- else if(s->dquant<-2) s->dquant=-2;
- }
-
- if(s->codec_id==CODEC_ID_MPEG4){
- if(!s->mb_intra){
- if(s->mv_dir&MV_DIRECT)
- s->dquant=0;
-
- assert(s->dquant==0 || s->mv_type!=MV_TYPE_8X8);
- }
- }
- s->qscale+= s->dquant;
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
- }
-
- if (s->mb_intra) {
- uint8_t *ptr;
- int wrap_y;
- int emu=0;
-
- wrap_y = s->linesize;
- ptr = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
-
- if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height);
- ptr= s->edge_emu_buffer;
- emu=1;
- }
-
- if(s->flags&CODEC_FLAG_INTERLACED_DCT){
- int progressive_score, interlaced_score;
-
- progressive_score= pix_vcmp16x8(ptr, wrap_y ) + pix_vcmp16x8(ptr + wrap_y*8, wrap_y );
- interlaced_score = pix_vcmp16x8(ptr, wrap_y*2) + pix_vcmp16x8(ptr + wrap_y , wrap_y*2);
-
- if(progressive_score > interlaced_score + 100){
- s->interlaced_dct=1;
-
- dct_offset= wrap_y;
- wrap_y<<=1;
- }else
- s->interlaced_dct=0;
- }
-
- s->dsp.get_pixels(s->block[0], ptr , wrap_y);
- s->dsp.get_pixels(s->block[1], ptr + 8, wrap_y);
- s->dsp.get_pixels(s->block[2], ptr + dct_offset , wrap_y);
- s->dsp.get_pixels(s->block[3], ptr + dct_offset + 8, wrap_y);
-
- if(s->flags&CODEC_FLAG_GRAY){
- skip_dct[4]= 1;
- skip_dct[5]= 1;
- }else{
- int wrap_c = s->uvlinesize;
- ptr = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr= s->edge_emu_buffer;
- }
- s->dsp.get_pixels(s->block[4], ptr, wrap_c);
-
- ptr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr= s->edge_emu_buffer;
- }
- s->dsp.get_pixels(s->block[5], ptr, wrap_c);
- }
- }else{
- op_pixels_func (*op_pix)[4];
- qpel_mc_func (*op_qpix)[16];
- uint8_t *dest_y, *dest_cb, *dest_cr;
- uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int wrap_y, wrap_c;
- int emu=0;
-
- dest_y = s->dest[0];
- dest_cb = s->dest[1];
- dest_cr = s->dest[2];
- wrap_y = s->linesize;
- wrap_c = s->uvlinesize;
- ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16;
- ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8;
- ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8;
-
- if ((!s->no_rounding) || s->pict_type==B_TYPE){
- op_pix = s->dsp.put_pixels_tab;
- op_qpix= s->dsp.put_qpel_pixels_tab;
- }else{
- op_pix = s->dsp.put_no_rnd_pixels_tab;
- op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab;
- }
-
- if (s->mv_dir & MV_DIR_FORWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix);
- op_pix = s->dsp.avg_pixels_tab;
- op_qpix= s->dsp.avg_qpel_pixels_tab;
- }
- if (s->mv_dir & MV_DIR_BACKWARD) {
- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix);
- }
-
- if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height);
- ptr_y= s->edge_emu_buffer;
- emu=1;
- }
-
- if(s->flags&CODEC_FLAG_INTERLACED_DCT){
- int progressive_score, interlaced_score;
-
- progressive_score= pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y )
- + pix_diff_vcmp16x8(ptr_y + wrap_y*8, dest_y + wrap_y*8, wrap_y );
- interlaced_score = pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y*2)
- + pix_diff_vcmp16x8(ptr_y + wrap_y , dest_y + wrap_y , wrap_y*2);
-
- if(progressive_score > interlaced_score + 600){
- s->interlaced_dct=1;
-
- dct_offset= wrap_y;
- wrap_y<<=1;
- }else
- s->interlaced_dct=0;
- }
-
- s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y);
- s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
- s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y);
- s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y);
-
- if(s->flags&CODEC_FLAG_GRAY){
- skip_dct[4]= 1;
- skip_dct[5]= 1;
- }else{
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr_cb= s->edge_emu_buffer;
- }
- s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1);
- ptr_cr= s->edge_emu_buffer;
- }
- s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
- }
- /* pre quantization */
- if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){
- //FIXME optimize
- if(s->dsp.pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1;
- if(s->dsp.pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1;
- if(s->dsp.pix_abs8x8(ptr_y +dct_offset , dest_y +dct_offset , wrap_y) < 20*s->qscale) skip_dct[2]= 1;
- if(s->dsp.pix_abs8x8(ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1;
- if(s->dsp.pix_abs8x8(ptr_cb , dest_cb , wrap_c) < 20*s->qscale) skip_dct[4]= 1;
- if(s->dsp.pix_abs8x8(ptr_cr , dest_cr , wrap_c) < 20*s->qscale) skip_dct[5]= 1;
-#if 0
-{
- static int stat[7];
- int num=0;
- for(i=0; i<6; i++)
- if(skip_dct[i]) num++;
- stat[num]++;
-
- if(s->mb_x==0 && s->mb_y==0){
- for(i=0; i<7; i++){
- printf("%6d %1d\n", stat[i], i);
- }
- }
-}
-#endif
- }
-
- }
-
-#if 0
- {
- float adap_parm;
-
- adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_stride*mb_y+mb_x] + 1.0) /
- ((s->mb_var[s->mb_stride*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0);
-
- printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d",
- (s->mb_type[s->mb_stride*mb_y+mb_x] > 0) ? 'I' : 'P',
- s->qscale, adap_parm, s->qscale*adap_parm,
- s->mb_var[s->mb_stride*mb_y+mb_x], s->avg_mb_var);
- }
-#endif
- /* DCT & quantize */
- if(s->out_format==FMT_MJPEG){
- for(i=0;i<6;i++) {
- int overflow;
- s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, 8, &overflow);
- if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
- }
- }else{
- for(i=0;i<6;i++) {
- if(!skip_dct[i]){
- int overflow;
- s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
- // FIXME we could decide to change to quantizer instead of clipping
- // JS: I don't think that would be a good idea it could lower quality instead
- // of improve it. Just INTRADC clipping deserves changes in quantizer
- if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]);
- }else
- s->block_last_index[i]= -1;
- }
- if(s->luma_elim_threshold && !s->mb_intra)
- for(i=0; i<4; i++)
- dct_single_coeff_elimination(s, i, s->luma_elim_threshold);
- if(s->chroma_elim_threshold && !s->mb_intra)
- for(i=4; i<6; i++)
- dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
- }
-
- if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){
- s->block_last_index[4]=
- s->block_last_index[5]= 0;
- s->block[4][0]=
- s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale;
- }
-
- /* huffman encode */
- switch(s->codec_id){ //FIXME funct ptr could be slightly faster
- case CODEC_ID_MPEG1VIDEO:
- case CODEC_ID_MPEG2VIDEO:
- mpeg1_encode_mb(s, s->block, motion_x, motion_y); break;
-#ifdef CONFIG_RISKY
- case CODEC_ID_MPEG4:
- mpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_MSMPEG4V2:
- case CODEC_ID_MSMPEG4V3:
- case CODEC_ID_WMV1:
- msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_WMV2:
- ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break;
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- case CODEC_ID_RV10:
- h263_encode_mb(s, s->block, motion_x, motion_y); break;
-#endif
- case CODEC_ID_MJPEG:
- mjpeg_encode_mb(s, s->block); break;
- default:
- assert(0);
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-/**
- * combines the (truncated) bitstream to a complete frame
- * @returns -1 if no complete frame could be created
- */
-int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){
- ParseContext *pc= &s->parse_context;
-
-#if 0
- if(pc->overread){
- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
- }
-#endif
-
- /* copy overreaded byes from last frame into buffer */
- for(; pc->overread>0; pc->overread--){
- pc->buffer[pc->index++]= pc->buffer[pc->overread_index++];
- }
-
- pc->last_index= pc->index;
-
- /* copy into buffer end return */
- if(next == END_NOT_FOUND){
- pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(&pc->buffer[pc->index], *buf, *buf_size);
- pc->index += *buf_size;
- return -1;
- }
-
- *buf_size=
- pc->overread_index= pc->index + next;
-
- /* append to buffer */
- if(pc->index){
- pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE);
-
- memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE );
- pc->index = 0;
- *buf= pc->buffer;
- }
-
- /* store overread bytes */
- for(;next < 0; next++){
- pc->state = (pc->state<<8) | pc->buffer[pc->last_index + next];
- pc->overread++;
- }
-
-#if 0
- if(pc->overread){
- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index);
- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]);
- }
-#endif
-
- return 0;
-}
-
-void ff_mpeg_flush(AVCodecContext *avctx){
- int i;
- MpegEncContext *s = avctx->priv_data;
-
- for(i=0; i<MAX_PICTURE_COUNT; i++){
- if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL
- || s->picture[i].type == FF_BUFFER_TYPE_USER))
- avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
- }
- s->last_picture_ptr = s->next_picture_ptr = NULL;
-
- s->parse_context.state= -1;
- s->parse_context.frame_start_found= 0;
- s->parse_context.overread= 0;
- s->parse_context.overread_index= 0;
- s->parse_context.index= 0;
- s->parse_context.last_index= 0;
-}
-
-#ifdef CONFIG_ENCODERS
-void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length)
-{
- int bytes= length>>4;
- int bits= length&15;
- int i;
-
- if(length==0) return;
-
- for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i]));
- put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits));
-}
-
-static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){
- int i;
-
- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
-
- /* mpeg1 */
- d->mb_skip_run= s->mb_skip_run;
- for(i=0; i<3; i++)
- d->last_dc[i]= s->last_dc[i];
-
- /* statistics */
- d->mv_bits= s->mv_bits;
- d->i_tex_bits= s->i_tex_bits;
- d->p_tex_bits= s->p_tex_bits;
- d->i_count= s->i_count;
- d->f_count= s->f_count;
- d->b_count= s->b_count;
- d->skip_count= s->skip_count;
- d->misc_bits= s->misc_bits;
- d->last_bits= 0;
-
- d->mb_skiped= 0;
- d->qscale= s->qscale;
-}
-
-static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){
- int i;
-
- memcpy(d->mv, s->mv, 2*4*2*sizeof(int));
- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop?
-
- /* mpeg1 */
- d->mb_skip_run= s->mb_skip_run;
- for(i=0; i<3; i++)
- d->last_dc[i]= s->last_dc[i];
-
- /* statistics */
- d->mv_bits= s->mv_bits;
- d->i_tex_bits= s->i_tex_bits;
- d->p_tex_bits= s->p_tex_bits;
- d->i_count= s->i_count;
- d->f_count= s->f_count;
- d->b_count= s->b_count;
- d->skip_count= s->skip_count;
- d->misc_bits= s->misc_bits;
-
- d->mb_intra= s->mb_intra;
- d->mb_skiped= s->mb_skiped;
- d->mv_type= s->mv_type;
- d->mv_dir= s->mv_dir;
- d->pb= s->pb;
- if(s->data_partitioning){
- d->pb2= s->pb2;
- d->tex_pb= s->tex_pb;
- }
- d->block= s->block;
- for(i=0; i<6; i++)
- d->block_last_index[i]= s->block_last_index[i];
- d->interlaced_dct= s->interlaced_dct;
- d->qscale= s->qscale;
-}
-
-static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type,
- PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2],
- int *dmin, int *next_block, int motion_x, int motion_y)
-{
- int score;
- uint8_t *dest_backup[3];
-
- copy_context_before_encode(s, backup, type);
-
- s->block= s->blocks[*next_block];
- s->pb= pb[*next_block];
- if(s->data_partitioning){
- s->pb2 = pb2 [*next_block];
- s->tex_pb= tex_pb[*next_block];
- }
-
- if(*next_block){
- memcpy(dest_backup, s->dest, sizeof(s->dest));
- s->dest[0] = s->me.scratchpad;
- s->dest[1] = s->me.scratchpad + 16;
- s->dest[2] = s->me.scratchpad + 16 + 8;
- assert(2*s->uvlinesize == s->linesize); //should be no prob for encoding
- assert(s->linesize >= 64); //FIXME
- }
-
- encode_mb(s, motion_x, motion_y);
-
- score= get_bit_count(&s->pb);
- if(s->data_partitioning){
- score+= get_bit_count(&s->pb2);
- score+= get_bit_count(&s->tex_pb);
- }
-
- if(s->avctx->mb_decision == FF_MB_DECISION_RD){
- MPV_decode_mb(s, s->block);
-
- score *= s->qscale * s->qscale * 109;
- score += sse_mb(s) << 7;
- }
-
- if(*next_block){
- memcpy(s->dest, dest_backup, sizeof(s->dest));
- }
-
- if(score<*dmin){
- *dmin= score;
- *next_block^=1;
-
- copy_context_after_encode(best, s, type);
- }
-}
-
-static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){
- uint32_t *sq = squareTbl + 256;
- int acc=0;
- int x,y;
-
- if(w==16 && h==16)
- return s->dsp.sse[0](NULL, src1, src2, stride);
- else if(w==8 && h==8)
- return s->dsp.sse[1](NULL, src1, src2, stride);
-
- for(y=0; y<h; y++){
- for(x=0; x<w; x++){
- acc+= sq[src1[x + y*stride] - src2[x + y*stride]];
- }
- }
-
- assert(acc>=0);
-
- return acc;
-}
-
-static int sse_mb(MpegEncContext *s){
- int w= 16;
- int h= 16;
-
- if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
- if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
-
- if(w==16 && h==16)
- return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize)
- +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize)
- +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize);
- else
- return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize)
- +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize)
- +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize);
-}
-
-static void encode_picture(MpegEncContext *s, int picture_number)
-{
- int mb_x, mb_y, pdif = 0;
- int i;
- int bits;
- MpegEncContext best_s, backup_s;
- uint8_t bit_buf[2][3000];
- uint8_t bit_buf2[2][3000];
- uint8_t bit_buf_tex[2][3000];
- PutBitContext pb[2], pb2[2], tex_pb[2];
-
- for(i=0; i<2; i++){
- init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL);
- init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL);
- init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL);
- }
-
- s->picture_number = picture_number;
-
- /* Reset the average MB variance */
- s->current_picture.mb_var_sum = 0;
- s->current_picture.mc_mb_var_sum = 0;
-
-#ifdef CONFIG_RISKY
- /* we need to initialize some time vars before we can encode b-frames */
- // RAL: Condition added for MPEG1VIDEO
- if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
- ff_set_mpeg4_time(s, s->picture_number);
-#endif
-
- s->scene_change_score=0;
-
- s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration
-
- if(s->pict_type==I_TYPE){
- if(s->msmpeg4_version >= 3) s->no_rounding=1;
- else s->no_rounding=0;
- }else if(s->pict_type!=B_TYPE){
- if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4)
- s->no_rounding ^= 1;
- }
-
- /* Estimate motion for every MB */
- s->mb_intra=0; //for the rate distoration & bit compare functions
- if(s->pict_type != I_TYPE){
- if(s->pict_type != B_TYPE){
- if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){
- s->me.pre_pass=1;
- s->me.dia_size= s->avctx->pre_dia_size;
-
- for(mb_y=s->mb_height-1; mb_y >=0 ; mb_y--) {
- for(mb_x=s->mb_width-1; mb_x >=0 ; mb_x--) {
- s->mb_x = mb_x;
- s->mb_y = mb_y;
- ff_pre_estimate_p_frame_motion(s, mb_x, mb_y);
- }
- }
- s->me.pre_pass=0;
- }
- }
-
- s->me.dia_size= s->avctx->dia_size;
- for(mb_y=0; mb_y < s->mb_height; mb_y++) {
- s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1;
- s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1);
- s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1;
- s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2);
- for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- s->mb_x = mb_x;
- s->mb_y = mb_y;
- s->block_index[0]+=2;
- s->block_index[1]+=2;
- s->block_index[2]+=2;
- s->block_index[3]+=2;
-
- /* compute motion vector & mb_type and store in context */
- if(s->pict_type==B_TYPE)
- ff_estimate_b_frame_motion(s, mb_x, mb_y);
- else
- ff_estimate_p_frame_motion(s, mb_x, mb_y);
- }
- }
- }else /* if(s->pict_type == I_TYPE) */{
- /* I-Frame */
- //FIXME do we need to zero them?
- memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2);
- memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_stride)*s->mb_height*2);
- memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_stride*s->mb_height);
-
- if(!s->fixed_qscale){
- /* finding spatial complexity for I-frame rate control */
- for(mb_y=0; mb_y < s->mb_height; mb_y++) {
- for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- int xx = mb_x * 16;
- int yy = mb_y * 16;
- uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx;
- int varc;
- int sum = s->dsp.pix_sum(pix, s->linesize);
-
- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8;
-
- s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc;
- s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
- s->current_picture.mb_var_sum += varc;
- }
- }
- }
- }
- emms_c();
-
- if(s->scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){
- s->pict_type= I_TYPE;
- memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_stride*s->mb_height);
-//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum);
- }
-
- if(!s->umvplus){
- if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) {
- s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER);
-
- ff_fix_long_p_mvs(s);
- }
-
- if(s->pict_type==B_TYPE){
- int a, b;
-
- a = ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD);
- b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, MB_TYPE_BIDIR);
- s->f_code = FFMAX(a, b);
-
- a = ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD);
- b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, MB_TYPE_BIDIR);
- s->b_code = FFMAX(a, b);
-
- ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD);
- ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD);
- ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR);
- ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR);
- }
- }
-
- if (s->fixed_qscale)
- s->frame_qscale = s->current_picture.quality;
- else
- s->frame_qscale = ff_rate_estimate_qscale(s);
-
- if(s->adaptive_quant){
-#ifdef CONFIG_RISKY
- switch(s->codec_id){
- case CODEC_ID_MPEG4:
- ff_clean_mpeg4_qscales(s);
- break;
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- ff_clean_h263_qscales(s);
- break;
- }
-#endif
-
- s->qscale= s->current_picture.qscale_table[0];
- }else
- s->qscale= (int)(s->frame_qscale + 0.5);
-
- if (s->out_format == FMT_MJPEG) {
- /* for mjpeg, we do include qscale in the matrix */
- s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0];
- for(i=1;i<64;i++){
- int j= s->dsp.idct_permutation[i];
-
- s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3);
- }
- convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16,
- s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8);
- }
-
- //FIXME var duplication
- s->current_picture.key_frame= s->pict_type == I_TYPE;
- s->current_picture.pict_type= s->pict_type;
-
- if(s->current_picture.key_frame)
- s->picture_in_gop_number=0;
-
- s->last_bits= get_bit_count(&s->pb);
- switch(s->out_format) {
- case FMT_MJPEG:
- mjpeg_picture_header(s);
- break;
-#ifdef CONFIG_RISKY
- case FMT_H263:
- if (s->codec_id == CODEC_ID_WMV2)
- ff_wmv2_encode_picture_header(s, picture_number);
- else if (s->h263_msmpeg4)
- msmpeg4_encode_picture_header(s, picture_number);
- else if (s->h263_pred)
- mpeg4_encode_picture_header(s, picture_number);
- else if (s->h263_rv10)
- rv10_encode_picture_header(s, picture_number);
- else if (s->codec_id == CODEC_ID_FLV1)
- ff_flv_encode_picture_header(s, picture_number);
- else
- h263_encode_picture_header(s, picture_number);
- break;
-#endif
- case FMT_MPEG1:
- mpeg1_encode_picture_header(s, picture_number);
- break;
- case FMT_H264:
- break;
- }
- bits= get_bit_count(&s->pb);
- s->header_bits= bits - s->last_bits;
- s->last_bits= bits;
- s->mv_bits=0;
- s->misc_bits=0;
- s->i_tex_bits=0;
- s->p_tex_bits=0;
- s->i_count=0;
- s->f_count=0;
- s->b_count=0;
- s->skip_count=0;
-
- for(i=0; i<3; i++){
- /* init last dc values */
- /* note: quant matrix value (8) is implied here */
- s->last_dc[i] = 128;
-
- s->current_picture_ptr->error[i] = 0;
- }
- s->mb_skip_run = 0;
- s->last_mv[0][0][0] = 0;
- s->last_mv[0][0][1] = 0;
- s->last_mv[1][0][0] = 0;
- s->last_mv[1][0][1] = 0;
-
- s->last_mv_dir = 0;
-
-#ifdef CONFIG_RISKY
- switch(s->codec_id){
- case CODEC_ID_H263:
- case CODEC_ID_H263P:
- case CODEC_ID_FLV1:
- s->gob_index = ff_h263_get_gob_height(s);
- break;
- case CODEC_ID_MPEG4:
- if(s->partitioned_frame)
- ff_mpeg4_init_partitions(s);
- break;
- }
-#endif
-
- s->resync_mb_x=0;
- s->resync_mb_y=0;
- s->first_slice_line = 1;
- s->ptr_lastgob = s->pb.buf;
- for(mb_y=0; mb_y < s->mb_height; mb_y++) {
- s->mb_x=0;
- s->mb_y= mb_y;
-
- s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
- s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
- ff_init_block_index(s);
-
- for(mb_x=0; mb_x < s->mb_width; mb_x++) {
- const int xy= mb_y*s->mb_stride + mb_x;
- int mb_type= s->mb_type[xy];
-// int d;
- int dmin= INT_MAX;
-
- s->mb_x = mb_x;
- ff_update_block_index(s);
-
- /* write gob / video packet header */
-#ifdef CONFIG_RISKY
- if(s->rtp_mode && mb_y + mb_x>0){
- int current_packet_size, is_gob_start;
-
- current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob;
- is_gob_start=0;
-
- if(s->codec_id==CODEC_ID_MPEG4){
- if(current_packet_size >= s->rtp_payload_size){
-
- if(s->partitioned_frame){
- ff_mpeg4_merge_partitions(s);
- ff_mpeg4_init_partitions(s);
- }
- ff_mpeg4_encode_video_packet_header(s);
-
- if(s->flags&CODEC_FLAG_PASS1){
- int bits= get_bit_count(&s->pb);
- s->misc_bits+= bits - s->last_bits;
- s->last_bits= bits;
- }
- ff_mpeg4_clean_buffers(s);
- is_gob_start=1;
- }
- }else if(s->codec_id==CODEC_ID_MPEG1VIDEO){
- if( current_packet_size >= s->rtp_payload_size
- && s->mb_skip_run==0){
- ff_mpeg1_encode_slice_header(s);
- ff_mpeg1_clean_buffers(s);
- is_gob_start=1;
- }
- }else if(s->codec_id==CODEC_ID_MPEG2VIDEO){
- if( ( current_packet_size >= s->rtp_payload_size || mb_x==0)
- && s->mb_skip_run==0){
- ff_mpeg1_encode_slice_header(s);
- ff_mpeg1_clean_buffers(s);
- is_gob_start=1;
- }
- }else{
- if(current_packet_size >= s->rtp_payload_size
- && s->mb_x==0 && s->mb_y%s->gob_index==0){
-
- h263_encode_gob_header(s, mb_y);
- is_gob_start=1;
- }
- }
-
- if(is_gob_start){
- s->ptr_lastgob = pbBufPtr(&s->pb);
- s->first_slice_line=1;
- s->resync_mb_x=mb_x;
- s->resync_mb_y=mb_y;
- }
- }
-#endif
-
- if( (s->resync_mb_x == s->mb_x)
- && s->resync_mb_y+1 == s->mb_y){
- s->first_slice_line=0;
- }
-
- s->mb_skiped=0;
-
- if(mb_type & (mb_type-1)){ // more than 1 MB type possible
- int next_block=0;
- int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
-
- copy_context_before_encode(&backup_s, s, -1);
- backup_s.pb= s->pb;
- best_s.data_partitioning= s->data_partitioning;
- best_s.partitioned_frame= s->partitioned_frame;
- if(s->data_partitioning){
- backup_s.pb2= s->pb2;
- backup_s.tex_pb= s->tex_pb;
- }
-
- if(mb_type&MB_TYPE_INTER){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->p_mv_table[xy][0];
- s->mv[0][0][1] = s->p_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
- }
- if(mb_type&MB_TYPE_INTER4V){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_8X8;
- s->mb_intra= 0;
- for(i=0; i<4; i++){
- s->mv[0][i][0] = s->motion_val[s->block_index[i]][0];
- s->mv[0][i][1] = s->motion_val[s->block_index[i]][1];
- }
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&MB_TYPE_FORWARD){
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]);
- }
- if(mb_type&MB_TYPE_BACKWARD){
- s->mv_dir = MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[1][0][0] = s->b_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_back_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb,
- &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]);
- }
- if(mb_type&MB_TYPE_BIDIR){
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 0;
- s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
- s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- }
- if(mb_type&MB_TYPE_DIRECT){
- int mx= s->b_direct_mv_table[xy][0];
- int my= s->b_direct_mv_table[xy][1];
-
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
-#ifdef CONFIG_RISKY
- ff_mpeg4_set_direct_mv(s, mx, my);
-#endif
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb,
- &dmin, &next_block, mx, my);
- }
- if(mb_type&MB_TYPE_INTRA){
- s->mv_dir = 0;
- s->mv_type = MV_TYPE_16X16;
- s->mb_intra= 1;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb,
- &dmin, &next_block, 0, 0);
- if(s->h263_pred || s->h263_aic){
- if(best_s.mb_intra)
- s->mbintra_table[mb_x + mb_y*s->mb_stride]=1;
- else
- ff_clean_intra_table_entries(s); //old mode?
- }
- }
- copy_context_after_encode(s, &best_s, -1);
-
- pb_bits_count= get_bit_count(&s->pb);
- flush_put_bits(&s->pb);
- ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
- s->pb= backup_s.pb;
-
- if(s->data_partitioning){
- pb2_bits_count= get_bit_count(&s->pb2);
- flush_put_bits(&s->pb2);
- ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
- s->pb2= backup_s.pb2;
-
- tex_pb_bits_count= get_bit_count(&s->tex_pb);
- flush_put_bits(&s->tex_pb);
- ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count);
- s->tex_pb= backup_s.tex_pb;
- }
- s->last_bits= get_bit_count(&s->pb);
-
-#ifdef CONFIG_RISKY
- if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-#endif
-
- if(next_block==0){
- s->dsp.put_pixels_tab[0][0](s->dest[0], s->me.scratchpad , s->linesize ,16);
- s->dsp.put_pixels_tab[1][0](s->dest[1], s->me.scratchpad + 16, s->uvlinesize, 8);
- s->dsp.put_pixels_tab[1][0](s->dest[2], s->me.scratchpad + 24, s->uvlinesize, 8);
- }
-
- if(s->avctx->mb_decision == FF_MB_DECISION_BITS)
- MPV_decode_mb(s, s->block);
- } else {
- int motion_x, motion_y;
- int intra_score;
- int inter_score= s->current_picture.mb_cmp_score[mb_x + mb_y*s->mb_stride];
-
- if(s->avctx->mb_decision==FF_MB_DECISION_SIMPLE && s->pict_type==P_TYPE){ //FIXME check if the mess is usefull at all
- /* get luma score */
- if((s->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
- intra_score= (s->current_picture.mb_var[mb_x + mb_y*s->mb_stride]<<8) - 500; //FIXME dont scale it down so we dont have to fix it
- }else{
- uint8_t *dest_y;
-
- int mean= s->current_picture.mb_mean[mb_x + mb_y*s->mb_stride]; //FIXME
- mean*= 0x01010101;
-
- dest_y = s->new_picture.data[0] + (mb_y * 16 * s->linesize ) + mb_x * 16;
-
- for(i=0; i<16; i++){
- *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 0]) = mean;
- *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 4]) = mean;
- *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 8]) = mean;
- *(uint32_t*)(&s->me.scratchpad[i*s->linesize+12]) = mean;
- }
-
- s->mb_intra=1;
- intra_score= s->dsp.mb_cmp[0](s, s->me.scratchpad, dest_y, s->linesize);
-
-/* printf("intra:%7d inter:%7d var:%7d mc_var.%7d\n", intra_score>>8, inter_score>>8,
- s->current_picture.mb_var[mb_x + mb_y*s->mb_stride],
- s->current_picture.mc_mb_var[mb_x + mb_y*s->mb_stride]);*/
- }
-
- /* get chroma score */
- if(s->avctx->mb_cmp&FF_CMP_CHROMA){
- int i;
-
- s->mb_intra=1;
- for(i=1; i<3; i++){
- uint8_t *dest_c;
- int mean;
-
- if(s->out_format == FMT_H263){
- mean= (s->dc_val[i][mb_x + (mb_y+1)*(s->mb_width+2)] + 4)>>3; //FIXME not exact but simple ;)
- }else{
- mean= (s->last_dc[i] + 4)>>3;
- }
- dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
-
- mean*= 0x01010101;
- for(i=0; i<8; i++){
- *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 0]) = mean;
- *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 4]) = mean;
- }
-
- intra_score+= s->dsp.mb_cmp[1](s, s->me.scratchpad, dest_c, s->uvlinesize);
- }
- }
-
- /* bias */
- switch(s->avctx->mb_cmp&0xFF){
- default:
- case FF_CMP_SAD:
- intra_score+= 32*s->qscale;
- break;
- case FF_CMP_SSE:
- intra_score+= 24*s->qscale*s->qscale;
- break;
- case FF_CMP_SATD:
- intra_score+= 96*s->qscale;
- break;
- case FF_CMP_DCT:
- intra_score+= 48*s->qscale;
- break;
- case FF_CMP_BIT:
- intra_score+= 16;
- break;
- case FF_CMP_PSNR:
- case FF_CMP_RD:
- intra_score+= (s->qscale*s->qscale*109*8 + 64)>>7;
- break;
- }
-
- if(intra_score < inter_score)
- mb_type= MB_TYPE_INTRA;
- }
-
- s->mv_type=MV_TYPE_16X16;
- // only one MB-Type possible
-
- switch(mb_type){
- case MB_TYPE_INTRA:
- s->mv_dir = 0;
- s->mb_intra= 1;
- motion_x= s->mv[0][0][0] = 0;
- motion_y= s->mv[0][0][1] = 0;
- break;
- case MB_TYPE_INTER:
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra= 0;
- motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0];
- motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1];
- break;
- case MB_TYPE_INTER4V:
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_8X8;
- s->mb_intra= 0;
- for(i=0; i<4; i++){
- s->mv[0][i][0] = s->motion_val[s->block_index[i]][0];
- s->mv[0][i][1] = s->motion_val[s->block_index[i]][1];
- }
- motion_x= motion_y= 0;
- break;
- case MB_TYPE_DIRECT:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- s->mb_intra= 0;
- motion_x=s->b_direct_mv_table[xy][0];
- motion_y=s->b_direct_mv_table[xy][1];
-#ifdef CONFIG_RISKY
- ff_mpeg4_set_direct_mv(s, motion_x, motion_y);
-#endif
- break;
- case MB_TYPE_BIDIR:
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
- s->mb_intra= 0;
- motion_x=0;
- motion_y=0;
- s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0];
- s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1];
- s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0];
- s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1];
- break;
- case MB_TYPE_BACKWARD:
- s->mv_dir = MV_DIR_BACKWARD;
- s->mb_intra= 0;
- motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0];
- motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1];
- break;
- case MB_TYPE_FORWARD:
- s->mv_dir = MV_DIR_FORWARD;
- s->mb_intra= 0;
- motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0];
- motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1];
-// printf(" %d %d ", motion_x, motion_y);
- break;
- default:
- motion_x=motion_y=0; //gcc warning fix
- printf("illegal MB type\n");
- }
-
- encode_mb(s, motion_x, motion_y);
-
- // RAL: Update last macrobloc type
- s->last_mv_dir = s->mv_dir;
-
-#ifdef CONFIG_RISKY
- if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE)
- ff_h263_update_motion_val(s);
-#endif
-
- MPV_decode_mb(s, s->block);
- }
-
- /* clean the MV table in IPS frames for direct mode in B frames */
- if(s->mb_intra /* && I,P,S_TYPE */){
- s->p_mv_table[xy][0]=0;
- s->p_mv_table[xy][1]=0;
- }
-
- if(s->flags&CODEC_FLAG_PSNR){
- int w= 16;
- int h= 16;
-
- if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16;
- if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16;
-
- s->current_picture_ptr->error[0] += sse(
- s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16,
- s->dest[0], w, h, s->linesize);
- s->current_picture_ptr->error[1] += sse(
- s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
- s->dest[1], w>>1, h>>1, s->uvlinesize);
- s->current_picture_ptr->error[2] += sse(
- s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
- s->dest[2], w>>1, h>>1, s->uvlinesize);
- }
-//printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, get_bit_count(&s->pb));
- }
- }
- emms_c();
-
-#ifdef CONFIG_RISKY
- if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame)
- ff_mpeg4_merge_partitions(s);
-
- if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE)
- msmpeg4_encode_ext_header(s);
-
- if(s->codec_id==CODEC_ID_MPEG4)
- ff_mpeg4_stuffing(&s->pb);
-#endif
-
- //if (s->gob_number)
- // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number);
-
- /* Send the last GOB if RTP */
- if (s->rtp_mode) {
- flush_put_bits(&s->pb);
- pdif = pbBufPtr(&s->pb) - s->ptr_lastgob;
- /* Call the RTP callback to send the last GOB */
- if (s->rtp_callback)
- s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number);
- s->ptr_lastgob = pbBufPtr(&s->pb);
- //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif);
- }
-}
-
-static int dct_quantize_trellis_c(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow){
- const int *qmat;
- const uint8_t *scantable= s->intra_scantable.scantable;
- int max=0;
- unsigned int threshold1, threshold2;
- int bias=0;
- int run_tab[65];
- int level_tab[65];
- int score_tab[65];
- int last_run=0;
- int last_level=0;
- int last_score= 0;
- int last_i= 0;
- int coeff[3][64];
- int coeff_count[64];
- int lambda, qmul, qadd, start_i, last_non_zero, i, dc;
- const int esc_length= s->ac_esc_length;
- uint8_t * length;
- uint8_t * last_length;
- int score_limit=0;
- int left_limit= 0;
-
- s->dsp.fdct (block);
-
- qmul= qscale*16;
- qadd= ((qscale-1)|1)*8;
-
- if (s->mb_intra) {
- int q;
- if (!s->h263_aic) {
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- q = q << 3;
- } else{
- /* For AIC we skip quant/dequant of INTRADC */
- q = 1 << 3;
- qadd=0;
- }
-
- /* note: block[0] is assumed to be positive */
- block[0] = (block[0] + (q >> 1)) / q;
- start_i = 1;
- last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
- if(s->mpeg_quant || s->out_format == FMT_MPEG1)
- bias= 1<<(QMAT_SHIFT-1);
- length = s->intra_ac_vlc_length;
- last_length= s->intra_ac_vlc_last_length;
- } else {
- start_i = 0;
- last_non_zero = -1;
- qmat = s->q_inter_matrix[qscale];
- length = s->inter_ac_vlc_length;
- last_length= s->inter_ac_vlc_last_length;
- }
-
- threshold1= (1<<QMAT_SHIFT) - bias - 1;
- threshold2= (threshold1<<1);
-
- for(i=start_i; i<64; i++) {
- const int j = scantable[i];
- const int k= i-start_i;
- int level = block[j];
- level = level * qmat[j];
-
-// if( bias+level >= (1<<(QMAT_SHIFT - 3))
-// || bias-level >= (1<<(QMAT_SHIFT - 3))){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QMAT_SHIFT;
- coeff[0][k]= level;
- coeff[1][k]= level-1;
-// coeff[2][k]= level-2;
- }else{
- level= (bias - level)>>QMAT_SHIFT;
- coeff[0][k]= -level;
- coeff[1][k]= -level+1;
-// coeff[2][k]= -level+2;
- }
- coeff_count[k]= FFMIN(level, 2);
- max |=level;
- last_non_zero = i;
- }else{
- coeff[0][k]= (level>>31)|1;
- coeff_count[k]= 1;
- }
- }
-
- *overflow= s->max_qcoeff < max; //overflow might have happend
-
- if(last_non_zero < start_i){
- memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
- return last_non_zero;
- }
-
- lambda= (qscale*qscale*64*105 + 64)>>7; //FIXME finetune
-
- score_tab[0]= 0;
- for(i=0; i<=last_non_zero - start_i; i++){
- int level_index, run, j;
- const int dct_coeff= block[ scantable[i + start_i] ];
- const int zero_distoration= dct_coeff*dct_coeff;
- int best_score=256*256*256*120;
-
- last_score += zero_distoration;
- for(level_index=0; level_index < coeff_count[i]; level_index++){
- int distoration;
- int level= coeff[level_index][i];
- int unquant_coeff;
-
- assert(level);
-
- if(s->out_format == FMT_H263){
- if(level>0){
- unquant_coeff= level*qmul + qadd;
- }else{
- unquant_coeff= level*qmul - qadd;
- }
- }else{ //MPEG1
- j= s->dsp.idct_permutation[ scantable[i + start_i] ]; //FIXME optimize
- if(s->mb_intra){
- if (level < 0) {
- unquant_coeff = (int)((-level) * qscale * s->intra_matrix[j]) >> 3;
- unquant_coeff = -((unquant_coeff - 1) | 1);
- } else {
- unquant_coeff = (int)( level * qscale * s->intra_matrix[j]) >> 3;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }
- }else{
- if (level < 0) {
- unquant_coeff = ((((-level) << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4;
- unquant_coeff = -((unquant_coeff - 1) | 1);
- } else {
- unquant_coeff = ((( level << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }
- }
- unquant_coeff<<= 3;
- }
-
- distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff);
- level+=64;
- if((level&(~127)) == 0){
- for(run=0; run<=i - left_limit; run++){
- int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda;
- score += score_tab[i-run];
-
- if(score < best_score){
- best_score=
- score_tab[i+1]= score;
- run_tab[i+1]= run;
- level_tab[i+1]= level-64;
- }
- }
-
- if(s->out_format == FMT_H263){
- for(run=0; run<=i - left_limit; run++){
- int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda;
- score += score_tab[i-run];
- if(score < last_score){
- last_score= score;
- last_run= run;
- last_level= level-64;
- last_i= i+1;
- }
- }
- }
- }else{
- distoration += esc_length*lambda;
- for(run=0; run<=i - left_limit; run++){
- int score= distoration + score_tab[i-run];
-
- if(score < best_score){
- best_score=
- score_tab[i+1]= score;
- run_tab[i+1]= run;
- level_tab[i+1]= level-64;
- }
- }
-
- if(s->out_format == FMT_H263){
- for(run=0; run<=i - left_limit; run++){
- int score= distoration + score_tab[i-run];
- if(score < last_score){
- last_score= score;
- last_run= run;
- last_level= level-64;
- last_i= i+1;
- }
- }
- }
- }
- }
-
- for(j=left_limit; j<=i; j++){
- score_tab[j] += zero_distoration;
- }
- score_limit+= zero_distoration;
- if(score_tab[i+1] < score_limit)
- score_limit= score_tab[i+1];
-
- //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level
- while(score_tab[ left_limit ] > score_limit + lambda) left_limit++;
- }
-
- //FIXME add some cbp penalty
-
- if(s->out_format != FMT_H263){
- last_score= 256*256*256*120;
- for(i= left_limit; i<=last_non_zero - start_i + 1; i++){
- int score= score_tab[i];
- if(i) score += lambda*2; //FIXME exacter?
-
- if(score < last_score){
- last_score= score;
- last_i= i;
- last_level= level_tab[i];
- last_run= run_tab[i];
- }
- }
- }
-
- dc= block[0];
- last_non_zero= last_i - 1 + start_i;
- memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM));
-
- if(last_non_zero < start_i)
- return last_non_zero;
-
- if(last_non_zero == 0 && start_i == 0){
- int best_level= 0;
- int best_score= dc * dc;
-
- for(i=0; i<coeff_count[0]; i++){
- const int level= coeff[i][0];
- int unquant_coeff, score, distoration;
-
- if(s->out_format == FMT_H263){
- if(level>0){
- unquant_coeff= (level*qmul + qadd)>>3;
- }else{
- unquant_coeff= (level*qmul - qadd)>>3;
- }
- }else{ //MPEG1
- if (level < 0) {
- unquant_coeff = ((((-level) << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4;
- unquant_coeff = -((unquant_coeff - 1) | 1);
- } else {
- unquant_coeff = ((( level << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4;
- unquant_coeff = (unquant_coeff - 1) | 1;
- }
- }
- unquant_coeff = (unquant_coeff + 4) >> 3;
- unquant_coeff<<= 3 + 3;
-
- distoration= (unquant_coeff - dc) * (unquant_coeff - dc);
- score= distoration + last_length[UNI_AC_ENC_INDEX(0, level+64)]*lambda;
- if(score < best_score){
- best_score= score;
- best_level= level;
- }
- }
- block[0]= best_level;
- if(best_level == 0)
- last_non_zero=-1;
- return last_non_zero;
- }
-
- i= last_i;
- assert(last_level);
-//FIXME use permutated scantable
- block[ s->dsp.idct_permutation[ scantable[last_non_zero] ] ]= last_level;
- i -= last_run + 1;
-
- for(;i>0 ; i -= run_tab[i] + 1){
- const int j= s->dsp.idct_permutation[ scantable[i - 1 + start_i] ];
-
- block[j]= level_tab[i];
- assert(block[j]);
- }
-
- return last_non_zero;
-}
-
-static int dct_quantize_c(MpegEncContext *s,
- DCTELEM *block, int n,
- int qscale, int *overflow)
-{
- int i, j, level, last_non_zero, q;
- const int *qmat;
- const uint8_t *scantable= s->intra_scantable.scantable;
- int bias;
- int max=0;
- unsigned int threshold1, threshold2;
-
- s->dsp.fdct (block);
-
- if (s->mb_intra) {
- if (!s->h263_aic) {
- if (n < 4)
- q = s->y_dc_scale;
- else
- q = s->c_dc_scale;
- q = q << 3;
- } else
- /* For AIC we skip quant/dequant of INTRADC */
- q = 1 << 3;
-
- /* note: block[0] is assumed to be positive */
- block[0] = (block[0] + (q >> 1)) / q;
- i = 1;
- last_non_zero = 0;
- qmat = s->q_intra_matrix[qscale];
- bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
- } else {
- i = 0;
- last_non_zero = -1;
- qmat = s->q_inter_matrix[qscale];
- bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT);
- }
- threshold1= (1<<QMAT_SHIFT) - bias - 1;
- threshold2= (threshold1<<1);
-
- for(;i<64;i++) {
- j = scantable[i];
- level = block[j];
- level = level * qmat[j];
-
-// if( bias+level >= (1<<QMAT_SHIFT)
-// || bias-level >= (1<<QMAT_SHIFT)){
- if(((unsigned)(level+threshold1))>threshold2){
- if(level>0){
- level= (bias + level)>>QMAT_SHIFT;
- block[j]= level;
- }else{
- level= (bias - level)>>QMAT_SHIFT;
- block[j]= -level;
- }
- max |=level;
- last_non_zero = i;
- }else{
- block[j]=0;
- }
- }
- *overflow= s->max_qcoeff < max; //overflow might have happend
-
- /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */
- if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM)
- ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero);
-
- return last_non_zero;
-}
-
-#endif //CONFIG_ENCODERS
-
-static void dct_unquantize_mpeg1_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
-
- nCoeffs= s->block_last_index[n];
-
- if (s->mb_intra) {
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- /* XXX: only mpeg1 */
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = (level - 1) | 1;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = (level - 1) | 1;
- }
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- block[j] = level;
- }
- }
- } else {
- i = 0;
- quant_matrix = s->inter_matrix;
- for(;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = (level - 1) | 1;
- level = -level;
- } else {
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = (level - 1) | 1;
- }
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- block[j] = level;
- }
- }
- }
-}
-
-static void dct_unquantize_mpeg2_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, nCoeffs;
- const uint16_t *quant_matrix;
-
- if(s->alternate_scan) nCoeffs= 63;
- else nCoeffs= s->block_last_index[n];
-
- if (s->mb_intra) {
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- quant_matrix = s->intra_matrix;
- for(i=1;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- level = -level;
- } else {
- level = (int)(level * qscale * quant_matrix[j]) >> 3;
- }
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- block[j] = level;
- }
- }
- } else {
- int sum=-1;
- i = 0;
- quant_matrix = s->inter_matrix;
- for(;i<=nCoeffs;i++) {
- int j= s->intra_scantable.permutated[i];
- level = block[j];
- if (level) {
- if (level < 0) {
- level = -level;
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- level = -level;
- } else {
- level = (((level << 1) + 1) * qscale *
- ((int) (quant_matrix[j]))) >> 4;
- }
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- block[j] = level;
- sum+=level;
- }
- }
- block[63]^=sum&1;
- }
-}
-
-
-static void dct_unquantize_h263_c(MpegEncContext *s,
- DCTELEM *block, int n, int qscale)
-{
- int i, level, qmul, qadd;
- int nCoeffs;
-
- assert(s->block_last_index[n]>=0);
-
- qadd = (qscale - 1) | 1;
- qmul = qscale << 1;
-
- if (s->mb_intra) {
- if (!s->h263_aic) {
- if (n < 4)
- block[0] = block[0] * s->y_dc_scale;
- else
- block[0] = block[0] * s->c_dc_scale;
- }else
- qadd = 0;
- i = 1;
- nCoeffs= 63; //does not allways use zigzag table
- } else {
- i = 0;
- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
- }
-
- for(;i<=nCoeffs;i++) {
- level = block[i];
- if (level) {
- if (level < 0) {
- level = level * qmul - qadd;
- } else {
- level = level * qmul + qadd;
- }
-#ifdef PARANOID
- if (level < -2048 || level > 2047)
- fprintf(stderr, "unquant error %d %d\n", i, level);
-#endif
- block[i] = level;
- }
- }
-}
-
-
-static const AVOption mpeg4_options[] =
-{
- AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000),
- AVOPTION_CODEC_INT("ratetol", "number of bits the bitstream is allowed to diverge from the reference"
- "the reference can be CBR (for CBR pass1) or VBR (for pass2)",
- bit_rate_tolerance, 4, 240000000, 8000),
- AVOPTION_CODEC_INT("qmin", "minimum quantizer", qmin, 1, 31, 2),
- AVOPTION_CODEC_INT("qmax", "maximum quantizer", qmax, 1, 31, 31),
- AVOPTION_CODEC_STRING("rc_eq", "rate control equation",
- rc_eq, "tex^qComp,option1,options2", 0),
- AVOPTION_CODEC_INT("rc_minrate", "rate control minimum bitrate",
- rc_min_rate, 4, 24000000, 0),
- AVOPTION_CODEC_INT("rc_maxrate", "rate control maximum bitrate",
- rc_max_rate, 4, 24000000, 0),
- AVOPTION_CODEC_DOUBLE("rc_buf_aggresivity", "rate control buffer aggresivity",
- rc_buffer_aggressivity, 4, 24000000, 0),
- AVOPTION_CODEC_DOUBLE("rc_initial_cplx", "initial complexity for pass1 ratecontrol",
- rc_initial_cplx, 0., 9999999., 0),
- AVOPTION_CODEC_DOUBLE("i_quant_factor", "qscale factor between p and i frames",
- i_quant_factor, 0., 0., 0),
- AVOPTION_CODEC_DOUBLE("i_quant_offset", "qscale offset between p and i frames",
- i_quant_factor, -999999., 999999., 0),
- AVOPTION_CODEC_INT("dct_algo", "dct alghorithm",
- dct_algo, 0, 5, 0), // fixme - "Auto,FastInt,Int,MMX,MLib,Altivec"
- AVOPTION_CODEC_DOUBLE("lumi_masking", "luminance masking",
- lumi_masking, 0., 999999., 0),
- AVOPTION_CODEC_DOUBLE("temporal_cplx_masking", "temporary complexity masking",
- temporal_cplx_masking, 0., 999999., 0),
- AVOPTION_CODEC_DOUBLE("spatial_cplx_masking", "spatial complexity masking",
- spatial_cplx_masking, 0., 999999., 0),
- AVOPTION_CODEC_DOUBLE("p_masking", "p block masking",
- p_masking, 0., 999999., 0),
- AVOPTION_CODEC_DOUBLE("dark_masking", "darkness masking",
- dark_masking, 0., 999999., 0),
- AVOPTION_CODEC_INT("idct_algo", "idct alghorithm",
- idct_algo, 0, 8, 0), // fixme - "Auto,Int,Simple,SimpleMMX,LibMPEG2MMX,PS2,MLib,ARM,Altivec"
-
- AVOPTION_CODEC_INT("mb_qmin", "minimum MB quantizer",
- mb_qmin, 0, 8, 0),
- AVOPTION_CODEC_INT("mb_qmax", "maximum MB quantizer",
- mb_qmin, 0, 8, 0),
-
- AVOPTION_CODEC_INT("me_cmp", "ME compare function",
- me_cmp, 0, 24000000, 0),
- AVOPTION_CODEC_INT("me_sub_cmp", "subpixel ME compare function",
- me_sub_cmp, 0, 24000000, 0),
-
-
- AVOPTION_CODEC_INT("dia_size", "ME diamond size & shape",
- dia_size, 0, 24000000, 0),
- AVOPTION_CODEC_INT("last_predictor_count", "amount of previous MV predictors",
- last_predictor_count, 0, 24000000, 0),
-
- AVOPTION_CODEC_INT("pre_me", "pre pass for ME",
- pre_me, 0, 24000000, 0),
- AVOPTION_CODEC_INT("me_pre_cmp", "ME pre pass compare function",
- me_pre_cmp, 0, 24000000, 0),
-
- AVOPTION_CODEC_INT("me_range", "maximum ME search range",
- me_range, 0, 24000000, 0),
- AVOPTION_CODEC_INT("pre_dia_size", "ME pre pass diamod size & shape",
- pre_dia_size, 0, 24000000, 0),
- AVOPTION_CODEC_INT("me_subpel_quality", "subpel ME quality",
- me_subpel_quality, 0, 24000000, 0),
- AVOPTION_CODEC_INT("me_range", "maximum ME search range",
- me_range, 0, 24000000, 0),
- AVOPTION_CODEC_FLAG("psnr", "calculate PSNR of compressed frames",
- flags, CODEC_FLAG_PSNR, 0),
- AVOPTION_CODEC_RCOVERRIDE("rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)",
- rc_override),
- AVOPTION_SUB(avoptions_common),
- AVOPTION_END()
-};
-
-#ifdef CONFIG_ENCODERS
-
-AVCodec mpeg1video_encoder = {
- "mpeg1video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG1VIDEO,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-#ifdef CONFIG_RISKY
-
-AVCodec mpeg2video_encoder = {
- "mpeg2video",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG2VIDEO,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-AVCodec h263_encoder = {
- "h263",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-AVCodec h263p_encoder = {
- "h263p",
- CODEC_TYPE_VIDEO,
- CODEC_ID_H263P,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-AVCodec flv_encoder = {
- "flv",
- CODEC_TYPE_VIDEO,
- CODEC_ID_FLV1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-AVCodec rv10_encoder = {
- "rv10",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-AVCodec mpeg4_encoder = {
- "mpeg4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MPEG4,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .options = mpeg4_options,
-};
-
-AVCodec msmpeg4v1_encoder = {
- "msmpeg4v1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .options = mpeg4_options,
-};
-
-AVCodec msmpeg4v2_encoder = {
- "msmpeg4v2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V2,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .options = mpeg4_options,
-};
-
-AVCodec msmpeg4v3_encoder = {
- "msmpeg4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MSMPEG4V3,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .options = mpeg4_options,
-};
-
-AVCodec wmv1_encoder = {
- "wmv1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV1,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
- .options = mpeg4_options,
-};
-
-#endif
-
-AVCodec mjpeg_encoder = {
- "mjpeg",
- CODEC_TYPE_VIDEO,
- CODEC_ID_MJPEG,
- sizeof(MpegEncContext),
- MPV_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-
-#endif //CONFIG_ENCODERS
-
+++ /dev/null
-/*
- * Generic DCT based hybrid video encoder
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file mpegvideo.h
- * mpegvideo header.
- */
-
-#ifndef AVCODEC_MPEGVIDEO_H
-#define AVCODEC_MPEGVIDEO_H
-
-#include "dsputil.h"
-
-#define FRAME_SKIPED 100 ///< return value for header parsers if frame is not coded
-
-enum OutputFormat {
- FMT_MPEG1,
- FMT_H263,
- FMT_MJPEG,
- FMT_H264,
-};
-
-#define EDGE_WIDTH 16
-
-#define MPEG_BUF_SIZE (16 * 1024)
-
-#define QMAT_SHIFT_MMX 16
-#define QMAT_SHIFT 22
-
-#define MAX_FCODE 7
-#define MAX_MV 2048
-
-#define MAX_PICTURE_COUNT 15
-
-#define ME_MAP_SIZE 64
-#define ME_MAP_SHIFT 3
-#define ME_MAP_MV_BITS 11
-
-/* run length table */
-#define MAX_RUN 64
-#define MAX_LEVEL 64
-
-#define I_TYPE FF_I_TYPE ///< Intra
-#define P_TYPE FF_P_TYPE ///< Predicted
-#define B_TYPE FF_B_TYPE ///< Bi-dir predicted
-#define S_TYPE FF_S_TYPE ///< S(GMC)-VOP MPEG4
-#define SI_TYPE FF_SI_TYPE ///< Switching Intra
-#define SP_TYPE FF_SP_TYPE ///< Switching Predicted
-
-typedef struct Predictor{
- double coeff;
- double count;
- double decay;
-} Predictor;
-
-typedef struct RateControlEntry{
- int pict_type;
- float qscale;
- int mv_bits;
- int i_tex_bits;
- int p_tex_bits;
- int misc_bits;
- uint64_t expected_bits;
- int new_pict_type;
- float new_qscale;
- int mc_mb_var_sum;
- int mb_var_sum;
- int i_count;
- int f_code;
- int b_code;
-}RateControlEntry;
-
-/**
- * rate control context.
- */
-typedef struct RateControlContext{
- FILE *stats_file;
- int num_entries; ///< number of RateControlEntries
- RateControlEntry *entry;
- int buffer_index; ///< amount of bits in the video/audio buffer
- Predictor pred[5];
- double short_term_qsum; ///< sum of recent qscales
- double short_term_qcount; ///< count of recent qscales
- double pass1_rc_eq_output_sum;///< sum of the output of the rc equation, this is used for normalization
- double pass1_wanted_bits; ///< bits which should have been outputed by the pass1 code (including complexity init)
- double last_qscale;
- double last_qscale_for[5]; ///< last qscale for a specific pict type, used for max_diff & ipb factor stuff
- int last_mc_mb_var_sum;
- int last_mb_var_sum;
- uint64_t i_cplx_sum[5];
- uint64_t p_cplx_sum[5];
- uint64_t mv_bits_sum[5];
- uint64_t qscale_sum[5];
- int frame_count[5];
- int last_non_b_pict_type;
-}RateControlContext;
-
-/**
- * Scantable.
- */
-typedef struct ScanTable{
- const uint8_t *scantable;
- uint8_t permutated[64];
- uint8_t raster_end[64];
-#ifdef ARCH_POWERPC
- /** Used by dct_quantise_alitvec to find last-non-zero */
- uint8_t __align8 inverse[64];
-#endif
-} ScanTable;
-
-/**
- * Picture.
- */
-typedef struct Picture{
- FF_COMMON_FRAME
-
- /**
- * halfpel luma planes.
- */
- uint8_t *interpolated[3];
-
- int16_t (*motion_val[2])[2];
- int8_t *ref_index[2];
- uint32_t *mb_type_base;
- uint32_t *mb_type; ///< mb_type_base + mb_width + 2, note: only used for decoding currently
-#define MB_TYPE_INTRA4x4 0x0001
-#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific
-#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific
-#define MB_TYPE_16x16 0x0008
-#define MB_TYPE_16x8 0x0010
-#define MB_TYPE_8x16 0x0020
-#define MB_TYPE_8x8 0x0040
-#define MB_TYPE_INTERLACED 0x0080
-#define MB_TYPE_DIRECT2 0x0100 //FIXME
-#define MB_TYPE_ACPRED 0x0200
-#define MB_TYPE_GMC 0x0400 //FIXME mpeg4 specific
-#define MB_TYPE_SKIP 0x0800
-#define MB_TYPE_P0L0 0x1000
-#define MB_TYPE_P1L0 0x2000
-#define MB_TYPE_P0L1 0x4000
-#define MB_TYPE_P1L1 0x8000
-#define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0)
-#define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1)
-#define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1)
-#define MB_TYPE_QUANT 0x00010000
-//Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 pat, ...)
-
-#define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4)
-#define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16)
-#define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
-#define IS_INTRA(a) ((a)&7)
-#define IS_INTER(a) ((a)&(MB_TYPE_16x16|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8))
-#define IS_SKIP(a) ((a)&MB_TYPE_SKIP)
-#define IS_INTRA_PCM(a) ((a)&MB_TYPE_INTRA_PCM)
-#define IS_INTERLACED(a) ((a)&MB_TYPE_INTERLACED)
-#define IS_DIRECT(a) ((a)&MB_TYPE_DIRECT2)
-#define IS_GMC(a) ((a)&MB_TYPE_GMC)
-#define IS_16X16(a) ((a)&MB_TYPE_16x16)
-#define IS_16X8(a) ((a)&MB_TYPE_16x8)
-#define IS_8X16(a) ((a)&MB_TYPE_8x16)
-#define IS_8X8(a) ((a)&MB_TYPE_8x8)
-#define IS_SUB_8X8(a) ((a)&MB_TYPE_16x16) //note reused
-#define IS_SUB_8X4(a) ((a)&MB_TYPE_16x8) //note reused
-#define IS_SUB_4X8(a) ((a)&MB_TYPE_8x16) //note reused
-#define IS_SUB_4X4(a) ((a)&MB_TYPE_8x8) //note reused
-#define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED)
-#define IS_QUANT(a) ((a)&MB_TYPE_QUANT)
-#define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list))))
-#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs
-
-
- int field_poc[2]; ///< h264 top/bottom POC
- int poc; ///< h264 frame POC
- int frame_num; ///< h264 frame_num
- int pic_id; ///< h264 pic_num or long_term_pic_idx
- int long_ref; ///< 1->long term reference 0->short term reference
-
- int mb_var_sum; ///< sum of MB variance for current frame
- int mc_mb_var_sum; ///< motion compensated MB variance for current frame
- uint16_t *mb_var; ///< Table for MB variances
- uint16_t *mc_mb_var; ///< Table for motion compensated MB variances
- uint8_t *mb_mean; ///< Table for MB luminance
- int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decission
- int b_frame_score; /* */
-} Picture;
-
-typedef struct ParseContext{
- uint8_t *buffer;
- int index;
- int last_index;
- int buffer_size;
- uint32_t state; ///< contains the last few bytes in MSB order
- int frame_start_found;
- int overread; ///< the number of bytes which where irreversibly read from the next frame
- int overread_index; ///< the index into ParseContext.buffer of the overreaded bytes
-} ParseContext;
-
-struct MpegEncContext;
-
-/**
- * Motion estimation context.
- */
-typedef struct MotionEstContext{
- int skip; ///< set if ME is skiped for the current MB
- int co_located_mv[4][2]; ///< mv from last p frame for direct mode ME
- int direct_basis_mv[4][2];
- uint8_t *scratchpad; ///< data area for the me algo, so that the ME doesnt need to malloc/free
- uint32_t *map; ///< map to avoid duplicate evaluations
- uint32_t *score_map; ///< map to store the scores
- int map_generation;
- int pre_penalty_factor;
- int penalty_factor;
- int sub_penalty_factor;
- int mb_penalty_factor;
- int pre_pass; ///< = 1 for the pre pass
- int dia_size;
- uint8_t (*mv_penalty)[MAX_MV*2+1]; ///< amount of bits needed to encode a MV
- int (*sub_motion_search)(struct MpegEncContext * s,
- int *mx_ptr, int *my_ptr, int dmin,
- int xmin, int ymin, int xmax, int ymax,
- int pred_x, int pred_y, Picture *ref_picture,
- int n, int size, uint8_t * const mv_penalty);
- int (*motion_search[7])(struct MpegEncContext * s, int block,
- int *mx_ptr, int *my_ptr,
- int P[10][2], int pred_x, int pred_y,
- int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2],
- int ref_mv_scale, uint8_t * const mv_penalty);
- int (*pre_motion_search)(struct MpegEncContext * s, int block,
- int *mx_ptr, int *my_ptr,
- int P[10][2], int pred_x, int pred_y,
- int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2],
- int ref_mv_scale, uint8_t * const mv_penalty);
- int (*get_mb_score)(struct MpegEncContext * s, int mx, int my, int pred_x, int pred_y, Picture *ref_picture,
- uint8_t * const mv_penalty);
-}MotionEstContext;
-
-/**
- * MpegEncContext.
- */
-typedef struct MpegEncContext {
- struct AVCodecContext *avctx;
- /* the following parameters must be initialized before encoding */
- int width, height;///< picture size. must be a multiple of 16
- int gop_size;
- int intra_only; ///< if true, only intra pictures are generated
- int bit_rate; ///< wanted bit rate
- int bit_rate_tolerance; ///< amount of +- bits (>0)
- enum OutputFormat out_format; ///< output format
- int h263_pred; ///< use mpeg4/h263 ac/dc predictions
-
-/* the following codec id fields are deprecated in favor of codec_id */
- int h263_plus; ///< h263 plus headers
- int h263_rv10; ///< use RV10 variation for H263
- int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
- int h263_intel; ///< use I263 intel h263 header
- int h263_flv; ///< use flv h263 header
-
- int codec_id; /* see CODEC_ID_xxx */
- int fixed_qscale; ///< fixed qscale if non zero
- float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0)
- float qblur; ///< amount of qscale smoothing over time (0.0-1.0)
- int max_qdiff; ///< max qscale difference between frames
- int encoding; ///< true if we are encoding (vs decoding)
- int flags; ///< AVCodecContext.flags (HQ, MV4, ...)
- int max_b_frames; ///< max number of b-frames for encoding
- int b_frame_strategy;
- int luma_elim_threshold;
- int chroma_elim_threshold;
- int strict_std_compliance; ///< strictly follow the std (MPEG4, ...)
- int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
- /* the following fields are managed internally by the encoder */
-
- /** bit output */
- PutBitContext pb;
-
- /* sequence parameters */
- int context_initialized;
- int input_picture_number;
- int picture_number;
- int picture_in_gop_number; ///< 0-> first pic in gop, ...
- int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input
- int mb_width, mb_height; ///< number of MBs horizontally & vertically
- int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressng of left & top MBs withoutt sig11
- int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replicateion)
- int mb_num; ///< number of MBs of a picture
- int linesize; ///< line size, in bytes, may be different from width
- int uvlinesize; ///< line size, for chroma in bytes, may be different from width
- Picture picture[MAX_PICTURE_COUNT]; ///< main picture buffer
- Picture *input_picture[MAX_PICTURE_COUNT]; ///< next pictures on display order for encoding
- Picture *reordered_input_picture[MAX_PICTURE_COUNT]; ///< pointer to the next pictures in codedorder for encoding
-
- /**
- * copy of the previous picture structure.
- * note, linesize & data, might not match the previous picture (for field pictures)
- */
- Picture last_picture;
-
- /**
- * copy of the next picture structure.
- * note, linesize & data, might not match the next picture (for field pictures)
- */
- Picture next_picture;
-
- /**
- * copy of the source picture structure for encoding.
- * note, linesize & data, might not match the source picture (for field pictures)
- */
- Picture new_picture;
-
- /**
- * copy of the current picture structure.
- * note, linesize & data, might not match the current picture (for field pictures)
- */
- Picture current_picture; ///< buffer to store the decompressed current picture
-
- Picture *last_picture_ptr; ///< pointer to the previous picture.
- Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
- Picture *new_picture_ptr; ///< pointer to the source picture for encoding
- Picture *current_picture_ptr; ///< pointer to the current picture
- int last_dc[3]; ///< last DC values for MPEG1
- int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
- int16_t dc_cache[4*5];
- int y_dc_scale, c_dc_scale;
- uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
- uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table
- uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
- int16_t (*ac_val[3])[16]; ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
- int ac_pred;
- uint8_t *prev_pict_types; ///< previous picture types in bitstream order, used for mb skip
-#define PREV_PICT_TYPES_BUFFER_SIZE 256
- int mb_skiped; ///< MUST BE SET only during DECODING
- uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example)
- and used for b-frame encoding & decoding (contains skip table of next P Frame) */
- uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
- uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding
- uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding
- uint8_t *allocated_edge_emu_buffer;
- uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer
-
- int qscale; ///< QP
- float frame_qscale; ///< qscale from the frame level rc FIXME remove
- int adaptive_quant; ///< use adaptive quantization
- int dquant; ///< qscale difference to prev qscale
- int pict_type; ///< I_TYPE, P_TYPE, B_TYPE, ...
- int last_pict_type;
- int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol
- int frame_rate_index;
- /* motion compensation */
- int unrestricted_mv; ///< mv can point outside of the coded picture
- int h263_long_vectors; ///< use horrible h263v1 long vector mode
- int decode; ///< if 0 then decoding will be skiped (for encoding b frames for example)
-
- DSPContext dsp; ///< pointers for accelerated dsp fucntions
- int f_code; ///< forward MV resolution
- int b_code; ///< backward MV resolution for B Frames (mpeg4)
- int16_t (*motion_val)[2];
- int16_t (*p_mv_table_base)[2];
- int16_t (*b_forw_mv_table_base)[2];
- int16_t (*b_back_mv_table_base)[2];
- int16_t (*b_bidir_forw_mv_table_base)[2];
- int16_t (*b_bidir_back_mv_table_base)[2];
- int16_t (*b_direct_mv_table_base)[2];
- int16_t (*p_mv_table)[2]; ///< MV table (1MV per MB) p-frame encoding
- int16_t (*b_forw_mv_table)[2]; ///< MV table (1MV per MB) forward mode b-frame encoding
- int16_t (*b_back_mv_table)[2]; ///< MV table (1MV per MB) backward mode b-frame encoding
- int16_t (*b_bidir_forw_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
- int16_t (*b_bidir_back_mv_table)[2]; ///< MV table (1MV per MB) bidir mode b-frame encoding
- int16_t (*b_direct_mv_table)[2]; ///< MV table (1MV per MB) direct mode b-frame encoding
- int me_method; ///< ME algorithm
- int scene_change_score;
- int mv_dir;
-#define MV_DIR_BACKWARD 1
-#define MV_DIR_FORWARD 2
-#define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4)
- int mv_type;
-#define MV_TYPE_16X16 0 ///< 1 vector for the whole mb
-#define MV_TYPE_8X8 1 ///< 4 vectors (h263, mpeg4 4MV)
-#define MV_TYPE_16X8 2 ///< 2 vectors, one per 16x8 block
-#define MV_TYPE_FIELD 3 ///< 2 vectors, one per field
-#define MV_TYPE_DMV 4 ///< 2 vectors, special mpeg2 Dual Prime Vectors
- /**motion vectors for a macroblock
- first coordinate : 0 = forward 1 = backward
- second " : depend on type
- third " : 0 = x, 1 = y
- */
- int mv[2][4][2];
- int field_select[2][2];
- int last_mv[2][2][2]; ///< last MV, used for MV prediction in MPEG1 & B-frame MPEG4
- uint8_t *fcode_tab; ///< smallest fcode needed for each MV
-
- MotionEstContext me;
-
- int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...)
- for b-frames rounding mode is allways 0 */
-
- int hurry_up; /**< when set to 1 during decoding, b frames will be skiped
- when set to 2 idct/dequant will be skipped too */
-
- /* macroblock layer */
- int mb_x, mb_y;
- int mb_skip_run;
- int mb_intra;
- uint8_t *mb_type; ///< Table for MB type FIXME remove and use picture->mb_type
-#define MB_TYPE_INTRA 0x01
-#define MB_TYPE_INTER 0x02
-#define MB_TYPE_INTER4V 0x04
-#define MB_TYPE_SKIPED 0x08
-//#define MB_TYPE_GMC 0x10
-
-#define MB_TYPE_DIRECT 0x10
-#define MB_TYPE_FORWARD 0x20
-#define MB_TYPE_BACKWARD 0x40
-#define MB_TYPE_BIDIR 0x80
-
- int block_index[6]; ///< index to current MB in block based arrays with edges
- int block_wrap[6];
- uint8_t *dest[3];
-
- int *mb_index2xy; ///< mb_index -> mb_x + mb_y*mb_stride
-
- /** matrix transmitted in the bitstream */
- uint16_t intra_matrix[64];
- uint16_t chroma_intra_matrix[64];
- uint16_t inter_matrix[64];
- uint16_t chroma_inter_matrix[64];
-#define QUANT_BIAS_SHIFT 8
- int intra_quant_bias; ///< bias for the quantizer
- int inter_quant_bias; ///< bias for the quantizer
- int min_qcoeff; ///< minimum encodable coefficient
- int max_qcoeff; ///< maximum encodable coefficient
- int ac_esc_length; ///< num of bits needed to encode the longest esc
- uint8_t *intra_ac_vlc_length;
- uint8_t *intra_ac_vlc_last_length;
- uint8_t *inter_ac_vlc_length;
- uint8_t *inter_ac_vlc_last_length;
- uint8_t *luma_dc_vlc_length;
- uint8_t *chroma_dc_vlc_length;
-#define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
-
- /** precomputed matrix (combine qscale and DCT renorm) */
- int __align8 q_intra_matrix[32][64];
- int __align8 q_inter_matrix[32][64];
- /** identical to the above but for MMX & these are not permutated */
- uint16_t __align8 q_intra_matrix16[32][64];
- uint16_t __align8 q_inter_matrix16[32][64];
- uint16_t __align8 q_intra_matrix16_bias[32][64];
- uint16_t __align8 q_inter_matrix16_bias[32][64];
- int block_last_index[6]; ///< last non zero coefficient in block
- /* scantables */
- ScanTable __align8 intra_scantable;
- ScanTable intra_h_scantable;
- ScanTable intra_v_scantable;
- ScanTable inter_scantable; ///< if inter == intra then intra should be used to reduce tha cache usage
-
- void *opaque; ///< private data for the user
-
- /* bit rate control */
- int I_frame_bits; //FIXME used in mpeg12 ...
- int64_t wanted_bits;
- int64_t total_bits;
- int frame_bits; ///< bits used for the current frame
- RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
-
- /* statistics, used for 2-pass encoding */
- int mv_bits;
- int header_bits;
- int i_tex_bits;
- int p_tex_bits;
- int i_count;
- int f_count;
- int b_count;
- int skip_count;
- int misc_bits; ///< cbp, mb_type
- int last_bits; ///< temp var used for calculating the above vars
-
- /* error concealment / resync */
- int error_count;
- uint8_t *error_status_table; ///< table of the error status of each MB
-#define VP_START 1 ///< current MB is the first after a resync marker
-#define AC_ERROR 2
-#define DC_ERROR 4
-#define MV_ERROR 8
-#define AC_END 16
-#define DC_END 32
-#define MV_END 64
-//FIXME some prefix?
-
- int resync_mb_x; ///< x position of last resync marker
- int resync_mb_y; ///< y position of last resync marker
- GetBitContext last_resync_gb; ///< used to search for the next resync marker
- int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
- int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed b frames
- int error_resilience;
-
- ParseContext parse_context;
-
- /* H.263 specific */
- int gob_number;
- int gob_index;
-
- /* H.263+ specific */
- int umvplus; ///< == H263+ && unrestricted_mv
- int h263_aic; ///< Advanded INTRA Coding (AIC)
- int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
-
- /* mpeg4 specific */
- int time_increment_resolution;
- int time_increment_bits; ///< number of bits to represent the fractional part of time
- int last_time_base;
- int time_base; ///< time in seconds of last I,P,S Frame
- int64_t time; ///< time of current frame
- int64_t last_non_b_time;
- uint16_t pp_time; ///< time distance between the last 2 p,s,i frames
- uint16_t pb_time; ///< time distance between the last b and p,s,i frame
- uint16_t pp_field_time;
- uint16_t pb_field_time; ///< like above, just for interlaced
- int shape;
- int vol_sprite_usage;
- int sprite_width;
- int sprite_height;
- int sprite_left;
- int sprite_top;
- int sprite_brightness_change;
- int num_sprite_warping_points;
- int real_sprite_warping_points;
- int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY]
- int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY]
- int sprite_shift[2]; ///< sprite shift [isChroma]
- int mcsel;
- int quant_precision;
- int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
- int scalability;
- int hierachy_type;
- int enhancement_type;
- int new_pred;
- int reduced_res_vop;
- int aspect_ratio_info; //FIXME remove
- int aspected_width; //FIXME remove
- int aspected_height; //FIXME remove
- int sprite_warping_accuracy;
- int low_latency_sprite;
- int data_partitioning; ///< data partitioning flag from header
- int partitioned_frame; ///< is current frame partitioned
- int rvlc; ///< reversible vlc
- int resync_marker; ///< could this stream contain resync markers
- int low_delay; ///< no reordering needed / has no b-frames
- int vo_type;
- int vol_control_parameters; ///< does the stream contain the low_delay flag, used to workaround buggy encoders
- PutBitContext tex_pb; ///< used for data partitioned VOPs
- PutBitContext pb2; ///< used for data partitioned VOPs
-#define PB_BUFFER_SIZE 1024*256
- uint8_t *tex_pb_buffer;
- uint8_t *pb2_buffer;
- int mpeg_quant;
- int16_t (*field_mv_table)[2][2]; ///< used for interlaced b frame decoding
- int8_t (*field_select_table)[2]; ///< wtf, no really another table for interlaced b frames
- int t_frame; ///< time distance of first I -> B, used for interlaced b frames
- int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG4
-
- /* divx specific, used to workaround (many) bugs in divx5 */
- int divx_version;
- int divx_build;
- int divx_packed;
-#define BITSTREAM_BUFFER_SIZE 1024*256
- uint8_t *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
- int bitstream_buffer_size;
-
- int xvid_build;
-
- /* lavc specific stuff, used to workaround bugs in libavcodec */
- int ffmpeg_version;
- int lavc_build;
-
- /* RV10 specific */
- int rv10_version; ///< RV10 version: 0 or 3
- int rv10_first_dc_coded[3];
-
- /* MJPEG specific */
- struct MJpegContext *mjpeg_ctx;
- int mjpeg_vsample[3]; ///< vertical sampling factors, default = {2, 1, 1}
- int mjpeg_hsample[3]; ///< horizontal sampling factors, default = {2, 1, 1}
- int mjpeg_write_tables; ///< do we want to have quantisation- and huffmantables in the jpeg file ?
- int mjpeg_data_only_frames; ///< frames only with SOI, SOS and EOI markers
-
- /* MSMPEG4 specific */
- int mv_table_index;
- int rl_table_index;
- int rl_chroma_table_index;
- int dc_table_index;
- int use_skip_mb_code;
- int slice_height; ///< in macroblocks
- int first_slice_line; ///< used in mpeg4 too to handle resync markers
- int flipflop_rounding;
- int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
- int per_mb_rl_table;
- int esc3_level_length;
- int esc3_run_length;
- /** [mb_intra][isChroma][level][run][last] */
- int (*ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2];
- int inter_intra_pred;
- int mspel;
-
- /* decompression specific */
- GetBitContext gb;
-
- /* Mpeg1 specific */
- int fake_picture_number; ///< picture number at the bitstream frame rate
- int gop_picture_number; ///< index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
- int last_mv_dir; ///< last mv_dir, used for b frame encoding
- int broken_link; ///< no_output_of_prior_pics_flag
-
- /* MPEG2 specific - I wish I had not to support this mess. */
- int progressive_sequence;
- int mpeg_f_code[2][2];
- int picture_structure;
-/* picture type */
-#define PICT_TOP_FIELD 1
-#define PICT_BOTTOM_FIELD 2
-#define PICT_FRAME 3
-
- int intra_dc_precision;
- int frame_pred_frame_dct;
- int top_field_first;
- int concealment_motion_vectors;
- int q_scale_type;
- int intra_vlc_format;
- int alternate_scan;
- int repeat_first_field;
- int chroma_420_type;
- int progressive_frame;
- int full_pel[2];
- int interlaced_dct;
- int first_slice;
- int first_field; ///< is 1 for the first field of a field picture 0 otherwise
-
- /* RTP specific */
- /* These are explained on avcodec.h */
- int rtp_mode;
- int rtp_payload_size;
- void (*rtp_callback)(void *data, int size, int packet_number);
- uint8_t *ptr_lastgob;
-
- DCTELEM (*block)[64]; ///< points to one of the following blocks
- DCTELEM blocks[2][6][64] __align8; // for HQ mode we need to keep the best block
- int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()
-#define SLICE_OK 0
-#define SLICE_ERROR -1
-#define SLICE_END -2 ///<end marker found
-#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
-
- void (*dct_unquantize_mpeg1)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_mpeg2)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize_h263)(struct MpegEncContext *s,
- DCTELEM *block/*align 16*/, int n, int qscale);
- void (*dct_unquantize)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both)
- DCTELEM *block/*align 16*/, int n, int qscale);
- int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
- int (*fast_dct_quantize)(struct MpegEncContext *s, DCTELEM *block/*align 16*/, int n, int qscale, int *overflow);
-} MpegEncContext;
-
-
-int DCT_common_init(MpegEncContext *s);
-int MPV_common_init(MpegEncContext *s);
-void MPV_common_end(MpegEncContext *s);
-void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx);
-void MPV_frame_end(MpegEncContext *s);
-int MPV_encode_init(AVCodecContext *avctx);
-int MPV_encode_end(AVCodecContext *avctx);
-int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data);
-#ifdef HAVE_MMX
-void MPV_common_init_mmx(MpegEncContext *s);
-#endif
-#ifdef ARCH_ALPHA
-void MPV_common_init_axp(MpegEncContext *s);
-#endif
-#ifdef HAVE_MLIB
-void MPV_common_init_mlib(MpegEncContext *s);
-#endif
-#ifdef HAVE_MMI
-void MPV_common_init_mmi(MpegEncContext *s);
-#endif
-#ifdef ARCH_ARMV4L
-void MPV_common_init_armv4l(MpegEncContext *s);
-#endif
-#ifdef ARCH_POWERPC
-void MPV_common_init_ppc(MpegEncContext *s);
-#endif
-extern void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w);
-void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length);
-void ff_clean_intra_table_entries(MpegEncContext *s);
-void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable);
-void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
-void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h,
- int src_x, int src_y, int w, int h);
-#define END_NOT_FOUND -100
-int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);
-void ff_mpeg_flush(AVCodecContext *avctx);
-void ff_print_debug_info(MpegEncContext *s, Picture *pict);
-void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix);
-
-void ff_er_frame_start(MpegEncContext *s);
-void ff_er_frame_end(MpegEncContext *s);
-void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status);
-
-
-extern enum PixelFormat ff_yuv420p_list[2];
-
-void ff_init_block_index(MpegEncContext *s);
-
-static inline void ff_update_block_index(MpegEncContext *s){
- s->block_index[0]+=2;
- s->block_index[1]+=2;
- s->block_index[2]+=2;
- s->block_index[3]+=2;
- s->block_index[4]++;
- s->block_index[5]++;
- s->dest[0]+= 16;
- s->dest[1]+= 8;
- s->dest[2]+= 8;
-}
-
-static inline int get_bits_diff(MpegEncContext *s){
- const int bits= get_bit_count(&s->pb);
- const int last= s->last_bits;
-
- s->last_bits = bits;
-
- return bits - last;
-}
-
-/* motion_est.c */
-void ff_estimate_p_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y);
-void ff_estimate_b_frame_motion(MpegEncContext * s,
- int mb_x, int mb_y);
-int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
-void ff_fix_long_p_mvs(MpegEncContext * s);
-void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type);
-void ff_init_me(MpegEncContext *s);
-int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y);
-
-
-/* mpeg12.c */
-extern const int16_t ff_mpeg1_default_intra_matrix[64];
-extern const int16_t ff_mpeg1_default_non_intra_matrix[64];
-extern uint8_t ff_mpeg1_dc_scale_table[128];
-
-void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
-void mpeg1_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-void ff_mpeg1_encode_init(MpegEncContext *s);
-void ff_mpeg1_encode_slice_header(MpegEncContext *s);
-void ff_mpeg1_clean_buffers(MpegEncContext *s);
-
-
-/** RLTable. */
-typedef struct RLTable {
- int n; ///< number of entries of table_vlc minus 1
- int last; ///< number of values for last = 0
- const uint16_t (*table_vlc)[2];
- const int8_t *table_run;
- const int8_t *table_level;
- uint8_t *index_run[2]; ///< encoding only
- int8_t *max_level[2]; ///< encoding & decoding
- int8_t *max_run[2]; ///< encoding & decoding
- VLC vlc; ///< decoding only deprected FIXME remove
- RL_VLC_ELEM *rl_vlc[32]; ///< decoding only
-} RLTable;
-
-void init_rl(RLTable *rl);
-void init_vlc_rl(RLTable *rl);
-
-static inline int get_rl_index(const RLTable *rl, int last, int run, int level)
-{
- int index;
- index = rl->index_run[last][run];
- if (index >= rl->n)
- return rl->n;
- if (level > rl->max_level[last][run])
- return rl->n;
- return index + level - 1;
-}
-
-extern uint8_t ff_mpeg4_y_dc_scale_table[32];
-extern uint8_t ff_mpeg4_c_dc_scale_table[32];
-extern const int16_t ff_mpeg4_default_intra_matrix[64];
-extern const int16_t ff_mpeg4_default_non_intra_matrix[64];
-int ff_h263_decode_init(AVCodecContext *avctx);
-int ff_h263_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size);
-int ff_h263_decode_end(AVCodecContext *avctx);
-void h263_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-void mpeg4_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-void h263_encode_picture_header(MpegEncContext *s, int picture_number);
-void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number);
-int h263_encode_gob_header(MpegEncContext * s, int mb_line);
-int16_t *h263_pred_motion(MpegEncContext * s, int block,
- int *px, int *py);
-void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
- int dir);
-void ff_set_mpeg4_time(MpegEncContext * s, int picture_number);
-void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
-void h263_encode_init(MpegEncContext *s);
-void h263_decode_init_vlc(MpegEncContext *s);
-int h263_decode_picture_header(MpegEncContext *s);
-int ff_h263_decode_gob_header(MpegEncContext *s);
-int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb);
-void ff_h263_update_motion_val(MpegEncContext * s);
-
-
-int intel_h263_decode_picture_header(MpegEncContext *s);
-int flv_h263_decode_picture_header(MpegEncContext *s);
-int ff_h263_decode_mb(MpegEncContext *s,
- DCTELEM block[6][64]);
-int h263_get_picture_format(int width, int height);
-void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
-void ff_mpeg4_clean_buffers(MpegEncContext *s);
-void ff_mpeg4_stuffing(PutBitContext * pbc);
-void ff_mpeg4_init_partitions(MpegEncContext *s);
-void ff_mpeg4_merge_partitions(MpegEncContext *s);
-void ff_clean_mpeg4_qscales(MpegEncContext *s);
-void ff_clean_h263_qscales(MpegEncContext *s);
-int ff_mpeg4_decode_partitions(MpegEncContext *s);
-int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
-int ff_h263_resync(MpegEncContext *s);
-int ff_h263_get_gob_height(MpegEncContext *s);
-int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my);
-inline int ff_h263_round_chroma(int x);
-
-
-/* rv10.c */
-void rv10_encode_picture_header(MpegEncContext *s, int picture_number);
-int rv_decode_dc(MpegEncContext *s, int n);
-
-
-/* msmpeg4.c */
-void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
-void msmpeg4_encode_ext_header(MpegEncContext * s);
-void msmpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-int msmpeg4_decode_picture_header(MpegEncContext * s);
-int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
-int ff_msmpeg4_decode_init(MpegEncContext *s);
-void ff_msmpeg4_encode_init(MpegEncContext *s);
-int ff_wmv2_decode_picture_header(MpegEncContext * s);
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
-void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
-void ff_mspel_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h);
-int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number);
-void ff_wmv2_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y);
-
-/* mjpeg.c */
-int mjpeg_init(MpegEncContext *s);
-void mjpeg_close(MpegEncContext *s);
-void mjpeg_encode_mb(MpegEncContext *s,
- DCTELEM block[6][64]);
-void mjpeg_picture_header(MpegEncContext *s);
-void mjpeg_picture_trailer(MpegEncContext *s);
-
-
-/* rate control */
-int ff_rate_control_init(MpegEncContext *s);
-float ff_rate_estimate_qscale(MpegEncContext *s);
-void ff_write_pass1_stats(MpegEncContext *s);
-void ff_rate_control_uninit(MpegEncContext *s);
-double ff_eval(char *s, double *const_value, const char **const_name,
- double (**func1)(void *, double), const char **func1_name,
- double (**func2)(void *, double, double), char **func2_name,
- void *opaque);
-
-
-#endif /* AVCODEC_MPEGVIDEO_H */
+++ /dev/null
-/*
- * MSMPEG4 backend for ffmpeg encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
- */
-
-/**
- * @file msmpeg4.c
- * MSMPEG4 backend for ffmpeg encoder and decoder.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-/*
- * You can also call this codec : MPEG4 with a twist !
- *
- * TODO:
- * - (encoding) select best mv table (two choices)
- * - (encoding) select best vlc/dc table
- */
-//#define DEBUG
-
-#define DC_VLC_BITS 9
-#define CBPY_VLC_BITS 6
-#define INTER_INTRA_VLC_BITS 3
-#define V1_INTRA_CBPC_VLC_BITS 6
-#define V1_INTER_CBPC_VLC_BITS 6
-#define V2_INTRA_CBPC_VLC_BITS 3
-#define V2_MB_TYPE_VLC_BITS 7
-#define MV_VLC_BITS 9
-#define V2_MV_VLC_BITS 9
-#define TEX_VLC_BITS 9
-#define MB_NON_INTRA_VLC_BITS 9
-#define MB_INTRA_VLC_BITS 9
-
-#define II_BITRATE 128*1024
-#define MBAC_BITRATE 50*1024
-
-#define DEFAULT_INTER_INDEX 3
-
-static uint32_t v2_dc_lum_table[512][2];
-static uint32_t v2_dc_chroma_table[512][2];
-
-static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
-static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, const uint8_t *scantable);
-static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
-static int msmpeg4_decode_motion(MpegEncContext * s,
- int *mx_ptr, int *my_ptr);
-static void msmpeg4v2_encode_motion(MpegEncContext * s, int val);
-static void init_h263_dc_for_msmpeg4(void);
-static inline void msmpeg4_memsetw(short *tab, int val, int n);
-#ifdef CONFIG_ENCODERS
-static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra);
-#endif //CONFIG_ENCODERS
-static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
-
-
-#ifdef DEBUG
-int intra_count = 0;
-int frame_count = 0;
-#endif
-
-#include "msmpeg4data.h"
-
-#ifdef CONFIG_ENCODERS //strangely gcc includes this even if its not references
-static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
-#endif //CONFIG_ENCODERS
-
-#ifdef STATS
-
-const char *st_names[ST_NB] = {
- "unknown",
- "dc",
- "intra_ac",
- "inter_ac",
- "intra_mb",
- "inter_mb",
- "mv",
-};
-
-int st_current_index = 0;
-unsigned int st_bit_counts[ST_NB];
-unsigned int st_out_bit_counts[ST_NB];
-
-#define set_stat(var) st_current_index = var;
-
-void print_stats(void)
-{
- unsigned int total;
- int i;
-
- printf("Input:\n");
- total = 0;
- for(i=0;i<ST_NB;i++)
- total += st_bit_counts[i];
- if (total == 0)
- total = 1;
- for(i=0;i<ST_NB;i++) {
- printf("%-10s : %10.1f %5.1f%%\n",
- st_names[i],
- (double)st_bit_counts[i] / 8.0,
- (double)st_bit_counts[i] * 100.0 / total);
- }
- printf("%-10s : %10.1f %5.1f%%\n",
- "total",
- (double)total / 8.0,
- 100.0);
-
- printf("Output:\n");
- total = 0;
- for(i=0;i<ST_NB;i++)
- total += st_out_bit_counts[i];
- if (total == 0)
- total = 1;
- for(i=0;i<ST_NB;i++) {
- printf("%-10s : %10.1f %5.1f%%\n",
- st_names[i],
- (double)st_out_bit_counts[i] / 8.0,
- (double)st_out_bit_counts[i] * 100.0 / total);
- }
- printf("%-10s : %10.1f %5.1f%%\n",
- "total",
- (double)total / 8.0,
- 100.0);
-}
-
-#else
-
-#define set_stat(var)
-
-#endif
-
-static void common_init(MpegEncContext * s)
-{
- static int inited=0;
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- break;
- case 3:
- if(s->workaround_bugs){
- s->y_dc_scale_table= old_ff_y_dc_scale_table;
- s->c_dc_scale_table= old_ff_c_dc_scale_table;
- } else{
- s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
- s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
- }
- break;
- case 4:
- case 5:
- s->y_dc_scale_table= wmv1_y_dc_scale_table;
- s->c_dc_scale_table= wmv1_c_dc_scale_table;
- break;
- }
-
-
- if(s->msmpeg4_version>=4){
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , wmv1_scantable[1]);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, wmv1_scantable[2]);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, wmv1_scantable[3]);
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , wmv1_scantable[0]);
- }
- //Note the default tables are set in common_init in mpegvideo.c
-
- if(!inited){
- inited=1;
-
- init_h263_dc_for_msmpeg4();
- }
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* build the table which associate a (x,y) motion vector to a vlc */
-static void init_mv_table(MVTable *tab)
-{
- int i, x, y;
-
- tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
- /* mark all entries as not used */
- for(i=0;i<4096;i++)
- tab->table_mv_index[i] = tab->n;
-
- for(i=0;i<tab->n;i++) {
- x = tab->table_mvx[i];
- y = tab->table_mvy[i];
- tab->table_mv_index[(x << 6) | y] = i;
- }
-}
-
-static void code012(PutBitContext *pb, int n)
-{
- if (n == 0) {
- put_bits(pb, 1, 0);
- } else {
- put_bits(pb, 1, 1);
- put_bits(pb, 1, (n >= 2));
- }
-}
-
-void ff_msmpeg4_encode_init(MpegEncContext *s)
-{
- static int init_done=0;
- int i;
-
- common_init(s);
- if(s->msmpeg4_version>=4){
- s->min_qcoeff= -255;
- s->max_qcoeff= 255;
- }
-
- if (!init_done) {
- /* init various encoding tables */
- init_done = 1;
- init_mv_table(&mv_tables[0]);
- init_mv_table(&mv_tables[1]);
- for(i=0;i<NB_RL_TABLES;i++)
- init_rl(&rl_table[i]);
-
- for(i=0; i<NB_RL_TABLES; i++){
- int level;
- for(level=0; level<=MAX_LEVEL; level++){
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- for(last=0; last<2; last++){
- rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0);
- }
- }
- }
- }
- }
-}
-
-static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
- int size=0;
- int code;
- int run_diff= intra ? 0 : 1;
-
- code = get_rl_index(rl, last, run, level);
- size+= rl->table_vlc[code][1];
- if (code == rl->n) {
- int level1, run1;
-
- level1 = level - rl->max_level[last][run];
- if (level1 < 1)
- goto esc2;
- code = get_rl_index(rl, last, run, level1);
- if (code == rl->n) {
- esc2:
- size++;
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- size+=1+1+6+8;
- } else {
- /* second escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- /* first escape */
- size+= 1+1+ rl->table_vlc[code][1];
- }
- } else {
- size++;
- }
- return size;
-}
-
-static void find_best_tables(MpegEncContext * s)
-{
- int i;
- int best =-1, best_size =9999999;
- int chroma_best=-1, best_chroma_size=9999999;
-
- for(i=0; i<3; i++){
- int level;
- int chroma_size=0;
- int size=0;
-
- if(i>0){// ;)
- size++;
- chroma_size++;
- }
- for(level=0; level<=MAX_LEVEL; level++){
- int run;
- for(run=0; run<=MAX_RUN; run++){
- int last;
- const int last_size= size + chroma_size;
- for(last=0; last<2; last++){
- int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
- int intra_luma_count = s->ac_stats[1][0][level][run][last];
- int intra_chroma_count= s->ac_stats[1][1][level][run][last];
-
- if(s->pict_type==I_TYPE){
- size += intra_luma_count *rl_length[i ][level][run][last];
- chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
- }else{
- size+= intra_luma_count *rl_length[i ][level][run][last]
- +intra_chroma_count*rl_length[i+3][level][run][last]
- +inter_count *rl_length[i+3][level][run][last];
- }
- }
- if(last_size == size+chroma_size) break;
- }
- }
- if(size<best_size){
- best_size= size;
- best= i;
- }
- if(chroma_size<best_chroma_size){
- best_chroma_size= chroma_size;
- chroma_best= i;
- }
- }
-
-// printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
-// s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
-
- if(s->pict_type==P_TYPE) chroma_best= best;
-
- memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
-
- s->rl_table_index = best;
- s->rl_chroma_table_index= chroma_best;
-
- if(s->pict_type != s->last_non_b_pict_type){
- s->rl_table_index= 2;
- if(s->pict_type==I_TYPE)
- s->rl_chroma_table_index= 1;
- else
- s->rl_chroma_table_index= 2;
- }
-
-}
-
-/* write MSMPEG4 compatible frame header */
-void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- find_best_tables(s);
-
- align_put_bits(&s->pb);
- put_bits(&s->pb, 2, s->pict_type - 1);
-
- put_bits(&s->pb, 5, s->qscale);
- if(s->msmpeg4_version<=2){
- s->rl_table_index = 2;
- s->rl_chroma_table_index = 2;
- }
-
- s->dc_table_index = 1;
- s->mv_table_index = 1; /* only if P frame */
- s->use_skip_mb_code = 1; /* only if P frame */
- s->per_mb_rl_table = 0;
- if(s->msmpeg4_version==4)
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==P_TYPE);
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
-
- if (s->pict_type == I_TYPE) {
- s->slice_height= s->mb_height/1;
- put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
-
- if(s->msmpeg4_version==4){
- msmpeg4_encode_ext_header(s);
- if(s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
- }
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_chroma_table_index);
- code012(&s->pb, s->rl_table_index);
- }
-
- put_bits(&s->pb, 1, s->dc_table_index);
- }
- } else {
- put_bits(&s->pb, 1, s->use_skip_mb_code);
-
- if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
- put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(s->msmpeg4_version>2){
- if(!s->per_mb_rl_table)
- code012(&s->pb, s->rl_table_index);
-
- put_bits(&s->pb, 1, s->dc_table_index);
-
- put_bits(&s->pb, 1, s->mv_table_index);
- }
- }
-
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-#ifdef DEBUG
- intra_count = 0;
- printf("*****frame %d:\n", frame_count++);
-#endif
-}
-
-void msmpeg4_encode_ext_header(MpegEncContext * s)
-{
- put_bits(&s->pb, 5, s->avctx->frame_rate / s->avctx->frame_rate_base); //yes 29.97 -> 29
-
- put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
-
- if(s->msmpeg4_version>=3)
- put_bits(&s->pb, 1, s->flipflop_rounding);
- else
- assert(s->flipflop_rounding==0);
-}
-
-#endif //CONFIG_ENCODERS
-
-/* predict coded block */
-static inline int coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
-{
- int xy, wrap, pred, a, b, c;
-
- xy = s->block_index[n];
- wrap = s->block_wrap[0];
-
- /* B C
- * A X
- */
- a = s->coded_block[xy - 1 ];
- b = s->coded_block[xy - 1 - wrap];
- c = s->coded_block[xy - wrap];
-
- if (b == c) {
- pred = a;
- } else {
- pred = c;
- }
-
- /* store value */
- *coded_block_ptr = &s->coded_block[xy];
-
- return pred;
-}
-
-#ifdef CONFIG_ENCODERS
-
-static void msmpeg4_encode_motion(MpegEncContext * s,
- int mx, int my)
-{
- int code;
- MVTable *mv;
-
- /* modulo encoding */
- /* WARNING : you cannot reach all the MVs even with the modulo
- encoding. This is a somewhat strange compromise they took !!! */
- if (mx <= -64)
- mx += 64;
- else if (mx >= 64)
- mx -= 64;
- if (my <= -64)
- my += 64;
- else if (my >= 64)
- my -= 64;
-
- mx += 32;
- my += 32;
-#if 0
- if ((unsigned)mx >= 64 ||
- (unsigned)my >= 64)
- fprintf(stderr, "error mx=%d my=%d\n", mx, my);
-#endif
- mv = &mv_tables[s->mv_table_index];
-
- code = mv->table_mv_index[(mx << 6) | my];
- set_stat(ST_MV);
- put_bits(&s->pb,
- mv->table_mv_bits[code],
- mv->table_mv_code[code]);
- if (code == mv->n) {
- /* escape : code litterally */
- put_bits(&s->pb, 6, mx);
- put_bits(&s->pb, 6, my);
- }
-}
-
-static inline void handle_slices(MpegEncContext *s){
- if (s->mb_x == 0) {
- if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
- if(s->msmpeg4_version < 4){
- ff_mpeg4_clean_buffers(s);
- }
- s->first_slice_line = 1;
- } else {
- s->first_slice_line = 0;
- }
- }
-}
-
-void msmpeg4_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- int cbp, coded_cbp, i;
- int pred_x, pred_y;
- uint8_t *coded_block;
-
- handle_slices(s);
-
- if (!s->mb_intra) {
- /* compute cbp */
- set_stat(ST_INTER_MB);
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
- /* skip macroblock */
- put_bits(&s->pb, 1, 1);
- s->last_bits++;
- s->misc_bits++;
- s->skip_count++;
-
- return;
- }
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
-
- if(s->msmpeg4_version<=2){
- put_bits(&s->pb,
- v2_mb_type[cbp&3][1],
- v2_mb_type[cbp&3][0]);
- if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
- else coded_cbp= cbp;
-
- put_bits(&s->pb,
- cbpy_tab[coded_cbp>>2][1],
- cbpy_tab[coded_cbp>>2][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- h263_pred_motion(s, 0, &pred_x, &pred_y);
- msmpeg4v2_encode_motion(s, motion_x - pred_x);
- msmpeg4v2_encode_motion(s, motion_y - pred_y);
- }else{
- put_bits(&s->pb,
- table_mb_non_intra[cbp + 64][1],
- table_mb_non_intra[cbp + 64][0]);
-
- s->misc_bits += get_bits_diff(s);
-
- /* motion vector */
- h263_pred_motion(s, 0, &pred_x, &pred_y);
- msmpeg4_encode_motion(s, motion_x - pred_x,
- motion_y - pred_y);
- }
-
- s->mv_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
- s->p_tex_bits += get_bits_diff(s);
- } else {
- /* compute cbp */
- cbp = 0;
- coded_cbp = 0;
- for (i = 0; i < 6; i++) {
- int val, pred;
- val = (s->block_last_index[i] >= 1);
- cbp |= val << (5 - i);
- if (i < 4) {
- /* predict value for close blocks only for luma */
- pred = coded_block_pred(s, i, &coded_block);
- *coded_block = val;
- val = val ^ pred;
- }
- coded_cbp |= val << (5 - i);
- }
-#if 0
- if (coded_cbp)
- printf("cbp=%x %x\n", cbp, coded_cbp);
-#endif
-
- if(s->msmpeg4_version<=2){
- if (s->pict_type == I_TYPE) {
- put_bits(&s->pb,
- v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- v2_mb_type[(cbp&3) + 4][1],
- v2_mb_type[(cbp&3) + 4][0]);
- }
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- put_bits(&s->pb,
- cbpy_tab[cbp>>2][1],
- cbpy_tab[cbp>>2][0]);
- }else{
- if (s->pict_type == I_TYPE) {
- set_stat(ST_INTRA_MB);
- put_bits(&s->pb,
- table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]);
- } else {
- if (s->use_skip_mb_code)
- put_bits(&s->pb, 1, 0); /* mb coded */
- put_bits(&s->pb,
- table_mb_non_intra[cbp][1],
- table_mb_non_intra[cbp][0]);
- }
- set_stat(ST_INTRA_MB);
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- if(s->inter_intra_pred){
- s->h263_aic_dir=0;
- put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
- }
- }
- s->misc_bits += get_bits_diff(s);
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
- s->i_tex_bits += get_bits_diff(s);
- s->i_count++;
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-/* old ffmpeg msmpeg4v3 mode */
-static void ff_old_msmpeg4_dc_scale(MpegEncContext * s)
-{
- if (s->qscale < 5){
- s->y_dc_scale = 8;
- s->c_dc_scale = 8;
- }else if (s->qscale < 9){
- s->y_dc_scale = 2 * s->qscale;
- s->c_dc_scale = (s->qscale + 13)>>1;
- }else{
- s->y_dc_scale = s->qscale + 8;
- s->c_dc_scale = (s->qscale + 13)>>1;
- }
-}
-
-static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
- int32_t **dc_val_ptr)
-{
- int i;
-
- if (n < 4) {
- i= 0;
- } else {
- i= n-3;
- }
-
- *dc_val_ptr= &s->last_dc[i];
- return s->last_dc[i];
-}
-
-static int get_dc(uint8_t *src, int stride, int scale)
-{
- int y;
- int sum=0;
- for(y=0; y<8; y++){
- int x;
- for(x=0; x<8; x++){
- sum+=src[x + y*stride];
- }
- }
- return FASTDIV((sum + (scale>>1)), scale);
-}
-
-/* dir = 0: left, dir = 1: top prediction */
-static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
- uint16_t **dc_val_ptr, int *dir_ptr)
-{
- int a, b, c, wrap, pred, scale;
- int16_t *dc_val;
-
- /* find prediction */
- if (n < 4) {
- scale = s->y_dc_scale;
- } else {
- scale = s->c_dc_scale;
- }
-
- wrap = s->block_wrap[n];
- dc_val= s->dc_val[0] + s->block_index[n];
-
- /* B C
- * A X
- */
- a = dc_val[ - 1];
- b = dc_val[ - 1 - wrap];
- c = dc_val[ - wrap];
-
- if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){
- b=c=1024;
- }
-
- /* XXX: the following solution consumes divisions, but it does not
- necessitate to modify mpegvideo.c. The problem comes from the
- fact they decided to store the quantized DC (which would lead
- to problems if Q could vary !) */
-#if defined ARCH_X86 && !defined PIC
- asm volatile(
- "movl %3, %%eax \n\t"
- "shrl $1, %%eax \n\t"
- "addl %%eax, %2 \n\t"
- "addl %%eax, %1 \n\t"
- "addl %0, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %0 \n\t"
- "movl %1, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %1 \n\t"
- "movl %2, %%eax \n\t"
- "mull %4 \n\t"
- "movl %%edx, %2 \n\t"
- : "+b" (a), "+c" (b), "+D" (c)
- : "g" (scale), "S" (inverse[scale])
- : "%eax", "%edx"
- );
-#else
- /* #elif defined (ARCH_ALPHA) */
- /* Divisions are extremely costly on Alpha; optimize the most
- common case. But they are costly everywhere...
- */
- if (scale == 8) {
- a = (a + (8 >> 1)) / 8;
- b = (b + (8 >> 1)) / 8;
- c = (c + (8 >> 1)) / 8;
- } else {
- a = FASTDIV((a + (scale >> 1)), scale);
- b = FASTDIV((b + (scale >> 1)), scale);
- c = FASTDIV((c + (scale >> 1)), scale);
- }
-#endif
- /* XXX: WARNING: they did not choose the same test as MPEG4. This
- is very important ! */
- if(s->msmpeg4_version>3){
- if(s->inter_intra_pred){
- uint8_t *dest;
- int wrap;
-
- if(n==1){
- pred=a;
- *dir_ptr = 0;
- }else if(n==2){
- pred=c;
- *dir_ptr = 1;
- }else if(n==3){
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }else{
- if(n<4){
- wrap= s->linesize;
- dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8;
- }else{
- wrap= s->uvlinesize;
- dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
- }
- if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
- else a= get_dc(dest-8, wrap, scale*8);
- if(s->mb_y==0) c= (1024 + (scale>>1))/scale;
- else c= get_dc(dest-8*wrap, wrap, scale*8);
-
- if (s->h263_aic_dir==0) {
- pred= a;
- *dir_ptr = 0;
- }else if (s->h263_aic_dir==1) {
- if(n==0){
- pred= c;
- *dir_ptr = 1;
- }else{
- pred= a;
- *dir_ptr = 0;
- }
- }else if (s->h263_aic_dir==2) {
- if(n==0){
- pred= a;
- *dir_ptr = 0;
- }else{
- pred= c;
- *dir_ptr = 1;
- }
- } else {
- pred= c;
- *dir_ptr = 1;
- }
- }
- }else{
- if (abs(a - b) < abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }
- }else{
- if (abs(a - b) <= abs(b - c)) {
- pred = c;
- *dir_ptr = 1;
- } else {
- pred = a;
- *dir_ptr = 0;
- }
- }
-
- /* update predictor */
- *dc_val_ptr = &dc_val[0];
- return pred;
-}
-
-#define DC_MAX 119
-
-static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
-{
- int sign, code;
- int pred;
-
- if(s->msmpeg4_version==1){
- int32_t *dc_val;
- pred = msmpeg4v1_pred_dc(s, n, &dc_val);
-
- /* update predictor */
- *dc_val= level;
- }else{
- uint16_t *dc_val;
- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
-
- /* update predictor */
- if (n < 4) {
- *dc_val = level * s->y_dc_scale;
- } else {
- *dc_val = level * s->c_dc_scale;
- }
- }
-
- /* do the prediction */
- level -= pred;
-
- if(s->msmpeg4_version<=2){
- if (n < 4) {
- put_bits(&s->pb,
- v2_dc_lum_table[level+256][1],
- v2_dc_lum_table[level+256][0]);
- }else{
- put_bits(&s->pb,
- v2_dc_chroma_table[level+256][1],
- v2_dc_chroma_table[level+256][0]);
- }
- }else{
- sign = 0;
- if (level < 0) {
- level = -level;
- sign = 1;
- }
- code = level;
- if (code > DC_MAX)
- code = DC_MAX;
-
- if (s->dc_table_index == 0) {
- if (n < 4) {
- put_bits(&s->pb, table0_dc_lum[code][1], table0_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, table0_dc_chroma[code][1], table0_dc_chroma[code][0]);
- }
- } else {
- if (n < 4) {
- put_bits(&s->pb, table1_dc_lum[code][1], table1_dc_lum[code][0]);
- } else {
- put_bits(&s->pb, table1_dc_chroma[code][1], table1_dc_chroma[code][0]);
- }
- }
-
- if (code == DC_MAX)
- put_bits(&s->pb, 8, level);
-
- if (level != 0) {
- put_bits(&s->pb, 1, sign);
- }
- }
-}
-
-/* Encoding of a block. Very similar to MPEG4 except for a different
- escape coding (same as H263) and more vlc tables.
- */
-static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
-{
- int level, run, last, i, j, last_index;
- int last_non_zero, sign, slevel;
- int code, run_diff, dc_pred_dir;
- const RLTable *rl;
- const uint8_t *scantable;
-
- if (s->mb_intra) {
- set_stat(ST_DC);
- msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
- i = 1;
- if (n < 4) {
- rl = &rl_table[s->rl_table_index];
- } else {
- rl = &rl_table[3 + s->rl_chroma_table_index];
- }
- run_diff = 0;
- scantable= s->intra_scantable.permutated;
- set_stat(ST_INTRA_AC);
- } else {
- i = 0;
- rl = &rl_table[3 + s->rl_table_index];
- if(s->msmpeg4_version<=2)
- run_diff = 0;
- else
- run_diff = 1;
- scantable= s->inter_scantable.permutated;
- set_stat(ST_INTER_AC);
- }
-
- /* recalculate block_last_index for M$ wmv1 */
- if(s->msmpeg4_version>=4 && s->block_last_index[n]>0){
- for(last_index=63; last_index>=0; last_index--){
- if(block[scantable[last_index]]) break;
- }
- s->block_last_index[n]= last_index;
- }else
- last_index = s->block_last_index[n];
- /* AC coefs */
- last_non_zero = i - 1;
- for (; i <= last_index; i++) {
- j = scantable[i];
- level = block[j];
- if (level) {
- run = i - last_non_zero - 1;
- last = (i == last_index);
- sign = 0;
- slevel = level;
- if (level < 0) {
- sign = 1;
- level = -level;
- }
-
- if(level<=MAX_LEVEL && run<=MAX_RUN){
- s->ac_stats[s->mb_intra][n>3][level][run][last]++;
- }
-#if 0
-else
- s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like
-#endif
- code = get_rl_index(rl, last, run, level);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- if (code == rl->n) {
- int level1, run1;
-
- level1 = level - rl->max_level[last][run];
- if (level1 < 1)
- goto esc2;
- code = get_rl_index(rl, last, run, level1);
- if (code == rl->n) {
- esc2:
- put_bits(&s->pb, 1, 0);
- if (level > MAX_LEVEL)
- goto esc3;
- run1 = run - rl->max_run[last][level] - run_diff;
- if (run1 < 0)
- goto esc3;
- code = get_rl_index(rl, last, run1, level);
- if (code == rl->n) {
- esc3:
- /* third escape */
- put_bits(&s->pb, 1, 0);
- put_bits(&s->pb, 1, last);
- if(s->msmpeg4_version>=4){
- if(s->esc3_level_length==0){
- s->esc3_level_length=8;
- s->esc3_run_length= 6;
- if(s->qscale<8)
- put_bits(&s->pb, 6, 3);
- else
- put_bits(&s->pb, 8, 3);
- }
- put_bits(&s->pb, s->esc3_run_length, run);
- put_bits(&s->pb, 1, sign);
- put_bits(&s->pb, s->esc3_level_length, level);
- }else{
- put_bits(&s->pb, 6, run);
- put_bits(&s->pb, 8, slevel & 0xff);
- }
- } else {
- /* second escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- /* first escape */
- put_bits(&s->pb, 1, 1);
- put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
- put_bits(&s->pb, 1, sign);
- }
- } else {
- put_bits(&s->pb, 1, sign);
- }
- last_non_zero = i;
- }
- }
-}
-
-/****************************************/
-/* decoding stuff */
-
-static VLC mb_non_intra_vlc[4];
-static VLC mb_intra_vlc;
-static VLC dc_lum_vlc[2];
-static VLC dc_chroma_vlc[2];
-static VLC v2_dc_lum_vlc;
-static VLC v2_dc_chroma_vlc;
-static VLC cbpy_vlc;
-static VLC v2_intra_cbpc_vlc;
-static VLC v2_mb_type_vlc;
-static VLC v2_mv_vlc;
-static VLC v1_intra_cbpc_vlc;
-static VLC v1_inter_cbpc_vlc;
-static VLC inter_intra_vlc;
-
-/* this table is practically identical to the one from h263 except that its inverted */
-static void init_h263_dc_for_msmpeg4(void)
-{
- int level, uni_code, uni_len;
-
- for(level=-256; level<256; level++){
- int size, v, l;
- /* find number of bits */
- size = 0;
- v = abs(level);
- while (v) {
- v >>= 1;
- size++;
- }
-
- if (level < 0)
- l= (-level) ^ ((1 << size) - 1);
- else
- l= level;
-
- /* luminance h263 */
- uni_code= DCtab_lum[size][0];
- uni_len = DCtab_lum[size][1];
- uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
-
- if (size > 0) {
- uni_code<<=size; uni_code|=l;
- uni_len+=size;
- if (size > 8){
- uni_code<<=1; uni_code|=1;
- uni_len++;
- }
- }
- v2_dc_lum_table[level+256][0]= uni_code;
- v2_dc_lum_table[level+256][1]= uni_len;
-
- /* chrominance h263 */
- uni_code= DCtab_chrom[size][0];
- uni_len = DCtab_chrom[size][1];
- uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
-
- if (size > 0) {
- uni_code<<=size; uni_code|=l;
- uni_len+=size;
- if (size > 8){
- uni_code<<=1; uni_code|=1;
- uni_len++;
- }
- }
- v2_dc_chroma_table[level+256][0]= uni_code;
- v2_dc_chroma_table[level+256][1]= uni_len;
-
- }
-}
-
-/* init all vlc decoding tables */
-int ff_msmpeg4_decode_init(MpegEncContext *s)
-{
- static int done = 0;
- int i;
- MVTable *mv;
-
- common_init(s);
-
- if (!done) {
- done = 1;
-
- for(i=0;i<NB_RL_TABLES;i++) {
- init_rl(&rl_table[i]);
- init_vlc_rl(&rl_table[i]);
- }
- for(i=0;i<2;i++) {
- mv = &mv_tables[i];
- init_vlc(&mv->vlc, MV_VLC_BITS, mv->n + 1,
- mv->table_mv_bits, 1, 1,
- mv->table_mv_code, 2, 2);
- }
-
- init_vlc(&dc_lum_vlc[0], DC_VLC_BITS, 120,
- &table0_dc_lum[0][1], 8, 4,
- &table0_dc_lum[0][0], 8, 4);
- init_vlc(&dc_chroma_vlc[0], DC_VLC_BITS, 120,
- &table0_dc_chroma[0][1], 8, 4,
- &table0_dc_chroma[0][0], 8, 4);
- init_vlc(&dc_lum_vlc[1], DC_VLC_BITS, 120,
- &table1_dc_lum[0][1], 8, 4,
- &table1_dc_lum[0][0], 8, 4);
- init_vlc(&dc_chroma_vlc[1], DC_VLC_BITS, 120,
- &table1_dc_chroma[0][1], 8, 4,
- &table1_dc_chroma[0][0], 8, 4);
-
- init_vlc(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
- &v2_dc_lum_table[0][1], 8, 4,
- &v2_dc_lum_table[0][0], 8, 4);
- init_vlc(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
- &v2_dc_chroma_table[0][1], 8, 4,
- &v2_dc_chroma_table[0][0], 8, 4);
-
- init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
- &cbpy_tab[0][1], 2, 1,
- &cbpy_tab[0][0], 2, 1);
- init_vlc(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
- &v2_intra_cbpc[0][1], 2, 1,
- &v2_intra_cbpc[0][0], 2, 1);
- init_vlc(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
- &v2_mb_type[0][1], 2, 1,
- &v2_mb_type[0][0], 2, 1);
- init_vlc(&v2_mv_vlc, V2_MV_VLC_BITS, 33,
- &mvtab[0][1], 2, 1,
- &mvtab[0][0], 2, 1);
-
- for(i=0; i<4; i++){
- init_vlc(&mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128,
- &wmv2_inter_table[i][0][1], 8, 4,
- &wmv2_inter_table[i][0][0], 8, 4); //FIXME name?
- }
-
- init_vlc(&mb_intra_vlc, MB_INTRA_VLC_BITS, 64,
- &table_mb_intra[0][1], 4, 2,
- &table_mb_intra[0][0], 4, 2);
-
- init_vlc(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8,
- intra_MCBPC_bits, 1, 1,
- intra_MCBPC_code, 1, 1);
- init_vlc(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25,
- inter_MCBPC_bits, 1, 1,
- inter_MCBPC_code, 1, 1);
-
- init_vlc(&inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
- &table_inter_intra[0][1], 2, 1,
- &table_inter_intra[0][0], 2, 1);
- }
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->decode_mb= msmpeg4v12_decode_mb;
- break;
- case 3:
- case 4:
- s->decode_mb= msmpeg4v34_decode_mb;
- break;
- case 5:
- s->decode_mb= wmv2_decode_mb;
- break;
- }
-
- s->slice_height= s->mb_height; //to avoid 1/0 if the first frame isnt a keyframe
-
- return 0;
-}
-
-static int decode012(GetBitContext *gb)
-{
- int n;
- n = get_bits1(gb);
- if (n == 0)
- return 0;
- else
- return get_bits1(gb) + 1;
-}
-
-int msmpeg4_decode_picture_header(MpegEncContext * s)
-{
- int code;
-
-#if 0
-{
-int i;
-for(i=0; i<s->gb.size_in_bits; i++)
- printf("%d", get_bits1(&s->gb));
-// get_bits1(&s->gb);
-printf("END\n");
-return -1;
-}
-#endif
-
- if(s->msmpeg4_version==1){
- int start_code, num;
- start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16);
- if(start_code!=0x00000100){
- fprintf(stderr, "invalid startcode\n");
- return -1;
- }
-
- num= get_bits(&s->gb, 5); // frame number */
- }
-
- s->pict_type = get_bits(&s->gb, 2) + 1;
- if (s->pict_type != I_TYPE &&
- s->pict_type != P_TYPE){
- fprintf(stderr, "invalid picture type\n");
- return -1;
- }
-#if 0
-{
- static int had_i=0;
- if(s->pict_type == I_TYPE) had_i=1;
- if(!had_i) return -1;
-}
-#endif
- s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- fprintf(stderr, "invalid qscale\n");
- return -1;
- }
-
- if (s->pict_type == I_TYPE) {
- code = get_bits(&s->gb, 5);
- if(s->msmpeg4_version==1){
- if(code==0 || code>s->mb_height){
- fprintf(stderr, "invalid slice height %d\n", code);
- return -1;
- }
-
- s->slice_height = code;
- }else{
- /* 0x17: one slice, 0x18: two slices, ... */
- if (code < 0x17){
- fprintf(stderr, "error, slice code was %X\n", code);
- return -1;
- }
-
- s->slice_height = s->mb_height / (code - 0x16);
- }
-
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- s->rl_chroma_table_index = 2;
- s->rl_table_index = 2;
-
- s->dc_table_index = 0; //not used
- break;
- case 3:
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
-
- s->dc_table_index = get_bits1(&s->gb);
- break;
- case 4:
- msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
-
- if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- s->inter_intra_pred= 0;
- break;
- }
- s->no_rounding = 1;
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- printf("qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
- s->qscale,
- s->rl_chroma_table_index,
- s->rl_table_index,
- s->dc_table_index,
- s->per_mb_rl_table,
- s->slice_height);
- } else {
- switch(s->msmpeg4_version){
- case 1:
- case 2:
- if(s->msmpeg4_version==1)
- s->use_skip_mb_code = 1;
- else
- s->use_skip_mb_code = get_bits1(&s->gb);
- s->rl_table_index = 2;
- s->rl_chroma_table_index = s->rl_table_index;
- s->dc_table_index = 0; //not used
- s->mv_table_index = 0;
- break;
- case 3:
- s->use_skip_mb_code = get_bits1(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
-
- s->dc_table_index = get_bits1(&s->gb);
-
- s->mv_table_index = get_bits1(&s->gb);
- break;
- case 4:
- s->use_skip_mb_code = get_bits1(&s->gb);
-
- if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- s->dc_table_index = get_bits1(&s->gb);
-
- s->mv_table_index = get_bits1(&s->gb);
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- break;
- }
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- printf("skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
- s->use_skip_mb_code,
- s->rl_table_index,
- s->rl_chroma_table_index,
- s->dc_table_index,
- s->mv_table_index,
- s->per_mb_rl_table,
- s->qscale);
-
- if(s->flipflop_rounding){
- s->no_rounding ^= 1;
- }else{
- s->no_rounding = 0;
- }
- }
-//printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
-
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-#ifdef DEBUG
- printf("*****frame %d:\n", frame_count++);
-#endif
- return 0;
-}
-
-int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
-{
- int left= buf_size*8 - get_bits_count(&s->gb);
- int length= s->msmpeg4_version>=3 ? 17 : 16;
- /* the alt_bitstream reader could read over the end so we need to check it */
- if(left>=length && left<length+8)
- {
- int fps;
-
- fps= get_bits(&s->gb, 5);
- s->bit_rate= get_bits(&s->gb, 11)*1024;
- if(s->msmpeg4_version>=3)
- s->flipflop_rounding= get_bits1(&s->gb);
- else
- s->flipflop_rounding= 0;
-
-// printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate/1024, s->flipflop_rounding);
- }
- else if(left<length+8)
- {
- s->flipflop_rounding= 0;
- if(s->msmpeg4_version != 2)
- printf("ext header missing, %d left\n", left);
- }
- else
- {
- fprintf(stderr, "I frame too long, ignoring ext header\n");
- }
-
- return 0;
-}
-
-static inline void msmpeg4_memsetw(short *tab, int val, int n)
-{
- int i;
- for(i=0;i<n;i++)
- tab[i] = val;
-}
-
-static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
-{
- int range, bit_size, sign, code, bits;
-
- if (val == 0) {
- /* zero vector */
- code = 0;
- put_bits(&s->pb, mvtab[code][1], mvtab[code][0]);
- } else {
- bit_size = s->f_code - 1;
- range = 1 << bit_size;
- if (val <= -64)
- val += 64;
- else if (val >= 64)
- val -= 64;
-
- if (val >= 0) {
- sign = 0;
- } else {
- val = -val;
- sign = 1;
- }
- val--;
- code = (val >> bit_size) + 1;
- bits = val & (range - 1);
-
- put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign);
- if (bit_size > 0) {
- put_bits(&s->pb, bit_size, bits);
- }
- }
-}
-
-/* this is identical to h263 except that its range is multiplied by 2 */
-static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
-{
- int code, val, sign, shift;
-
- code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2);
-// printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
- if (code < 0)
- return 0xffff;
-
- if (code == 0)
- return pred;
- sign = get_bits1(&s->gb);
- shift = f_code - 1;
- val = code;
- if (shift) {
- val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
- val++;
- }
- if (sign)
- val = -val;
-
- val += pred;
- if (val <= -64)
- val += 64;
- else if (val >= 64)
- val -= 64;
-
- return val;
-}
-
-static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- int cbp, code, i;
-
- if (s->pict_type == P_TYPE) {
- if (s->use_skip_mb_code) {
- if (get_bits1(&s->gb)) {
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skiped = 1;
- return 0;
- }
- }
-
- if(s->msmpeg4_version==2)
- code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1);
- else
- code = get_vlc2(&s->gb, v1_inter_cbpc_vlc.table, V1_INTER_CBPC_VLC_BITS, 3);
- if(code<0 || code>7){
- fprintf(stderr, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
- return -1;
- }
-
- s->mb_intra = code >>2;
-
- cbp = code & 0x3;
- } else {
- s->mb_intra = 1;
- if(s->msmpeg4_version==2)
- cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
- else
- cbp= get_vlc2(&s->gb, v1_intra_cbpc_vlc.table, V1_INTRA_CBPC_VLC_BITS, 1);
- if(cbp<0 || cbp>3){
- fprintf(stderr, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- if (!s->mb_intra) {
- int mx, my, cbpy;
-
- cbpy= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
- if(cbpy<0){
- fprintf(stderr, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
- return -1;
- }
-
- cbp|= cbpy<<2;
- if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
-
- h263_pred_motion(s, 0, &mx, &my);
- mx= msmpeg4v2_decode_motion(s, mx, 1);
- my= msmpeg4v2_decode_motion(s, my, 1);
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
- } else {
- if(s->msmpeg4_version==2){
- s->ac_pred = get_bits1(&s->gb);
- cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
- } else{
- s->ac_pred = 0;
- cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
- if(s->pict_type==P_TYPE) cbp^=0x3C;
- }
- }
-
- for (i = 0; i < 6; i++) {
- if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
- {
- fprintf(stderr,"\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
- return 0;
-}
-
-static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- int cbp, code, i;
- uint8_t *coded_val;
- uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
-
- if (s->pict_type == P_TYPE) {
- set_stat(ST_INTER_MB);
- if (s->use_skip_mb_code) {
- if (get_bits1(&s->gb)) {
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skiped = 1;
- *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
-
- return 0;
- }
- }
-
- code = get_vlc2(&s->gb, mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3);
- if (code < 0)
- return -1;
- //s->mb_intra = (code & 0x40) ? 0 : 1;
- s->mb_intra = (~code & 0x40) >> 6;
-
- cbp = code & 0x3f;
- } else {
- set_stat(ST_INTRA_MB);
- s->mb_intra = 1;
- code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2);
- if (code < 0)
- return -1;
- /* predict coded block pattern */
- cbp = 0;
- for(i=0;i<6;i++) {
- int val = ((code >> (5 - i)) & 1);
- if (i < 4) {
- int pred = coded_block_pred(s, i, &coded_val);
- val = val ^ pred;
- *coded_val = val;
- }
- cbp |= val << (5 - i);
- }
- }
-
- if (!s->mb_intra) {
- int mx, my;
-//printf("P at %d %d\n", s->mb_x, s->mb_y);
- if(s->per_mb_rl_table && cbp){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
- set_stat(ST_MV);
- h263_pred_motion(s, 0, &mx, &my);
- if (msmpeg4_decode_motion(s, &mx, &my) < 0)
- return -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
- *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
- } else {
-//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
- set_stat(ST_INTRA_MB);
- s->ac_pred = get_bits1(&s->gb);
- *mb_type_ptr = MB_TYPE_INTRA;
- if(s->inter_intra_pred){
- s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
-// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
- }
- if(s->per_mb_rl_table && cbp){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
- }
-
- for (i = 0; i < 6; i++) {
- if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
- {
- fprintf(stderr,"\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
-
- return 0;
-}
-//#define ERROR_DETAILS
-static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
- int n, int coded, const uint8_t *scan_table)
-{
- int level, i, last, run, run_diff;
- int dc_pred_dir;
- RLTable *rl;
- RL_VLC_ELEM *rl_vlc;
- int qmul, qadd;
-
- if (s->mb_intra) {
- qmul=1;
- qadd=0;
-
- /* DC coef */
- set_stat(ST_DC);
- level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
-
- if (level < 0){
- fprintf(stderr, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
- if(s->inter_intra_pred) level=0;
- else return -1;
- }
- if (n < 4) {
- rl = &rl_table[s->rl_table_index];
- if(level > 256*s->y_dc_scale){
- fprintf(stderr, "dc overflow+ L qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
- }
- } else {
- rl = &rl_table[3 + s->rl_chroma_table_index];
- if(level > 256*s->c_dc_scale){
- fprintf(stderr, "dc overflow+ C qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
- }
- }
- block[0] = level;
-
- run_diff = 0;
- i = 0;
- if (!coded) {
- goto not_coded;
- }
- if (s->ac_pred) {
- if (dc_pred_dir == 0)
- scan_table = s->intra_v_scantable.permutated; /* left */
- else
- scan_table = s->intra_h_scantable.permutated; /* top */
- } else {
- scan_table = s->intra_scantable.permutated;
- }
- set_stat(ST_INTRA_AC);
- rl_vlc= rl->rl_vlc[0];
- } else {
- qmul = s->qscale << 1;
- qadd = (s->qscale - 1) | 1;
- i = -1;
- rl = &rl_table[3 + s->rl_table_index];
-
- if(s->msmpeg4_version==2)
- run_diff = 0;
- else
- run_diff = 1;
-
- if (!coded) {
- s->block_last_index[n] = i;
- return 0;
- }
- if(!scan_table)
- scan_table = s->inter_scantable.permutated;
- set_stat(ST_INTER_AC);
- rl_vlc= rl->rl_vlc[s->qscale];
- }
- {
- OPEN_READER(re, &s->gb);
- for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- if (level==0) {
- int cache;
- cache= GET_CACHE(re, &s->gb);
- /* escape */
- if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
- if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
- /* third escape */
- if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
- if(s->msmpeg4_version<=3){
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
- run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
- level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);
- SKIP_COUNTER(re, &s->gb, 1+6+8);
- }else{
- int sign;
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
- if(!s->esc3_level_length){
- int ll;
- //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
- if(s->qscale<8){
- ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
- if(ll==0){
- if(SHOW_UBITS(re, &s->gb, 1)) printf("cool a new vlc code ,contact the ffmpeg developers and upload the file\n");
- SKIP_BITS(re, &s->gb, 1);
- ll=8;
- }
- }else{
- ll=2;
- while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
- ll++;
- SKIP_BITS(re, &s->gb, 1);
- }
- if(ll<8) SKIP_BITS(re, &s->gb, 1);
- }
-
- s->esc3_level_length= ll;
- s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
-//printf("level length:%d, run length: %d\n", ll, s->esc3_run_length);
- UPDATE_CACHE(re, &s->gb);
- }
- run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
- SKIP_BITS(re, &s->gb, s->esc3_run_length);
-
- sign= SHOW_UBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
-
- level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
- SKIP_BITS(re, &s->gb, s->esc3_level_length);
- if(sign) level= -level;
- }
-//printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y);
-#if 0 // waste of time / this will detect very few errors
- {
- const int abs_level= ABS(level);
- const int run1= run - rl->max_run[last][abs_level] - run_diff;
- if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
- if(abs_level <= rl->max_level[last][run]){
- fprintf(stderr, "illegal 3. esc, vlc encoding possible\n");
- return DECODING_AC_LOST;
- }
- if(abs_level <= rl->max_level[last][run]*2){
- fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n");
- return DECODING_AC_LOST;
- }
- if(run1>=0 && abs_level <= rl->max_level[last][run1]){
- fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n");
- return DECODING_AC_LOST;
- }
- }
- }
-#endif
- //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
- if (level>0) level= level * qmul + qadd;
- else level= level * qmul - qadd;
-#if 0 // waste of time too :(
- if(level>2048 || level<-2048){
- fprintf(stderr, "|level| overflow in 3. esc\n");
- return DECODING_AC_LOST;
- }
-#endif
- i+= run + 1;
- if(last) i+=192;
-#ifdef ERROR_DETAILS
- if(run==66)
- fprintf(stderr, "illegal vlc code in ESC3 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- fprintf(stderr, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
-#endif
- } else {
- /* second escape */
-#if MIN_CACHE_BITS < 23
- LAST_SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
-#else
- SKIP_BITS(re, &s->gb, 2);
-#endif
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
-#ifdef ERROR_DETAILS
- if(run==66)
- fprintf(stderr, "illegal vlc code in ESC2 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- fprintf(stderr, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- } else {
- /* first escape */
-#if MIN_CACHE_BITS < 22
- LAST_SKIP_BITS(re, &s->gb, 1);
- UPDATE_CACHE(re, &s->gb);
-#else
- SKIP_BITS(re, &s->gb, 1);
-#endif
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2);
- i+= run;
- level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
-#ifdef ERROR_DETAILS
- if(run==66)
- fprintf(stderr, "illegal vlc code in ESC1 level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- fprintf(stderr, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- } else {
- i+= run;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
-#ifdef ERROR_DETAILS
- if(run==66)
- fprintf(stderr, "illegal vlc code level=%d\n", level);
- else if((i>62 && i<192) || i>192+63)
- fprintf(stderr, "run overflow i=%d run=%d level=%d\n", i, run, level);
-#endif
- }
- if (i > 62){
- i-= 192;
- if(i&(~63)){
- const int left= s->gb.size_in_bits - get_bits_count(&s->gb);
- if(((i+192 == 64 && level/qmul==-1) || s->error_resilience<=1) && left>=0){
- fprintf(stderr, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
- break;
- }else{
- fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- }
-
- block[scan_table[i]] = level;
- break;
- }
-
- block[scan_table[i]] = level;
- }
- CLOSE_READER(re, &s->gb);
- }
- not_coded:
- if (s->mb_intra) {
- mpeg4_pred_ac(s, block, n, dc_pred_dir);
- if (s->ac_pred) {
- i = 63; /* XXX: not optimal */
- }
- }
- if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
- s->block_last_index[n] = i;
-
- return 0;
-}
-
-static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
-{
- int level, pred;
-
- if(s->msmpeg4_version<=2){
- if (n < 4) {
- level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3);
- } else {
- level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3);
- }
- if (level < 0)
- return -1;
- level-=256;
- }else{ //FIXME optimize use unified tables & index
- if (n < 4) {
- level = get_vlc2(&s->gb, dc_lum_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- } else {
- level = get_vlc2(&s->gb, dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
- }
- if (level < 0){
- fprintf(stderr, "illegal dc vlc\n");
- return -1;
- }
-
- if (level == DC_MAX) {
- level = get_bits(&s->gb, 8);
- if (get_bits1(&s->gb))
- level = -level;
- } else if (level != 0) {
- if (get_bits1(&s->gb))
- level = -level;
- }
- }
-
- if(s->msmpeg4_version==1){
- int32_t *dc_val;
- pred = msmpeg4v1_pred_dc(s, n, &dc_val);
- level += pred;
-
- /* update predictor */
- *dc_val= level;
- }else{
- uint16_t *dc_val;
- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
- level += pred;
-
- /* update predictor */
- if (n < 4) {
- *dc_val = level * s->y_dc_scale;
- } else {
- *dc_val = level * s->c_dc_scale;
- }
- }
-
- return level;
-}
-
-static int msmpeg4_decode_motion(MpegEncContext * s,
- int *mx_ptr, int *my_ptr)
-{
- MVTable *mv;
- int code, mx, my;
-
- mv = &mv_tables[s->mv_table_index];
-
- code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
- if (code < 0){
- fprintf(stderr, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- if (code == mv->n) {
-//printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
- mx = get_bits(&s->gb, 6);
- my = get_bits(&s->gb, 6);
- } else {
- mx = mv->table_mvx[code];
- my = mv->table_mvy[code];
- }
-
- mx += *mx_ptr - 32;
- my += *my_ptr - 32;
- /* WARNING : they do not do exactly modulo encoding */
- if (mx <= -64)
- mx += 64;
- else if (mx >= 64)
- mx -= 64;
-
- if (my <= -64)
- my += 64;
- else if (my >= 64)
- my -= 64;
- *mx_ptr = mx;
- *my_ptr = my;
- return 0;
-}
-
-/* cleanest way to support it
- * there is too much shared between versions so that we cant have 1 file per version & 1 common
- * as allmost everything would be in the common file
- */
-#include "wmv2.c"
+++ /dev/null
-/**
- * @file msmpeg4data.h
- * MSMPEG4 data tables.
- */
-
-/* intra picture macro block coded block pattern */
-static const uint16_t table_mb_intra[64][2] = {
-{ 0x1, 1 },{ 0x17, 6 },{ 0x9, 5 },{ 0x5, 5 },
-{ 0x6, 5 },{ 0x47, 9 },{ 0x20, 7 },{ 0x10, 7 },
-{ 0x2, 5 },{ 0x7c, 9 },{ 0x3a, 7 },{ 0x1d, 7 },
-{ 0x2, 6 },{ 0xec, 9 },{ 0x77, 8 },{ 0x0, 8 },
-{ 0x3, 5 },{ 0xb7, 9 },{ 0x2c, 7 },{ 0x13, 7 },
-{ 0x1, 6 },{ 0x168, 10 },{ 0x46, 8 },{ 0x3f, 8 },
-{ 0x1e, 6 },{ 0x712, 13 },{ 0xb5, 9 },{ 0x42, 8 },
-{ 0x22, 7 },{ 0x1c5, 11 },{ 0x11e, 10 },{ 0x87, 9 },
-{ 0x6, 4 },{ 0x3, 9 },{ 0x1e, 7 },{ 0x1c, 6 },
-{ 0x12, 7 },{ 0x388, 12 },{ 0x44, 9 },{ 0x70, 9 },
-{ 0x1f, 6 },{ 0x23e, 11 },{ 0x39, 8 },{ 0x8e, 9 },
-{ 0x1, 7 },{ 0x1c6, 11 },{ 0xb6, 9 },{ 0x45, 9 },
-{ 0x14, 6 },{ 0x23f, 11 },{ 0x7d, 9 },{ 0x18, 9 },
-{ 0x7, 7 },{ 0x1c7, 11 },{ 0x86, 9 },{ 0x19, 9 },
-{ 0x15, 6 },{ 0x1db, 10 },{ 0x2, 9 },{ 0x46, 9 },
-{ 0xd, 8 },{ 0x713, 13 },{ 0x1da, 10 },{ 0x169, 10 },
-};
-
-/* non intra picture macro block coded block pattern + mb type */
-static const uint32_t table_mb_non_intra[128][2] = {
-{ 0x40, 7 },{ 0x13c9, 13 },{ 0x9fd, 12 },{ 0x1fc, 15 },
-{ 0x9fc, 12 },{ 0xa83, 18 },{ 0x12d34, 17 },{ 0x83bc, 16 },
-{ 0x83a, 12 },{ 0x7f8, 17 },{ 0x3fd, 16 },{ 0x3ff, 16 },
-{ 0x79, 13 },{ 0xa82, 18 },{ 0x969d, 16 },{ 0x2a4, 16 },
-{ 0x978, 12 },{ 0x543, 17 },{ 0x41df, 15 },{ 0x7f9, 17 },
-{ 0x12f3, 13 },{ 0x25a6b, 18 },{ 0x25ef9, 18 },{ 0x3fa, 16 },
-{ 0x20ee, 14 },{ 0x969ab, 20 },{ 0x969c, 16 },{ 0x25ef8, 18 },
-{ 0x12d2, 13 },{ 0xa85, 18 },{ 0x969e, 16 },{ 0x4bc8, 15 },
-{ 0x3d, 12 },{ 0x12f7f, 17 },{ 0x2a2, 16 },{ 0x969f, 16 },
-{ 0x25ee, 14 },{ 0x12d355, 21 },{ 0x12f7d, 17 },{ 0x12f7e, 17 },
-{ 0x9e5, 12 },{ 0xa81, 18 },{ 0x4b4d4, 19 },{ 0x83bd, 16 },
-{ 0x78, 13 },{ 0x969b, 16 },{ 0x3fe, 16 },{ 0x2a5, 16 },
-{ 0x7e, 13 },{ 0xa80, 18 },{ 0x2a3, 16 },{ 0x3fb, 16 },
-{ 0x1076, 13 },{ 0xa84, 18 },{ 0x153, 15 },{ 0x4bc9, 15 },
-{ 0x55, 13 },{ 0x12d354, 21 },{ 0x4bde, 15 },{ 0x25e5, 14 },
-{ 0x25b, 10 },{ 0x4b4c, 15 },{ 0x96b, 12 },{ 0x96a, 12 },
-{ 0x1, 2 },{ 0x0, 7 },{ 0x26, 6 },{ 0x12b, 9 },
-{ 0x7, 3 },{ 0x20f, 10 },{ 0x4, 9 },{ 0x28, 12 },
-{ 0x6, 3 },{ 0x20a, 10 },{ 0x128, 9 },{ 0x2b, 12 },
-{ 0x11, 5 },{ 0x1b, 11 },{ 0x13a, 9 },{ 0x4ff, 11 },
-{ 0x3, 4 },{ 0x277, 10 },{ 0x106, 9 },{ 0x839, 12 },
-{ 0xb, 4 },{ 0x27b, 10 },{ 0x12c, 9 },{ 0x4bf, 11 },
-{ 0x9, 6 },{ 0x35, 12 },{ 0x27e, 10 },{ 0x13c8, 13 },
-{ 0x1, 6 },{ 0x4aa, 11 },{ 0x208, 10 },{ 0x29, 12 },
-{ 0x1, 4 },{ 0x254, 10 },{ 0x12e, 9 },{ 0x838, 12 },
-{ 0x24, 6 },{ 0x4f3, 11 },{ 0x276, 10 },{ 0x12f6, 13 },
-{ 0x1, 5 },{ 0x27a, 10 },{ 0x13e, 9 },{ 0x3e, 12 },
-{ 0x8, 6 },{ 0x413, 11 },{ 0xc, 10 },{ 0x4be, 11 },
-{ 0x14, 5 },{ 0x412, 11 },{ 0x253, 10 },{ 0x97a, 12 },
-{ 0x21, 6 },{ 0x4ab, 11 },{ 0x20b, 10 },{ 0x34, 12 },
-{ 0x15, 5 },{ 0x278, 10 },{ 0x252, 10 },{ 0x968, 12 },
-{ 0x5, 5 },{ 0xb, 10 },{ 0x9c, 8 },{ 0xe, 10 },
-};
-
-/* dc table 0 */
-
-static const uint32_t table0_dc_lum[120][2] = {
-{ 0x1, 1 },{ 0x1, 2 },{ 0x1, 4 },{ 0x1, 5 },
-{ 0x5, 5 },{ 0x7, 5 },{ 0x8, 6 },{ 0xc, 6 },
-{ 0x0, 7 },{ 0x2, 7 },{ 0x12, 7 },{ 0x1a, 7 },
-{ 0x3, 8 },{ 0x7, 8 },{ 0x27, 8 },{ 0x37, 8 },
-{ 0x5, 9 },{ 0x4c, 9 },{ 0x6c, 9 },{ 0x6d, 9 },
-{ 0x8, 10 },{ 0x19, 10 },{ 0x9b, 10 },{ 0x1b, 10 },
-{ 0x9a, 10 },{ 0x13, 11 },{ 0x34, 11 },{ 0x35, 11 },
-{ 0x61, 12 },{ 0x48, 13 },{ 0xc4, 13 },{ 0x4a, 13 },
-{ 0xc6, 13 },{ 0xc7, 13 },{ 0x92, 14 },{ 0x18b, 14 },
-{ 0x93, 14 },{ 0x183, 14 },{ 0x182, 14 },{ 0x96, 14 },
-{ 0x97, 14 },{ 0x180, 14 },{ 0x314, 15 },{ 0x315, 15 },
-{ 0x605, 16 },{ 0x604, 16 },{ 0x606, 16 },{ 0xc0e, 17 },
-{ 0x303cd, 23 },{ 0x303c9, 23 },{ 0x303c8, 23 },{ 0x303ca, 23 },
-{ 0x303cb, 23 },{ 0x303cc, 23 },{ 0x303ce, 23 },{ 0x303cf, 23 },
-{ 0x303d0, 23 },{ 0x303d1, 23 },{ 0x303d2, 23 },{ 0x303d3, 23 },
-{ 0x303d4, 23 },{ 0x303d5, 23 },{ 0x303d6, 23 },{ 0x303d7, 23 },
-{ 0x303d8, 23 },{ 0x303d9, 23 },{ 0x303da, 23 },{ 0x303db, 23 },
-{ 0x303dc, 23 },{ 0x303dd, 23 },{ 0x303de, 23 },{ 0x303df, 23 },
-{ 0x303e0, 23 },{ 0x303e1, 23 },{ 0x303e2, 23 },{ 0x303e3, 23 },
-{ 0x303e4, 23 },{ 0x303e5, 23 },{ 0x303e6, 23 },{ 0x303e7, 23 },
-{ 0x303e8, 23 },{ 0x303e9, 23 },{ 0x303ea, 23 },{ 0x303eb, 23 },
-{ 0x303ec, 23 },{ 0x303ed, 23 },{ 0x303ee, 23 },{ 0x303ef, 23 },
-{ 0x303f0, 23 },{ 0x303f1, 23 },{ 0x303f2, 23 },{ 0x303f3, 23 },
-{ 0x303f4, 23 },{ 0x303f5, 23 },{ 0x303f6, 23 },{ 0x303f7, 23 },
-{ 0x303f8, 23 },{ 0x303f9, 23 },{ 0x303fa, 23 },{ 0x303fb, 23 },
-{ 0x303fc, 23 },{ 0x303fd, 23 },{ 0x303fe, 23 },{ 0x303ff, 23 },
-{ 0x60780, 24 },{ 0x60781, 24 },{ 0x60782, 24 },{ 0x60783, 24 },
-{ 0x60784, 24 },{ 0x60785, 24 },{ 0x60786, 24 },{ 0x60787, 24 },
-{ 0x60788, 24 },{ 0x60789, 24 },{ 0x6078a, 24 },{ 0x6078b, 24 },
-{ 0x6078c, 24 },{ 0x6078d, 24 },{ 0x6078e, 24 },{ 0x6078f, 24 },
-};
-
-static const uint32_t table0_dc_chroma[120][2] = {
-{ 0x0, 2 },{ 0x1, 2 },{ 0x5, 3 },{ 0x9, 4 },
-{ 0xd, 4 },{ 0x11, 5 },{ 0x1d, 5 },{ 0x1f, 5 },
-{ 0x21, 6 },{ 0x31, 6 },{ 0x38, 6 },{ 0x33, 6 },
-{ 0x39, 6 },{ 0x3d, 6 },{ 0x61, 7 },{ 0x79, 7 },
-{ 0x80, 8 },{ 0xc8, 8 },{ 0xca, 8 },{ 0xf0, 8 },
-{ 0x81, 8 },{ 0xc0, 8 },{ 0xc9, 8 },{ 0x107, 9 },
-{ 0x106, 9 },{ 0x196, 9 },{ 0x183, 9 },{ 0x1e3, 9 },
-{ 0x1e2, 9 },{ 0x20a, 10 },{ 0x20b, 10 },{ 0x609, 11 },
-{ 0x412, 11 },{ 0x413, 11 },{ 0x60b, 11 },{ 0x411, 11 },
-{ 0x60a, 11 },{ 0x65f, 11 },{ 0x410, 11 },{ 0x65d, 11 },
-{ 0x65e, 11 },{ 0xcb8, 12 },{ 0xc10, 12 },{ 0xcb9, 12 },
-{ 0x1823, 13 },{ 0x3045, 14 },{ 0x6089, 15 },{ 0xc110, 16 },
-{ 0x304448, 22 },{ 0x304449, 22 },{ 0x30444a, 22 },{ 0x30444b, 22 },
-{ 0x30444c, 22 },{ 0x30444d, 22 },{ 0x30444e, 22 },{ 0x30444f, 22 },
-{ 0x304450, 22 },{ 0x304451, 22 },{ 0x304452, 22 },{ 0x304453, 22 },
-{ 0x304454, 22 },{ 0x304455, 22 },{ 0x304456, 22 },{ 0x304457, 22 },
-{ 0x304458, 22 },{ 0x304459, 22 },{ 0x30445a, 22 },{ 0x30445b, 22 },
-{ 0x30445c, 22 },{ 0x30445d, 22 },{ 0x30445e, 22 },{ 0x30445f, 22 },
-{ 0x304460, 22 },{ 0x304461, 22 },{ 0x304462, 22 },{ 0x304463, 22 },
-{ 0x304464, 22 },{ 0x304465, 22 },{ 0x304466, 22 },{ 0x304467, 22 },
-{ 0x304468, 22 },{ 0x304469, 22 },{ 0x30446a, 22 },{ 0x30446b, 22 },
-{ 0x30446c, 22 },{ 0x30446d, 22 },{ 0x30446e, 22 },{ 0x30446f, 22 },
-{ 0x304470, 22 },{ 0x304471, 22 },{ 0x304472, 22 },{ 0x304473, 22 },
-{ 0x304474, 22 },{ 0x304475, 22 },{ 0x304476, 22 },{ 0x304477, 22 },
-{ 0x304478, 22 },{ 0x304479, 22 },{ 0x30447a, 22 },{ 0x30447b, 22 },
-{ 0x30447c, 22 },{ 0x30447d, 22 },{ 0x30447e, 22 },{ 0x30447f, 22 },
-{ 0x608880, 23 },{ 0x608881, 23 },{ 0x608882, 23 },{ 0x608883, 23 },
-{ 0x608884, 23 },{ 0x608885, 23 },{ 0x608886, 23 },{ 0x608887, 23 },
-{ 0x608888, 23 },{ 0x608889, 23 },{ 0x60888a, 23 },{ 0x60888b, 23 },
-{ 0x60888c, 23 },{ 0x60888d, 23 },{ 0x60888e, 23 },{ 0x60888f, 23 },
-};
-
-/* dc table 1 */
-
-static const uint32_t table1_dc_lum[120][2] = {
-{ 0x2, 2 },{ 0x3, 2 },{ 0x3, 3 },{ 0x2, 4 },
-{ 0x5, 4 },{ 0x1, 5 },{ 0x3, 5 },{ 0x8, 5 },
-{ 0x0, 6 },{ 0x5, 6 },{ 0xd, 6 },{ 0xf, 6 },
-{ 0x13, 6 },{ 0x8, 7 },{ 0x18, 7 },{ 0x1c, 7 },
-{ 0x24, 7 },{ 0x4, 8 },{ 0x6, 8 },{ 0x12, 8 },
-{ 0x32, 8 },{ 0x3b, 8 },{ 0x4a, 8 },{ 0x4b, 8 },
-{ 0xb, 9 },{ 0x26, 9 },{ 0x27, 9 },{ 0x66, 9 },
-{ 0x74, 9 },{ 0x75, 9 },{ 0x14, 10 },{ 0x1c, 10 },
-{ 0x1f, 10 },{ 0x1d, 10 },{ 0x2b, 11 },{ 0x3d, 11 },
-{ 0x19d, 11 },{ 0x19f, 11 },{ 0x54, 12 },{ 0x339, 12 },
-{ 0x338, 12 },{ 0x33d, 12 },{ 0xab, 13 },{ 0xf1, 13 },
-{ 0x678, 13 },{ 0xf2, 13 },{ 0x1e0, 14 },{ 0x1e1, 14 },
-{ 0x154, 14 },{ 0xcf2, 14 },{ 0x3cc, 15 },{ 0x2ab, 15 },
-{ 0x19e7, 15 },{ 0x3ce, 15 },{ 0x19e6, 15 },{ 0x554, 16 },
-{ 0x79f, 16 },{ 0x555, 16 },{ 0xf3d, 17 },{ 0xf37, 17 },
-{ 0xf3c, 17 },{ 0xf35, 17 },{ 0x1e6d, 18 },{ 0x1e68, 18 },
-{ 0x3cd8, 19 },{ 0x3cd3, 19 },{ 0x3cd9, 19 },{ 0x79a4, 20 },
-{ 0xf34ba, 25 },{ 0xf34b4, 25 },{ 0xf34b5, 25 },{ 0xf34b6, 25 },
-{ 0xf34b7, 25 },{ 0xf34b8, 25 },{ 0xf34b9, 25 },{ 0xf34bb, 25 },
-{ 0xf34bc, 25 },{ 0xf34bd, 25 },{ 0xf34be, 25 },{ 0xf34bf, 25 },
-{ 0x1e6940, 26 },{ 0x1e6941, 26 },{ 0x1e6942, 26 },{ 0x1e6943, 26 },
-{ 0x1e6944, 26 },{ 0x1e6945, 26 },{ 0x1e6946, 26 },{ 0x1e6947, 26 },
-{ 0x1e6948, 26 },{ 0x1e6949, 26 },{ 0x1e694a, 26 },{ 0x1e694b, 26 },
-{ 0x1e694c, 26 },{ 0x1e694d, 26 },{ 0x1e694e, 26 },{ 0x1e694f, 26 },
-{ 0x1e6950, 26 },{ 0x1e6951, 26 },{ 0x1e6952, 26 },{ 0x1e6953, 26 },
-{ 0x1e6954, 26 },{ 0x1e6955, 26 },{ 0x1e6956, 26 },{ 0x1e6957, 26 },
-{ 0x1e6958, 26 },{ 0x1e6959, 26 },{ 0x1e695a, 26 },{ 0x1e695b, 26 },
-{ 0x1e695c, 26 },{ 0x1e695d, 26 },{ 0x1e695e, 26 },{ 0x1e695f, 26 },
-{ 0x1e6960, 26 },{ 0x1e6961, 26 },{ 0x1e6962, 26 },{ 0x1e6963, 26 },
-{ 0x1e6964, 26 },{ 0x1e6965, 26 },{ 0x1e6966, 26 },{ 0x1e6967, 26 },
-};
-
-static const uint32_t table1_dc_chroma[120][2] = {
-{ 0x0, 2 },{ 0x1, 2 },{ 0x4, 3 },{ 0x7, 3 },
-{ 0xb, 4 },{ 0xd, 4 },{ 0x15, 5 },{ 0x28, 6 },
-{ 0x30, 6 },{ 0x32, 6 },{ 0x52, 7 },{ 0x62, 7 },
-{ 0x66, 7 },{ 0xa6, 8 },{ 0xc6, 8 },{ 0xcf, 8 },
-{ 0x14f, 9 },{ 0x18e, 9 },{ 0x19c, 9 },{ 0x29d, 10 },
-{ 0x33a, 10 },{ 0x538, 11 },{ 0x63c, 11 },{ 0x63e, 11 },
-{ 0x63f, 11 },{ 0x676, 11 },{ 0xa73, 12 },{ 0xc7a, 12 },
-{ 0xcef, 12 },{ 0x14e5, 13 },{ 0x19dd, 13 },{ 0x29c8, 14 },
-{ 0x29c9, 14 },{ 0x63dd, 15 },{ 0x33b8, 14 },{ 0x33b9, 14 },
-{ 0xc7b6, 16 },{ 0x63d8, 15 },{ 0x63df, 15 },{ 0xc7b3, 16 },
-{ 0xc7b4, 16 },{ 0xc7b5, 16 },{ 0x63de, 15 },{ 0xc7b7, 16 },
-{ 0xc7b8, 16 },{ 0xc7b9, 16 },{ 0x18f65, 17 },{ 0x31ec8, 18 },
-{ 0xc7b248, 24 },{ 0xc7b249, 24 },{ 0xc7b24a, 24 },{ 0xc7b24b, 24 },
-{ 0xc7b24c, 24 },{ 0xc7b24d, 24 },{ 0xc7b24e, 24 },{ 0xc7b24f, 24 },
-{ 0xc7b250, 24 },{ 0xc7b251, 24 },{ 0xc7b252, 24 },{ 0xc7b253, 24 },
-{ 0xc7b254, 24 },{ 0xc7b255, 24 },{ 0xc7b256, 24 },{ 0xc7b257, 24 },
-{ 0xc7b258, 24 },{ 0xc7b259, 24 },{ 0xc7b25a, 24 },{ 0xc7b25b, 24 },
-{ 0xc7b25c, 24 },{ 0xc7b25d, 24 },{ 0xc7b25e, 24 },{ 0xc7b25f, 24 },
-{ 0xc7b260, 24 },{ 0xc7b261, 24 },{ 0xc7b262, 24 },{ 0xc7b263, 24 },
-{ 0xc7b264, 24 },{ 0xc7b265, 24 },{ 0xc7b266, 24 },{ 0xc7b267, 24 },
-{ 0xc7b268, 24 },{ 0xc7b269, 24 },{ 0xc7b26a, 24 },{ 0xc7b26b, 24 },
-{ 0xc7b26c, 24 },{ 0xc7b26d, 24 },{ 0xc7b26e, 24 },{ 0xc7b26f, 24 },
-{ 0xc7b270, 24 },{ 0xc7b271, 24 },{ 0xc7b272, 24 },{ 0xc7b273, 24 },
-{ 0xc7b274, 24 },{ 0xc7b275, 24 },{ 0xc7b276, 24 },{ 0xc7b277, 24 },
-{ 0xc7b278, 24 },{ 0xc7b279, 24 },{ 0xc7b27a, 24 },{ 0xc7b27b, 24 },
-{ 0xc7b27c, 24 },{ 0xc7b27d, 24 },{ 0xc7b27e, 24 },{ 0xc7b27f, 24 },
-{ 0x18f6480, 25 },{ 0x18f6481, 25 },{ 0x18f6482, 25 },{ 0x18f6483, 25 },
-{ 0x18f6484, 25 },{ 0x18f6485, 25 },{ 0x18f6486, 25 },{ 0x18f6487, 25 },
-{ 0x18f6488, 25 },{ 0x18f6489, 25 },{ 0x18f648a, 25 },{ 0x18f648b, 25 },
-{ 0x18f648c, 25 },{ 0x18f648d, 25 },{ 0x18f648e, 25 },{ 0x18f648f, 25 },
-};
-
-/* vlc table 0, for intra luma */
-
-static const uint16_t table0_vlc[133][2] = {
-{ 0x1, 2 },{ 0x6, 3 },{ 0xf, 4 },{ 0x16, 5 },
-{ 0x20, 6 },{ 0x18, 7 },{ 0x8, 8 },{ 0x9a, 8 },
-{ 0x56, 9 },{ 0x13e, 9 },{ 0xf0, 10 },{ 0x3a5, 10 },
-{ 0x77, 11 },{ 0x1ef, 11 },{ 0x9a, 12 },{ 0x5d, 13 },
-{ 0x1, 4 },{ 0x11, 5 },{ 0x2, 7 },{ 0xb, 8 },
-{ 0x12, 9 },{ 0x1d6, 9 },{ 0x27e, 10 },{ 0x191, 11 },
-{ 0xea, 12 },{ 0x3dc, 12 },{ 0x13b, 13 },{ 0x4, 5 },
-{ 0x14, 7 },{ 0x9e, 8 },{ 0x9, 10 },{ 0x1ac, 11 },
-{ 0x1e2, 11 },{ 0x3ca, 12 },{ 0x5f, 13 },{ 0x17, 5 },
-{ 0x4e, 7 },{ 0x5e, 9 },{ 0xf3, 10 },{ 0x1ad, 11 },
-{ 0xec, 12 },{ 0x5f0, 13 },{ 0xe, 6 },{ 0xe1, 8 },
-{ 0x3a4, 10 },{ 0x9c, 12 },{ 0x13d, 13 },{ 0x3b, 6 },
-{ 0x1c, 9 },{ 0x14, 11 },{ 0x9be, 12 },{ 0x6, 7 },
-{ 0x7a, 9 },{ 0x190, 11 },{ 0x137, 13 },{ 0x1b, 7 },
-{ 0x8, 10 },{ 0x75c, 11 },{ 0x71, 7 },{ 0xd7, 10 },
-{ 0x9bf, 12 },{ 0x7, 8 },{ 0xaf, 10 },{ 0x4cc, 11 },
-{ 0x34, 8 },{ 0x265, 10 },{ 0x9f, 12 },{ 0xe0, 8 },
-{ 0x16, 11 },{ 0x327, 12 },{ 0x15, 9 },{ 0x17d, 11 },
-{ 0xebb, 12 },{ 0x14, 9 },{ 0xf6, 10 },{ 0x1e4, 11 },
-{ 0xcb, 10 },{ 0x99d, 12 },{ 0xca, 10 },{ 0x2fc, 12 },
-{ 0x17f, 11 },{ 0x4cd, 11 },{ 0x2fd, 12 },{ 0x4fe, 11 },
-{ 0x13a, 13 },{ 0xa, 4 },{ 0x42, 7 },{ 0x1d3, 9 },
-{ 0x4dd, 11 },{ 0x12, 5 },{ 0xe8, 8 },{ 0x4c, 11 },
-{ 0x136, 13 },{ 0x39, 6 },{ 0x264, 10 },{ 0xeba, 12 },
-{ 0x0, 7 },{ 0xae, 10 },{ 0x99c, 12 },{ 0x1f, 7 },
-{ 0x4de, 11 },{ 0x43, 7 },{ 0x4dc, 11 },{ 0x3, 8 },
-{ 0x3cb, 12 },{ 0x6, 8 },{ 0x99e, 12 },{ 0x2a, 8 },
-{ 0x5f1, 13 },{ 0xf, 8 },{ 0x9fe, 12 },{ 0x33, 8 },
-{ 0x9ff, 12 },{ 0x98, 8 },{ 0x99f, 12 },{ 0xea, 8 },
-{ 0x13c, 13 },{ 0x2e, 8 },{ 0x192, 11 },{ 0x136, 9 },
-{ 0x6a, 9 },{ 0x15, 11 },{ 0x3af, 10 },{ 0x1e3, 11 },
-{ 0x74, 11 },{ 0xeb, 12 },{ 0x2f9, 12 },{ 0x5c, 13 },
-{ 0xed, 12 },{ 0x3dd, 12 },{ 0x326, 12 },{ 0x5e, 13 },
-{ 0x16, 7 },
-};
-
-static const int8_t table0_level[132] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 1, 2, 3, 4, 5,
- 6, 7, 8, 1, 2, 3, 4, 5,
- 6, 7, 1, 2, 3, 4, 5, 1,
- 2, 3, 4, 1, 2, 3, 4, 1,
- 2, 3, 1, 2, 3, 1, 2, 3,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 3, 1, 2, 3, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 2, 3,
- 4, 1, 2, 3, 4, 1, 2, 3,
- 1, 2, 3, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const int8_t table0_run[132] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 2, 2, 2, 2, 2,
- 2, 2, 2, 3, 3, 3, 3, 3,
- 3, 3, 4, 4, 4, 4, 4, 5,
- 5, 5, 5, 6, 6, 6, 6, 7,
- 7, 7, 8, 8, 8, 9, 9, 9,
- 10, 10, 10, 11, 11, 11, 12, 12,
- 12, 13, 13, 13, 14, 14, 15, 15,
- 16, 17, 18, 19, 20, 0, 0, 0,
- 0, 1, 1, 1, 1, 2, 2, 2,
- 3, 3, 3, 4, 4, 5, 5, 6,
- 6, 7, 7, 8, 8, 9, 9, 10,
- 10, 11, 11, 12, 12, 13, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22,
- 23, 24, 25, 26,
-};
-
-/* vlc table 1, for intra chroma and P macro blocks */
-
-static const uint16_t table1_vlc[149][2] = {
-{ 0x4, 3 },{ 0x14, 5 },{ 0x17, 7 },{ 0x7f, 8 },
-{ 0x154, 9 },{ 0x1f2, 10 },{ 0xbf, 11 },{ 0x65, 12 },
-{ 0xaaa, 12 },{ 0x630, 13 },{ 0x1597, 13 },{ 0x3b7, 14 },
-{ 0x2b22, 14 },{ 0xbe6, 15 },{ 0xb, 4 },{ 0x37, 7 },
-{ 0x62, 9 },{ 0x7, 11 },{ 0x166, 12 },{ 0xce, 13 },
-{ 0x1590, 13 },{ 0x5f6, 14 },{ 0xbe7, 15 },{ 0x7, 5 },
-{ 0x6d, 8 },{ 0x3, 11 },{ 0x31f, 12 },{ 0x5f2, 14 },
-{ 0x2, 6 },{ 0x61, 9 },{ 0x55, 12 },{ 0x1df, 14 },
-{ 0x1a, 6 },{ 0x1e, 10 },{ 0xac9, 12 },{ 0x2b23, 14 },
-{ 0x1e, 6 },{ 0x1f, 10 },{ 0xac3, 12 },{ 0x2b2b, 14 },
-{ 0x6, 7 },{ 0x4, 11 },{ 0x2f8, 13 },{ 0x19, 7 },
-{ 0x6, 11 },{ 0x63d, 13 },{ 0x57, 7 },{ 0x182, 11 },
-{ 0x2aa2, 14 },{ 0x4, 8 },{ 0x180, 11 },{ 0x59c, 14 },
-{ 0x7d, 8 },{ 0x164, 12 },{ 0x76d, 15 },{ 0x2, 9 },
-{ 0x18d, 11 },{ 0x1581, 13 },{ 0xad, 8 },{ 0x60, 12 },
-{ 0xc67, 14 },{ 0x1c, 9 },{ 0xee, 13 },{ 0x3, 9 },
-{ 0x2cf, 13 },{ 0xd9, 9 },{ 0x1580, 13 },{ 0x2, 11 },
-{ 0x183, 11 },{ 0x57, 12 },{ 0x61, 12 },{ 0x31, 11 },
-{ 0x66, 12 },{ 0x631, 13 },{ 0x632, 13 },{ 0xac, 13 },
-{ 0x31d, 12 },{ 0x76, 12 },{ 0x3a, 11 },{ 0x165, 12 },
-{ 0xc66, 14 },{ 0x3, 2 },{ 0x54, 7 },{ 0x2ab, 10 },
-{ 0x16, 13 },{ 0x5f7, 14 },{ 0x5, 4 },{ 0xf8, 9 },
-{ 0xaa9, 12 },{ 0x5f, 15 },{ 0x4, 4 },{ 0x1c, 10 },
-{ 0x1550, 13 },{ 0x4, 5 },{ 0x77, 11 },{ 0x76c, 15 },
-{ 0xe, 5 },{ 0xa, 12 },{ 0xc, 5 },{ 0x562, 11 },
-{ 0x4, 6 },{ 0x31c, 12 },{ 0x6, 6 },{ 0xc8, 13 },
-{ 0xd, 6 },{ 0x1da, 13 },{ 0x7, 6 },{ 0xc9, 13 },
-{ 0x1, 7 },{ 0x2e, 14 },{ 0x14, 7 },{ 0x1596, 13 },
-{ 0xa, 7 },{ 0xac2, 12 },{ 0x16, 7 },{ 0x15b, 14 },
-{ 0x15, 7 },{ 0x15a, 14 },{ 0xf, 8 },{ 0x5e, 15 },
-{ 0x7e, 8 },{ 0xab, 8 },{ 0x2d, 9 },{ 0xd8, 9 },
-{ 0xb, 9 },{ 0x14, 10 },{ 0x2b3, 10 },{ 0x1f3, 10 },
-{ 0x3a, 10 },{ 0x0, 10 },{ 0x58, 10 },{ 0x2e, 9 },
-{ 0x5e, 10 },{ 0x563, 11 },{ 0xec, 12 },{ 0x54, 12 },
-{ 0xac1, 12 },{ 0x1556, 13 },{ 0x2fa, 13 },{ 0x181, 11 },
-{ 0x1557, 13 },{ 0x59d, 14 },{ 0x2aa3, 14 },{ 0x2b2a, 14 },
-{ 0x1de, 14 },{ 0x63c, 13 },{ 0xcf, 13 },{ 0x1594, 13 },
-{ 0xd, 9 },
-};
-
-static const int8_t table1_level[148] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 1, 2,
- 3, 4, 5, 6, 7, 8, 9, 1,
- 2, 3, 4, 5, 1, 2, 3, 4,
- 1, 2, 3, 4, 1, 2, 3, 4,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 3, 1, 2, 3, 1, 2, 3, 1,
- 2, 3, 1, 2, 3, 1, 2, 1,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 2, 3, 4, 5, 1, 2,
- 3, 4, 1, 2, 3, 1, 2, 3,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const int8_t table1_run[148] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 2,
- 2, 2, 2, 2, 3, 3, 3, 3,
- 4, 4, 4, 4, 5, 5, 5, 5,
- 6, 6, 6, 7, 7, 7, 8, 8,
- 8, 9, 9, 9, 10, 10, 10, 11,
- 11, 11, 12, 12, 12, 13, 13, 14,
- 14, 15, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28,
- 29, 0, 0, 0, 0, 0, 1, 1,
- 1, 1, 2, 2, 2, 3, 3, 3,
- 4, 4, 5, 5, 6, 6, 7, 7,
- 8, 8, 9, 9, 10, 10, 11, 11,
- 12, 12, 13, 13, 14, 14, 15, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43,
-};
-
-/* third vlc table */
-
-static const uint16_t table2_vlc[186][2] = {
-{ 0x1, 2 },{ 0x5, 3 },{ 0xd, 4 },{ 0x12, 5 },
-{ 0xe, 6 },{ 0x15, 7 },{ 0x13, 8 },{ 0x3f, 8 },
-{ 0x4b, 9 },{ 0x11f, 9 },{ 0xb8, 10 },{ 0x3e3, 10 },
-{ 0x172, 11 },{ 0x24d, 12 },{ 0x3da, 12 },{ 0x2dd, 13 },
-{ 0x1f55, 13 },{ 0x5b9, 14 },{ 0x3eae, 14 },{ 0x0, 4 },
-{ 0x10, 5 },{ 0x8, 7 },{ 0x20, 8 },{ 0x29, 9 },
-{ 0x1f4, 9 },{ 0x233, 10 },{ 0x1e0, 11 },{ 0x12a, 12 },
-{ 0x3dd, 12 },{ 0x50a, 13 },{ 0x1f29, 13 },{ 0xa42, 14 },
-{ 0x1272, 15 },{ 0x1737, 15 },{ 0x3, 5 },{ 0x11, 7 },
-{ 0xc4, 8 },{ 0x4b, 10 },{ 0xb4, 11 },{ 0x7d4, 11 },
-{ 0x345, 12 },{ 0x2d7, 13 },{ 0x7bf, 13 },{ 0x938, 14 },
-{ 0xbbb, 14 },{ 0x95e, 15 },{ 0x13, 5 },{ 0x78, 7 },
-{ 0x69, 9 },{ 0x232, 10 },{ 0x461, 11 },{ 0x3ec, 12 },
-{ 0x520, 13 },{ 0x1f2a, 13 },{ 0x3e50, 14 },{ 0x3e51, 14 },
-{ 0x1486, 15 },{ 0xc, 6 },{ 0x24, 9 },{ 0x94, 11 },
-{ 0x8c0, 12 },{ 0xf09, 14 },{ 0x1ef0, 15 },{ 0x3d, 6 },
-{ 0x53, 9 },{ 0x1a0, 11 },{ 0x2d6, 13 },{ 0xf08, 14 },
-{ 0x13, 7 },{ 0x7c, 9 },{ 0x7c1, 11 },{ 0x4ac, 14 },
-{ 0x1b, 7 },{ 0xa0, 10 },{ 0x344, 12 },{ 0xf79, 14 },
-{ 0x79, 7 },{ 0x3e1, 10 },{ 0x2d4, 13 },{ 0x2306, 14 },
-{ 0x21, 8 },{ 0x23c, 10 },{ 0xfae, 12 },{ 0x23de, 14 },
-{ 0x35, 8 },{ 0x175, 11 },{ 0x7b3, 13 },{ 0xc5, 8 },
-{ 0x174, 11 },{ 0x785, 13 },{ 0x48, 9 },{ 0x1a3, 11 },
-{ 0x49e, 13 },{ 0x2c, 9 },{ 0xfa, 10 },{ 0x7d6, 11 },
-{ 0x92, 10 },{ 0x5cc, 13 },{ 0x1ef1, 15 },{ 0xa3, 10 },
-{ 0x3ed, 12 },{ 0x93e, 14 },{ 0x1e2, 11 },{ 0x1273, 15 },
-{ 0x7c4, 11 },{ 0x1487, 15 },{ 0x291, 12 },{ 0x293, 12 },
-{ 0xf8a, 12 },{ 0x509, 13 },{ 0x508, 13 },{ 0x78d, 13 },
-{ 0x7be, 13 },{ 0x78c, 13 },{ 0x4ae, 14 },{ 0xbba, 14 },
-{ 0x2307, 14 },{ 0xb9a, 14 },{ 0x1736, 15 },{ 0xe, 4 },
-{ 0x45, 7 },{ 0x1f3, 9 },{ 0x47a, 11 },{ 0x5dc, 13 },
-{ 0x23df, 14 },{ 0x19, 5 },{ 0x28, 9 },{ 0x176, 11 },
-{ 0x49d, 13 },{ 0x23dd, 14 },{ 0x30, 6 },{ 0xa2, 10 },
-{ 0x2ef, 12 },{ 0x5b8, 14 },{ 0x3f, 6 },{ 0xa5, 10 },
-{ 0x3db, 12 },{ 0x93f, 14 },{ 0x44, 7 },{ 0x7cb, 11 },
-{ 0x95f, 15 },{ 0x63, 7 },{ 0x3c3, 12 },{ 0x15, 8 },
-{ 0x8f6, 12 },{ 0x17, 8 },{ 0x498, 13 },{ 0x2c, 8 },
-{ 0x7b2, 13 },{ 0x2f, 8 },{ 0x1f54, 13 },{ 0x8d, 8 },
-{ 0x7bd, 13 },{ 0x8e, 8 },{ 0x1182, 13 },{ 0xfb, 8 },
-{ 0x50b, 13 },{ 0x2d, 8 },{ 0x7c0, 11 },{ 0x79, 9 },
-{ 0x1f5f, 13 },{ 0x7a, 9 },{ 0x1f56, 13 },{ 0x231, 10 },
-{ 0x3e4, 10 },{ 0x1a1, 11 },{ 0x143, 11 },{ 0x1f7, 11 },
-{ 0x16f, 12 },{ 0x292, 12 },{ 0x2e7, 12 },{ 0x16c, 12 },
-{ 0x16d, 12 },{ 0x3dc, 12 },{ 0xf8b, 12 },{ 0x499, 13 },
-{ 0x3d8, 12 },{ 0x78e, 13 },{ 0x2d5, 13 },{ 0x1f5e, 13 },
-{ 0x1f2b, 13 },{ 0x78f, 13 },{ 0x4ad, 14 },{ 0x3eaf, 14 },
-{ 0x23dc, 14 },{ 0x4a, 9 },
-};
-
-static const int8_t table2_level[185] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 1, 2, 3, 4, 5, 6,
- 7, 8, 9, 10, 11, 12, 1, 2,
- 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 1, 2, 3, 4, 5, 6, 1,
- 2, 3, 4, 5, 1, 2, 3, 4,
- 1, 2, 3, 4, 1, 2, 3, 4,
- 1, 2, 3, 4, 1, 2, 3, 1,
- 2, 3, 1, 2, 3, 1, 2, 3,
- 1, 2, 3, 1, 2, 3, 1, 2,
- 1, 2, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 3, 4, 5, 6, 1, 2, 3,
- 4, 5, 1, 2, 3, 4, 1, 2,
- 3, 4, 1, 2, 3, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1,
-};
-
-static const int8_t table2_run[185] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 3,
- 3, 4, 4, 4, 4, 4, 4, 5,
- 5, 5, 5, 5, 6, 6, 6, 6,
- 7, 7, 7, 7, 8, 8, 8, 8,
- 9, 9, 9, 9, 10, 10, 10, 11,
- 11, 11, 12, 12, 12, 13, 13, 13,
- 14, 14, 14, 15, 15, 15, 16, 16,
- 17, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 0,
- 0, 0, 0, 0, 0, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 3, 3,
- 3, 3, 4, 4, 4, 5, 5, 6,
- 6, 7, 7, 8, 8, 9, 9, 10,
- 10, 11, 11, 12, 12, 13, 13, 14,
- 14, 15, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28,
- 29, 30, 31, 32, 33, 34, 35, 36,
- 37,
-};
-
-/* second non intra vlc table */
-static const uint16_t table4_vlc[169][2] = {
-{ 0x0, 3 },{ 0x3, 4 },{ 0xb, 5 },{ 0x14, 6 },
-{ 0x3f, 6 },{ 0x5d, 7 },{ 0xa2, 8 },{ 0xac, 9 },
-{ 0x16e, 9 },{ 0x20a, 10 },{ 0x2e2, 10 },{ 0x432, 11 },
-{ 0x5c9, 11 },{ 0x827, 12 },{ 0xb54, 12 },{ 0x4e6, 13 },
-{ 0x105f, 13 },{ 0x172a, 13 },{ 0x20b2, 14 },{ 0x2d4e, 14 },
-{ 0x39f0, 14 },{ 0x4175, 15 },{ 0x5a9e, 15 },{ 0x4, 4 },
-{ 0x1e, 5 },{ 0x42, 7 },{ 0xb6, 8 },{ 0x173, 9 },
-{ 0x395, 10 },{ 0x72e, 11 },{ 0xb94, 12 },{ 0x16a4, 13 },
-{ 0x20b3, 14 },{ 0x2e45, 14 },{ 0x5, 5 },{ 0x40, 7 },
-{ 0x49, 9 },{ 0x28f, 10 },{ 0x5cb, 11 },{ 0x48a, 13 },
-{ 0x9dd, 14 },{ 0x73e2, 15 },{ 0x18, 5 },{ 0x25, 8 },
-{ 0x8a, 10 },{ 0x51b, 11 },{ 0xe5f, 12 },{ 0x9c9, 14 },
-{ 0x139c, 15 },{ 0x29, 6 },{ 0x4f, 9 },{ 0x412, 11 },
-{ 0x48d, 13 },{ 0x2e41, 14 },{ 0x38, 6 },{ 0x10e, 9 },
-{ 0x5a8, 11 },{ 0x105c, 13 },{ 0x39f2, 14 },{ 0x58, 7 },
-{ 0x21f, 10 },{ 0xe7e, 12 },{ 0x39ff, 14 },{ 0x23, 8 },
-{ 0x2e3, 10 },{ 0x4e5, 13 },{ 0x2e40, 14 },{ 0xa1, 8 },
-{ 0x5be, 11 },{ 0x9c8, 14 },{ 0x83, 8 },{ 0x13a, 11 },
-{ 0x1721, 13 },{ 0x44, 9 },{ 0x276, 12 },{ 0x39f6, 14 },
-{ 0x8b, 10 },{ 0x4ef, 13 },{ 0x5a9b, 15 },{ 0x208, 10 },
-{ 0x1cfe, 13 },{ 0x399, 10 },{ 0x1cb4, 13 },{ 0x39e, 10 },
-{ 0x39f3, 14 },{ 0x5ab, 11 },{ 0x73e3, 15 },{ 0x737, 11 },
-{ 0x5a9f, 15 },{ 0x82d, 12 },{ 0xe69, 12 },{ 0xe68, 12 },
-{ 0x433, 11 },{ 0xb7b, 12 },{ 0x2df8, 14 },{ 0x2e56, 14 },
-{ 0x2e57, 14 },{ 0x39f7, 14 },{ 0x51a5, 15 },{ 0x3, 3 },
-{ 0x2a, 6 },{ 0xe4, 8 },{ 0x28e, 10 },{ 0x735, 11 },
-{ 0x1058, 13 },{ 0x1cfa, 13 },{ 0x2df9, 14 },{ 0x4174, 15 },
-{ 0x9, 4 },{ 0x54, 8 },{ 0x398, 10 },{ 0x48b, 13 },
-{ 0x139d, 15 },{ 0xd, 4 },{ 0xad, 9 },{ 0x826, 12 },
-{ 0x2d4c, 14 },{ 0x11, 5 },{ 0x16b, 9 },{ 0xb7f, 12 },
-{ 0x51a4, 15 },{ 0x19, 5 },{ 0x21b, 10 },{ 0x16fd, 13 },
-{ 0x1d, 5 },{ 0x394, 10 },{ 0x28d3, 14 },{ 0x2b, 6 },
-{ 0x5bc, 11 },{ 0x5a9a, 15 },{ 0x2f, 6 },{ 0x247, 12 },
-{ 0x10, 7 },{ 0xa35, 12 },{ 0x3e, 6 },{ 0xb7a, 12 },
-{ 0x59, 7 },{ 0x105e, 13 },{ 0x26, 8 },{ 0x9cf, 14 },
-{ 0x55, 8 },{ 0x1cb5, 13 },{ 0x57, 8 },{ 0xe5b, 12 },
-{ 0xa0, 8 },{ 0x1468, 13 },{ 0x170, 9 },{ 0x90, 10 },
-{ 0x1ce, 9 },{ 0x21a, 10 },{ 0x218, 10 },{ 0x168, 9 },
-{ 0x21e, 10 },{ 0x244, 12 },{ 0x736, 11 },{ 0x138, 11 },
-{ 0x519, 11 },{ 0xe5e, 12 },{ 0x72c, 11 },{ 0xb55, 12 },
-{ 0x9dc, 14 },{ 0x20bb, 14 },{ 0x48c, 13 },{ 0x1723, 13 },
-{ 0x2e44, 14 },{ 0x16a5, 13 },{ 0x518, 11 },{ 0x39fe, 14 },
-{ 0x169, 9 },
-};
-
-static const int8_t table4_level[168] = {
- 1, 2, 3, 4, 5, 6, 7, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 1,
- 2, 3, 4, 5, 6, 7, 8, 9,
- 10, 11, 1, 2, 3, 4, 5, 6,
- 7, 8, 1, 2, 3, 4, 5, 6,
- 7, 1, 2, 3, 4, 5, 1, 2,
- 3, 4, 5, 1, 2, 3, 4, 1,
- 2, 3, 4, 1, 2, 3, 1, 2,
- 3, 1, 2, 3, 1, 2, 3, 1,
- 2, 1, 2, 1, 2, 1, 2, 1,
- 2, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 2, 3, 4, 5,
- 6, 7, 8, 9, 1, 2, 3, 4,
- 5, 1, 2, 3, 4, 1, 2, 3,
- 4, 1, 2, 3, 1, 2, 3, 1,
- 2, 3, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 2, 1, 2, 1, 2,
- 1, 2, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const int8_t table4_run[168] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 2, 2, 2, 2,
- 2, 2, 3, 3, 3, 3, 3, 3,
- 3, 4, 4, 4, 4, 4, 5, 5,
- 5, 5, 5, 6, 6, 6, 6, 7,
- 7, 7, 7, 8, 8, 8, 9, 9,
- 9, 10, 10, 10, 11, 11, 11, 12,
- 12, 13, 13, 14, 14, 15, 15, 16,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 1, 1, 1, 1,
- 1, 2, 2, 2, 2, 3, 3, 3,
- 3, 4, 4, 4, 5, 5, 5, 6,
- 6, 6, 7, 7, 8, 8, 9, 9,
- 10, 10, 11, 11, 12, 12, 13, 13,
- 14, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28,
- 29, 30, 31, 32, 33, 34, 35, 36,
-};
-
-extern const uint16_t inter_vlc[103][2];
-extern const int8_t inter_level[102];
-extern const int8_t inter_run[102];
-
-extern const uint16_t intra_vlc[103][2];
-extern const int8_t intra_level[102];
-extern const int8_t intra_run[102];
-
-extern const uint8_t DCtab_lum[13][2];
-extern const uint8_t DCtab_chrom[13][2];
-
-extern const uint8_t cbpy_tab[16][2];
-extern const uint8_t mvtab[33][2];
-
-extern const uint8_t intra_MCBPC_code[8];
-extern const uint8_t intra_MCBPC_bits[8];
-
-extern const uint8_t inter_MCBPC_code[25];
-extern const uint8_t inter_MCBPC_bits[25];
-
-#define NB_RL_TABLES 6
-
-static RLTable rl_table[NB_RL_TABLES] = {
- /* intra luminance tables */
- {
- 132,
- 85,
- table0_vlc,
- table0_run,
- table0_level,
- },
- {
- 185,
- 119,
- table2_vlc,
- table2_run,
- table2_level,
- },
- {
- 102,
- 67,
- intra_vlc,
- intra_run,
- intra_level,
- },
- /* intra chrominance / non intra tables */
- {
- 148,
- 81,
- table1_vlc,
- table1_run,
- table1_level,
- },
- {
- 168,
- 99,
- table4_vlc,
- table4_run,
- table4_level,
- },
- {
- 102,
- 58,
- inter_vlc,
- inter_run,
- inter_level,
- },
-};
-
-/* motion vector table 0 */
-
-static const uint16_t table0_mv_code[1100] = {
- 0x0001, 0x0003, 0x0005, 0x0007, 0x0003, 0x0008, 0x000c, 0x0001,
- 0x0002, 0x001b, 0x0006, 0x000b, 0x0015, 0x0002, 0x000e, 0x000f,
- 0x0014, 0x0020, 0x0022, 0x0025, 0x0027, 0x0029, 0x002d, 0x004b,
- 0x004d, 0x0003, 0x0022, 0x0023, 0x0025, 0x0027, 0x0042, 0x0048,
- 0x0049, 0x0050, 0x005c, 0x0091, 0x009f, 0x000e, 0x0043, 0x004c,
- 0x0054, 0x0056, 0x008c, 0x0098, 0x009a, 0x009b, 0x00b1, 0x00b2,
- 0x0120, 0x0121, 0x0126, 0x0133, 0x0139, 0x01a1, 0x01a4, 0x01a5,
- 0x01a6, 0x01a7, 0x01ae, 0x01af, 0x000b, 0x0019, 0x0085, 0x0090,
- 0x009b, 0x00aa, 0x00af, 0x010c, 0x010e, 0x011c, 0x011e, 0x0133,
- 0x0144, 0x0160, 0x0174, 0x0175, 0x0177, 0x0178, 0x0249, 0x024b,
- 0x0252, 0x0261, 0x0265, 0x0270, 0x0352, 0x0353, 0x0355, 0x0359,
- 0x0010, 0x0011, 0x0013, 0x0034, 0x0035, 0x0036, 0x0037, 0x003d,
- 0x003e, 0x0109, 0x0126, 0x0156, 0x021a, 0x021e, 0x023a, 0x023e,
- 0x028e, 0x028f, 0x02cf, 0x0491, 0x0494, 0x049f, 0x04a0, 0x04a3,
- 0x04a6, 0x04a7, 0x04ad, 0x04ae, 0x04c0, 0x04c4, 0x04c6, 0x04c8,
- 0x04c9, 0x04f5, 0x04f6, 0x04f7, 0x0680, 0x0682, 0x0683, 0x0688,
- 0x0689, 0x068d, 0x068e, 0x068f, 0x06a2, 0x06a3, 0x06a9, 0x06b0,
- 0x06b1, 0x06b4, 0x06b5, 0x0024, 0x0060, 0x0063, 0x0078, 0x0079,
- 0x0211, 0x0244, 0x0245, 0x0247, 0x0248, 0x0249, 0x024a, 0x024b,
- 0x026b, 0x02af, 0x02b8, 0x02bb, 0x0436, 0x0476, 0x0477, 0x047e,
- 0x04c8, 0x04c9, 0x04ca, 0x0514, 0x0586, 0x0587, 0x0598, 0x059d,
- 0x05d9, 0x05da, 0x0920, 0x0921, 0x093b, 0x093c, 0x093d, 0x0942,
- 0x0943, 0x0944, 0x0945, 0x0959, 0x095e, 0x095f, 0x0982, 0x0983,
- 0x098e, 0x098f, 0x09c4, 0x09e7, 0x09e8, 0x09e9, 0x0d02, 0x0d17,
- 0x0d18, 0x0d19, 0x0d41, 0x0d42, 0x0d43, 0x0d50, 0x0d5f, 0x0d6d,
- 0x0d6e, 0x0d6f, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
- 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x041e, 0x041f, 0x0420, 0x0421,
- 0x048c, 0x048d, 0x04d3, 0x04d4, 0x04d5, 0x055c, 0x055d, 0x0572,
- 0x0573, 0x0574, 0x0575, 0x08de, 0x08df, 0x08fe, 0x08ff, 0x0996,
- 0x0a36, 0x0a37, 0x0b08, 0x0b09, 0x0b0a, 0x0b0b, 0x0b32, 0x0b33,
- 0x0b34, 0x0b35, 0x0b36, 0x0b37, 0x0b38, 0x0b39, 0x0bb0, 0x0bf7,
- 0x0bf8, 0x0bf9, 0x0bfa, 0x0bfb, 0x0bfc, 0x0bfd, 0x0bfe, 0x0bff,
- 0x1254, 0x1255, 0x1256, 0x1257, 0x1270, 0x1271, 0x1272, 0x1273,
- 0x1274, 0x1275, 0x12ab, 0x12ac, 0x12ad, 0x12ae, 0x12af, 0x12b0,
- 0x12b1, 0x1315, 0x1316, 0x1317, 0x13bf, 0x13c0, 0x13c1, 0x13c2,
- 0x13c3, 0x13c4, 0x13c5, 0x13c6, 0x13c7, 0x13c8, 0x13c9, 0x13ca,
- 0x13cb, 0x13cc, 0x13cd, 0x1a06, 0x1a07, 0x1a28, 0x1a29, 0x1a2a,
- 0x1a2b, 0x1a2c, 0x1a2d, 0x1a80, 0x1abb, 0x1abc, 0x1abd, 0x1ad8,
- 0x1ad9, 0x0094, 0x0095, 0x0096, 0x0097, 0x00a0, 0x00a1, 0x00a2,
- 0x00a3, 0x0831, 0x0832, 0x0833, 0x0834, 0x0835, 0x0836, 0x0837,
- 0x0838, 0x0839, 0x083a, 0x083b, 0x0939, 0x093a, 0x093b, 0x093c,
- 0x093d, 0x093e, 0x093f, 0x09a0, 0x09a1, 0x09a2, 0x09a3, 0x09a4,
- 0x09a5, 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2,
- 0x11b3, 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba,
- 0x11bb, 0x132f, 0x1454, 0x1455, 0x1456, 0x1457, 0x1458, 0x1459,
- 0x145a, 0x145b, 0x145c, 0x145d, 0x145e, 0x145f, 0x1460, 0x1461,
- 0x1462, 0x1463, 0x1464, 0x1465, 0x1466, 0x1467, 0x1468, 0x1469,
- 0x146a, 0x146b, 0x17de, 0x17df, 0x17e0, 0x17e1, 0x17e2, 0x17e3,
- 0x17e4, 0x17e5, 0x17e6, 0x17e7, 0x17e8, 0x17e9, 0x17ea, 0x17eb,
- 0x17ec, 0x17ed, 0x2540, 0x2541, 0x2542, 0x2543, 0x2544, 0x2545,
- 0x2546, 0x2547, 0x2548, 0x2549, 0x254a, 0x254b, 0x254c, 0x254d,
- 0x254e, 0x254f, 0x2550, 0x2551, 0x2552, 0x2553, 0x2554, 0x2555,
- 0x2628, 0x2766, 0x2767, 0x2768, 0x2769, 0x276a, 0x276b, 0x276c,
- 0x276d, 0x276e, 0x276f, 0x2770, 0x2771, 0x2772, 0x2773, 0x2774,
- 0x2775, 0x2776, 0x2777, 0x2778, 0x2779, 0x277a, 0x277b, 0x277c,
- 0x277d, 0x3503, 0x3544, 0x3545, 0x3546, 0x3547, 0x3560, 0x3561,
- 0x3562, 0x3563, 0x3564, 0x3565, 0x3566, 0x3567, 0x3568, 0x3569,
- 0x356a, 0x356b, 0x356c, 0x356d, 0x356e, 0x356f, 0x3570, 0x3571,
- 0x3572, 0x3573, 0x3574, 0x3575, 0x03f0, 0x103d, 0x103e, 0x103f,
- 0x1040, 0x1041, 0x1042, 0x1043, 0x1044, 0x1045, 0x1046, 0x1047,
- 0x1048, 0x1049, 0x104a, 0x104b, 0x104c, 0x104d, 0x104e, 0x104f,
- 0x1050, 0x1051, 0x1052, 0x1053, 0x1054, 0x1055, 0x1056, 0x1057,
- 0x1058, 0x1059, 0x105a, 0x105b, 0x105c, 0x105d, 0x105e, 0x105f,
- 0x1060, 0x1061, 0x1270, 0x1271, 0x21b8, 0x21b9, 0x21ba, 0x21bb,
- 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x21f0, 0x21f1, 0x21f2, 0x21f3,
- 0x21f4, 0x21f5, 0x21f6, 0x21f7, 0x21f8, 0x21f9, 0x21fa, 0x21fb,
- 0x21fc, 0x21fd, 0x21fe, 0x21ff, 0x2340, 0x2341, 0x2342, 0x2343,
- 0x2344, 0x2345, 0x2346, 0x2347, 0x2348, 0x2349, 0x234a, 0x234b,
- 0x234c, 0x234d, 0x234e, 0x234f, 0x2350, 0x2351, 0x2352, 0x2353,
- 0x2354, 0x2355, 0x2356, 0x2357, 0x265c, 0x2f88, 0x2f89, 0x2f8a,
- 0x2f8b, 0x2f8c, 0x2f8d, 0x2f8e, 0x2f8f, 0x2f90, 0x2f91, 0x2f92,
- 0x2f93, 0x2f94, 0x2f95, 0x2f96, 0x2f97, 0x2f98, 0x2f99, 0x2f9a,
- 0x2f9b, 0x2f9c, 0x2f9d, 0x2f9e, 0x2f9f, 0x2fa0, 0x2fa1, 0x2fa2,
- 0x2fa3, 0x2fa4, 0x2fa5, 0x2fa6, 0x2fa7, 0x2fa8, 0x2fa9, 0x2faa,
- 0x2fab, 0x2fac, 0x2fad, 0x2fae, 0x2faf, 0x2fb0, 0x2fb1, 0x2fb2,
- 0x2fb3, 0x2fb4, 0x2fb5, 0x2fb6, 0x2fb7, 0x2fb8, 0x2fb9, 0x2fba,
- 0x2fbb, 0x4c52, 0x4c53, 0x4e28, 0x4e29, 0x4e2a, 0x4e2b, 0x4e2c,
- 0x4e2d, 0x4e2e, 0x4e2f, 0x4e30, 0x4e31, 0x4e32, 0x4e33, 0x4e34,
- 0x4e35, 0x4e36, 0x4e37, 0x4e38, 0x4e39, 0x4e3a, 0x4e3b, 0x4e3c,
- 0x4e3d, 0x4e3e, 0x4e3f, 0x4e80, 0x4e81, 0x4e82, 0x4e83, 0x4e84,
- 0x4e85, 0x4e86, 0x4e87, 0x4e88, 0x4e89, 0x4e8a, 0x4e8b, 0x4e8c,
- 0x4e8d, 0x4e8e, 0x4e8f, 0x4e90, 0x4e91, 0x4e92, 0x4e93, 0x4e94,
- 0x4e95, 0x4e96, 0x4e97, 0x4e98, 0x4e99, 0x4e9a, 0x4e9b, 0x4e9c,
- 0x4e9d, 0x4e9e, 0x4e9f, 0x4ea0, 0x4ea1, 0x4ea2, 0x4ea3, 0x4ea4,
- 0x4ea5, 0x4ea6, 0x4ea7, 0x4ea8, 0x4ea9, 0x4eaa, 0x4eab, 0x4eac,
- 0x4ead, 0x4eae, 0x4eaf, 0x4eb0, 0x4eb1, 0x4eb2, 0x4eb3, 0x4eb4,
- 0x4eb5, 0x4eb6, 0x4eb7, 0x4eb8, 0x4eb9, 0x4eba, 0x4ebb, 0x4ebc,
- 0x4ebd, 0x4ebe, 0x4ebf, 0x4ec0, 0x4ec1, 0x4ec2, 0x4ec3, 0x4ec4,
- 0x4ec5, 0x4ec6, 0x4ec7, 0x4ec8, 0x4ec9, 0x4eca, 0x4ecb, 0x6a04,
- 0x6a05, 0x07e2, 0x07e3, 0x07e4, 0x07e5, 0x07e6, 0x07e7, 0x07e8,
- 0x07e9, 0x07ea, 0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0,
- 0x07f1, 0x07f2, 0x07f3, 0x07f4, 0x07f5, 0x07f6, 0x07f7, 0x07f8,
- 0x07f9, 0x07fa, 0x07fb, 0x07fc, 0x07fd, 0x07fe, 0x07ff, 0x2000,
- 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
- 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x2010,
- 0x2011, 0x2012, 0x2013, 0x2014, 0x2015, 0x2016, 0x2017, 0x2018,
- 0x2019, 0x201a, 0x201b, 0x201c, 0x201d, 0x201e, 0x201f, 0x2020,
- 0x2021, 0x2022, 0x2023, 0x2024, 0x2025, 0x2026, 0x2027, 0x2028,
- 0x2029, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x202f, 0x2030,
- 0x2031, 0x2032, 0x2033, 0x2034, 0x2035, 0x2036, 0x2037, 0x2038,
- 0x2039, 0x203a, 0x203b, 0x203c, 0x203d, 0x203e, 0x203f, 0x2040,
- 0x2041, 0x2042, 0x2043, 0x2044, 0x2045, 0x2046, 0x2047, 0x2048,
- 0x2049, 0x204a, 0x204b, 0x204c, 0x204d, 0x204e, 0x204f, 0x2050,
- 0x2051, 0x2052, 0x2053, 0x2054, 0x2055, 0x2056, 0x2057, 0x2058,
- 0x2059, 0x205a, 0x205b, 0x205c, 0x205d, 0x205e, 0x205f, 0x2060,
- 0x2061, 0x2062, 0x2063, 0x2064, 0x2065, 0x2066, 0x2067, 0x2068,
- 0x2069, 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0x2070,
- 0x2071, 0x2072, 0x2073, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078,
- 0x2079, 0x4cba, 0x4cbb, 0x5d88, 0x5d89, 0x5d8a, 0x5d8b, 0x5d8c,
- 0x5d8d, 0x5d8e, 0x5d8f, 0x5db0, 0x5db1, 0x5db2, 0x5db3, 0x5db4,
- 0x5db5, 0x5db6, 0x5db7, 0x5db8, 0x5db9, 0x5dba, 0x5dbb, 0x5dbc,
- 0x5dbd, 0x5dbe, 0x5dbf, 0x5e40, 0x5e41, 0x5e42, 0x5e43, 0x5e44,
- 0x5e45, 0x5e46, 0x5e47, 0x5e48, 0x5e49, 0x5e4a, 0x5e4b, 0x5e4c,
- 0x5e4d, 0x5e4e, 0x5e4f, 0x5e50, 0x5e51, 0x5e52, 0x5e53, 0x5e54,
- 0x5e55, 0x5e56, 0x5e57, 0x5e58, 0x5e59, 0x5e5a, 0x5e5b, 0x5e5c,
- 0x5e5d, 0x5e5e, 0x5e5f, 0x5e60, 0x5e61, 0x5e62, 0x5e63, 0x5e64,
- 0x5e65, 0x5e66, 0x5e67, 0x5e68, 0x5e69, 0x5e6a, 0x5e6b, 0x5e6c,
- 0x5e6d, 0x5e6e, 0x5e6f, 0x5e70, 0x5e71, 0x5e72, 0x5e73, 0x5e74,
- 0x5e75, 0x5e76, 0x5e77, 0x5e78, 0x5e79, 0x5e7a, 0x5e7b, 0x5e7c,
- 0x5e7d, 0x5e7e, 0x5e7f, 0x5e80, 0x5e81, 0x5e82, 0x5e83, 0x5e84,
- 0x5e85, 0x5e86, 0x5e87, 0x5e88, 0x5e89, 0x5e8a, 0x5e8b, 0x5e8c,
- 0x5e8d, 0x5e8e, 0x5e8f, 0x5e90, 0x5e91, 0x5e92, 0x5e93, 0x5e94,
- 0x5e95, 0x5e96, 0x5e97, 0x5e98, 0x5e99, 0x5e9a, 0x5e9b, 0x5e9c,
- 0x5e9d, 0x5e9e, 0x5e9f, 0x5ea0, 0x5ea1, 0x5ea2, 0x5ea3, 0x5ea4,
- 0x5ea5, 0x5ea6, 0x5ea7, 0x5ea8, 0x5ea9, 0x5eaa, 0x5eab, 0x5eac,
- 0x5ead, 0x5eae, 0x5eaf, 0x5eb0, 0x5eb1, 0x5eb2, 0x5eb3, 0x5eb4,
- 0x5eb5, 0x5eb6, 0x5eb7, 0x5eb8, 0x5eb9, 0x5eba, 0x5ebb, 0x5ebc,
- 0x5ebd, 0x5ebe, 0x5ebf, 0x5ec0, 0x5ec1, 0x5ec2, 0x5ec3, 0x5ec4,
- 0x5ec5, 0x5ec6, 0x5ec7, 0x5ec8, 0x5ec9, 0x5eca, 0x5ecb, 0x5ecc,
- 0x5ecd, 0x5ece, 0x5ecf, 0x5ed0, 0x5ed1, 0x5ed2, 0x5ed3, 0x5ed4,
- 0x5ed5, 0x5ed6, 0x5ed7, 0x5ed8, 0x5ed9, 0x5eda, 0x5edb, 0x5edc,
- 0x5edd, 0x5ede, 0x5edf, 0x5ee0, 0x5ee1, 0x5ee2, 0x5ee3, 0x5ee4,
- 0x5ee5, 0x5ee6, 0x5ee7, 0x5ee8, 0x5ee9, 0x5eea, 0x5eeb, 0x5eec,
- 0x5eed, 0x5eee, 0x5eef, 0x5ef0, 0x5ef1, 0x5ef2, 0x5ef3, 0x5ef4,
- 0x5ef5, 0x5ef6, 0x5ef7, 0x5ef8, 0x5ef9, 0x5efa, 0x5efb, 0x5efc,
- 0x5efd, 0x5efe, 0x5eff, 0x5f00, 0x5f01, 0x5f02, 0x5f03, 0x5f04,
- 0x5f05, 0x5f06, 0x5f07, 0x5f08, 0x5f09, 0x5f0a, 0x5f0b, 0x5f0c,
- 0x5f0d, 0x5f0e, 0x5f0f, 0x0000,
-};
-
-static const uint8_t table0_mv_bits[1100] = {
- 1, 4, 4, 4, 5, 5, 5, 6,
- 6, 6, 7, 7, 7, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 8,
-};
-
-static const uint8_t table0_mvx[1099] = {
- 32, 32, 31, 32, 33, 31, 33, 31,
- 33, 32, 34, 32, 30, 32, 31, 34,
- 35, 32, 34, 33, 29, 33, 30, 30,
- 31, 31, 35, 29, 33, 35, 33, 34,
- 31, 29, 30, 34, 30, 36, 28, 32,
- 34, 37, 30, 27, 32, 25, 39, 32,
- 34, 32, 35, 35, 35, 31, 35, 29,
- 32, 29, 30, 29, 37, 27, 36, 38,
- 37, 33, 32, 31, 29, 31, 28, 36,
- 33, 30, 34, 33, 33, 28, 27, 25,
- 31, 26, 39, 32, 32, 31, 33, 39,
- 31, 38, 28, 36, 21, 23, 43, 36,
- 34, 41, 30, 25, 28, 31, 30, 34,
- 38, 35, 61, 34, 28, 30, 37, 37,
- 35, 27, 36, 3, 59, 38, 37, 32,
- 31, 29, 26, 33, 37, 33, 27, 27,
- 35, 34, 34, 40, 42, 33, 32, 29,
- 4, 5, 28, 24, 25, 35, 39, 38,
- 32, 23, 27, 32, 30, 35, 26, 34,
- 60, 36, 29, 22, 26, 41, 7, 30,
- 38, 30, 36, 29, 30, 41, 26, 25,
- 32, 34, 24, 39, 1, 25, 39, 32,
- 28, 29, 32, 38, 26, 36, 28, 63,
- 28, 39, 23, 21, 26, 35, 31, 35,
- 57, 31, 29, 29, 28, 30, 27, 35,
- 2, 38, 40, 34, 37, 29, 38, 43,
- 26, 32, 33, 42, 24, 40, 28, 32,
- 32, 32, 36, 32, 43, 25, 21, 31,
- 30, 31, 41, 29, 33, 37, 26, 37,
- 27, 59, 23, 33, 35, 31, 31, 37,
- 38, 39, 32, 23, 32, 27, 37, 36,
- 31, 40, 25, 27, 38, 31, 36, 28,
- 31, 36, 25, 45, 3, 34, 38, 39,
- 40, 38, 30, 32, 19, 24, 25, 26,
- 45, 20, 24, 33, 33, 31, 41, 34,
- 39, 47, 40, 58, 59, 41, 33, 3,
- 17, 61, 42, 30, 26, 29, 36, 61,
- 33, 37, 62, 28, 25, 38, 25, 38,
- 17, 23, 34, 33, 21, 33, 49, 27,
- 32, 23, 27, 22, 24, 22, 39, 43,
- 27, 37, 6, 42, 47, 26, 30, 31,
- 41, 39, 33, 22, 45, 36, 32, 45,
- 19, 22, 30, 5, 5, 17, 29, 22,
- 31, 31, 43, 37, 27, 32, 32, 32,
- 33, 34, 43, 35, 29, 26, 22, 32,
- 19, 32, 25, 31, 41, 49, 28, 34,
- 28, 39, 34, 19, 37, 38, 29, 21,
- 36, 42, 24, 48, 16, 28, 49, 22,
- 34, 31, 38, 39, 44, 11, 35, 30,
- 33, 33, 23, 28, 33, 46, 15, 13,
- 24, 41, 24, 34, 34, 30, 26, 24,
- 14, 60, 21, 29, 39, 23, 35, 37,
- 63, 45, 33, 34, 47, 41, 22, 42,
- 35, 35, 23, 32, 35, 43, 32, 7,
- 31, 41, 20, 31, 16, 13, 63, 25,
- 30, 32, 35, 30, 30, 31, 42, 47,
- 39, 38, 40, 40, 51, 55, 56, 18,
- 21, 39, 39, 33, 17, 41, 23, 24,
- 43, 25, 31, 20, 19, 45, 1, 34,
- 31, 22, 35, 15, 46, 46, 35, 31,
- 28, 29, 29, 23, 41, 27, 14, 53,
- 53, 27, 24, 32, 57, 32, 17, 42,
- 37, 29, 33, 1, 25, 32, 32, 63,
- 26, 40, 44, 36, 31, 39, 20, 20,
- 44, 23, 33, 34, 35, 33, 33, 28,
- 41, 23, 41, 41, 29, 25, 26, 49,
- 29, 24, 37, 49, 50, 51, 51, 26,
- 39, 25, 26, 15, 39, 18, 42, 17,
- 4, 31, 32, 32, 60, 1, 42, 32,
- 0, 12, 19, 35, 21, 41, 17, 26,
- 20, 45, 46, 32, 37, 22, 47, 29,
- 31, 27, 29, 30, 21, 33, 35, 18,
- 25, 33, 50, 51, 42, 2, 15, 51,
- 53, 33, 25, 29, 55, 37, 38, 33,
- 38, 59, 38, 33, 39, 13, 32, 40,
- 61, 61, 32, 9, 44, 3, 31, 29,
- 25, 31, 27, 23, 9, 25, 9, 29,
- 20, 30, 30, 42, 18, 28, 25, 28,
- 28, 21, 29, 43, 29, 43, 26, 44,
- 44, 21, 38, 21, 24, 45, 45, 35,
- 39, 22, 35, 36, 34, 34, 45, 34,
- 29, 31, 46, 25, 46, 16, 17, 31,
- 20, 32, 47, 47, 47, 32, 49, 49,
- 49, 31, 1, 27, 28, 39, 39, 21,
- 36, 23, 51, 2, 40, 51, 32, 53,
- 24, 30, 24, 30, 21, 40, 57, 57,
- 31, 41, 58, 32, 12, 4, 32, 34,
- 59, 31, 32, 13, 9, 35, 26, 35,
- 37, 61, 37, 63, 26, 29, 41, 38,
- 23, 20, 41, 26, 41, 42, 42, 42,
- 26, 26, 26, 26, 1, 26, 37, 37,
- 37, 23, 34, 42, 27, 43, 34, 27,
- 31, 24, 33, 16, 3, 31, 24, 33,
- 24, 4, 44, 44, 11, 44, 31, 13,
- 13, 44, 45, 13, 25, 22, 38, 26,
- 38, 38, 39, 32, 30, 39, 30, 22,
- 32, 26, 30, 47, 47, 47, 19, 47,
- 30, 31, 35, 8, 23, 47, 47, 27,
- 35, 47, 31, 48, 35, 19, 36, 49,
- 49, 33, 31, 39, 27, 39, 49, 49,
- 50, 50, 50, 39, 31, 51, 51, 39,
- 28, 33, 33, 21, 40, 31, 52, 53,
- 40, 53, 9, 33, 31, 53, 54, 54,
- 54, 55, 55, 34, 15, 56, 25, 56,
- 21, 21, 40, 40, 25, 40, 58, 36,
- 5, 41, 41, 12, 60, 41, 41, 37,
- 22, 61, 18, 29, 29, 30, 61, 30,
- 61, 62, 62, 30, 30, 63, 18, 13,
- 30, 23, 19, 20, 20, 41, 13, 2,
- 5, 5, 1, 5, 32, 6, 32, 35,
- 20, 35, 27, 35, 35, 36, 36, 13,
- 36, 41, 41, 41, 3, 30, 42, 27,
- 20, 30, 27, 28, 30, 21, 33, 33,
- 14, 24, 30, 42, 24, 33, 25, 42,
- 43, 14, 43, 43, 14, 43, 7, 36,
- 37, 37, 37, 37, 7, 14, 25, 43,
- 43, 44, 15, 37, 7, 7, 3, 1,
- 8, 15, 15, 8, 44, 44, 44, 45,
- 45, 45, 45, 8, 8, 45, 21, 45,
- 28, 28, 28, 21, 28, 28, 22, 37,
- 46, 46, 37, 8, 29, 37, 29, 22,
- 46, 37, 22, 29, 47, 47, 38, 38,
- 16, 38, 38, 33, 38, 22, 47, 47,
- 29, 25, 16, 0, 48, 1, 34, 48,
- 48, 34, 25, 26, 26, 49, 49, 26,
- 1, 49, 4, 26, 4, 49, 1, 9,
- 49, 49, 49, 10, 49, 17, 38, 17,
- 17, 50, 38, 50, 50, 22, 38, 51,
- 38, 38, 51, 39, 39, 18, 22, 39,
- 51, 22, 52, 52, 52, 39, 53, 53,
- 10, 23, 18, 29, 10, 53, 29, 54,
- 11, 54, 11, 11, 55, 1, 18, 55,
- 55, 55, 55, 55, 55, 29, 34, 18,
- 29, 56, 56, 34, 57, 34, 34, 29,
- 29, 57, 57, 35, 35, 35, 35, 35,
- 39, 35, 59, 59, 18, 59, 39, 30,
- 18, 40, 60, 60, 61, 30, 18, 61,
- 61, 19, 19,
-};
-
-static const uint8_t table0_mvy[1099] = {
- 32, 31, 32, 33, 32, 31, 31, 33,
- 33, 34, 32, 30, 32, 35, 34, 31,
- 32, 29, 33, 30, 32, 34, 33, 31,
- 30, 35, 31, 31, 29, 33, 35, 30,
- 29, 33, 34, 34, 30, 32, 32, 36,
- 29, 32, 35, 32, 28, 32, 32, 27,
- 35, 37, 34, 29, 30, 36, 35, 34,
- 25, 30, 29, 35, 33, 31, 31, 32,
- 31, 28, 39, 28, 29, 37, 31, 33,
- 27, 36, 28, 36, 37, 33, 33, 31,
- 27, 32, 31, 38, 26, 25, 25, 33,
- 39, 31, 34, 30, 32, 32, 32, 34,
- 36, 32, 28, 33, 30, 38, 37, 27,
- 33, 28, 32, 37, 35, 38, 29, 34,
- 27, 29, 29, 32, 32, 34, 35, 3,
- 26, 36, 31, 38, 30, 26, 35, 34,
- 37, 26, 25, 32, 32, 39, 23, 37,
- 32, 32, 29, 32, 29, 36, 29, 30,
- 41, 31, 30, 21, 39, 25, 34, 38,
- 32, 35, 39, 32, 33, 33, 32, 27,
- 29, 25, 28, 27, 26, 31, 30, 35,
- 24, 24, 31, 34, 32, 30, 35, 40,
- 28, 38, 5, 35, 29, 36, 36, 32,
- 38, 30, 33, 31, 35, 26, 23, 38,
- 32, 41, 28, 25, 37, 40, 37, 39,
- 32, 36, 33, 39, 25, 26, 28, 31,
- 28, 42, 23, 31, 33, 31, 39, 1,
- 59, 22, 27, 4, 33, 34, 33, 24,
- 41, 3, 35, 41, 41, 28, 36, 36,
- 28, 33, 35, 21, 23, 21, 22, 37,
- 27, 27, 43, 29, 60, 39, 27, 25,
- 59, 34, 27, 27, 26, 40, 37, 27,
- 61, 26, 39, 33, 31, 22, 37, 25,
- 30, 25, 24, 61, 31, 34, 25, 38,
- 32, 32, 30, 3, 61, 43, 29, 23,
- 28, 32, 28, 32, 31, 34, 5, 33,
- 32, 33, 33, 42, 37, 23, 38, 31,
- 40, 26, 32, 26, 37, 38, 36, 24,
- 29, 30, 20, 22, 29, 24, 32, 41,
- 2, 34, 25, 33, 29, 31, 39, 35,
- 36, 24, 32, 30, 33, 27, 44, 60,
- 30, 36, 19, 34, 31, 24, 16, 35,
- 32, 38, 21, 33, 31, 31, 21, 35,
- 5, 17, 29, 38, 38, 18, 58, 19,
- 43, 41, 30, 41, 43, 39, 29, 7,
- 29, 17, 28, 19, 28, 31, 25, 19,
- 40, 26, 21, 33, 39, 23, 40, 30,
- 39, 34, 35, 32, 32, 24, 33, 30,
- 40, 47, 39, 37, 32, 33, 24, 23,
- 45, 47, 27, 23, 42, 32, 32, 33,
- 36, 37, 37, 17, 18, 22, 40, 38,
- 32, 31, 35, 24, 17, 25, 17, 23,
- 33, 34, 51, 42, 31, 36, 36, 29,
- 21, 22, 37, 44, 43, 25, 47, 33,
- 45, 27, 31, 58, 31, 32, 31, 38,
- 43, 20, 47, 45, 54, 1, 26, 34,
- 38, 14, 22, 24, 33, 34, 32, 32,
- 37, 21, 23, 49, 35, 23, 28, 39,
- 39, 23, 55, 33, 30, 30, 63, 16,
- 42, 28, 13, 33, 33, 35, 19, 46,
- 43, 17, 19, 36, 39, 24, 31, 32,
- 33, 26, 28, 62, 33, 63, 33, 39,
- 19, 49, 17, 31, 43, 13, 15, 29,
- 25, 35, 33, 23, 49, 41, 28, 29,
- 34, 38, 7, 61, 11, 50, 13, 41,
- 19, 47, 25, 26, 15, 42, 41, 29,
- 45, 27, 17, 35, 32, 29, 32, 24,
- 13, 26, 26, 31, 24, 33, 28, 30,
- 31, 11, 45, 46, 33, 33, 35, 57,
- 32, 32, 35, 45, 34, 11, 37, 42,
- 39, 37, 31, 49, 21, 27, 29, 47,
- 53, 40, 51, 16, 26, 1, 40, 30,
- 41, 44, 34, 25, 27, 31, 35, 35,
- 31, 15, 49, 1, 35, 40, 5, 58,
- 21, 29, 22, 59, 45, 31, 9, 26,
- 9, 29, 11, 32, 30, 3, 13, 20,
- 18, 20, 11, 3, 29, 40, 31, 53,
- 30, 17, 20, 37, 31, 42, 47, 47,
- 54, 38, 9, 34, 13, 37, 21, 25,
- 27, 43, 42, 45, 40, 25, 27, 46,
- 22, 25, 53, 20, 2, 14, 39, 15,
- 22, 44, 34, 21, 38, 33, 27, 48,
- 34, 52, 35, 47, 49, 54, 2, 13,
- 23, 52, 29, 45, 22, 49, 54, 21,
- 40, 42, 31, 30, 29, 34, 0, 25,
- 23, 51, 24, 59, 28, 38, 29, 31,
- 2, 13, 31, 8, 31, 33, 12, 45,
- 41, 7, 14, 30, 25, 18, 43, 20,
- 43, 35, 44, 1, 49, 42, 42, 18,
- 41, 38, 41, 44, 53, 11, 20, 25,
- 45, 46, 47, 48, 39, 52, 46, 49,
- 63, 55, 44, 38, 13, 13, 57, 22,
- 51, 16, 12, 28, 35, 57, 25, 20,
- 26, 28, 28, 29, 32, 31, 62, 34,
- 35, 35, 19, 49, 48, 39, 40, 18,
- 43, 46, 11, 6, 48, 19, 49, 41,
- 10, 23, 58, 17, 21, 23, 34, 30,
- 60, 0, 44, 34, 26, 37, 46, 43,
- 49, 59, 4, 34, 59, 37, 22, 25,
- 28, 46, 6, 40, 59, 42, 36, 61,
- 28, 30, 31, 43, 10, 22, 23, 47,
- 20, 52, 55, 36, 25, 16, 1, 11,
- 27, 29, 5, 63, 18, 41, 31, 34,
- 38, 1, 5, 13, 28, 31, 17, 38,
- 39, 41, 36, 37, 22, 39, 33, 43,
- 43, 15, 17, 49, 30, 21, 22, 20,
- 10, 17, 25, 54, 57, 3, 34, 8,
- 36, 25, 31, 14, 15, 19, 29, 25,
- 18, 39, 53, 22, 27, 20, 29, 33,
- 41, 42, 35, 62, 50, 29, 53, 50,
- 35, 55, 42, 61, 63, 4, 7, 42,
- 21, 46, 47, 49, 27, 46, 17, 55,
- 41, 50, 63, 4, 56, 18, 8, 10,
- 18, 51, 63, 36, 55, 18, 5, 55,
- 9, 29, 17, 21, 30, 27, 1, 59,
- 7, 11, 12, 15, 5, 42, 24, 41,
- 43, 7, 27, 22, 25, 31, 30, 37,
- 22, 39, 53, 29, 36, 37, 48, 0,
- 5, 13, 17, 31, 32, 26, 46, 28,
- 44, 45, 46, 53, 49, 51, 3, 41,
- 3, 22, 42, 33, 5, 45, 7, 22,
- 40, 53, 24, 14, 25, 27, 10, 12,
- 34, 16, 17, 53, 20, 26, 39, 45,
- 18, 45, 35, 33, 31, 49, 4, 39,
- 42, 11, 51, 5, 13, 26, 27, 17,
- 52, 30, 0, 22, 12, 34, 62, 36,
- 38, 41, 47, 30, 63, 38, 41, 43,
- 59, 33, 45, 37, 38, 40, 47, 24,
- 48, 49, 30, 1, 10, 22, 49, 15,
- 39, 59, 31, 32, 33, 18, 13, 15,
- 31, 21, 27, 44, 42, 39, 46, 17,
- 26, 32, 30, 31, 0, 30, 34, 9,
- 12, 13, 25, 31, 32, 55, 43, 35,
- 61, 33, 35, 46, 25, 47, 48, 62,
- 63, 38, 61, 1, 2, 5, 7, 9,
- 46, 10, 34, 35, 36, 55, 51, 7,
- 40, 23, 34, 37, 5, 13, 42, 18,
- 25, 27, 28,
-};
-
-/* motion vector table 1 */
-static const uint16_t table1_mv_code[1100] = {
- 0x0000, 0x0007, 0x0009, 0x000f, 0x000a, 0x0011, 0x001a, 0x001c,
- 0x0011, 0x0031, 0x0025, 0x002d, 0x002f, 0x006f, 0x0075, 0x0041,
- 0x004c, 0x004e, 0x005c, 0x0060, 0x0062, 0x0066, 0x0068, 0x0069,
- 0x006b, 0x00a6, 0x00c1, 0x00cb, 0x00cc, 0x00ce, 0x00da, 0x00e8,
- 0x00ee, 0x0087, 0x0090, 0x009e, 0x009f, 0x00ba, 0x00ca, 0x00d8,
- 0x00db, 0x00df, 0x0104, 0x0109, 0x010c, 0x0143, 0x0145, 0x014a,
- 0x0156, 0x015c, 0x01b3, 0x01d3, 0x01da, 0x0103, 0x0109, 0x010b,
- 0x0122, 0x0127, 0x0134, 0x0161, 0x0164, 0x0176, 0x0184, 0x018d,
- 0x018e, 0x018f, 0x0190, 0x0193, 0x0196, 0x019d, 0x019e, 0x019f,
- 0x01a9, 0x01b2, 0x01b4, 0x01ba, 0x01bb, 0x01bc, 0x0201, 0x0202,
- 0x0205, 0x0207, 0x020d, 0x0210, 0x0211, 0x0215, 0x021b, 0x021f,
- 0x0281, 0x0285, 0x0290, 0x029c, 0x029d, 0x02a2, 0x02a7, 0x02a8,
- 0x02aa, 0x02b0, 0x02b1, 0x02b4, 0x02bc, 0x02bf, 0x0320, 0x0326,
- 0x0327, 0x0329, 0x032a, 0x0336, 0x0360, 0x0362, 0x0363, 0x0372,
- 0x03b2, 0x03bc, 0x03bd, 0x0203, 0x0205, 0x021a, 0x0249, 0x024a,
- 0x024c, 0x02c7, 0x02ca, 0x02ce, 0x02ef, 0x030d, 0x0322, 0x0325,
- 0x0338, 0x0373, 0x037a, 0x0409, 0x0415, 0x0416, 0x0418, 0x0428,
- 0x042d, 0x042f, 0x0434, 0x0508, 0x0509, 0x0510, 0x0511, 0x051c,
- 0x051e, 0x0524, 0x0541, 0x0543, 0x0546, 0x0547, 0x054d, 0x0557,
- 0x055f, 0x056a, 0x056c, 0x056d, 0x056f, 0x0576, 0x0577, 0x057a,
- 0x057b, 0x057c, 0x057d, 0x0600, 0x0601, 0x0603, 0x0614, 0x0616,
- 0x0617, 0x061c, 0x061f, 0x0642, 0x0648, 0x0649, 0x064a, 0x064b,
- 0x0657, 0x0668, 0x0669, 0x066b, 0x066e, 0x067f, 0x06c2, 0x06c8,
- 0x06cb, 0x06de, 0x06df, 0x06e2, 0x06e3, 0x06ef, 0x0748, 0x074b,
- 0x076e, 0x076f, 0x077c, 0x0409, 0x0423, 0x0428, 0x0429, 0x042a,
- 0x042b, 0x0432, 0x0433, 0x0496, 0x049a, 0x04d5, 0x04db, 0x0581,
- 0x0582, 0x058b, 0x058c, 0x058d, 0x0598, 0x0599, 0x059a, 0x059e,
- 0x05dd, 0x0619, 0x0632, 0x0633, 0x0648, 0x0672, 0x06a1, 0x06a2,
- 0x06a3, 0x06af, 0x06e2, 0x06e3, 0x06e4, 0x0800, 0x0801, 0x0802,
- 0x0803, 0x081a, 0x081b, 0x0829, 0x082f, 0x0832, 0x083e, 0x083f,
- 0x0852, 0x0853, 0x0858, 0x086b, 0x0877, 0x0878, 0x0879, 0x087a,
- 0x087b, 0x0a00, 0x0a01, 0x0a0d, 0x0a0e, 0x0a0f, 0x0a24, 0x0a37,
- 0x0a3a, 0x0a3b, 0x0a3e, 0x0a46, 0x0a47, 0x0a4a, 0x0a4b, 0x0a5f,
- 0x0a79, 0x0a7a, 0x0a7b, 0x0a80, 0x0a81, 0x0a84, 0x0a85, 0x0a99,
- 0x0aa5, 0x0aa6, 0x0ab8, 0x0aba, 0x0abb, 0x0abc, 0x0abd, 0x0ac8,
- 0x0ace, 0x0acf, 0x0ad7, 0x0adc, 0x0aeb, 0x0c04, 0x0c25, 0x0c26,
- 0x0c27, 0x0c2a, 0x0c2b, 0x0c3a, 0x0c3b, 0x0c3c, 0x0c3d, 0x0ca0,
- 0x0cad, 0x0cd4, 0x0cd5, 0x0cfc, 0x0cfd, 0x0d86, 0x0d92, 0x0d93,
- 0x0d94, 0x0d95, 0x0db0, 0x0db8, 0x0db9, 0x0dba, 0x0dbb, 0x0dc0,
- 0x0dc2, 0x0dc3, 0x0dda, 0x0ddb, 0x0ddc, 0x0ddd, 0x0e92, 0x0e93,
- 0x0e94, 0x0e95, 0x0ec7, 0x0ecc, 0x0ece, 0x0ecf, 0x0ed8, 0x0ed9,
- 0x0eda, 0x0edb, 0x0808, 0x0809, 0x080a, 0x0810, 0x0811, 0x0844,
- 0x0845, 0x0861, 0x0862, 0x0863, 0x086c, 0x0922, 0x0923, 0x092e,
- 0x092f, 0x0936, 0x0937, 0x09b1, 0x09b2, 0x09b3, 0x09b4, 0x09b5,
- 0x09b8, 0x09b9, 0x09ba, 0x09bb, 0x09bc, 0x09bd, 0x09be, 0x09bf,
- 0x0b00, 0x0b15, 0x0b2c, 0x0b2d, 0x0b2e, 0x0b2f, 0x0b36, 0x0bb9,
- 0x0c28, 0x0c2a, 0x0c2b, 0x0c2c, 0x0c2d, 0x0c2e, 0x0c2f, 0x0c30,
- 0x0c31, 0x0c38, 0x0c60, 0x0c61, 0x0c62, 0x0c63, 0x0c8d, 0x0c8e,
- 0x0c8f, 0x0c92, 0x0cbe, 0x0cbf, 0x0ce6, 0x0ce7, 0x0d40, 0x0d41,
- 0x0d57, 0x0d58, 0x0d59, 0x0d5a, 0x0d5b, 0x0d5c, 0x0d5d, 0x0d98,
- 0x0d99, 0x0d9a, 0x0d9b, 0x0d9c, 0x0d9d, 0x0dad, 0x0dae, 0x0daf,
- 0x0dc0, 0x0dc1, 0x0dc2, 0x0dc3, 0x0dca, 0x0dcb, 0x0dec, 0x0ded,
- 0x0dee, 0x0def, 0x1018, 0x1022, 0x1023, 0x1030, 0x1031, 0x1032,
- 0x1033, 0x1050, 0x1051, 0x105c, 0x1074, 0x1075, 0x1076, 0x1077,
- 0x1078, 0x1079, 0x107a, 0x107b, 0x10b2, 0x10b3, 0x10b8, 0x10b9,
- 0x10ba, 0x10bb, 0x10d4, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x1404,
- 0x1405, 0x1406, 0x1407, 0x1410, 0x1411, 0x1412, 0x1413, 0x1414,
- 0x1415, 0x1416, 0x1417, 0x1418, 0x1419, 0x1466, 0x1467, 0x1468,
- 0x1469, 0x146a, 0x146b, 0x146c, 0x146d, 0x147e, 0x147f, 0x1488,
- 0x1489, 0x148a, 0x148b, 0x14b6, 0x14b7, 0x14b8, 0x14b9, 0x14ba,
- 0x14bb, 0x14bc, 0x14bd, 0x14f0, 0x14f1, 0x14f8, 0x14f9, 0x14fa,
- 0x14fb, 0x14fc, 0x14fd, 0x14fe, 0x14ff, 0x152a, 0x152b, 0x152c,
- 0x152d, 0x152e, 0x152f, 0x1530, 0x1531, 0x1548, 0x1549, 0x154e,
- 0x154f, 0x1558, 0x1559, 0x155a, 0x155b, 0x1572, 0x159a, 0x159b,
- 0x15ac, 0x15ba, 0x15bb, 0x15d0, 0x15d1, 0x15d2, 0x15d3, 0x15d4,
- 0x15d5, 0x181d, 0x181e, 0x181f, 0x1840, 0x1841, 0x1842, 0x1843,
- 0x1844, 0x1845, 0x1846, 0x1847, 0x1848, 0x1849, 0x1861, 0x1862,
- 0x1863, 0x1864, 0x1865, 0x1866, 0x1867, 0x1868, 0x1869, 0x186a,
- 0x186b, 0x186c, 0x186d, 0x186e, 0x191b, 0x191c, 0x191d, 0x191e,
- 0x191f, 0x1942, 0x1943, 0x1944, 0x1945, 0x1946, 0x1947, 0x1958,
- 0x1959, 0x19ed, 0x19ee, 0x19ef, 0x19f0, 0x19f1, 0x19f2, 0x19f3,
- 0x19f4, 0x19f5, 0x19f6, 0x19f7, 0x1b0e, 0x1b0f, 0x1b62, 0x1b63,
- 0x1b64, 0x1b65, 0x1b66, 0x1b67, 0x1b68, 0x1b69, 0x1b6a, 0x1b6b,
- 0x1b6c, 0x1b6d, 0x1b6e, 0x1b6f, 0x1b82, 0x1ba8, 0x1ba9, 0x1baa,
- 0x1bab, 0x1bac, 0x1bad, 0x1bae, 0x1baf, 0x1bb0, 0x1bb1, 0x1bb2,
- 0x1bb3, 0x1d80, 0x1d81, 0x1d82, 0x1d83, 0x1d84, 0x1d85, 0x1d86,
- 0x1d87, 0x1d88, 0x1d89, 0x1d8a, 0x1d8b, 0x1d8c, 0x1d8d, 0x1007,
- 0x1008, 0x1009, 0x100a, 0x100b, 0x100c, 0x100d, 0x100e, 0x100f,
- 0x1016, 0x1080, 0x1081, 0x1082, 0x1083, 0x1084, 0x1085, 0x1086,
- 0x1087, 0x10c0, 0x123a, 0x123b, 0x123c, 0x123d, 0x123e, 0x123f,
- 0x1240, 0x1241, 0x1242, 0x1243, 0x1350, 0x1352, 0x1353, 0x1358,
- 0x1359, 0x135a, 0x135b, 0x135c, 0x135d, 0x135e, 0x135f, 0x1360,
- 0x1361, 0x1602, 0x1603, 0x160c, 0x160d, 0x160e, 0x160f, 0x1620,
- 0x1621, 0x1622, 0x1623, 0x1624, 0x1625, 0x1626, 0x1627, 0x1628,
- 0x1629, 0x166e, 0x166f, 0x167c, 0x167d, 0x167e, 0x167f, 0x1770,
- 0x1771, 0x1852, 0x1853, 0x1872, 0x1873, 0x1874, 0x1875, 0x1876,
- 0x1877, 0x1878, 0x1879, 0x187a, 0x187b, 0x187c, 0x187d, 0x187e,
- 0x187f, 0x1918, 0x1919, 0x1926, 0x1927, 0x1970, 0x1971, 0x1972,
- 0x1973, 0x1974, 0x1975, 0x1976, 0x1977, 0x1978, 0x1979, 0x197a,
- 0x197b, 0x1aa0, 0x1aa1, 0x1aa2, 0x1aa3, 0x1aa4, 0x1aa5, 0x1aa6,
- 0x1aa7, 0x1aa8, 0x1aa9, 0x1aaa, 0x1aab, 0x1aac, 0x1aad, 0x1b3c,
- 0x1b3d, 0x1b3e, 0x1b3f, 0x1b50, 0x1b51, 0x1b52, 0x1b53, 0x1b54,
- 0x1b55, 0x1b56, 0x1b57, 0x1b58, 0x1b59, 0x2032, 0x2033, 0x2034,
- 0x2035, 0x2036, 0x2037, 0x2038, 0x2039, 0x203a, 0x203b, 0x203c,
- 0x203d, 0x203e, 0x203f, 0x2040, 0x2041, 0x2042, 0x2043, 0x20ba,
- 0x20bb, 0x20cc, 0x20cd, 0x20ce, 0x20cf, 0x20e0, 0x20e1, 0x20e2,
- 0x20e3, 0x20e4, 0x20e5, 0x20e6, 0x20e7, 0x21aa, 0x21ab, 0x21c0,
- 0x21c1, 0x21c2, 0x21c3, 0x21c4, 0x21c5, 0x21c6, 0x21c7, 0x21c8,
- 0x21c9, 0x21ca, 0x21cb, 0x21cc, 0x21cd, 0x21ce, 0x21cf, 0x21d0,
- 0x21d1, 0x21d2, 0x21d3, 0x2894, 0x2895, 0x2896, 0x2897, 0x2898,
- 0x2899, 0x289a, 0x289b, 0x289c, 0x289d, 0x289e, 0x289f, 0x28c0,
- 0x28c1, 0x28c2, 0x28c3, 0x28c4, 0x28c5, 0x28c6, 0x28c7, 0x28c8,
- 0x28c9, 0x28ca, 0x28cb, 0x2930, 0x2931, 0x2932, 0x2933, 0x2934,
- 0x2935, 0x2936, 0x2937, 0x2938, 0x2939, 0x293a, 0x293b, 0x293c,
- 0x293d, 0x293e, 0x293f, 0x2960, 0x2961, 0x2962, 0x2963, 0x2964,
- 0x2965, 0x2966, 0x2967, 0x2968, 0x2969, 0x296a, 0x296b, 0x2a40,
- 0x2a41, 0x2a42, 0x2a43, 0x2a44, 0x2a45, 0x2a46, 0x2a47, 0x2a48,
- 0x2a49, 0x2a4a, 0x2a4b, 0x2a4c, 0x2a4d, 0x2a4e, 0x2a4f, 0x2a50,
- 0x2a51, 0x2a52, 0x2a53, 0x2ae6, 0x2ae7, 0x2b24, 0x2b25, 0x2b26,
- 0x2b27, 0x2b28, 0x2b29, 0x2b2a, 0x2b2b, 0x2b2c, 0x2b2d, 0x2b2e,
- 0x2b2f, 0x2b30, 0x2b31, 0x2b32, 0x2b33, 0x2b5a, 0x2b5b, 0x3014,
- 0x3015, 0x3016, 0x3017, 0x3020, 0x3021, 0x3022, 0x3023, 0x3024,
- 0x3025, 0x3026, 0x3027, 0x3028, 0x3029, 0x302a, 0x302b, 0x302c,
- 0x302d, 0x302e, 0x302f, 0x3030, 0x3031, 0x3032, 0x3033, 0x3034,
- 0x3035, 0x3036, 0x3037, 0x3038, 0x3039, 0x30c0, 0x30c1, 0x30de,
- 0x30df, 0x3218, 0x3219, 0x321a, 0x321b, 0x321c, 0x321d, 0x321e,
- 0x321f, 0x3220, 0x3221, 0x3222, 0x3223, 0x3224, 0x3225, 0x3226,
- 0x3227, 0x3228, 0x3229, 0x322a, 0x322b, 0x322c, 0x322d, 0x322e,
- 0x322f, 0x3230, 0x3231, 0x3232, 0x3233, 0x3234, 0x3235, 0x3378,
- 0x3379, 0x337a, 0x337b, 0x337c, 0x337d, 0x337e, 0x337f, 0x33c0,
- 0x33c1, 0x33c2, 0x33c3, 0x33c4, 0x33c5, 0x33c6, 0x33c7, 0x33c8,
- 0x33c9, 0x33ca, 0x33cb, 0x33cc, 0x33cd, 0x33ce, 0x33cf, 0x33d0,
- 0x33d1, 0x33d2, 0x33d3, 0x33d4, 0x33d5, 0x33d6, 0x33d7, 0x33d8,
- 0x33d9, 0x3706, 0x3707, 0x3730, 0x3731, 0x3732, 0x3733, 0x3734,
- 0x3735, 0x3736, 0x3737, 0x3738, 0x3739, 0x373a, 0x373b, 0x373c,
- 0x373d, 0x373e, 0x373f, 0x3740, 0x3741, 0x3742, 0x3743, 0x3744,
- 0x3745, 0x3746, 0x3747, 0x3748, 0x3749, 0x374a, 0x374b, 0x374c,
- 0x374d, 0x374e, 0x374f, 0x3b34, 0x3b35, 0x3b36, 0x3b37, 0x3be8,
- 0x3be9, 0x3bea, 0x3beb, 0x3bec, 0x3bed, 0x3bee, 0x3bef, 0x3bf0,
- 0x3bf1, 0x3bf2, 0x3bf3, 0x3bf4, 0x3bf5, 0x3bf6, 0x3bf7, 0x3bf8,
- 0x3bf9, 0x3bfa, 0x3bfb, 0x3bfc, 0x3bfd, 0x3bfe, 0x3bff, 0x2000,
- 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
- 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x202e, 0x202f, 0x2182,
- 0x2183, 0x21b4, 0x21b5, 0x21b6, 0x21b7, 0x21b8, 0x21b9, 0x21ba,
- 0x21bb, 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x2460, 0x2461, 0x2462,
- 0x2463, 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x246a,
- 0x246b, 0x246c, 0x246d, 0x246e, 0x246f, 0x2470, 0x2471, 0x2472,
- 0x2473, 0x26a2, 0x26a3, 0x000b,
-};
-
-static const uint8_t table1_mv_bits[1100] = {
- 2, 4, 4, 4, 5, 5, 5, 5,
- 6, 6, 7, 7, 7, 7, 7, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 4,
-};
-
-static const uint8_t table1_mvx[1099] = {
- 32, 31, 32, 31, 33, 32, 33, 33,
- 31, 34, 30, 32, 32, 34, 35, 32,
- 34, 33, 29, 30, 30, 32, 31, 31,
- 33, 35, 35, 33, 31, 29, 29, 33,
- 34, 30, 31, 28, 36, 30, 34, 32,
- 32, 37, 32, 32, 25, 27, 39, 32,
- 32, 32, 38, 35, 36, 32, 37, 61,
- 26, 32, 34, 35, 3, 35, 27, 28,
- 29, 34, 28, 37, 31, 36, 32, 27,
- 31, 30, 29, 39, 33, 29, 33, 35,
- 25, 25, 29, 33, 31, 31, 31, 33,
- 32, 30, 32, 32, 41, 39, 33, 36,
- 32, 28, 34, 36, 38, 24, 60, 31,
- 23, 28, 32, 33, 59, 32, 40, 30,
- 5, 34, 32, 38, 32, 30, 43, 4,
- 32, 32, 42, 31, 31, 32, 26, 38,
- 26, 22, 21, 37, 61, 63, 37, 31,
- 32, 33, 2, 1, 23, 33, 41, 27,
- 35, 30, 38, 23, 33, 3, 28, 34,
- 34, 27, 41, 29, 39, 35, 36, 29,
- 32, 27, 30, 32, 24, 61, 37, 26,
- 59, 25, 35, 27, 36, 37, 30, 31,
- 34, 40, 3, 28, 34, 39, 32, 31,
- 32, 30, 24, 28, 35, 36, 26, 32,
- 31, 33, 29, 33, 39, 25, 30, 24,
- 35, 59, 29, 34, 25, 30, 21, 35,
- 43, 40, 32, 29, 5, 28, 31, 62,
- 33, 33, 25, 31, 21, 31, 43, 31,
- 34, 33, 20, 40, 39, 31, 31, 57,
- 38, 32, 42, 33, 32, 31, 32, 29,
- 30, 44, 5, 31, 22, 34, 36, 17,
- 38, 58, 38, 35, 32, 60, 35, 24,
- 32, 38, 16, 45, 42, 32, 31, 29,
- 4, 30, 17, 40, 46, 48, 63, 32,
- 42, 19, 41, 22, 28, 36, 45, 33,
- 33, 32, 29, 7, 41, 42, 18, 33,
- 33, 32, 22, 37, 1, 26, 22, 23,
- 49, 28, 26, 27, 32, 33, 27, 23,
- 28, 36, 15, 6, 34, 27, 31, 26,
- 23, 2, 33, 32, 34, 41, 28, 32,
- 41, 0, 36, 38, 34, 31, 47, 32,
- 17, 31, 39, 33, 37, 51, 30, 47,
- 32, 50, 32, 19, 63, 30, 25, 27,
- 33, 62, 24, 31, 27, 30, 37, 31,
- 45, 32, 39, 20, 46, 47, 35, 19,
- 34, 1, 49, 21, 21, 14, 51, 26,
- 23, 31, 36, 35, 58, 29, 29, 21,
- 20, 42, 13, 28, 12, 40, 31, 33,
- 39, 60, 32, 44, 33, 31, 28, 37,
- 29, 32, 30, 49, 43, 28, 39, 25,
- 32, 48, 2, 15, 20, 25, 31, 28,
- 21, 24, 25, 15, 31, 17, 37, 43,
- 18, 32, 33, 24, 33, 36, 13, 33,
- 31, 39, 11, 31, 33, 32, 39, 37,
- 32, 32, 29, 17, 44, 46, 36, 35,
- 26, 37, 58, 32, 34, 38, 8, 38,
- 38, 22, 29, 25, 16, 35, 32, 35,
- 33, 43, 18, 46, 38, 50, 33, 18,
- 53, 60, 13, 32, 36, 33, 51, 36,
- 43, 45, 27, 42, 29, 24, 30, 25,
- 31, 52, 31, 35, 38, 9, 22, 34,
- 4, 17, 28, 55, 42, 25, 17, 20,
- 47, 34, 33, 16, 40, 25, 16, 30,
- 53, 29, 10, 11, 14, 26, 33, 4,
- 35, 44, 26, 16, 31, 26, 34, 38,
- 29, 31, 30, 24, 22, 61, 32, 9,
- 45, 34, 31, 19, 9, 31, 46, 31,
- 35, 54, 29, 57, 30, 50, 3, 31,
- 63, 34, 47, 41, 51, 18, 31, 14,
- 37, 38, 31, 24, 32, 31, 50, 33,
- 31, 54, 27, 9, 33, 23, 19, 32,
- 29, 29, 33, 28, 47, 49, 30, 47,
- 33, 27, 25, 54, 44, 45, 50, 58,
- 51, 48, 33, 59, 33, 34, 57, 13,
- 26, 33, 13, 48, 30, 11, 7, 56,
- 34, 55, 26, 0, 26, 35, 1, 51,
- 33, 53, 31, 45, 12, 29, 29, 51,
- 31, 48, 2, 6, 34, 30, 28, 33,
- 60, 40, 27, 46, 31, 9, 35, 29,
- 31, 39, 55, 46, 19, 37, 62, 34,
- 30, 16, 19, 49, 41, 41, 39, 37,
- 14, 5, 13, 35, 55, 30, 40, 40,
- 42, 8, 20, 25, 45, 35, 33, 36,
- 54, 38, 27, 37, 62, 40, 15, 59,
- 49, 31, 29, 34, 34, 39, 24, 29,
- 25, 29, 21, 29, 10, 61, 33, 49,
- 35, 34, 3, 38, 39, 29, 7, 41,
- 1, 35, 4, 23, 15, 23, 11, 37,
- 28, 35, 30, 30, 24, 1, 43, 56,
- 8, 34, 42, 24, 45, 30, 20, 23,
- 8, 38, 22, 33, 17, 52, 34, 22,
- 53, 43, 44, 1, 27, 31, 41, 43,
- 41, 30, 31, 36, 30, 5, 55, 31,
- 33, 30, 40, 23, 15, 29, 34, 34,
- 59, 34, 30, 11, 13, 38, 5, 0,
- 30, 42, 5, 30, 29, 34, 10, 44,
- 30, 63, 35, 12, 3, 26, 15, 17,
- 25, 34, 43, 39, 34, 56, 29, 23,
- 30, 12, 30, 10, 35, 9, 24, 58,
- 10, 12, 54, 33, 37, 20, 41, 35,
- 29, 18, 61, 30, 40, 24, 39, 53,
- 62, 26, 29, 33, 34, 53, 49, 21,
- 27, 11, 63, 20, 26, 23, 7, 13,
- 6, 47, 29, 30, 9, 51, 22, 34,
- 21, 25, 33, 56, 57, 30, 38, 51,
- 51, 38, 63, 28, 40, 35, 33, 18,
- 33, 33, 24, 58, 58, 34, 49, 29,
- 43, 4, 1, 4, 42, 35, 35, 30,
- 17, 5, 56, 61, 25, 37, 36, 55,
- 28, 35, 29, 50, 48, 52, 2, 42,
- 34, 40, 46, 46, 43, 35, 29, 48,
- 20, 29, 31, 41, 7, 30, 35, 19,
- 14, 21, 8, 39, 39, 40, 46, 55,
- 34, 6, 30, 34, 37, 25, 37, 33,
- 22, 44, 52, 17, 35, 29, 36, 35,
- 40, 37, 28, 30, 50, 14, 28, 55,
- 6, 23, 19, 14, 30, 3, 30, 28,
- 28, 61, 61, 47, 45, 48, 40, 40,
- 34, 34, 25, 30, 29, 35, 4, 26,
- 53, 50, 26, 41, 27, 59, 27, 38,
- 39, 3, 50, 43, 47, 23, 33, 55,
- 35, 21, 23, 35, 61, 33, 46, 52,
- 35, 34, 24, 30, 43, 16, 37, 21,
- 2, 24, 45, 34, 30, 55, 55, 1,
- 29, 29, 26, 28, 25, 31, 36, 22,
- 17, 30, 52, 2, 44, 44, 57, 26,
- 62, 41, 39, 57, 26, 46, 49, 11,
- 16, 19, 5, 59, 38, 39, 58, 38,
- 25, 49, 50, 22, 28, 59, 9, 59,
- 7, 28, 55, 17, 4, 35, 50, 21,
- 29, 44, 47, 18, 24, 19, 25, 42,
- 35, 3, 51, 35, 16, 35, 30, 63,
- 57, 39, 39, 25, 35, 38, 9, 16,
- 36, 45, 31, 60, 14, 34, 42, 24,
- 0, 37, 18, 61, 57, 37, 28, 53,
- 20, 46, 14, 47, 38, 38, 38, 9,
- 34, 39, 43, 17, 39, 59, 5, 27,
- 0, 12, 27,
-};
-
-static const uint8_t table1_mvy[1099] = {
- 32, 32, 31, 31, 32, 33, 31, 33,
- 33, 32, 32, 30, 34, 31, 32, 29,
- 33, 30, 32, 33, 31, 35, 34, 30,
- 34, 31, 33, 29, 29, 31, 33, 35,
- 30, 30, 35, 32, 32, 34, 34, 28,
- 25, 32, 36, 27, 32, 32, 32, 37,
- 39, 3, 32, 30, 31, 26, 31, 32,
- 32, 38, 29, 29, 32, 34, 31, 31,
- 34, 35, 33, 33, 28, 33, 1, 33,
- 27, 29, 30, 31, 28, 29, 37, 35,
- 31, 33, 35, 27, 36, 37, 25, 25,
- 61, 35, 4, 5, 32, 33, 36, 30,
- 23, 30, 28, 34, 31, 32, 32, 39,
- 32, 34, 21, 39, 32, 59, 32, 28,
- 32, 36, 60, 33, 24, 36, 32, 32,
- 41, 2, 32, 38, 26, 22, 33, 30,
- 31, 32, 32, 30, 31, 32, 29, 3,
- 40, 38, 32, 32, 33, 26, 31, 34,
- 28, 38, 34, 31, 3, 31, 35, 38,
- 27, 35, 33, 28, 29, 27, 29, 27,
- 43, 29, 37, 63, 31, 33, 34, 30,
- 31, 30, 37, 30, 35, 35, 26, 41,
- 37, 31, 33, 28, 26, 30, 42, 24,
- 7, 27, 33, 29, 36, 28, 34, 57,
- 23, 41, 36, 23, 35, 34, 25, 30,
- 25, 33, 25, 25, 29, 24, 33, 39,
- 33, 33, 0, 37, 31, 36, 21, 32,
- 61, 24, 35, 61, 31, 5, 31, 59,
- 39, 21, 32, 30, 34, 22, 40, 32,
- 29, 16, 31, 5, 62, 2, 20, 39,
- 39, 32, 33, 1, 31, 24, 36, 32,
- 36, 32, 28, 26, 6, 31, 38, 34,
- 58, 35, 32, 33, 33, 17, 43, 26,
- 31, 40, 31, 34, 32, 32, 31, 19,
- 30, 32, 29, 33, 38, 38, 32, 59,
- 40, 18, 38, 32, 35, 34, 32, 17,
- 1, 15, 30, 28, 31, 28, 34, 29,
- 32, 27, 35, 27, 49, 22, 37, 34,
- 37, 26, 32, 32, 22, 28, 45, 29,
- 30, 31, 43, 46, 41, 30, 26, 13,
- 34, 32, 27, 38, 42, 42, 33, 47,
- 33, 60, 27, 42, 25, 32, 22, 32,
- 48, 32, 45, 33, 33, 41, 27, 25,
- 19, 31, 35, 19, 36, 42, 27, 17,
- 31, 44, 28, 33, 33, 31, 23, 31,
- 40, 33, 31, 34, 30, 32, 33, 36,
- 35, 47, 37, 41, 31, 23, 41, 29,
- 30, 35, 32, 25, 32, 28, 58, 2,
- 37, 33, 14, 33, 49, 20, 39, 36,
- 21, 9, 23, 33, 35, 24, 39, 37,
- 11, 33, 30, 31, 31, 28, 51, 40,
- 35, 29, 25, 33, 46, 35, 37, 30,
- 30, 8, 63, 28, 15, 40, 33, 45,
- 49, 25, 32, 4, 47, 51, 36, 39,
- 53, 10, 24, 29, 30, 31, 25, 40,
- 38, 38, 33, 56, 23, 27, 32, 37,
- 26, 29, 43, 36, 33, 24, 55, 43,
- 9, 29, 34, 34, 24, 33, 18, 33,
- 33, 30, 31, 50, 24, 60, 30, 39,
- 34, 30, 39, 28, 22, 38, 2, 26,
- 63, 32, 57, 21, 39, 33, 28, 18,
- 30, 34, 22, 33, 29, 41, 30, 34,
- 35, 21, 13, 34, 35, 39, 30, 46,
- 32, 42, 32, 31, 33, 26, 11, 33,
- 22, 31, 25, 31, 53, 27, 43, 25,
- 40, 50, 21, 36, 38, 30, 12, 31,
- 34, 20, 15, 29, 32, 62, 30, 13,
- 17, 32, 19, 31, 20, 31, 30, 7,
- 1, 17, 34, 37, 31, 31, 44, 34,
- 26, 40, 16, 37, 52, 48, 30, 20,
- 18, 33, 38, 29, 7, 25, 30, 54,
- 45, 47, 46, 41, 29, 29, 16, 30,
- 14, 26, 38, 34, 34, 29, 34, 30,
- 29, 30, 57, 30, 4, 46, 33, 29,
- 39, 44, 30, 31, 50, 33, 31, 32,
- 19, 32, 40, 31, 37, 47, 1, 35,
- 16, 31, 0, 35, 33, 1, 17, 34,
- 9, 34, 33, 31, 49, 43, 42, 51,
- 34, 29, 23, 29, 14, 30, 45, 49,
- 11, 24, 31, 28, 35, 41, 30, 44,
- 18, 29, 34, 35, 36, 25, 26, 21,
- 31, 30, 34, 19, 34, 44, 36, 38,
- 25, 31, 28, 23, 37, 3, 55, 41,
- 30, 22, 41, 24, 33, 26, 35, 35,
- 30, 55, 51, 47, 48, 38, 24, 15,
- 21, 50, 25, 46, 30, 29, 10, 34,
- 42, 45, 29, 42, 22, 3, 33, 27,
- 34, 1, 34, 28, 34, 36, 35, 23,
- 23, 13, 58, 3, 26, 63, 25, 31,
- 34, 61, 38, 39, 25, 61, 29, 37,
- 30, 41, 26, 48, 28, 33, 50, 35,
- 30, 37, 29, 29, 40, 6, 39, 28,
- 28, 19, 8, 22, 45, 34, 35, 10,
- 58, 17, 37, 39, 30, 18, 54, 14,
- 29, 16, 59, 30, 35, 23, 35, 30,
- 47, 36, 29, 55, 20, 12, 31, 35,
- 14, 29, 18, 34, 34, 24, 29, 26,
- 22, 2, 27, 23, 8, 30, 55, 38,
- 60, 31, 4, 34, 49, 34, 27, 34,
- 33, 30, 31, 54, 42, 35, 38, 46,
- 44, 26, 27, 9, 39, 25, 21, 29,
- 28, 42, 13, 0, 5, 34, 37, 28,
- 24, 29, 63, 26, 22, 27, 29, 25,
- 33, 25, 61, 0, 35, 25, 36, 15,
- 27, 40, 53, 33, 3, 10, 16, 37,
- 38, 18, 30, 46, 27, 9, 6, 29,
- 62, 8, 42, 28, 29, 3, 25, 16,
- 26, 29, 35, 28, 27, 51, 61, 48,
- 37, 9, 34, 7, 49, 45, 20, 29,
- 21, 5, 5, 29, 28, 34, 29, 24,
- 10, 24, 35, 36, 38, 55, 11, 36,
- 38, 53, 54, 26, 30, 49, 20, 27,
- 30, 39, 33, 41, 49, 22, 38, 38,
- 4, 30, 8, 9, 3, 24, 22, 50,
- 37, 36, 31, 27, 2, 9, 42, 63,
- 25, 19, 44, 1, 28, 28, 48, 30,
- 34, 41, 41, 38, 12, 27, 15, 0,
- 16, 34, 35, 38, 28, 29, 40, 42,
- 51, 52, 45, 54, 59, 59, 42, 44,
- 37, 26, 46, 24, 15, 39, 22, 46,
- 19, 35, 38, 17, 37, 23, 52, 55,
- 50, 37, 26, 11, 37, 12, 24, 30,
- 16, 13, 22, 13, 36, 35, 40, 41,
- 34, 41, 26, 53, 51, 5, 21, 30,
- 2, 63, 41, 20, 1, 56, 21, 24,
- 25, 5, 28, 35, 26, 28, 30, 18,
- 29, 23, 40, 34, 20, 42, 39, 34,
- 28, 61, 38, 27, 62, 9, 36, 17,
- 9, 49, 24, 25, 54, 34, 39, 37,
- 3, 1, 25, 38, 38, 44, 35, 36,
- 12, 60, 36, 38, 40, 25, 43, 39,
- 53, 28, 39, 57, 46, 10, 52, 27,
- 35, 42, 45, 59, 15, 60, 38, 24,
- 23, 39, 12, 29, 24, 0, 20, 16,
- 28, 43, 35, 28, 1, 49, 4, 21,
- 42, 39, 29, 3, 44, 21, 53, 55,
- 11, 5, 3, 39, 53, 28, 25, 19,
- 34, 28, 21,
-};
-
-/* motion vector table */
-typedef struct MVTable {
- int n;
- const uint16_t *table_mv_code;
- const uint8_t *table_mv_bits;
- const uint8_t *table_mvx;
- const uint8_t *table_mvy;
- uint16_t *table_mv_index; /* encoding: convert mv to index in table_mv */
- VLC vlc; /* decoding: vlc */
-} MVTable;
-
-static MVTable mv_tables[2] = {
- {
- 1099,
- table0_mv_code,
- table0_mv_bits,
- table0_mvx,
- table0_mvy,
- },
- {
- 1099,
- table1_mv_code,
- table1_mv_bits,
- table1_mvx,
- table1_mvy,
- }
-};
-
-static const uint8_t v2_mb_type[8][2] = {
- {1, 1}, {0 , 2}, {3 , 3}, {9 , 5},
- {5, 4}, {0x21, 7}, {0x20, 7}, {0x11, 6},
-};
-
-static const uint8_t v2_intra_cbpc[4][2] = {
- {1, 1}, {0, 3}, {1, 3}, {1, 2},
-};
-
-static uint8_t wmv1_y_dc_scale_table[32]={
-// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
- 0, 8, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21
-};
-static uint8_t wmv1_c_dc_scale_table[32]={
-// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
- 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22
-};
-
-static uint8_t old_ff_y_dc_scale_table[32]={
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
-};
-static uint8_t old_ff_c_dc_scale_table[32]={
-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
- 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22
-};
-
-
-#define WMV1_SCANTABLE_COUNT 4
-
-static const uint8_t wmv1_scantable00[64]= {
-0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11,
-0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28,
-0x30, 0x38, 0x29, 0x21, 0x1A, 0x13, 0x0C, 0x05,
-0x06, 0x0D, 0x14, 0x1B, 0x22, 0x31, 0x39, 0x3A,
-0x32, 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F,
-0x16, 0x1D, 0x24, 0x2B, 0x33, 0x3B, 0x3C, 0x34,
-0x2C, 0x25, 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x35,
-0x3D, 0x3E, 0x36, 0x2E, 0x27, 0x2F, 0x37, 0x3F,
-};
-static const uint8_t wmv1_scantable01[64]= {
-0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11,
-0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28,
-0x21, 0x30, 0x1A, 0x13, 0x0C, 0x05, 0x06, 0x0D,
-0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, 0x2A,
-0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, 0x16, 0x1D,
-0x24, 0x2B, 0x32, 0x3A, 0x33, 0x3B, 0x2C, 0x25,
-0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3C, 0x35,
-0x3D, 0x2E, 0x27, 0x2F, 0x36, 0x3E, 0x37, 0x3F,
-};
-static const uint8_t wmv1_scantable02[64]= {
-0x00, 0x01, 0x08, 0x02, 0x03, 0x09, 0x10, 0x18,
-0x11, 0x0A, 0x04, 0x05, 0x0B, 0x12, 0x19, 0x20,
-0x28, 0x30, 0x21, 0x1A, 0x13, 0x0C, 0x06, 0x07,
-0x0D, 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39,
-0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x0F, 0x16, 0x1D,
-0x24, 0x2B, 0x32, 0x3A, 0x33, 0x2C, 0x25, 0x1E,
-0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3B, 0x3C, 0x35,
-0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F,
-};
-static const uint8_t wmv1_scantable03[64]= {
-0x00, 0x08, 0x10, 0x01, 0x18, 0x20, 0x28, 0x09,
-0x02, 0x03, 0x0A, 0x11, 0x19, 0x30, 0x38, 0x29,
-0x21, 0x1A, 0x12, 0x0B, 0x04, 0x05, 0x0C, 0x13,
-0x1B, 0x22, 0x31, 0x39, 0x32, 0x2A, 0x23, 0x1C,
-0x14, 0x0D, 0x06, 0x07, 0x0E, 0x15, 0x1D, 0x24,
-0x2B, 0x33, 0x3A, 0x3B, 0x34, 0x2C, 0x25, 0x1E,
-0x16, 0x0F, 0x17, 0x1F, 0x26, 0x2D, 0x3C, 0x35,
-0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F,
-};
-
-static const uint8_t *wmv1_scantable[WMV1_SCANTABLE_COUNT+1]={
- wmv1_scantable00,
- wmv1_scantable01,
- wmv1_scantable02,
- wmv1_scantable03,
-};
-
-static const uint8_t table_inter_intra[4][2]={
- {0,1} /*Luma-Left Chroma-Left*/,
- {2,2} /*Luma-Top Chroma-Left*/,
- {6,3} /*luma-Left Chroma-Top */,
- {7,3} /*luma-Top Chroma-Top */
-};
-
-#define WMV2_INTER_CBP_TABLE_COUNT 4
-
-static const uint32_t table_mb_non_intra2[128][2] = {
-{0x0000A7, 14}, {0x01B2B8, 18}, {0x01B28E, 18}, {0x036575, 19},
-{0x006CAC, 16}, {0x000A69, 18}, {0x002934, 20}, {0x00526B, 21},
-{0x006CA1, 16}, {0x01B2B9, 18}, {0x0029AD, 20}, {0x029353, 24},
-{0x006CA7, 16}, {0x006CAB, 16}, {0x01B2BB, 18}, {0x00029B, 16},
-{0x00D944, 17}, {0x000A6A, 18}, {0x0149A8, 23}, {0x03651F, 19},
-{0x006CAF, 16}, {0x000A4C, 18}, {0x03651E, 19}, {0x000A48, 18},
-{0x00299C, 20}, {0x00299F, 20}, {0x029352, 24}, {0x0029AC, 20},
-{0x000296, 16}, {0x00D946, 17}, {0x000A68, 18}, {0x000298, 16},
-{0x000527, 17}, {0x00D94D, 17}, {0x0014D7, 19}, {0x036574, 19},
-{0x000A5C, 18}, {0x01B299, 18}, {0x00299D, 20}, {0x00299E, 20},
-{0x000525, 17}, {0x000A66, 18}, {0x00A4D5, 22}, {0x00149B, 19},
-{0x000295, 16}, {0x006CAD, 16}, {0x000A49, 18}, {0x000521, 17},
-{0x006CAA, 16}, {0x00D945, 17}, {0x01B298, 18}, {0x00052F, 17},
-{0x003654, 15}, {0x006CA0, 16}, {0x000532, 17}, {0x000291, 16},
-{0x003652, 15}, {0x000520, 17}, {0x000A5D, 18}, {0x000294, 16},
-{0x00009B, 11}, {0x0006E2, 12}, {0x000028, 12}, {0x0001B0, 10},
-{0x000001, 3}, {0x000010, 8}, {0x00002F, 6}, {0x00004C, 10},
-{0x00000D, 4}, {0x000000, 10}, {0x000006, 9}, {0x000134, 12},
-{0x00000C, 4}, {0x000007, 10}, {0x000007, 9}, {0x0006E1, 12},
-{0x00000E, 5}, {0x0000DA, 9}, {0x000022, 9}, {0x000364, 11},
-{0x00000F, 4}, {0x000006, 10}, {0x00000F, 9}, {0x000135, 12},
-{0x000014, 5}, {0x0000DD, 9}, {0x000004, 9}, {0x000015, 11},
-{0x00001A, 6}, {0x0001B3, 10}, {0x000005, 10}, {0x0006E3, 12},
-{0x00000C, 5}, {0x0000B9, 8}, {0x000004, 8}, {0x0000DB, 9},
-{0x00000E, 4}, {0x00000B, 10}, {0x000023, 9}, {0x0006CB, 12},
-{0x000005, 6}, {0x0001B1, 10}, {0x000001, 10}, {0x0006E0, 12},
-{0x000011, 5}, {0x0000DF, 9}, {0x00000E, 9}, {0x000373, 11},
-{0x000003, 5}, {0x0000B8, 8}, {0x000006, 8}, {0x000175, 9},
-{0x000015, 5}, {0x000174, 9}, {0x000027, 9}, {0x000372, 11},
-{0x000010, 5}, {0x0000BB, 8}, {0x000005, 8}, {0x0000DE, 9},
-{0x00000F, 5}, {0x000001, 9}, {0x000012, 8}, {0x000004, 10},
-{0x000002, 3}, {0x000016, 5}, {0x000009, 4}, {0x000001, 5},
-};
-
-static const uint32_t table_mb_non_intra3[128][2] = {
-{0x0002A1, 10}, {0x005740, 15}, {0x01A0BF, 18}, {0x015D19, 17},
-{0x001514, 13}, {0x00461E, 15}, {0x015176, 17}, {0x015177, 17},
-{0x0011AD, 13}, {0x00682E, 16}, {0x0682F9, 20}, {0x03417D, 19},
-{0x001A36, 14}, {0x002A2D, 14}, {0x00D05E, 17}, {0x006824, 16},
-{0x001515, 13}, {0x00545C, 15}, {0x0230E9, 18}, {0x011AFA, 17},
-{0x0015D7, 13}, {0x005747, 15}, {0x008D79, 16}, {0x006825, 16},
-{0x002BA2, 14}, {0x00A8BA, 16}, {0x0235F6, 18}, {0x015D18, 17},
-{0x0011AE, 13}, {0x00346F, 15}, {0x008C3B, 16}, {0x00346E, 15},
-{0x000D1A, 13}, {0x00461F, 15}, {0x0682F8, 20}, {0x011875, 17},
-{0x002BA1, 14}, {0x008D61, 16}, {0x0235F7, 18}, {0x0230E8, 18},
-{0x001513, 13}, {0x008D7B, 16}, {0x011AF4, 17}, {0x011AF5, 17},
-{0x001185, 13}, {0x0046BF, 15}, {0x008D60, 16}, {0x008D7C, 16},
-{0x001512, 13}, {0x00461C, 15}, {0x00AE8D, 16}, {0x008D78, 16},
-{0x000D0E, 13}, {0x003413, 15}, {0x0046B1, 15}, {0x003416, 15},
-{0x000AEA, 12}, {0x002A2C, 14}, {0x005741, 15}, {0x002A2F, 14},
-{0x000158, 9}, {0x0008D2, 12}, {0x00054C, 11}, {0x000686, 12},
-{0x000000, 2}, {0x000069, 8}, {0x00006B, 8}, {0x00068C, 12},
-{0x000007, 3}, {0x00015E, 9}, {0x0002A3, 10}, {0x000AE9, 12},
-{0x000006, 3}, {0x000231, 10}, {0x0002B8, 10}, {0x001A08, 14},
-{0x000010, 5}, {0x0001A9, 10}, {0x000342, 11}, {0x000A88, 12},
-{0x000004, 4}, {0x0001A2, 10}, {0x0002A4, 10}, {0x001184, 13},
-{0x000012, 5}, {0x000232, 10}, {0x0002B2, 10}, {0x000680, 12},
-{0x00001B, 6}, {0x00046A, 11}, {0x00068E, 12}, {0x002359, 14},
-{0x000016, 5}, {0x00015F, 9}, {0x0002A0, 10}, {0x00054D, 11},
-{0x000005, 4}, {0x000233, 10}, {0x0002B9, 10}, {0x0015D6, 13},
-{0x000022, 6}, {0x000468, 11}, {0x000683, 12}, {0x001A0A, 14},
-{0x000013, 5}, {0x000236, 10}, {0x0002BB, 10}, {0x001186, 13},
-{0x000017, 5}, {0x0001AB, 10}, {0x0002A7, 10}, {0x0008D3, 12},
-{0x000014, 5}, {0x000237, 10}, {0x000460, 11}, {0x000D0F, 13},
-{0x000019, 6}, {0x0001AA, 10}, {0x0002B3, 10}, {0x000681, 12},
-{0x000018, 6}, {0x0001A8, 10}, {0x0002A5, 10}, {0x00068F, 12},
-{0x000007, 4}, {0x000055, 7}, {0x000047, 7}, {0x0000AD, 8},
-};
-
-static const uint32_t table_mb_non_intra4[128][2] = {
-{0x0000D4, 8}, {0x0021C5, 14}, {0x00F18A, 16}, {0x00D5BC, 16},
-{0x000879, 12}, {0x00354D, 14}, {0x010E3F, 17}, {0x010F54, 17},
-{0x000866, 12}, {0x00356E, 14}, {0x010F55, 17}, {0x010E3E, 17},
-{0x0010CE, 13}, {0x003C84, 14}, {0x00D5BD, 16}, {0x00F18B, 16},
-{0x000868, 12}, {0x00438C, 15}, {0x0087AB, 16}, {0x00790B, 15},
-{0x000F10, 12}, {0x00433D, 15}, {0x006AD3, 15}, {0x00790A, 15},
-{0x001AA7, 13}, {0x0043D4, 15}, {0x00871E, 16}, {0x006ADF, 15},
-{0x000D7C, 12}, {0x003C94, 14}, {0x00438D, 15}, {0x006AD2, 15},
-{0x0006BC, 11}, {0x0021E9, 14}, {0x006ADA, 15}, {0x006A99, 15},
-{0x0010F7, 13}, {0x004389, 15}, {0x006ADB, 15}, {0x0078C4, 15},
-{0x000D56, 12}, {0x0035F7, 14}, {0x00438E, 15}, {0x006A98, 15},
-{0x000D52, 12}, {0x003C95, 14}, {0x004388, 15}, {0x00433C, 15},
-{0x000D54, 12}, {0x001E4B, 13}, {0x003C63, 14}, {0x003C83, 14},
-{0x000861, 12}, {0x0021EB, 14}, {0x00356C, 14}, {0x0035F6, 14},
-{0x000863, 12}, {0x00219F, 14}, {0x003568, 14}, {0x003C82, 14},
-{0x0001AE, 9}, {0x0010C0, 13}, {0x000F11, 12}, {0x001AFA, 13},
-{0x000000, 1}, {0x0000F0, 8}, {0x0001AD, 9}, {0x0010C1, 13},
-{0x00000A, 4}, {0x0003C5, 10}, {0x000789, 11}, {0x001AB5, 13},
-{0x000009, 4}, {0x000435, 11}, {0x000793, 11}, {0x001E40, 13},
-{0x00001D, 5}, {0x0003CB, 10}, {0x000878, 12}, {0x001AAF, 13},
-{0x00000B, 4}, {0x0003C7, 10}, {0x000791, 11}, {0x001AAB, 13},
-{0x00001F, 5}, {0x000436, 11}, {0x0006BF, 11}, {0x000F19, 12},
-{0x00003D, 6}, {0x000D51, 12}, {0x0010C4, 13}, {0x0021E8, 14},
-{0x000036, 6}, {0x000437, 11}, {0x0006AF, 11}, {0x0010C5, 13},
-{0x00000C, 4}, {0x000432, 11}, {0x000794, 11}, {0x001E30, 13},
-{0x000042, 7}, {0x000870, 12}, {0x000F24, 12}, {0x001E43, 13},
-{0x000020, 6}, {0x00043E, 11}, {0x000795, 11}, {0x001AAA, 13},
-{0x000037, 6}, {0x0006AC, 11}, {0x0006AE, 11}, {0x0010F6, 13},
-{0x000034, 6}, {0x00043A, 11}, {0x000D50, 12}, {0x001AAE, 13},
-{0x000039, 6}, {0x00043F, 11}, {0x00078D, 11}, {0x0010D2, 13},
-{0x000038, 6}, {0x00043B, 11}, {0x0006BD, 11}, {0x0010D3, 13},
-{0x000011, 5}, {0x0001AC, 9}, {0x0000F3, 8}, {0x000439, 11},
-};
-
-static const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]={
- table_mb_non_intra2,
- table_mb_non_intra3,
- table_mb_non_intra4,
- table_mb_non_intra,
-};
-
-static const uint8_t wmv2_scantableA[64]={
-0x00, 0x01, 0x02, 0x08, 0x03, 0x09, 0x0A, 0x10,
-0x04, 0x0B, 0x11, 0x18, 0x12, 0x0C, 0x05, 0x13,
-0x19, 0x0D, 0x14, 0x1A, 0x1B, 0x06, 0x15, 0x1C,
-0x0E, 0x16, 0x1D, 0x07, 0x1E, 0x0F, 0x17, 0x1F,
-};
-
-static const uint8_t wmv2_scantableB[64]={
-0x00, 0x08, 0x01, 0x10, 0x09, 0x18, 0x11, 0x02,
-0x20, 0x0A, 0x19, 0x28, 0x12, 0x30, 0x21, 0x1A,
-0x38, 0x29, 0x22, 0x03, 0x31, 0x39, 0x0B, 0x2A,
-0x13, 0x32, 0x1B, 0x3A, 0x23, 0x2B, 0x33, 0x3B,
-};
+++ /dev/null
-/**
- * @file oggvorbis.c
- * Ogg Vorbis codec support via libvorbisenc.
- * @author Mark Hills <mark@pogo.org.uk>
- */
-
-#include <time.h>
-
-#include <vorbis/vorbisenc.h>
-
-#include "avcodec.h"
-#include "oggvorbis.h"
-
-#define OGGVORBIS_FRAME_SIZE 1024
-
-
-typedef struct OggVorbisContext {
- vorbis_info vi ;
- vorbis_dsp_state vd ;
- vorbis_block vb ;
-
- /* decoder */
- vorbis_comment vc ;
-} OggVorbisContext ;
-
-
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
-
-#ifdef OGGVORBIS_VBR_BY_ESTIMATE
- /* variable bitrate by estimate */
-
- return (vorbis_encode_setup_managed(vi, avccontext->channels,
- avccontext->sample_rate, -1, avccontext->bit_rate, -1) ||
- vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_AVG, NULL) ||
- vorbis_encode_setup_init(vi)) ;
-#else
- /* constant bitrate */
-
- return vorbis_encode_init(vi, avccontext->channels,
- avccontext->sample_rate, -1, avccontext->bit_rate, -1) ;
-#endif
-}
-
-
-static int oggvorbis_encode_init(AVCodecContext *avccontext) {
- OggVorbisContext *context = avccontext->priv_data ;
-
- vorbis_info_init(&context->vi) ;
- if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) {
- fprintf(stderr, "oggvorbis_encode_init: init_encoder failed") ;
- return -1 ;
- }
- vorbis_analysis_init(&context->vd, &context->vi) ;
- vorbis_block_init(&context->vd, &context->vb) ;
-
- avccontext->frame_size = OGGVORBIS_FRAME_SIZE ;
-
- avccontext->coded_frame= avcodec_alloc_frame();
- avccontext->coded_frame->key_frame= 1;
-
- return 0 ;
-}
-
-
-static int oggvorbis_encode_frame(AVCodecContext *avccontext,
- unsigned char *packets,
- int buf_size, void *data)
-{
- OggVorbisContext *context = avccontext->priv_data ;
- float **buffer ;
- ogg_packet op ;
- signed char *audio = data ;
- int l, samples = OGGVORBIS_FRAME_SIZE ;
-
- buffer = vorbis_analysis_buffer(&context->vd, samples) ;
-
- if(context->vi.channels == 1) {
- for(l = 0 ; l < samples ; l++)
- buffer[0][l]=((audio[l*2+1]<<8)|(0x00ff&(int)audio[l*2]))/32768.f;
- } else {
- for(l = 0 ; l < samples ; l++){
- buffer[0][l]=((audio[l*4+1]<<8)|(0x00ff&(int)audio[l*4]))/32768.f;
- buffer[1][l]=((audio[l*4+3]<<8)|(0x00ff&(int)audio[l*4+2]))/32768.f;
- }
- }
-
- vorbis_analysis_wrote(&context->vd, samples) ;
-
- l = 0 ;
-
- while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) {
- vorbis_analysis(&context->vb, NULL);
- vorbis_bitrate_addblock(&context->vb) ;
-
- while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
- memcpy(packets + l, &op, sizeof(ogg_packet)) ;
- memcpy(packets + l + sizeof(ogg_packet), op.packet, op.bytes) ;
- l += sizeof(ogg_packet) + op.bytes ;
- }
- }
-
- return l ;
-}
-
-
-static int oggvorbis_encode_close(AVCodecContext *avccontext) {
- OggVorbisContext *context = avccontext->priv_data ;
-/* ogg_packet op ; */
-
- vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */
-
- /* We need to write all the remaining packets into the stream
- * on closing */
-
- fprintf(stderr, "fixme: not all packets written on oggvorbis_encode_close()\n") ;
-
-/*
- while(vorbis_bitrate_flushpacket(&context->vd, &op)) {
- memcpy(packets + l, &op, sizeof(ogg_packet)) ;
- memcpy(packets + l + sizeof(ogg_packet), op.packet, op.bytes) ;
- l += sizeof(ogg_packet) + op.bytes ;
- }
-*/
-
- vorbis_block_clear(&context->vb);
- vorbis_dsp_clear(&context->vd);
- vorbis_info_clear(&context->vi);
-
- av_freep(&avccontext->coded_frame);
-
- return 0 ;
-}
-
-
-AVCodec oggvorbis_encoder = {
- "vorbis",
- CODEC_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(OggVorbisContext),
- oggvorbis_encode_init,
- oggvorbis_encode_frame,
- oggvorbis_encode_close
-} ;
-
-
-static int oggvorbis_decode_init(AVCodecContext *avccontext) {
- OggVorbisContext *context = avccontext->priv_data ;
-
- vorbis_info_init(&context->vi) ;
- vorbis_comment_init(&context->vc) ;
-
- return 0 ;
-}
-
-
-static inline int conv(int samples, float **pcm, char *buf, int channels) {
- int i, j, val ;
- ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ;
- float *mono ;
-
- for(i = 0 ; i < channels ; i++){
- ptr = &data[i];
- mono = pcm[i] ;
-
- for(j = 0 ; j < samples ; j++) {
-
- val = mono[j] * 32767.f;
-
- if(val > 32767) val = 32767 ;
- if(val < -32768) val = -32768 ;
-
- *ptr = val ;
- ptr += channels;
- }
- }
-
- return 0 ;
-}
-
-
-static int oggvorbis_decode_frame(AVCodecContext *avccontext,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- OggVorbisContext *context = avccontext->priv_data ;
- ogg_packet *op = (ogg_packet*)buf ;
- float **pcm ;
- int samples, total_samples, total_bytes ;
-
- op->packet = (char*)op + sizeof(ogg_packet) ; /* correct data pointer */
-
- if(op->packetno < 3) {
- vorbis_synthesis_headerin(&context->vi, &context->vc, op) ;
- return buf_size ;
- }
-
- if(op->packetno == 3) {
- fprintf(stderr, "vorbis_decode: %d channel, %ldHz, encoder `%s'\n",
- context->vi.channels, context->vi.rate, context->vc.vendor);
-
- avccontext->channels = context->vi.channels ;
- avccontext->sample_rate = context->vi.rate ;
-
- vorbis_synthesis_init(&context->vd, &context->vi) ;
- vorbis_block_init(&context->vd, &context->vb);
- }
-
- if(vorbis_synthesis(&context->vb, op) == 0)
- vorbis_synthesis_blockin(&context->vd, &context->vb) ;
-
- total_samples = 0 ;
- total_bytes = 0 ;
-
- while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) {
- conv(samples, pcm, (char*)data + total_bytes, context->vi.channels) ;
- total_bytes += samples * 2 * context->vi.channels ;
- total_samples += samples ;
- vorbis_synthesis_read(&context->vd, samples) ;
- }
-
- *data_size = total_bytes ;
- return buf_size ;
-}
-
-
-static int oggvorbis_decode_close(AVCodecContext *avccontext) {
- OggVorbisContext *context = avccontext->priv_data ;
-
- vorbis_info_clear(&context->vi) ;
- vorbis_comment_clear(&context->vc) ;
-
- return 0 ;
-}
-
-
-AVCodec oggvorbis_decoder = {
- "vorbis",
- CODEC_TYPE_AUDIO,
- CODEC_ID_VORBIS,
- sizeof(OggVorbisContext),
- oggvorbis_decode_init,
- NULL,
- oggvorbis_decode_close,
- oggvorbis_decode_frame,
-} ;
+++ /dev/null
-/**
- * @file oggvorbis.h
- * oggvorbis.
- */
-
-#ifndef AVCODEC_OGGVORBIS_H
-#define AVCODEC_OGGVORBIS_H
-
-#include <vorbis/vorbisenc.h>
-
-#include "avcodec.h"
-
-int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) ;
-
-#endif
+++ /dev/null
-/*
- * LGPL
- */
-
-/**
- * @file opts.c
- * options parser.
- * typical parsed command line:
- * msmpeg4:bitrate=720000:qmax=16
- *
- */
-
-#include "avcodec.h"
-
-const AVOption avoptions_common[] = {
- AVOPTION_CODEC_FLAG("bit_exact", "use only bit-exact stuff", flags, CODEC_FLAG_BITEXACT, 0),
- AVOPTION_CODEC_FLAG("mm_force", "force mm flags", dsp_mask, FF_MM_FORCE, 0),
-#ifdef HAVE_MMX
- AVOPTION_CODEC_FLAG("mm_mmx", "mask MMX feature", dsp_mask, FF_MM_MMX, 0),
- AVOPTION_CODEC_FLAG("mm_3dnow", "mask 3DNow feature", dsp_mask, FF_MM_3DNOW, 0),
- AVOPTION_CODEC_FLAG("mm_mmxext", "mask MMXEXT (MMX2) feature", dsp_mask, FF_MM_MMXEXT, 0),
- AVOPTION_CODEC_FLAG("mm_sse", "mask SSE feature", dsp_mask, FF_MM_SSE, 0),
- AVOPTION_CODEC_FLAG("mm_sse2", "mask SSE2 feature", dsp_mask, FF_MM_SSE2, 0),
-#endif
- AVOPTION_END()
-};
-
-const AVOption avoptions_workaround_bug[] = {
- AVOPTION_CODEC_FLAG("bug_autodetect", "workaround bug autodetection", workaround_bugs, FF_BUG_AUTODETECT, 1),
- AVOPTION_CODEC_FLAG("bug_old_msmpeg4", "workaround old msmpeg4 bug", workaround_bugs, FF_BUG_OLD_MSMPEG4, 0),
- AVOPTION_CODEC_FLAG("bug_xvid_ilace", "workaround XviD interlace bug", workaround_bugs, FF_BUG_XVID_ILACE, 0),
- AVOPTION_CODEC_FLAG("bug_ump4", "workaround ump4 bug", workaround_bugs, FF_BUG_UMP4, 0),
- AVOPTION_CODEC_FLAG("bug_no_padding", "workaround padding bug", workaround_bugs, FF_BUG_NO_PADDING, 0),
- AVOPTION_CODEC_FLAG("bug_ac_vlc", "workaround ac VLC bug", workaround_bugs, FF_BUG_AC_VLC, 0),
- AVOPTION_CODEC_FLAG("bug_qpel_chroma", "workaround qpel chroma bug", workaround_bugs, FF_BUG_QPEL_CHROMA, 0),
- AVOPTION_CODEC_FLAG("bug_std_qpel", "workaround std qpel bug", workaround_bugs, FF_BUG_STD_QPEL, 0),
- AVOPTION_CODEC_FLAG("bug_qpel_chroma2", "workaround qpel chroma2 bug", workaround_bugs, FF_BUG_QPEL_CHROMA2, 0),
- AVOPTION_CODEC_FLAG("bug_direct_blocksize", "workaround direct blocksize bug", workaround_bugs, FF_BUG_DIRECT_BLOCKSIZE, 0),
- AVOPTION_END()
-};
-
-/* avoid compatibility problems by redefining it */
-static int av_strcasecmp(const char *s1, const char *s2)
-{
- signed char val;
-
- for(;;) {
- val = toupper(*s1) - toupper(*s2);
- if (val != 0)
- break;
- if (*s1 != '\0')
- break;
- s1++;
- s2++;
- }
- return val;
-}
-
-
-static int parse_bool(const AVOption *c, char *s, int *var)
-{
- int b = 1; /* by default -on- when present */
- if (s) {
- if (!av_strcasecmp(s, "off") || !av_strcasecmp(s, "false")
- || !strcmp(s, "0"))
- b = 0;
- else if (!av_strcasecmp(s, "on") || !av_strcasecmp(s, "true")
- || !strcmp(s, "1"))
- b = 1;
- else
- return -1;
- }
-
- if (c->type == FF_OPT_TYPE_FLAG) {
- if (b)
- *var |= (int)c->min;
- else
- *var &= ~(int)c->min;
- } else
- *var = b;
- return 0;
-}
-
-static int parse_double(const AVOption *c, char *s, double *var)
-{
- double d;
- if (!s)
- return -1;
- d = atof(s);
- if (c->min != c->max) {
- if (d < c->min || d > c->max) {
- fprintf(stderr, "Option: %s double value: %f out of range <%f, %f>\n",
- c->name, d, c->min, c->max);
- return -1;
- }
- }
- *var = d;
- return 0;
-}
-
-static int parse_int(const AVOption* c, char* s, int* var)
-{
- int i;
- if (!s)
- return -1;
- i = atoi(s);
- if (c->min != c->max) {
- if (i < (int)c->min || i > (int)c->max) {
- fprintf(stderr, "Option: %s integer value: %d out of range <%d, %d>\n",
- c->name, i, (int)c->min, (int)c->max);
- return -1;
- }
- }
- *var = i;
- return 0;
-}
-
-static int parse_string(const AVOption *c, char *s, void* strct, char **var)
-{
- if (!s)
- return -1;
-
- if (c->type == FF_OPT_TYPE_RCOVERRIDE) {
- int sf, ef, qs;
- float qf;
- if (sscanf(s, "%d,%d,%d,%f", &sf, &ef, &qs, &qf) == 4 && sf < ef) {
- AVCodecContext *avctx = (AVCodecContext *) strct;
- RcOverride *o;
- avctx->rc_override = av_realloc(avctx->rc_override,
- sizeof(RcOverride) * (avctx->rc_override_count + 1));
- o = avctx->rc_override + avctx->rc_override_count++;
- o->start_frame = sf;
- o->end_frame = ef;
- o->qscale = qs;
- o->quality_factor = qf;
-
- //printf("parsed Rc: %d,%d,%d,%f (%d)\n", sf,ef,qs,qf, avctx->rc_override_count);
- } else {
- printf("incorrect/unparsable Rc: \"%s\"\n", s);
- }
- } else
- *var = av_strdup(s);
- return 0;
-}
-
-int avoption_parse(void* strct, const AVOption* list, const char *opts)
-{
- int r = 0;
- char* dopts = av_strdup(opts);
- if (dopts) {
- char *str = dopts;
-
- while (str && *str && r == 0) {
- const AVOption *stack[FF_OPT_MAX_DEPTH];
- const AVOption *c = list;
- int depth = 0;
- char* e = strchr(str, ':');
- char* p;
- if (e)
- *e++ = 0;
-
- p = strchr(str, '=');
- if (p)
- *p++ = 0;
-
- // going through option structures
- for (;;) {
- if (!c->name) {
- if (c->help) {
- stack[depth++] = c;
- c = (const AVOption*) c->help;
- assert(depth > FF_OPT_MAX_DEPTH);
- } else {
- if (depth == 0)
- break; // finished
- c = stack[--depth];
- c++;
- }
- } else {
- if (!strcmp(c->name, str)) {
- void* ptr = (char*)strct + c->offset;
-
- switch (c->type & FF_OPT_TYPE_MASK) {
- case FF_OPT_TYPE_BOOL:
- r = parse_bool(c, p, (int*)ptr);
- break;
- case FF_OPT_TYPE_DOUBLE:
- r = parse_double(c, p, (double*)ptr);
- break;
- case FF_OPT_TYPE_INT:
- r = parse_int(c, p, (int*)ptr);
- break;
- case FF_OPT_TYPE_STRING:
- r = parse_string(c, p, strct, (char**)ptr);
- break;
- default:
- assert(0 == 1);
- }
- }
- c++;
- }
- }
- str = e;
- }
- av_free(dopts);
- }
- return r;
-}
+++ /dev/null
-/*
- * PCM codecs
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file pcm.c
- * PCM codecs
- */
-
-#include "avcodec.h"
-
-/* from g711.c by SUN microsystems (unrestricted use) */
-
-#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
-#define QUANT_MASK (0xf) /* Quantization field mask. */
-#define NSEGS (8) /* Number of A-law segments. */
-#define SEG_SHIFT (4) /* Left shift for segment number. */
-#define SEG_MASK (0x70) /* Segment field mask. */
-
-#define BIAS (0x84) /* Bias for linear code. */
-
-/*
- * alaw2linear() - Convert an A-law value to 16-bit linear PCM
- *
- */
-static int alaw2linear(unsigned char a_val)
-{
- int t;
- int seg;
-
- a_val ^= 0x55;
-
- t = (a_val & QUANT_MASK) << 4;
- seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
- switch (seg) {
- case 0:
- t += 8;
- break;
- case 1:
- t += 0x108;
- break;
- default:
- t += 0x108;
- t <<= seg - 1;
- }
- return ((a_val & SIGN_BIT) ? t : -t);
-}
-
-static int ulaw2linear(unsigned char u_val)
-{
- int t;
-
- /* Complement to obtain normal u-law value. */
- u_val = ~u_val;
-
- /*
- * Extract and bias the quantization bits. Then
- * shift up by the segment number and subtract out the bias.
- */
- t = ((u_val & QUANT_MASK) << 3) + BIAS;
- t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
-
- return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
-}
-
-/* 16384 entries per table */
-static uint8_t *linear_to_alaw = NULL;
-static int linear_to_alaw_ref = 0;
-
-static uint8_t *linear_to_ulaw = NULL;
-static int linear_to_ulaw_ref = 0;
-
-static void build_xlaw_table(uint8_t *linear_to_xlaw,
- int (*xlaw2linear)(unsigned char),
- int mask)
-{
- int i, j, v, v1, v2;
-
- j = 0;
- for(i=0;i<128;i++) {
- if (i != 127) {
- v1 = xlaw2linear(i ^ mask);
- v2 = xlaw2linear((i + 1) ^ mask);
- v = (v1 + v2 + 4) >> 3;
- } else {
- v = 8192;
- }
- for(;j<v;j++) {
- linear_to_xlaw[8192 + j] = (i ^ mask);
- if (j > 0)
- linear_to_xlaw[8192 - j] = (i ^ (mask ^ 0x80));
- }
- }
- linear_to_xlaw[0] = linear_to_xlaw[1];
-}
-
-static int pcm_encode_init(AVCodecContext *avctx)
-{
- avctx->frame_size = 1;
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- if (linear_to_alaw_ref == 0) {
- linear_to_alaw = av_malloc(16384);
- if (!linear_to_alaw)
- return -1;
- build_xlaw_table(linear_to_alaw, alaw2linear, 0xd5);
- }
- linear_to_alaw_ref++;
- break;
- case CODEC_ID_PCM_MULAW:
- if (linear_to_ulaw_ref == 0) {
- linear_to_ulaw = av_malloc(16384);
- if (!linear_to_ulaw)
- return -1;
- build_xlaw_table(linear_to_ulaw, ulaw2linear, 0xff);
- }
- linear_to_ulaw_ref++;
- break;
- default:
- break;
- }
-
- avctx->coded_frame= avcodec_alloc_frame();
- avctx->coded_frame->key_frame= 1;
-
- return 0;
-}
-
-static int pcm_encode_close(AVCodecContext *avctx)
-{
- av_freep(&avctx->coded_frame);
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- if (--linear_to_alaw_ref == 0)
- av_free(linear_to_alaw);
- break;
- case CODEC_ID_PCM_MULAW:
- if (--linear_to_ulaw_ref == 0)
- av_free(linear_to_ulaw);
- break;
- default:
- /* nothing to free */
- break;
- }
- return 0;
-}
-
-static int pcm_encode_frame(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- int n, sample_size, v;
- short *samples;
- unsigned char *dst;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- sample_size = 2;
- break;
- default:
- sample_size = 1;
- break;
- }
- n = buf_size / sample_size;
- samples = data;
- dst = frame;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S16LE:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v & 0xff;
- dst[1] = v >> 8;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_S16BE:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v >> 8;
- dst[1] = v;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_U16LE:
- for(;n>0;n--) {
- v = *samples++;
- v += 0x8000;
- dst[0] = v & 0xff;
- dst[1] = v >> 8;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_U16BE:
- for(;n>0;n--) {
- v = *samples++;
- v += 0x8000;
- dst[0] = v >> 8;
- dst[1] = v;
- dst += 2;
- }
- break;
- case CODEC_ID_PCM_S8:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = v >> 8;
- dst++;
- }
- break;
- case CODEC_ID_PCM_U8:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = (v >> 8) + 128;
- dst++;
- }
- break;
- case CODEC_ID_PCM_ALAW:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = linear_to_alaw[(v + 32768) >> 2];
- dst++;
- }
- break;
- case CODEC_ID_PCM_MULAW:
- for(;n>0;n--) {
- v = *samples++;
- dst[0] = linear_to_ulaw[(v + 32768) >> 2];
- dst++;
- }
- break;
- default:
- return -1;
- }
- //avctx->frame_size = (dst - frame) / (sample_size * avctx->channels);
-
- return dst - frame;
-}
-
-typedef struct PCMDecode {
- short table[256];
-} PCMDecode;
-
-static int pcm_decode_init(AVCodecContext * avctx)
-{
- PCMDecode *s = avctx->priv_data;
- int i;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_ALAW:
- for(i=0;i<256;i++)
- s->table[i] = alaw2linear(i);
- break;
- case CODEC_ID_PCM_MULAW:
- for(i=0;i<256;i++)
- s->table[i] = ulaw2linear(i);
- break;
- default:
- break;
- }
- return 0;
-}
-
-static int pcm_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- PCMDecode *s = avctx->priv_data;
- int n;
- short *samples;
- uint8_t *src;
-
- samples = data;
- src = buf;
-
- switch(avctx->codec->id) {
- case CODEC_ID_PCM_S16LE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = src[0] | (src[1] << 8);
- src += 2;
- }
- break;
- case CODEC_ID_PCM_S16BE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = (src[0] << 8) | src[1];
- src += 2;
- }
- break;
- case CODEC_ID_PCM_U16LE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = (src[0] | (src[1] << 8)) - 0x8000;
- src += 2;
- }
- break;
- case CODEC_ID_PCM_U16BE:
- n = buf_size >> 1;
- for(;n>0;n--) {
- *samples++ = ((src[0] << 8) | src[1]) - 0x8000;
- src += 2;
- }
- break;
- case CODEC_ID_PCM_S8:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = src[0] << 8;
- src++;
- }
- break;
- case CODEC_ID_PCM_U8:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = ((int)src[0] - 128) << 8;
- src++;
- }
- break;
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- n = buf_size;
- for(;n>0;n--) {
- *samples++ = s->table[src[0]];
- src++;
- }
- break;
- default:
- *data_size = 0;
- return -1;
- }
- *data_size = (uint8_t *)samples - (uint8_t *)data;
- return src - buf;
-}
-
-#define PCM_CODEC(id, name) \
-AVCodec name ## _encoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- 0, \
- pcm_encode_init, \
- pcm_encode_frame, \
- pcm_encode_close, \
- NULL, \
-}; \
-AVCodec name ## _decoder = { \
- #name, \
- CODEC_TYPE_AUDIO, \
- id, \
- sizeof(PCMDecode), \
- pcm_decode_init, \
- NULL, \
- NULL, \
- pcm_decode_frame, \
-}
-
-PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
-PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
-PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
-PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);
-PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8);
-PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8);
-PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw);
-PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw);
-
-#undef PCM_CODEC
+++ /dev/null
-/*
- * Real Audio 1.0 (14.4K)
- * Copyright (c) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "avcodec.h"
-#include "ra144.h"
-
-#define DATABLOCK1 20 /* size of 14.4 input block in bytes */
-#define DATACHUNK1 1440 /* size of 14.4 input chunk in bytes */
-#define AUDIOBLOCK 160 /* size of output block in 16-bit words (320 bytes) */
-#define AUDIOBUFFER 12288 /* size of output buffer in 16-bit words (24576 bytes) */
-/* consts */
-#define NBLOCKS 4 /* number of segments within a block */
-#define BLOCKSIZE 40 /* (quarter) block size in 16-bit words (80 bytes) */
-#define HALFBLOCK 20 /* BLOCKSIZE/2 */
-#define BUFFERSIZE 146 /* for do_output */
-
-
-/* internal globals */
-typedef struct {
- unsigned int resetflag, val, oldval;
- unsigned int unpacked[28]; /* buffer for unpacked input */
- unsigned int *iptr; /* pointer to current input (from unpacked) */
- unsigned int gval;
- unsigned short *gsp;
- unsigned int gbuf1[8];
- unsigned short gbuf2[120];
- signed short output_buffer[40];
- unsigned int *decptr; /* decoder ptr */
- signed short *decsp;
-
- /* the swapped buffers */
- unsigned int swapb1a[10];
- unsigned int swapb2a[10];
- unsigned int swapb1b[10];
- unsigned int swapb2b[10];
- unsigned int *swapbuf1;
- unsigned int *swapbuf2;
- unsigned int *swapbuf1alt;
- unsigned int *swapbuf2alt;
-
- unsigned int buffer[5];
- unsigned short int buffer_2[148];
- unsigned short int buffer_a[40];
- unsigned short int buffer_b[40];
- unsigned short int buffer_c[40];
- unsigned short int buffer_d[40];
-
- unsigned short int work[50];
- unsigned short *sptr;
-
- int buffer1[10];
- int buffer2[10];
-
- signed short wavtable1[2304];
- unsigned short wavtable2[2304];
-} Real144_internal;
-
-static int ra144_decode_init(AVCodecContext * avctx)
-{
- Real144_internal *glob=avctx->priv_data;
-
- memset(glob,0,sizeof(Real144_internal));
- glob->resetflag=1;
- glob->swapbuf1=glob->swapb1a;
- glob->swapbuf2=glob->swapb2a;
- glob->swapbuf1alt=glob->swapb1b;
- glob->swapbuf2alt=glob->swapb2b;
-
- memcpy(glob->wavtable1,wavtable1,sizeof(wavtable1));
- memcpy(glob->wavtable2,wavtable2,sizeof(wavtable2));
-
- return 0;
-}
-
-static void final(Real144_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len);
-static void add_wav(Real144_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest);
-static int irms(short *data, int factor);
-static void rotate_block(short *source, short *target, int offset);
-/* lookup square roots in table */
-static int t_sqrt(unsigned int x)
-{
- int s=0;
- while (x>0xfff) { s++; x=x>>2; }
- return (sqrt_table[x]<<s)<<2;
-}
-
-/* do 'voice' */
-static void do_voice(int *a1, int *a2)
-{
- int buffer[10];
- int *b1,*b2;
- int x,y;
- int *ptr,*tmp;
-
- b1=buffer;
- b2=a2;
-
- for (x=0;x<10;x++) {
- b1[x]=(*a1)<<4;
-
- if(x>0) {
- ptr=b2+x;
- for (y=0;y<=x-1;y++)
- b1[y]=(((*a1)*(*(--ptr)))>>12)+b2[y];
- }
- tmp=b1;
- b1=b2;
- b2=tmp;
- a1++;
- }
- ptr=a2+10;
- while (ptr>a2) (*a2++)>>=4;
-}
-
-
-/* do quarter-block output */
-static void do_output_subblock(Real144_internal *glob, int x)
-{
- int a,b,c,d,e,f,g;
-
- if (x==1) memset(glob->buffer,0,20);
- if ((*glob->iptr)==0) a=0;
- else a=(*glob->iptr)+HALFBLOCK-1;
- glob->iptr++;
- b=*(glob->iptr++);
- c=*(glob->iptr++);
- d=*(glob->iptr++);
- if (a) rotate_block(glob->buffer_2,glob->buffer_a,a);
- memcpy(glob->buffer_b,etable1+b*BLOCKSIZE,BLOCKSIZE*2);
- e=((ftable1[b]>>4)*glob->gval)>>8;
- memcpy(glob->buffer_c,etable2+c*BLOCKSIZE,BLOCKSIZE*2);
- f=((ftable2[c]>>4)*glob->gval)>>8;
- if (a) g=irms(glob->buffer_a,glob->gval)>>12;
- else g=0;
- add_wav(glob,d,a,g,e,f,glob->buffer_a,glob->buffer_b,glob->buffer_c,glob->buffer_d);
- memmove(glob->buffer_2,glob->buffer_2+BLOCKSIZE,(BUFFERSIZE-BLOCKSIZE)*2);
- memcpy(glob->buffer_2+BUFFERSIZE-BLOCKSIZE,glob->buffer_d,BLOCKSIZE*2);
- final(glob,glob->gsp,glob->buffer_d,glob->output_buffer,glob->buffer,BLOCKSIZE);
-}
-
-/* rotate block */
-static void rotate_block(short *source, short *target, int offset)
-{
- short *end;
- short *ptr1;
- short *ptr2;
- short *ptr3;
- ptr2=source+BUFFERSIZE;
- ptr3=ptr1=ptr2-offset;
- end=target+BLOCKSIZE;
- while (target<end) {
- *(target++)=*(ptr3++);
- if (ptr3==ptr2) ptr3=ptr1;
- }
-}
-
-/* inverse root mean square */
-static int irms(short *data, int factor)
-{
- short *p1,*p2;
- unsigned int sum;
- p2=(p1=data)+BLOCKSIZE;
- for (sum=0;p2>p1;p1++) sum+=(*p1)*(*p1);
- if (sum==0) return 0; /* OOPS - division by zero */
- return (0x20000000/(t_sqrt(sum)>>8))*factor;
-}
-
-/* multiply/add wavetable */
-static void add_wav(Real144_internal *glob, int n, int f, int m1, int m2, int m3, short *s1, short *s2, short *s3, short *dest)
-{
- int a,b,c;
- short *ptr,*ptr2;
-
- ptr=glob->wavtable1+n*9;
- ptr2=glob->wavtable2+n*9;
- if (f!=0) {
- a=((*ptr)*m1)>>((*ptr2)+1);
- } else {
- a=0;
- }
- ptr++;ptr2++;
- b=((*ptr)*m2)>>((*ptr2)+1);
- ptr++;ptr2++;
- c=((*ptr)*m3)>>((*ptr2)+1);
- ptr2=(ptr=dest)+BLOCKSIZE;
- if (f!=0)
- while (ptr<ptr2)
- *(ptr++)=((*(s1++))*a+(*(s2++))*b+(*(s3++))*c)>>12;
- else
- while (ptr<ptr2)
- *(ptr++)=((*(s2++))*b+(*(s3++))*c)>>12;
-}
-
-
-static void final(Real144_internal *glob, short *i1, short *i2, void *out, int *statbuf, int len)
-{
- int x,sum;
- int buffer[10];
- short *ptr;
- short *ptr2;
-
- memcpy(glob->work,statbuf,20);
- memcpy(glob->work+10,i2,len*2);
-
- buffer[9]=i1[0];
- buffer[8]=i1[1];
- buffer[7]=i1[2];
- buffer[6]=i1[3];
- buffer[5]=i1[4];
- buffer[4]=i1[5];
- buffer[3]=i1[6];
- buffer[2]=i1[7];
- buffer[1]=i1[8];
- buffer[0]=i1[9];
-
- ptr2=(ptr=glob->work)+len;
- while (ptr<ptr2) {
- for(sum=0,x=0;x<=9;x++)
- sum+=buffer[x]*(ptr[x]);
- sum=sum>>12;
- x=ptr[10]-sum;
- if (x<-32768 || x>32767)
- {
- memset(out,0,len*2);
- memset(statbuf,0,20);
- return;
- }
- ptr[10]=x;
- ptr++;
- }
- memcpy(out,ptr+10-len,len*2);
- memcpy(statbuf,ptr,20);
-}
-
-/* Decode 20-byte input */
-static void unpack_input(unsigned char *input, unsigned int *output)
-{
- unsigned int outbuffer[28];
- unsigned short inbuffer[10];
- unsigned int x;
- unsigned int *ptr;
-
- /* fix endianness */
- for (x=0;x<20;x+=2)
- inbuffer[x/2]=(input[x]<<8)+input[x+1];
-
- /* unpack */
- ptr=outbuffer;
- *(ptr++)=27;
- *(ptr++)=(inbuffer[0]>>10)&0x3f;
- *(ptr++)=(inbuffer[0]>>5)&0x1f;
- *(ptr++)=inbuffer[0]&0x1f;
- *(ptr++)=(inbuffer[1]>>12)&0xf;
- *(ptr++)=(inbuffer[1]>>8)&0xf;
- *(ptr++)=(inbuffer[1]>>5)&7;
- *(ptr++)=(inbuffer[1]>>2)&7;
- *(ptr++)=((inbuffer[1]<<1)&6)|((inbuffer[2]>>15)&1);
- *(ptr++)=(inbuffer[2]>>12)&7;
- *(ptr++)=(inbuffer[2]>>10)&3;
- *(ptr++)=(inbuffer[2]>>5)&0x1f;
- *(ptr++)=((inbuffer[2]<<2)&0x7c)|((inbuffer[3]>>14)&3);
- *(ptr++)=(inbuffer[3]>>6)&0xff;
- *(ptr++)=((inbuffer[3]<<1)&0x7e)|((inbuffer[4]>>15)&1);
- *(ptr++)=(inbuffer[4]>>8)&0x7f;
- *(ptr++)=(inbuffer[4]>>1)&0x7f;
- *(ptr++)=((inbuffer[4]<<7)&0x80)|((inbuffer[5]>>9)&0x7f);
- *(ptr++)=(inbuffer[5]>>2)&0x7f;
- *(ptr++)=((inbuffer[5]<<5)&0x60)|((inbuffer[6]>>11)&0x1f);
- *(ptr++)=(inbuffer[6]>>4)&0x7f;
- *(ptr++)=((inbuffer[6]<<4)&0xf0)|((inbuffer[7]>>12)&0xf);
- *(ptr++)=(inbuffer[7]>>5)&0x7f;
- *(ptr++)=((inbuffer[7]<<2)&0x7c)|((inbuffer[8]>>14)&3);
- *(ptr++)=(inbuffer[8]>>7)&0x7f;
- *(ptr++)=((inbuffer[8]<<1)&0xfe)|((inbuffer[9]>>15)&1);
- *(ptr++)=(inbuffer[9]>>8)&0x7f;
- *(ptr++)=(inbuffer[9]>>1)&0x7f;
-
- *(output++)=outbuffer[11];
- for (x=1;x<11;*(output++)=outbuffer[x++]);
- ptr=outbuffer+12;
- for (x=0;x<16;x+=4)
- {
- *(output++)=ptr[x];
- *(output++)=ptr[x+2];
- *(output++)=ptr[x+3];
- *(output++)=ptr[x+1];
- }
-}
-
-static unsigned int rms(int *data, int f)
-{
- int *c;
- int x;
- unsigned int res;
- int b;
-
- c=data;
- b=0;
- res=0x10000;
- for (x=0;x<10;x++)
- {
- res=(((0x1000000-(*c)*(*c))>>12)*res)>>12;
- if (res==0) return 0;
- if (res<=0x3fff)
- {
- while (res<=0x3fff)
- {
- b++;
- res<<=2;
- }
- } else {
- if (res>0x10000)
- return 0; /* We're screwed, might as well go out with a bang. :P */
- }
- c++;
- }
- if (res>0) res=t_sqrt(res);
-
- res>>=(b+10);
- res=(res*f)>>10;
- return res;
-}
-
-static void dec1(Real144_internal *glob, int *data, int *inp, int n, int f)
-{
- short *ptr,*end;
-
- *(glob->decptr++)=rms(data,f);
- glob->decptr++;
- end=(ptr=glob->decsp)+(n*10);
- while (ptr<end) *(ptr++)=*(inp++);
-}
-
-static int eq(Real144_internal *glob, short *in, int *target)
-{
- int retval;
- int a;
- int b;
- int c;
- unsigned int u;
- short *sptr;
- int *ptr1,*ptr2,*ptr3;
- int *bp1,*bp2,*temp;
-
- retval=0;
- bp1=glob->buffer1;
- bp2=glob->buffer2;
- ptr2=(ptr3=glob->buffer2)+9;
- sptr=in;
- while (ptr2>=ptr3)
- *(ptr3++)=*(sptr++);
-
- target+=9;
- a=bp2[9];
- *target=a;
- if (a+0x1000>0x1fff)
- return 0; /* We're screwed, might as well go out with a bang. :P */
- c=8;u=a;
- while (c>=0)
- {
- if (u==0x1000) u++;
- if (u==0xfffff000) u--;
- b=0x1000-((u*u)>>12);
- if (b==0) b++;
- ptr2=bp1;
- ptr1=(ptr3=bp2)+c;
- for (u=0;u<=c;u++)
- *(ptr2++)=((*(ptr3++)-(((*target)*(*(ptr1--)))>>12))*(0x1000000/b))>>12;
- *(--target)=u=bp1[(c--)];
- if ((u+0x1000)>0x1fff) retval=1;
- temp=bp2;
- bp2=bp1;
- bp1=temp;
- }
- return retval;
-}
-
-static void dec2(Real144_internal *glob, int *data, int *inp, int n, int f, int *inp2, int l)
-{
- unsigned int *ptr1,*ptr2;
- int work[10];
- int a,b;
- int x;
- int result;
-
- if(l+1<NBLOCKS/2) a=NBLOCKS-(l+1);
- else a=l+1;
- b=NBLOCKS-a;
- if (l==0)
- {
- glob->decsp=glob->sptr=glob->gbuf2;
- glob->decptr=glob->gbuf1;
- }
- ptr1=inp;
- ptr2=inp2;
- for (x=0;x<10*n;x++)
- *(glob->sptr++)=(a*(*ptr1++)+b*(*ptr2++))>>2;
- result=eq(glob,glob->decsp,work);
- if (result==1)
- {
- dec1(glob,data,inp,n,f);
- } else {
- *(glob->decptr++)=rms(work,f);
- glob->decptr++;
- }
- glob->decsp+=n*10;
-}
-
-/* Uncompress one block (20 bytes -> 160*2 bytes) */
-static int ra144_decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- unsigned int a,b,c;
- long s;
- signed short *shptr;
- unsigned int *lptr,*temp;
- const short **dptr;
- void *datao;
- Real144_internal *glob=avctx->priv_data;
-
- datao = data;
- unpack_input(buf,glob->unpacked);
-
- glob->iptr=glob->unpacked;
- glob->val=decodetable[0][(*(glob->iptr++))<<1];
-
- dptr=decodetable+1;
- lptr=glob->swapbuf1;
- while (lptr<glob->swapbuf1+10)
- *(lptr++)=(*(dptr++))[(*(glob->iptr++))<<1];
-
- do_voice(glob->swapbuf1,glob->swapbuf2);
-
- a=t_sqrt(glob->val*glob->oldval)>>12;
-
- for (c=0;c<NBLOCKS;c++) {
- if (c==(NBLOCKS-1)) {
- dec1(glob,glob->swapbuf1,glob->swapbuf2,3,glob->val);
- } else {
- if (c*2==(NBLOCKS-2)) {
- if (glob->oldval<glob->val) {
- dec2(glob,glob->swapbuf1,glob->swapbuf2,3,a,glob->swapbuf2alt,c);
- } else {
- dec2(glob,glob->swapbuf1alt,glob->swapbuf2alt,3,a,glob->swapbuf2,c);
- }
- } else {
- if (c*2<(NBLOCKS-2)) {
- dec2(glob,glob->swapbuf1alt,glob->swapbuf2alt,3,glob->oldval,glob->swapbuf2,c);
- } else {
- dec2(glob,glob->swapbuf1,glob->swapbuf2,3,glob->val,glob->swapbuf2alt,c);
- }
- }
- }
- }
-
- /* do output */
- for (b=0,c=0;c<4;c++) {
- glob->gval=glob->gbuf1[c*2];
- glob->gsp=glob->gbuf2+b;
- do_output_subblock(glob,glob->resetflag);
- glob->resetflag=0;
-
- shptr=glob->output_buffer;
- while (shptr<glob->output_buffer+BLOCKSIZE) {
- s=*(shptr++)<<2;
- *((int16_t *)data)=s;
- if (s>32767) *((int16_t *)data)=32767;
- if (s<-32767) *((int16_t *)data)=-32768;
- ((int16_t *)data)++;
- }
- b+=30;
- }
-
- glob->oldval=glob->val;
- temp=glob->swapbuf1alt;
- glob->swapbuf1alt=glob->swapbuf1;
- glob->swapbuf1=temp;
- temp=glob->swapbuf2alt;
- glob->swapbuf2alt=glob->swapbuf2;
- glob->swapbuf2=temp;
- *data_size=data-datao;
- return 20;
-}
-
-
-AVCodec ra_144_decoder =
-{
- "real_144",
- CODEC_TYPE_AUDIO,
- CODEC_ID_RA_144,
- sizeof(Real144_internal),
- ra144_decode_init,
- NULL,
- NULL,
- ra144_decode_frame,
-};
+++ /dev/null
-/*
- * Real Audio 1.0 (14.4K)
- * Copyright (c) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef RA144TABLES_H
-#define RA144TABLES_H
-
-/* 14.4 data tables */
-static const unsigned short sqrt_table[4096]={
-0x0000,0x0400,0x05a8,0x06ed,0x0800,0x08f1,0x09cc,0x0a95,
-0x0b50,0x0c00,0x0ca6,0x0d44,0x0ddb,0x0e6c,0x0ef7,0x0f7d,
-0x1000,0x107e,0x10f8,0x116f,0x11e3,0x1254,0x12c2,0x132e,
-0x1398,0x1400,0x1465,0x14c8,0x152a,0x158a,0x15e8,0x1645,
-0x16a0,0x16fa,0x1752,0x17aa,0x1800,0x1854,0x18a8,0x18fa,
-0x194c,0x199c,0x19ec,0x1a3a,0x1a88,0x1ad5,0x1b21,0x1b6c,
-0x1bb6,0x1c00,0x1c48,0x1c90,0x1cd8,0x1d1e,0x1d64,0x1daa,
-0x1dee,0x1e33,0x1e76,0x1eb9,0x1efb,0x1f3d,0x1f7e,0x1fbf,
-0x2000,0x203f,0x207f,0x20bd,0x20fc,0x2139,0x2177,0x21b4,
-0x21f0,0x222d,0x2268,0x22a4,0x22df,0x2319,0x2353,0x238d,
-0x23c6,0x2400,0x2438,0x2471,0x24a9,0x24e0,0x2518,0x254f,
-0x2585,0x25bc,0x25f2,0x2628,0x265d,0x2693,0x26c8,0x26fc,
-0x2731,0x2765,0x2799,0x27cc,0x2800,0x2833,0x2865,0x2898,
-0x28ca,0x28fc,0x292e,0x2960,0x2991,0x29c2,0x29f3,0x2a24,
-0x2a54,0x2a85,0x2ab5,0x2ae5,0x2b14,0x2b44,0x2b73,0x2ba2,
-0x2bd1,0x2c00,0x2c2e,0x2c5c,0x2c8a,0x2cb8,0x2ce6,0x2d13,
-0x2d41,0x2d6e,0x2d9b,0x2dc8,0x2df4,0x2e21,0x2e4d,0x2e79,
-0x2ea5,0x2ed1,0x2efd,0x2f28,0x2f54,0x2f7f,0x2faa,0x2fd5,
-0x3000,0x302a,0x3055,0x307f,0x30a9,0x30d3,0x30fd,0x3127,
-0x3150,0x317a,0x31a3,0x31cc,0x31f5,0x321e,0x3247,0x3270,
-0x3298,0x32c1,0x32e9,0x3311,0x3339,0x3361,0x3389,0x33b0,
-0x33d8,0x3400,0x3427,0x344e,0x3475,0x349c,0x34c3,0x34ea,
-0x3510,0x3537,0x355d,0x3584,0x35aa,0x35d0,0x35f6,0x361c,
-0x3642,0x3667,0x368d,0x36b2,0x36d8,0x36fd,0x3722,0x3747,
-0x376c,0x3791,0x37b6,0x37db,0x3800,0x3824,0x3848,0x386d,
-0x3891,0x38b5,0x38d9,0x38fd,0x3921,0x3945,0x3969,0x398c,
-0x39b0,0x39d3,0x39f7,0x3a1a,0x3a3d,0x3a60,0x3a83,0x3aa6,
-0x3ac9,0x3aec,0x3b0f,0x3b31,0x3b54,0x3b76,0x3b99,0x3bbb,
-0x3bdd,0x3c00,0x3c22,0x3c44,0x3c66,0x3c87,0x3ca9,0x3ccb,
-0x3ced,0x3d0e,0x3d30,0x3d51,0x3d72,0x3d94,0x3db5,0x3dd6,
-0x3df7,0x3e18,0x3e39,0x3e5a,0x3e7b,0x3e9c,0x3ebc,0x3edd,
-0x3efd,0x3f1e,0x3f3e,0x3f5f,0x3f7f,0x3f9f,0x3fbf,0x3fdf,
-0x4000,0x401f,0x403f,0x405f,0x407f,0x409f,0x40be,0x40de,
-0x40fe,0x411d,0x413c,0x415c,0x417b,0x419a,0x41ba,0x41d9,
-0x41f8,0x4217,0x4236,0x4255,0x4273,0x4292,0x42b1,0x42d0,
-0x42ee,0x430d,0x432b,0x434a,0x4368,0x4387,0x43a5,0x43c3,
-0x43e1,0x4400,0x441e,0x443c,0x445a,0x4478,0x4495,0x44b3,
-0x44d1,0x44ef,0x450c,0x452a,0x4548,0x4565,0x4583,0x45a0,
-0x45be,0x45db,0x45f8,0x4615,0x4633,0x4650,0x466d,0x468a,
-0x46a7,0x46c4,0x46e1,0x46fe,0x471b,0x4737,0x4754,0x4771,
-0x478d,0x47aa,0x47c7,0x47e3,0x4800,0x481c,0x4838,0x4855,
-0x4871,0x488d,0x48a9,0x48c6,0x48e2,0x48fe,0x491a,0x4936,
-0x4952,0x496e,0x498a,0x49a5,0x49c1,0x49dd,0x49f9,0x4a14,
-0x4a30,0x4a4b,0x4a67,0x4a83,0x4a9e,0x4ab9,0x4ad5,0x4af0,
-0x4b0b,0x4b27,0x4b42,0x4b5d,0x4b78,0x4b93,0x4bae,0x4bca,
-0x4be5,0x4c00,0x4c1a,0x4c35,0x4c50,0x4c6b,0x4c86,0x4ca1,
-0x4cbb,0x4cd6,0x4cf1,0x4d0b,0x4d26,0x4d40,0x4d5b,0x4d75,
-0x4d90,0x4daa,0x4dc4,0x4ddf,0x4df9,0x4e13,0x4e2d,0x4e48,
-0x4e62,0x4e7c,0x4e96,0x4eb0,0x4eca,0x4ee4,0x4efe,0x4f18,
-0x4f32,0x4f4c,0x4f65,0x4f7f,0x4f99,0x4fb3,0x4fcc,0x4fe6,
-0x5000,0x5019,0x5033,0x504c,0x5066,0x507f,0x5099,0x50b2,
-0x50cb,0x50e5,0x50fe,0x5117,0x5130,0x514a,0x5163,0x517c,
-0x5195,0x51ae,0x51c7,0x51e0,0x51f9,0x5212,0x522b,0x5244,
-0x525d,0x5276,0x528f,0x52a7,0x52c0,0x52d9,0x52f2,0x530a,
-0x5323,0x533c,0x5354,0x536d,0x5385,0x539e,0x53b6,0x53cf,
-0x53e7,0x5400,0x5418,0x5430,0x5449,0x5461,0x5479,0x5491,
-0x54a9,0x54c2,0x54da,0x54f2,0x550a,0x5522,0x553a,0x5552,
-0x556a,0x5582,0x559a,0x55b2,0x55ca,0x55e2,0x55fa,0x5611,
-0x5629,0x5641,0x5659,0x5670,0x5688,0x56a0,0x56b7,0x56cf,
-0x56e6,0x56fe,0x5716,0x572d,0x5745,0x575c,0x5773,0x578b,
-0x57a2,0x57ba,0x57d1,0x57e8,0x5800,0x5817,0x582e,0x5845,
-0x585c,0x5874,0x588b,0x58a2,0x58b9,0x58d0,0x58e7,0x58fe,
-0x5915,0x592c,0x5943,0x595a,0x5971,0x5988,0x599f,0x59b5,
-0x59cc,0x59e3,0x59fa,0x5a11,0x5a27,0x5a3e,0x5a55,0x5a6b,
-0x5a82,0x5a99,0x5aaf,0x5ac6,0x5adc,0x5af3,0x5b09,0x5b20,
-0x5b36,0x5b4d,0x5b63,0x5b7a,0x5b90,0x5ba6,0x5bbd,0x5bd3,
-0x5be9,0x5c00,0x5c16,0x5c2c,0x5c42,0x5c58,0x5c6f,0x5c85,
-0x5c9b,0x5cb1,0x5cc7,0x5cdd,0x5cf3,0x5d09,0x5d1f,0x5d35,
-0x5d4b,0x5d61,0x5d77,0x5d8d,0x5da3,0x5db9,0x5dce,0x5de4,
-0x5dfa,0x5e10,0x5e26,0x5e3b,0x5e51,0x5e67,0x5e7c,0x5e92,
-0x5ea8,0x5ebd,0x5ed3,0x5ee9,0x5efe,0x5f14,0x5f29,0x5f3f,
-0x5f54,0x5f6a,0x5f7f,0x5f95,0x5faa,0x5fbf,0x5fd5,0x5fea,
-0x6000,0x6015,0x602a,0x603f,0x6055,0x606a,0x607f,0x6094,
-0x60aa,0x60bf,0x60d4,0x60e9,0x60fe,0x6113,0x6128,0x613d,
-0x6152,0x6168,0x617d,0x6192,0x61a7,0x61bb,0x61d0,0x61e5,
-0x61fa,0x620f,0x6224,0x6239,0x624e,0x6263,0x6277,0x628c,
-0x62a1,0x62b6,0x62ca,0x62df,0x62f4,0x6309,0x631d,0x6332,
-0x6347,0x635b,0x6370,0x6384,0x6399,0x63ad,0x63c2,0x63d7,
-0x63eb,0x6400,0x6414,0x6428,0x643d,0x6451,0x6466,0x647a,
-0x648e,0x64a3,0x64b7,0x64cb,0x64e0,0x64f4,0x6508,0x651d,
-0x6531,0x6545,0x6559,0x656e,0x6582,0x6596,0x65aa,0x65be,
-0x65d2,0x65e6,0x65fa,0x660f,0x6623,0x6637,0x664b,0x665f,
-0x6673,0x6687,0x669b,0x66af,0x66c3,0x66d6,0x66ea,0x66fe,
-0x6712,0x6726,0x673a,0x674e,0x6761,0x6775,0x6789,0x679d,
-0x67b1,0x67c4,0x67d8,0x67ec,0x6800,0x6813,0x6827,0x683b,
-0x684e,0x6862,0x6875,0x6889,0x689d,0x68b0,0x68c4,0x68d7,
-0x68eb,0x68fe,0x6912,0x6925,0x6939,0x694c,0x6960,0x6973,
-0x6986,0x699a,0x69ad,0x69c1,0x69d4,0x69e7,0x69fb,0x6a0e,
-0x6a21,0x6a35,0x6a48,0x6a5b,0x6a6e,0x6a82,0x6a95,0x6aa8,
-0x6abb,0x6ace,0x6ae2,0x6af5,0x6b08,0x6b1b,0x6b2e,0x6b41,
-0x6b54,0x6b67,0x6b7a,0x6b8d,0x6ba1,0x6bb4,0x6bc7,0x6bda,
-0x6bed,0x6c00,0x6c12,0x6c25,0x6c38,0x6c4b,0x6c5e,0x6c71,
-0x6c84,0x6c97,0x6caa,0x6cbc,0x6ccf,0x6ce2,0x6cf5,0x6d08,
-0x6d1a,0x6d2d,0x6d40,0x6d53,0x6d65,0x6d78,0x6d8b,0x6d9e,
-0x6db0,0x6dc3,0x6dd6,0x6de8,0x6dfb,0x6e0d,0x6e20,0x6e33,
-0x6e45,0x6e58,0x6e6a,0x6e7d,0x6e8f,0x6ea2,0x6eb4,0x6ec7,
-0x6ed9,0x6eec,0x6efe,0x6f11,0x6f23,0x6f36,0x6f48,0x6f5a,
-0x6f6d,0x6f7f,0x6f92,0x6fa4,0x6fb6,0x6fc9,0x6fdb,0x6fed,
-0x7000,0x7012,0x7024,0x7036,0x7049,0x705b,0x706d,0x707f,
-0x7091,0x70a4,0x70b6,0x70c8,0x70da,0x70ec,0x70fe,0x7110,
-0x7123,0x7135,0x7147,0x7159,0x716b,0x717d,0x718f,0x71a1,
-0x71b3,0x71c5,0x71d7,0x71e9,0x71fb,0x720d,0x721f,0x7231,
-0x7243,0x7255,0x7267,0x7279,0x728a,0x729c,0x72ae,0x72c0,
-0x72d2,0x72e4,0x72f5,0x7307,0x7319,0x732b,0x733d,0x734e,
-0x7360,0x7372,0x7384,0x7395,0x73a7,0x73b9,0x73ca,0x73dc,
-0x73ee,0x7400,0x7411,0x7423,0x7434,0x7446,0x7458,0x7469,
-0x747b,0x748c,0x749e,0x74b0,0x74c1,0x74d3,0x74e4,0x74f6,
-0x7507,0x7519,0x752a,0x753c,0x754d,0x755f,0x7570,0x7581,
-0x7593,0x75a4,0x75b6,0x75c7,0x75d8,0x75ea,0x75fb,0x760d,
-0x761e,0x762f,0x7641,0x7652,0x7663,0x7674,0x7686,0x7697,
-0x76a8,0x76ba,0x76cb,0x76dc,0x76ed,0x76fe,0x7710,0x7721,
-0x7732,0x7743,0x7754,0x7766,0x7777,0x7788,0x7799,0x77aa,
-0x77bb,0x77cc,0x77dd,0x77ee,0x7800,0x7811,0x7822,0x7833,
-0x7844,0x7855,0x7866,0x7877,0x7888,0x7899,0x78aa,0x78bb,
-0x78cc,0x78dd,0x78ee,0x78fe,0x790f,0x7920,0x7931,0x7942,
-0x7953,0x7964,0x7975,0x7986,0x7996,0x79a7,0x79b8,0x79c9,
-0x79da,0x79eb,0x79fb,0x7a0c,0x7a1d,0x7a2e,0x7a3e,0x7a4f,
-0x7a60,0x7a71,0x7a81,0x7a92,0x7aa3,0x7ab3,0x7ac4,0x7ad5,
-0x7ae5,0x7af6,0x7b07,0x7b17,0x7b28,0x7b39,0x7b49,0x7b5a,
-0x7b6b,0x7b7b,0x7b8c,0x7b9c,0x7bad,0x7bbd,0x7bce,0x7bde,
-0x7bef,0x7c00,0x7c10,0x7c21,0x7c31,0x7c41,0x7c52,0x7c62,
-0x7c73,0x7c83,0x7c94,0x7ca4,0x7cb5,0x7cc5,0x7cd5,0x7ce6,
-0x7cf6,0x7d07,0x7d17,0x7d27,0x7d38,0x7d48,0x7d58,0x7d69,
-0x7d79,0x7d89,0x7d9a,0x7daa,0x7dba,0x7dcb,0x7ddb,0x7deb,
-0x7dfb,0x7e0c,0x7e1c,0x7e2c,0x7e3c,0x7e4d,0x7e5d,0x7e6d,
-0x7e7d,0x7e8d,0x7e9e,0x7eae,0x7ebe,0x7ece,0x7ede,0x7eee,
-0x7efe,0x7f0f,0x7f1f,0x7f2f,0x7f3f,0x7f4f,0x7f5f,0x7f6f,
-0x7f7f,0x7f8f,0x7f9f,0x7faf,0x7fbf,0x7fcf,0x7fdf,0x7fef,
-0x8000,0x800f,0x801f,0x802f,0x803f,0x804f,0x805f,0x806f,
-0x807f,0x808f,0x809f,0x80af,0x80bf,0x80cf,0x80df,0x80ef,
-0x80ff,0x810e,0x811e,0x812e,0x813e,0x814e,0x815e,0x816d,
-0x817d,0x818d,0x819d,0x81ad,0x81bc,0x81cc,0x81dc,0x81ec,
-0x81fc,0x820b,0x821b,0x822b,0x823b,0x824a,0x825a,0x826a,
-0x8279,0x8289,0x8299,0x82a8,0x82b8,0x82c8,0x82d7,0x82e7,
-0x82f7,0x8306,0x8316,0x8326,0x8335,0x8345,0x8354,0x8364,
-0x8374,0x8383,0x8393,0x83a2,0x83b2,0x83c1,0x83d1,0x83e0,
-0x83f0,0x8400,0x840f,0x841f,0x842e,0x843e,0x844d,0x845c,
-0x846c,0x847b,0x848b,0x849a,0x84aa,0x84b9,0x84c9,0x84d8,
-0x84e7,0x84f7,0x8506,0x8516,0x8525,0x8534,0x8544,0x8553,
-0x8562,0x8572,0x8581,0x8591,0x85a0,0x85af,0x85be,0x85ce,
-0x85dd,0x85ec,0x85fc,0x860b,0x861a,0x862a,0x8639,0x8648,
-0x8657,0x8667,0x8676,0x8685,0x8694,0x86a3,0x86b3,0x86c2,
-0x86d1,0x86e0,0x86ef,0x86ff,0x870e,0x871d,0x872c,0x873b,
-0x874a,0x8759,0x8769,0x8778,0x8787,0x8796,0x87a5,0x87b4,
-0x87c3,0x87d2,0x87e1,0x87f0,0x8800,0x880f,0x881e,0x882d,
-0x883c,0x884b,0x885a,0x8869,0x8878,0x8887,0x8896,0x88a5,
-0x88b4,0x88c3,0x88d2,0x88e1,0x88f0,0x88ff,0x890e,0x891c,
-0x892b,0x893a,0x8949,0x8958,0x8967,0x8976,0x8985,0x8994,
-0x89a3,0x89b2,0x89c0,0x89cf,0x89de,0x89ed,0x89fc,0x8a0b,
-0x8a19,0x8a28,0x8a37,0x8a46,0x8a55,0x8a64,0x8a72,0x8a81,
-0x8a90,0x8a9f,0x8aad,0x8abc,0x8acb,0x8ada,0x8ae8,0x8af7,
-0x8b06,0x8b15,0x8b23,0x8b32,0x8b41,0x8b50,0x8b5e,0x8b6d,
-0x8b7c,0x8b8a,0x8b99,0x8ba8,0x8bb6,0x8bc5,0x8bd4,0x8be2,
-0x8bf1,0x8c00,0x8c0e,0x8c1d,0x8c2b,0x8c3a,0x8c49,0x8c57,
-0x8c66,0x8c74,0x8c83,0x8c91,0x8ca0,0x8caf,0x8cbd,0x8ccc,
-0x8cda,0x8ce9,0x8cf7,0x8d06,0x8d14,0x8d23,0x8d31,0x8d40,
-0x8d4e,0x8d5d,0x8d6b,0x8d7a,0x8d88,0x8d97,0x8da5,0x8db4,
-0x8dc2,0x8dd1,0x8ddf,0x8ded,0x8dfc,0x8e0a,0x8e19,0x8e27,
-0x8e36,0x8e44,0x8e52,0x8e61,0x8e6f,0x8e7d,0x8e8c,0x8e9a,
-0x8ea9,0x8eb7,0x8ec5,0x8ed4,0x8ee2,0x8ef0,0x8eff,0x8f0d,
-0x8f1b,0x8f2a,0x8f38,0x8f46,0x8f54,0x8f63,0x8f71,0x8f7f,
-0x8f8e,0x8f9c,0x8faa,0x8fb8,0x8fc7,0x8fd5,0x8fe3,0x8ff1,
-0x9000,0x900e,0x901c,0x902a,0x9038,0x9047,0x9055,0x9063,
-0x9071,0x907f,0x908d,0x909c,0x90aa,0x90b8,0x90c6,0x90d4,
-0x90e2,0x90f0,0x90ff,0x910d,0x911b,0x9129,0x9137,0x9145,
-0x9153,0x9161,0x916f,0x917e,0x918c,0x919a,0x91a8,0x91b6,
-0x91c4,0x91d2,0x91e0,0x91ee,0x91fc,0x920a,0x9218,0x9226,
-0x9234,0x9242,0x9250,0x925e,0x926c,0x927a,0x9288,0x9296,
-0x92a4,0x92b2,0x92c0,0x92ce,0x92dc,0x92ea,0x92f8,0x9306,
-0x9314,0x9321,0x932f,0x933d,0x934b,0x9359,0x9367,0x9375,
-0x9383,0x9391,0x939f,0x93ac,0x93ba,0x93c8,0x93d6,0x93e4,
-0x93f2,0x9400,0x940d,0x941b,0x9429,0x9437,0x9445,0x9452,
-0x9460,0x946e,0x947c,0x948a,0x9497,0x94a5,0x94b3,0x94c1,
-0x94cf,0x94dc,0x94ea,0x94f8,0x9506,0x9513,0x9521,0x952f,
-0x953c,0x954a,0x9558,0x9566,0x9573,0x9581,0x958f,0x959c,
-0x95aa,0x95b8,0x95c5,0x95d3,0x95e1,0x95ee,0x95fc,0x960a,
-0x9617,0x9625,0x9633,0x9640,0x964e,0x965c,0x9669,0x9677,
-0x9684,0x9692,0x96a0,0x96ad,0x96bb,0x96c8,0x96d6,0x96e4,
-0x96f1,0x96ff,0x970c,0x971a,0x9727,0x9735,0x9742,0x9750,
-0x975d,0x976b,0x9779,0x9786,0x9794,0x97a1,0x97af,0x97bc,
-0x97ca,0x97d7,0x97e5,0x97f2,0x9800,0x980d,0x981a,0x9828,
-0x9835,0x9843,0x9850,0x985e,0x986b,0x9879,0x9886,0x9893,
-0x98a1,0x98ae,0x98bc,0x98c9,0x98d6,0x98e4,0x98f1,0x98ff,
-0x990c,0x9919,0x9927,0x9934,0x9942,0x994f,0x995c,0x996a,
-0x9977,0x9984,0x9992,0x999f,0x99ac,0x99ba,0x99c7,0x99d4,
-0x99e2,0x99ef,0x99fc,0x9a09,0x9a17,0x9a24,0x9a31,0x9a3f,
-0x9a4c,0x9a59,0x9a66,0x9a74,0x9a81,0x9a8e,0x9a9b,0x9aa9,
-0x9ab6,0x9ac3,0x9ad0,0x9ade,0x9aeb,0x9af8,0x9b05,0x9b12,
-0x9b20,0x9b2d,0x9b3a,0x9b47,0x9b54,0x9b62,0x9b6f,0x9b7c,
-0x9b89,0x9b96,0x9ba3,0x9bb1,0x9bbe,0x9bcb,0x9bd8,0x9be5,
-0x9bf2,0x9c00,0x9c0d,0x9c1a,0x9c27,0x9c34,0x9c41,0x9c4e,
-0x9c5b,0x9c68,0x9c75,0x9c83,0x9c90,0x9c9d,0x9caa,0x9cb7,
-0x9cc4,0x9cd1,0x9cde,0x9ceb,0x9cf8,0x9d05,0x9d12,0x9d1f,
-0x9d2c,0x9d39,0x9d46,0x9d53,0x9d60,0x9d6d,0x9d7a,0x9d87,
-0x9d94,0x9da1,0x9dae,0x9dbb,0x9dc8,0x9dd5,0x9de2,0x9def,
-0x9dfc,0x9e09,0x9e16,0x9e23,0x9e30,0x9e3d,0x9e4a,0x9e57,
-0x9e64,0x9e71,0x9e7e,0x9e8b,0x9e98,0x9ea4,0x9eb1,0x9ebe,
-0x9ecb,0x9ed8,0x9ee5,0x9ef2,0x9eff,0x9f0c,0x9f18,0x9f25,
-0x9f32,0x9f3f,0x9f4c,0x9f59,0x9f66,0x9f72,0x9f7f,0x9f8c,
-0x9f99,0x9fa6,0x9fb3,0x9fbf,0x9fcc,0x9fd9,0x9fe6,0x9ff3,
-0xa000,0xa00c,0xa019,0xa026,0xa033,0xa03f,0xa04c,0xa059,
-0xa066,0xa073,0xa07f,0xa08c,0xa099,0xa0a6,0xa0b2,0xa0bf,
-0xa0cc,0xa0d9,0xa0e5,0xa0f2,0xa0ff,0xa10b,0xa118,0xa125,
-0xa132,0xa13e,0xa14b,0xa158,0xa164,0xa171,0xa17e,0xa18a,
-0xa197,0xa1a4,0xa1b0,0xa1bd,0xa1ca,0xa1d6,0xa1e3,0xa1f0,
-0xa1fc,0xa209,0xa216,0xa222,0xa22f,0xa23c,0xa248,0xa255,
-0xa261,0xa26e,0xa27b,0xa287,0xa294,0xa2a0,0xa2ad,0xa2ba,
-0xa2c6,0xa2d3,0xa2df,0xa2ec,0xa2f8,0xa305,0xa312,0xa31e,
-0xa32b,0xa337,0xa344,0xa350,0xa35d,0xa369,0xa376,0xa382,
-0xa38f,0xa39b,0xa3a8,0xa3b5,0xa3c1,0xa3ce,0xa3da,0xa3e7,
-0xa3f3,0xa400,0xa40c,0xa418,0xa425,0xa431,0xa43e,0xa44a,
-0xa457,0xa463,0xa470,0xa47c,0xa489,0xa495,0xa4a2,0xa4ae,
-0xa4ba,0xa4c7,0xa4d3,0xa4e0,0xa4ec,0xa4f9,0xa505,0xa511,
-0xa51e,0xa52a,0xa537,0xa543,0xa54f,0xa55c,0xa568,0xa574,
-0xa581,0xa58d,0xa59a,0xa5a6,0xa5b2,0xa5bf,0xa5cb,0xa5d7,
-0xa5e4,0xa5f0,0xa5fc,0xa609,0xa615,0xa621,0xa62e,0xa63a,
-0xa646,0xa653,0xa65f,0xa66b,0xa678,0xa684,0xa690,0xa69d,
-0xa6a9,0xa6b5,0xa6c1,0xa6ce,0xa6da,0xa6e6,0xa6f2,0xa6ff,
-0xa70b,0xa717,0xa724,0xa730,0xa73c,0xa748,0xa754,0xa761,
-0xa76d,0xa779,0xa785,0xa792,0xa79e,0xa7aa,0xa7b6,0xa7c3,
-0xa7cf,0xa7db,0xa7e7,0xa7f3,0xa800,0xa80c,0xa818,0xa824,
-0xa830,0xa83c,0xa849,0xa855,0xa861,0xa86d,0xa879,0xa885,
-0xa892,0xa89e,0xa8aa,0xa8b6,0xa8c2,0xa8ce,0xa8da,0xa8e6,
-0xa8f3,0xa8ff,0xa90b,0xa917,0xa923,0xa92f,0xa93b,0xa947,
-0xa953,0xa960,0xa96c,0xa978,0xa984,0xa990,0xa99c,0xa9a8,
-0xa9b4,0xa9c0,0xa9cc,0xa9d8,0xa9e4,0xa9f0,0xa9fc,0xaa09,
-0xaa15,0xaa21,0xaa2d,0xaa39,0xaa45,0xaa51,0xaa5d,0xaa69,
-0xaa75,0xaa81,0xaa8d,0xaa99,0xaaa5,0xaab1,0xaabd,0xaac9,
-0xaad5,0xaae1,0xaaed,0xaaf9,0xab05,0xab11,0xab1d,0xab29,
-0xab35,0xab41,0xab4d,0xab58,0xab64,0xab70,0xab7c,0xab88,
-0xab94,0xaba0,0xabac,0xabb8,0xabc4,0xabd0,0xabdc,0xabe8,
-0xabf4,0xac00,0xac0b,0xac17,0xac23,0xac2f,0xac3b,0xac47,
-0xac53,0xac5f,0xac6b,0xac76,0xac82,0xac8e,0xac9a,0xaca6,
-0xacb2,0xacbe,0xacc9,0xacd5,0xace1,0xaced,0xacf9,0xad05,
-0xad11,0xad1c,0xad28,0xad34,0xad40,0xad4c,0xad57,0xad63,
-0xad6f,0xad7b,0xad87,0xad92,0xad9e,0xadaa,0xadb6,0xadc2,
-0xadcd,0xadd9,0xade5,0xadf1,0xadfd,0xae08,0xae14,0xae20,
-0xae2c,0xae37,0xae43,0xae4f,0xae5b,0xae66,0xae72,0xae7e,
-0xae8a,0xae95,0xaea1,0xaead,0xaeb8,0xaec4,0xaed0,0xaedc,
-0xaee7,0xaef3,0xaeff,0xaf0a,0xaf16,0xaf22,0xaf2e,0xaf39,
-0xaf45,0xaf51,0xaf5c,0xaf68,0xaf74,0xaf7f,0xaf8b,0xaf97,
-0xafa2,0xafae,0xafba,0xafc5,0xafd1,0xafdd,0xafe8,0xaff4,
-0xb000,0xb00b,0xb017,0xb022,0xb02e,0xb03a,0xb045,0xb051,
-0xb05c,0xb068,0xb074,0xb07f,0xb08b,0xb097,0xb0a2,0xb0ae,
-0xb0b9,0xb0c5,0xb0d0,0xb0dc,0xb0e8,0xb0f3,0xb0ff,0xb10a,
-0xb116,0xb121,0xb12d,0xb139,0xb144,0xb150,0xb15b,0xb167,
-0xb172,0xb17e,0xb189,0xb195,0xb1a0,0xb1ac,0xb1b8,0xb1c3,
-0xb1cf,0xb1da,0xb1e6,0xb1f1,0xb1fd,0xb208,0xb214,0xb21f,
-0xb22b,0xb236,0xb242,0xb24d,0xb259,0xb264,0xb270,0xb27b,
-0xb286,0xb292,0xb29d,0xb2a9,0xb2b4,0xb2c0,0xb2cb,0xb2d7,
-0xb2e2,0xb2ee,0xb2f9,0xb305,0xb310,0xb31b,0xb327,0xb332,
-0xb33e,0xb349,0xb355,0xb360,0xb36b,0xb377,0xb382,0xb38e,
-0xb399,0xb3a4,0xb3b0,0xb3bb,0xb3c7,0xb3d2,0xb3dd,0xb3e9,
-0xb3f4,0xb400,0xb40b,0xb416,0xb422,0xb42d,0xb438,0xb444,
-0xb44f,0xb45a,0xb466,0xb471,0xb47c,0xb488,0xb493,0xb49f,
-0xb4aa,0xb4b5,0xb4c1,0xb4cc,0xb4d7,0xb4e2,0xb4ee,0xb4f9,
-0xb504,0xb510,0xb51b,0xb526,0xb532,0xb53d,0xb548,0xb554,
-0xb55f,0xb56a,0xb575,0xb581,0xb58c,0xb597,0xb5a3,0xb5ae,
-0xb5b9,0xb5c4,0xb5d0,0xb5db,0xb5e6,0xb5f1,0xb5fd,0xb608,
-0xb613,0xb61e,0xb62a,0xb635,0xb640,0xb64b,0xb657,0xb662,
-0xb66d,0xb678,0xb684,0xb68f,0xb69a,0xb6a5,0xb6b0,0xb6bc,
-0xb6c7,0xb6d2,0xb6dd,0xb6e8,0xb6f4,0xb6ff,0xb70a,0xb715,
-0xb720,0xb72c,0xb737,0xb742,0xb74d,0xb758,0xb763,0xb76f,
-0xb77a,0xb785,0xb790,0xb79b,0xb7a6,0xb7b2,0xb7bd,0xb7c8,
-0xb7d3,0xb7de,0xb7e9,0xb7f4,0xb800,0xb80b,0xb816,0xb821,
-0xb82c,0xb837,0xb842,0xb84d,0xb858,0xb864,0xb86f,0xb87a,
-0xb885,0xb890,0xb89b,0xb8a6,0xb8b1,0xb8bc,0xb8c7,0xb8d3,
-0xb8de,0xb8e9,0xb8f4,0xb8ff,0xb90a,0xb915,0xb920,0xb92b,
-0xb936,0xb941,0xb94c,0xb957,0xb962,0xb96d,0xb978,0xb983,
-0xb98f,0xb99a,0xb9a5,0xb9b0,0xb9bb,0xb9c6,0xb9d1,0xb9dc,
-0xb9e7,0xb9f2,0xb9fd,0xba08,0xba13,0xba1e,0xba29,0xba34,
-0xba3f,0xba4a,0xba55,0xba60,0xba6b,0xba76,0xba81,0xba8c,
-0xba97,0xbaa2,0xbaad,0xbab8,0xbac3,0xbace,0xbad8,0xbae3,
-0xbaee,0xbaf9,0xbb04,0xbb0f,0xbb1a,0xbb25,0xbb30,0xbb3b,
-0xbb46,0xbb51,0xbb5c,0xbb67,0xbb72,0xbb7d,0xbb88,0xbb92,
-0xbb9d,0xbba8,0xbbb3,0xbbbe,0xbbc9,0xbbd4,0xbbdf,0xbbea,
-0xbbf5,0xbc00,0xbc0a,0xbc15,0xbc20,0xbc2b,0xbc36,0xbc41,
-0xbc4c,0xbc57,0xbc61,0xbc6c,0xbc77,0xbc82,0xbc8d,0xbc98,
-0xbca3,0xbcad,0xbcb8,0xbcc3,0xbcce,0xbcd9,0xbce4,0xbcef,
-0xbcf9,0xbd04,0xbd0f,0xbd1a,0xbd25,0xbd30,0xbd3a,0xbd45,
-0xbd50,0xbd5b,0xbd66,0xbd70,0xbd7b,0xbd86,0xbd91,0xbd9c,
-0xbda6,0xbdb1,0xbdbc,0xbdc7,0xbdd2,0xbddc,0xbde7,0xbdf2,
-0xbdfd,0xbe08,0xbe12,0xbe1d,0xbe28,0xbe33,0xbe3d,0xbe48,
-0xbe53,0xbe5e,0xbe68,0xbe73,0xbe7e,0xbe89,0xbe93,0xbe9e,
-0xbea9,0xbeb4,0xbebe,0xbec9,0xbed4,0xbedf,0xbee9,0xbef4,
-0xbeff,0xbf0a,0xbf14,0xbf1f,0xbf2a,0xbf34,0xbf3f,0xbf4a,
-0xbf55,0xbf5f,0xbf6a,0xbf75,0xbf7f,0xbf8a,0xbf95,0xbf9f,
-0xbfaa,0xbfb5,0xbfbf,0xbfca,0xbfd5,0xbfdf,0xbfea,0xbff5,
-0xc000,0xc00a,0xc015,0xc01f,0xc02a,0xc035,0xc03f,0xc04a,
-0xc055,0xc05f,0xc06a,0xc075,0xc07f,0xc08a,0xc095,0xc09f,
-0xc0aa,0xc0b5,0xc0bf,0xc0ca,0xc0d4,0xc0df,0xc0ea,0xc0f4,
-0xc0ff,0xc109,0xc114,0xc11f,0xc129,0xc134,0xc13e,0xc149,
-0xc154,0xc15e,0xc169,0xc173,0xc17e,0xc189,0xc193,0xc19e,
-0xc1a8,0xc1b3,0xc1bd,0xc1c8,0xc1d3,0xc1dd,0xc1e8,0xc1f2,
-0xc1fd,0xc207,0xc212,0xc21d,0xc227,0xc232,0xc23c,0xc247,
-0xc251,0xc25c,0xc266,0xc271,0xc27b,0xc286,0xc290,0xc29b,
-0xc2a5,0xc2b0,0xc2bb,0xc2c5,0xc2d0,0xc2da,0xc2e5,0xc2ef,
-0xc2fa,0xc304,0xc30f,0xc319,0xc324,0xc32e,0xc339,0xc343,
-0xc34e,0xc358,0xc363,0xc36d,0xc377,0xc382,0xc38c,0xc397,
-0xc3a1,0xc3ac,0xc3b6,0xc3c1,0xc3cb,0xc3d6,0xc3e0,0xc3eb,
-0xc3f5,0xc400,0xc40a,0xc414,0xc41f,0xc429,0xc434,0xc43e,
-0xc449,0xc453,0xc45d,0xc468,0xc472,0xc47d,0xc487,0xc492,
-0xc49c,0xc4a6,0xc4b1,0xc4bb,0xc4c6,0xc4d0,0xc4da,0xc4e5,
-0xc4ef,0xc4fa,0xc504,0xc50e,0xc519,0xc523,0xc52e,0xc538,
-0xc542,0xc54d,0xc557,0xc562,0xc56c,0xc576,0xc581,0xc58b,
-0xc595,0xc5a0,0xc5aa,0xc5b4,0xc5bf,0xc5c9,0xc5d4,0xc5de,
-0xc5e8,0xc5f3,0xc5fd,0xc607,0xc612,0xc61c,0xc626,0xc631,
-0xc63b,0xc645,0xc650,0xc65a,0xc664,0xc66f,0xc679,0xc683,
-0xc68e,0xc698,0xc6a2,0xc6ac,0xc6b7,0xc6c1,0xc6cb,0xc6d6,
-0xc6e0,0xc6ea,0xc6f5,0xc6ff,0xc709,0xc713,0xc71e,0xc728,
-0xc732,0xc73d,0xc747,0xc751,0xc75b,0xc766,0xc770,0xc77a,
-0xc784,0xc78f,0xc799,0xc7a3,0xc7ae,0xc7b8,0xc7c2,0xc7cc,
-0xc7d7,0xc7e1,0xc7eb,0xc7f5,0xc800,0xc80a,0xc814,0xc81e,
-0xc828,0xc833,0xc83d,0xc847,0xc851,0xc85c,0xc866,0xc870,
-0xc87a,0xc884,0xc88f,0xc899,0xc8a3,0xc8ad,0xc8b7,0xc8c2,
-0xc8cc,0xc8d6,0xc8e0,0xc8ea,0xc8f5,0xc8ff,0xc909,0xc913,
-0xc91d,0xc928,0xc932,0xc93c,0xc946,0xc950,0xc95a,0xc965,
-0xc96f,0xc979,0xc983,0xc98d,0xc997,0xc9a2,0xc9ac,0xc9b6,
-0xc9c0,0xc9ca,0xc9d4,0xc9df,0xc9e9,0xc9f3,0xc9fd,0xca07,
-0xca11,0xca1b,0xca26,0xca30,0xca3a,0xca44,0xca4e,0xca58,
-0xca62,0xca6c,0xca76,0xca81,0xca8b,0xca95,0xca9f,0xcaa9,
-0xcab3,0xcabd,0xcac7,0xcad1,0xcadc,0xcae6,0xcaf0,0xcafa,
-0xcb04,0xcb0e,0xcb18,0xcb22,0xcb2c,0xcb36,0xcb40,0xcb4a,
-0xcb55,0xcb5f,0xcb69,0xcb73,0xcb7d,0xcb87,0xcb91,0xcb9b,
-0xcba5,0xcbaf,0xcbb9,0xcbc3,0xcbcd,0xcbd7,0xcbe1,0xcbeb,
-0xcbf5,0xcc00,0xcc0a,0xcc14,0xcc1e,0xcc28,0xcc32,0xcc3c,
-0xcc46,0xcc50,0xcc5a,0xcc64,0xcc6e,0xcc78,0xcc82,0xcc8c,
-0xcc96,0xcca0,0xccaa,0xccb4,0xccbe,0xccc8,0xccd2,0xccdc,
-0xcce6,0xccf0,0xccfa,0xcd04,0xcd0e,0xcd18,0xcd22,0xcd2c,
-0xcd36,0xcd40,0xcd4a,0xcd54,0xcd5e,0xcd68,0xcd72,0xcd7c,
-0xcd86,0xcd90,0xcd99,0xcda3,0xcdad,0xcdb7,0xcdc1,0xcdcb,
-0xcdd5,0xcddf,0xcde9,0xcdf3,0xcdfd,0xce07,0xce11,0xce1b,
-0xce25,0xce2f,0xce39,0xce43,0xce4c,0xce56,0xce60,0xce6a,
-0xce74,0xce7e,0xce88,0xce92,0xce9c,0xcea6,0xceb0,0xceba,
-0xcec3,0xcecd,0xced7,0xcee1,0xceeb,0xcef5,0xceff,0xcf09,
-0xcf13,0xcf1d,0xcf26,0xcf30,0xcf3a,0xcf44,0xcf4e,0xcf58,
-0xcf62,0xcf6c,0xcf75,0xcf7f,0xcf89,0xcf93,0xcf9d,0xcfa7,
-0xcfb1,0xcfbb,0xcfc4,0xcfce,0xcfd8,0xcfe2,0xcfec,0xcff6,
-0xd000,0xd009,0xd013,0xd01d,0xd027,0xd031,0xd03b,0xd044,
-0xd04e,0xd058,0xd062,0xd06c,0xd076,0xd07f,0xd089,0xd093,
-0xd09d,0xd0a7,0xd0b0,0xd0ba,0xd0c4,0xd0ce,0xd0d8,0xd0e1,
-0xd0eb,0xd0f5,0xd0ff,0xd109,0xd112,0xd11c,0xd126,0xd130,
-0xd13a,0xd143,0xd14d,0xd157,0xd161,0xd16b,0xd174,0xd17e,
-0xd188,0xd192,0xd19b,0xd1a5,0xd1af,0xd1b9,0xd1c3,0xd1cc,
-0xd1d6,0xd1e0,0xd1ea,0xd1f3,0xd1fd,0xd207,0xd211,0xd21a,
-0xd224,0xd22e,0xd238,0xd241,0xd24b,0xd255,0xd25f,0xd268,
-0xd272,0xd27c,0xd285,0xd28f,0xd299,0xd2a3,0xd2ac,0xd2b6,
-0xd2c0,0xd2c9,0xd2d3,0xd2dd,0xd2e7,0xd2f0,0xd2fa,0xd304,
-0xd30d,0xd317,0xd321,0xd32b,0xd334,0xd33e,0xd348,0xd351,
-0xd35b,0xd365,0xd36e,0xd378,0xd382,0xd38b,0xd395,0xd39f,
-0xd3a8,0xd3b2,0xd3bc,0xd3c6,0xd3cf,0xd3d9,0xd3e3,0xd3ec,
-0xd3f6,0xd400,0xd409,0xd413,0xd41c,0xd426,0xd430,0xd439,
-0xd443,0xd44d,0xd456,0xd460,0xd46a,0xd473,0xd47d,0xd487,
-0xd490,0xd49a,0xd4a3,0xd4ad,0xd4b7,0xd4c0,0xd4ca,0xd4d4,
-0xd4dd,0xd4e7,0xd4f0,0xd4fa,0xd504,0xd50d,0xd517,0xd521,
-0xd52a,0xd534,0xd53d,0xd547,0xd551,0xd55a,0xd564,0xd56d,
-0xd577,0xd581,0xd58a,0xd594,0xd59d,0xd5a7,0xd5b0,0xd5ba,
-0xd5c4,0xd5cd,0xd5d7,0xd5e0,0xd5ea,0xd5f4,0xd5fd,0xd607,
-0xd610,0xd61a,0xd623,0xd62d,0xd637,0xd640,0xd64a,0xd653,
-0xd65d,0xd666,0xd670,0xd679,0xd683,0xd68c,0xd696,0xd6a0,
-0xd6a9,0xd6b3,0xd6bc,0xd6c6,0xd6cf,0xd6d9,0xd6e2,0xd6ec,
-0xd6f5,0xd6ff,0xd708,0xd712,0xd71b,0xd725,0xd72f,0xd738,
-0xd742,0xd74b,0xd755,0xd75e,0xd768,0xd771,0xd77b,0xd784,
-0xd78e,0xd797,0xd7a1,0xd7aa,0xd7b4,0xd7bd,0xd7c7,0xd7d0,
-0xd7da,0xd7e3,0xd7ed,0xd7f6,0xd800,0xd809,0xd812,0xd81c,
-0xd825,0xd82f,0xd838,0xd842,0xd84b,0xd855,0xd85e,0xd868,
-0xd871,0xd87b,0xd884,0xd88e,0xd897,0xd8a0,0xd8aa,0xd8b3,
-0xd8bd,0xd8c6,0xd8d0,0xd8d9,0xd8e3,0xd8ec,0xd8f5,0xd8ff,
-0xd908,0xd912,0xd91b,0xd925,0xd92e,0xd938,0xd941,0xd94a,
-0xd954,0xd95d,0xd967,0xd970,0xd979,0xd983,0xd98c,0xd996,
-0xd99f,0xd9a9,0xd9b2,0xd9bb,0xd9c5,0xd9ce,0xd9d8,0xd9e1,
-0xd9ea,0xd9f4,0xd9fd,0xda07,0xda10,0xda19,0xda23,0xda2c,
-0xda35,0xda3f,0xda48,0xda52,0xda5b,0xda64,0xda6e,0xda77,
-0xda81,0xda8a,0xda93,0xda9d,0xdaa6,0xdaaf,0xdab9,0xdac2,
-0xdacb,0xdad5,0xdade,0xdae8,0xdaf1,0xdafa,0xdb04,0xdb0d,
-0xdb16,0xdb20,0xdb29,0xdb32,0xdb3c,0xdb45,0xdb4e,0xdb58,
-0xdb61,0xdb6a,0xdb74,0xdb7d,0xdb86,0xdb90,0xdb99,0xdba2,
-0xdbac,0xdbb5,0xdbbe,0xdbc8,0xdbd1,0xdbda,0xdbe4,0xdbed,
-0xdbf6,0xdc00,0xdc09,0xdc12,0xdc1b,0xdc25,0xdc2e,0xdc37,
-0xdc41,0xdc4a,0xdc53,0xdc5d,0xdc66,0xdc6f,0xdc78,0xdc82,
-0xdc8b,0xdc94,0xdc9e,0xdca7,0xdcb0,0xdcb9,0xdcc3,0xdccc,
-0xdcd5,0xdcde,0xdce8,0xdcf1,0xdcfa,0xdd04,0xdd0d,0xdd16,
-0xdd1f,0xdd29,0xdd32,0xdd3b,0xdd44,0xdd4e,0xdd57,0xdd60,
-0xdd69,0xdd73,0xdd7c,0xdd85,0xdd8e,0xdd98,0xdda1,0xddaa,
-0xddb3,0xddbd,0xddc6,0xddcf,0xddd8,0xdde2,0xddeb,0xddf4,
-0xddfd,0xde06,0xde10,0xde19,0xde22,0xde2b,0xde35,0xde3e,
-0xde47,0xde50,0xde59,0xde63,0xde6c,0xde75,0xde7e,0xde87,
-0xde91,0xde9a,0xdea3,0xdeac,0xdeb5,0xdebf,0xdec8,0xded1,
-0xdeda,0xdee3,0xdeed,0xdef6,0xdeff,0xdf08,0xdf11,0xdf1a,
-0xdf24,0xdf2d,0xdf36,0xdf3f,0xdf48,0xdf52,0xdf5b,0xdf64,
-0xdf6d,0xdf76,0xdf7f,0xdf89,0xdf92,0xdf9b,0xdfa4,0xdfad,
-0xdfb6,0xdfbf,0xdfc9,0xdfd2,0xdfdb,0xdfe4,0xdfed,0xdff6,
-0xe000,0xe009,0xe012,0xe01b,0xe024,0xe02d,0xe036,0xe03f,
-0xe049,0xe052,0xe05b,0xe064,0xe06d,0xe076,0xe07f,0xe088,
-0xe092,0xe09b,0xe0a4,0xe0ad,0xe0b6,0xe0bf,0xe0c8,0xe0d1,
-0xe0db,0xe0e4,0xe0ed,0xe0f6,0xe0ff,0xe108,0xe111,0xe11a,
-0xe123,0xe12c,0xe136,0xe13f,0xe148,0xe151,0xe15a,0xe163,
-0xe16c,0xe175,0xe17e,0xe187,0xe190,0xe199,0xe1a3,0xe1ac,
-0xe1b5,0xe1be,0xe1c7,0xe1d0,0xe1d9,0xe1e2,0xe1eb,0xe1f4,
-0xe1fd,0xe206,0xe20f,0xe218,0xe221,0xe22b,0xe234,0xe23d,
-0xe246,0xe24f,0xe258,0xe261,0xe26a,0xe273,0xe27c,0xe285,
-0xe28e,0xe297,0xe2a0,0xe2a9,0xe2b2,0xe2bb,0xe2c4,0xe2cd,
-0xe2d6,0xe2df,0xe2e8,0xe2f1,0xe2fa,0xe303,0xe30c,0xe315,
-0xe31f,0xe328,0xe331,0xe33a,0xe343,0xe34c,0xe355,0xe35e,
-0xe367,0xe370,0xe379,0xe382,0xe38b,0xe394,0xe39d,0xe3a6,
-0xe3af,0xe3b8,0xe3c1,0xe3ca,0xe3d3,0xe3dc,0xe3e5,0xe3ee,
-0xe3f7,0xe400,0xe408,0xe411,0xe41a,0xe423,0xe42c,0xe435,
-0xe43e,0xe447,0xe450,0xe459,0xe462,0xe46b,0xe474,0xe47d,
-0xe486,0xe48f,0xe498,0xe4a1,0xe4aa,0xe4b3,0xe4bc,0xe4c5,
-0xe4ce,0xe4d7,0xe4e0,0xe4e9,0xe4f2,0xe4fa,0xe503,0xe50c,
-0xe515,0xe51e,0xe527,0xe530,0xe539,0xe542,0xe54b,0xe554,
-0xe55d,0xe566,0xe56f,0xe578,0xe580,0xe589,0xe592,0xe59b,
-0xe5a4,0xe5ad,0xe5b6,0xe5bf,0xe5c8,0xe5d1,0xe5da,0xe5e3,
-0xe5eb,0xe5f4,0xe5fd,0xe606,0xe60f,0xe618,0xe621,0xe62a,
-0xe633,0xe63c,0xe644,0xe64d,0xe656,0xe65f,0xe668,0xe671,
-0xe67a,0xe683,0xe68c,0xe694,0xe69d,0xe6a6,0xe6af,0xe6b8,
-0xe6c1,0xe6ca,0xe6d3,0xe6db,0xe6e4,0xe6ed,0xe6f6,0xe6ff,
-0xe708,0xe711,0xe71a,0xe722,0xe72b,0xe734,0xe73d,0xe746,
-0xe74f,0xe758,0xe760,0xe769,0xe772,0xe77b,0xe784,0xe78d,
-0xe795,0xe79e,0xe7a7,0xe7b0,0xe7b9,0xe7c2,0xe7cb,0xe7d3,
-0xe7dc,0xe7e5,0xe7ee,0xe7f7,0xe800,0xe808,0xe811,0xe81a,
-0xe823,0xe82c,0xe834,0xe83d,0xe846,0xe84f,0xe858,0xe861,
-0xe869,0xe872,0xe87b,0xe884,0xe88d,0xe895,0xe89e,0xe8a7,
-0xe8b0,0xe8b9,0xe8c1,0xe8ca,0xe8d3,0xe8dc,0xe8e5,0xe8ed,
-0xe8f6,0xe8ff,0xe908,0xe911,0xe919,0xe922,0xe92b,0xe934,
-0xe93c,0xe945,0xe94e,0xe957,0xe960,0xe968,0xe971,0xe97a,
-0xe983,0xe98b,0xe994,0xe99d,0xe9a6,0xe9ae,0xe9b7,0xe9c0,
-0xe9c9,0xe9d2,0xe9da,0xe9e3,0xe9ec,0xe9f5,0xe9fd,0xea06,
-0xea0f,0xea18,0xea20,0xea29,0xea32,0xea3b,0xea43,0xea4c,
-0xea55,0xea5e,0xea66,0xea6f,0xea78,0xea80,0xea89,0xea92,
-0xea9b,0xeaa3,0xeaac,0xeab5,0xeabe,0xeac6,0xeacf,0xead8,
-0xeae0,0xeae9,0xeaf2,0xeafb,0xeb03,0xeb0c,0xeb15,0xeb1d,
-0xeb26,0xeb2f,0xeb38,0xeb40,0xeb49,0xeb52,0xeb5a,0xeb63,
-0xeb6c,0xeb74,0xeb7d,0xeb86,0xeb8f,0xeb97,0xeba0,0xeba9,
-0xebb1,0xebba,0xebc3,0xebcb,0xebd4,0xebdd,0xebe5,0xebee,
-0xebf7,0xec00,0xec08,0xec11,0xec1a,0xec22,0xec2b,0xec34,
-0xec3c,0xec45,0xec4e,0xec56,0xec5f,0xec68,0xec70,0xec79,
-0xec82,0xec8a,0xec93,0xec9c,0xeca4,0xecad,0xecb5,0xecbe,
-0xecc7,0xeccf,0xecd8,0xece1,0xece9,0xecf2,0xecfb,0xed03,
-0xed0c,0xed15,0xed1d,0xed26,0xed2e,0xed37,0xed40,0xed48,
-0xed51,0xed5a,0xed62,0xed6b,0xed74,0xed7c,0xed85,0xed8d,
-0xed96,0xed9f,0xeda7,0xedb0,0xedb8,0xedc1,0xedca,0xedd2,
-0xeddb,0xede4,0xedec,0xedf5,0xedfd,0xee06,0xee0f,0xee17,
-0xee20,0xee28,0xee31,0xee3a,0xee42,0xee4b,0xee53,0xee5c,
-0xee65,0xee6d,0xee76,0xee7e,0xee87,0xee8f,0xee98,0xeea1,
-0xeea9,0xeeb2,0xeeba,0xeec3,0xeecc,0xeed4,0xeedd,0xeee5,
-0xeeee,0xeef6,0xeeff,0xef08,0xef10,0xef19,0xef21,0xef2a,
-0xef32,0xef3b,0xef43,0xef4c,0xef55,0xef5d,0xef66,0xef6e,
-0xef77,0xef7f,0xef88,0xef90,0xef99,0xefa2,0xefaa,0xefb3,
-0xefbb,0xefc4,0xefcc,0xefd5,0xefdd,0xefe6,0xefee,0xeff7,
-0xf000,0xf008,0xf011,0xf019,0xf022,0xf02a,0xf033,0xf03b,
-0xf044,0xf04c,0xf055,0xf05d,0xf066,0xf06e,0xf077,0xf07f,
-0xf088,0xf090,0xf099,0xf0a1,0xf0aa,0xf0b2,0xf0bb,0xf0c3,
-0xf0cc,0xf0d4,0xf0dd,0xf0e5,0xf0ee,0xf0f6,0xf0ff,0xf107,
-0xf110,0xf118,0xf121,0xf129,0xf132,0xf13a,0xf143,0xf14b,
-0xf154,0xf15c,0xf165,0xf16d,0xf176,0xf17e,0xf187,0xf18f,
-0xf198,0xf1a0,0xf1a9,0xf1b1,0xf1ba,0xf1c2,0xf1cb,0xf1d3,
-0xf1dc,0xf1e4,0xf1ec,0xf1f5,0xf1fd,0xf206,0xf20e,0xf217,
-0xf21f,0xf228,0xf230,0xf239,0xf241,0xf24a,0xf252,0xf25a,
-0xf263,0xf26b,0xf274,0xf27c,0xf285,0xf28d,0xf296,0xf29e,
-0xf2a6,0xf2af,0xf2b7,0xf2c0,0xf2c8,0xf2d1,0xf2d9,0xf2e1,
-0xf2ea,0xf2f2,0xf2fb,0xf303,0xf30c,0xf314,0xf31c,0xf325,
-0xf32d,0xf336,0xf33e,0xf347,0xf34f,0xf357,0xf360,0xf368,
-0xf371,0xf379,0xf381,0xf38a,0xf392,0xf39b,0xf3a3,0xf3ac,
-0xf3b4,0xf3bc,0xf3c5,0xf3cd,0xf3d6,0xf3de,0xf3e6,0xf3ef,
-0xf3f7,0xf400,0xf408,0xf410,0xf419,0xf421,0xf429,0xf432,
-0xf43a,0xf443,0xf44b,0xf453,0xf45c,0xf464,0xf46d,0xf475,
-0xf47d,0xf486,0xf48e,0xf496,0xf49f,0xf4a7,0xf4b0,0xf4b8,
-0xf4c0,0xf4c9,0xf4d1,0xf4d9,0xf4e2,0xf4ea,0xf4f2,0xf4fb,
-0xf503,0xf50c,0xf514,0xf51c,0xf525,0xf52d,0xf535,0xf53e,
-0xf546,0xf54e,0xf557,0xf55f,0xf567,0xf570,0xf578,0xf580,
-0xf589,0xf591,0xf599,0xf5a2,0xf5aa,0xf5b2,0xf5bb,0xf5c3,
-0xf5cb,0xf5d4,0xf5dc,0xf5e4,0xf5ed,0xf5f5,0xf5fd,0xf606,
-0xf60e,0xf616,0xf61f,0xf627,0xf62f,0xf638,0xf640,0xf648,
-0xf651,0xf659,0xf661,0xf66a,0xf672,0xf67a,0xf682,0xf68b,
-0xf693,0xf69b,0xf6a4,0xf6ac,0xf6b4,0xf6bd,0xf6c5,0xf6cd,
-0xf6d6,0xf6de,0xf6e6,0xf6ee,0xf6f7,0xf6ff,0xf707,0xf710,
-0xf718,0xf720,0xf728,0xf731,0xf739,0xf741,0xf74a,0xf752,
-0xf75a,0xf762,0xf76b,0xf773,0xf77b,0xf784,0xf78c,0xf794,
-0xf79c,0xf7a5,0xf7ad,0xf7b5,0xf7bd,0xf7c6,0xf7ce,0xf7d6,
-0xf7de,0xf7e7,0xf7ef,0xf7f7,0xf800,0xf808,0xf810,0xf818,
-0xf821,0xf829,0xf831,0xf839,0xf842,0xf84a,0xf852,0xf85a,
-0xf863,0xf86b,0xf873,0xf87b,0xf883,0xf88c,0xf894,0xf89c,
-0xf8a4,0xf8ad,0xf8b5,0xf8bd,0xf8c5,0xf8ce,0xf8d6,0xf8de,
-0xf8e6,0xf8ef,0xf8f7,0xf8ff,0xf907,0xf90f,0xf918,0xf920,
-0xf928,0xf930,0xf939,0xf941,0xf949,0xf951,0xf959,0xf962,
-0xf96a,0xf972,0xf97a,0xf982,0xf98b,0xf993,0xf99b,0xf9a3,
-0xf9ab,0xf9b4,0xf9bc,0xf9c4,0xf9cc,0xf9d4,0xf9dd,0xf9e5,
-0xf9ed,0xf9f5,0xf9fd,0xfa06,0xfa0e,0xfa16,0xfa1e,0xfa26,
-0xfa2f,0xfa37,0xfa3f,0xfa47,0xfa4f,0xfa58,0xfa60,0xfa68,
-0xfa70,0xfa78,0xfa80,0xfa89,0xfa91,0xfa99,0xfaa1,0xfaa9,
-0xfab1,0xfaba,0xfac2,0xfaca,0xfad2,0xfada,0xfae2,0xfaeb,
-0xfaf3,0xfafb,0xfb03,0xfb0b,0xfb13,0xfb1c,0xfb24,0xfb2c,
-0xfb34,0xfb3c,0xfb44,0xfb4c,0xfb55,0xfb5d,0xfb65,0xfb6d,
-0xfb75,0xfb7d,0xfb85,0xfb8e,0xfb96,0xfb9e,0xfba6,0xfbae,
-0xfbb6,0xfbbe,0xfbc7,0xfbcf,0xfbd7,0xfbdf,0xfbe7,0xfbef,
-0xfbf7,0xfc00,0xfc08,0xfc10,0xfc18,0xfc20,0xfc28,0xfc30,
-0xfc38,0xfc40,0xfc49,0xfc51,0xfc59,0xfc61,0xfc69,0xfc71,
-0xfc79,0xfc81,0xfc8a,0xfc92,0xfc9a,0xfca2,0xfcaa,0xfcb2,
-0xfcba,0xfcc2,0xfcca,0xfcd2,0xfcdb,0xfce3,0xfceb,0xfcf3,
-0xfcfb,0xfd03,0xfd0b,0xfd13,0xfd1b,0xfd23,0xfd2c,0xfd34,
-0xfd3c,0xfd44,0xfd4c,0xfd54,0xfd5c,0xfd64,0xfd6c,0xfd74,
-0xfd7c,0xfd84,0xfd8d,0xfd95,0xfd9d,0xfda5,0xfdad,0xfdb5,
-0xfdbd,0xfdc5,0xfdcd,0xfdd5,0xfddd,0xfde5,0xfded,0xfdf5,
-0xfdfd,0xfe06,0xfe0e,0xfe16,0xfe1e,0xfe26,0xfe2e,0xfe36,
-0xfe3e,0xfe46,0xfe4e,0xfe56,0xfe5e,0xfe66,0xfe6e,0xfe76,
-0xfe7e,0xfe86,0xfe8e,0xfe97,0xfe9f,0xfea7,0xfeaf,0xfeb7,
-0xfebf,0xfec7,0xfecf,0xfed7,0xfedf,0xfee7,0xfeef,0xfef7,
-0xfeff,0xff07,0xff0f,0xff17,0xff1f,0xff27,0xff2f,0xff37,
-0xff3f,0xff47,0xff4f,0xff57,0xff5f,0xff67,0xff6f,0xff77,
-0xff7f,0xff87,0xff8f,0xff97,0xff9f,0xffa7,0xffaf,0xffb7,
-0xffbf,0xffc7,0xffcf,0xffd7,0xffdf,0xffe7,0xffef,0xfff7};
-
-static const signed short wavtable1[2304]={
-0x021d,0x03bc,0x0300,0xfc0d,0xfcd5,0xfd33,0xfdc5,0xfc83,
-0xfdc0,0x036d,0x0245,0x0238,0xfc1b,0xfc31,0xfd7a,0xfd10,
-0xfd6b,0xfd88,0x02a3,0x0313,0x027b,0xfdf9,0xfcba,0xfc2f,
-0xfc86,0xfda3,0xfceb,0x0270,0x02dc,0x029c,0xfc83,0xfcd1,
-0xfc44,0xfd06,0xfdf5,0xfc97,0x026f,0x0347,0x02b9,0xfc02,
-0xfcaf,0xfdc5,0xfd09,0xfd50,0xfc4b,0x0280,0x02b5,0x03df,
-0xfc9d,0xfd95,0xfd61,0xfce0,0xfc54,0xfc41,0x039d,0x02af,
-0x0260,0xfd93,0xfddb,0xfccf,0xfcbb,0xfc64,0xfd2e,0x0228,
-0x031d,0x023c,0xfca3,0xfd97,0xfc84,0xfdac,0xfd93,0xfd80,
-0x0217,0x0340,0x031f,0xfc99,0xfcbc,0xfd77,0xfdd0,0xfd5c,
-0xfd90,0x02fa,0x025d,0x0241,0xfc7a,0xfca5,0xfd56,0xfdc8,
-0xfd34,0xfd76,0x0340,0x0231,0x03eb,0xfc6f,0xfcd1,0xfdda,
-0xfd5c,0xfd98,0xfc2a,0x024e,0x02af,0x024c,0xfce7,0xfd59,
-0xfcea,0xfd57,0xfc65,0xfd5b,0x0286,0x0385,0x02dc,0xfdc7,
-0xfc64,0xfd7b,0xfcd0,0xfce6,0xfdf4,0x033c,0x02b1,0x0380,
-0xfdd3,0xfd2b,0xfda5,0xfd62,0xfc61,0xfcf0,0x036b,0x0270,
-0x0350,0xfdeb,0xfd2b,0xfdfc,0xfd14,0xfd08,0xfd42,0x023b,
-0x03ae,0x03fe,0xfdf2,0xfdc6,0xfc53,0xfd82,0xfc9c,0xfc04,
-0x0338,0x02e0,0x0283,0xfdaf,0xfdfb,0xfc63,0xfd69,0xfdee,
-0xfcd8,0x0205,0x02fd,0x0200,0xfcfa,0xfdfa,0xfd01,0xfdf5,
-0xfdc4,0xfdff,0x0232,0x038c,0x02f9,0xfc1b,0xfcbc,0xfd5d,
-0xfd97,0xfcdb,0xfdca,0x02b6,0x0391,0x02a3,0xfd95,0xfc6c,
-0xfda5,0xfc53,0xfcd1,0xfc85,0x02c0,0x020c,0x02a0,0xfd2e,
-0xfc63,0xfd4f,0xfc37,0xfde6,0xfc8d,0x02d1,0x02f5,0x022e,
-0xfdea,0xfcee,0xfcc6,0xfc06,0xfdcf,0xfda0,0x0374,0x0227,
-0x0279,0xfc49,0xfdde,0xfd57,0xfd05,0xfdb0,0xfcf0,0x022e,
-0x03ef,0x034e,0xfddb,0xfc65,0xfcc0,0xfda0,0xfc21,0xfd45,
-0x03a4,0x02ea,0x0309,0xfd59,0xfd3d,0xfdca,0xfcaf,0xfde0,
-0xfdb3,0x0236,0x0336,0x039e,0xfc72,0xfdff,0xfd18,0xfd8d,
-0xfd6d,0xfcb9,0x0265,0x0303,0x0263,0xfc64,0xfd25,0xfc67,
-0xfd23,0xfdbb,0xfd27,0x02e1,0x029f,0x03f0,0xfc39,0xfd2a,
-0xfd6b,0xfded,0xfc90,0xfc1f,0x028b,0x0252,0x0243,0xfd0b,
-0xfd1f,0xfd5f,0xfcc2,0xfd4d,0xfd71,0x0321,0x027c,0x0234,
-0xfc1c,0xfc8d,0xfd42,0xfd8e,0xfce8,0xfd92,0x0354,0x038e,
-0x02cf,0xfd0b,0xfda9,0xfd81,0xfd3b,0xfcd7,0xfc0c,0x03e6,
-0x0266,0x023f,0xfda9,0xfdcf,0xfd4d,0xfc32,0xfd1f,0xfd79,
-0x0299,0x03a7,0x0274,0xfda1,0xfcd0,0xfdc2,0xfca1,0xfcaa,
-0xfcfd,0x0277,0x0254,0x033d,0xfd21,0xfc01,0xfc3a,0xfcf6,
-0xfd4a,0xfd60,0x0284,0x039e,0x020e,0xfdb9,0xfd69,0xfc47,
-0xfcd5,0xfcba,0xfde2,0x036f,0x03dc,0x0265,0xfcb0,0xfdf2,
-0xfdb0,0xfd0d,0xfc47,0xfd22,0x03ad,0x02b4,0x02b5,0xfd83,
-0xfd82,0xfc55,0xfc9e,0xfc57,0xfc54,0x0235,0x02a0,0x0240,
-0xfd1a,0xfd83,0xfd0b,0xfd8f,0xfc8e,0xfd77,0x0223,0x0274,
-0x02e4,0xfd61,0xfce9,0xfc73,0xfdb7,0xfcfd,0xfde9,0x027f,
-0x0214,0x0219,0xfd67,0xfd61,0xfdd1,0xfce2,0xfdd6,0xfdcc,
-0x03bb,0x025c,0x0256,0xfdcc,0xfdd2,0xfd3e,0xfc85,0xfd36,
-0xfd45,0x0232,0x0244,0x0384,0xfd83,0xfc23,0xfc03,0xfd97,
-0xfd6e,0xfce9,0x025b,0x0383,0x026d,0xfdee,0xfd23,0xfddf,
-0xfd38,0xfceb,0xfd0d,0x02ea,0x0215,0x0270,0xfcf8,0xfc73,
-0xfd76,0xfde1,0xfdd5,0xfd07,0x02d9,0x0202,0x02df,0xfd23,
-0xfdf5,0xfd1d,0xfdf9,0xfdfb,0xfdf0,0x0355,0x0227,0x02b4,
-0xfc69,0xfdbf,0xfd17,0xfd39,0xfdaf,0xfc58,0x03b5,0x03fa,
-0x03ec,0xfc50,0xfc5d,0xfc19,0xfc90,0xfc0b,0xfc27,0x0220,
-0x03dc,0x02df,0xfdf3,0xfcf3,0xfd3a,0xfdbe,0xfc46,0xfdf0,
-0x0315,0x030e,0x0335,0xfda5,0xfd87,0xfd8c,0xfda0,0xfdaa,
-0xfd6d,0x0381,0x0204,0x02f2,0xfc76,0xfd6b,0xfd07,0xfcee,
-0xfdf7,0xfdd4,0x0205,0x02be,0x033c,0xfd3a,0xfcbb,0xfdc8,
-0xfdf5,0xfc3d,0xfd62,0x024a,0x0332,0x02fb,0xfc57,0xfc96,
-0xfd9f,0xfd60,0xfd72,0xfdc8,0x038b,0x028c,0x0250,0xfdbe,
-0xfdf3,0xfd0e,0xfcdc,0xfcc2,0xfd52,0x0210,0x028c,0x0282,
-0xfd5f,0xfd69,0xfcce,0xfdde,0xfcc2,0xfcda,0x0213,0x02c4,
-0x030c,0xfd20,0xfcd5,0xfde4,0xfdd8,0xfc2b,0xfdad,0x029a,
-0x0271,0x02d7,0xfcd3,0xfc4e,0xfc88,0xfc9d,0xfd05,0xfdfc,
-0x03b3,0x02d7,0x022a,0xfd5f,0xfe00,0xfced,0xfc95,0xfdfb,
-0xfda9,0x0225,0x0291,0x03d5,0xfd3f,0xfdf2,0xfd8a,0xfdb3,
-0xfcb5,0xfc53,0x025d,0x0398,0x0354,0xfde0,0xfc10,0xfd02,
-0xfd34,0xfcc5,0xfd3b,0x0270,0x026b,0x03d7,0xfd0d,0xfda9,
-0xfdad,0xfd07,0xfd12,0xfc50,0x025d,0x038d,0x0223,0xfde7,
-0xfd7a,0xfc35,0xfd35,0xfcd9,0xfdb8,0x02b2,0x03a7,0x0204,
-0xfd89,0xfd47,0xfc50,0xfc5c,0xfca9,0xfdf7,0x02bc,0x0264,
-0x0355,0xfcba,0xfdb8,0xfc03,0xfc41,0xfd24,0xfd39,0x02ff,
-0x0340,0x023e,0xfd91,0xfca3,0xfc5b,0xfdc1,0xfd5c,0xfd7d,
-0x020b,0x0382,0x039b,0xfc69,0xfc4f,0xfcd6,0xfde8,0xfceb,
-0xfcbf,0x02d2,0x03be,0x02b3,0xfd5c,0xfc30,0xfd79,0xfc04,
-0xfc80,0xfc59,0x0265,0x0303,0x03a0,0xfc64,0xfdd4,0xfd44,
-0xfd22,0xfdbb,0xfcb6,0x02f6,0x02f5,0x0248,0xfdcf,0xfc9e,
-0xfc9f,0xfdce,0xfdd0,0xfd65,0x0200,0x0237,0x0241,0xfdc9,
-0xfdbf,0xfd81,0xfe00,0xfd8c,0xfd76,0x0267,0x027e,0x02ba,
-0xfd02,0xfcb9,0xfc99,0xfd1d,0xfce5,0xfc46,0x023e,0x0282,
-0x024d,0xfd30,0xfd6c,0xfd1d,0xfd7c,0xfcda,0xfd5b,0x03e1,
-0x02aa,0x036e,0xfd6a,0xfcac,0xfdb7,0xfc3d,0xfc72,0xfd0f,
-0x021b,0x037a,0x0391,0xfc55,0xfc3d,0xfce5,0xfdc7,0xfcf9,
-0xfcd1,0x02b6,0x03a0,0x0220,0xfd8b,0xfd1e,0xfc25,0xfc53,
-0xfcb6,0xfdbe,0x0325,0x0258,0x02a8,0xfc50,0xfde9,0xfce2,
-0xfd87,0xfd40,0xfc77,0x021c,0x03b7,0x030e,0xfc14,0xfcc7,
-0xfd29,0xfdc6,0xfc8c,0xfdab,0x0330,0x03b6,0x024e,0xfd0b,
-0xfc53,0xfddc,0xfd76,0xfc8f,0xfd57,0x03bb,0x034f,0x032b,
-0xfcea,0xfd0b,0xfd61,0xfc85,0xfd44,0xfd7d,0x0223,0x0373,
-0x022c,0xfc4f,0xfdad,0xfc40,0xfdb6,0xfd06,0xfda3,0x028c,
-0x0378,0x025c,0xfdcb,0xfcfe,0xfdf4,0xfcc1,0xfcfe,0xfd37,
-0x035f,0x0249,0x0357,0xfc26,0xfd2f,0xfc2e,0xfd29,0xfd64,
-0xfd35,0x03ff,0x03e5,0x0204,0xfc1b,0xfdfc,0xfc12,0xfc01,
-0xfc34,0xfdf8,0x03a4,0x0266,0x0280,0xfdd0,0xfdb9,0xfcff,
-0xfcae,0xfd1e,0xfce0,0x0273,0x0234,0x023d,0xfd4d,0xfd42,
-0xfd89,0xfcff,0xfd93,0xfd7f,0x036c,0x0384,0x02d4,0xfcfe,
-0xfd94,0xfd83,0xfd12,0xfce8,0xfe00,0x0203,0x0359,0x0380,
-0xfca1,0xfc7a,0xfd12,0xfdf9,0xfd32,0xfcf0,0x0287,0x03b9,
-0x036f,0xfda6,0xfdd5,0xfcce,0xfccf,0xfc88,0xfd0d,0x0326,
-0x0356,0x0359,0xfd60,0xfd5d,0xfd35,0xfd86,0xfd38,0xfd32,
-0x0221,0x0247,0x0277,0xfd93,0xfd60,0xfd31,0xfdbb,0xfd68,
-0xfcf6,0x0291,0x0259,0x02ef,0xfcfc,0xfc3d,0xfc8e,0xfcb5,
-0xfd3d,0xfdda,0x02e4,0x0389,0x031b,0xfd72,0xfdc1,0xfd40,
-0xfde9,0xfcdf,0xfd96,0x0349,0x03f8,0x0238,0xfcbd,0xfc5a,
-0xfdcc,0xfd4d,0xfc0f,0xfd89,0x02eb,0x024d,0x03d7,0xfca3,
-0xfd32,0xfdca,0xfddf,0xfd59,0xfc4f,0x036e,0x0265,0x020e,
-0xfdf2,0xfc7a,0xfd8a,0xfd0f,0xfd20,0xfde4,0x0360,0x02d3,
-0x030b,0xfd9e,0xfd6f,0xfdda,0xfd27,0xfc02,0xfdb0,0x0216,
-0x02a2,0x0306,0xfd41,0xfcd8,0xfc05,0xfdd3,0xfc89,0xfdb6,
-0x03b6,0x0289,0x03ab,0xfda6,0xfc99,0xfdad,0xfc8f,0xfcc8,
-0xfca3,0x024e,0x02bf,0x0383,0xfcd5,0xfdfa,0xfd96,0xfd58,
-0xfc3a,0xfcea,0x026a,0x020f,0x0243,0xfd83,0xfd44,0xfdab,
-0xfd16,0xfde1,0xfd6f,0x02d5,0x0287,0x03cc,0xfc6b,0xfd4f,
-0xfd99,0xfdff,0xfcce,0xfc64,0x0281,0x0287,0x02c3,0xfcd6,
-0xfc8b,0xfc83,0xfcdd,0xfccf,0xfc30,0x02da,0x0297,0x0284,
-0xfc4e,0xfc68,0xfcbd,0xfdf7,0xfca4,0xfcd4,0x0327,0x023c,
-0x0242,0xfc7a,0xfc70,0xfd7a,0xfd83,0xfd81,0xfd73,0x036f,
-0x0263,0x0335,0xfdf4,0xfd3f,0xfc2d,0xfd0d,0xfd27,0xfd6e,
-0x029b,0x02d9,0x0349,0xfc49,0xfddb,0xfda9,0xfc99,0xfdf9,
-0xfd4c,0x030e,0x0249,0x02ef,0xfc81,0xfdc2,0xfca5,0xfdaa,
-0xfd62,0xfdd9,0x0322,0x02dd,0x03d0,0xfdc2,0xfd03,0xfd45,
-0xfd8c,0xfdf3,0xfc5d,0x0352,0x0367,0x02c4,0xfd2c,0xfdb4,
-0xfda6,0xfd3e,0xfd1a,0xfc2d,0x0366,0x02e7,0x02c0,0xfd88,
-0xfdaa,0xfc01,0xfd1d,0xfde4,0xfc36,0x03ad,0x0383,0x0249,
-0xfcc5,0xfde6,0xfdfe,0xfc9e,0xfcea,0xfd63,0x03af,0x0278,
-0x036b,0xfdba,0xfcda,0xfde3,0xfc9b,0xfcf3,0xfd13,0x03ff,
-0x02dc,0x027e,0xfd25,0xfd83,0xfc70,0xfc02,0xfdf5,0xfce5,
-0x030a,0x02f1,0x028f,0xfdc3,0xfc1b,0xfc3b,0xfdb0,0xfdd6,
-0xfcb9,0x034b,0x03b1,0x03b1,0xfcf5,0xfcf5,0xfc97,0xfd4a,
-0xfc97,0xfc97,0x03ae,0x03c9,0x023c,0xfc84,0xfdf1,0xfde2,
-0xfc9d,0xfc6a,0xfd80,0x03f0,0x022f,0x0356,0xfdd9,0xfcb7,
-0xfc5a,0xfc1f,0xfd9c,0xfd38,0x0364,0x02d9,0x0313,0xfd96,
-0xfd64,0xfdd0,0xfd1f,0xfdf9,0xfda3,0x03ca,0x02ae,0x0223,
-0xfd76,0xfdfa,0xfd23,0xfc69,0xfc69,0xfdb7,0x0217,0x027b,
-0x02a2,0xfd68,0xfd3f,0xfcbc,0xfdd0,0xfcec,0xfc89,0x0230,
-0x027c,0x033c,0xfd48,0xfc75,0xfdfe,0xfd9b,0xfcea,0xfd62,
-0x03e2,0x0250,0x0341,0xfdc1,0xfcd7,0xfc3c,0xfc3a,0xfd52,
-0xfd5b,0x0224,0x026d,0x02b6,0xfd67,0xfd19,0xfcb5,0xfdb5,
-0xfd0d,0xfc52,0x0226,0x0321,0x03bb,0xfca3,0xfdff,0xfd14,
-0xfdb1,0xfd8d,0xfc84,0x0246,0x020a,0x0286,0xfdae,0xfd21,
-0xfd6d,0xfd69,0xfdeb,0xfcd1,0x025e,0x0271,0x0332,0xfd1d,
-0xfc37,0xfc19,0xfd33,0xfd05,0xfd71,0x026f,0x024f,0x036a,
-0xfd30,0xfded,0xfc0e,0xfd0a,0xfd55,0xfd16,0x029d,0x0217,
-0x03e9,0xfd44,0xfd72,0xfdf5,0xfc94,0xfdd1,0xfc2d,0x02bd,
-0x03aa,0x0250,0xfd7e,0xfcd6,0xfde2,0xfc40,0xfca4,0xfd54,
-0x039d,0x0334,0x02e2,0xfd1b,0xfd65,0xfdb0,0xfcbd,0xfd6f,
-0xfdeb,0x02df,0x0316,0x0220,0xfdc9,0xfcf3,0xfcb8,0xfdf1,
-0xfd9e,0xfdbe,0x023f,0x0314,0x02a2,0xfc8a,0xfd0a,0xfdf9,
-0xfd79,0xfda1,0xfc88,0x028f,0x030f,0x0210,0xfc15,0xfd5b,
-0xfcd7,0xfcb8,0xfda9,0xfddf,0x020f,0x0201,0x02a5,0xfdef,
-0xfd45,0xfd59,0xfde0,0xfdfe,0xfc7f,0x030e,0x0354,0x03ac,
-0xfd75,0xfd32,0xfcf1,0xfdab,0xfd3b,0xfca1,0x0242,0x038e,
-0x0201,0xfdfe,0xfdbb,0xfc6e,0xfd72,0xfcd7,0xfdfd,0x02b4,
-0x0372,0x02de,0xfdac,0xfc1f,0xfd88,0xfc57,0xfd09,0xfdf2,
-0x024a,0x02ab,0x02cb,0xfcf2,0xfcce,0xfc46,0xfd62,0xfc71,
-0xfc19,0x02e3,0x0261,0x02cd,0xfc90,0xfdfa,0xfcaa,0xfdea,
-0xfd2b,0xfc12,0x030a,0x0305,0x02b9,0xfdb4,0xfdee,0xfdf1,
-0xfdb0,0xfdb8,0xfc49,0x039a,0x0311,0x032d,0xfd3d,0xfd24,
-0xfd90,0xfcc2,0xfda6,0xfd7a,0x02fe,0x028b,0x03d8,0xfc32,
-0xfd20,0xfd8e,0xfdc3,0xfcc5,0xfc4e,0x03d2,0x0254,0x0203,
-0xfdc7,0xfc28,0xfda8,0xfc5a,0xfd4a,0xfdfa,0x0217,0x02f5,
-0x021c,0xfce8,0xfdcb,0xfce1,0xfdd0,0xfdd1,0xfdc5,0x0296,
-0x02af,0x024d,0xfc86,0xfd06,0xfce9,0xfca7,0xfc64,0xfd5a,
-0x022a,0x0218,0x03d3,0xfdbc,0xfdee,0xfe00,0xfda7,0xfdcf,
-0xfc58,0x02d3,0x03d6,0x02b2,0xfd4a,0xfc30,0xfd6a,0xfc02,
-0xfc51,0xfc5c,0x03a8,0x03bc,0x020f,0xfc95,0xfc3b,0xfc26,
-0xfca8,0xfc82,0xfde1,0x024e,0x03ea,0x0223,0xfdbf,0xfd89,
-0xfde8,0xfd58,0xfc2c,0xfdb6,0x0205,0x028d,0x0339,0xfd6c,
-0xfcbf,0xfdf2,0xfdf6,0xfcbe,0xfd68,0x0340,0x0250,0x03ce,
-0xfc3c,0xfce8,0xfdcc,0xfd5b,0xfd52,0xfc60,0x0200,0x03bd,
-0x0387,0xfc43,0xfc79,0xfcb4,0xfe00,0xfc82,0xfce4,0x0277,
-0x0221,0x038a,0xfd60,0xfdd2,0xfc3b,0xfcf7,0xfdbb,0xfcde,
-0x0202,0x02d0,0x0289,0xfd2d,0xfd74,0xfc6f,0xfdfc,0xfc0c,
-0xfcc8,0x0254,0x02a7,0x02b6,0xfcea,0xfcd9,0xfc68,0xfd4b,
-0xfc7c,0xfc54,0x0269,0x02e4,0x03d3,0xfc84,0xfdb2,0xfd3c,
-0xfd19,0xfde9,0xfc58,0x02c7,0x02ad,0x036d,0xfc48,0xfd9f,
-0xfdb5,0xfc25,0xfc6b,0xfd10,0x028f,0x0343,0x0350,0xfdea,
-0xfde2,0xfd4d,0xfcba,0xfd57,0xfd42,0x02f2,0x0347,0x02ba,
-0xfd96,0xfdfd,0xfdc3,0xfdd4,0xfd50,0xfc46,0x0367,0x0203,
-0x0301,0xfc93,0xfd71,0xfcfa,0xfd1a,0xfdfa,0xfdbe,0x03bb,
-0x0354,0x023d,0xfce5,0xfde9,0xfc45,0xfc84,0xfd3b,0xfd7d,
-0x0280,0x035b,0x024b,0xfde7,0xfd21,0xfc26,0xfcdf,0xfd2f,
-0xfd5e,0x0318,0x035f,0x022a,0xfd65,0xfca6,0xfc59,0xfd9c,
-0xfd29,0xfda7,0x034b,0x02c4,0x02aa,0xfdb9,0xfdce,0xfc50,
-0xfd4a,0xfc2d,0xfc72,0x03cb,0x0300,0x0228,0xfd28,0xfdf4,
-0xfcc3,0xfc67,0xfdc0,0xfdac,0x037b,0x0218,0x02b2,0xfc59,
-0xfda7,0xfd2c,0xfcf8,0xfdcd,0xfc5d,0x03f8,0x0230,0x0297,
-0xfdd4,0xfd6d,0xfd29,0xfc0f,0xfd9a,0xfca4,0x021f,0x0366,
-0x02a2,0xfc64,0xfd34,0xfdc3,0xfdbf,0xfd1d,0xfc87,0x0259,
-0x03e7,0x0249,0xfdb6,0xfd52,0xfdc5,0xfd3f,0xfc31,0xfd64,
-0x03b1,0x03c6,0x0379,0xfc84,0xfccb,0xfcb8,0xfc98,0xfc70,
-0xfcfb,0x0211,0x0390,0x0309,0xfc51,0xfcdc,0xfd4c,0xfddd,
-0xfcd4,0xfdb2,0x023e,0x03fc,0x02ca,0xfdc4,0xfcdf,0xfd39,
-0xfd7d,0xfc08,0xfc1b,0x0261,0x039a,0x03a4,0xfddb,0xfdd5,
-0xfcb8,0xfd2b,0xfcc1,0xfcb0,0x0256,0x030a,0x03a1,0xfc73,
-0xfde1,0xfd3d,0xfd46,0xfdb0,0xfcb4,0x028b,0x0304,0x02e8,
-0xfc2a,0xfc4d,0xfdcf,0xfcc5,0xfdba,0xfde3,0x02b3,0x03bd,
-0x02d2,0xfd7a,0xfc30,0xfd5d,0xfc5a,0xfc82,0xfc04,0x02d9,
-0x02fe,0x03d8,0xfdde,0xfd43,0xfd20,0xfdf8,0xfdc3,0xfc4f,
-0x0223,0x0207,0x0278,0xfdd5,0xfd5d,0xfd80,0xfdb7,0xfdf2,
-0xfcf4,0x0247,0x0214,0x039a,0xfda1,0xfdf3,0xfc40,0xfd68,
-0xfdd6,0xfcc1,0x0279,0x03e3,0x025b,0xfd99,0xfd17,0xfdb6,
-0xfcf1,0xfc38,0xfd3a,0x02a5,0x023b,0x036a,0xfd0b,0xfdbe,
-0xfc2f,0xfc80,0xfd82,0xfd15,0x025a,0x0221,0x029a,0xfd7f,
-0xfcf1,0xfd3b,0xfd3c,0xfdbc,0xfc9e,0x0273,0x021e,0x036b,
-0xfd67,0xfde8,0xfc60,0xfcff,0xfdc1,0xfd14,0x02a0,0x03d7,
-0x0256,0xfd7b,0xfcee,0xfdc1,0xfc8e,0xfc50,0xfd44,0x02b4,
-0x03d3,0x02da,0xfd6a,0xfc24,0xfd46,0xfc57,0xfc57,0xfdf7,
-0x029c,0x027a,0x0368,0xfcc5,0xfdc7,0xfde4,0xfc99,0xfcef,
-0xfd1a,0x02c7,0x02c2,0x02a2,0xfc2a,0xfc57,0xfc5d,0xfc24,
-0xfc31,0xfc87,0x02e3,0x03d1,0x0253,0xfd3e,0xfca4,0xfdc8,
-0xfdea,0xfc5c,0xfd4d,0x02f7,0x0389,0x02fb,0xfd61,0xfdca,
-0xfd5d,0xfdcd,0xfce1,0xfdc7,0x02f4,0x0246,0x02fb,0xfca4,
-0xfdcd,0xfc9c,0xfdd2,0xfd69,0xfdc8,0x02ec,0x03f5,0x038c,
-0xfd1b,0xfd68,0xfc7e,0xfddd,0xfc16,0xfcdb,0x0324,0x03a9,
-0x03b6,0xfd20,0xfd16,0xfc9b,0xfd89,0xfca6,0xfc8e,0x0311,
-0x021f,0x03e6,0xfcbf,0xfd02,0xfdef,0xfda6,0xfdc0,0xfc33,
-0x03e7,0x02ac,0x03ae,0xfd64,0xfc68,0xfd8a,0xfc31,0xfc6d,
-0xfc9c,0x0272,0x0279,0x03e4,0xfcfa,0xfd9f,0xfd98,0xfd03,
-0xfcf1,0xfc36,0x0272,0x0237,0x0343,0xfd4b,0xfc03,0xfc63,
-0xfd03,0xfd8c,0xfd57,0x02e3,0x023b,0x03cd,0xfcc7,0xfd42,
-0xfde1,0xfdeb,0xfd83,0xfc63,0x028f,0x0301,0x02c3,0xfc28,
-0xfc76,0xfded,0xfcb9,0xfdbf,0xfc2e,0x02be,0x03b8,0x023b,
-0xfd73,0xfcef,0xfdec,0xfc3c,0xfc8a,0xfd82,0x02d7,0x02c8,
-0x0202,0xfc0c,0xfd26,0xfd35,0xfdfc,0xfc22,0xfdfc,0x02e8,
-0x02ae,0x02e5,0xfc1a,0xfde5,0xfc1e,0xfde3,0xfc67,0xfde8,
-0x02db,0x0228,0x02ca,0xfceb,0xfc03,0xfcfc,0xfdf6,0xfdac,
-0xfc1a,0x0338,0x03df,0x02d6,0xfce2,0xfdb7,0xfd41,0xfd68,
-0xfc41,0xfdfd,0x031b,0x0267,0x0220,0xfc45,0xfcb4,0xfd73,
-0xfd97,0xfd1e,0xfdbe,0x0366,0x023f,0x0338,0xfc2e,0xfd44,
-0xfc62,0xfd1d,0xfd7a,0xfd68,0x0323,0x0340,0x039b,0xfd73,
-0xfd2c,0xfd12,0xfd8a,0xfd5b,0xfcc0,0x0333,0x0347,0x0213,
-0xfd61,0xfcaf,0xfc99,0xfd71,0xfd50,0xfdda,0x0377,0x0312,
-0x0354,0xfd57,0xfd1e,0xfd72,0xfcff,0xfda5,0xfd3b,0x03a5,
-0x02fc,0x023a,0xfd48,0xfdf9,0xfcad,0xfcae,0xfdc6,0xfd86,
-0x02cc,0x038a,0x028e,0xfd86,0xfc6c,0xfdbd,0xfc15,0xfcde,
-0xfcbb,0x0310,0x0324,0x0233,0xfd98,0xfca0,0xfc8b,0xfda7,
-0xfd89,0xfd94,0x0306,0x0217,0x036c,0xfcd7,0xfd6a,0xfc6d,
-0xfdb7,0xfdd1,0xfd13,0x0327,0x0256,0x0289,0xfc51,0xfc01,
-0xfd0a,0xfd84,0xfd45,0xfcca,0x0331,0x02f7,0x02ce,0xfda2,
-0xfdc3,0xfdeb,0xfd74,0xfdcd,0xfc10,0x033f,0x03e1,0x034e,
-0xfcda,0xfd51,0xfccb,0xfd5d,0xfc3d,0xfd45,0x035a,0x0237,
-0x025d,0xfc49,0xfc09,0xfd62,0xfd30,0xfd8c,0xfd34,0x036c,
-0x03f4,0x028b,0xfc9e,0xfdd3,0xfd7d,0xfd12,0xfc17,0xfcc5,
-0x0354,0x0224,0x0225,0xfc6f,0xfc6e,0xfdb4,0xfd3a,0xfdb5,
-0xfdb3,0x037f,0x03f0,0x0367,0xfc8f,0xfd07,0xfca6,0xfcf2,
-0xfc1f,0xfd1b,0x037c,0x03e8,0x024f,0xfc98,0xfdfd,0xfdbe,
-0xfcf7,0xfc2f,0xfd55,0x03a7,0x0204,0x0344,0xfc50,0xfd04,
-0xfcb4,0xfca9,0xfdf7,0xfd56,0x03a3,0x0264,0x0308,0xfdd3,
-0xfd3e,0xfc5f,0xfcb1,0xfd23,0xfdb3,0x03c8,0x0266,0x0330,
-0xfdbb,0xfcfd,0xfc2c,0xfc6d,0xfd1e,0xfd75,0x020c,0x0309,
-0x02cf,0xfce4,0xfd1f,0xfdde,0xfde7,0xfdb2,0xfc0c,0x0225,
-0x02b6,0x0312,0xfd18,0xfcb5,0xfdeb,0xfdb3,0xfc53,0xfda5,
-0x0372,0x02f2,0x0216,0xfd77,0xfc68,0xfced,0xfd09,0xfdd5,
-0xfdd3,0x0255,0x0345,0x02fe,0xfc2f,0xfc81,0xfd8d,0xfd47,
-0xfd54,0xfdc2,0x027b,0x03ba,0x02c0,0xfdb0,0xfc97,0xfd70,
-0xfcec,0xfc86,0xfc37,0x0323,0x0226,0x031e,0xfca1,0xfd8e,
-0xfca6,0xfd8a,0xfdb1,0xfd92,0x02bb,0x028e,0x031e,0xfc82,
-0xfddf,0xfc03,0xfc46,0xfcbb,0xfd92,0x039c,0x02ff,0x02e2,
-0xfd4b,0xfd66,0xfdd7,0xfcbe,0xfdc1,0xfded,0x03ca,0x02a3,
-0x0260,0xfd81,0xfdc0,0xfcdf,0xfc69,0xfc86,0xfd2e,0x0278,
-0x02c2,0x02ac,0xfc97,0xfcb4,0xfc50,0xfcf4,0xfc30,0xfc6e,
-0x035a,0x02ff,0x0233,0xfd7d,0xfc4f,0xfcb4,0xfd31,0xfdc2,
-0xfd94,0x020f,0x02fd,0x02be,0xfcec,0xfd2c,0xfdf3,0xfde1,
-0xfdc4,0xfc3c,0x022f,0x039c,0x03eb,0xfc0f,0xfddd,0xfc77,
-0xfd9e,0xfcbf,0xfc29,0x026a,0x020c,0x0263,0xfd87,0xfd1e,
-0xfd8f,0xfd15,0xfde8,0xfd27,0x03e7,0x03ae,0x03c3,0xfc68,
-0xfc54,0xfc8a,0xfc30,0xfc9d,0xfc77,0x0223,0x0359,0x03a7,
-0xfc6c,0xfc19,0xfcf1,0xfdb8,0xfd32,0xfcaa,0x02de,0x039e,
-0x0239,0xfd67,0xfcce,0xfdfd,0xfdf1,0xfcba,0xfd86,0x03c7,
-0x02ea,0x0227,0xfd3f,0xfdf8,0xfcdc,0xfc6f,0xfde0,0xfdaf,
-0x0342,0x0279,0x0371,0xfdfd,0xfd32,0xfddf,0xfd59,0xfcf1,
-0xfd0a,0x03ad,0x02bd,0x02d7,0xfd7b,0xfd64,0xfc1b,0xfc9f,
-0xfc3f,0xfdfc,0x03b1,0x0234,0x027c,0xfdf7,0xfdb5,0xfd43,
-0xfc97,0xfd91,0xfcea,0x0200,0x0233,0x0319,0xfdcd,0xfce6,
-0xfc97,0xfe00,0xfd95,0xfd99,0x03d8,0x022c,0x023a,0xfdea,
-0xfddc,0xfd94,0xfc4f,0xfda4,0xfd84,0x03d8,0x021c,0x02e4,
-0xfdf9,0xfd38,0xfcf2,0xfc4e,0xfdc6,0xfde8,0x020f,0x02fc,
-0x036a,0xfced,0xfc7b,0xfd74,0xfde1,0xfdc6,0xfd15,0x0212,
-0x0298,0x03f6,0xfd50,0xfdf3,0xfd6e,0xfddb,0xfca2,0xfc13,
-0x0222,0x0203,0x0209,0xfdda,0xfdd4,0xfdf3,0xfdb8,0xfdf9,
-0xfded,0x022a,0x03a6,0x02a0,0xfc0d,0xfd28,0xfd9b,0xfda8,
-0xfcac,0xfc8e,0x0256,0x03b1,0x022c,0xfdd8,0xfd76,0xfdff,
-0xfd44,0xfc98,0xfda5,0x0273,0x0213,0x02dd,0xfd75,0xfc7d,
-0xfd08,0xfcff,0xfdd9,0xfdf3,0x0240,0x03fc,0x03f6,0xfdc2,
-0xfdc5,0xfc0d,0xfd76,0xfc08,0xfc13,0x026f,0x039c,0x0252,
-0xfdcd,0xfd2c,0xfde7,0xfd09,0xfcbd,0xfd4d,0x02a6,0x038d,
-0x025b,0xfda6,0xfce0,0xfde8,0xfc7d,0xfcd9,0xfd38,0x032e,
-0x02e8,0x021f,0xfdb0,0xfc9f,0xfcea,0xfd78,0xfde3,0xfdbf};
-
-static const unsigned short wavtable2[2304]={
-0x0e,0x0e,0x0e,0x14,0x14,0x13,0x15,0x14,0x14,0x0e,0x0e,0x0e,
-0x14,0x14,0x14,0x14,0x15,0x15,0x0e,0x0d,0x0e,0x12,0x14,0x13,
-0x15,0x12,0x15,0x0d,0x0d,0x0e,0x12,0x13,0x13,0x13,0x12,0x15,
-0x0d,0x0e,0x0d,0x13,0x12,0x12,0x13,0x14,0x13,0x0d,0x0e,0x0f,
-0x13,0x13,0x14,0x13,0x15,0x16,0x0d,0x0d,0x0d,0x11,0x11,0x12,
-0x12,0x13,0x13,0x0c,0x0e,0x0d,0x12,0x11,0x13,0x11,0x14,0x13,
-0x0d,0x0d,0x0d,0x12,0x12,0x11,0x13,0x12,0x12,0x0d,0x0d,0x0c,
-0x12,0x11,0x11,0x12,0x13,0x11,0x0d,0x0c,0x0d,0x11,0x11,0x10,
-0x12,0x11,0x12,0x0c,0x0d,0x0c,0x11,0x10,0x11,0x11,0x13,0x11,
-0x0c,0x0d,0x0d,0x10,0x11,0x11,0x11,0x12,0x12,0x0c,0x0d,0x0d,
-0x10,0x10,0x11,0x10,0x13,0x12,0x0c,0x0c,0x0d,0x0f,0x10,0x10,
-0x10,0x11,0x12,0x0b,0x0d,0x0d,0x0f,0x0f,0x11,0x0f,0x12,0x12,
-0x0d,0x0c,0x0d,0x10,0x11,0x11,0x12,0x10,0x13,0x0c,0x0c,0x0c,
-0x10,0x10,0x10,0x11,0x10,0x11,0x0d,0x0c,0x0c,0x11,0x11,0x0f,
-0x13,0x10,0x10,0x0d,0x0c,0x0b,0x10,0x10,0x0e,0x13,0x10,0x0f,
-0x0c,0x0c,0x0c,0x10,0x10,0x10,0x11,0x11,0x11,0x0c,0x0d,0x0b,
-0x10,0x0f,0x10,0x11,0x12,0x0f,0x0c,0x0c,0x0b,0x10,0x0e,0x0f,
-0x10,0x11,0x0f,0x0b,0x0d,0x0c,0x0f,0x0f,0x10,0x0f,0x12,0x10,
-0x0c,0x0c,0x0c,0x0f,0x0f,0x0f,0x10,0x10,0x10,0x0b,0x0c,0x0c,
-0x0f,0x0e,0x0f,0x0f,0x10,0x10,0x0b,0x0c,0x0c,0x0f,0x0f,0x10,
-0x0f,0x10,0x11,0x0b,0x0c,0x0d,0x0f,0x0f,0x10,0x0e,0x11,0x12,
-0x0b,0x0c,0x0b,0x0f,0x0e,0x0f,0x0f,0x11,0x0f,0x0b,0x0c,0x0b,
-0x0f,0x0e,0x0f,0x0e,0x11,0x0f,0x0b,0x0d,0x0c,0x0f,0x0e,0x10,
-0x0e,0x12,0x11,0x0b,0x0c,0x0c,0x0e,0x0e,0x10,0x0e,0x11,0x11,
-0x0c,0x0c,0x0c,0x0f,0x10,0x0f,0x11,0x10,0x11,0x0c,0x0b,0x0c,
-0x0f,0x10,0x0f,0x11,0x0f,0x10,0x0c,0x0c,0x0b,0x0f,0x0f,0x0f,
-0x11,0x10,0x0f,0x0c,0x0c,0x0b,0x0f,0x0e,0x0e,0x10,0x10,0x0f,
-0x0d,0x0b,0x0b,0x0f,0x0f,0x0e,0x12,0x0f,0x0f,0x0c,0x0b,0x0a,
-0x0f,0x0e,0x0d,0x11,0x0f,0x0d,0x0b,0x0b,0x0b,0x0e,0x0e,0x0e,
-0x0f,0x0f,0x0e,0x0b,0x0b,0x0a,0x0e,0x0d,0x0d,0x0f,0x0f,0x0d,
-0x0c,0x0b,0x0c,0x0e,0x0f,0x0f,0x10,0x0f,0x11,0x0b,0x0b,0x0c,
-0x0e,0x0f,0x0f,0x0f,0x0f,0x10,0x0b,0x0c,0x0b,0x0e,0x0e,0x0e,
-0x0f,0x10,0x0f,0x0b,0x0b,0x0b,0x0e,0x0e,0x0e,0x0e,0x0f,0x0f,
-0x0b,0x0b,0x0c,0x0e,0x0e,0x0f,0x0e,0x0f,0x10,0x0b,0x0b,0x0c,
-0x0e,0x0e,0x0f,0x0e,0x0f,0x11,0x0b,0x0c,0x0c,0x0e,0x0e,0x0f,
-0x0e,0x10,0x10,0x0a,0x0c,0x0c,0x0d,0x0e,0x0f,0x0d,0x10,0x10,
-0x0b,0x0c,0x0b,0x0e,0x0d,0x0e,0x0e,0x10,0x0e,0x0b,0x0b,0x0b,
-0x0e,0x0d,0x0e,0x0e,0x0f,0x0e,0x0a,0x0c,0x0b,0x0e,0x0d,0x0e,
-0x0d,0x11,0x0e,0x0a,0x0c,0x0b,0x0e,0x0d,0x0e,0x0d,0x10,0x0e,
-0x0b,0x0b,0x0b,0x0d,0x0d,0x0e,0x0e,0x0f,0x0f,0x0a,0x0b,0x0b,
-0x0d,0x0d,0x0e,0x0d,0x0f,0x0f,0x0a,0x0b,0x0c,0x0d,0x0e,0x0e,
-0x0d,0x0f,0x10,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x0d,0x0f,0x10,
-0x0b,0x0c,0x0b,0x0e,0x0d,0x0f,0x0e,0x10,0x0f,0x0a,0x0c,0x0c,
-0x0e,0x0d,0x0f,0x0d,0x11,0x10,0x0a,0x0d,0x0c,0x0e,0x0e,0x10,
-0x0d,0x12,0x10,0x0a,0x0c,0x0d,0x0e,0x0e,0x10,0x0d,0x11,0x12,
-0x0a,0x0c,0x0b,0x0d,0x0d,0x0f,0x0d,0x10,0x0f,0x0a,0x0c,0x0b,
-0x0d,0x0d,0x0f,0x0d,0x10,0x0f,0x0a,0x0c,0x0c,0x0e,0x0d,0x10,
-0x0d,0x11,0x10,0x0a,0x0c,0x0c,0x0d,0x0e,0x10,0x0c,0x10,0x11,
-0x0c,0x0b,0x0c,0x0f,0x10,0x0e,0x11,0x0e,0x10,0x0c,0x0b,0x0b,
-0x0e,0x0f,0x0d,0x11,0x0e,0x0f,0x0b,0x0b,0x0c,0x0e,0x0e,0x0e,
-0x0f,0x0e,0x10,0x0b,0x0b,0x0b,0x0d,0x0e,0x0e,0x0e,0x0e,0x0f,
-0x0b,0x0a,0x0b,0x0d,0x0e,0x0d,0x0f,0x0d,0x0f,0x0b,0x0a,0x0b,
-0x0d,0x0e,0x0d,0x0f,0x0d,0x0f,0x0c,0x0a,0x0a,0x0e,0x0e,0x0c,
-0x11,0x0d,0x0d,0x0c,0x0a,0x0a,0x0d,0x0d,0x0b,0x10,0x0d,0x0c,
-0x0b,0x0b,0x0b,0x0e,0x0e,0x0d,0x0f,0x0e,0x0e,0x0b,0x0b,0x0a,
-0x0d,0x0d,0x0d,0x0f,0x0e,0x0d,0x0b,0x0b,0x0a,0x0e,0x0c,0x0d,
-0x0e,0x0f,0x0d,0x0a,0x0c,0x0a,0x0e,0x0c,0x0d,0x0d,0x10,0x0c,
-0x0b,0x0b,0x0b,0x0d,0x0e,0x0d,0x0e,0x0e,0x0f,0x0b,0x0b,0x0b,
-0x0d,0x0d,0x0d,0x0e,0x0e,0x0e,0x0a,0x0b,0x0b,0x0d,0x0d,0x0e,
-0x0d,0x0e,0x0f,0x0a,0x0b,0x0b,0x0c,0x0d,0x0d,0x0d,0x0e,0x0f,
-0x0b,0x0a,0x0b,0x0d,0x0d,0x0d,0x0e,0x0d,0x0e,0x0b,0x0b,0x0a,
-0x0d,0x0c,0x0d,0x0e,0x0e,0x0d,0x0b,0x0a,0x0a,0x0c,0x0c,0x0c,
-0x0e,0x0d,0x0d,0x0a,0x0a,0x0a,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,
-0x0b,0x0b,0x0a,0x0d,0x0c,0x0c,0x0e,0x0e,0x0c,0x0a,0x0b,0x0a,
-0x0d,0x0c,0x0c,0x0d,0x0e,0x0c,0x0a,0x0b,0x0a,0x0c,0x0b,0x0c,
-0x0d,0x0e,0x0c,0x0a,0x0b,0x0a,0x0c,0x0b,0x0c,0x0c,0x0e,0x0c,
-0x0a,0x0a,0x0b,0x0c,0x0d,0x0d,0x0d,0x0d,0x0f,0x0a,0x0a,0x0b,
-0x0c,0x0d,0x0d,0x0d,0x0d,0x0e,0x0a,0x0b,0x0b,0x0c,0x0c,0x0d,
-0x0c,0x0e,0x0e,0x0a,0x0b,0x0b,0x0c,0x0d,0x0d,0x0c,0x0e,0x0f,
-0x0a,0x0a,0x0b,0x0c,0x0c,0x0c,0x0c,0x0d,0x0e,0x0a,0x0a,0x0a,
-0x0b,0x0c,0x0c,0x0c,0x0d,0x0d,0x0a,0x0a,0x0b,0x0b,0x0c,0x0c,
-0x0c,0x0d,0x0e,0x09,0x0a,0x0b,0x0b,0x0c,0x0d,0x0b,0x0d,0x0e,
-0x0b,0x0b,0x0b,0x0d,0x0d,0x0d,0x0e,0x0f,0x0e,0x0a,0x0b,0x0b,
-0x0d,0x0c,0x0d,0x0d,0x0f,0x0e,0x0a,0x0b,0x0a,0x0d,0x0c,0x0d,
-0x0d,0x0f,0x0d,0x0a,0x0b,0x0b,0x0d,0x0c,0x0d,0x0c,0x0f,0x0e,
-0x0a,0x0b,0x0b,0x0d,0x0d,0x0e,0x0d,0x0f,0x0f,0x0a,0x0b,0x0b,
-0x0d,0x0d,0x0e,0x0c,0x0f,0x0f,0x0a,0x0b,0x0b,0x0d,0x0d,0x0e,
-0x0c,0x0f,0x0f,0x0a,0x0b,0x0c,0x0c,0x0d,0x0f,0x0c,0x0f,0x10,
-0x0a,0x0c,0x0b,0x0e,0x0c,0x0e,0x0d,0x10,0x0e,0x0a,0x0c,0x0b,
-0x0e,0x0c,0x0f,0x0c,0x11,0x0e,0x0a,0x0c,0x0c,0x0d,0x0d,0x0f,
-0x0c,0x10,0x10,0x0a,0x0d,0x0c,0x0e,0x0d,0x10,0x0c,0x12,0x11,
-0x0a,0x0c,0x0b,0x0d,0x0c,0x0f,0x0c,0x10,0x0f,0x0a,0x0c,0x0b,
-0x0d,0x0c,0x0e,0x0c,0x10,0x0f,0x0a,0x0c,0x0c,0x0d,0x0d,0x0f,
-0x0c,0x11,0x10,0x0a,0x0c,0x0c,0x0d,0x0d,0x10,0x0c,0x10,0x11,
-0x0a,0x0c,0x0a,0x0d,0x0c,0x0e,0x0c,0x10,0x0d,0x0a,0x0c,0x0b,
-0x0d,0x0c,0x0e,0x0c,0x10,0x0e,0x0a,0x0c,0x0a,0x0d,0x0b,0x0d,
-0x0c,0x10,0x0d,0x0a,0x0b,0x0b,0x0c,0x0c,0x0e,0x0c,0x0f,0x0e,
-0x0a,0x0b,0x0b,0x0c,0x0c,0x0d,0x0c,0x0e,0x0e,0x0a,0x0b,0x0b,
-0x0c,0x0c,0x0e,0x0c,0x0f,0x0f,0x09,0x0b,0x0b,0x0c,0x0c,0x0e,
-0x0b,0x0f,0x0f,0x09,0x0b,0x0c,0x0c,0x0d,0x0e,0x0b,0x0f,0x10,
-0x0a,0x0c,0x0b,0x0d,0x0c,0x0f,0x0c,0x11,0x0e,0x09,0x0c,0x0b,
-0x0d,0x0c,0x0f,0x0b,0x11,0x0f,0x09,0x0c,0x0c,0x0d,0x0c,0x0f,
-0x0b,0x10,0x10,0x09,0x0c,0x0c,0x0d,0x0d,0x10,0x0b,0x11,0x11,
-0x09,0x0c,0x0b,0x0d,0x0c,0x0f,0x0b,0x11,0x0e,0x09,0x0c,0x0c,
-0x0d,0x0c,0x10,0x0b,0x11,0x10,0x09,0x0c,0x0c,0x0d,0x0c,0x0f,
-0x0b,0x11,0x10,0x09,0x0d,0x0c,0x0d,0x0d,0x10,0x0b,0x12,0x11,
-0x0c,0x0a,0x0b,0x0d,0x0e,0x0c,0x10,0x0c,0x0e,0x0b,0x0a,0x0a,
-0x0c,0x0d,0x0c,0x0e,0x0c,0x0d,0x0a,0x0a,0x0b,0x0c,0x0d,0x0c,
-0x0d,0x0c,0x0f,0x0a,0x0a,0x0a,0x0c,0x0c,0x0c,0x0d,0x0c,0x0d,
-0x0b,0x09,0x0a,0x0c,0x0d,0x0b,0x0f,0x0b,0x0d,0x0b,0x0a,0x0a,
-0x0c,0x0c,0x0b,0x0e,0x0c,0x0c,0x0a,0x0a,0x09,0x0b,0x0b,0x0b,
-0x0d,0x0c,0x0b,0x0a,0x0a,0x09,0x0b,0x0b,0x0a,0x0d,0x0c,0x0a,
-0x0a,0x0a,0x0a,0x0c,0x0c,0x0c,0x0d,0x0d,0x0d,0x0a,0x0a,0x0a,
-0x0c,0x0b,0x0c,0x0c,0x0d,0x0d,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,
-0x0c,0x0c,0x0d,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0c,0x0c,
-0x0a,0x0a,0x0a,0x0c,0x0b,0x0b,0x0c,0x0d,0x0c,0x0a,0x0a,0x09,
-0x0b,0x0b,0x0b,0x0c,0x0d,0x0b,0x09,0x0a,0x09,0x0b,0x0a,0x0b,
-0x0b,0x0c,0x0b,0x09,0x0a,0x09,0x0b,0x0a,0x0b,0x0b,0x0d,0x0b,
-0x0a,0x09,0x0b,0x0b,0x0c,0x0b,0x0d,0x0b,0x0e,0x0a,0x0a,0x0a,
-0x0b,0x0c,0x0b,0x0d,0x0c,0x0d,0x0a,0x0a,0x0a,0x0b,0x0c,0x0c,
-0x0c,0x0c,0x0d,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x0d,
-0x0a,0x09,0x0a,0x0b,0x0c,0x0a,0x0d,0x0b,0x0c,0x0a,0x09,0x0a,
-0x0b,0x0b,0x0a,0x0c,0x0b,0x0c,0x09,0x0a,0x0a,0x0b,0x0b,0x0b,
-0x0b,0x0c,0x0c,0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,
-0x09,0x0a,0x0a,0x0b,0x0b,0x0c,0x0b,0x0d,0x0d,0x09,0x0a,0x0a,
-0x0b,0x0b,0x0c,0x0b,0x0d,0x0d,0x09,0x0a,0x0b,0x0b,0x0b,0x0c,
-0x0b,0x0c,0x0e,0x09,0x0a,0x0b,0x0b,0x0b,0x0c,0x0b,0x0d,0x0e,
-0x09,0x0a,0x0a,0x0a,0x0a,0x0b,0x0b,0x0c,0x0c,0x09,0x0a,0x0a,
-0x0a,0x0a,0x0b,0x0a,0x0c,0x0d,0x09,0x09,0x0a,0x0a,0x0a,0x0b,
-0x0a,0x0b,0x0c,0x09,0x0a,0x0a,0x0a,0x0a,0x0c,0x0a,0x0c,0x0d,
-0x0a,0x0b,0x0a,0x0c,0x0c,0x0d,0x0d,0x0e,0x0d,0x0a,0x0b,0x0a,
-0x0c,0x0c,0x0d,0x0c,0x0e,0x0d,0x0a,0x0b,0x0a,0x0c,0x0b,0x0d,
-0x0c,0x0f,0x0d,0x0a,0x0b,0x0a,0x0c,0x0b,0x0d,0x0c,0x0e,0x0d,
-0x0a,0x0a,0x0a,0x0c,0x0b,0x0c,0x0c,0x0d,0x0d,0x0a,0x0a,0x0a,
-0x0b,0x0b,0x0c,0x0c,0x0d,0x0d,0x09,0x0b,0x0a,0x0c,0x0b,0x0c,
-0x0b,0x0e,0x0d,0x09,0x0b,0x0a,0x0b,0x0b,0x0c,0x0b,0x0e,0x0d,
-0x0a,0x0b,0x0b,0x0c,0x0c,0x0d,0x0c,0x0e,0x0e,0x09,0x0b,0x0b,
-0x0c,0x0c,0x0d,0x0b,0x0e,0x0e,0x09,0x0b,0x0b,0x0b,0x0c,0x0d,
-0x0b,0x0e,0x0f,0x09,0x0b,0x0c,0x0b,0x0c,0x0e,0x0b,0x0e,0x10,
-0x09,0x0b,0x0b,0x0c,0x0b,0x0d,0x0b,0x0e,0x0e,0x09,0x0b,0x0b,
-0x0c,0x0c,0x0d,0x0b,0x0e,0x0e,0x09,0x0b,0x0b,0x0b,0x0c,0x0d,
-0x0b,0x0e,0x0f,0x09,0x0b,0x0c,0x0b,0x0c,0x0e,0x0a,0x0e,0x10,
-0x09,0x0b,0x0a,0x0c,0x0b,0x0d,0x0b,0x0f,0x0d,0x09,0x0b,0x0b,
-0x0c,0x0b,0x0e,0x0b,0x0f,0x0e,0x09,0x0c,0x0a,0x0c,0x0b,0x0d,
-0x0b,0x10,0x0d,0x09,0x0b,0x0b,0x0c,0x0b,0x0e,0x0b,0x0f,0x0e,
-0x09,0x0b,0x0b,0x0c,0x0c,0x0e,0x0b,0x0f,0x0f,0x09,0x0b,0x0c,
-0x0c,0x0c,0x0f,0x0b,0x0f,0x10,0x09,0x0c,0x0b,0x0c,0x0c,0x0e,
-0x0b,0x10,0x0f,0x09,0x0c,0x0c,0x0c,0x0d,0x0f,0x0b,0x10,0x10,
-0x09,0x0c,0x0b,0x0d,0x0b,0x0e,0x0b,0x11,0x0e,0x09,0x0c,0x0b,
-0x0d,0x0c,0x0f,0x0b,0x11,0x0f,0x09,0x0c,0x0b,0x0c,0x0c,0x0e,
-0x0a,0x10,0x0f,0x09,0x0c,0x0c,0x0c,0x0c,0x0f,0x0a,0x10,0x10,
-0x09,0x0c,0x0b,0x0d,0x0b,0x0f,0x0a,0x11,0x0e,0x09,0x0d,0x0c,
-0x0d,0x0c,0x10,0x0a,0x12,0x10,0x09,0x0d,0x0c,0x0d,0x0c,0x10,
-0x0a,0x12,0x10,0x09,0x0c,0x0d,0x0d,0x0d,0x10,0x0a,0x11,0x12,
-0x0a,0x0b,0x0a,0x0c,0x0b,0x0c,0x0c,0x0f,0x0c,0x09,0x0b,0x0a,
-0x0c,0x0a,0x0c,0x0b,0x0f,0x0c,0x09,0x0a,0x0a,0x0b,0x0b,0x0c,
-0x0b,0x0d,0x0c,0x09,0x0a,0x0a,0x0b,0x0a,0x0b,0x0a,0x0d,0x0c,
-0x09,0x0b,0x0a,0x0c,0x0b,0x0c,0x0b,0x0e,0x0d,0x09,0x0b,0x0a,
-0x0b,0x0b,0x0c,0x0b,0x0e,0x0d,0x09,0x0b,0x0a,0x0c,0x0b,0x0d,
-0x0a,0x0f,0x0d,0x09,0x0b,0x0b,0x0c,0x0b,0x0e,0x0a,0x0f,0x0e,
-0x09,0x0a,0x0a,0x0b,0x0b,0x0c,0x0a,0x0d,0x0d,0x09,0x0b,0x0a,
-0x0b,0x0a,0x0c,0x0a,0x0e,0x0c,0x09,0x0a,0x0a,0x0b,0x0b,0x0c,
-0x0a,0x0d,0x0d,0x09,0x0a,0x0b,0x0b,0x0b,0x0d,0x0a,0x0d,0x0e,
-0x09,0x0b,0x0b,0x0b,0x0b,0x0d,0x0a,0x0e,0x0e,0x09,0x0b,0x0b,
-0x0b,0x0c,0x0e,0x0a,0x0e,0x0f,0x09,0x0b,0x0b,0x0b,0x0b,0x0d,
-0x0a,0x0e,0x0e,0x09,0x0b,0x0b,0x0b,0x0b,0x0e,0x0a,0x0e,0x0f,
-0x09,0x0c,0x0a,0x0c,0x0b,0x0d,0x0b,0x10,0x0d,0x09,0x0c,0x0a,
-0x0c,0x0b,0x0e,0x0a,0x10,0x0d,0x09,0x0b,0x0b,0x0c,0x0b,0x0e,
-0x0a,0x0f,0x0e,0x09,0x0b,0x0b,0x0c,0x0c,0x0e,0x0a,0x0f,0x0f,
-0x09,0x0c,0x0b,0x0c,0x0b,0x0e,0x0a,0x10,0x0f,0x09,0x0c,0x0c,
-0x0c,0x0c,0x0f,0x0a,0x10,0x10,0x09,0x0c,0x0b,0x0d,0x0c,0x0f,
-0x0a,0x11,0x0f,0x09,0x0d,0x0c,0x0d,0x0c,0x10,0x0a,0x12,0x11,
-0x09,0x0b,0x0a,0x0c,0x0b,0x0d,0x0a,0x0f,0x0d,0x09,0x0c,0x0b,
-0x0c,0x0b,0x0e,0x0a,0x10,0x0e,0x09,0x0c,0x0b,0x0c,0x0b,0x0e,
-0x0a,0x10,0x0f,0x09,0x0b,0x0c,0x0c,0x0c,0x0f,0x0a,0x0f,0x10,
-0x09,0x0c,0x0b,0x0c,0x0b,0x0f,0x0a,0x11,0x0e,0x09,0x0c,0x0c,
-0x0c,0x0c,0x10,0x0a,0x11,0x10,0x08,0x0c,0x0b,0x0c,0x0b,0x0e,
-0x09,0x10,0x0f,0x08,0x0c,0x0c,0x0c,0x0c,0x0f,0x09,0x11,0x10,
-0x0a,0x09,0x09,0x0a,0x0b,0x0a,0x0c,0x0a,0x0b,0x09,0x09,0x09,
-0x0a,0x0a,0x09,0x0b,0x0a,0x0a,0x09,0x0a,0x09,0x0a,0x0a,0x0a,
-0x0b,0x0c,0x0b,0x09,0x09,0x09,0x0a,0x09,0x0a,0x0a,0x0b,0x0a,
-0x09,0x09,0x0a,0x0a,0x0a,0x0b,0x0b,0x0b,0x0c,0x09,0x09,0x0a,
-0x09,0x0a,0x0a,0x0a,0x0a,0x0c,0x09,0x09,0x09,0x09,0x09,0x0a,
-0x0a,0x0b,0x0b,0x08,0x09,0x09,0x09,0x09,0x0a,0x09,0x0b,0x0b,
-0x09,0x0a,0x09,0x0a,0x0a,0x0b,0x0a,0x0c,0x0b,0x08,0x0a,0x09,
-0x0a,0x09,0x0a,0x09,0x0c,0x0b,0x08,0x0a,0x0a,0x0a,0x09,0x0b,
-0x09,0x0c,0x0c,0x08,0x09,0x0a,0x09,0x0a,0x0b,0x09,0x0b,0x0d,
-0x09,0x09,0x09,0x09,0x09,0x09,0x0a,0x0a,0x0a,0x07,0x08,0x08,
-0x07,0x07,0x07,0x07,0x08,0x08,0x08,0x0a,0x09,0x09,0x09,0x0a,
-0x08,0x0c,0x0b,0x08,0x09,0x09,0x08,0x08,0x0a,0x08,0x0a,0x0b,
-0x09,0x0b,0x0a,0x0b,0x0a,0x0c,0x0a,0x0f,0x0c,0x09,0x0b,0x0a,
-0x0b,0x0a,0x0d,0x0a,0x0f,0x0c,0x09,0x0a,0x0a,0x0a,0x0a,0x0c,
-0x0a,0x0d,0x0d,0x08,0x0a,0x0b,0x0a,0x0b,0x0d,0x09,0x0d,0x0e,
-0x09,0x0b,0x0a,0x0b,0x0a,0x0d,0x0a,0x0f,0x0d,0x09,0x0b,0x0b,
-0x0b,0x0b,0x0e,0x0a,0x0f,0x0e,0x08,0x0b,0x0b,0x0b,0x0b,0x0d,
-0x09,0x0e,0x0e,0x08,0x0b,0x0c,0x0b,0x0b,0x0e,0x09,0x0f,0x10,
-0x08,0x0a,0x09,0x0a,0x09,0x0b,0x09,0x0d,0x0b,0x08,0x0b,0x0a,
-0x0b,0x0a,0x0c,0x09,0x0e,0x0d,0x08,0x0b,0x0a,0x0a,0x0a,0x0c,
-0x09,0x0e,0x0d,0x08,0x0a,0x0b,0x0a,0x0b,0x0d,0x09,0x0d,0x0e,
-0x08,0x0c,0x0b,0x0b,0x0a,0x0e,0x09,0x10,0x0e,0x08,0x0c,0x0b,
-0x0b,0x0b,0x0e,0x09,0x10,0x0f,0x08,0x0b,0x0a,0x0a,0x0a,0x0c,
-0x09,0x0e,0x0d,0x08,0x0b,0x0a,0x0a,0x0a,0x0d,0x08,0x0e,0x0d};
-
-static const signed short etable1[5120]={
-0x0026,0xfffc,0x000f,0xfffc,0x000e,0xfff3,0x000c,0xfff5,
-0xfffe,0xfffa,0xfffa,0xfff5,0xffd3,0xfff0,0xfff5,0xfff3,
-0xfff9,0x0006,0xfff4,0x0004,0xffec,0x0003,0xfff0,0x000c,
-0xffff,0x000c,0x002e,0x0018,0x0000,0x0021,0xfffd,0x0009,
-0xfff4,0xfff4,0xfff8,0xfff9,0x0011,0xfffa,0x0000,0xfffe,
-0x003c,0xfff0,0x0003,0xffea,0x000a,0xffe0,0x0000,0xffe4,
-0xffef,0xffee,0xfffd,0xffe7,0xffdb,0xffe9,0xfff6,0x0003,
-0x0002,0x0003,0x0000,0x0003,0xfff2,0x0000,0xfff2,0xffff,
-0x0000,0x0002,0x0020,0x0009,0xffff,0x0019,0x0007,0x000d,
-0xfffb,0x000d,0x0008,0x0001,0x0002,0x0008,0xfff6,0x0006,
-0x001b,0xfff4,0x001c,0xfffe,0x0006,0xfff9,0x000f,0x0009,
-0xfff5,0x0001,0xfff3,0xfff5,0xffd8,0x0004,0xffe3,0xfff2,
-0xffed,0xfffb,0xffe9,0xfff8,0xffe2,0xfff3,0xffef,0x0000,
-0xfff2,0x000c,0x0022,0x0014,0xfffe,0x0019,0x0002,0xfff0,
-0xfffc,0xfff4,0x000f,0x0010,0x001d,0x0007,0x0018,0x000a,
-0x0031,0xffe8,0x0010,0xffec,0x0002,0xffe6,0x0002,0xfff9,
-0xffe7,0xfff6,0xfff5,0xffe7,0xffe0,0xfffd,0xffe5,0x0002,
-0xfff8,0xfff8,0xfff5,0xfff7,0xffe8,0xffef,0xfff0,0xfff2,
-0xfff3,0x0002,0x0014,0x0005,0xfffc,0x0011,0x000e,0xfff4,
-0x0003,0x000d,0x0021,0x0019,0x000e,0x0017,0x000f,0x0013,
-0x002e,0xfffa,0x0015,0x0008,0xfffe,0xfff0,0xfffb,0xfff8,
-0xfff5,0x0004,0x0008,0x000f,0xffe8,0x0004,0xfffe,0xffe6,
-0xfffd,0xfff0,0xfff0,0xfff2,0xfff7,0xfffe,0xffff,0x0004,
-0x0013,0x0007,0x0024,0x0011,0x0009,0x000d,0x0000,0x001f,
-0xfffb,0xfff4,0x0007,0xfff8,0x000b,0xfff1,0xfff3,0xfffc,
-0x0044,0xffee,0x0009,0xfff7,0xfffa,0xffdd,0xffee,0xffe7,
-0xffe6,0xfff9,0x000a,0x0001,0xfff0,0xfffd,0xffff,0xfff7,
-0x0006,0xffed,0xfffc,0xfff1,0xfffc,0xfffa,0x0000,0xfff8,
-0x0014,0xfffe,0x0017,0x0002,0x0007,0x0005,0x000c,0x0023,
-0x0001,0x000d,0x0018,0x0000,0xfffd,0x0000,0xffea,0x0004,
-0x0023,0xfff2,0x0022,0x000a,0xfff6,0xfff6,0xffff,0x000c,
-0xffec,0x000c,0x0000,0x000f,0xffee,0x0018,0xffec,0xffe5,
-0xfff2,0xffe4,0xffe5,0xffe5,0xffec,0xffed,0xfffe,0xfff8,
-0x0005,0x0007,0x0019,0x000d,0x0005,0x0005,0x0006,0x0005,
-0x0002,0xfff4,0x001f,0x000f,0x0017,0xffff,0x000c,0x0008,
-0x0039,0xffe6,0x0016,0xfff9,0xfff2,0xffe4,0xfff2,0xfffd,
-0xffdd,0x0000,0x0003,0x0001,0xfff5,0x0010,0xffee,0xfff6,
-0xfffc,0xffe1,0xfff1,0xffe4,0xfff2,0xffe9,0xffff,0xffeb,
-0x0007,0xfffe,0x000b,0xffff,0x0003,0xffff,0x0012,0x0009,
-0x000a,0x000d,0x0031,0x0018,0x0008,0x000e,0x0002,0x0010,
-0x0019,0x000f,0x0016,0x000b,0x0012,0x0004,0x000f,0xffea,
-0x0008,0xfffe,0xffef,0xfff7,0xffd0,0xffec,0xffe2,0xffef,
-0xfff0,0x000b,0xffff,0x0010,0x0002,0x000a,0xfffb,0x001a,
-0xfffe,0xfffc,0x0016,0x0000,0x0002,0x000a,0xfffa,0x000d,
-0xfff2,0x000a,0xffe9,0x0000,0x000a,0xfffe,0x0001,0x0000,
-0x002f,0x0003,0x000b,0xfffa,0x000f,0xfff3,0x0002,0xffda,
-0xfffa,0xfff3,0xfff1,0xffea,0xffd8,0xffe4,0xffe4,0x0000,
-0xfffb,0x0008,0x000a,0x000f,0x0007,0x0007,0xfffc,0x000d,
-0xffff,0xfff2,0x0009,0xfff2,0x0000,0x0002,0x0004,0x0012,
-0xfff9,0x0024,0xfffa,0x0008,0xfffd,0x000d,0xfff9,0x0008,
-0x000e,0x0007,0x0024,0x000d,0x000a,0x000a,0x0012,0x0000,
-0x0000,0x0005,0xffe7,0xfff8,0xffd5,0x0000,0xffd0,0xffee,
-0xffe5,0x0000,0xfff4,0x0003,0xfff9,0xfffa,0xfff9,0x000d,
-0xfff1,0xfffb,0x000b,0xfffd,0x0000,0x0002,0x0000,0xfff4,
-0xfffa,0x000a,0x0000,0x0017,0x0016,0x000b,0x001a,0x000c,
-0x0024,0xfffb,0x0018,0xfffc,0x0007,0xfff9,0x0006,0xffef,
-0xfff2,0xfffb,0xffea,0xffea,0xffdd,0xfff8,0xffd2,0xffff,
-0xffef,0xfffd,0x0000,0x0002,0xfffe,0xfff6,0xfffb,0x0000,
-0xfff2,0xfff1,0xfffe,0xffee,0xfffe,0xfffc,0x000b,0xfff9,
-0x0001,0x0024,0x0012,0x0020,0x0007,0x001b,0x0011,0x0014,
-0x0021,0x000d,0x001d,0x0018,0x0001,0x0001,0xfffe,0xffee,
-0x0000,0x0009,0xfffd,0x0011,0xffe5,0x0000,0xffeb,0xffe2,
-0xfff4,0xfff5,0xfffb,0xfffe,0x000c,0x0004,0x0009,0x0013,
-0x0012,0xfff7,0x000d,0xfffa,0x000b,0xfff8,0xfffe,0x0023,
-0xfff8,0x000a,0xfff9,0xffff,0x0004,0xfff5,0xfff6,0xfffe,
-0x0037,0x0001,0x0011,0x0006,0xffff,0xfff0,0xfff1,0xffdd,
-0xfff1,0xfffe,0x0000,0x0004,0xffed,0xfff8,0xffec,0xfff3,
-0xffff,0xfff2,0x0007,0xfffd,0x0012,0x0000,0x000a,0x0005,
-0x0013,0xffed,0x0000,0xffeb,0x0008,0xfff0,0x0009,0x0027,
-0x0000,0x0024,0x000a,0x0007,0xfff7,0x0004,0xffec,0x0005,
-0x0016,0x0005,0x002a,0x001a,0xfffa,0x0008,0x0001,0x0002,
-0xfff7,0x0011,0xfff6,0x0012,0xffeb,0x0013,0xffd9,0xffe1,
-0xffe9,0xffe9,0xfff0,0xfff1,0x0002,0xfff4,0x0007,0x0006,
-0x0005,0xfff7,0x0001,0xfff6,0x0007,0xfff0,0x0004,0x0009,
-0x0000,0x000a,0x0011,0x0016,0x0010,0x0002,0x000e,0x0009,
-0x002c,0xfffa,0x001e,0x0008,0xfff7,0xfff6,0xfff5,0xfff2,
-0xffe9,0x0005,0xfff8,0x0004,0xfff2,0x000c,0xffdb,0xfff2,
-0xfff4,0xffe6,0xfffc,0xfff0,0x0008,0xfff0,0x0009,0xfff9,
-0x0006,0xffed,0xfff4,0xffe7,0x0005,0xffe8,0x000f,0x000d,
-0x0008,0x0024,0x0022,0x001f,0x0001,0x0012,0x0004,0x0012,
-0xfffd,0xfffb,0xfff7,0xfff9,0x000f,0xffff,0x0005,0x000d,
-0x0002,0x000c,0x0005,0x0002,0xffeb,0xffe9,0xfffe,0xfff0,
-0x0000,0x0005,0xfffa,0x000d,0xffe9,0x0003,0xffe0,0x000a,
-0xfff1,0x0008,0x002c,0x001c,0x0009,0x0025,0xfffe,0x000d,
-0xfff7,0xfff1,0xfff4,0xffe5,0xfff9,0xfff4,0x0000,0xfff5,
-0x0012,0xffef,0xffeb,0xffe7,0x000b,0xffed,0xfffa,0xfffd,
-0xfff5,0x0000,0x0007,0xfff5,0xfff3,0xffe1,0xffff,0x0000,
-0x0009,0x0001,0x0005,0x000c,0xffee,0x0000,0xffe1,0xfffe,
-0xfff3,0xffff,0x001e,0x000e,0x0007,0x001d,0x0009,0x0012,
-0xffff,0x000a,0x0004,0xffee,0xffea,0x0003,0xfff6,0xfffe,
-0xfff3,0xfff3,0x0003,0xfffb,0x0007,0x0004,0x0009,0x0022,
-0xfffb,0x0014,0xfffe,0x0003,0xfff0,0xfffd,0xffec,0xffef,
-0xfff5,0xfff9,0xffef,0x0000,0xffde,0xfff3,0xffdf,0xfffe,
-0xffe4,0x0008,0x0020,0x0018,0x0005,0x001d,0x0003,0xfff4,
-0x0000,0xfff1,0x000b,0xfffd,0x0003,0x0002,0x0018,0x0001,
-0x0008,0xffe7,0xfff8,0xffe9,0x0003,0xfff3,0xfffd,0x0011,
-0xffec,0x0008,0x0000,0xfff6,0xfff8,0xfff5,0xffee,0x0000,
-0xffff,0xfff6,0xfffb,0x0000,0xffe4,0xffef,0xffe0,0xfff1,
-0xffe6,0xffff,0x0013,0x0009,0x0003,0x0015,0x000f,0xfff9,
-0x0006,0x0009,0x001d,0x0005,0xfff6,0x0011,0x000f,0x0009,
-0x0004,0xfffa,0xfffd,0x0005,0xffff,0xfffc,0xfff5,0x0010,
-0xfffa,0x0017,0x0013,0x001d,0x0000,0xfffd,0x0006,0xffe2,
-0x0003,0xffef,0xfff6,0xfffb,0xfff3,0xfffe,0xffef,0x0003,
-0x0005,0x0003,0x0023,0x0015,0x0011,0x0011,0x0002,0x0023,
-0xfffe,0xfff1,0x0003,0xffe4,0xfff3,0xffeb,0xfff3,0xfff3,
-0x001a,0xffed,0xfff1,0xfff4,0xfffb,0xffea,0xffe8,0x0000,
-0xffeb,0x000c,0x0015,0x000f,0x0008,0xfff5,0x0007,0xfff4,
-0x000e,0xffec,0x0002,0xfffa,0xfff9,0xfffa,0xfff0,0xfff7,
-0x0006,0xfffb,0x0015,0x0007,0x000f,0x000a,0x000d,0x0027,
-0x0005,0x000a,0x0014,0xffed,0xffe4,0xfffb,0xffea,0xfffb,
-0xfffb,0xfff1,0x0009,0x0007,0xfff7,0x0002,0xfff8,0x0025,
-0xfff2,0x001f,0x000b,0x001d,0x0005,0x0010,0xfff5,0xffe2,
-0xfff9,0xffe3,0xffeb,0xffee,0xffe9,0xffed,0xffee,0xfff7,
-0xfff9,0x0003,0x0017,0x0011,0x000e,0x0009,0x0008,0x0009,
-0x0006,0xfff1,0x001b,0xfffc,0xfffe,0xfffa,0x000c,0xffff,
-0x0010,0xffe5,0xfffe,0xfff6,0xfff3,0xfff0,0xffec,0x0014,
-0xffe3,0x0014,0x000e,0x0010,0x000d,0x0008,0xfff7,0xfff3,
-0x0002,0xffdf,0xfff7,0xffed,0xffef,0xffe9,0xffef,0xffea,
-0xfffa,0xfffa,0x0009,0x0002,0x000c,0x0002,0x0014,0x000d,
-0x000d,0x000a,0x002d,0x0004,0xfff0,0x0008,0x0002,0x0007,
-0xfff0,0x000e,0xfffe,0x0008,0x0014,0x0011,0x0009,0x0002,
-0x000e,0x0010,0xfffa,0x0005,0xffe8,0xffe4,0xffeb,0xffec,
-0xfff8,0x0009,0x0004,0x0019,0xffff,0x000b,0xffea,0x0018,
-0xfff1,0xfff8,0x0015,0x0005,0x000b,0x000e,0xfffb,0x0012,
-0xfff5,0x0007,0xffe5,0xffec,0xfff2,0xfff9,0x0001,0xfff7,
-0x0006,0x0002,0xfff2,0xfff7,0x0010,0xffff,0xfffd,0xfff2,
-0x0000,0x0005,0xfffd,0xfff8,0xfff0,0xffdc,0xffed,0xfffd,
-0x0001,0x0006,0x0011,0x0018,0x0004,0x0007,0xffeb,0x000b,
-0xfff2,0xffee,0x0007,0xfff7,0x0009,0x0007,0x0006,0x0016,
-0xfffd,0x0021,0xfff6,0xfff5,0xffe4,0x0007,0xfff9,0x0000,
-0xffe6,0x0006,0x000b,0x000a,0x000c,0x0017,0x000c,0x0017,
-0x0005,0x0018,0xfff3,0x0005,0xffed,0xfff8,0xffda,0xffeb,
-0xffec,0xfffe,0xfffa,0x000c,0xfff5,0xfffb,0xffe9,0x000b,
-0xffe3,0xfff7,0x0009,0x0000,0x0007,0x0006,0x0001,0xfff9,
-0xfffe,0x0007,0xfffd,0x0003,0xfffe,0x0006,0x001b,0x0003,
-0xfffc,0xfffa,0x0000,0xfff9,0x0008,0x0004,0x0000,0x0006,
-0xfff7,0x000d,0xfff5,0xfff9,0xfff5,0xfff1,0xffdb,0xfffc,
-0xfff7,0xfffb,0x0005,0x000b,0xfffb,0xfff7,0xffea,0xffff,
-0xffe5,0xffee,0xfffc,0xfff2,0x0005,0x0000,0x000c,0xfffd,
-0x0004,0x0020,0x000e,0x000c,0xffef,0x0016,0x0011,0x000b,
-0xfff8,0x000c,0x0003,0x0015,0x0003,0x000e,0xfff8,0x0005,
-0x0004,0x001c,0x0007,0x0020,0xfffe,0xfff8,0xfff4,0xffde,
-0xfffc,0xfff4,0x0001,0x0006,0x0009,0x0004,0xfff9,0x0011,
-0x0004,0xfff3,0x000b,0xffff,0x0013,0xfffc,0x0000,0x0027,
-0xfffc,0x0007,0xfff5,0xffeb,0xffec,0xfff0,0xfff6,0xfff5,
-0x000d,0x0000,0xfff8,0x0003,0x0000,0xfffc,0xffeb,0xfff5,
-0xfff7,0x0010,0x000a,0x0012,0x0005,0xfff0,0xfff6,0xfff0,
-0x0005,0xfff1,0x000d,0x0005,0x000f,0x0001,0xfffa,0x0004,
-0x0006,0xffe9,0xfffe,0xfff0,0x0011,0xfff4,0x000a,0x002c,
-0x0003,0x0021,0x0006,0xfff4,0xffde,0xffff,0xffec,0xfffd,
-0xffee,0x0004,0x0011,0x0017,0xfffc,0x0014,0xfffc,0x001a,
-0xfffd,0x0024,0x0000,0x0020,0x0002,0x000c,0xffe3,0xffde,
-0xfff0,0xffe8,0xfff6,0xfffa,0x0000,0xfff4,0xfff8,0x0004,
-0xfff8,0xfff3,0x0000,0xfffa,0x0010,0xfff4,0x0005,0x000d,
-0x0003,0x0007,0x000d,0x0003,0xfff8,0xfffe,0x000e,0x0000,
-0x0003,0xfff9,0x0005,0x0005,0xfff8,0x0002,0xffef,0x0009,
-0xffee,0x0018,0x0002,0x0013,0x000a,0x0004,0xffe4,0xffef,
-0xfffb,0xffe4,0x0002,0xfff9,0x0004,0xfff1,0xfff9,0xfff8,
-0xfffa,0xffe9,0xfff3,0xffeb,0x000e,0xffec,0x0011,0x0012,
-0x000b,0x0021,0x001e,0x000b,0xffe9,0x000d,0x0005,0x0009,
-0x003c,0x000a,0x0007,0xffff,0x0009,0xfff8,0x0006,0xfff3,
-0x0002,0xfff1,0xffff,0xfff6,0xfff3,0xfff5,0x000f,0x0000,
-0x0006,0x0009,0xffff,0x0000,0xfff3,0x0001,0xfff5,0xfffd,
-0xfff3,0x0015,0x000d,0x001a,0xfff9,0x001f,0xfff6,0xfff9,
-0xfff0,0xffdf,0xffe1,0xfff6,0x0016,0xfff8,0x0001,0xfffe,
-0x0052,0xffff,0xfffc,0xffed,0x0006,0xffe5,0xfffa,0xffe3,
-0xfff4,0xffe6,0x0001,0xffe8,0xfffb,0xffee,0x0011,0x0011,
-0x0011,0x0006,0x000a,0x0000,0xfff9,0xfffe,0xfff7,0xfff0,
-0xfff4,0x000b,0x0000,0x000b,0xfff7,0x0017,0x0000,0xfffd,
-0xfff8,0xfff8,0xfff3,0xffff,0x0008,0x0007,0xfff9,0x0006,
-0x0031,0x0002,0x0015,0x0000,0x0001,0xfffe,0x0009,0x0008,
-0xfffa,0xfffa,0xfff8,0xfff6,0xfff8,0x0009,0xfffe,0x0000,
-0xfffc,0xfffe,0xfff3,0xfff4,0xffe9,0xfff1,0xfff4,0xfff0,
-0xffe6,0x0015,0x0002,0x0015,0xfff5,0x0017,0xfffc,0xffdf,
-0xfff9,0xffdf,0xfffa,0x000d,0x0022,0x0005,0x001b,0x000a,
-0x0047,0xfff6,0x0009,0xffef,0xffff,0xffec,0xfffd,0xfff8,
-0xffeb,0xffee,0xfffa,0xffe8,0x0000,0x0001,0x0000,0x0010,
-0x0006,0xfffb,0x0000,0xfff3,0xffef,0xffed,0xfff5,0xffe3,
-0xffe7,0x000b,0xfff5,0x0006,0xfff3,0x000f,0x0007,0xffe3,
-0x0000,0xfff8,0x000b,0x0016,0x0014,0x0015,0x0011,0x0012,
-0x0043,0x0008,0x000e,0x000b,0xfff9,0xfff5,0xfff5,0xfff7,
-0xfff9,0xfffd,0x000d,0x0010,0x0008,0x0009,0x0018,0xfff4,
-0x000a,0xfff3,0xfffb,0xffef,0xfffe,0xfffc,0x0003,0xfff6,
-0x0006,0x0011,0x0004,0x0013,0x0000,0x000b,0xfffa,0x000d,
-0xfff7,0xffdf,0xfff2,0xfff6,0x0010,0xffef,0xfff6,0xfffc,
-0x005a,0xfffd,0x0002,0xfffa,0xfff6,0xffe3,0xffe8,0xffe6,
-0xffeb,0xfff1,0x000f,0x0002,0x0010,0x0001,0x0019,0x0004,
-0x0015,0xfff0,0x0006,0xffee,0x0003,0xfff8,0x0005,0xffe8,
-0x0008,0x0007,0xfff7,0x0004,0xffff,0x0003,0x0005,0x0012,
-0xffff,0xfff9,0x0002,0xffff,0x0002,0xffff,0xffed,0x0003,
-0x0039,0x0000,0x001b,0x000d,0xfff2,0xfffb,0xfff9,0x000b,
-0xfff1,0x0004,0x0005,0x0010,0x000d,0x001d,0x0006,0xfff3,
-0x0000,0xffe7,0xfff0,0xffe1,0xfff4,0xffea,0x0002,0xffe9,
-0xfffa,0x0010,0xfff9,0x000e,0xfffe,0x0003,0x0000,0xfff4,
-0x0000,0xffdf,0x0009,0x000d,0x001c,0xfffd,0x000e,0x0007,
-0x004f,0xfff5,0x000f,0xfffc,0xffee,0xffe9,0xffec,0xfffb,
-0xffe2,0xfff9,0x0007,0x0002,0x0015,0x0015,0x0008,0x0003,
-0x000a,0xffe4,0xfffc,0xffe1,0xfffa,0xffe7,0x0003,0xffdb,
-0xfffc,0x0007,0xffec,0x0000,0xfffc,0xfffc,0x000b,0xfff9,
-0x0006,0xfff8,0x001b,0x0016,0x000e,0x000c,0x0005,0x0010,
-0x002f,0x001e,0x000f,0x000e,0x000e,0x0009,0x0009,0xffe9,
-0x000d,0xfff6,0xfff4,0xfff9,0xfff0,0xfff1,0xfffd,0xfffd,
-0xffff,0x000e,0x0009,0x000c,0x0009,0x0008,0x0000,0x000a,
-0xfff2,0x0004,0xfff7,0x0002,0xfffb,0x0008,0xfff3,0xfffd,
-0xffee,0xfff6,0xffd3,0xfffd,0x0010,0xfffc,0x0004,0x0000,
-0x0045,0x0011,0x0003,0xfffd,0x000a,0xfff8,0xfffd,0xffd8,
-0xffff,0xffeb,0xfff6,0xffeb,0xfff8,0xffe9,0xffff,0x000d,
-0x0008,0x000b,0x0015,0x000b,0x000f,0x0004,0x0000,0xfffe,
-0xfff3,0xfffb,0xffe9,0xfff4,0xfff9,0x0000,0xffff,0x0000,
-0xfff6,0x000e,0xffe4,0x0005,0x0001,0x000b,0xfffb,0x0007,
-0x0024,0x0015,0x001c,0x0010,0x0006,0x0010,0x000c,0xfffe,
-0x0004,0xfffe,0xffec,0xfff9,0xfff5,0x0004,0xffec,0xfffc,
-0xfff4,0x0002,0xffff,0x0000,0x0000,0xfff8,0xfffe,0xfffe,
-0xffe5,0x0004,0xffeb,0xfffe,0xfff7,0x0000,0xfffa,0xffe3,
-0xfff7,0xfff6,0xffeb,0x0015,0x001c,0x000a,0x001d,0x000b,
-0x003a,0x0009,0x0010,0xffff,0x0002,0xfffe,0x0000,0xffed,
-0xfff6,0xfff3,0xffef,0xffeb,0xfffd,0xfffd,0xffed,0x000c,
-0xfffe,0x0000,0x000a,0xffff,0x0005,0xfff4,0x0000,0xfff1,
-0xffe6,0xfffb,0xffde,0xfff0,0xfff5,0xfff9,0x0004,0xffe7,
-0xfffe,0x000e,0xfffd,0x001d,0x000d,0x0019,0x0014,0x0014,
-0x0037,0x001c,0x0015,0x001b,0xfffe,0x0007,0xfff8,0xffec,
-0x0004,0x0001,0x0001,0x0012,0x0005,0x0004,0x0005,0xfff0,
-0x0002,0xfff8,0x0005,0xfffb,0x0013,0x0002,0x000e,0x0003,
-0x0006,0x0000,0xffee,0xfffc,0x0002,0xfff5,0xfff8,0x0012,
-0xfff5,0xfff6,0xffe3,0xfffd,0x000a,0xfff3,0xfff8,0xfffd,
-0x004d,0x0010,0x0009,0x0009,0xfffa,0xfff5,0xffeb,0xffdb,
-0xfff6,0xfff6,0x0004,0x0005,0x000d,0xfffd,0x0007,0x0000,
-0x000d,0xfff5,0x0011,0xfffa,0x0019,0xffff,0x000f,0xfff7,
-0x0007,0xfff7,0xffe0,0xffed,0x0000,0xffee,0x0002,0x0016,
-0xfffd,0x000f,0xfff4,0x0005,0xfffc,0x0002,0xffef,0x0005,
-0x002c,0x0014,0x0022,0x001d,0xfff6,0x000d,0xfffc,0x0000,
-0xfffc,0x0009,0xfffb,0x0013,0x000a,0x0018,0xfff5,0xffef,
-0xfff8,0xffec,0xfffb,0xffed,0x0009,0xfff2,0x000c,0xfff7,
-0xfffa,0x0000,0xffe2,0xfff7,0x0000,0xffed,0xfffe,0xfff9,
-0xfffe,0xfff6,0xfffb,0x0014,0x0015,0x0001,0x0011,0x0009,
-0x0042,0x0008,0x0017,0x000b,0xfff2,0xfffb,0xffef,0xfff0,
-0xffed,0xfffe,0xfffd,0x0005,0x0012,0x0011,0xfff6,0x0000,
-0x0001,0xffe9,0x0006,0xffec,0x000f,0xffee,0x000e,0xffea,
-0xfffb,0xfff6,0xffd4,0xffe9,0xfffe,0xffe6,0x0009,0xfffd,
-0x0004,0x000e,0x000c,0x001d,0x0007,0x0010,0x0007,0x0012,
-0x0012,0x0009,0xffef,0xfffc,0x000b,0x0003,0x0000,0x000b,
-0x0007,0x0004,0x000a,0x0003,0x000a,0xffee,0x0018,0xfffd,
-0x000e,0x0007,0x0004,0x000a,0xfff0,0x0001,0xffe5,0xfffc,
-0xffe5,0x0011,0x000c,0x001e,0x0000,0x0023,0xfff7,0xfffd,
-0xfff4,0xffdc,0xffdd,0xffe2,0xfffe,0xfff3,0x0002,0xfff5,
-0x0028,0xfffe,0xffe3,0xffea,0x0007,0xfff2,0xfff4,0xfffb,
-0xfff9,0xfff9,0x000c,0xfff7,0x0012,0xffe6,0x001a,0x000e,
-0x0018,0x0004,0x0010,0x0009,0xfff6,0xfffe,0xffe6,0xffee,
-0xffe6,0x0007,0xffff,0x000f,0xffff,0x001b,0x0002,0x0000,
-0xfffc,0xfff5,0xffef,0xffeb,0xfff0,0x0001,0xfff9,0xfffd,
-0x0008,0x0001,0xfffd,0xfffe,0x0003,0x000a,0x0003,0x0020,
-0xffff,0x000c,0x0002,0x0004,0x000f,0x0001,0x0007,0xfffd,
-0x0002,0xfffc,0xfffa,0xfffd,0xffe6,0xfff1,0xffe3,0xffef,
-0xffd8,0x0011,0x0000,0x001a,0xfffe,0x001b,0xfffe,0xffe3,
-0xfffc,0xffdc,0xfff6,0xfffa,0x0009,0x0000,0x001b,0x0000,
-0x001e,0xfff5,0xfff1,0xffec,0x0000,0xfff8,0xfff7,0x000f,
-0xfff1,0x0000,0x0005,0xfff7,0x0017,0xfffa,0x0008,0x000d,
-0x000d,0xfff9,0x0005,0xfffd,0xffec,0xffed,0xffe5,0xffe1,
-0xffd9,0x0007,0xfff3,0x000b,0xfffc,0x0013,0x0008,0xffe7,
-0x0003,0xfff5,0x0007,0x0002,0xfffc,0x0010,0x0012,0x0009,
-0x001a,0x0007,0xfff5,0x0008,0xfffb,0x0001,0xffef,0x000e,
-0xffff,0x000f,0x0018,0x001e,0x0020,0x0001,0x0021,0xfff0,
-0x0012,0xfff2,0x0000,0xfff8,0xfffa,0xfffc,0xfff4,0xfff4,
-0xfffa,0x000d,0x0002,0x0017,0x0008,0x000f,0xfffc,0x0011,
-0xfffb,0xffdc,0xffee,0xffe2,0xfff8,0xffea,0xfff6,0xfff2,
-0x0030,0xfffc,0xffe9,0xfff7,0xfff7,0xffef,0xffe2,0xfffe,
-0xfff0,0x0003,0x001a,0x0010,0x0028,0xfffa,0x0023,0x0001,
-0x001c,0xffef,0x000c,0xfff7,0x0000,0xfff8,0xfff5,0xffe7,
-0xfffb,0x0003,0xfff6,0x0008,0x0006,0x0007,0x0006,0x0016,
-0x0001,0xfff5,0xffff,0xffeb,0xffea,0xfff9,0xffed,0xfffb,
-0x000f,0x0000,0x0002,0x000a,0xfff3,0x0007,0xfff2,0x0023,
-0xfff6,0x0017,0x0010,0x001f,0x0025,0x0015,0x0010,0xffef,
-0x0006,0xffe6,0xfff6,0xffeb,0xfff0,0xffeb,0xfff3,0xffe7,
-0xffed,0x000d,0xfff8,0x0013,0x0005,0x0007,0x0001,0xfff8,
-0x0002,0xffdc,0x0005,0xfffa,0x0003,0xfff8,0x000f,0xffff,
-0x0025,0xfff4,0xfff7,0xfff9,0xffef,0xfff5,0xffe6,0x0012,
-0xffe7,0x000c,0x0013,0x0011,0x002d,0x000e,0x0011,0x0000,
-0x0011,0xffe2,0x0001,0xffea,0xfff6,0xffe7,0xfff4,0xffda,
-0xffee,0x0003,0xffea,0x0004,0x0003,0x0000,0x000d,0xfffd,
-0x000a,0xfff5,0x0017,0x0002,0xfff6,0x0007,0x0005,0x0007,
-0x0005,0x001d,0xfff7,0x000b,0x000f,0x0016,0x0003,0x0000,
-0x0012,0x0008,0xffff,0x0006,0x0007,0xffe9,0x0006,0xfffa,
-0x0005,0x000c,0x000f,0x0015,0x0005,0x0008,0xffef,0x0009,
-0xffe4,0x0000,0xfff5,0x0006,0x0002,0x000c,0xfff5,0x0000,
-0xfff2,0xfff3,0xffcf,0xffea,0xfff8,0xfff7,0x0004,0xfff7,
-0x001b,0x0010,0xffeb,0xfffa,0x000c,0x0003,0xfff7,0xfff0,
-0x0003,0xfffe,0x0001,0xfff9,0x000f,0xffe1,0x0007,0x000a,
-0x0010,0x0009,0x001b,0x0015,0x000b,0x0005,0xfff0,0xfffd,
-0xffe6,0xfff7,0xffe8,0xfff9,0x0000,0x0004,0x0000,0x0004,
-0xfffa,0x000b,0xffe0,0xfff2,0xffe9,0x0006,0xfffb,0xffff,
-0xfffc,0x0014,0x0003,0x000d,0x0008,0x001c,0x0006,0x0015,
-0x000a,0x0010,0xfff8,0x0007,0x000c,0xfffd,0xfff5,0xfff9,
-0xfffb,0x0000,0x0004,0x0008,0xfffc,0xfff8,0xffee,0xfffd,
-0xffd7,0x0000,0xffea,0x0002,0x0000,0x0004,0xfffb,0xffe7,
-0xfffa,0xfff2,0xffe7,0x0001,0x0002,0x0004,0x001d,0x0002,
-0x0011,0x0008,0xfff8,0xfffc,0x0004,0x000a,0xfffa,0x0005,
-0xfffc,0x0005,0xfffa,0xfffa,0x0014,0xfff6,0xfff7,0x0009,
-0x0004,0xfffe,0x0010,0x0007,0x0001,0xfff4,0xffef,0xfff0,
-0xffd9,0xfff7,0xffdc,0xfff4,0xfffe,0xfffd,0x0006,0xffeb,
-0x0001,0x000b,0xfff9,0x000a,0xfff5,0x0014,0x0014,0x000b,
-0x000d,0x001b,0xfffd,0x0018,0xffff,0x0013,0xfff2,0x0003,
-0x0009,0x0014,0x000c,0x0021,0x001d,0xfffd,0x000f,0xffec,
-0x0009,0xfff7,0x000b,0x0003,0x0010,0x0002,0xfffe,0x0002,
-0xfff9,0xfffd,0xffec,0x0000,0x000a,0xfff9,0xfff9,0x0016,
-0xfff9,0xfff3,0xffdf,0xffe9,0xfff2,0xffee,0xfff9,0xfff4,
-0x0023,0x000f,0xfff1,0x0006,0xfffc,0x0001,0xffe5,0xfff4,
-0xfffb,0x0008,0x000f,0x0013,0x0025,0xfff5,0x0010,0xfffe,
-0x0014,0xfff4,0x0017,0x0002,0x0016,0xffff,0xffff,0xfff5,
-0xfffb,0xfff3,0xffde,0xfff2,0x0008,0xfff2,0x0004,0x001a,
-0x0000,0x000b,0xfff0,0xfff2,0xffe3,0xfffe,0xffef,0xfffd,
-0x0003,0x0013,0x0009,0x001a,0xfff8,0x001a,0xfff6,0x0018,
-0x0000,0x001c,0x0005,0x0021,0x0022,0x0011,0xfffe,0xffec,
-0xffff,0xffea,0x0000,0xfff6,0x0006,0xfff2,0xfffd,0xfff6,
-0xffec,0xfffc,0xffe0,0xfffc,0x0007,0xfff1,0x0000,0xfffd,
-0x0000,0xfff3,0xfff7,0x0000,0xfffd,0xfffc,0x0011,0x0000,
-0x0019,0x0007,0xfffe,0x0008,0xfff4,0x0007,0xffe9,0x0008,
-0xfff3,0x0010,0x0007,0x0014,0x002a,0x0009,0x0000,0xfffd,
-0x0009,0xffe7,0x000c,0xfff6,0x000c,0xffee,0xfffe,0xffe8,
-0xffed,0xfff3,0xffd2,0xffed,0x0005,0xffea,0x000a,0x0000,
-0x0008,0x000b,0x0008,0x0009,0xffef,0x000b,0x0007,0x0008,
-0xffe7,0xfff9,0x0002,0xfff8,0x000c,0xfff9,0x0017,0xfff8,
-0x000d,0xfff0,0xfff9,0xffec,0xffd6,0xfff7,0x0000,0x0003,
-0xfff7,0x0019,0xfff4,0x000a,0xfff4,0x0012,0x0002,0x0018,
-0x0013,0x000d,0x002e,0x0013,0xfffb,0x0016,0xfff6,0x0000,
-0xfff8,0xfff5,0xfff8,0xfff7,0x0011,0xfff5,0xfff9,0xfff8,
-0xfffd,0xffed,0xfff7,0xffe6,0x0008,0xffe6,0x000a,0xffe8,
-0x0000,0xffe4,0xfffb,0xffdf,0xffde,0xffef,0x0002,0x0014,
-0x0001,0x0016,0x0000,0x000a,0xfffa,0x000e,0x0003,0x000a,
-0x0014,0x0004,0x0020,0x0004,0xfff9,0x000f,0x0000,0x0003,
-0x0000,0x000d,0x0009,0x0000,0x0003,0x0004,0xffef,0x0000,
-0xffdd,0xfff1,0x000f,0xfffa,0x0004,0xffff,0x001b,0x000c,
-0x0005,0xfff8,0xfff1,0xffed,0xffdb,0x000b,0xfff0,0x0002,
-0xffec,0x000c,0xffe9,0xfffe,0xffea,0x0001,0x0001,0x000b,
-0x0005,0x000d,0x0022,0x000e,0xfff8,0x000e,0xfffc,0xffe6,
-0x0000,0xfff5,0x0010,0x000e,0x001d,0x0002,0x0011,0x0003,
-0xfff3,0xffe5,0x0003,0xffe8,0x0001,0xffed,0x000e,0xfffd,
-0xfff7,0xffec,0xfff4,0xffdf,0xffe3,0x0003,0xfff1,0x0014,
-0xfff7,0x0009,0xfff5,0xfffd,0xfff0,0xfffe,0x0002,0xfffe,
-0x0007,0x0003,0x0014,0x0000,0xfff6,0x0007,0x0007,0xffea,
-0x0007,0x000d,0x0021,0x0017,0x000e,0x0012,0x0007,0x000c,
-0xffef,0xfff8,0x0008,0x0004,0xfffc,0xfff6,0x0006,0xfffb,
-0x0004,0xfffb,0x0006,0x0006,0xffec,0x000a,0x0009,0xfff7,
-0xfffc,0x0002,0xfff0,0xfff9,0xffff,0x000c,0x0011,0x0010,
-0x0027,0x0009,0x0024,0x000c,0x0002,0x0003,0xfffa,0x0015,
-0xffff,0xfff5,0x0007,0xfff6,0x000b,0xffec,0xffec,0xfff5,
-0x0004,0xffec,0xfffd,0xfff3,0xfff8,0xffe4,0xfffa,0xffeb,
-0xfff6,0xfff0,0x0008,0xfff9,0xfff4,0x0003,0x000b,0x0007,
-0x0005,0x0000,0xfffc,0xfff8,0x0004,0x0008,0x0012,0x0003,
-0x0029,0x0000,0x0016,0xfffe,0x0000,0xfffc,0x0005,0x0019,
-0x0006,0x000e,0x0019,0xffff,0xfffe,0xfffc,0xffe3,0xfffe,
-0xffe5,0xfff0,0x0015,0x0006,0xfff4,0xfffd,0x0009,0x0010,
-0xfffd,0x0002,0xffff,0x0007,0xfff1,0x001f,0xfff9,0xfff6,
-0xfff0,0xfff7,0xffe5,0xffeb,0xfff5,0xfffb,0x0010,0x0003,
-0x001a,0x0009,0x0018,0x0007,0x0000,0xfffc,0x0000,0xfffc,
-0x0006,0xfff5,0x0020,0x000e,0x0017,0xfffa,0x0005,0x0001,
-0xfffb,0xffe3,0x0009,0xfff5,0xfff1,0xffea,0xfffd,0x0000,
-0xffee,0xfff8,0x0001,0xfffa,0xfff9,0x0017,0xfffa,0x0006,
-0xfffb,0xfff4,0xfff1,0xffeb,0xfffb,0xfff8,0x0011,0xfff7,
-0x001c,0x0000,0x000b,0xfffa,0xfffe,0xfff4,0x000b,0x0000,
-0x000e,0x000d,0x0031,0x0016,0x0008,0x0009,0xfffc,0x0009,
-0xffdb,0x000c,0x0009,0x0007,0x0011,0x000b,0x001a,0xffee,
-0x0019,0xfff4,0xffed,0xffef,0xffd3,0xfff2,0xffef,0x0000,
-0xffef,0x001e,0xffff,0x0016,0x000a,0x0019,0x000c,0x0026,
-0x0012,0xfffd,0x0016,0xfffc,0xfffd,0x0000,0xfff3,0x0003,
-0xfff6,0x000b,0xffe9,0xfffe,0x000a,0xfff9,0xfffb,0xfff9,
-0xfff1,0x0000,0xfffe,0xfff6,0x000d,0xfff9,0x000e,0xffdd,
-0x000a,0xffe9,0xfff0,0xffe1,0xffdb,0xffeb,0xfff0,0x0011,
-0xfffa,0x001a,0x000a,0x0015,0x0010,0x0015,0x000d,0x0019,
-0x0013,0xfff3,0x0008,0xffed,0xfffb,0xfff9,0xffff,0x0008,
-0xfffe,0x0024,0xfffb,0x0006,0xfffd,0x0008,0xfff1,0x0001,
-0xffd0,0x0004,0x0017,0x0009,0x0009,0x0011,0x001e,0x0002,
-0x0010,0xfffd,0xffe6,0xfff0,0xffd8,0x0006,0xffdd,0xffff,
-0xffe4,0x0011,0xfff4,0x0009,0x0000,0x0008,0x000b,0x0019,
-0x0005,0xfffd,0x000a,0xfff8,0xfffa,0xfff9,0xfffa,0xffea,
-0xffff,0x000b,0x0001,0x0015,0x0016,0x0007,0x0013,0x0005,
-0xffe6,0xfff9,0x000b,0xfff8,0x0005,0xffff,0x0011,0xfff2,
-0x0001,0xfff1,0xffe8,0xffe2,0xffe0,0xffff,0xffdf,0x0010,
-0xffee,0x000e,0x0000,0x0008,0x0006,0x0004,0x000c,0x000c,
-0x0006,0xfff3,0xfffe,0xffe9,0xfff8,0xfff1,0x0004,0xffef,
-0x0005,0x0024,0x0012,0x001e,0x0008,0x0016,0x000a,0x000e,
-0xffe2,0x000b,0x000f,0x0014,0x0000,0x0008,0x0009,0xfff1,
-0x000f,0x0000,0xfffb,0x0009,0xffe9,0x0006,0xfff8,0xfff3,
-0xfff3,0x0007,0xfffb,0x0003,0x0014,0x0013,0x001b,0x001f,
-0x0027,0xfff9,0x000d,0xfff5,0x0004,0xffed,0xfff8,0x0019,
-0xfffd,0x000b,0xfff9,0xfffe,0x0004,0xfff0,0xffee,0xfff7,
-0xfff8,0xffff,0x0003,0x0002,0xfffd,0xfff6,0xfffd,0xffe0,
-0x0001,0xfff4,0xfffe,0xfffc,0xfff1,0xffff,0xfff9,0x0003,
-0xfffe,0x0004,0x0006,0x0003,0x001a,0x000f,0x001d,0x0011,
-0x0028,0xffef,0x0000,0xffe6,0x0002,0xffe5,0x0002,0x001d,
-0x0004,0x0024,0x000a,0x0006,0xfff7,0x0000,0xffe5,0x0000,
-0xffd8,0x0002,0x001d,0x0016,0xfff9,0x000e,0x000c,0x0005,
-0x0007,0x0007,0xfff4,0x0009,0xffee,0x001a,0xffe6,0xfff2,
-0xffe8,0xfffc,0xfff0,0xfff7,0x000a,0x0002,0x001a,0x0012,
-0x001a,0xfff9,0x0001,0xfff1,0x0001,0xffe5,0xfffe,0x0000,
-0x0004,0x000b,0x0011,0x0015,0x0010,0xffff,0x0007,0x0003,
-0xffee,0xfff7,0x0011,0x0004,0xfff5,0xfffd,0x0000,0xfff5,
-0xfff9,0xfffc,0xfff6,0xfffd,0xfff6,0x0012,0xffe8,0x0003,
-0xfff2,0xfff9,0xfffc,0xfff6,0x0010,0xffff,0x001b,0x0004,
-0x001b,0xffef,0xfff4,0xffe2,0x0000,0xffdd,0x0009,0x0003,
-0x000c,0x0024,0x0023,0x001e,0x0002,0x000d,0xfffe,0x000b,
-0xffbe,0xfff8,0xffe9,0xfff5,0x000e,0x0005,0x0011,0x0010,
-0x0013,0x0002,0x0003,0xfffb,0xffee,0xffef,0x000a,0x0000,
-0xffff,0x0017,0xfffa,0x0014,0xfff1,0x0012,0xfff2,0x0016,
-0x0005,0x000a,0x002c,0x0017,0x0002,0x001a,0xfff7,0x0003,
-0xfffc,0xfff2,0xfff4,0xffe3,0xfff9,0xfff0,0xfff9,0xffee,
-0xffd4,0xffec,0xffde,0xffe3,0x000a,0xfff3,0x0004,0x0000,
-0x0004,0xfff7,0x0005,0xffed,0xfff6,0xffe8,0x000b,0x0011,
-0x0008,0x0014,0x0005,0x0013,0xfff7,0x000e,0xfff4,0x0009,
-0x0006,0x0000,0x001e,0x0009,0x0000,0x0013,0x0002,0x0007,
-0x0002,0x000a,0x0005,0xffec,0xffeb,0xffff,0xffef,0xfff7,
-0xffb3,0xfff0,0xfff7,0xfff7,0x0006,0x000b,0x0015,0x0025,
-0x000a,0x000a,0xfffc,0xfffb,0xfff3,0x0003,0xfff9,0x0000,
-0xfff3,0x000b,0xffef,0x0006,0xffe7,0x0001,0xfff1,0x0009,
-0xfff9,0x0009,0x0020,0x0013,0x0000,0x0012,0xfffe,0xffea,
-0x0003,0xfff1,0x000c,0xfffb,0x0004,0xfffe,0x0011,0xfffb,
-0xffc9,0xffe4,0xffeb,0xffe5,0x0002,0xfff9,0x0008,0x0014,
-0xfffc,0xffff,0xffff,0xffee,0xfffb,0xfffc,0xfffb,0x0010,
-0xfffe,0x0008,0xfffb,0x0005,0xffed,0xfffe,0xfff2,0xfffd,
-0xfffa,0x0000,0x0012,0x0004,0xfffe,0x000b,0x0008,0xffee,
-0x000b,0x000a,0x001d,0x0003,0xfff6,0x000d,0x0008,0x0003,
-0xffc6,0xfff7,0xfff0,0x0001,0xfffe,0x0002,0x0000,0x0013,
-0x000a,0x000d,0x0011,0x0015,0x0003,0x0003,0x0013,0xfff4,
-0x0002,0x0000,0xfff6,0x0001,0xfffb,0x000c,0x0000,0x000f,
-0x001a,0x0005,0x0022,0x0010,0x000b,0x0007,0xfffc,0x0019,
-0x0002,0xfff2,0x0003,0xffe3,0xfff3,0xffe7,0xffec,0xffec,
-0xffdc,0xffeb,0xffe4,0xfff0,0xfffa,0xfff0,0xfff4,0x0002,
-0xfffc,0x0002,0x0014,0x0007,0x000b,0xfffc,0x0014,0x0004,
-0x000c,0xfffe,0x0001,0x0000,0x0000,0x0008,0x0002,0x0002,
-0x001b,0xfffc,0x0015,0x0002,0x0009,0x0000,0x0006,0x001d,
-0x0009,0x000a,0x0015,0xffeb,0xffe4,0xfff6,0xffe3,0xfff5,
-0xffbb,0xffef,0xfffd,0x0003,0xfff6,0x0008,0x0003,0x0028,
-0x0001,0x0015,0x000a,0x0015,0x0008,0x0017,0x0001,0xfff3,
-0xfff8,0xfff5,0xffeb,0xfff5,0xfff1,0xfffc,0x0000,0x0002,
-0x000d,0x0005,0x0017,0x000c,0x0007,0x0000,0x0001,0x0000,
-0x000a,0xfff2,0x001c,0xfffb,0xffff,0xfff5,0x0005,0xfff9,
-0xffd1,0xffe2,0xfff1,0xfff2,0xfff2,0xfff7,0xfff7,0x0017,
-0xfff3,0x000a,0x000c,0x0007,0x0010,0x000f,0x0003,0x0003,
-0x0001,0xfff2,0xfff7,0xfff4,0xfff7,0xfff8,0x0000,0xfff6,
-0x000e,0xfffc,0x0009,0xfffe,0x0005,0xfff8,0x000d,0x0003,
-0x0012,0x000a,0x002d,0x0003,0xfff0,0x0004,0xfffc,0x0000,
-0xffb1,0x000b,0xfff1,0x0004,0x0012,0x0017,0x0014,0x0005,
-0x001e,0x0007,0xfff9,0xfffe,0xffeb,0xffeb,0xfff8,0xfffd,
-0xfff6,0x001c,0x0004,0x001f,0x0006,0x0019,0xfffd,0x0025,
-0x0004,0xfff9,0x0014,0x0000,0x0004,0x0004,0xfff5,0x0007,
-0xfffa,0x0008,0xffe5,0xffea,0xfff2,0xfff4,0xfffb,0xfff0,
-0xffc7,0x0000,0xffe5,0xfff3,0x000e,0x0005,0x0007,0xfff5,
-0x000f,0xfffc,0xfffb,0xfff0,0xfff3,0xffe3,0xfffa,0x000d,
-0x0000,0x0019,0x0010,0x001f,0x000c,0x0016,0xfffe,0x0017,
-0x0006,0xfff0,0x0007,0xfff2,0x0002,0xfffd,0x0000,0x000c,
-0x0000,0x0021,0xfff7,0xfff3,0xffe4,0x0003,0xfff2,0xfff9,
-0xffa6,0x0003,0xfffe,0x0006,0x000a,0x001d,0x0018,0x001a,
-0x0015,0x000f,0xfff1,0xfffe,0xfff0,0xffff,0xffe7,0xfffc,
-0xffeb,0x0010,0xfffa,0x0012,0xfffd,0x0008,0xfffb,0x0018,
-0xfff8,0xfff9,0x0009,0xfffc,0x0001,0xfffd,0xfffb,0xffee,
-0x0001,0x0007,0xfffe,0x0001,0xfffe,0x0001,0x0013,0xfffd,
-0xffbd,0xfff8,0xfff2,0xfff5,0x0007,0x000b,0x000b,0x0009,
-0x0007,0x0003,0xfff3,0xfff0,0xfff8,0xfff7,0xffe8,0x000c,
-0xfff6,0x000d,0x0005,0x0011,0x0002,0x0004,0xfffd,0x000a,
-0xfffa,0xffef,0xfffc,0xffed,0x0000,0xfff5,0x0006,0xfff3,
-0x0009,0x0021,0x000e,0x000a,0xfff0,0x0011,0x000a,0x0004,
-0xffb9,0x000a,0xfff7,0x0011,0x0001,0x0014,0x0003,0x0008,
-0x0015,0x0012,0x0006,0x0018,0x0000,0xffff,0x0000,0xfff0,
-0xfffa,0x0005,0x0000,0x000d,0x0011,0x0013,0x000b,0x001d,
-0x0019,0xfff5,0x000b,0xfffa,0x000d,0xfff1,0xfff9,0x001d,
-0x0000,0x0008,0xfff5,0xffea,0xffec,0xffeb,0xffef,0xffee,
-0xffcf,0xfffe,0xffeb,0x0000,0xffff,0x0002,0xfff7,0xfff8,
-0x0006,0x0006,0x0008,0x000a,0x0008,0xfff7,0x0002,0x0000,
-0x0004,0x0002,0x000d,0x000c,0x0017,0x000f,0x000c,0x0010,
-0x001a,0xffeb,0xfffe,0xffeb,0x000b,0xffe9,0x0004,0x0021,
-0x0007,0x0021,0x0006,0xfff3,0xffde,0xfffb,0xffe5,0xfff6,
-0xffae,0x0001,0x0004,0x0013,0xfffa,0x001b,0x0006,0x001d,
-0x000c,0x001a,0xffff,0x0018,0x0005,0x0012,0xffef,0xffef,
-0xffef,0xfffa,0xfff6,0x0000,0x0007,0x0002,0x0009,0x0010,
-0x000c,0xfff5,0x0000,0xfff5,0x0009,0xffe9,0x0000,0x0003,
-0x0008,0x0008,0x000d,0x0001,0xfff8,0xfff9,0x0007,0xfffa,
-0xffc4,0xfff6,0xfff9,0x0001,0xfff7,0x0008,0xfffa,0x000d,
-0xfffe,0x000f,0x0001,0x000a,0x000d,0x000b,0xfff1,0x0000,
-0xfffa,0xfff7,0x0001,0x0000,0x000d,0xffff,0x000b,0x0003,
-0x000d,0xffeb,0xfff3,0xffe6,0x0007,0xffe1,0x000a,0x0007,
-0x0010,0x0021,0x001f,0x000a,0xffea,0x0008,0xffff,0x0002,
-0xfffd,0x0007,0xfffb,0xfffb,0x0008,0xfffe,0x0011,0xfff7,
-0x0012,0xffe8,0xfffe,0xffed,0xfff6,0xfffc,0x001c,0x0011,
-0x0005,0x001c,0xfffe,0x0007,0xfffc,0x000f,0x0007,0x0008,
-0x0006,0x0017,0x000d,0x0015,0xfff2,0x0014,0xffef,0xffee,
-0xfff5,0xffdf,0xffe2,0xfff5,0x0017,0xfff3,0xfffb,0xfff7,
-0x0012,0xfffc,0xffef,0xffe9,0x0004,0xffec,0x0004,0xffe6,
-0x0003,0xffdc,0x0000,0xffe0,0xfffe,0xfff4,0x001d,0x0022,
-0x0010,0x0018,0x000a,0x0006,0x0000,0x000c,0x0008,0xfffc,
-0x0008,0x000d,0x0000,0x0006,0xfff0,0x000c,0xfffb,0xfff3,
-0xfffd,0xfff9,0xfff3,0xfffd,0x0008,0x0002,0xfff2,0x0000,
-0xfff3,0x0000,0x0008,0xfffd,0x0000,0x0004,0x0015,0x000b,
-0x0009,0xfff0,0xfff6,0xffee,0xfffb,0x0010,0x000a,0x0010,
-0xfffb,0x000f,0xfff3,0xfffb,0xfff1,0xffff,0x0006,0xfffc,
-0xfffa,0x0017,0x0002,0x0010,0xffef,0x000c,0xfff6,0xffd4,
-0xfffd,0xffdf,0xfffa,0x000c,0x0022,0x0001,0x0014,0x0003,
-0x0008,0xfff4,0xfffd,0xffeb,0xfffd,0xfff2,0x0008,0xfffb,
-0xfffc,0xffe4,0xfff9,0xffe0,0x0002,0x0008,0x000c,0x0022,
-0x0004,0x000c,0xffff,0xfffa,0xfff7,0xfffc,0x0007,0xffef,
-0xfffc,0x000d,0xfff5,0x0001,0xffed,0x0004,0x0000,0xffd9,
-0x0004,0xfff9,0x000b,0x0015,0x0014,0x0010,0x000a,0x000b,
-0x0004,0x0006,0x0000,0x0007,0xfff8,0xfffc,0x0000,0xfffa,
-0x0009,0xfff3,0x000b,0x0007,0x000b,0x000f,0x0025,0x0004,
-0x0009,0x0005,0xfffb,0xfff5,0x0005,0x0009,0x0016,0x0001,
-0x001b,0x0012,0x0004,0x000e,0xfffb,0x0000,0xfff4,0x0003,
-0xfffc,0xffe0,0xfff2,0xfff4,0x0011,0xffea,0xffef,0xfff5,
-0x001a,0xfffa,0xfff5,0xfff6,0xfff4,0xffe9,0xfff4,0xffe9,
-0xfffb,0xffe8,0x000d,0xfffb,0x0013,0x0008,0x0026,0x0015,
-0x0014,0x0002,0x0006,0xfff4,0x000b,0x0005,0x0017,0xfff5,
-0x001d,0x0009,0xfff7,0x0000,0xfff9,0xfffa,0xffff,0x0007,
-0x0002,0xfff9,0x0003,0xfffd,0x0002,0xfffa,0xffe5,0xfffd,
-0xfffa,0xfffe,0x000e,0x0009,0xfff0,0x0001,0x0003,0x000e,
-0x0000,0xfffb,0x0003,0x0008,0x0010,0x0024,0x0013,0x0003,
-0xffff,0xfffa,0xffef,0xffe8,0xfffc,0xfff9,0x0015,0xfff5,
-0x000e,0x0012,0xfff9,0x0009,0xfff7,0xfff9,0xfffa,0xffea,
-0x0003,0xffdf,0x000a,0x000b,0x001c,0xfff9,0x0007,0x0000,
-0x0010,0xfff2,0x0002,0xfff8,0xffec,0xffef,0xfff7,0xfffe,
-0xfff2,0xfff0,0x0006,0xfffb,0x0018,0x001c,0x0015,0x0014,
-0x0008,0xfff7,0xfffc,0xffe7,0x0001,0xfff5,0x0016,0xffe8,
-0x000f,0x0008,0xffeb,0xfffb,0xfff5,0xfff2,0x0005,0xffee,
-0x000b,0xfff9,0x001b,0x0014,0x000e,0x0007,0xffff,0x0009,
-0xfff0,0x001b,0x0002,0x000a,0x000d,0x0010,0x0014,0xffec,
-0x001d,0xffec,0xfff2,0xfff0,0xfff3,0xfff8,0x0009,0x000d,
-0xfffe,0x0021,0x0009,0x0013,0x0011,0x0017,0x0011,0x0016,
-0x0006,0x0006,0xfff7,0xfffe,0xfff4,0xfffe,0xffec,0xfff3,
-0xfff3,0xfff6,0xffd3,0xfffc,0x0010,0xfff8,0xfffe,0xfff9,
-0x0005,0x000f,0xfff7,0xfff9,0x0009,0xfffe,0x0008,0xffdb,
-0x000e,0xffe1,0xfff5,0xffe3,0xfffb,0xfff0,0x000b,0x001e,
-0x0007,0x001d,0x0015,0x0012,0x0017,0x0013,0x0012,0x0009,
-0x0007,0xfffd,0xffe9,0xffef,0xfff2,0xfff7,0xfff8,0xfff7,
-0xfffa,0x000f,0xffe5,0x0004,0x0002,0x0006,0xfff4,0x0001,
-0xffe6,0x0013,0x000f,0x000c,0x0005,0x0016,0x0018,0x0000,
-0x0015,0xfff4,0xffeb,0xfff1,0xfff8,0x000b,0xfff9,0x000c,
-0xfff2,0x0014,0xfffe,0x0006,0x0007,0x0006,0x0010,0x0009,
-0xfffa,0x0005,0xffeb,0xfff9,0xfff1,0xfff6,0xfff3,0xffd9,
-0xfffb,0xfff6,0xffec,0x0013,0x001c,0x0005,0x0016,0x0005,
-0xfffc,0x0006,0x0003,0xfffb,0x0001,0x0004,0x000b,0xfff0,
-0x0006,0xffe9,0xffed,0xffe3,0x0000,0x0003,0xfffa,0x001e,
-0xfffd,0x0011,0x000a,0x0005,0x000d,0x0002,0x0011,0xfffd,
-0xfffb,0xfffd,0xffdd,0xffeb,0xffef,0xffef,0xfffe,0xffdd,
-0x0002,0x000f,0xfffd,0x001c,0x000d,0x0015,0x000d,0x000d,
-0xfff8,0x0019,0x0008,0x0017,0xfffd,0x000d,0x0003,0xffef,
-0x0014,0xfff8,0x0000,0x000a,0x0008,0x000b,0x0012,0x0000,
-0x0001,0x000a,0x0005,0x0000,0x001c,0x0011,0x0020,0x000f,
-0x001a,0x0001,0xffed,0xfff7,0xfffd,0xffeb,0xfff1,0x0007,
-0xfffa,0xfff7,0xffe3,0xfffb,0x000a,0xffef,0xfff1,0xfff7,
-0x000d,0x000d,0xfffd,0x0005,0xfff9,0xfffc,0xfff7,0xffde,
-0x0005,0xffec,0x0002,0xfffd,0x0010,0x0003,0x0014,0x0011,
-0x000b,0x0007,0x0011,0x0000,0x0022,0x000d,0x0021,0x0002,
-0x001c,0xfff8,0xffe0,0xffe8,0xfffb,0xffe3,0xfffd,0x000c,
-0x0000,0x000f,0xfff5,0x0003,0xfffd,0xfffe,0xffe8,0xffff,
-0xffee,0x0011,0x0015,0x0019,0xfff5,0x0013,0x0006,0x0003,
-0x000b,0x0000,0xfff9,0x000b,0x000d,0x001f,0x0001,0x0000,
-0xfff7,0xffff,0xfffb,0xfff4,0x0012,0x0000,0x001f,0x0002,
-0x000d,0x0001,0xffe2,0xfff2,0xfff9,0xffe3,0xfff7,0xffee,
-0x0001,0xfff6,0xfffc,0x0012,0x0016,0xfffd,0x000a,0x0002,
-0x0003,0x0005,0x0009,0x0007,0xfff1,0x0001,0xfffb,0xfff3,
-0xfffe,0xfff4,0xfffb,0xfffe,0x0015,0x0017,0x0002,0x0010,
-0x0000,0xfffb,0x0006,0xfff3,0x0017,0xfffd,0x0020,0xfff6,
-0x000f,0xfff8,0xffd4,0xffe4,0xfff7,0xffdb,0x0002,0xfff3,
-0x0009,0x000f,0x000c,0x001b,0x0007,0x000c,0x0000,0x000b,
-0xffd4,0x0006,0xffe2,0xfff8,0x0009,0x000a,0x000b,0x000e,
-0x0017,0xfffb,0x0008,0xfffc,0x000e,0xfff4,0x0025,0x000e,
-0x000c,0x001a,0x0004,0x0010,0xfff8,0x0010,0xfff7,0x0007,
-0xfffa,0x0013,0x000c,0x0019,0xfffb,0x0018,0xfff1,0xfff3,
-0xfff8,0xffdc,0xffde,0xffe1,0xffff,0xffee,0xfffc,0xffee,
-0xffea,0xfffb,0xffd6,0xffe6,0x0006,0xfff8,0xffff,0xfffe,
-0x0009,0xffef,0x000a,0xffee,0x0015,0xffed,0x0027,0x001f,
-0x0017,0x0017,0x0010,0x000f,0xfffe,0x000c,0xfff9,0xfffa,
-0xfffb,0x0009,0xffff,0x000a,0xfff9,0x0010,0xfffc,0xfff7,
-0x0000,0xfff6,0xffef,0xffea,0xfff0,0xfffe,0xfff2,0xfff7,
-0xffc9,0xffff,0xffef,0xfffa,0x0001,0x0010,0x000f,0x0023,
-0x000f,0x0002,0x0000,0xfffc,0x0013,0x0008,0x0014,0x000d,
-0x0001,0x000e,0xfff9,0x0003,0xffee,0x0000,0xfff6,0xfffb,
-0xffed,0x0013,0x0000,0x0015,0xfff8,0x0010,0xfff7,0xffd9,
-0x0000,0xffdc,0xfff6,0xfff9,0x0009,0xfffc,0x0014,0xfffb,
-0xffdf,0xfff3,0xffe3,0xffe8,0xffff,0xffff,0x0002,0x0012,
-0x0000,0xfff7,0x0003,0xffef,0x001b,0x0000,0x0015,0x001e,
-0x000c,0x000b,0x0005,0x0002,0xfff4,0xfffc,0xfff7,0xffed,
-0xffee,0x0009,0xfff3,0x0006,0xfff5,0x0008,0x0002,0xffdd,
-0x0008,0xfff6,0x0007,0x0001,0xfffc,0x000b,0x000a,0x0002,
-0xffdc,0x0005,0xffe8,0x0004,0xfff9,0x0007,0xfffa,0x0011,
-0x000e,0x0005,0x0016,0x0016,0x0023,0x0008,0x002e,0x0001,
-0x0011,0x0003,0x0000,0xfffe,0x0002,0x000a,0x0005,0x0000,
-0x000e,0x000f,0x0002,0x0012,0x0002,0x0004,0xfff5,0x0007,
-0xffff,0xffdc,0xffee,0xffe0,0xfff9,0xffe5,0xffef,0xffec,
-0xfff2,0xfff9,0xffdc,0xfff3,0xfff6,0xfff6,0xffee,0x0000,
-0x0000,0xfffb,0x0019,0x0008,0x002b,0x0000,0x0030,0x0012,
-0x001b,0x0000,0x000c,0xfffd,0x0007,0x0006,0x0007,0xfff3,
-0x000f,0x0005,0xfff5,0x0003,0x0000,0xfffe,0x0000,0x000c,
-0x0006,0xfff6,0x0000,0xffe9,0xffea,0xfff5,0xffe6,0xfff4,
-0xffd1,0xfffd,0xfff5,0x0006,0xfff1,0x000d,0xfffe,0x0026,
-0x0006,0x000d,0x000f,0x0016,0x0028,0x001c,0x001c,0x0000,
-0x0005,0xfff8,0xfff6,0xfff1,0xfff9,0xfff9,0x0004,0xfff3,
-0x0001,0x000e,0xfff7,0x000e,0x0000,0xfffe,0xfffc,0xffee,
-0x0007,0xffdc,0x0006,0xfff8,0x0003,0xfff3,0x0007,0xfff8,
-0xffe7,0xfff1,0xffea,0xfff5,0xffee,0xfffc,0xfff1,0x0016,
-0xfff8,0x0002,0x0011,0x0009,0x0030,0x0014,0x001e,0x0011,
-0x0010,0xfff5,0x0001,0xfff0,0xfffe,0xfff6,0x0005,0xffe6,
-0x0002,0x0004,0xffea,0x0000,0xfffe,0xfff6,0x0006,0xfff3,
-0x000e,0xfff6,0x0017,0x0000,0xfff6,0x0002,0xffff,0x0000,
-0xffc7,0x001a,0xffea,0x0007,0x000e,0x001c,0x000e,0x0003,
-0x0023,0x0000,0xfffd,0xffff,0x000b,0xfff0,0x0012,0x000a,
-0x0004,0x001f,0x000f,0x001c,0x000e,0x0017,0x0001,0x0015,
-0xfff9,0x0002,0xfff5,0x0001,0xfffd,0x0001,0xffee,0xfff7,
-0xfff6,0xfff3,0xffcf,0xffe8,0xfff8,0xfff2,0xfffe,0xfff0,
-0xffdd,0x000e,0xffde,0xfff6,0x000a,0x000a,0x0001,0xfff4,
-0x0014,0xfff4,0x0000,0xfff1,0x0012,0xffe8,0x0014,0x001b,
-0x000e,0x001c,0x001b,0x001b,0x0014,0x0013,0x0002,0x0008,
-0xfffb,0xfff9,0xffe7,0xfff3,0xfffb,0xfffb,0xfffa,0xfffb,
-0xfffe,0x000c,0xffe1,0xfff1,0xffe9,0x0001,0xfff4,0xfff8,
-0xffbc,0x0012,0xfff7,0x0009,0x0006,0x0023,0x0012,0x0019,
-0x001a,0x0007,0xfff6,0xffff,0x0010,0x0003,0x0001,0x0009,
-0xfffa,0x0013,0x0004,0x000f,0x0004,0x0006,0x0000,0x0008,
-0xffec,0x0002,0xffe9,0xfffe,0xfff9,0xfffb,0xfff4,0xffdd,
-0xffff,0xfff3,0xffe8,0x0000,0x0003,0x0000,0x0016,0xfffc,
-0xffd2,0x0006,0xffeb,0xfff8,0x0002,0x0010,0x0005,0x0008,
-0x000b,0xfffc,0xfff8,0xfff1,0x0018,0xfffc,0x0002,0x001a,
-0x0003,0x0010,0x0010,0x000e,0x0009,0x0002,0x0001,0xfffc,
-0xffed,0xfff9,0xffdc,0xffef,0xfff7,0xfff3,0x0000,0xffe1,
-0x0005,0x000c,0xfff9,0x0008,0xfff5,0x000f,0x000d,0x0004,
-0xffcf,0x0018,0xfff0,0x0014,0xfffe,0x001a,0xfffe,0x0007,
-0x0019,0x000a,0x000b,0x0019,0x0020,0x0003,0x001b,0xfffe,
-0x0008,0x0008,0x000b,0x0009,0x0018,0x0011,0x0010,0x000e,
-0x000d,0xfffe,0xffec,0xfffb,0x0004,0xffef,0xfff2,0x000c,
-0xfffd,0xfff3,0xffdf,0xffe7,0xfff2,0xffe9,0xfff1,0xffed,
-0xffe5,0x000c,0xffe4,0x0002,0xfffa,0x0007,0xfff1,0xfff7,
-0x000b,0xffff,0x000d,0x000b,0x0028,0xfffc,0x001d,0x000e,
-0x0013,0x0005,0x0017,0x0008,0x001e,0x000d,0x0011,0x0000,
-0x000e,0xfff4,0xffde,0xffec,0x0002,0xffe7,0xfffe,0x0010,
-0x0004,0x000c,0xfff1,0xfff0,0xffe3,0xfff9,0xffe8,0xfff6,
-0xffc4,0x0010,0xfffd,0x0016,0xfff6,0x0020,0x0000,0x001c,
-0x0011,0x0012,0x0003,0x0019,0x0025,0x0017,0x000a,0xfffd,
-0xfffe,0xfffd,0x0000,0xfffd,0x000e,0x0000,0x000e,0x0001,
-0x0000,0xfffe,0xffe0,0xfff7,0x0001,0xffe7,0xfff9,0xfff3,
-0x0005,0xfff3,0xfff8,0xffff,0xfffe,0xfff8,0x000a,0xfffa,
-0xffda,0x0004,0xfff1,0x0004,0xfff2,0x000d,0xfff4,0x000b,
-0x0002,0x0006,0x0006,0x000b,0x002d,0x0010,0x000b,0x000d,
-0x0007,0xfffa,0x000c,0xfffc,0x0014,0xfffd,0x0010,0xfff4,
-0x0001,0xfff4,0xffd2,0xffe8,0x0000,0xffdf,0x0003,0xfff7,
-0x000c,0x000c,0x0008,0x0007,0xffef,0x0006,0x0000,0x0002};
-
-static const signed short etable2[5120]={
-0x0049,0xffe0,0xffc4,0xfff1,0xffe6,0x003b,0x0002,0xffdf,
-0x001e,0xfff6,0xfffd,0xffef,0x0008,0x001e,0xffff,0xffe6,
-0xfffc,0xffea,0x000a,0x0010,0xffdc,0xfffb,0xfff5,0x0038,
-0x0025,0x0006,0xfff6,0xfffb,0xfff3,0xfffd,0x0006,0xfffb,
-0x000b,0x0004,0xffed,0xfffb,0xfff0,0x0029,0x0018,0x000d,
-0x0004,0xfff5,0xffdb,0x0017,0xfffb,0x002e,0xfffe,0xffe3,
-0xfffb,0xffd9,0xffeb,0xfff7,0x0000,0x0031,0x000c,0xfff7,
-0xfff0,0xffe6,0x0016,0x000f,0xffd3,0xffec,0xfffb,0x0028,
-0x0016,0x0011,0xffe6,0x001f,0xfff2,0x0002,0xfff2,0x000a,
-0x001e,0x0014,0xffe5,0xfff7,0xffd9,0x0027,0x0012,0x0005,
-0x0022,0xffe7,0xffd0,0xffe4,0xfff5,0x0022,0xfffe,0xffd7,
-0x0009,0xfff9,0xffef,0x0015,0x0014,0x0018,0xffef,0xffdf,
-0x0000,0xffe8,0x000a,0x002a,0x0003,0xfffb,0x000a,0x002a,
-0x000b,0x0008,0xfffd,0x0003,0x0010,0x0009,0x0016,0xfffe,
-0x0000,0xffdf,0xfff6,0x0012,0x0007,0x003a,0x000a,0x001c,
-0xffde,0xfffc,0xffe7,0x000a,0x0009,0x0015,0xfff9,0xffdc,
-0xffe6,0xffdc,0xffdd,0x001c,0x000c,0x002a,0xfffd,0xfff0,
-0xfff4,0xffe4,0x0015,0x002a,0xfffb,0xffeb,0x0010,0x001a,
-0xfffc,0x0013,0xffed,0x0027,0x000f,0x000f,0x0001,0x000d,
-0x0013,0xffef,0xffef,0x000e,0xfff1,0x0037,0x0004,0x0013,
-0x001c,0xffec,0xffcd,0xfff2,0xfffa,0x0007,0x0000,0xffe6,
-0x001b,0xfffc,0x0012,0xffd8,0xfffa,0x0010,0xffff,0xfff1,
-0x0000,0xffc9,0xfffb,0xfff0,0xffed,0x000e,0xfffd,0x0031,
-0x000e,0x0001,0xffea,0xffe2,0xfff4,0x0000,0x0018,0x000f,
-0x0009,0xffef,0xffd3,0xffe3,0x0004,0x001c,0x0033,0x0023,
-0xffd8,0x0000,0xffe4,0x0018,0x000e,0xfffb,0xfffc,0xffeb,
-0xfff9,0xffdf,0x0000,0xffe0,0xfff1,0x0023,0x000c,0x0001,
-0xfff5,0xffc6,0x0005,0xfff0,0xffe4,0x0000,0x0001,0x0021,
-0x0000,0x000b,0xffd9,0x0005,0xfff2,0x0006,0x0003,0x001f,
-0x001c,0xffff,0xffcb,0xffdf,0xffed,0x0019,0x002e,0x001a,
-0xfff5,0xfff2,0xffd9,0xffe5,0x0009,0xffef,0xfffc,0xffdf,
-0x0006,0x0000,0x0004,0xffff,0x0005,0x000a,0xffef,0xffea,
-0x0005,0xffc7,0xfffb,0x0009,0x0014,0x000d,0x0012,0x0023,
-0xfff5,0x0003,0xfff0,0xffea,0x0011,0x000d,0x0028,0x0013,
-0xffff,0xffc9,0xffdd,0xfffb,0x001b,0x002c,0x0025,0x0031,
-0xffb0,0x0006,0xfff0,0x000b,0x001e,0xffe2,0xfff7,0xffe4,
-0xffe4,0xffe3,0xfff3,0x0006,0xfffe,0x001c,0xfffd,0xfffb,
-0xfff9,0xffc4,0x0005,0x0009,0x000b,0xffff,0x0018,0x0013,
-0xffe5,0x000d,0xffe0,0x000d,0x000f,0x0013,0x0013,0x0023,
-0x0011,0xffd9,0xffd5,0xfff7,0x0004,0x002a,0x0020,0x0029,
-0x004e,0xffeb,0xffd5,0x0004,0xffda,0x0011,0x0011,0xfffb,
-0x0037,0x0018,0xfff1,0xffdc,0x000e,0x0004,0x0018,0xffe8,
-0x000c,0x0005,0x0011,0x001f,0xffca,0xfffb,0xfffe,0x001b,
-0x002b,0xfff4,0x0002,0x0009,0xfff7,0xfff1,0x0016,0xfffd,
-0x001c,0x0015,0xffec,0x0003,0x0014,0x001c,0x0009,0xfffb,
-0x0009,0xffff,0xffec,0x002b,0xffef,0x0003,0x000c,0x0000,
-0x0014,0xfffc,0xffdf,0xffe3,0x0006,0x0016,0x0026,0xfff9,
-0x0000,0x0001,0x001d,0x001e,0xffc1,0xffeb,0x0003,0x000b,
-0x001b,0xffff,0xfff2,0x002d,0xfff6,0xfff7,0x0001,0x000c,
-0x002f,0x0025,0xffe4,0x0000,0xfffe,0x001a,0x0004,0xfff3,
-0x0027,0xfff2,0xffe2,0xfff8,0xffea,0xfff8,0x000c,0xfff4,
-0x0022,0x001b,0xffe3,0x0002,0x001a,0xfffe,0x0008,0xffe1,
-0x0010,0x0003,0x0011,0x0039,0xfff2,0xfffa,0x0013,0x000d,
-0x0010,0xfff6,0x0008,0x0011,0x0014,0xfffe,0x0026,0x0000,
-0x0011,0xfff0,0xfff5,0x001b,0x002c,0x002d,0xfffc,0x0008,
-0xffe3,0x0005,0xfff9,0x001e,0xffff,0xffeb,0x0007,0xfff9,
-0x0000,0x0000,0xffd1,0x0009,0x0012,0x000f,0x0016,0xfff2,
-0x0004,0x0000,0x001c,0x0039,0xffe9,0xffeb,0x0019,0xfffe,
-0x0001,0x0000,0xfff9,0x0035,0x0013,0x0003,0x0011,0x000f,
-0x0024,0x0000,0xffed,0x0018,0x0015,0x002b,0xfff7,0x0000,
-0x0021,0xfff6,0xffde,0x0005,0xffef,0xffdd,0x000f,0x0001,
-0x0035,0x001e,0x0006,0xffc5,0x0000,0xfff6,0x0018,0xfff3,
-0x0011,0xffe5,0x0001,0xffff,0xffdb,0x000d,0x0004,0x0014,
-0x0014,0xffee,0xfff6,0xfff0,0xfff8,0xfff5,0x0027,0x0012,
-0x001a,0x0000,0xffd2,0xffec,0x0029,0x000f,0x0025,0x000f,
-0xffdd,0x000a,0xfff5,0x002c,0x0003,0xffd0,0x000a,0x0006,
-0x0011,0x0002,0xfff5,0xffcd,0xfff8,0x0008,0x0026,0x0003,
-0x0004,0xffe1,0x000c,0xfffe,0xffd2,0xffff,0x000a,0x0004,
-0x0005,0xfff9,0xffe6,0x0013,0xfff6,0xfffb,0x0012,0x0022,
-0x002d,0x000f,0xffca,0xffe8,0x0012,0x000d,0x001f,0x0007,
-0xfffb,0xfffd,0xffeb,0xfff9,0xfffe,0xffc4,0x000a,0xfffb,
-0x0020,0x0022,0xfff9,0xffec,0x000b,0xfff0,0x0008,0xffec,
-0x0015,0xffe3,0x0001,0x0018,0x0002,0x000d,0x001b,0x0006,
-0xfffb,0xfff1,0xfffd,0xfff8,0x0015,0x0001,0x0037,0x0015,
-0x000f,0xffda,0xffdb,0x0003,0x0041,0x0020,0x0017,0x001e,
-0xffb6,0x0011,0x0000,0x001f,0x0012,0xffb7,0x0005,0x0000,
-0xfffd,0x0005,0xffe7,0xfff4,0x0003,0x0001,0x0016,0xfffd,
-0x0009,0xffdf,0x000c,0x0018,0xfffa,0xfffe,0x0021,0xfff7,
-0xffeb,0xfffb,0xffec,0x001b,0x0013,0x0007,0x0022,0x0025,
-0x0022,0xffea,0xffd4,0x0000,0x0029,0x001d,0x0011,0x0015,
-0x004c,0xffdd,0xffe1,0xffe4,0xffcf,0x002b,0xffd8,0x0000,
-0x001d,0xfff2,0x0008,0x0005,0x000a,0x0012,0xffe6,0xffd2,
-0x0000,0x0007,0x0006,0x0003,0xffe7,0xfff9,0xfffe,0x0028,
-0x001c,0x000e,0x0012,0xfffd,0xffe5,0xffe4,0xfff8,0xffd3,
-0xfff3,0x0022,0xfff3,0xffe5,0xfff1,0x001f,0x000c,0x0003,
-0x0007,0xfff1,0xfff7,0x0009,0xffe4,0x001d,0xffd3,0x0005,
-0xfffa,0xffd5,0xfff7,0x000c,0x0002,0x0024,0xfff4,0xffe2,
-0xfff5,0x0003,0x0011,0x0003,0xffde,0xffea,0x0003,0x0018,
-0x000c,0x0018,0x0002,0x0020,0xffe4,0xffea,0xffe3,0xffe3,
-0x0005,0x0032,0xffeb,0xffe1,0xffda,0x001d,0x0007,0xfffb,
-0x0024,0xffe3,0xffed,0xffd7,0xffde,0x0012,0xffd3,0xfffa,
-0x0008,0xfff6,0xfffb,0x002b,0x0017,0x000b,0xffd6,0xffcb,
-0x0005,0x0005,0x0006,0x001e,0x000e,0xfff8,0x0014,0x001a,
-0x0001,0x0010,0x0019,0x0004,0x0003,0xfff1,0x0007,0xffd7,
-0xffe9,0xfffd,0xfffc,0xfffd,0x0008,0x0030,0xffff,0x0011,
-0xffe0,0xfff8,0x0003,0xfffe,0xfff3,0x0004,0xffce,0xffff,
-0xffe5,0xffd9,0xffe9,0x0033,0x000f,0x001e,0xffe5,0xffdb,
-0xfff9,0x0001,0x0011,0x001d,0x0005,0xffe9,0x0019,0x000a,
-0xfff2,0x001a,0x0008,0x0029,0x0001,0xfff7,0xfff3,0xffe6,
-0xfffb,0x000c,0xfff4,0xfff9,0xfff2,0x002d,0xfffa,0x0009,
-0x001f,0xffe8,0xffe9,0xffe5,0xffe3,0xfff7,0xffd5,0x0008,
-0x001a,0xfff9,0x001e,0xffef,0xfffc,0x0003,0xffe6,0xffdd,
-0x0005,0xffe8,0xfff6,0xffe4,0xfff7,0x000c,0x0005,0x0021,
-0x0005,0x0008,0x0005,0xffe3,0xffe6,0xffe8,0x0009,0xffe9,
-0xfff2,0x000c,0xffd9,0xffcc,0x0005,0x0012,0x0027,0x0018,
-0xffdb,0xfffd,0x0000,0x000a,0xfff9,0xffea,0xffd0,0x000c,
-0xfff8,0xffdc,0x000c,0xfff7,0xfff4,0x0016,0xfff4,0xffed,
-0xfffa,0xffe4,0x0000,0xffe3,0xffee,0xfffd,0x000b,0x0011,
-0xfff6,0x0012,0xfff6,0x0007,0xffe5,0xffee,0xfff5,0xfff9,
-0x0003,0x001c,0xffd1,0xffc9,0xffee,0x000f,0x0022,0x0010,
-0xfff8,0xffef,0xfff6,0xffd8,0xfff3,0xffde,0xffd1,0x0000,
-0x0005,0xfffc,0x0010,0x0015,0x0008,0xfffe,0xffd6,0xffd5,
-0x000a,0xffe6,0xfff6,0xfffe,0x001f,0x000b,0x001b,0x0013,
-0xffeb,0x000a,0x000c,0xffec,0x0003,0xfff5,0x0019,0xffec,
-0xffe7,0xffe7,0xffe3,0xffe4,0x001c,0x0022,0x0019,0x0026,
-0xffb3,0x0002,0x000b,0xffff,0x0007,0xffd1,0xffcc,0x0005,
-0xffe3,0xffdf,0xffff,0x001c,0x0000,0x000f,0xffe4,0xffe6,
-0xfffe,0xffe2,0x0000,0xfffe,0x0016,0xfffc,0x0021,0x0003,
-0xffdc,0x0015,0xfffd,0x000f,0x0002,0xfffb,0x0004,0xfffc,
-0xfffa,0xfff7,0xffdb,0xffe1,0x0005,0x0020,0x0014,0x001e,
-0x0051,0xffe7,0xfff2,0xfff8,0xffc3,0x0000,0xffe7,0x001c,
-0x0036,0x0014,0xfffd,0xfff2,0x0011,0xfff8,0x0000,0xffd4,
-0x0010,0x0023,0x000d,0x0012,0xffd5,0xfff9,0x0006,0x000b,
-0x0021,0xfffc,0x001e,0x000b,0xffea,0xffd8,0x0006,0xffd5,
-0x0003,0x0032,0xfff2,0xffee,0x0016,0x0012,0xffff,0xfff0,
-0x000c,0xfffc,0x0008,0x001d,0xffd9,0xfff4,0xffe2,0x0021,
-0x0013,0xfff8,0xffeb,0xfffa,0x0008,0x0009,0x000d,0xffe4,
-0x0004,0x001f,0x0018,0x0012,0xffcc,0xffe9,0x000c,0xfffc,
-0x0012,0x0005,0x000e,0x002f,0xffe8,0xffde,0xfff2,0xffe5,
-0x0016,0x0042,0xffea,0xffea,0xffff,0x0010,0xfffa,0xffe8,
-0x0029,0xffee,0xfffe,0xffeb,0xffd3,0xffe8,0xffe2,0x0015,
-0x0021,0x0018,0xffef,0x0018,0x001d,0xfff1,0xfff0,0xffcd,
-0x0015,0x0021,0x000d,0x002d,0xfffd,0xfff8,0x001c,0xfffe,
-0x0007,0xfffe,0x0025,0x0013,0x0007,0xffe5,0x0016,0xffd9,
-0xfff9,0x000c,0xfffb,0x0005,0x002d,0x0023,0xfff1,0xffff,
-0xffe5,0x0001,0x0014,0x0011,0xffe8,0xffda,0xffdd,0x001a,
-0xffff,0xfffc,0xffdd,0x0020,0x0015,0x0003,0xfffe,0xffdd,
-0x0008,0x001d,0x0018,0x002c,0xfff4,0xffe8,0x0022,0xffee,
-0xfff8,0x0007,0x0015,0x0037,0x0005,0xffeb,0x0002,0xffe9,
-0x000b,0x001c,0xfff3,0x0001,0x0016,0x0021,0xffeb,0xfff6,
-0x0024,0xfff3,0xfffb,0xfff9,0xffd8,0xffcd,0xffe4,0x0024,
-0x0034,0x001b,0x0012,0xffdc,0x0002,0xffea,0x0000,0xffdf,
-0x0015,0x0002,0xfffd,0xfff3,0xffe6,0x000b,0x000e,0x0004,
-0x000a,0xfff6,0x0012,0xfff2,0xffea,0xffdc,0x0018,0xffeb,
-0x0001,0x001c,0xffd8,0xffd6,0x002a,0x0005,0x0019,0x0005,
-0xffe0,0x0006,0x0011,0x001f,0xffed,0xffbf,0xffdf,0x0029,
-0x0010,0xffff,0x0000,0xffe3,0xfffa,0xfffc,0x000d,0xffef,
-0x0009,0xffff,0x0008,0xfff2,0xffdd,0xfffd,0x0013,0xfff5,
-0xfffc,0x0000,0x0001,0x0015,0xffe9,0xffe2,0x0003,0xfffb,
-0x0014,0x002c,0xffd0,0xffd2,0x0013,0x0003,0x0014,0xfffd,
-0xfffd,0xfff9,0x0006,0xffec,0xffe7,0xffb3,0xffe0,0x001d,
-0x001f,0x001e,0x0004,0x0002,0x000e,0xffe3,0xfff0,0xffd8,
-0x001a,0x0000,0xfffd,0x000c,0x000d,0x000a,0x0024,0xfff7,
-0xfff1,0xfff8,0x0018,0xfffa,0x0007,0xffea,0x0028,0xffef,
-0xfff8,0xfff7,0xffe1,0xffee,0x0042,0x0016,0x000b,0x0013,
-0xffb8,0x000d,0x001d,0x0012,0xfffc,0xffa6,0xffdb,0x0022,
-0xfffc,0x0001,0xfff3,0x0009,0x0006,0xfff5,0xfffe,0xffe8,
-0x000d,0xfffd,0x0007,0x000b,0x0004,0xfffc,0x002a,0xffe7,
-0xffe1,0x0001,0x0008,0x001d,0x0006,0xffef,0x0013,0xfffe,
-0x000a,0x0006,0xffda,0xffea,0x002a,0x0013,0x0006,0x000b,
-0x0074,0xffec,0xffbc,0xffe2,0xffe4,0x0053,0x001c,0xffee,
-0x0020,0xffea,0xfff3,0xffeb,0x0005,0x001c,0x0005,0xfff9,
-0xffe8,0xfff8,0xffea,0x0011,0xffe9,0x001e,0xffe7,0x002d,
-0x000f,0xfff7,0xfff5,0xffee,0x0016,0xfff6,0x0004,0xfffe,
-0x0013,0xfff4,0x0017,0x0003,0xffd5,0x0002,0x000c,0xfffc,
-0x002f,0x0000,0xffd3,0x0007,0xfff9,0x0045,0x0017,0xfff3,
-0xfffe,0xffcd,0xffe0,0xfff2,0xfffd,0x002f,0x0013,0x0008,
-0xffdb,0xfff5,0xfff6,0x0010,0xffe0,0x000f,0xffed,0x001d,
-0x0000,0x0001,0xffe4,0x0012,0x0014,0xfffc,0xfff0,0x000d,
-0x0026,0x0003,0x000f,0x0000,0xffbe,0x0000,0x0007,0xfff3,
-0x004d,0xfff3,0xffc8,0xffd5,0xfff3,0x0039,0x0017,0xffe6,
-0x000b,0xffed,0xffe5,0x0010,0x0011,0x0016,0xfff6,0xfff1,
-0xffed,0xfff6,0xffea,0x002b,0x0010,0x001e,0xfffe,0x001f,
-0xfff5,0xfffa,0xfffb,0xfff7,0x0034,0x0002,0x0014,0x0000,
-0x0008,0xffce,0x0021,0x001b,0xffed,0x0013,0xffff,0x0009,
-0x0008,0x0006,0xffdf,0xfffc,0x0007,0x002c,0x0012,0xffeb,
-0xffe9,0xffd0,0xffd2,0x0018,0x0009,0x0028,0x0003,0x0001,
-0xffe0,0xfff3,0xfff5,0x002b,0x0007,0x000e,0x0003,0x000f,
-0xffe6,0x0003,0xffeb,0x001a,0x0032,0x0008,0x0000,0x0010,
-0x001b,0xffde,0x0019,0x0017,0xffd5,0x0011,0xfffa,0x0001,
-0x0047,0xfff7,0xffc5,0xffe3,0xfff8,0x001e,0x001a,0xfff5,
-0x001e,0xfff0,0x0008,0xffd4,0xfff7,0x000e,0x0005,0x0002,
-0xffed,0xffd8,0xffda,0xfff1,0xfff9,0x0032,0xffef,0x0026,
-0xfff9,0xfff2,0xffe8,0xffd5,0x0016,0xfffa,0x0016,0x0013,
-0x0011,0xffde,0xfffe,0xffec,0xffe9,0xfff6,0x0027,0x0010,
-0x0002,0x000b,0xffdc,0x0009,0x000d,0x0011,0x0015,0xfffa,
-0xfffb,0xffd3,0xfff6,0xffdc,0xffee,0x0021,0x0013,0x0013,
-0xffe1,0xffd4,0xffe5,0xfff1,0xfff0,0x0022,0xfff5,0x0016,
-0xffea,0xfffc,0xffd8,0xfff9,0x0015,0x0000,0x0001,0x0023,
-0x0024,0xffee,0xfff6,0xffe8,0xffd2,0xfff4,0x0022,0x0008,
-0x0020,0xfffe,0xffd1,0xffd6,0x0007,0x0005,0x0015,0xffee,
-0x0009,0xfff4,0xfffb,0xfffb,0x0002,0x0008,0xfff6,0xfffc,
-0xfff2,0xffd6,0xffda,0x000a,0x0021,0x0031,0x0005,0x0018,
-0xffdf,0xfff4,0xffef,0xffdd,0x0034,0x0006,0x0026,0x0016,
-0x0007,0xffb8,0x0007,0x0003,0x0000,0x0006,0x0019,0x001e,
-0xffdc,0x0012,0xffe8,0xfffd,0x001c,0xfff9,0x0010,0xfff3,
-0xffe6,0xffd7,0xffe8,0x0001,0xfffb,0x001a,0x0003,0x000c,
-0xffe5,0xffd2,0xffe5,0x000a,0x0018,0x0022,0x000a,0x0008,
-0xffcf,0xfffe,0xffde,0x0000,0x0033,0x000c,0x0011,0x0026,
-0x0019,0xffc8,0x0000,0x0000,0xffea,0x0003,0x0014,0x0016,
-0x0079,0xfff7,0xffce,0xfff6,0xffd8,0x0028,0x002b,0x0009,
-0x003a,0x000c,0xffe7,0xffd7,0x000b,0x0002,0x001f,0xfffb,
-0xfff8,0x0013,0xfff1,0x0020,0xffd7,0x001e,0xfff0,0x0010,
-0x0014,0xffe4,0x0000,0xfffd,0x001a,0xffea,0x0013,0x0000,
-0x0024,0x0004,0x0016,0x000c,0xfffa,0xfff7,0xffff,0xffe8,
-0x0034,0x000a,0xffe5,0x001b,0xffee,0x001a,0x0026,0x000e,
-0x0017,0xfff0,0xffd4,0xffdf,0x0003,0x0014,0x002d,0x000a,
-0xffec,0x000f,0xfffd,0x001f,0xffce,0x000e,0xfff6,0x0000,
-0x0005,0xffef,0xfff1,0x0020,0x0018,0xfff0,0xffff,0x000f,
-0x0037,0x0014,0x000e,0x0008,0xffe3,0xfff4,0xfff9,0xffe0,
-0x0052,0xfffd,0xffda,0xffe9,0xffe8,0x000f,0x0026,0x0002,
-0x0025,0x000f,0xffd9,0xfffe,0x0017,0xfffc,0x000f,0xfff4,
-0xfffd,0x0011,0xfff1,0x003a,0xffff,0x001d,0x0006,0x0002,
-0xfffb,0xffe6,0x0007,0x0004,0x0038,0xfff7,0x0023,0x0003,
-0x0019,0xffdf,0x0020,0x0024,0x0011,0x0007,0xfff1,0xfff7,
-0x000d,0x0011,0xfff1,0x000f,0xfffd,0x0001,0x0021,0x0007,
-0x0001,0xfff4,0xffc6,0x0005,0x000f,0x000d,0x001d,0x0003,
-0xfff0,0x000d,0xfffc,0x0039,0xfff6,0x000d,0x000b,0xfff3,
-0xffeb,0xfff1,0xfff7,0x0028,0x0037,0xfffd,0x000e,0x0013,
-0x002c,0xffef,0x0018,0x0020,0xfffb,0x0004,0xffeb,0xffee,
-0x004c,0x0001,0xffd7,0xfff7,0xffed,0xfff4,0x0029,0x0011,
-0x0037,0x0012,0xfffd,0xffc1,0xfffd,0xfff4,0x001e,0x0005,
-0xfffd,0xfff4,0xffe1,0x0000,0xffe8,0x0031,0xfff8,0x0009,
-0xffff,0xffdf,0xfff4,0xffe3,0x001b,0xffee,0x0025,0x0015,
-0x0022,0xffef,0xfffd,0xfff5,0x000e,0xffe9,0x0019,0xfffe,
-0x0007,0x0016,0xffee,0x001d,0x0001,0xffe7,0x0024,0x0015,
-0x0014,0xfff7,0xffea,0xffc8,0xfff5,0x0006,0x002d,0x0015,
-0xfff1,0xfff0,0xffec,0xffff,0xffdf,0x0022,0xfffe,0xfffa,
-0xffef,0xffe9,0xffe4,0x0006,0x0019,0xfff4,0x0010,0x0025,
-0x0035,0xffff,0xfff5,0xfff1,0xfff8,0xffe7,0x0014,0xfff5,
-0x0025,0x0008,0xffe3,0xffea,0xfffc,0xffdb,0x0024,0x0009,
-0x0022,0x0016,0xffef,0xffe8,0x0008,0xffee,0x000f,0xfffe,
-0x0001,0xfff2,0xffe1,0x0019,0x000f,0x0030,0x000d,0xfffc,
-0xffe4,0xffe1,0xfffb,0xffeb,0x0039,0xfffc,0x0035,0x0018,
-0x0017,0xffc9,0x0006,0x000c,0x0025,0xfffa,0x000b,0x000b,
-0xffe1,0x001c,0xfffa,0x0010,0x0010,0xffce,0x001f,0x000e,
-0x0000,0xfffa,0xffdc,0xffef,0x0000,0x0000,0x001d,0x000e,
-0xfff5,0xffee,0xffec,0x0019,0x0006,0x0021,0x0013,0xffec,
-0xffd5,0xffeb,0xffeb,0x000e,0x0037,0x0000,0x0020,0x0028,
-0x002a,0xffd9,0xffff,0x0008,0x000e,0xfff8,0x0006,0x0003,
-0x0077,0xffe8,0xffd9,0xffd4,0xffcd,0x0042,0xfff2,0x000f,
-0x001f,0xffe6,0xffff,0x0000,0x0007,0x0010,0xffed,0xffe4,
-0xffed,0x0016,0xffe6,0x0004,0xfff3,0x001c,0xfff0,0x001d,
-0x0005,0xffff,0x0010,0xfff0,0x0008,0xffdd,0xfff6,0xffd6,
-0xfffc,0x0011,0x001d,0xffed,0xffd6,0xfff9,0x0000,0xfff1,
-0x0032,0xfffd,0xfff0,0xfffb,0xffe2,0x0035,0xffed,0x0014,
-0xfffd,0xffc9,0xffed,0x0008,0x0000,0x0022,0xfffb,0xfff5,
-0xffe0,0x0012,0xfff1,0x0004,0xffea,0x000d,0xfff6,0x000d,
-0xfff7,0x0008,0x0000,0x0013,0x0007,0xffe3,0xffe1,0xffe6,
-0x000d,0x0021,0x0015,0xffea,0xffbf,0xfff7,0xfffc,0xffe9,
-0x004f,0xffef,0xffe5,0xffc8,0xffdc,0x0029,0xffed,0x0008,
-0x000a,0xffea,0xfff1,0x0027,0x0014,0x0009,0xffdd,0xffdd,
-0xfff1,0x0014,0xffe6,0x001f,0x001a,0x001b,0x0006,0x000f,
-0xffec,0x0000,0x0017,0xfff8,0x0026,0xffea,0x0005,0xffda,
-0xfff1,0xffec,0x0027,0x0004,0xffee,0x0009,0xfff3,0xffff,
-0x000a,0x0003,0xfffc,0xffee,0xfff1,0x001b,0xffe8,0x000d,
-0xffe8,0xffcd,0xffde,0x002f,0x000c,0x001c,0xffeb,0xffed,
-0xffe5,0x0010,0xfff1,0x001e,0x0011,0x000c,0x000c,0x0000,
-0xffdc,0x000a,0x0007,0x001b,0x0025,0xfff0,0xfff1,0xffea,
-0x0003,0xfffc,0x001f,0x0001,0xffd6,0x0007,0xffee,0xfff7,
-0x004a,0xfff4,0xffe2,0xffd6,0xffe2,0x000e,0xfff0,0x0017,
-0x001d,0xffed,0x0014,0xffeb,0xfff9,0x0001,0xffed,0xffef,
-0xfff2,0xfff6,0xffd5,0xffe5,0x0003,0x0030,0xfff8,0x0016,
-0xfff0,0xfff9,0x0004,0xffd6,0x0009,0xffe1,0x0006,0xffec,
-0xfffa,0xfffc,0x0003,0xffd5,0xffea,0xffec,0x001c,0x0005,
-0x0005,0x0007,0xfff9,0xfffc,0xfff7,0x0000,0xffeb,0x001c,
-0xfffa,0xffd0,0x0002,0xfff2,0xfff1,0x0014,0xfffb,0x0000,
-0xffe5,0xfff2,0xffe0,0xffe4,0xfffb,0x0020,0xfffe,0x0006,
-0xffe0,0x0003,0xfff4,0xfffb,0x0008,0xffe7,0xfff2,0xfffc,
-0x000c,0x000b,0xfffc,0xffd1,0xffd3,0xffea,0x0016,0xfffe,
-0x0022,0xfffa,0xffee,0xffc9,0xfff1,0xfff5,0xffeb,0x0010,
-0x0008,0xfff0,0x0006,0x0010,0x0005,0xfffc,0xffdd,0xffe8,
-0xfff6,0xfff4,0xffd5,0xffff,0x002b,0x002f,0x000e,0x0008,
-0xffd5,0xfffb,0x000a,0xffde,0x0027,0xffee,0x0016,0xfff0,
-0xffef,0xffd6,0x000d,0xffed,0x0001,0xfffd,0x000e,0x0014,
-0xffde,0x000e,0x0004,0xffef,0x0005,0xffe8,0xffe6,0x0014,
-0xffe5,0xffd3,0xfff4,0x0018,0xfffe,0x000d,0xffeb,0xfff8,
-0xffea,0xfff0,0xffe0,0xfffe,0x0022,0x001f,0x0014,0xfff9,
-0xffc6,0x0005,0xfffb,0x0002,0x0026,0xfff4,0x0002,0xffff,
-0x0001,0xffe6,0x0005,0xffe9,0xffeb,0xfffa,0x0008,0x000b,
-0x007c,0xfff3,0xffeb,0xffe9,0xffc2,0x0017,0x0000,0x002b,
-0x0039,0x0008,0xfff3,0xffee,0x000e,0xfff6,0x0006,0xffe6,
-0xfffd,0x0031,0xffed,0x0013,0xffe1,0x001b,0xfff9,0x0000,
-0x000b,0xffec,0x001d,0xffff,0x000c,0xffd1,0x0004,0xffd9,
-0x000b,0x0022,0x001c,0xfff7,0xfffb,0xffed,0xfff3,0xffde,
-0x0037,0x0006,0x0001,0x000e,0xffd7,0x000a,0xfffc,0x0030,
-0x0016,0xffec,0xffe1,0xfff6,0x0005,0x0007,0x0014,0xfff7,
-0xfff0,0x002d,0xfff8,0x0013,0xffd8,0x000c,0xffff,0xfff1,
-0xfffc,0xfff6,0x000c,0x0022,0x000b,0xffd7,0xfff0,0xffe8,
-0x001e,0x0031,0x0014,0xfff3,0xffe4,0xffea,0xffee,0xffd5,
-0x0054,0xfffa,0xfff7,0xffdc,0xffd1,0xffff,0xfffc,0x0024,
-0x0024,0x000c,0xffe5,0x0014,0x001a,0xffef,0xfff7,0xffdf,
-0x0001,0x002f,0xffed,0x002e,0x0009,0x001b,0x000f,0xfff3,
-0xfff1,0xffee,0x0023,0x0006,0x002a,0xffdf,0x0014,0xffdc,
-0x0001,0xfffc,0x0026,0x000e,0x0012,0xfffe,0xffe5,0xffec,
-0x000f,0x000d,0x000d,0x0001,0xffe6,0xfff2,0xfff7,0x0029,
-0x0001,0xfff0,0xffd2,0x001b,0x0012,0x0001,0x0004,0xfff0,
-0xfff5,0x002b,0xfff8,0x002d,0x0000,0x000b,0x0015,0xffe3,
-0xffe2,0xfff8,0x0013,0x002a,0x0029,0xffe4,0x0000,0xffec,
-0x0014,0x000b,0x001e,0x000a,0xfffc,0xfffb,0xffe0,0xffe4,
-0x004f,0xfffe,0xfff4,0xffea,0xffd6,0xffe4,0xffff,0x0033,
-0x0036,0x000f,0x0008,0xffd7,0x0000,0xffe8,0x0006,0xfff1,
-0x0001,0x0011,0xffdc,0xfff4,0xfff2,0x002f,0x0000,0xfffa,
-0xfff5,0xffe6,0x0010,0xffe5,0x000d,0xffd5,0x0016,0xffee,
-0x000a,0x000c,0x0002,0xffde,0x000f,0xffdf,0x000d,0xfff3,
-0x000a,0x0012,0x000a,0x000f,0xffeb,0xffd7,0xfffa,0x0038,
-0x0013,0xfff3,0xfff7,0xffdf,0xfff7,0xfffa,0x0014,0x0001,
-0xfff5,0x000d,0xffe8,0xfff3,0xffe9,0x0020,0x0006,0xffea,
-0xffe6,0xfff1,0x0000,0x0008,0x000c,0xffdb,0x0001,0xfffe,
-0x001c,0x001b,0xfffb,0xffdb,0xfff9,0xffdd,0x0008,0xffeb,
-0x0027,0x0004,0x0000,0xffdd,0xffe5,0xffcb,0xfffa,0x002c,
-0x0021,0x0012,0xfffb,0xfffe,0x000b,0xffe1,0xfff7,0xffea,
-0x0006,0x000f,0xffdc,0x000d,0x0019,0x002e,0x0017,0xffec,
-0xffdb,0xffe8,0x0017,0xffed,0x002b,0xffe3,0x0026,0xfff2,
-0x0000,0xffe6,0x000c,0xfff6,0x0026,0xfff0,0x0000,0x0000,
-0xffe3,0x0019,0x0016,0x0002,0xfffa,0xffbd,0xfff5,0x0031,
-0xffff,0xfff6,0xffe8,0x0005,0x0003,0xfff3,0x0004,0xfffb,
-0xfffa,0x000b,0xffe7,0x000c,0x0010,0x001f,0x001c,0xffdc,
-0xffcb,0xfff3,0x0006,0x0010,0x002a,0xffe8,0x0011,0x0001,
-0x0012,0xfff6,0x0004,0xfff3,0x000f,0xffee,0xfffb,0xfff9,
-0x001d,0xffe7,0xffea,0xfffe,0x0006,0x0043,0x000b,0xffcf,
-0x0001,0x000a,0x0018,0xfffb,0xfffd,0x000d,0xfffc,0x0005,
-0x0006,0xfff5,0x0019,0xfff4,0xfff0,0xffe1,0xffe4,0x0024,
-0x0035,0x000d,0xfffa,0xfff0,0xffd6,0x0018,0xffef,0xffff,
-0xffee,0x000a,0xfffc,0x000d,0xfff1,0x0012,0x0005,0x0007,
-0xffd9,0xfffc,0x0000,0x0023,0x001b,0x0035,0x0006,0xffd4,
-0xffdf,0xffee,0x0005,0x0002,0xfff5,0x001f,0x0009,0x0016,
-0xfffa,0xfff1,0x0024,0xfff3,0xffe7,0xffd2,0xffe9,0x0014,
-0x0025,0x0018,0xffe9,0x0013,0xffd5,0x001d,0xffda,0x000e,
-0x0000,0x001a,0xfff4,0x000a,0xffda,0x0010,0x0000,0x0000,
-0xfff6,0xffee,0xfff6,0xfff1,0x0015,0x0029,0x0006,0xffc8,
-0xffed,0x000d,0x0009,0x0021,0x0009,0x0006,0xffec,0xffff,
-0x000b,0xfff3,0x0018,0x000d,0x0017,0xffe0,0xfffa,0x0016,
-0x001a,0x000f,0x0000,0xfff8,0xfff4,0x0025,0xffff,0x0002,
-0xffe4,0xffe5,0x0005,0x0025,0x0007,0x0023,0xfff8,0x0015,
-0xffb1,0x0002,0x000c,0x0016,0x002a,0x001c,0x0001,0xffcd,
-0xffca,0xfff1,0xfff8,0x0029,0x0000,0x0018,0xfffa,0x000f,
-0xffff,0xffef,0x0024,0x000c,0x000e,0xffd1,0x0000,0x0006,
-0x000b,0x001a,0xfff0,0x001b,0xfff3,0x002b,0xffea,0x0012,
-0xfff6,0xfff4,0xfffe,0x0022,0xfff1,0x0021,0xfff3,0x000d,
-0xfff1,0xfff3,0xfff3,0xffff,0x001a,0x000e,0x0009,0xffd7,
-0xffff,0x0010,0x002e,0xffe5,0xffee,0xffff,0xfffc,0x0010,
-0x000b,0xffd5,0x0008,0xffd3,0x0000,0xfff5,0xffeb,0x001d,
-0x001e,0x0008,0xffed,0xffd6,0xffd7,0x001c,0x0000,0x0014,
-0xffec,0xfff5,0xffe2,0xfff6,0x0004,0x0005,0x0020,0x001c,
-0xffac,0x0006,0x0009,0x0024,0x002f,0x0001,0x0004,0xffdc,
-0xffdc,0xfff4,0x001b,0xffec,0xffe6,0x0011,0x0009,0x0021,
-0xffff,0xffd1,0x0013,0xffd2,0xfff7,0xffe5,0xfff1,0x000d,
-0x000f,0x0012,0xffdd,0xfffa,0xffd6,0x0021,0xffec,0x0024,
-0xffff,0x0004,0xffda,0xfff2,0xffee,0x0002,0x001b,0x0014,
-0xffc9,0xfffa,0xffff,0xfff2,0x0029,0xfff6,0x0004,0xffd0,
-0xffea,0x0014,0x001f,0x000a,0xfffb,0xfff9,0xffec,0x0009,
-0x0010,0xffd3,0x0008,0xffed,0x0028,0xfff4,0x0001,0x000f,
-0x0004,0x000a,0xfff4,0xffde,0xfff5,0x0029,0x0010,0x0018,
-0xffe2,0xffcf,0xffec,0x000d,0x001c,0x0016,0x0012,0x002b,
-0xff84,0x000d,0x0015,0x0017,0x003e,0xffe9,0x0000,0xffd5,
-0xffc7,0xfff8,0x000d,0x0012,0xfff2,0x000a,0xfffa,0x001a,
-0x0003,0xffcf,0x0013,0xffed,0x001f,0xffe5,0x0007,0x0000,
-0xfff5,0x0014,0xffe3,0x0001,0xfff4,0x002f,0xfffc,0x0027,
-0xfff5,0xffde,0xffe4,0x0009,0x0005,0x0013,0x000d,0x0022,
-0x0022,0xfff2,0xfffc,0x0011,0xfffb,0x0018,0x001a,0xffec,
-0x001b,0x002d,0x000c,0xffe8,0x0002,0xfff3,0x0015,0x0008,
-0x0016,0x0010,0x0020,0x0002,0xffde,0xffe1,0xffec,0x0007,
-0x003a,0xfffb,0x0005,0xfffe,0xffda,0x000c,0xfffe,0x0001,
-0xffff,0x001a,0xfffb,0x0017,0x0015,0x0006,0xfff8,0xfff5,
-0xffde,0x0006,0x0012,0x0037,0x000f,0x000b,0x0015,0xfff0,
-0xfff8,0x0010,0xfffa,0xfff0,0xfffb,0x0004,0x0023,0x0018,
-0x000a,0x000c,0x002b,0x0001,0xffd5,0xffd1,0xfff2,0xfff8,
-0x002b,0x0005,0xfff6,0x0022,0xffd9,0x0012,0xffea,0x0010,
-0x0011,0x002a,0xfff3,0x0013,0xffff,0x0003,0xfff2,0xffec,
-0xfffb,0xfff9,0x0007,0x0004,0x0009,0x0000,0x0015,0xffe4,
-0x0006,0x0030,0xfffe,0x000e,0x000f,0xffec,0x0005,0x0000,
-0x001b,0x000e,0x0020,0x001c,0x0005,0xffe0,0x0002,0xfffa,
-0x0020,0xfffd,0x000c,0x0005,0xfff8,0x0019,0x000e,0x0004,
-0xfff4,0xfff5,0x0004,0x002f,0x002d,0x0016,0xffea,0x0002,
-0xffb6,0x000c,0x001e,0x002a,0x001e,0xfff2,0x0010,0xffe9,
-0xffe3,0x0013,0xffec,0x0015,0x0007,0xffff,0x0013,0x0011,
-0x000e,0x000a,0x002b,0x001b,0xfffd,0xffd0,0x0008,0xffea,
-0x0010,0x0007,0xfffc,0x002a,0xfff7,0x001f,0xfffa,0x0014,
-0x0006,0x0004,0xfffd,0x002b,0x0016,0x0014,0xffe4,0xfffb,
-0xfff6,0xfffd,0x0004,0x0012,0x000f,0xffe5,0x0018,0xfff3,
-0x0018,0x0033,0x0022,0xffd1,0xfff4,0xffe4,0x0015,0x0013,
-0x001b,0xfff0,0x000f,0xffe2,0xffef,0xfff4,0xfff4,0x0000,
-0x0024,0xfff6,0xfff9,0xffe5,0xffdb,0x0010,0x000f,0x0016,
-0xfffd,0x0004,0xffe1,0xffff,0x002a,0xfff9,0x0012,0x0009,
-0xffb1,0x0011,0x001b,0x0038,0x0024,0xffd7,0x0013,0xfff8,
-0xfff6,0x0016,0x000f,0xffd9,0xffec,0xfff7,0x0023,0x0023,
-0x000f,0xffec,0x001a,0xffe1,0xffe6,0xffe5,0xfffa,0xfff1,
-0x0014,0x0000,0xffe9,0x0008,0xffda,0x0016,0xfffb,0x0026,
-0x000f,0x0014,0xffd9,0xfffc,0x0012,0xfff7,0x000d,0x0001,
-0xffce,0x0003,0x0010,0x0005,0x001e,0xffcb,0x0013,0xffec,
-0x0003,0x0037,0x0013,0xfff8,0x0000,0xffde,0x0005,0x000b,
-0x0020,0xffee,0x000f,0xfffc,0x0016,0xfff3,0x000a,0xfff3,
-0x0009,0xfff8,0x0000,0xffed,0xfff9,0x001d,0x001f,0x001a,
-0xfff3,0xffdf,0xffeb,0x0016,0x0041,0x0009,0x0004,0x0017,
-0xff89,0x0018,0x0027,0x002c,0x0033,0xffbe,0x000e,0xfff1,
-0xffe1,0x001a,0x0001,0x0000,0xfff9,0xfff0,0x0013,0x001c,
-0x0013,0xffea,0x001a,0xfffc,0x000d,0xffe4,0x0010,0xffe3,
-0xfffb,0x0001,0xfff0,0x0010,0xfff8,0x0023,0x000a,0x002a,
-0x0004,0xffef,0xffe3,0x0013,0x002a,0x0007,0x0000,0x000f,
-0x001f,0xffe4,0x0006,0xfff0,0xfff0,0x0032,0xffe1,0xfff2,
-0x0000,0x0006,0x0024,0x0011,0x0000,0x0000,0xffe3,0xfff2,
-0x000b,0x0012,0x0014,0xffe7,0xfffa,0xffdf,0xffed,0x0014,
-0x002b,0x0015,0x0015,0xfff2,0xffc9,0x0000,0xffe0,0xffd8,
-0xffd6,0x0027,0x0001,0xfff8,0xfff2,0x0008,0xfffa,0xfffd,
-0xffdb,0xfff8,0x001d,0x0016,0x0004,0x0025,0xffdc,0xfff7,
-0xffde,0xffea,0x0011,0x0018,0xfff8,0x0012,0xfff1,0x0002,
-0xffff,0x000e,0x001f,0xffe7,0xfff1,0xffd0,0xfff3,0x0004,
-0x001c,0x001f,0x0005,0x0015,0xffc7,0x0004,0xffcb,0xffe8,
-0xffe9,0x0037,0xfffa,0xfff4,0xffdb,0x0006,0xfff5,0xfff5,
-0xfff9,0xffea,0x0012,0xffe3,0xffff,0x0019,0xffdc,0xffeb,
-0xffec,0x0009,0x0016,0x0038,0x000b,0xfffa,0xffd3,0xffeb,
-0x000f,0x0010,0x0014,0x0001,0x0021,0xffde,0x0002,0x0006,
-0x0011,0x0017,0x001c,0xfffa,0xffe7,0x000c,0xfff0,0xffdb,
-0xffcb,0x0001,0x000b,0x000f,0x0008,0x0019,0xffec,0x000b,
-0xffb4,0xffff,0x0029,0x0009,0x0013,0x000c,0xffd7,0xffef,
-0xffc9,0xffee,0x0003,0x003f,0x0003,0x000c,0xffe2,0xfffb,
-0x0003,0x000c,0x001f,0x0000,0x0018,0xffcf,0x0008,0xfff7,
-0x0001,0x0021,0x000c,0x001d,0xffe5,0x0012,0xffdb,0xffeb,
-0xffde,0x0011,0x0003,0x000b,0xfff2,0x0017,0xffe7,0x0002,
-0xfff3,0xffef,0x000f,0xfff1,0x0003,0xffff,0xffdf,0xfff9,
-0xffff,0x000c,0x003a,0xfffb,0xfff1,0xfff3,0xffe3,0xfffd,
-0x0010,0xfff3,0x0004,0xffc7,0x000a,0xfff3,0xfff5,0x000d,
-0x0015,0x000f,0x0009,0xffd8,0xffc9,0x0003,0xfff2,0xffed,
-0xffd4,0x0011,0xffe8,0xffe0,0x0005,0xfffc,0x0015,0x0012,
-0xffae,0x0003,0x0026,0x0017,0x0018,0xfff1,0xffda,0xfffe,
-0xffdb,0xfff1,0x0027,0x0002,0xffe9,0x0004,0xfff1,0x000c,
-0x0003,0xffef,0x000f,0xffc6,0x0001,0xffe3,0xfffa,0xfffe,
-0x0005,0x001a,0xfff9,0xfffc,0xffc8,0x0009,0xffdd,0xfffd,
-0xffe7,0x0021,0xffe0,0xffdc,0xffef,0xfff9,0x000f,0x0009,
-0xffcc,0xfff6,0x001b,0xffe5,0x0012,0xffe6,0xffda,0xfff2,
-0xffe9,0x0010,0x002c,0x0021,0xfffd,0xffec,0xffd3,0xfff6,
-0x0014,0xfff1,0x0003,0xffe1,0x0032,0xfff2,0x000a,0x0000,
-0xfffb,0x0011,0x000f,0xffe0,0xffe8,0x0010,0x0001,0xfff1,
-0xffc9,0xffec,0xfff2,0xfff8,0x001d,0x000c,0x0007,0x0020,
-0xff87,0x0009,0x0032,0x000a,0x0028,0xffd8,0xffd5,0xfff7,
-0xffc6,0xfff4,0x0019,0x0029,0xfff5,0xfffe,0xffe1,0x0005,
-0x0008,0xffed,0x000f,0xffe0,0x0029,0xffe2,0x0010,0xfff0,
-0xffec,0x001c,0x0000,0x0003,0xffe6,0x0016,0xffed,0x0000,
-0xffdc,0xfffc,0xffea,0xfff4,0x0006,0x0009,0x0001,0x0018,
-0x0024,0xffee,0x0018,0x0003,0xffe4,0x0007,0xfff0,0x000d,
-0x001a,0x0029,0x0018,0xffff,0x0005,0xffe6,0xfffd,0xfff4,
-0x001b,0x002e,0x001b,0xfff6,0xffe8,0xffde,0xfff6,0xfff8,
-0x0031,0x0002,0x0022,0x0000,0xffcd,0xfff4,0xffef,0xffda,
-0xffe7,0x0038,0x0000,0x0000,0x0016,0xfffd,0xffec,0xffea,
-0xffe0,0x0002,0x002f,0x002a,0xfff9,0xfffb,0xffeb,0x0012,
-0xfff7,0x000c,0x0005,0x0005,0xfffe,0xfff8,0x000a,0x0004,
-0x000e,0x002a,0x0026,0xfff6,0xffdf,0xffcf,0xfffb,0xffe8,
-0x0021,0x000c,0x0011,0x0023,0xffcc,0xfffa,0xffda,0xffea,
-0xfff9,0x0048,0xfff9,0xfffd,0x0000,0xfffa,0xffe7,0xffe2,
-0xfffe,0xfff5,0x0024,0xfff7,0xfff3,0xffef,0xffeb,0x0006,
-0x0005,0x002d,0x000a,0x0024,0x0012,0xffdf,0xffed,0xffed,
-0x001f,0x002c,0x001b,0x000f,0x0010,0xffde,0x000b,0xffea,
-0x0016,0x0004,0x0028,0x0007,0xffeb,0x0000,0xffff,0xffdd,
-0xffdc,0x0012,0x000a,0x0018,0x002e,0x000c,0xffde,0xfff8,
-0xffb9,0x0009,0x003b,0x001d,0x0008,0xffe2,0xffe6,0x000b,
-0xffe2,0x0010,0xfff8,0x002c,0x0009,0xfff2,0xfffb,0xfffe,
-0x0013,0x0028,0x0026,0x000f,0x0007,0xffce,0x0011,0xffda,
-0x0007,0x000e,0x0018,0x002b,0xffea,0x0006,0xffea,0xffed,
-0xffef,0x0022,0x0002,0x0014,0x0017,0x000a,0xffd9,0xfff0,
-0xfff8,0xfffa,0x0021,0x0004,0xfff9,0xffd4,0xffee,0x0015,
-0x0017,0x0030,0x002e,0xffe8,0xfff7,0xffd8,0xfffd,0xffff,
-0x0020,0x000d,0x000b,0xffd5,0xfff9,0xfff2,0xfffd,0xfff1,
-0x001a,0xfffd,0x0015,0xffe6,0xffce,0xfff8,0x0000,0xfff0,
-0xffe5,0x0022,0xffe7,0xffe9,0x002b,0xffef,0x0006,0xffff,
-0xffb3,0x000d,0x0038,0x002b,0x000d,0xffc7,0xffe9,0x001a,
-0xfff5,0x0013,0x001b,0xfff0,0xffef,0xffea,0x000a,0x000f,
-0x0013,0x000a,0x0016,0xffd5,0xfff0,0xffe2,0x0002,0xffe1,
-0x000b,0x0006,0x0005,0x0009,0xffcc,0xfffe,0xffec,0x0000,
-0xfff8,0x0032,0xffdf,0xffe5,0x0013,0xffed,0x0001,0xfff7,
-0xffd1,0x0000,0x002d,0xfff9,0x0007,0xffbb,0xffe9,0x000d,
-0x0002,0x0033,0x0020,0x000e,0x0003,0xffd1,0xffed,0xfff8,
-0x0025,0x000b,0x000a,0xfff0,0x0020,0xfff1,0x0013,0xffe3,
-0x0000,0xffff,0x001c,0xffee,0xffec,0x0004,0x0010,0xfff3,
-0xffda,0xfffd,0xfff1,0x0000,0x0042,0x0000,0xfff9,0x000d,
-0xff8c,0x0014,0x0044,0x001e,0x001c,0xffad,0xffe4,0x0012,
-0xffe0,0x0016,0x000d,0x0015,0xfffb,0xffe4,0xfffb,0x0007,
-0x0018,0x0008,0x0016,0xffef,0x0017,0xffe2,0x0019,0xffd3,
-0xfff1,0x0009,0x000b,0x0012,0xffea,0x000a,0xfffc,0x0002,
-0xffed,0x000c,0xffe9,0xfffd,0x002b,0xfffe,0xfff4,0x0004,
-0x0048,0xfff3,0xffe3,0xffee,0x0004,0x005a,0x0025,0xffde,
-0x0004,0xffff,0x000d,0xfff7,0xfffa,0x000b,0x0002,0x0018,
-0xfff3,0x0003,0xfff9,0xfff5,0xfffc,0x0004,0xffd6,0x0019,
-0x001f,0xffff,0xfff8,0xffe3,0xfffa,0x0011,0xffed,0x0002,
-0xfff6,0xfffa,0x0026,0x0016,0xffd6,0xffed,0xfffa,0xfff5,
-0x0003,0x0007,0xfffa,0x0014,0x0019,0x004d,0x0020,0xffe3,
-0xffe1,0xffe2,0xfffc,0xfffe,0xfff2,0x001d,0x0010,0x0028,
-0xffe6,0x0000,0x0003,0xfff4,0xfff3,0xfff6,0xffdc,0x0009,
-0x000f,0x0008,0xffe8,0x0006,0xfff9,0x0016,0xffd8,0x0011,
-0x0008,0x0009,0x001f,0x0012,0xffbe,0xffea,0xfff5,0xffed,
-0x0020,0xfffa,0xffef,0xffe1,0x0013,0x0041,0x0021,0xffd7,
-0xfff0,0x0001,0x0000,0x001d,0x0006,0x0004,0xfff3,0x0011,
-0xfff7,0x0001,0xfff8,0x000e,0x0023,0x0003,0xffed,0x000b,
-0x0004,0x0000,0xffff,0xffeb,0x0017,0x001e,0xfffd,0x0005,
-0xffec,0xffd4,0x0030,0x002e,0xffed,0xfffd,0xffec,0x0003,
-0xffdc,0x000d,0x0005,0x0007,0x0028,0x0033,0x001c,0xffdc,
-0xffcc,0xffe5,0xffee,0x0024,0xfffe,0x0016,0x0000,0x0021,
-0xffeb,0xfffe,0x0003,0x000d,0x001a,0xfff5,0xfff2,0xfffc,
-0xfff6,0x000a,0xffee,0x000e,0x0016,0x0024,0xffe8,0x0015,
-0xffff,0xffe4,0x0028,0x002a,0xffd6,0xfffb,0xffe7,0xfffb,
-0x001b,0xffff,0xffec,0xffef,0x0018,0x0026,0x0023,0xffe6,
-0x0001,0x0004,0x0023,0xffe0,0xffeb,0xfffd,0x0002,0x0023,
-0xfff8,0xffe3,0xffe8,0xffd4,0x000c,0x0018,0xffde,0x0012,
-0x0008,0xfff9,0xffeb,0xffc9,0xfffb,0x0015,0xfffe,0x0017,
-0xfff5,0xffe4,0x000d,0xffff,0xffea,0xffdf,0x0015,0x000a,
-0xffd7,0x0012,0x0002,0x0015,0x002d,0x0018,0x001e,0xffeb,
-0xffdf,0xffe8,0x0011,0xffe8,0xffe3,0x000f,0x0010,0x0033,
-0xffeb,0xffdf,0xfff3,0xffd3,0x0003,0x0008,0xffe4,0x0002,
-0xfff9,0x0002,0xffdb,0xffed,0xfff9,0x001b,0xffea,0x0027,
-0x0007,0xfff4,0x0005,0xfffb,0xffd3,0xffdd,0x000f,0x0001,
-0xfff4,0x0004,0xfff8,0xffe3,0x0027,0x000c,0x001e,0xffdf,
-0xffed,0x0008,0x0015,0x0006,0xfff8,0xfff7,0xfff3,0x001c,
-0xfffc,0xffe1,0xffe8,0xffee,0x0034,0x0017,0xfff4,0x0004,
-0xffee,0xfffb,0xfff2,0xffd1,0x0018,0x0022,0x000e,0x001b,
-0xffea,0xffbe,0x0016,0x0016,0x0001,0xfff0,0x0006,0x0018,
-0xffaf,0x0019,0x000e,0x0008,0x003d,0x0000,0x0019,0xffe4,
-0xffca,0xffec,0x0003,0x000e,0xffef,0x0008,0x0000,0x002c,
-0xfff0,0xffdd,0xfff3,0xffee,0x002b,0x0007,0xfffa,0xfff5,
-0xffdf,0x0004,0xffe2,0xfff5,0x0016,0x0028,0xfffa,0x002b,
-0xfffd,0xffce,0x000e,0x0012,0xffea,0xffee,0x0001,0x0010,
-0x004d,0xfffe,0xfff5,0x0001,0xfff9,0x002f,0x0034,0xfffb,
-0x001d,0x0021,0x0001,0xffe4,0x0000,0xfff1,0x001c,0x001a,
-0x0002,0x001e,0x0000,0x0002,0xffea,0x0004,0xffdf,0xfffd,
-0x0024,0xffeb,0x0003,0xfff1,0xfffe,0x0005,0xfffc,0x0004,
-0x0006,0x0009,0x0025,0x001f,0xfffb,0xffe0,0xffec,0xffe2,
-0x0008,0x0011,0x000a,0x0028,0x000d,0x0022,0x002f,0x0000,
-0xfffb,0x0004,0xfff0,0xffeb,0xfff8,0x0002,0x002a,0x002b,
-0xfff6,0x001a,0x000a,0x0002,0xffe1,0xfff5,0xffe5,0xffed,
-0x0015,0xfff6,0xfff4,0x0014,0xfffd,0x000b,0xffe7,0x0014,
-0x0019,0x0019,0x001d,0x001c,0xffe4,0xffde,0xffe7,0xffda,
-0x0025,0x0003,0x0000,0xfff6,0x0007,0x0016,0x0030,0xfff4,
-0x0008,0x0024,0xfff4,0x0009,0x000c,0xffea,0x000c,0x0013,
-0x0006,0x001c,0x0000,0x001d,0x0012,0x0003,0xfff5,0xffef,
-0x000a,0xffee,0x000a,0xfff9,0x001b,0x0012,0x000b,0x0007,
-0xfffd,0xffe4,0x002f,0x0037,0x0012,0xfff1,0xffde,0xfff0,
-0xffe1,0x0018,0x0017,0x001b,0x001d,0x0009,0x002b,0xfff8,
-0xffe6,0x0007,0xffe2,0x0011,0x0004,0xfffd,0x001a,0x0023,
-0xfffb,0x0018,0x000a,0x001c,0x0009,0xfff4,0xfffb,0xffdf,
-0xfffb,0xfff8,0xfffb,0x001d,0x001a,0x0018,0xfff7,0x0017,
-0x000e,0xfff4,0x0027,0x0034,0xfffb,0xffee,0xffd9,0xffe8,
-0x0020,0x0008,0xfffd,0x0002,0x000d,0xfffc,0x0032,0x0001,
-0x001b,0x0027,0x0017,0xffcd,0xfff1,0xffe2,0x001b,0x0025,
-0x0007,0xffff,0xffef,0xffe3,0xfffb,0x0017,0xffe7,0xfff6,
-0x000e,0xffe6,0xfff8,0xffd7,0xffff,0x0009,0x000d,0x001a,
-0x0005,0xfff4,0x000c,0x0007,0x000e,0xffd3,0x0006,0xfff7,
-0xffdc,0x001d,0x0013,0x0029,0x0022,0xffee,0x002d,0x0006,
-0xfff8,0x000a,0x0005,0xffd5,0xffe9,0xfff5,0x002a,0x0035,
-0xfffb,0xfffb,0xfffa,0xffe2,0xfff2,0x0008,0xffec,0xffe6,
-0xffff,0xfff0,0xffe7,0xfffc,0xfffd,0x000f,0xfff9,0x0029,
-0x0017,0x0003,0x0004,0x0003,0xfff8,0xffd0,0x0001,0xffef,
-0xfff9,0x000f,0x0009,0xfff7,0x001c,0xffe3,0x002d,0xfffb,
-0x0006,0x002b,0x0009,0xfff4,0xfffe,0xffdc,0x000c,0x001e,
-0x000b,0xfffd,0xffef,0xfffd,0x0022,0x0016,0xfffd,0xffe8,
-0xfff4,0xffe8,0xfffe,0xffe0,0x001c,0x0016,0x001d,0x001d,
-0xfffb,0xffce,0x0015,0x001f,0x0026,0xffe3,0xfff9,0x0005,
-0xffb4,0x0023,0x001f,0x001c,0x0031,0xffd5,0x0028,0x0000,
-0xffe3,0x000e,0xfff8,0xfffb,0xfff6,0xffee,0x001a,0x002e,
-0x0000,0xfff9,0xfffa,0xfffd,0x0019,0x0007,0x0002,0xffd8,
-0xffe4,0xfff2,0xffee,0x0003,0x001b,0x001c,0x0008,0x002d,
-0x000d,0xffde,0x000d,0x001b,0x000f,0xffe1,0xfff4,0xfffd,
-0x004a,0xffef,0x0000,0xffe1,0xffee,0x0049,0xfffb,0x0000,
-0x0003,0xfffb,0x0019,0x000c,0xfffd,0xffff,0xffea,0x0003,
-0xfff7,0x0021,0xfff4,0xffe8,0x0006,0x0002,0xffdf,0x0009,
-0x0015,0x0005,0x0014,0xffe5,0xffed,0xfff9,0xffde,0xffdb,
-0xffde,0x0016,0x002c,0x0000,0xffd7,0xffe3,0xffef,0xffeb,
-0x0005,0x0003,0x0015,0x0007,0x0002,0x003c,0xfff6,0x0005,
-0xffe0,0xffde,0x0007,0x0014,0xfff5,0x0010,0xfff8,0x0014,
-0xffeb,0x001d,0xffff,0xffe8,0xfffe,0xfff3,0xffe5,0xfffa,
-0x0005,0x000f,0x0003,0x0008,0xffeb,0xffff,0xffc9,0xffeb,
-0xfff1,0x0026,0x0025,0xfffd,0xffbf,0xffe0,0xffe9,0xffe2,
-0x0023,0xfff6,0x000b,0xffd4,0xfffd,0x0030,0xfff6,0xfffa,
-0xffef,0xfffe,0x000b,0x0033,0x0008,0xfff8,0xffda,0xfffd,
-0xfffc,0x001f,0xfff4,0x0002,0x002e,0x0001,0xfff6,0xfffc,
-0xfffb,0x0007,0x001a,0xffed,0x000a,0x0005,0xffee,0xffde,
-0xffd3,0xfff1,0x0036,0x0018,0xffee,0xfff3,0xffe1,0xfff9,
-0xffdf,0x000a,0x0022,0xfffb,0x0011,0x0023,0xfff1,0xffff,
-0xffcb,0xffe2,0xfffa,0x003b,0x0000,0x000a,0xffe8,0x000d,
-0xffef,0x001b,0xffff,0x0001,0x0025,0xfff3,0xfffc,0xffec,
-0xffec,0x0012,0x000a,0x0010,0x0008,0x000b,0xffd9,0xffee,
-0xffe6,0x0000,0x002e,0x0014,0xffd7,0xfff1,0xffdb,0xfff1,
-0x001d,0xfffb,0x0007,0xffe2,0x0001,0x0015,0xfff9,0x0007,
-0x0000,0x0000,0x002f,0xfff7,0xffee,0xfff1,0xffea,0x000e,
-0xfffc,0x0000,0xffe4,0xffc7,0x0017,0x0015,0xffe7,0x0002,
-0xffff,0x0000,0x0007,0xffcb,0xffed,0xfffd,0xffef,0xfff1,
-0xffdc,0x0000,0x0013,0xffe8,0xffeb,0xffd5,0x0009,0x0000,
-0xffd9,0x000e,0x001e,0x0008,0x0016,0x0008,0xfff4,0x000c,
-0xffde,0xffe5,0x001d,0xfffe,0xffe6,0x0002,0xfff8,0x001f,
-0xfff0,0xfffd,0xffef,0xffc7,0x000e,0x0006,0xffed,0xfff3,
-0xfff0,0x000a,0xfff8,0xffef,0xffec,0x0002,0xffda,0x0000,
-0xffef,0x0010,0x000b,0xffe5,0xffd4,0xffd3,0x0004,0xfff8,
-0xfff7,0x0001,0x0014,0xffd5,0x0011,0xfffd,0xfff4,0x0000,
-0xffec,0x0004,0x0021,0x001d,0xfffa,0xffea,0xffda,0x0007,
-0x0000,0xffff,0xffe3,0xffe2,0x003f,0x0015,0xfffd,0xfff5,
-0xffe5,0x0001,0x000e,0xffd3,0x000a,0x0009,0xffff,0xfff4,
-0xffd1,0xffdb,0x001c,0x0000,0x0002,0xffe6,0xfffc,0x000d,
-0xffb2,0x0015,0x002b,0xfffc,0x0026,0xffef,0xffef,0x0005,
-0xffc9,0xffe8,0x000f,0x0024,0xfff2,0xfffc,0xffe8,0x0018,
-0xfff4,0xfffb,0xffef,0xffe1,0x0036,0x0005,0x0002,0xffe5,
-0xffd5,0x000c,0xfffe,0xfff7,0x0009,0x000f,0xffea,0x0003,
-0xffe4,0xffeb,0x0014,0xfffd,0xffec,0xffe4,0xfff7,0x0005,
-0x0050,0xfffa,0x0010,0xfff5,0xffe2,0x001e,0x0009,0x001c,
-0x001c,0x001d,0x000d,0xfffa,0x0002,0xffe4,0x0003,0x0005,
-0x0007,0x003c,0xfffb,0xfff7,0xfff5,0x0001,0xffe8,0xffed,
-0x001b,0xfff3,0x0020,0xfff3,0xfff1,0xffed,0xffed,0xffdd,
-0xffef,0x0027,0x002b,0x0009,0xfffc,0xffd6,0xffe0,0xffd7,
-0x000b,0x000e,0x0027,0x001b,0xfff7,0x0011,0x0004,0x0021,
-0xfffa,0x0000,0xfffc,0x0001,0xfffb,0xfff6,0x0011,0x0016,
-0xfffb,0x0039,0x0005,0xfff7,0xffec,0xfff3,0xffee,0xffdd,
-0x000b,0xfffd,0x0010,0x0016,0xffef,0xfff3,0xffd8,0xffed,
-0x0001,0x0037,0x0023,0x0005,0xffe5,0xffd4,0xffdb,0xffcf,
-0x0028,0x0000,0x001c,0xffe8,0xfff2,0x0005,0x0004,0x0015,
-0x0007,0x0021,0x0000,0x0020,0x000f,0xffdd,0xfff4,0xffff,
-0x000b,0x003a,0xfffb,0x0010,0x001c,0x0000,0xffff,0xffdf,
-0x0000,0xfff5,0x0027,0xfffb,0x000e,0xfffa,0xfffd,0xffe1,
-0xffe4,0x0001,0x0035,0x0021,0x0013,0xffe7,0xffd2,0xffe6,
-0xffe4,0x0014,0x0033,0x000e,0x0006,0xfff9,0x0000,0x001a,
-0xffe5,0x0004,0xffee,0x0028,0x0006,0xfff0,0x0001,0x000f,
-0x0000,0x0037,0x0005,0x0010,0x0013,0xfff2,0x0003,0xffcf,
-0xfff2,0xffff,0x0016,0x001e,0x000c,0x0000,0xffe8,0xfff1,
-0xfff7,0x0011,0x002d,0x001d,0xfffc,0xffe4,0xffcd,0xffdd,
-0x0022,0x0004,0x0019,0xfff6,0xfff7,0xffeb,0x0007,0x0024,
-0x001a,0x0024,0x0023,0xffe4,0xfff4,0xffd6,0x0003,0x0010,
-0x000c,0x001c,0xffeb,0xffd6,0x0005,0x0015,0xfff0,0xffe6,
-0x0004,0xffed,0x0013,0xffd9,0xfff1,0xfff1,0xffff,0xfff3,
-0xffed,0x0011,0x0011,0xfff2,0x000f,0xffc9,0xfffc,0xffed,
-0xffde,0x0019,0x0030,0x001c,0x000b,0xffde,0x0002,0x0029,
-0xfff7,0x0007,0x0011,0xffeb,0xffec,0xffe8,0x0011,0x0021,
-0x0000,0x0018,0xfff6,0xffd6,0xfffd,0x0005,0xfff6,0xffd6,
-0xfff5,0xfff8,0x0003,0xfffd,0xfff0,0xfff7,0xffea,0x0002,
-0x0000,0x0021,0x000a,0xffee,0xfff9,0xffc6,0xfff6,0xffe4,
-0xfffc,0x000b,0x0025,0xffe9,0x0005,0xffd2,0x0002,0x001d,
-0x0005,0x0027,0x0015,0x0009,0x0000,0xffcf,0xfff4,0x0009,
-0x0010,0x001a,0xffea,0xfff1,0x002d,0x0014,0x0005,0xffd8,
-0xffea,0xffef,0x001a,0xffe1,0x000e,0xfffe,0x000e,0xfff6,
-0xffe2,0xffec,0x001b,0x0009,0x0027,0xffd9,0xffee,0xfffb,
-0xffb7,0x0020,0x003c,0x000f,0x001a,0xffc5,0xfffe,0x0021,
-0xffe2,0x000a,0x0003,0x0011,0xfff8,0xffe2,0x0001,0x001a,
-0x0004,0x0016,0xfff6,0xfff0,0x0024,0x0005,0x000b,0xffc8,
-0xffdb,0xfffa,0x000a,0x0005,0x000d,0x0003,0xfffa,0x0005,
-0xfff5,0xfffc,0x0013,0x0005,0x0010,0xffd7,0xffe8,0xfff3};
-
-static const unsigned long ftable1[128]={
-0x4cc9f,0x482af,0x47bd8,0x44700,0x5238b,0x47377,0x4898a,0x411fd,
-0x4f8b7,0x4a7d5,0x4bd1b,0x47feb,0x5554b,0x49414,0x4c9d4,0x4403c,
-0x4fa57,0x550c5,0x4ea1c,0x54c6e,0x51f27,0x4ff8f,0x4cab5,0x4bbb6,
-0x53e58,0x5a5e8,0x5551f,0x5d6ff,0x56499,0x540f7,0x528e8,0x51740,
-0x4cdba,0x459db,0x4a644,0x4445b,0x4e123,0x423bc,0x480ed,0x3ed60,
-0x5292b,0x49d33,0x51d8c,0x49f1d,0x53cc4,0x45a9d,0x4e88c,0x43073,
-0x4d3a1,0x4e583,0x4f702,0x5182e,0x4b81f,0x47291,0x49dc4,0x46541,
-0x5434b,0x55bc1,0x5a27e,0x5d510,0x51ba0,0x4c587,0x51f83,0x4d45f,
-0x4d45f,0x51f83,0x4c587,0x51ba0,0x5d510,0x5a27e,0x55bc1,0x5434b,
-0x46541,0x49dc4,0x47291,0x4b81f,0x5182e,0x4f702,0x4e583,0x4d3a1,
-0x43073,0x4e88c,0x45a9d,0x53cc4,0x49f1d,0x51d8c,0x49d33,0x5292b,
-0x3ed60,0x480ed,0x423bc,0x4e123,0x4445b,0x4a644,0x459db,0x4cdba,
-0x51740,0x528e8,0x540f7,0x56499,0x5d6ff,0x5551f,0x5a5e8,0x53e58,
-0x4bbb6,0x4cab5,0x4ff8f,0x51f27,0x54c6e,0x4ea1c,0x550c5,0x4fa57,
-0x4403c,0x4c9d4,0x49414,0x5554b,0x47feb,0x4bd1b,0x4a7d5,0x4f8b7,
-0x411fd,0x4898a,0x47377,0x5238b,0x44700,0x47bd8,0x482af,0x4cc9f};
-
-static const unsigned long ftable2[128]={
-0x2f8e9,0x3444d,0x3637b,0x3608d,0x3372e,0x33ab9,0x33946,0x2f157,
-0x307a1,0x36a4d,0x380c9,0x39279,0x332c0,0x34673,0x33a8a,0x2fec4,
-0x2ecea,0x36011,0x34bb0,0x37829,0x36353,0x39c4a,0x35f32,0x33352,
-0x2cb99,0x33db5,0x3221f,0x3595c,0x31b84,0x35804,0x31d79,0x3075f,
-0x27f6f,0x2f99d,0x2d6c9,0x3369b,0x2df25,0x34928,0x3018c,0x32129,
-0x28cb2,0x31e5c,0x2eebd,0x36c4e,0x2e2a3,0x3601f,0x30a58,0x33aa8,
-0x28cee,0x336a2,0x2e69d,0x37dcd,0x323b6,0x3fa08,0x34b2d,0x3acd3,
-0x27abc,0x3214b,0x2cff6,0x3695f,0x2f09d,0x3ae92,0x315ba,0x37761,
-0x37761,0x315ba,0x3ae92,0x2f09d,0x3695f,0x2cff6,0x3214b,0x27abc,
-0x3acd3,0x34b2d,0x3fa08,0x323b6,0x37dcd,0x2e69d,0x336a2,0x28cee,
-0x33aa8,0x30a58,0x3601f,0x2e2a3,0x36c4e,0x2eebd,0x31e5c,0x28cb2,
-0x32129,0x3018c,0x34928,0x2df25,0x3369b,0x2d6c9,0x2f99d,0x27f6f,
-0x3075f,0x31d79,0x35804,0x31b84,0x3595c,0x3221f,0x33db5,0x2cb99,
-0x33352,0x35f32,0x39c4a,0x36353,0x37829,0x34bb0,0x36011,0x2ecea,
-0x2fec4,0x33a8a,0x34673,0x332c0,0x39279,0x380c9,0x36a4d,0x307a1,
-0x2f157,0x33946,0x33ab9,0x3372e,0x3608d,0x3637b,0x3444d,0x2f8e9};
-
-static const short decodetable1[63]={
-0x0000,0x0006,0x0010,0x0012,0x0014,0x0017,0x0019,0x001d,
-0x0020,0x0024,0x0029,0x002e,0x0033,0x0039,0x0041,0x0049,
-0x0051,0x005b,0x0067,0x0073,0x0081,0x0091,0x00a3,0x00b7,
-0x00cd,0x00e6,0x0103,0x0122,0x0146,0x016d,0x019a,0x01cc,
-0x0204,0x0243,0x028a,0x02da,0x0333,0x0397,0x0407,0x0485,
-0x0512,0x05b0,0x0662,0x0729,0x0809,0x0904,0x0a1e,0x0b5a,
-0x0cbd,0x0e4b,0x1009,0x11fe,0x1430,0x16a7,0x196b,0x1c85,
-0x2000,0x23e7,0x2849,0x2d33,0x32b7,0x38e7,0x3fd9};
-
-static const short decodetable2[127]={
-0xf037,0xf043,0xf04e,0xf058,0xf062,0xf06c,0xf077,0xf082,
-0xf08e,0xf09a,0xf0a6,0xf0b2,0xf0be,0xf0cc,0xf0d9,0xf0e6,
-0xf0f4,0xf101,0xf10f,0xf11e,0xf12d,0xf13d,0xf14c,0xf15c,
-0xf16d,0xf17d,0xf18d,0xf19d,0xf1ae,0xf1bf,0xf1d1,0xf1e3,
-0xf1f6,0xf20a,0xf21d,0xf232,0xf247,0xf25d,0xf274,0xf28c,
-0xf2a4,0xf2bc,0xf2d4,0xf2ee,0xf307,0xf321,0xf33c,0xf358,
-0xf374,0xf391,0xf3af,0xf3ce,0xf3ee,0xf410,0xf433,0xf459,
-0xf480,0xf4a9,0xf4d1,0xf4ff,0xf52c,0xf55c,0xf58c,0xf5c4,
-0xf5fb,0xf637,0xf673,0xf6ad,0xf6e8,0xf727,0xf766,0xf7a7,
-0xf7e8,0xf82a,0xf86b,0xf8ae,0xf8f0,0xf93a,0xf984,0xf9d0,
-0xfa1c,0xfa6c,0xfabc,0xfb0d,0xfb5f,0xfbbe,0xfc1e,0xfc80,
-0xfce2,0xfd45,0xfda8,0xfe19,0xfe8a,0xff0e,0xff92,0x0015,
-0x0098,0x012c,0x01bf,0x0248,0x02d0,0x0353,0x03d6,0x0451,
-0x04cd,0x053e,0x05b0,0x0621,0x0692,0x0707,0x077c,0x07e7,
-0x0852,0x08c2,0x0931,0x09aa,0x0a23,0x0aa4,0x0b25,0x0baa,
-0x0c2e,0x0ca8,0x0d23,0x0d93,0x0e04,0x0e75,0x0ee6};
-
-static const short decodetable3[63]={
-0xf3ed,0xf54d,0xf6ae,0xf7af,0xf8b1,0xf990,0xfa6f,0xfb39,
-0xfc03,0xfcbd,0xfd77,0xfe1d,0xfec4,0xff58,0xffec,0x007b,
-0x010b,0x0196,0x0220,0x02a5,0x032a,0x03a9,0x0429,0x04a1,
-0x0519,0x058c,0x05fe,0x066d,0x06dc,0x0747,0x07b2,0x0817,
-0x087b,0x08d9,0x0937,0x0990,0x09e8,0x0a3a,0x0a8c,0x0ad9,
-0x0b26,0x0b6d,0x0bb4,0x0bf8,0x0c3d,0x0c7e,0x0cbf,0x0cfc,
-0x0d3a,0x0d72,0x0dab,0x0ddf,0x0e13,0x0e44,0x0e75,0x0ea1,
-0x0ecd,0x0ef5,0x0f1e,0x0f44,0x0f6b,0x0f8f,0x0fb4};
-
-static const short decodetable4[63]={
-0xf23b,0xf2ae,0xf321,0xf38c,0xf3f7,0xf457,0xf4b6,0xf517,
-0xf578,0xf5d5,0xf631,0xf68d,0xf6e8,0xf742,0xf79b,0xf7f0,
-0xf845,0xf896,0xf8e7,0xf937,0xf986,0xf9d6,0xfa26,0xfa74,
-0xfac3,0xfb0f,0xfb5c,0xfbaa,0xfbf8,0xfc46,0xfc94,0xfce2,
-0xfd2f,0xfd7f,0xfdcf,0xfe22,0xfe76,0xfec9,0xff1c,0xff73,
-0xffca,0x0020,0x0077,0x00d0,0x0128,0x0186,0x01e4,0x0248,
-0x02ab,0x0315,0x037f,0x03f1,0x0463,0x04e0,0x055d,0x05e8,
-0x0673,0x0710,0x07ad,0x0872,0x0938,0x0a2f,0x0b26};
-
-static const short decodetable5[31]={
-0xf8cb,0xfa55,0xfbdf,0xfcea,0xfdf6,0xfed4,0xffb3,0x006f,
-0x012d,0x01da,0x0287,0x032b,0x03cf,0x046a,0x0505,0x059a,
-0x062e,0x06bf,0x0751,0x07e2,0x0873,0x0904,0x0994,0x0a22,
-0x0aaf,0x0b3c,0x0bc9,0x0c56,0x0ce3,0x0d6a,0x0df1};
-
-static const short decodetable6[31]={
-0xf57d,0xf679,0xf775,0xf83d,0xf904,0xf9b5,0xfa65,0xfb04,
-0xfba2,0xfc2f,0xfcbb,0xfd40,0xfdc5,0xfe44,0xfec4,0xff44,
-0xffc5,0x0047,0x00c9,0x0150,0x01d6,0x0266,0x02f7,0x0396,
-0x0435,0x04f3,0x05b1,0x0692,0x0774,0x0899,0x09bf};
-
-static const short decodetable7[15]={
-0xfaa4,0xfc65,0xfe26,0xff56,0x0085,0x017f,0x0278,0x0362,
-0x044c,0x0537,0x0623,0x071f,0x081b,0x0946,0x0a70};
-
-static const short decodetable8[15]={
-0xf6ab,0xf7d8,0xf905,0xfa1b,0xfb31,0xfc32,0xfd33,0xfe22,
-0xff11,0xfffe,0x00ea,0x01f6,0x0302,0x0462,0x05c2};
-
-static const short decodetable9[15]={
-0xf9df,0xfb3f,0xfca0,0xfdbc,0xfed8,0xffd1,0x00c8,0x01b3,
-0x029e,0x038f,0x047f,0x0596,0x06ad,0x07ff,0x0951};
-
-static const short decodetable10[15]={
-0xf768,0xf890,0xf9b8,0xfac9,0xfbda,0xfcd0,0xfdc7,0xfea8,
-0xff88,0x006c,0x0152,0x0258,0x035f,0x04da,0x0655};
-
-static const short decodetable11[7]={
-0xfd97,0xff2b,0x00be,0x01f0,0x0322,0x0476,0x05cb};
-
-static const short *decodetable[11]={
-decodetable1,decodetable2,decodetable3,decodetable4,decodetable5,
-decodetable6,decodetable7,decodetable8,decodetable9,decodetable10,
-decodetable11};
-
-#endif /* RA144TABLES_H */
+++ /dev/null
-/*
- * RealAudio 2.0 (28.8K)
- * Copyright (c) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "avcodec.h"
-#include "ra288.h"
-
-typedef struct {
- float history[8];
- float output[40];
- float pr1[36];
- float pr2[10];
- int phase, phasep;
-
- float st1a[111],st1b[37],st1[37];
- float st2a[38],st2b[11],st2[11];
- float sb[41];
- float lhist[10];
-} Real288_internal;
-
-static int ra288_decode_init(AVCodecContext * avctx)
-{
- Real288_internal *glob=avctx->priv_data;
- memset(glob,0,sizeof(Real288_internal));
- return 0;
-}
-
-static void prodsum(float *tgt, float *src, int len, int n);
-static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table);
-static int pred(float *in, float *tgt, int n);
-static void colmult(float *tgt, float *m1, const float *m2, int n);
-
-
-/* initial decode */
-static void unpack(unsigned short *tgt, unsigned char *src, int len)
-{
- int x,y,z;
- int n,temp;
- int buffer[len];
-
- for (x=0;x<len;tgt[x++]=0)
- buffer[x]=9+(x&1);
-
- for (x=y=z=0;x<len/*was 38*/;x++) {
- n=buffer[y]-z;
- temp=src[x];
- if (n<8) temp&=255>>(8-n);
- tgt[y]+=temp<<z;
- if (n<=8) {
- tgt[++y]+=src[x]>>n;
- z=8-n;
- } else z+=8;
- }
-}
-
-static void update(Real288_internal *glob)
-{
- int x,y;
- float buffer1[40],temp1[37];
- float buffer2[8],temp2[11];
-
- for (x=0,y=glob->phasep+5;x<40;buffer1[x++]=glob->output[(y++)%40]);
- co(36,40,35,buffer1,temp1,glob->st1a,glob->st1b,table1);
- if (pred(temp1,glob->st1,36))
- colmult(glob->pr1,glob->st1,table1a,36);
-
- for (x=0,y=glob->phase+1;x<8;buffer2[x++]=glob->history[(y++)%8]);
- co(10,8,20,buffer2,temp2,glob->st2a,glob->st2b,table2);
- if (pred(temp2,glob->st2,10))
- colmult(glob->pr2,glob->st2,table2a,10);
-}
-
-/* Decode and produce output */
-static void decode(Real288_internal *glob, unsigned int input)
-{
- unsigned int x,y;
- float f;
- double sum,sumsum;
- float *p1,*p2;
- float buffer[5];
- const float *table;
-
- for (x=36;x--;glob->sb[x+5]=glob->sb[x]);
- for (x=5;x--;) {
- p1=glob->sb+x;p2=glob->pr1;
- for (sum=0,y=36;y--;sum-=(*(++p1))*(*(p2++)));
- glob->sb[x]=sum;
- }
-
- f=amptable[input&7];
- table=codetable+(input>>3)*5;
-
- /* convert log and do rms */
- for (sum=32,x=10;x--;sum-=glob->pr2[x]*glob->lhist[x]);
- if (sum<0) sum=0; else if (sum>60) sum=60;
-
- sumsum=exp(sum*0.1151292546497)*f; /* pow(10.0,sum/20)*f */
- for (sum=0,x=5;x--;) { buffer[x]=table[x]*sumsum; sum+=buffer[x]*buffer[x]; }
- if ((sum/=5)<1) sum=1;
-
- /* shift and store */
- for (x=10;--x;glob->lhist[x]=glob->lhist[x-1]);
- *glob->lhist=glob->history[glob->phase]=10*log10(sum)-32;
-
- for (x=1;x<5;x++) for (y=x;y--;buffer[x]-=glob->pr1[x-y-1]*buffer[y]);
-
- /* output */
- for (x=0;x<5;x++) {
- f=glob->sb[4-x]+buffer[x];
- if (f>4095) f=4095; else if (f<-4095) f=-4095;
- glob->output[glob->phasep+x]=glob->sb[4-x]=f;
- }
-}
-
-/* column multiply */
-static void colmult(float *tgt, float *m1, const float *m2, int n)
-{
- while (n--)
- *(tgt++)=(*(m1++))*(*(m2++));
-}
-
-static int pred(float *in, float *tgt, int n)
-{
- int x,y;
- float *p1,*p2;
- double f0,f1,f2;
- float temp;
-
- if (in[n]==0) return 0;
- if ((f0=*in)<=0) return 0;
-
- for (x=1;;x++) {
- if (n<x) return 1;
-
- p1=in+x;
- p2=tgt;
- f1=*(p1--);
- for (y=x;--y;f1+=(*(p1--))*(*(p2++)));
-
- p1=tgt+x-1;
- p2=tgt;
- *(p1--)=f2=-f1/f0;
- for (y=x>>1;y--;) {
- temp=*p2+*p1*f2;
- *(p1--)+=*p2*f2;
- *(p2++)=temp;
- }
- if ((f0+=f1*f2)<0) return 0;
- }
-}
-
-static void co(int n, int i, int j, float *in, float *out, float *st1, float *st2, const float *table)
-{
- int a,b,c;
- unsigned int x;
- float *fp;
- float buffer1[37];
- float buffer2[37];
- float work[111];
-
- /* rotate and multiply */
- c=(b=(a=n+i)+j)-i;
- fp=st1+i;
- for (x=0;x<b;x++) {
- if (x==c) fp=in;
- work[x]=*(table++)*(*(st1++)=*(fp++));
- }
-
- prodsum(buffer1,work+n,i,n);
- prodsum(buffer2,work+a,j,n);
-
- for (x=0;x<=n;x++) {
- *st2=*st2*(0.5625)+buffer1[x];
- out[x]=*(st2++)+buffer2[x];
- }
- *out*=1.00390625; /* to prevent clipping */
-}
-
-/* product sum (lsf) */
-static void prodsum(float *tgt, float *src, int len, int n)
-{
- unsigned int x;
- float *p1,*p2;
- double sum;
-
- while (n>=0)
- {
- p1=(p2=src)-n;
- for (sum=0,x=len;x--;sum+=(*p1++)*(*p2++));
- tgt[n--]=sum;
- }
-}
-
-void * decode_block(AVCodecContext * avctx, unsigned char *in, signed short int *out,unsigned len)
-{
- int x,y;
- Real288_internal *glob=avctx->priv_data;
- unsigned short int buffer[len];
-
- unpack(buffer,in,len);
- for (x=0;x<32;x++)
- {
- glob->phasep=(glob->phase=x&7)*5;
- decode(glob,buffer[x]);
- for (y=0;y<5;*(out++)=8*glob->output[glob->phasep+(y++)]);
- if (glob->phase==3) update(glob);
- }
- return out;
-}
-
-/* Decode a block (celp) */
-static int ra288_decode_frame(AVCodecContext * avctx,
- void *data, int *data_size,
- uint8_t * buf, int buf_size)
-{
- if(avctx->extradata_size>=6)
- {
-//((short*)(avctx->extradata))[0]; /* subpacket size */
-//((short*)(avctx->extradata))[1]; /* subpacket height */
-//((short*)(avctx->extradata))[2]; /* subpacket flavour */
-//((short*)(avctx->extradata))[3]; /* coded frame size */
-//((short*)(avctx->extradata))[4]; /* codec's data length */
-//((short*)(avctx->extradata))[5...] /* codec's data */
- int bret;
- void *datao;
- int w=avctx->block_align; /* 228 */
- int h=((short*)(avctx->extradata))[1]; /* 12 */
- int cfs=((short*)(avctx->extradata))[3]; /* coded frame size 38 */
- int i,j;
- if(buf_size<w*h)
- {
- fprintf(stderr,"ffra288: Error! Input buffer is too small [%d<%d]\n",buf_size,w*h);
- return 0;
- }
- datao = data;
- bret = 0;
- for (j = 0; j < h/2; j++)
- for (i = 0; i < h; i++)
- {
- data=decode_block(avctx,&buf[j*cfs+cfs*i*h/2],(signed short *)data,cfs);
- bret += cfs;
- }
- *data_size = data - datao;
- return bret;
- }
- else
- {
- fprintf(stderr,"ffra288: Error: need extra data!!!\n");
- return 0;
- }
-}
-
-AVCodec ra_288_decoder =
-{
- "real_288",
- CODEC_TYPE_AUDIO,
- CODEC_ID_RA_288,
- sizeof(Real288_internal),
- ra288_decode_init,
- NULL,
- NULL,
- ra288_decode_frame,
-};
+++ /dev/null
-/*
- * RealAudio 2.0 (28.8K)
- * Copyright (c) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#ifndef RA288TABLES_H
-#define RA288TABLES_H
-
-static const float amptable[8]={ 0.515625, 0.90234375, 1.57910156, 2.76342773,
- -0.515625,-0.90234375,-1.57910156,-2.76342773 };
-
-static const float codetable[640]={
- 0.326171875, -1.4404296875, -0.6123046875, -0.8740234375, -1.24658203125,
- -2.45703125, -2.23486328125, -0.51025390625, 1.419921875, 1.6201171875,
- -1.37646484375, -1.30712890625, -0.462890625, -1.37939453125, -2.1728515625,
- -3.26123046875, -0.166015625, 0.7236328125, -0.623046875, 0.6162109375,
- -0.2744140625, -3.29931640625, 0.62548828125, 0.08740234375, -0.6220703125,
- -1.2265625, -3.4814453125, -2.40478515625, 3.37548828125, 1.17724609375,
- -1.2099609375, -0.076171875, 2.28662109375, -1.89111328125, 0,
- -4.0078125, 1.044921875, -0.2333984375, -1.35986328125, 0.26025390625,
- 0.92236328125, 1.34716796875, 0.67431640625, -3.39599609375, -2.88720703125,
- 2.4814453125, -1.201171875, -2.8212890625, 0.87744140625, 0.27734375,
- -1.078125, -1.61572265625, -2.20849609375, -3.044921875, -3.66455078125,
- -1.32763671875, 2.1279296875, -1.458984375, -0.56103515625, 1.30078125,
- 0.61474609375, 0.48583984375, 1.32373046875, -1.203125, -5.0732421875,
- 0.8408203125, -3.69580078125, -1.3388671875, 1.06005859375, -1.13720703125,
- 0.50390625, 0.36474609375, -0.4189453125, -3.8798828125, -6.27099609375,
- 1.5166015625, 2.37109375, -2.04736328125, -1.24072265625, 0.50537109375,
- 0.9091796875, -0.46875, -3.236328125, 0.2001953125, 2.8720703125,
- -1.21728515625, -1.283203125, -1.953125, -0.029296875, 3.5166015625,
- -1.3046875, 0.7060546875, 0.75, -1.87060546875, 0.60205078125,
- -2.5888671875, 3.375, 0.77587890625, -2.04443359375, 1.78955078125,
- -1.6875, -3.9892578125, -3.76416015625, 0.67578125, 2.2939453125,
- -2.29443359375, -3.03173828125, -5.45703125, 3.95703125, 8.2177734375,
- 0.4541015625, 3.419921875, 0.61962890625, -4.38330078125, 1.25341796875,
- 2.27001953125, 5.763671875, 1.68017578125, -2.76220703125, 0.58544921875,
- 1.2412109375, -0.08935546875, -4.32568359375, -3.89453125, 1.5771484375,
- -1.40234375, -0.98193359375, -4.74267578125, -4.09423828125, 6.33935546875,
- 1.5068359375, 1.044921875, -1.796875, -4.70849609375, -1.4140625,
- -3.71533203125, 3.18115234375, -1.11474609375, -1.2314453125, 3.091796875,
- -1.62744140625, -2.744140625, -4.4580078125, -5.43505859375, 2.70654296875,
- -0.19873046875, -3.28173828125, -8.5283203125, -1.41064453125, 5.6484375,
- 1.802734375, 3.318359375, -0.1279296875, -5.2958984375, -0.90625,
- 3.55224609375, 6.544921875, -1.45947265625, -5.17333984375, 2.41015625,
- 0.119140625, -1.08349609375, 1.296875, 1.84375, -2.642578125,
- -1.97412109375, -2.8974609375, 1.04052734375, 0.42138671875, -1.3994140625,
- -1.6123046875, 0.85107421875, -0.9794921875, -0.0625, -1.001953125,
- -3.10595703125, 1.6318359375, -0.77294921875, -0.01025390625, 0.5576171875,
- -1.87353515625, -0.89404296875, 3.12353515625, 1.24267578125, -1.390625,
- -4.556640625, -3.1875, 2.59228515625, 0.9697265625, -1.09619140625,
- -2.1923828125, 0.365234375, 0.94482421875, -1.47802734375, -0.24072265625,
- -4.51904296875, 2.6201171875, 1.55908203125, -2.19384765625, 0.87109375,
- 2.3359375, -0.1806640625, 0.9111328125, 0.51611328125, -0.92236328125,
- 3.5849609375, -1.3134765625, -1.25830078125, 0.330078125, -0.29833984375,
- -0.2451171875, 1.09130859375, -0.9033203125, -0.86767578125, -1.00048828125,
- 0.49365234375, 1.89453125, -1.20361328125, 1.07861328125, -0.07421875,
- 1.265625, 1.38134765625, 2.728515625, 1.38623046875, -3.5673828125,
- -1.48876953125, -2.4013671875, 2.90771484375, 4.49267578125, -2.17138671875,
- 0.34033203125, 1.908203125, 2.8310546875, -2.17333984375, -2.267578125,
- -1.03564453125, 2.658203125, -1.2548828125, 0.15673828125, -0.5869140625,
- 1.3896484375, -1.0185546875, 1.724609375, 0.2763671875, -0.345703125,
- -2.08935546875, 0.4638671875, 2.431640625, 1.83056640625, 0.220703125,
- -1.212890625, 1.7099609375, 0.83935546875, -0.0830078125, 0.1162109375,
- -1.67724609375, 0.12841796875, 1.0322265625, -0.97900390625, 1.15283203125,
- -3.5830078125, -0.58984375, 4.56396484375, -0.59375, -1.95947265625,
- -6.5908203125, -0.21435546875, 3.919921875, -2.06640625, 0.17626953125,
- -1.82080078125, 2.65283203125, 0.978515625, -2.30810546875, -0.61474609375,
- -1.9462890625, 3.78076171875, 4.11572265625, -1.80224609375, -0.48193359375,
- 2.5380859375, -0.20654296875, 0.5615234375, -0.62548828125, 0.3984375,
- 3.61767578125, 2.00634765625, -1.92822265625, 1.3134765625, 0.0146484384313,
- 0.6083984375, 1.49169921875, -0.01708984375, -0.6689453125, -0.1201171875,
- -0.72705078125, 2.75146484375, -0.3310546875, -1.28271484375, 1.5478515625,
- 2.3583984375, -2.23876953125, 0.98046875, -0.5185546875, 0.39013671875,
- -0.06298828125, 0.35009765625, 2.2431640625, 7.29345703125, 5.2275390625,
- 0.20361328125, 1.34716796875, 0.9033203125, -2.46923828125, -0.56298828125,
- -1.89794921875, 3.59423828125, -2.81640625, 2.09228515625, 0.3251953125,
- 0.70458984375, -0.4580078125, 0.009765625, -1.03466796875, -0.82861328125,
- -1.8125, -1.6611328125, -1.080078125, 0.0537109375, 1.04296875,
- -1.44140625, 0.005859375, -0.765625, -1.708984375, -0.90576171875,
- -0.64208984375, -0.84521484375, 0.56640625, -0.2724609375, 0.83447265625,
- 0.04296875, -2.23095703125, 0.0947265625, -0.2216796875, -1.44384765625,
- -1.38623046875, -0.8134765625, -0.13330078125, 1.017578125, -0.07568359375,
- -0.09228515625, -1.16015625, 0.81201171875, -0.5078125, -1.19580078125,
- -1.3876953125, -0.66845703125, 0.310546875, -0.12109375, -1.30712890625,
- 0.74072265625, 0.03857421875, -1.47119140625, -1.79150390625, -0.47509765625,
- 0.93408203125, -1.21728515625, -2.59375, -0.36572265625, 0.62060546875,
- -1.41748046875, -1.623046875, -1.833984375, -1.8017578125, -0.89306640625,
- -1.42236328125, -0.75537109375, -1.34765625, -0.6865234375, 0.548828125,
- 0.900390625, -0.8955078125, 0.22265625, 0.3447265625, -2.0859375,
- 0.22802734375, -2.078125, -0.93212890625, 0.74267578125, 0.5537109375,
- -0.06201171875, -0.4853515625, -0.31103515625, -0.72802734375, -3.1708984375,
- 0.42626953125, -0.99853515625, -1.869140625, -1.36328125, -0.2822265625,
- 1.12841796875, -0.88720703125, 1.28515625, -1.490234375, 0.9609375,
- 0.31298828125, 0.5830078125, 0.92431640625, 2.00537109375, 3.0966796875,
- -0.02197265625, 0.5849609375, 1.0546875, -0.70751953125, 1.07568359375,
- -0.978515625, 0.83642578125, 1.7177734375, 1.294921875, 2.07568359375,
- 1.43359375, -1.9375, 0.625, 0.06396484375, -0.720703125,
- 1.38037109375, 0.00390625, -0.94140625, 1.2978515625, 1.71533203125,
- 1.56201171875, -0.3984375, 1.31201171875, -0.85009765625, -0.68701171875,
- 1.439453125, 1.96728515625, 0.1923828125, -0.12353515625, 0.6337890625,
- 2.0927734375, 0.02490234375, -2.20068359375, -0.015625, -0.32177734375,
- 1.90576171875, 2.7568359375, -2.728515625, -1.265625, 2.78662109375,
- -0.2958984375, 0.6025390625, -0.78466796875, -2.53271484375, 0.32421875,
- -0.25634765625, 1.767578125, -1.0703125, -1.23388671875, 0.83349609375,
- 2.09814453125, -1.58740234375, -1.11474609375, 0.396484375, -1.10546875,
- 2.81494140625, 0.2578125, -1.60498046875, 0.66015625, 0.81640625,
- 1.33544921875, 0.60595703125, -0.53857421875, -1.59814453125, -1.66357421875,
- 1.96923828125, 0.8046875, -1.44775390625, -0.5732421875, 0.705078125,
- 0.0361328125, 0.4482421875, 0.97607421875, 0.44677734375, -0.5009765625,
- -1.21875, -0.78369140625, 0.9931640625, 1.4404296875, 0.11181640625,
- -1.05859375, 0.99462890625, 0.00732421921566,-0.6171875, -0.1015625,
- -1.734375, 0.7470703125, 0.28369140625, 0.72802734375, 0.4697265625,
- -1.27587890625, -1.1416015625, 1.76806640625, -0.7265625, -1.06689453125,
- -0.85302734375, 0.03955078125, 2.7041015625, 0.69921875, -1.10205078125,
- -0.49755859375, 0.42333984375, 0.1044921875, -1.115234375, -0.7373046875,
- -0.822265625, 1.375, -0.11181640625, 1.24560546875, -0.67822265625,
- 1.32177734375, 0.24609375, 0.23388671875, 1.35888671875, -0.49267578125,
- 1.22900390625, -0.72607421875, -0.779296875, 0.30322265625, 0.94189453125,
- -0.072265625, 1.0771484375, -2.09375, 0.630859375, -0.68408203125,
- -0.25732421875, 0.60693359375, -1.33349609375, 0.93212890625, 0.625,
- 1.04931640625, -0.73291015625, 1.80078125, 0.2978515625, -2.24169921875,
- 1.6142578125, -1.64501953125, 0.91552734375, 1.775390625, -0.59423828125,
- 1.2568359375, 1.22705078125, 0.70751953125, -1.5009765625, -2.43115234375,
- 0.3974609375, 0.8916015625, -1.21923828125, 2.0673828125, -1.99072265625,
- 0.8125, -0.107421875, 1.6689453125, 0.4892578125, 0.54443359375,
- 0.38134765625, 0.8095703125, 1.91357421875, 2.9931640625, 1.533203125,
- 0.560546875, 1.98486328125, 0.740234375, 0.39794921875, 0.09716796875,
- 0.58154296875, 1.21533203125, 1.25048828125, 1.18212890625, 1.19287109375,
- 0.3759765625, -2.88818359375, 2.69287109375, -0.1796875, -1.56201171875,
- 0.5810546875, 0.51123046875, 1.8271484375, 3.38232421875, -1.02001953125,
- 0.142578125, 1.51318359375, 2.103515625, -0.3701171875, -1.19873046875,
- 0.25537109375, 1.91455078125, 1.974609375, 0.6767578125, 0.04150390625,
- 2.13232421875, 0.4912109375, -0.611328125, -0.7158203125, -0.67529296875,
- 1.880859375, 0.77099609375, -0.03759765625, 1.0078125, 0.423828125,
- 2.49462890625, 1.42529296875, -0.0986328125, 0.17529296875, -0.24853515625,
- 1.7822265625, 1.5654296875, 1.12451171875, 0.82666015625, 0.6328125,
- 1.41845703125, -1.90771484375, 0.11181640625, -0.583984375, -1.138671875,
- 2.91845703125, -1.75048828125, 0.39306640625, 1.86767578125, -1.5322265625,
- 1.8291015625, -0.2958984375, 0.02587890625, -0.13134765625, -1.61181640625,
- 0.2958984375, 0.9853515625, -0.642578125, 1.984375, 0.1943359375
-};
-
-static const float table1[111]={
- 0.576690972, 0.580838025, 0.585013986, 0.589219987, 0.59345597, 0.597723007,
- 0.602020264, 0.606384277, 0.610748291, 0.615142822, 0.619598389, 0.624084473,
- 0.628570557, 0.633117676, 0.637695313, 0.642272949, 0.646911621, 0.651580811,
- 0.656280518, 0.66104126, 0.665802002, 0.670593262, 0.675445557, 0.680328369,
- 0.685241699, 0.690185547, 0.695159912, 0.700164795, 0.705230713, 0.710327148,
- 0.715454102, 0.720611572, 0.725830078, 0.731048584, 0.736328125, 0.741638184,
- 0.747009277, 0.752380371, 0.7578125, 0.763305664, 0.768798828, 0.774353027,
- 0.779937744, 0.785583496, 0.791229248, 0.796936035, 0.802703857, 0.808502197,
- 0.814331055, 0.820220947, 0.826141357, 0.832092285, 0.838104248, 0.844146729,
- 0.850250244, 0.856384277, 0.862548828, 0.868774414, 0.875061035, 0.881378174,
- 0.88772583, 0.894134521, 0.900604248, 0.907104492, 0.913635254, 0.920227051,
- 0.926879883, 0.933563232, 0.940307617, 0.94708252, 0.953918457, 0.96081543,
- 0.96774292, 0.974731445, 0.981781006, 0.988861084, 0.994842529, 0.998565674,
- 0.999969482, 0.99911499, 0.996002197, 0.990600586, 0.982910156, 0.973022461,
- 0.960876465, 0.946533203, 0.930053711, 0.911437988, 0.89074707, 0.868041992,
- 0.843322754, 0.816680908, 0.788208008, 0.757904053, 0.725891113, 0.692199707,
- 0.656921387, 0.620178223, 0.582000732, 0.542480469, 0.501739502, 0.459838867,
- 0.416900635, 0.373016357, 0.328277588, 0.282775879, 0.236663818, 0.189971924,
- 0.142852783, 0.0954284668, 0.0477600098
-};
-
-static const float table2[38]={
- 0.505699992, 0.524200022, 0.54339999, 0.563300014, 0.583953857, 0.60534668,
- 0.627502441, 0.650482178, 0.674316406, 0.699005127, 0.724578857, 0.75112915,
- 0.778625488, 0.807128906, 0.836669922, 0.86730957, 0.899078369, 0.932006836,
- 0.961486816, 0.982757568, 0.995635986, 1, 0.995819092, 0.983154297,
- 0.96206665, 0.932769775, 0.895507813, 0.850585938, 0.798400879, 0.739379883,
- 0.674072266, 0.602996826, 0.526763916, 0.446014404, 0.361480713, 0.273834229,
- 0.183868408, 0.0923461914
-};
-
-static const float table1a[36]={
- 0.98828125, 0.976699829, 0.965254128, 0.953942537, 0.942763507, 0.931715488,
- 0.920796931, 0.910006344, 0.899342179, 0.888803005, 0.878387332, 0.868093729,
- 0.857920766, 0.847867012, 0.837931097, 0.828111589, 0.818407178, 0.808816493,
- 0.799338162, 0.789970934, 0.780713439, 0.771564424, 0.762522638, 0.753586829,
- 0.744755745, 0.736028135, 0.727402806, 0.718878567, 0.710454226, 0.702128589,
- 0.693900526, 0.685768902, 0.677732527, 0.669790328, 0.66194123, 0.654184103
-};
-
-static const float table2a[10]={
- 0.90625, 0.821289063, 0.74432373, 0.674499512, 0.61126709,
- 0.553955078, 0.50201416, 0.454956055, 0.41229248, 0.373657227
-};
-
-#endif /* RA288TABLES_H */
+++ /dev/null
-/*
- * Rate control for video encoders
- *
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file ratecontrol.c
- * Rate control for video encoders.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#undef NDEBUG // allways check asserts, the speed effect is far too small to disable them
-#include <assert.h>
-
-#ifndef M_E
-#define M_E 2.718281828
-#endif
-
-static int init_pass2(MpegEncContext *s);
-static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num);
-
-void ff_write_pass1_stats(MpegEncContext *s){
- sprintf(s->avctx->stats_out, "in:%d out:%d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d;\n",
- s->picture_number, s->input_picture_number - s->max_b_frames, s->pict_type,
- s->frame_qscale, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits,
- s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count);
-}
-
-int ff_rate_control_init(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- int i;
- emms_c();
-
- for(i=0; i<5; i++){
- rcc->pred[i].coeff= 7.0;
- rcc->pred[i].count= 1.0;
-
- rcc->pred[i].decay= 0.4;
- rcc->i_cplx_sum [i]=
- rcc->p_cplx_sum [i]=
- rcc->mv_bits_sum[i]=
- rcc->qscale_sum [i]=
- rcc->frame_count[i]= 1; // 1 is better cuz of 1/0 and such
- rcc->last_qscale_for[i]=5;
- }
- rcc->buffer_index= s->avctx->rc_buffer_size/2;
-
- if(s->flags&CODEC_FLAG_PASS2){
- int i;
- char *p;
-
- /* find number of pics */
- p= s->avctx->stats_in;
- for(i=-1; p; i++){
- p= strchr(p+1, ';');
- }
- i+= s->max_b_frames;
- rcc->entry = (RateControlEntry*)av_mallocz(i*sizeof(RateControlEntry));
- rcc->num_entries= i;
-
- /* init all to skiped p frames (with b frames we might have a not encoded frame at the end FIXME) */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- rce->pict_type= rce->new_pict_type=P_TYPE;
- rce->qscale= rce->new_qscale=2;
- rce->misc_bits= s->mb_num + 10;
- rce->mb_var_sum= s->mb_num*100;
- }
-
- /* read stats */
- p= s->avctx->stats_in;
- for(i=0; i<rcc->num_entries - s->max_b_frames; i++){
- RateControlEntry *rce;
- int picture_number;
- int e;
- char *next;
-
- next= strchr(p, ';');
- if(next){
- (*next)=0; //sscanf in unbelieavle slow on looong strings //FIXME copy / dont write
- next++;
- }
- e= sscanf(p, " in:%d ", &picture_number);
-
- assert(picture_number >= 0);
- assert(picture_number < rcc->num_entries);
- rce= &rcc->entry[picture_number];
-
- e+=sscanf(p, " in:%*d out:%*d type:%d q:%f itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d",
- &rce->pict_type, &rce->qscale, &rce->i_tex_bits, &rce->p_tex_bits, &rce->mv_bits, &rce->misc_bits,
- &rce->f_code, &rce->b_code, &rce->mc_mb_var_sum, &rce->mb_var_sum, &rce->i_count);
- if(e!=12){
- fprintf(stderr, "statistics are damaged at line %d, parser out=%d\n", i, e);
- return -1;
- }
- p= next;
- }
-
- if(init_pass2(s) < 0) return -1;
- }
-
- if(!(s->flags&CODEC_FLAG_PASS2)){
-
- rcc->short_term_qsum=0.001;
- rcc->short_term_qcount=0.001;
-
- rcc->pass1_rc_eq_output_sum= 0.001;
- rcc->pass1_wanted_bits=0.001;
-
- /* init stuff with the user specified complexity */
- if(s->avctx->rc_initial_cplx){
- for(i=0; i<60*30; i++){
- double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num;
- RateControlEntry rce;
- double q;
-
- if (i%((s->gop_size+3)/4)==0) rce.pict_type= I_TYPE;
- else if(i%(s->max_b_frames+1)) rce.pict_type= B_TYPE;
- else rce.pict_type= P_TYPE;
-
- rce.new_pict_type= rce.pict_type;
- rce.mc_mb_var_sum= bits*s->mb_num/100000;
- rce.mb_var_sum = s->mb_num;
- rce.qscale = 2;
- rce.f_code = 2;
- rce.b_code = 1;
- rce.misc_bits= 1;
-
- if(s->pict_type== I_TYPE){
- rce.i_count = s->mb_num;
- rce.i_tex_bits= bits;
- rce.p_tex_bits= 0;
- rce.mv_bits= 0;
- }else{
- rce.i_count = 0; //FIXME we do know this approx
- rce.i_tex_bits= 0;
- rce.p_tex_bits= bits*0.9;
- rce.mv_bits= bits*0.1;
- }
- rcc->i_cplx_sum [rce.pict_type] += rce.i_tex_bits*rce.qscale;
- rcc->p_cplx_sum [rce.pict_type] += rce.p_tex_bits*rce.qscale;
- rcc->mv_bits_sum[rce.pict_type] += rce.mv_bits;
- rcc->frame_count[rce.pict_type] ++;
-
- bits= rce.i_tex_bits + rce.p_tex_bits;
-
- q= get_qscale(s, &rce, rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum, i);
- rcc->pass1_wanted_bits+= s->bit_rate/(s->avctx->frame_rate / (double)s->avctx->frame_rate_base);
- }
- }
-
- }
-
- return 0;
-}
-
-void ff_rate_control_uninit(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- emms_c();
-
- av_freep(&rcc->entry);
-}
-
-static inline double qp2bits(RateControlEntry *rce, double qp){
- if(qp<=0.0){
- fprintf(stderr, "qp<=0.0\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ qp;
-}
-
-static inline double bits2qp(RateControlEntry *rce, double bits){
- if(bits<0.9){
- fprintf(stderr, "bits<0.9\n");
- }
- return rce->qscale * (double)(rce->i_tex_bits + rce->p_tex_bits+1)/ bits;
-}
-
-static void update_rc_buffer(MpegEncContext *s, int frame_size){
- RateControlContext *rcc= &s->rc_context;
- const double fps= (double)s->avctx->frame_rate / (double)s->avctx->frame_rate_base;
- const double buffer_size= s->avctx->rc_buffer_size;
- const double min_rate= s->avctx->rc_min_rate/fps;
- const double max_rate= s->avctx->rc_max_rate/fps;
-
- if(buffer_size){
- rcc->buffer_index-= frame_size;
- if(rcc->buffer_index < buffer_size/2 /*FIXME /2 */ || min_rate==0){
- rcc->buffer_index+= max_rate;
- if(rcc->buffer_index >= buffer_size)
- rcc->buffer_index= buffer_size-1;
- }else{
- rcc->buffer_index+= min_rate;
- }
-
- if(rcc->buffer_index < 0)
- fprintf(stderr, "rc buffer underflow\n");
- if(rcc->buffer_index >= s->avctx->rc_buffer_size)
- fprintf(stderr, "rc buffer overflow\n");
- }
-}
-
-/**
- * modifies the bitrate curve from pass1 for one frame
- */
-static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){
- RateControlContext *rcc= &s->rc_context;
- double q, bits;
- const int pict_type= rce->new_pict_type;
- const double mb_num= s->mb_num;
- int i;
-
- double const_values[]={
- M_PI,
- M_E,
- rce->i_tex_bits*rce->qscale,
- rce->p_tex_bits*rce->qscale,
- (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale,
- rce->mv_bits/mb_num,
- rce->pict_type == B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code,
- rce->i_count/mb_num,
- rce->mc_mb_var_sum/mb_num,
- rce->mb_var_sum/mb_num,
- rce->pict_type == I_TYPE,
- rce->pict_type == P_TYPE,
- rce->pict_type == B_TYPE,
- rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type],
- s->qcompress,
-/* rcc->last_qscale_for[I_TYPE],
- rcc->last_qscale_for[P_TYPE],
- rcc->last_qscale_for[B_TYPE],
- rcc->next_non_b_qscale,*/
- rcc->i_cplx_sum[I_TYPE] / (double)rcc->frame_count[I_TYPE],
- rcc->i_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
- rcc->p_cplx_sum[P_TYPE] / (double)rcc->frame_count[P_TYPE],
- rcc->p_cplx_sum[B_TYPE] / (double)rcc->frame_count[B_TYPE],
- (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type],
- 0
- };
- static const char *const_names[]={
- "PI",
- "E",
- "iTex",
- "pTex",
- "tex",
- "mv",
- "fCode",
- "iCount",
- "mcVar",
- "var",
- "isI",
- "isP",
- "isB",
- "avgQP",
- "qComp",
-/* "lastIQP",
- "lastPQP",
- "lastBQP",
- "nextNonBQP",*/
- "avgIITex",
- "avgPITex",
- "avgPPTex",
- "avgBPTex",
- "avgTex",
- NULL
- };
- static double (*func1[])(void *, double)={
- (void *)bits2qp,
- (void *)qp2bits,
- NULL
- };
- static const char *func1_names[]={
- "bits2qp",
- "qp2bits",
- NULL
- };
-
- bits= ff_eval(s->avctx->rc_eq, const_values, const_names, func1, func1_names, NULL, NULL, rce);
-
- rcc->pass1_rc_eq_output_sum+= bits;
- bits*=rate_factor;
- if(bits<0.0) bits=0.0;
- bits+= 1.0; //avoid 1/0 issues
-
- /* user override */
- for(i=0; i<s->avctx->rc_override_count; i++){
- RcOverride *rco= s->avctx->rc_override;
- if(rco[i].start_frame > frame_num) continue;
- if(rco[i].end_frame < frame_num) continue;
-
- if(rco[i].qscale)
- bits= qp2bits(rce, rco[i].qscale); //FIXME move at end to really force it?
- else
- bits*= rco[i].quality_factor;
- }
-
- q= bits2qp(rce, bits);
-
- /* I/B difference */
- if (pict_type==I_TYPE && s->avctx->i_quant_factor<0.0)
- q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset;
- else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0)
- q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset;
-
- return q;
-}
-
-static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, double q){
- RateControlContext *rcc= &s->rc_context;
- AVCodecContext *a= s->avctx;
- const int pict_type= rce->new_pict_type;
- const double last_p_q = rcc->last_qscale_for[P_TYPE];
- const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type];
-
- if (pict_type==I_TYPE && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==P_TYPE))
- q= last_p_q *ABS(a->i_quant_factor) + a->i_quant_offset;
- else if(pict_type==B_TYPE && a->b_quant_factor>0.0)
- q= last_non_b_q* a->b_quant_factor + a->b_quant_offset;
-
- /* last qscale / qdiff stuff */
- if(rcc->last_non_b_pict_type==pict_type || pict_type!=I_TYPE){
- double last_q= rcc->last_qscale_for[pict_type];
-
- if (q > last_q + a->max_qdiff) q= last_q + a->max_qdiff;
- else if(q < last_q - a->max_qdiff) q= last_q - a->max_qdiff;
- }
-
- rcc->last_qscale_for[pict_type]= q; //Note we cant do that after blurring
-
- if(pict_type!=B_TYPE)
- rcc->last_non_b_pict_type= pict_type;
-
- return q;
-}
-
-/**
- * gets the qmin & qmax for pict_type
- */
-static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type){
- int qmin= s->avctx->qmin;
- int qmax= s->avctx->qmax;
-
- assert(qmin <= qmax);
-
- if(pict_type==B_TYPE){
- qmin= (int)(qmin*ABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
- qmax= (int)(qmax*ABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5);
- }else if(pict_type==I_TYPE){
- qmin= (int)(qmin*ABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
- qmax= (int)(qmax*ABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5);
- }
-
- qmin= clip(qmin, 1, 31);
- qmax= clip(qmax, 1, 31);
-
- if(qmin==1 && s->avctx->qmin>1) qmin=2; //avoid qmin=1 unless the user wants qmin=1
-
- if(qmin<3 && s->max_qcoeff<=128 && pict_type==I_TYPE) qmin=3; //reduce cliping problems
-
- if(qmax<qmin) qmax= qmin;
-
- *qmin_ret= qmin;
- *qmax_ret= qmax;
-}
-
-static double modify_qscale(MpegEncContext *s, RateControlEntry *rce, double q, int frame_num){
- RateControlContext *rcc= &s->rc_context;
- int qmin, qmax;
- double bits;
- const int pict_type= rce->new_pict_type;
- const double buffer_size= s->avctx->rc_buffer_size;
- const double min_rate= s->avctx->rc_min_rate;
- const double max_rate= s->avctx->rc_max_rate;
-
- get_qminmax(&qmin, &qmax, s, pict_type);
-
- /* modulation */
- if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==P_TYPE)
- q*= s->avctx->rc_qmod_amp;
-
- bits= qp2bits(rce, q);
-//printf("q:%f\n", q);
- /* buffer overflow/underflow protection */
- if(buffer_size){
- double expected_size= rcc->buffer_index;
-
- if(min_rate){
- double d= 2*(buffer_size - expected_size)/buffer_size;
- if(d>1.0) d=1.0;
- else if(d<0.0001) d=0.0001;
- q*= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
-
- q= FFMIN(q, bits2qp(rce, FFMAX((min_rate - buffer_size + rcc->buffer_index)*2, 1)));
- }
-
- if(max_rate){
- double d= 2*expected_size/buffer_size;
- if(d>1.0) d=1.0;
- else if(d<0.0001) d=0.0001;
- q/= pow(d, 1.0/s->avctx->rc_buffer_aggressivity);
-
- q= FFMAX(q, bits2qp(rce, FFMAX(rcc->buffer_index/2, 1)));
- }
- }
-//printf("q:%f max:%f min:%f size:%f index:%d bits:%f agr:%f\n", q,max_rate, min_rate, buffer_size, rcc->buffer_index, bits, s->avctx->rc_buffer_aggressivity);
- if(s->avctx->rc_qsquish==0.0 || qmin==qmax){
- if (q<qmin) q=qmin;
- else if(q>qmax) q=qmax;
- }else{
- double min2= log(qmin);
- double max2= log(qmax);
-
- q= log(q);
- q= (q - min2)/(max2-min2) - 0.5;
- q*= -4.0;
- q= 1.0/(1.0 + exp(q));
- q= q*(max2-min2) + min2;
-
- q= exp(q);
- }
-
- return q;
-}
-
-//----------------------------------
-// 1 Pass Code
-
-static double predict_size(Predictor *p, double q, double var)
-{
- return p->coeff*var / (q*p->count);
-}
-
-/*
-static double predict_qp(Predictor *p, double size, double var)
-{
-//printf("coeff:%f, count:%f, var:%f, size:%f//\n", p->coeff, p->count, var, size);
- return p->coeff*var / (size*p->count);
-}
-*/
-
-static void update_predictor(Predictor *p, double q, double var, double size)
-{
- double new_coeff= size*q / (var + 1);
- if(var<10) return;
-
- p->count*= p->decay;
- p->coeff*= p->decay;
- p->count++;
- p->coeff+= new_coeff;
-}
-
-static void adaptive_quantization(MpegEncContext *s, double q){
- int i;
- const float lumi_masking= s->avctx->lumi_masking / (128.0*128.0);
- const float dark_masking= s->avctx->dark_masking / (128.0*128.0);
- const float temp_cplx_masking= s->avctx->temporal_cplx_masking;
- const float spatial_cplx_masking = s->avctx->spatial_cplx_masking;
- const float p_masking = s->avctx->p_masking;
- float bits_sum= 0.0;
- float cplx_sum= 0.0;
- float cplx_tab[s->mb_num];
- float bits_tab[s->mb_num];
- const int qmin= s->avctx->mb_qmin;
- const int qmax= s->avctx->mb_qmax;
- Picture * const pic= &s->current_picture;
- int last_qscale=0;
-
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- float temp_cplx= sqrt(pic->mc_mb_var[mb_xy]);
- float spat_cplx= sqrt(pic->mb_var[mb_xy]);
- const int lumi= pic->mb_mean[mb_xy];
- float bits, cplx, factor;
-
- if(spat_cplx < q/3) spat_cplx= q/3; //FIXME finetune
- if(temp_cplx < q/3) temp_cplx= q/3; //FIXME finetune
-
- if((s->mb_type[mb_xy]&MB_TYPE_INTRA)){//FIXME hq mode
- cplx= spat_cplx;
- factor= 1.0 + p_masking;
- }else{
- cplx= temp_cplx;
- factor= pow(temp_cplx, - temp_cplx_masking);
- }
- factor*=pow(spat_cplx, - spatial_cplx_masking);
-
- if(lumi>127)
- factor*= (1.0 - (lumi-128)*(lumi-128)*lumi_masking);
- else
- factor*= (1.0 - (lumi-128)*(lumi-128)*dark_masking);
-
- if(factor<0.00001) factor= 0.00001;
-
- bits= cplx*factor;
- cplx_sum+= cplx;
- bits_sum+= bits;
- cplx_tab[i]= cplx;
- bits_tab[i]= bits;
- }
-
- /* handle qmin/qmax cliping */
- if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
- for(i=0; i<s->mb_num; i++){
- float newq= q*cplx_tab[i]/bits_tab[i];
- newq*= bits_sum/cplx_sum;
-
- if (newq > qmax){
- bits_sum -= bits_tab[i];
- cplx_sum -= cplx_tab[i]*q/qmax;
- }
- else if(newq < qmin){
- bits_sum -= bits_tab[i];
- cplx_sum -= cplx_tab[i]*q/qmin;
- }
- }
- }
-
- for(i=0; i<s->mb_num; i++){
- const int mb_xy= s->mb_index2xy[i];
- float newq= q*cplx_tab[i]/bits_tab[i];
- int intq;
-
- if(s->flags&CODEC_FLAG_NORMALIZE_AQP){
- newq*= bits_sum/cplx_sum;
- }
-
- if(i && ABS(last_qscale - newq)<0.75)
- intq= last_qscale;
- else
- intq= (int)(newq + 0.5);
-
- if (intq > qmax) intq= qmax;
- else if(intq < qmin) intq= qmin;
-//if(i%s->mb_width==0) printf("\n");
-//printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i]));
- last_qscale=
- pic->qscale_table[mb_xy]= intq;
- }
-}
-
-float ff_rate_estimate_qscale(MpegEncContext *s)
-{
- float q;
- int qmin, qmax;
- float br_compensation;
- double diff;
- double short_term_q;
- double fps;
- int picture_number= s->picture_number;
- int64_t wanted_bits;
- RateControlContext *rcc= &s->rc_context;
- RateControlEntry local_rce, *rce;
- double bits;
- double rate_factor;
- int var;
- const int pict_type= s->pict_type;
- Picture * const pic= &s->current_picture;
- emms_c();
-
- get_qminmax(&qmin, &qmax, s, pict_type);
-
- fps= (double)s->avctx->frame_rate / (double)s->avctx->frame_rate_base;
-//printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate);
- /* update predictors */
- if(picture_number>2){
- const int last_var= s->last_pict_type == I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum;
- update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits);
- }
-
- if(s->flags&CODEC_FLAG_PASS2){
- assert(picture_number>=0);
- assert(picture_number<rcc->num_entries);
- rce= &rcc->entry[picture_number];
- wanted_bits= rce->expected_bits;
- }else{
- rce= &local_rce;
- wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps);
- }
-
- diff= s->total_bits - wanted_bits;
- br_compensation= (s->bit_rate_tolerance - diff)/s->bit_rate_tolerance;
- if(br_compensation<=0.0) br_compensation=0.001;
-
- var= pict_type == I_TYPE ? pic->mb_var_sum : pic->mc_mb_var_sum;
-
- short_term_q = 0; /* avoid warning */
- if(s->flags&CODEC_FLAG_PASS2){
- if(pict_type!=I_TYPE)
- assert(pict_type == rce->new_pict_type);
-
- q= rce->new_qscale / br_compensation;
-//printf("%f %f %f last:%d var:%d type:%d//\n", q, rce->new_qscale, br_compensation, s->frame_bits, var, pict_type);
- }else{
- rce->pict_type=
- rce->new_pict_type= pict_type;
- rce->mc_mb_var_sum= pic->mc_mb_var_sum;
- rce->mb_var_sum = pic-> mb_var_sum;
- rce->qscale = 2;
- rce->f_code = s->f_code;
- rce->b_code = s->b_code;
- rce->misc_bits= 1;
-
- if(picture_number>0)
- update_rc_buffer(s, s->frame_bits);
-
- bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var));
- if(pict_type== I_TYPE){
- rce->i_count = s->mb_num;
- rce->i_tex_bits= bits;
- rce->p_tex_bits= 0;
- rce->mv_bits= 0;
- }else{
- rce->i_count = 0; //FIXME we do know this approx
- rce->i_tex_bits= 0;
- rce->p_tex_bits= bits*0.9;
-
- rce->mv_bits= bits*0.1;
- }
- rcc->i_cplx_sum [pict_type] += rce->i_tex_bits*rce->qscale;
- rcc->p_cplx_sum [pict_type] += rce->p_tex_bits*rce->qscale;
- rcc->mv_bits_sum[pict_type] += rce->mv_bits;
- rcc->frame_count[pict_type] ++;
-
- bits= rce->i_tex_bits + rce->p_tex_bits;
- rate_factor= rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum * br_compensation;
-
- q= get_qscale(s, rce, rate_factor, picture_number);
-
- assert(q>0.0);
-//printf("%f ", q);
- q= get_diff_limited_q(s, rce, q);
-//printf("%f ", q);
- assert(q>0.0);
-
- if(pict_type==P_TYPE || s->intra_only){ //FIXME type dependant blur like in 2-pass
- rcc->short_term_qsum*=s->qblur;
- rcc->short_term_qcount*=s->qblur;
-
- rcc->short_term_qsum+= q;
- rcc->short_term_qcount++;
-//printf("%f ", q);
- q= short_term_q= rcc->short_term_qsum/rcc->short_term_qcount;
-//printf("%f ", q);
- }
- assert(q>0.0);
-
- q= modify_qscale(s, rce, q, picture_number);
-
- rcc->pass1_wanted_bits+= s->bit_rate/fps;
-
- assert(q>0.0);
- }
-
- if(s->avctx->debug&FF_DEBUG_RC){
- printf("%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f size:%d var:%d/%d br:%d fps:%d\n",
- av_get_pict_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000,
- br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate/1000, (int)fps
- );
- }
-
- if (q<qmin) q=qmin;
- else if(q>qmax) q=qmax;
-
- if(s->adaptive_quant)
- adaptive_quantization(s, q);
- else
- q= (int)(q + 0.5);
-
- rcc->last_qscale= q;
- rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum;
- rcc->last_mb_var_sum= pic->mb_var_sum;
-#if 0
-{
- static int mvsum=0, texsum=0;
- mvsum += s->mv_bits;
- texsum += s->i_tex_bits + s->p_tex_bits;
- printf("%d %d//\n\n", mvsum, texsum);
-}
-#endif
- return q;
-}
-
-//----------------------------------------------
-// 2-Pass code
-
-static int init_pass2(MpegEncContext *s)
-{
- RateControlContext *rcc= &s->rc_context;
- int i;
- double fps= (double)s->avctx->frame_rate / (double)s->avctx->frame_rate_base;
- double complexity[5]={0,0,0,0,0}; // aproximate bits at quant=1
- double avg_quantizer[5];
- uint64_t const_bits[5]={0,0,0,0,0}; // quantizer idependant bits
- uint64_t available_bits[5];
- uint64_t all_const_bits;
- uint64_t all_available_bits= (uint64_t)(s->bit_rate*(double)rcc->num_entries/fps);
- double rate_factor=0;
- double step;
- //int last_i_frame=-10000000;
- const int filter_size= (int)(s->qblur*4) | 1;
- double expected_bits;
- double *qscale, *blured_qscale;
-
- /* find complexity & const_bits & decide the pict_types */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
-
- rce->new_pict_type= rce->pict_type;
- rcc->i_cplx_sum [rce->pict_type] += rce->i_tex_bits*rce->qscale;
- rcc->p_cplx_sum [rce->pict_type] += rce->p_tex_bits*rce->qscale;
- rcc->mv_bits_sum[rce->pict_type] += rce->mv_bits;
- rcc->frame_count[rce->pict_type] ++;
-
- complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale;
- const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits;
- }
- all_const_bits= const_bits[I_TYPE] + const_bits[P_TYPE] + const_bits[B_TYPE];
-
- if(all_available_bits < all_const_bits){
- fprintf(stderr, "requested bitrate is to low\n");
- return -1;
- }
-
- /* find average quantizers */
- avg_quantizer[P_TYPE]=0;
- for(step=256*256; step>0.0000001; step*=0.5){
- double expected_bits=0;
- avg_quantizer[P_TYPE]+= step;
-
- avg_quantizer[I_TYPE]= avg_quantizer[P_TYPE]*ABS(s->avctx->i_quant_factor) + s->avctx->i_quant_offset;
- avg_quantizer[B_TYPE]= avg_quantizer[P_TYPE]*ABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
-
- expected_bits=
- + all_const_bits
- + complexity[I_TYPE]/avg_quantizer[I_TYPE]
- + complexity[P_TYPE]/avg_quantizer[P_TYPE]
- + complexity[B_TYPE]/avg_quantizer[B_TYPE];
-
- if(expected_bits < all_available_bits) avg_quantizer[P_TYPE]-= step;
-//printf("%f %lld %f\n", expected_bits, all_available_bits, avg_quantizer[P_TYPE]);
- }
-//printf("qp_i:%f, qp_p:%f, qp_b:%f\n", avg_quantizer[I_TYPE],avg_quantizer[P_TYPE],avg_quantizer[B_TYPE]);
-
- for(i=0; i<5; i++){
- available_bits[i]= const_bits[i] + complexity[i]/avg_quantizer[i];
- }
-//printf("%lld %lld %lld %lld\n", available_bits[I_TYPE], available_bits[P_TYPE], available_bits[B_TYPE], all_available_bits);
-
- qscale= av_malloc(sizeof(double)*rcc->num_entries);
- blured_qscale= av_malloc(sizeof(double)*rcc->num_entries);
-
- for(step=256*256; step>0.0000001; step*=0.5){
- expected_bits=0;
- rate_factor+= step;
-
- rcc->buffer_index= s->avctx->rc_buffer_size/2;
-
- /* find qscale */
- for(i=0; i<rcc->num_entries; i++){
- qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i);
- }
- assert(filter_size%2==1);
-
- /* fixed I/B QP relative to P mode */
- for(i=rcc->num_entries-1; i>=0; i--){
- RateControlEntry *rce= &rcc->entry[i];
-
- qscale[i]= get_diff_limited_q(s, rce, qscale[i]);
- }
-
- /* smooth curve */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- const int pict_type= rce->new_pict_type;
- int j;
- double q=0.0, sum=0.0;
-
- for(j=0; j<filter_size; j++){
- int index= i+j-filter_size/2;
- double d= index-i;
- double coeff= s->qblur==0 ? 1.0 : exp(-d*d/(s->qblur * s->qblur));
-
- if(index < 0 || index >= rcc->num_entries) continue;
- if(pict_type != rcc->entry[index].new_pict_type) continue;
- q+= qscale[index] * coeff;
- sum+= coeff;
- }
- blured_qscale[i]= q/sum;
- }
-
- /* find expected bits */
- for(i=0; i<rcc->num_entries; i++){
- RateControlEntry *rce= &rcc->entry[i];
- double bits;
- rce->new_qscale= modify_qscale(s, rce, blured_qscale[i], i);
- bits= qp2bits(rce, rce->new_qscale) + rce->mv_bits + rce->misc_bits;
-//printf("%d %f\n", rce->new_bits, blured_qscale[i]);
- update_rc_buffer(s, bits);
-
- rce->expected_bits= expected_bits;
- expected_bits += bits;
- }
-
-// printf("%f %d %f\n", expected_bits, (int)all_available_bits, rate_factor);
- if(expected_bits > all_available_bits) rate_factor-= step;
- }
- av_free(qscale);
- av_free(blured_qscale);
-
- if(abs(expected_bits/all_available_bits - 1.0) > 0.01 ){
- fprintf(stderr, "Error: 2pass curve failed to converge\n");
- return -1;
- }
-
- return 0;
-}
+++ /dev/null
-/*
- * Raw Video Codec
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file raw.c
- * Raw Video Codec
- */
-
-#include "avcodec.h"
-
-typedef struct RawVideoContext {
- unsigned char * buffer; /* block of memory for holding one frame */
- unsigned char * p; /* current position in buffer */
- int length; /* number of bytes in buffer */
- AVFrame pic; ///< AVCodecContext.coded_frame
-} RawVideoContext;
-
-typedef struct PixleFormatTag {
- int pix_fmt;
- unsigned int fourcc;
-} PixelFormatTag;
-
-const PixelFormatTag pixelFormatTags[] = {
- { PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
- { PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') },
- { PIX_FMT_YUV410P, MKTAG('Y', 'U', 'V', '9') },
- { PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') },
- { PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') },
- { PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') },
- { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') },
-
-
- { PIX_FMT_YUV422, MKTAG('Y', '4', '2', '2') }, /* Packed formats */
- { PIX_FMT_YUV422, MKTAG('U', 'Y', 'V', 'Y') },
- { PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') },
-
- { -1, 0 },
-};
-
-static int findPixelFormat(unsigned int fourcc)
-{
- const PixelFormatTag * tags = pixelFormatTags;
- while (tags->pix_fmt >= 0) {
- if (tags->fourcc == fourcc)
- return tags->pix_fmt;
- tags++;
- }
- return PIX_FMT_YUV420P;
-}
-
-static unsigned int findFourCC(int fmt)
-{
- const PixelFormatTag * tags = pixelFormatTags;
- while (tags->pix_fmt >= 0) {
- if (tags->pix_fmt == fmt)
- return tags->fourcc;
- tags++;
- }
- return 0;
-}
-
-/* RAW Decoder Implementation */
-
-static int raw_init_decoder(AVCodecContext *avctx)
-{
- RawVideoContext *context = avctx->priv_data;
-
- if (avctx->codec_tag)
- avctx->pix_fmt = findPixelFormat(avctx->codec_tag);
-
- context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
- context->buffer = av_malloc(context->length);
- context->p = context->buffer;
- context->pic.pict_type = FF_I_TYPE;
- context->pic.key_frame = 1;
-
- avctx->coded_frame= &context->pic;
-
- if (!context->buffer)
- return -1;
-
- return 0;
-}
-
-static int raw_decode(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- RawVideoContext *context = avctx->priv_data;
- int bytesNeeded;
-
- AVPicture * picture = (AVPicture *) data;
-
- /* Early out without copy if packet size == frame size */
- if (buf_size == context->length && context->p == context->buffer) {
- avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height);
- *data_size = sizeof(AVPicture);
- return buf_size;
- }
-
- bytesNeeded = context->length - (context->p - context->buffer);
- if (buf_size < bytesNeeded) {
- memcpy(context->p, buf, buf_size);
- context->p += buf_size;
- *data_size = 0;
- return buf_size;
- }
-
- memcpy(context->p, buf, bytesNeeded);
- context->p = context->buffer;
- avpicture_fill(picture, context->buffer, avctx->pix_fmt, avctx->width, avctx->height);
- *data_size = sizeof(AVPicture);
- return bytesNeeded;
-}
-
-static int raw_close_decoder(AVCodecContext *avctx)
-{
- RawVideoContext *context = avctx->priv_data;
-
- av_freep(&context->buffer);
- return 0;
-}
-
-/* RAW Encoder Implementation */
-
-static int raw_init_encoder(AVCodecContext *avctx)
-{
- avctx->coded_frame = (AVFrame *)avctx->priv_data;
- avctx->coded_frame->pict_type = FF_I_TYPE;
- avctx->coded_frame->key_frame = 1;
- avctx->codec_tag = findFourCC(avctx->pix_fmt);
- return 0;
-}
-
-static int raw_encode(AVCodecContext *avctx,
- unsigned char *frame, int buf_size, void *data)
-{
- return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width,
- avctx->height, frame, buf_size);
-}
-
-AVCodec rawvideo_encoder = {
- "rawvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(AVFrame),
- raw_init_encoder,
- raw_encode,
-};
-
-AVCodec rawvideo_decoder = {
- "rawvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RAWVIDEO,
- sizeof(RawVideoContext),
- raw_init_decoder,
- NULL,
- raw_close_decoder,
- raw_decode,
-};
+++ /dev/null
-/*
- * Sample rate convertion for both audio and video
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file resample.c
- * Sample rate convertion for both audio and video.
- */
-
-#include "avcodec.h"
-
-typedef struct {
- /* fractional resampling */
- uint32_t incr; /* fractional increment */
- uint32_t frac;
- int last_sample;
- /* integer down sample */
- int iratio; /* integer divison ratio */
- int icount, isum;
- int inv;
-} ReSampleChannelContext;
-
-struct ReSampleContext {
- ReSampleChannelContext channel_ctx[2];
- float ratio;
- /* channel convert */
- int input_channels, output_channels, filter_channels;
-};
-
-
-#define FRAC_BITS 16
-#define FRAC (1 << FRAC_BITS)
-
-static void init_mono_resample(ReSampleChannelContext *s, float ratio)
-{
- ratio = 1.0 / ratio;
- s->iratio = (int)floorf(ratio);
- if (s->iratio == 0)
- s->iratio = 1;
- s->incr = (int)((ratio / s->iratio) * FRAC);
- s->frac = FRAC;
- s->last_sample = 0;
- s->icount = s->iratio;
- s->isum = 0;
- s->inv = (FRAC / s->iratio);
-}
-
-/* fractional audio resampling */
-static int fractional_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
-{
- unsigned int frac, incr;
- int l0, l1;
- short *q, *p, *pend;
-
- l0 = s->last_sample;
- incr = s->incr;
- frac = s->frac;
-
- p = input;
- pend = input + nb_samples;
- q = output;
-
- l1 = *p++;
- for(;;) {
- /* interpolate */
- *q++ = (l0 * (FRAC - frac) + l1 * frac) >> FRAC_BITS;
- frac = frac + s->incr;
- while (frac >= FRAC) {
- frac -= FRAC;
- if (p >= pend)
- goto the_end;
- l0 = l1;
- l1 = *p++;
- }
- }
- the_end:
- s->last_sample = l1;
- s->frac = frac;
- return q - output;
-}
-
-static int integer_downsample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
-{
- short *q, *p, *pend;
- int c, sum;
-
- p = input;
- pend = input + nb_samples;
- q = output;
-
- c = s->icount;
- sum = s->isum;
-
- for(;;) {
- sum += *p++;
- if (--c == 0) {
- *q++ = (sum * s->inv) >> FRAC_BITS;
- c = s->iratio;
- sum = 0;
- }
- if (p >= pend)
- break;
- }
- s->isum = sum;
- s->icount = c;
- return q - output;
-}
-
-/* n1: number of samples */
-static void stereo_to_mono(short *output, short *input, int n1)
-{
- short *p, *q;
- int n = n1;
-
- p = input;
- q = output;
- while (n >= 4) {
- q[0] = (p[0] + p[1]) >> 1;
- q[1] = (p[2] + p[3]) >> 1;
- q[2] = (p[4] + p[5]) >> 1;
- q[3] = (p[6] + p[7]) >> 1;
- q += 4;
- p += 8;
- n -= 4;
- }
- while (n > 0) {
- q[0] = (p[0] + p[1]) >> 1;
- q++;
- p += 2;
- n--;
- }
-}
-
-/* n1: number of samples */
-static void mono_to_stereo(short *output, short *input, int n1)
-{
- short *p, *q;
- int n = n1;
- int v;
-
- p = input;
- q = output;
- while (n >= 4) {
- v = p[0]; q[0] = v; q[1] = v;
- v = p[1]; q[2] = v; q[3] = v;
- v = p[2]; q[4] = v; q[5] = v;
- v = p[3]; q[6] = v; q[7] = v;
- q += 8;
- p += 4;
- n -= 4;
- }
- while (n > 0) {
- v = p[0]; q[0] = v; q[1] = v;
- q += 2;
- p += 1;
- n--;
- }
-}
-
-/* XXX: should use more abstract 'N' channels system */
-static void stereo_split(short *output1, short *output2, short *input, int n)
-{
- int i;
-
- for(i=0;i<n;i++) {
- *output1++ = *input++;
- *output2++ = *input++;
- }
-}
-
-static void stereo_mux(short *output, short *input1, short *input2, int n)
-{
- int i;
-
- for(i=0;i<n;i++) {
- *output++ = *input1++;
- *output++ = *input2++;
- }
-}
-
-static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
-{
- int i;
- short l,r;
-
- for(i=0;i<n;i++) {
- l=*input1++;
- r=*input2++;
- *output++ = l; /* left */
- *output++ = (l/2)+(r/2); /* center */
- *output++ = r; /* right */
- *output++ = 0; /* left surround */
- *output++ = 0; /* right surroud */
- *output++ = 0; /* low freq */
- }
-}
-
-static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
-{
- short *buf1;
- short *buftmp;
-
- buf1= (short*)av_malloc( nb_samples * sizeof(short) );
-
- /* first downsample by an integer factor with averaging filter */
- if (s->iratio > 1) {
- buftmp = buf1;
- nb_samples = integer_downsample(s, buftmp, input, nb_samples);
- } else {
- buftmp = input;
- }
-
- /* then do a fractional resampling with linear interpolation */
- if (s->incr != FRAC) {
- nb_samples = fractional_resample(s, output, buftmp, nb_samples);
- } else {
- memcpy(output, buftmp, nb_samples * sizeof(short));
- }
- av_free(buf1);
- return nb_samples;
-}
-
-ReSampleContext *audio_resample_init(int output_channels, int input_channels,
- int output_rate, int input_rate)
-{
- ReSampleContext *s;
- int i;
-
- if ( input_channels > 2)
- {
- printf("Resampling with input channels greater than 2 unsupported.");
- return NULL;
- }
-
- s = av_mallocz(sizeof(ReSampleContext));
- if (!s)
- {
- printf("Can't allocate memory for resample context.");
- return NULL;
- }
-
- s->ratio = (float)output_rate / (float)input_rate;
-
- s->input_channels = input_channels;
- s->output_channels = output_channels;
-
- s->filter_channels = s->input_channels;
- if (s->output_channels < s->filter_channels)
- s->filter_channels = s->output_channels;
-
-/*
- * ac3 output is the only case where filter_channels could be greater than 2.
- * input channels can't be greater than 2, so resample the 2 channels and then
- * expand to 6 channels after the resampling.
- */
- if(s->filter_channels>2)
- s->filter_channels = 2;
-
- for(i=0;i<s->filter_channels;i++) {
- init_mono_resample(&s->channel_ctx[i], s->ratio);
- }
- return s;
-}
-
-/* resample audio. 'nb_samples' is the number of input samples */
-/* XXX: optimize it ! */
-/* XXX: do it with polyphase filters, since the quality here is
- HORRIBLE. Return the number of samples available in output */
-int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
-{
- int i, nb_samples1;
- short *bufin[2];
- short *bufout[2];
- short *buftmp2[2], *buftmp3[2];
- int lenout;
-
- if (s->input_channels == s->output_channels && s->ratio == 1.0) {
- /* nothing to do */
- memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
- return nb_samples;
- }
-
- /* XXX: move those malloc to resample init code */
- bufin[0]= (short*) av_malloc( nb_samples * sizeof(short) );
- bufin[1]= (short*) av_malloc( nb_samples * sizeof(short) );
-
- /* make some zoom to avoid round pb */
- lenout= (int)(nb_samples * s->ratio) + 16;
- bufout[0]= (short*) av_malloc( lenout * sizeof(short) );
- bufout[1]= (short*) av_malloc( lenout * sizeof(short) );
-
- if (s->input_channels == 2 &&
- s->output_channels == 1) {
- buftmp2[0] = bufin[0];
- buftmp3[0] = output;
- stereo_to_mono(buftmp2[0], input, nb_samples);
- } else if (s->output_channels >= 2 && s->input_channels == 1) {
- buftmp2[0] = input;
- buftmp3[0] = bufout[0];
- } else if (s->output_channels >= 2) {
- buftmp2[0] = bufin[0];
- buftmp2[1] = bufin[1];
- buftmp3[0] = bufout[0];
- buftmp3[1] = bufout[1];
- stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
- } else {
- buftmp2[0] = input;
- buftmp3[0] = output;
- }
-
- /* resample each channel */
- nb_samples1 = 0; /* avoid warning */
- for(i=0;i<s->filter_channels;i++) {
- nb_samples1 = mono_resample(&s->channel_ctx[i], buftmp3[i], buftmp2[i], nb_samples);
- }
-
- if (s->output_channels == 2 && s->input_channels == 1) {
- mono_to_stereo(output, buftmp3[0], nb_samples1);
- } else if (s->output_channels == 2) {
- stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
- } else if (s->output_channels == 6) {
- ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
- }
-
- av_free(bufin[0]);
- av_free(bufin[1]);
-
- av_free(bufout[0]);
- av_free(bufout[1]);
- return nb_samples1;
-}
-
-void audio_resample_close(ReSampleContext *s)
-{
- av_free(s);
-}
+++ /dev/null
-/*
- * Copyright (C) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file roqvideo.c
- * Id RoQ Video Decoder by Dr. Tim Ferguson
- * For more information about the Id RoQ format, visit:
- * http://www.csse.monash.edu.au/~timf/
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-typedef struct {
- unsigned char y0, y1, y2, y3, u, v;
-} roq_cell;
-
-typedef struct {
- int idx[4];
-} roq_qcell;
-
-
-typedef struct RoqContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame last_frame;
- AVFrame current_frame;
- int first_frame;
- int y_stride;
- int c_stride;
-
- roq_cell cells[256];
- roq_qcell qcells[256];
-
- unsigned char *buf;
- int size;
-
-} RoqContext;
-
-#define RoQ_INFO 0x1001
-#define RoQ_QUAD_CODEBOOK 0x1002
-#define RoQ_QUAD_VQ 0x1011
-#define RoQ_SOUND_MONO 0x1020
-#define RoQ_SOUND_STEREO 0x1021
-
-#define RoQ_ID_MOT 0x00
-#define RoQ_ID_FCC 0x01
-#define RoQ_ID_SLD 0x02
-#define RoQ_ID_CCC 0x03
-
-#define get_byte(in_buffer) *(in_buffer++)
-#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \
- (in_buffer[-1] << 8 | in_buffer[-2])))
-#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \
- (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4])))
-
-
-static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
-{
- unsigned char *yptr;
-
- yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- *yptr++ = cell->y0;
- *yptr++ = cell->y1;
- yptr += (ri->y_stride - 2);
- *yptr++ = cell->y2;
- *yptr++ = cell->y3;
- ri->current_frame.data[1][(y/2) * (ri->c_stride) + x/2] = cell->u;
- ri->current_frame.data[2][(y/2) * (ri->c_stride) + x/2] = cell->v;
-}
-
-static void apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
-{
- unsigned long row_inc, c_row_inc;
- register unsigned char y0, y1, u, v;
- unsigned char *yptr, *uptr, *vptr;
-
- yptr = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- uptr = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2;
- vptr = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2;
-
- row_inc = ri->y_stride - 4;
- c_row_inc = (ri->c_stride) - 2;
- *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v;
- *yptr++ = y0;
- *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v;
- *yptr++ = y1;
-
- yptr += row_inc;
-
- *yptr++ = y0;
- *yptr++ = y0;
- *yptr++ = y1;
- *yptr++ = y1;
-
- yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc;
-
- *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v;
- *yptr++ = y0;
- *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v;
- *yptr++ = y1;
-
- yptr += row_inc;
-
- *yptr++ = y0;
- *yptr++ = y0;
- *yptr++ = y1;
- *yptr++ = y1;
-}
-
-static void apply_motion_4x4(RoqContext *ri, int x, int y, unsigned char mv,
- char mean_x, char mean_y)
-{
- int i, mx, my;
- unsigned char *pa, *pb;
-
- mx = x + 8 - (mv >> 4) - mean_x;
- my = y + 8 - (mv & 0xf) - mean_y;
-
- pa = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx;
- for(i = 0; i < 4; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa += ri->y_stride;
- pb += ri->y_stride;
- }
-
- pa = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2;
- pb = ri->last_frame.data[1] + (my/2) * (ri->c_stride) + (mx + 1)/2;
- for(i = 0; i < 2; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa += ri->c_stride;
- pb += ri->c_stride;
- }
-
- pa = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2;
- pb = ri->last_frame.data[2] + (my/2) * (ri->c_stride) + (mx + 1)/2;
- for(i = 0; i < 2; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa += ri->c_stride;
- pb += ri->c_stride;
- }
-}
-
-static void apply_motion_8x8(RoqContext *ri, int x, int y,
- unsigned char mv, char mean_x, char mean_y)
-{
- int mx, my, i;
- unsigned char *pa, *pb;
-
- mx = x + 8 - (mv >> 4) - mean_x;
- my = y + 8 - (mv & 0xf) - mean_y;
-
- pa = ri->current_frame.data[0] + (y * ri->y_stride) + x;
- pb = ri->last_frame.data[0] + (my * ri->y_stride) + mx;
- for(i = 0; i < 8; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa[4] = pb[4];
- pa[5] = pb[5];
- pa[6] = pb[6];
- pa[7] = pb[7];
- pa += ri->y_stride;
- pb += ri->y_stride;
- }
-
- pa = ri->current_frame.data[1] + (y/2) * (ri->c_stride) + x/2;
- pb = ri->last_frame.data[1] + (my/2) * (ri->c_stride) + (mx + 1)/2;
- for(i = 0; i < 4; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa += ri->c_stride;
- pb += ri->c_stride;
- }
-
- pa = ri->current_frame.data[2] + (y/2) * (ri->c_stride) + x/2;
- pb = ri->last_frame.data[2] + (my/2) * (ri->c_stride) + (mx + 1)/2;
- for(i = 0; i < 4; i++) {
- pa[0] = pb[0];
- pa[1] = pb[1];
- pa[2] = pb[2];
- pa[3] = pb[3];
- pa += ri->c_stride;
- pb += ri->c_stride;
- }
-}
-
-static void roqvideo_decode_frame(RoqContext *ri)
-{
- unsigned int chunk_id = 0, chunk_arg = 0;
- unsigned long chunk_size = 0;
- int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1;
- int vqid, bpos, xpos, ypos, xp, yp, x, y;
- int frame_stats[2][4] = {{0},{0}};
- roq_qcell *qcell;
- unsigned char *buf = ri->buf;
- unsigned char *buf_end = ri->buf + ri->size;
-
- while (buf < buf_end) {
- chunk_id = get_word(buf);
- chunk_size = get_long(buf);
- chunk_arg = get_word(buf);
-
- if(chunk_id == RoQ_QUAD_VQ)
- break;
- if(chunk_id == RoQ_QUAD_CODEBOOK) {
- if((nv1 = chunk_arg >> 8) == 0)
- nv1 = 256;
- if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
- nv2 = 256;
- for(i = 0; i < nv1; i++) {
- ri->cells[i].y0 = get_byte(buf);
- ri->cells[i].y1 = get_byte(buf);
- ri->cells[i].y2 = get_byte(buf);
- ri->cells[i].y3 = get_byte(buf);
- ri->cells[i].u = get_byte(buf);
- ri->cells[i].v = get_byte(buf);
- }
- for(i = 0; i < nv2; i++)
- for(j = 0; j < 4; j++)
- ri->qcells[i].idx[j] = get_byte(buf);
- }
- }
-
- bpos = xpos = ypos = 0;
- while(bpos < chunk_size) {
- for (yp = ypos; yp < ypos + 16; yp += 8)
- for (xp = xpos; xp < xpos + 16; xp += 8) {
- if (vqflg_pos < 0) {
- vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
- vqflg_pos = 7;
- }
- vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
- frame_stats[0][vqid]++;
- vqflg_pos--;
-
- switch(vqid) {
- case RoQ_ID_MOT:
- apply_motion_8x8(ri, xp, yp, 0, 8, 8);
- break;
- case RoQ_ID_FCC:
- apply_motion_8x8(ri, xp, yp, buf[bpos++], chunk_arg >> 8,
- chunk_arg & 0xff);
- break;
- case RoQ_ID_SLD:
- qcell = ri->qcells + buf[bpos++];
- apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]);
- apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]);
- apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]);
- apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]);
- break;
- case RoQ_ID_CCC:
- for (k = 0; k < 4; k++) {
- x = xp; y = yp;
- if(k & 0x01) x += 4;
- if(k & 0x02) y += 4;
-
- if (vqflg_pos < 0) {
- vqflg = buf[bpos++];
- vqflg |= (buf[bpos++] << 8);
- vqflg_pos = 7;
- }
- vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
- frame_stats[1][vqid]++;
- vqflg_pos--;
- switch(vqid) {
- case RoQ_ID_MOT:
- apply_motion_4x4(ri, x, y, 0, 8, 8);
- break;
- case RoQ_ID_FCC:
- apply_motion_4x4(ri, x, y, buf[bpos++],
- chunk_arg >> 8, chunk_arg & 0xff);
- break;
- case RoQ_ID_SLD:
- qcell = ri->qcells + buf[bpos++];
- apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]);
- apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]);
- apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]);
- apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]);
- break;
- case RoQ_ID_CCC:
- apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]);
- apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]);
- apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]);
- apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]);
- bpos += 4;
- break;
- }
- }
- break;
- default:
- printf("Unknown vq code: %d\n", vqid);
- }
- }
-
- xpos += 16;
- if (xpos >= ri->avctx->width) {
- xpos -= ri->avctx->width;
- ypos += 16;
- }
- if(ypos >= ri->avctx->height)
- break;
- }
-}
-
-
-static int roq_decode_init(AVCodecContext *avctx)
-{
- RoqContext *s = avctx->priv_data;
-
- s->avctx = avctx;
- s->first_frame = 1;
- avctx->pix_fmt = PIX_FMT_YUV420P;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- return 0;
-}
-
-static int roq_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- RoqContext *s = avctx->priv_data;
-
- *data_size = 0;
-
- if (avctx->get_buffer(avctx, &s->current_frame)) {
- printf (" RoQ: get_buffer() failed\n");
- return -1;
- }
- s->y_stride = s->current_frame.linesize[0];
- s->c_stride = s->current_frame.linesize[1];
-
- s->buf = buf;
- s->size = buf_size;
- roqvideo_decode_frame(s);
-
- /* release the last frame if it is allocated */
- if (s->first_frame)
- s->first_frame = 0;
- else
- avctx->release_buffer(avctx, &s->last_frame);
-
- /* shuffle frames */
- s->last_frame = s->current_frame;
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->current_frame;
-
- return buf_size;
-}
-
-static int roq_decode_end(AVCodecContext *avctx)
-{
- RoqContext *s = avctx->priv_data;
-
- /* release the last frame */
- avctx->release_buffer(avctx, &s->last_frame);
-
- return 0;
-}
-
-AVCodec roq_decoder = {
- "roqvideo",
- CODEC_TYPE_VIDEO,
- CODEC_ID_ROQ,
- sizeof(RoqContext),
- roq_decode_init,
- NULL,
- roq_decode_end,
- roq_decode_frame,
- CODEC_CAP_DR1,
-};
+++ /dev/null
-/*
- * RV10 codec
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file rv10.c
- * RV10 codec.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-//#define DEBUG
-
-#define DC_VLC_BITS 14 //FIXME find a better solution
-
-static const uint16_t rv_lum_code[256] =
-{
- 0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06,
- 0x0f07, 0x0f08, 0x0f09, 0x0f0a, 0x0f0b, 0x0f0c, 0x0f0d, 0x0f0e,
- 0x0f0f, 0x0f10, 0x0f11, 0x0f12, 0x0f13, 0x0f14, 0x0f15, 0x0f16,
- 0x0f17, 0x0f18, 0x0f19, 0x0f1a, 0x0f1b, 0x0f1c, 0x0f1d, 0x0f1e,
- 0x0f1f, 0x0f20, 0x0f21, 0x0f22, 0x0f23, 0x0f24, 0x0f25, 0x0f26,
- 0x0f27, 0x0f28, 0x0f29, 0x0f2a, 0x0f2b, 0x0f2c, 0x0f2d, 0x0f2e,
- 0x0f2f, 0x0f30, 0x0f31, 0x0f32, 0x0f33, 0x0f34, 0x0f35, 0x0f36,
- 0x0f37, 0x0f38, 0x0f39, 0x0f3a, 0x0f3b, 0x0f3c, 0x0f3d, 0x0f3e,
- 0x0f3f, 0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0386,
- 0x0387, 0x0388, 0x0389, 0x038a, 0x038b, 0x038c, 0x038d, 0x038e,
- 0x038f, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396,
- 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e,
- 0x039f, 0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6,
- 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce,
- 0x00cf, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056,
- 0x0057, 0x0020, 0x0021, 0x0022, 0x0023, 0x000c, 0x000d, 0x0004,
- 0x0000, 0x0005, 0x000e, 0x000f, 0x0024, 0x0025, 0x0026, 0x0027,
- 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
- 0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
- 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
- 0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
- 0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
- 0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
- 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
- 0x0f40, 0x0f41, 0x0f42, 0x0f43, 0x0f44, 0x0f45, 0x0f46, 0x0f47,
- 0x0f48, 0x0f49, 0x0f4a, 0x0f4b, 0x0f4c, 0x0f4d, 0x0f4e, 0x0f4f,
- 0x0f50, 0x0f51, 0x0f52, 0x0f53, 0x0f54, 0x0f55, 0x0f56, 0x0f57,
- 0x0f58, 0x0f59, 0x0f5a, 0x0f5b, 0x0f5c, 0x0f5d, 0x0f5e, 0x0f5f,
- 0x0f60, 0x0f61, 0x0f62, 0x0f63, 0x0f64, 0x0f65, 0x0f66, 0x0f67,
- 0x0f68, 0x0f69, 0x0f6a, 0x0f6b, 0x0f6c, 0x0f6d, 0x0f6e, 0x0f6f,
- 0x0f70, 0x0f71, 0x0f72, 0x0f73, 0x0f74, 0x0f75, 0x0f76, 0x0f77,
- 0x0f78, 0x0f79, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f7e, 0x0f7f,
-};
-
-static const uint8_t rv_lum_bits[256] =
-{
- 14, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 7, 7, 7, 7, 7, 7, 7,
- 7, 6, 6, 6, 6, 5, 5, 4,
- 2, 4, 5, 5, 6, 6, 6, 6,
- 7, 7, 7, 7, 7, 7, 7, 7,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
-};
-
-static const uint16_t rv_chrom_code[256] =
-{
- 0xfe7f, 0x3f00, 0x3f01, 0x3f02, 0x3f03, 0x3f04, 0x3f05, 0x3f06,
- 0x3f07, 0x3f08, 0x3f09, 0x3f0a, 0x3f0b, 0x3f0c, 0x3f0d, 0x3f0e,
- 0x3f0f, 0x3f10, 0x3f11, 0x3f12, 0x3f13, 0x3f14, 0x3f15, 0x3f16,
- 0x3f17, 0x3f18, 0x3f19, 0x3f1a, 0x3f1b, 0x3f1c, 0x3f1d, 0x3f1e,
- 0x3f1f, 0x3f20, 0x3f21, 0x3f22, 0x3f23, 0x3f24, 0x3f25, 0x3f26,
- 0x3f27, 0x3f28, 0x3f29, 0x3f2a, 0x3f2b, 0x3f2c, 0x3f2d, 0x3f2e,
- 0x3f2f, 0x3f30, 0x3f31, 0x3f32, 0x3f33, 0x3f34, 0x3f35, 0x3f36,
- 0x3f37, 0x3f38, 0x3f39, 0x3f3a, 0x3f3b, 0x3f3c, 0x3f3d, 0x3f3e,
- 0x3f3f, 0x0f80, 0x0f81, 0x0f82, 0x0f83, 0x0f84, 0x0f85, 0x0f86,
- 0x0f87, 0x0f88, 0x0f89, 0x0f8a, 0x0f8b, 0x0f8c, 0x0f8d, 0x0f8e,
- 0x0f8f, 0x0f90, 0x0f91, 0x0f92, 0x0f93, 0x0f94, 0x0f95, 0x0f96,
- 0x0f97, 0x0f98, 0x0f99, 0x0f9a, 0x0f9b, 0x0f9c, 0x0f9d, 0x0f9e,
- 0x0f9f, 0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6,
- 0x03c7, 0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce,
- 0x03cf, 0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6,
- 0x00e7, 0x0030, 0x0031, 0x0032, 0x0033, 0x0008, 0x0009, 0x0002,
- 0x0000, 0x0003, 0x000a, 0x000b, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
- 0x03d0, 0x03d1, 0x03d2, 0x03d3, 0x03d4, 0x03d5, 0x03d6, 0x03d7,
- 0x03d8, 0x03d9, 0x03da, 0x03db, 0x03dc, 0x03dd, 0x03de, 0x03df,
- 0x0fa0, 0x0fa1, 0x0fa2, 0x0fa3, 0x0fa4, 0x0fa5, 0x0fa6, 0x0fa7,
- 0x0fa8, 0x0fa9, 0x0faa, 0x0fab, 0x0fac, 0x0fad, 0x0fae, 0x0faf,
- 0x0fb0, 0x0fb1, 0x0fb2, 0x0fb3, 0x0fb4, 0x0fb5, 0x0fb6, 0x0fb7,
- 0x0fb8, 0x0fb9, 0x0fba, 0x0fbb, 0x0fbc, 0x0fbd, 0x0fbe, 0x0fbf,
- 0x3f40, 0x3f41, 0x3f42, 0x3f43, 0x3f44, 0x3f45, 0x3f46, 0x3f47,
- 0x3f48, 0x3f49, 0x3f4a, 0x3f4b, 0x3f4c, 0x3f4d, 0x3f4e, 0x3f4f,
- 0x3f50, 0x3f51, 0x3f52, 0x3f53, 0x3f54, 0x3f55, 0x3f56, 0x3f57,
- 0x3f58, 0x3f59, 0x3f5a, 0x3f5b, 0x3f5c, 0x3f5d, 0x3f5e, 0x3f5f,
- 0x3f60, 0x3f61, 0x3f62, 0x3f63, 0x3f64, 0x3f65, 0x3f66, 0x3f67,
- 0x3f68, 0x3f69, 0x3f6a, 0x3f6b, 0x3f6c, 0x3f6d, 0x3f6e, 0x3f6f,
- 0x3f70, 0x3f71, 0x3f72, 0x3f73, 0x3f74, 0x3f75, 0x3f76, 0x3f77,
- 0x3f78, 0x3f79, 0x3f7a, 0x3f7b, 0x3f7c, 0x3f7d, 0x3f7e, 0x3f7f,
-};
-
-static const uint8_t rv_chrom_bits[256] =
-{
- 16, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 8, 8, 8, 8, 8, 8, 8,
- 8, 6, 6, 6, 6, 4, 4, 3,
- 2, 3, 4, 4, 6, 6, 6, 6,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
-};
-
-static VLC rv_dc_lum, rv_dc_chrom;
-
-int rv_decode_dc(MpegEncContext *s, int n)
-{
- int code;
-
- if (n < 4) {
- code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2);
- if (code < 0) {
- /* XXX: I don't understand why they use LONGER codes than
- necessary. The following code would be completely useless
- if they had thought about it !!! */
- code = get_bits(&s->gb, 7);
- if (code == 0x7c) {
- code = (int8_t)(get_bits(&s->gb, 7) + 1);
- } else if (code == 0x7d) {
- code = -128 + get_bits(&s->gb, 7);
- } else if (code == 0x7e) {
- if (get_bits(&s->gb, 1) == 0)
- code = (int8_t)(get_bits(&s->gb, 8) + 1);
- else
- code = (int8_t)(get_bits(&s->gb, 8));
- } else if (code == 0x7f) {
- get_bits(&s->gb, 11);
- code = 1;
- }
- } else {
- code -= 128;
- }
- } else {
- code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2);
- /* same remark */
- if (code < 0) {
- code = get_bits(&s->gb, 9);
- if (code == 0x1fc) {
- code = (int8_t)(get_bits(&s->gb, 7) + 1);
- } else if (code == 0x1fd) {
- code = -128 + get_bits(&s->gb, 7);
- } else if (code == 0x1fe) {
- get_bits(&s->gb, 9);
- code = 1;
- } else {
- fprintf(stderr, "chroma dc error\n");
- return 0xffff;
- }
- } else {
- code -= 128;
- }
- }
- return -code;
-}
-
-#ifdef CONFIG_ENCODERS
-
-/* write RV 1.0 compatible frame header */
-void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
-{
- int full_frame= 0;
-
- align_put_bits(&s->pb);
-
- put_bits(&s->pb, 1, 1); /* marker */
-
- put_bits(&s->pb, 1, (s->pict_type == P_TYPE));
-
- put_bits(&s->pb, 1, 0); /* not PB frame */
-
- put_bits(&s->pb, 5, s->qscale);
-
- if (s->pict_type == I_TYPE) {
- /* specific MPEG like DC coding not used */
- }
- /* if multiple packets per frame are sent, the position at which
- to display the macro blocks is coded here */
- if(!full_frame){
- put_bits(&s->pb, 6, 0); /* mb_x */
- put_bits(&s->pb, 6, 0); /* mb_y */
- put_bits(&s->pb, 12, s->mb_width * s->mb_height);
- }
-
- put_bits(&s->pb, 3, 0); /* ignored */
-}
-
-static int get_num(GetBitContext *gb)
-{
- int n, n1;
-
- n = get_bits(gb, 16);
- if (n >= 0x4000) {
- return n - 0x4000;
- } else {
- n1 = get_bits(gb, 16);
- return (n << 16) | n1;
- }
-}
-
-#endif //CONFIG_ENCODERS
-
-/* read RV 1.0 compatible frame header */
-static int rv10_decode_picture_header(MpegEncContext *s)
-{
- int mb_count, pb_frame, marker, full_frame, unk;
-
- full_frame= s->avctx->slice_count==1;
-//printf("ff:%d\n", full_frame);
- marker = get_bits(&s->gb, 1);
-
- if (get_bits(&s->gb, 1))
- s->pict_type = P_TYPE;
- else
- s->pict_type = I_TYPE;
-//printf("h:%X ver:%d\n",h,s->rv10_version);
- if(!marker) printf("marker missing\n");
- pb_frame = get_bits(&s->gb, 1);
-
-#ifdef DEBUG
- printf("pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
-#endif
-
- if (pb_frame){
- fprintf(stderr, "pb frame not supported\n");
- return -1;
- }
-
- s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- fprintf(stderr, "error, qscale:0\n");
- return -1;
- }
-
- if (s->pict_type == I_TYPE) {
- if (s->rv10_version == 3) {
- /* specific MPEG like DC coding not used */
- s->last_dc[0] = get_bits(&s->gb, 8);
- s->last_dc[1] = get_bits(&s->gb, 8);
- s->last_dc[2] = get_bits(&s->gb, 8);
-#ifdef DEBUG
- printf("DC:%d %d %d\n",
- s->last_dc[0],
- s->last_dc[1],
- s->last_dc[2]);
-#endif
- }
- }
- /* if multiple packets per frame are sent, the position at which
- to display the macro blocks is coded here */
- if ((!full_frame) || show_bits(&s->gb, 12)==0) {
- s->mb_x = get_bits(&s->gb, 6); /* mb_x */
- s->mb_y = get_bits(&s->gb, 6); /* mb_y */
- mb_count = get_bits(&s->gb, 12);
- } else {
- s->mb_x = 0;
- s->mb_y = 0;
- mb_count = s->mb_width * s->mb_height;
- }
- unk= get_bits(&s->gb, 3); /* ignored */
-//printf("%d\n", unk);
- s->f_code = 1;
- s->unrestricted_mv = 1;
-
- return mb_count;
-}
-
-static int rv10_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- static int done=0;
-
- s->avctx= avctx;
- s->out_format = FMT_H263;
-
- s->width = avctx->width;
- s->height = avctx->height;
-
- s->h263_rv10 = 1;
- switch(avctx->sub_id){
- case 0x10000000:
- s->rv10_version= 0;
- s->h263_long_vectors=0;
- break;
- case 0x10003000:
- s->rv10_version= 3;
- s->h263_long_vectors=1;
- break;
- case 0x10003001:
- s->rv10_version= 3;
- s->h263_long_vectors=0;
- break;
- default:
- fprintf(stderr, "unknown header %X\n", avctx->sub_id);
- }
-//printf("ver:%X\n", avctx->sub_id);
- s->flags= avctx->flags;
-
- if (MPV_common_init(s) < 0)
- return -1;
-
- h263_decode_init_vlc(s);
-
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
- s->progressive_sequence=1;
-
- /* init rv vlc */
- if (!done) {
- init_vlc(&rv_dc_lum, DC_VLC_BITS, 256,
- rv_lum_bits, 1, 1,
- rv_lum_code, 2, 2);
- init_vlc(&rv_dc_chrom, DC_VLC_BITS, 256,
- rv_chrom_bits, 1, 1,
- rv_chrom_code, 2, 2);
- done = 1;
- }
-
- avctx->pix_fmt = PIX_FMT_YUV420P;
-
- return 0;
-}
-
-static int rv10_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-
-static int rv10_decode_packet(AVCodecContext *avctx,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int i, mb_count, mb_pos, left;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- mb_count = rv10_decode_picture_header(s);
- if (mb_count < 0) {
- fprintf(stderr, "HEADER ERROR\n");
- return -1;
- }
-
- if (s->mb_x >= s->mb_width ||
- s->mb_y >= s->mb_height) {
- fprintf(stderr, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- mb_pos = s->mb_y * s->mb_width + s->mb_x;
- left = s->mb_width * s->mb_height - mb_pos;
- if (mb_count > left) {
- fprintf(stderr, "COUNT ERROR\n");
- return -1;
- }
-
- if (s->mb_x == 0 && s->mb_y == 0) {
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
- }
-
-#ifdef DEBUG
- printf("qscale=%d\n", s->qscale);
-#endif
-
- /* default quantization values */
- s->y_dc_scale = 8;
- s->c_dc_scale = 8;
- s->rv10_first_dc_coded[0] = 0;
- s->rv10_first_dc_coded[1] = 0;
- s->rv10_first_dc_coded[2] = 0;
-
- if(s->mb_y==0) s->first_slice_line=1;
-
- s->block_wrap[0]=
- s->block_wrap[1]=
- s->block_wrap[2]=
- s->block_wrap[3]= s->mb_width*2 + 2;
- s->block_wrap[4]=
- s->block_wrap[5]= s->mb_width + 2;
- ff_init_block_index(s);
- /* decode each macroblock */
- for(i=0;i<mb_count;i++) {
- ff_update_block_index(s);
-#ifdef DEBUG
- printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
-#endif
-
- s->dsp.clear_blocks(s->block[0]);
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- if (ff_h263_decode_mb(s, s->block) == SLICE_ERROR) {
- fprintf(stderr, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- ff_h263_update_motion_val(s);
- MPV_decode_mb(s, s->block);
- if (++s->mb_x == s->mb_width) {
- s->mb_x = 0;
- s->mb_y++;
- ff_init_block_index(s);
- s->first_slice_line=0;
- }
- }
-
- return buf_size;
-}
-
-static int rv10_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s = avctx->priv_data;
- int i;
- AVFrame *pict = data;
-
-#ifdef DEBUG
- printf("*****frame %d size=%d\n", avctx->frame_number, buf_size);
-#endif
-
- /* no supplementary picture */
- if (buf_size == 0) {
- *data_size = 0;
- return 0;
- }
-
- if(avctx->slice_count){
- for(i=0; i<avctx->slice_count; i++){
- int offset= avctx->slice_offset[i];
- int size;
-
- if(i+1 == avctx->slice_count)
- size= buf_size - offset;
- else
- size= avctx->slice_offset[i+1] - offset;
-
- if( rv10_decode_packet(avctx, buf+offset, size) < 0 )
- return -1;
- }
- }else{
- if( rv10_decode_packet(avctx, buf, buf_size) < 0 )
- return -1;
- }
-
- if(s->mb_y>=s->mb_height){
- MPV_frame_end(s);
-
- *pict= *(AVFrame*)&s->current_picture;
-
- *data_size = sizeof(AVFrame);
- }else{
- *data_size = 0;
- }
-
- return buf_size;
-}
-
-AVCodec rv10_decoder = {
- "rv10",
- CODEC_TYPE_VIDEO,
- CODEC_ID_RV10,
- sizeof(MpegEncContext),
- rv10_decode_init,
- NULL,
- rv10_decode_end,
- rv10_decode_frame,
- CODEC_CAP_DR1
-};
+++ /dev/null
-/*
- * Simple IDCT
- *
- * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file simple_idct.c
- * simpleidct in C.
- */
-
-/*
- based upon some outcommented c code from mpeg2dec (idct_mmx.c
- written by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>)
- */
-#include "avcodec.h"
-#include "dsputil.h"
-#include "simple_idct.h"
-
-#if 0
-#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */
-#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */
-#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */
-#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */
-#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */
-#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */
-#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */
-#define ROW_SHIFT 8
-#define COL_SHIFT 17
-#else
-#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
-#define ROW_SHIFT 11
-#define COL_SHIFT 20 // 6
-#endif
-
-#if defined(ARCH_POWERPC_405)
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MAC16(rt, ra, rb) \
- asm ("maclhw %0, %2, %3" : "=r" (rt) : "0" (rt), "r" (ra), "r" (rb));
-
-/* signed 16x16 -> 32 multiply */
-#define MUL16(rt, ra, rb) \
- asm ("mullhw %0, %1, %2" : "=r" (rt) : "r" (ra), "r" (rb));
-
-#else
-
-/* signed 16x16 -> 32 multiply add accumulate */
-#define MAC16(rt, ra, rb) rt += (ra) * (rb)
-
-/* signed 16x16 -> 32 multiply */
-#define MUL16(rt, ra, rb) rt = (ra) * (rb)
-
-#endif
-
-static inline void idctRowCondDC (DCTELEM * row)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-#ifdef FAST_64BIT
- uint64_t temp;
-#else
- uint32_t temp;
-#endif
-
-#ifdef FAST_64BIT
-#ifdef WORDS_BIGENDIAN
-#define ROW0_MASK 0xffff000000000000LL
-#else
-#define ROW0_MASK 0xffffLL
-#endif
- if(sizeof(DCTELEM)==2){
- if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) |
- ((uint64_t *)row)[1]) == 0) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- temp += temp << 32;
- ((uint64_t *)row)[0] = temp;
- ((uint64_t *)row)[1] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#else
- if(sizeof(DCTELEM)==2){
- if (!(((uint32_t*)row)[1] |
- ((uint32_t*)row)[2] |
- ((uint32_t*)row)[3] |
- row[1])) {
- temp = (row[0] << 3) & 0xffff;
- temp += temp << 16;
- ((uint32_t*)row)[0]=((uint32_t*)row)[1] =
- ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp;
- return;
- }
- }else{
- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) {
- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3;
- return;
- }
- }
-#endif
-
- a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- /* no need to optimize : gcc does it */
- a0 += W2 * row[2];
- a1 += W6 * row[2];
- a2 -= W6 * row[2];
- a3 -= W2 * row[2];
-
- MUL16(b0, W1, row[1]);
- MAC16(b0, W3, row[3]);
- MUL16(b1, W3, row[1]);
- MAC16(b1, -W7, row[3]);
- MUL16(b2, W5, row[1]);
- MAC16(b2, -W1, row[3]);
- MUL16(b3, W7, row[1]);
- MAC16(b3, -W5, row[3]);
-
-#ifdef FAST_64BIT
- temp = ((uint64_t*)row)[1];
-#else
- temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3];
-#endif
- if (temp != 0) {
- a0 += W4*row[4] + W6*row[6];
- a1 += - W4*row[4] - W2*row[6];
- a2 += - W4*row[4] + W2*row[6];
- a3 += W4*row[4] - W6*row[6];
-
- MAC16(b0, W5, row[5]);
- MAC16(b0, W7, row[7]);
-
- MAC16(b1, -W1, row[5]);
- MAC16(b1, -W5, row[7]);
-
- MAC16(b2, W7, row[5]);
- MAC16(b2, W3, row[7]);
-
- MAC16(b3, W3, row[5]);
- MAC16(b3, -W1, row[7]);
- }
-
- row[0] = (a0 + b0) >> ROW_SHIFT;
- row[7] = (a0 - b0) >> ROW_SHIFT;
- row[1] = (a1 + b1) >> ROW_SHIFT;
- row[6] = (a1 - b1) >> ROW_SHIFT;
- row[2] = (a2 + b2) >> ROW_SHIFT;
- row[5] = (a2 - b2) >> ROW_SHIFT;
- row[3] = (a3 + b3) >> ROW_SHIFT;
- row[4] = (a3 - b3) >> ROW_SHIFT;
-}
-
-static inline void idctSparseColPut (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[(a0 + b0) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 + b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 + b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 + b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a3 - b3) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a2 - b2) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a1 - b1) >> COL_SHIFT];
- dest += line_size;
- dest[0] = cm[(a0 - b0) >> COL_SHIFT];
-}
-
-static inline void idctSparseColAdd (uint8_t *dest, int line_size,
- DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)];
-}
-
-static inline void idctSparseCol (DCTELEM * col)
-{
- int a0, a1, a2, a3, b0, b1, b2, b3;
-
- /* XXX: I did that only to give same values as previous code */
- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4));
- a1 = a0;
- a2 = a0;
- a3 = a0;
-
- a0 += + W2*col[8*2];
- a1 += + W6*col[8*2];
- a2 += - W6*col[8*2];
- a3 += - W2*col[8*2];
-
- MUL16(b0, W1, col[8*1]);
- MUL16(b1, W3, col[8*1]);
- MUL16(b2, W5, col[8*1]);
- MUL16(b3, W7, col[8*1]);
-
- MAC16(b0, + W3, col[8*3]);
- MAC16(b1, - W7, col[8*3]);
- MAC16(b2, - W1, col[8*3]);
- MAC16(b3, - W5, col[8*3]);
-
- if(col[8*4]){
- a0 += + W4*col[8*4];
- a1 += - W4*col[8*4];
- a2 += - W4*col[8*4];
- a3 += + W4*col[8*4];
- }
-
- if (col[8*5]) {
- MAC16(b0, + W5, col[8*5]);
- MAC16(b1, - W1, col[8*5]);
- MAC16(b2, + W7, col[8*5]);
- MAC16(b3, + W3, col[8*5]);
- }
-
- if(col[8*6]){
- a0 += + W6*col[8*6];
- a1 += - W2*col[8*6];
- a2 += + W2*col[8*6];
- a3 += - W6*col[8*6];
- }
-
- if (col[8*7]) {
- MAC16(b0, + W7, col[8*7]);
- MAC16(b1, - W5, col[8*7]);
- MAC16(b2, + W3, col[8*7]);
- MAC16(b3, - W1, col[8*7]);
- }
-
- col[0 ] = ((a0 + b0) >> COL_SHIFT);
- col[8 ] = ((a1 + b1) >> COL_SHIFT);
- col[16] = ((a2 + b2) >> COL_SHIFT);
- col[24] = ((a3 + b3) >> COL_SHIFT);
- col[32] = ((a3 - b3) >> COL_SHIFT);
- col[40] = ((a2 - b2) >> COL_SHIFT);
- col[48] = ((a1 - b1) >> COL_SHIFT);
- col[56] = ((a0 - b0) >> COL_SHIFT);
-}
-
-void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColPut(dest + i, line_size, block + i);
-}
-
-void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseColAdd(dest + i, line_size, block + i);
-}
-
-void simple_idct(DCTELEM *block)
-{
- int i;
- for(i=0; i<8; i++)
- idctRowCondDC(block + i*8);
-
- for(i=0; i<8; i++)
- idctSparseCol(block + i);
-}
-
-/* 2x4x8 idct */
-
-#define CN_SHIFT 12
-#define C_FIX(x) ((int)((x) * (1 << CN_SHIFT) + 0.5))
-#define C1 C_FIX(0.6532814824)
-#define C2 C_FIX(0.2705980501)
-
-/* row idct is multiple by 16 * sqrt(2.0), col idct4 is normalized,
- and the butterfly must be multiplied by 0.5 * sqrt(2.0) */
-#define C_SHIFT (4+1+12)
-
-static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- const uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- a0 = col[8*0];
- a1 = col[8*2];
- a2 = col[8*4];
- a3 = col[8*6];
- c0 = ((a0 + a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
- c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1));
- c1 = a1 * C1 + a3 * C2;
- c3 = a1 * C2 - a3 * C1;
- dest[0] = cm[(c0 + c1) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c2 + c3) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c2 - c3) >> C_SHIFT];
- dest += line_size;
- dest[0] = cm[(c0 - c1) >> C_SHIFT];
-}
-
-#define BF(k) \
-{\
- int a0, a1;\
- a0 = ptr[k];\
- a1 = ptr[8 + k];\
- ptr[k] = a0 + a1;\
- ptr[8 + k] = a0 - a1;\
-}
-
-/* only used by DV codec. The input must be interlaced. 128 is added
- to the pixels before clamping to avoid systematic error
- (1024*sqrt(2)) offset would be needed otherwise. */
-/* XXX: I think a 1.0/sqrt(2) normalization should be needed to
- compensate the extra butterfly stage - I don't have the full DV
- specification */
-void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
- DCTELEM *ptr;
-
- /* butterfly */
- ptr = block;
- for(i=0;i<4;i++) {
- BF(0);
- BF(1);
- BF(2);
- BF(3);
- BF(4);
- BF(5);
- BF(6);
- BF(7);
- ptr += 2 * 8;
- }
-
- /* IDCT8 on each line */
- for(i=0; i<8; i++) {
- idctRowCondDC(block + i*8);
- }
-
- /* IDCT4 and store */
- for(i=0;i<8;i++) {
- idct4col(dest + i, 2 * line_size, block + i);
- idct4col(dest + line_size + i, 2 * line_size, block + 8 + i);
- }
-}
-
-/* 8x4 & 4x8 WMV2 IDCT */
-#undef CN_SHIFT
-#undef C_SHIFT
-#undef C_FIX
-#undef C1
-#undef C2
-#define CN_SHIFT 12
-#define C_FIX(x) ((int)((x) * 1.414213562 * (1 << CN_SHIFT) + 0.5))
-#define C1 C_FIX(0.6532814824)
-#define C2 C_FIX(0.2705980501)
-#define C3 C_FIX(0.5)
-#define C_SHIFT (4+1+12)
-static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- const uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- a0 = col[8*0];
- a1 = col[8*1];
- a2 = col[8*2];
- a3 = col[8*3];
- c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
- c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
- c1 = a1 * C1 + a3 * C2;
- c3 = a1 * C2 - a3 * C1;
- dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)];
- dest += line_size;
- dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)];
-}
-
-#define RN_SHIFT 15
-#define R_FIX(x) ((int)((x) * 1.414213562 * (1 << RN_SHIFT) + 0.5))
-#define R1 R_FIX(0.6532814824)
-#define R2 R_FIX(0.2705980501)
-#define R3 R_FIX(0.5)
-#define R_SHIFT 11
-static inline void idct4row(DCTELEM *row)
-{
- int c0, c1, c2, c3, a0, a1, a2, a3;
- //const uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- a0 = row[0];
- a1 = row[1];
- a2 = row[2];
- a3 = row[3];
- c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
- c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
- c1 = a1 * R1 + a3 * R2;
- c3 = a1 * R2 - a3 * R1;
- row[0]= (c0 + c1) >> R_SHIFT;
- row[1]= (c2 + c3) >> R_SHIFT;
- row[2]= (c2 - c3) >> R_SHIFT;
- row[3]= (c0 - c1) >> R_SHIFT;
-}
-
-void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
-
- /* IDCT8 on each line */
- for(i=0; i<4; i++) {
- idctRowCondDC(block + i*8);
- }
-
- /* IDCT4 and store */
- for(i=0;i<8;i++) {
- idct4col_add(dest + i, line_size, block + i);
- }
-}
-
-void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block)
-{
- int i;
-
- /* IDCT4 on each line */
- for(i=0; i<8; i++) {
- idct4row(block + i*8);
- }
-
- /* IDCT8 and store */
- for(i=0; i<4; i++){
- idctSparseColAdd(dest + i, line_size, block + i);
- }
-}
-
+++ /dev/null
-/*
- * Simple IDCT
- *
- * Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file simple_idct.h
- * simple idct header.
- */
-
-void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block);
-void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block);
-void ff_simple_idct_mmx(int16_t *block);
-void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
-void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
-void simple_idct(DCTELEM *block);
-
-void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block);
-
-void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block);
-void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block);
+++ /dev/null
-/*
- *
- * Copyright (C) 2002 the xine project
- * Copyright (C) 2002 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Ported to mplayer by Arpi <arpi@thot.banki.hu>
- * Ported to libavcodec by Nick Kurshev <nickols_k@mail.ru>
- *
- */
-
-/**
- * @file svq1.c
- * Sorenson Vector Quantizer #1 (SVQ1) video decoder.
- */
-
-
-//#define DEBUG_SVQ1
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "bswap.h"
-
-static VLC svq1_block_type;
-static VLC svq1_motion_component;
-static VLC svq1_intra_multistage[6];
-static VLC svq1_inter_multistage[6];
-static VLC svq1_intra_mean;
-static VLC svq1_inter_mean;
-
-#define MEDIAN(a,b,c) (((a < b) != (b >= c)) ? b : (((a < c) != (c > b)) ? c : a))
-
-#define SVQ1_BLOCK_SKIP 0
-#define SVQ1_BLOCK_INTER 1
-#define SVQ1_BLOCK_INTER_4V 2
-#define SVQ1_BLOCK_INTRA 3
-
-/* motion vector (prediction) */
-typedef struct svq1_pmv_s {
- int x;
- int y;
-} svq1_pmv_t;
-
-#include "svq1_cb.h"
-#include "svq1_vlc.h"
-
-static const uint16_t checksum_table[256] = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
- 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
- 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
- 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
- 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
- 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
- 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
- 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
- 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
- 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
- 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
- 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
- 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
- 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
- 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
- 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
- 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
- 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
- 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
- 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
- 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
- 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
- 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
-};
-
-static const uint8_t string_table[256] = {
- 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
- 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
- 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
- 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
- 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
- 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
- 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
- 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
- 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
- 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
- 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
- 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
- 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
- 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
- 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
- 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
- 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
- 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
- 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
- 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
- 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
- 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
- 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
- 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
- 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
- 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
- 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
- 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
- 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
- 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
- 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
- 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
-};
-
-#define SVQ1_PROCESS_VECTOR()\
- for (; level > 0; i++) {\
- /* process next depth */\
- if (i == m) {\
- m = n;\
- if (--level == 0)\
- break;\
- }\
- /* divide block if next bit set */\
- if (get_bits (bitbuf, 1) == 0)\
- break;\
- /* add child nodes */\
- list[n++] = list[i];\
- list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\
- }
-
-#define SVQ1_ADD_CODEBOOK()\
- /* add codebook entries to vector */\
- for (j=0; j < stages; j++) {\
- n3 = codebook[entries[j]] ^ 0x80808080;\
- n1 += ((n3 & 0xFF00FF00) >> 8);\
- n2 += (n3 & 0x00FF00FF);\
- }\
-\
- /* clip to [0..255] */\
- if (n1 & 0xFF00FF00) {\
- n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n1 += 0x7F007F00;\
- n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n1 &= (n3 & 0x00FF00FF);\
- }\
-\
- if (n2 & 0xFF00FF00) {\
- n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n2 += 0x7F007F00;\
- n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\
- n2 &= (n3 & 0x00FF00FF);\
- }
-
-#define SVQ1_DO_CODEBOOK_INTRA()\
- for (y=0; y < height; y++) {\
- for (x=0; x < (width / 4); x++, codebook++) {\
- n1 = n4;\
- n2 = n4;\
- SVQ1_ADD_CODEBOOK()\
- /* store result */\
- dst[x] = (n1 << 8) | n2;\
- }\
- dst += (pitch / 4);\
- }
-
-#define SVQ1_DO_CODEBOOK_NONINTRA()\
- for (y=0; y < height; y++) {\
- for (x=0; x < (width / 4); x++, codebook++) {\
- n3 = dst[x];\
- /* add mean value to vector */\
- n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\
- n2 = (n3 & 0x00FF00FF) + n4;\
- SVQ1_ADD_CODEBOOK()\
- /* store result */\
- dst[x] = (n1 << 8) | n2;\
- }\
- dst += (pitch / 4);\
- }
-
-#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\
- codebook = (const uint32_t *) cbook[level];\
- bit_cache = get_bits (bitbuf, 4*stages);\
- /* calculate codebook entries for this vector */\
- for (j=0; j < stages; j++) {\
- entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\
- }\
- mean -= (stages * 128);\
- n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
-
-static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
- uint32_t bit_cache;
- uint8_t *list[63];
- uint32_t *dst;
- const uint32_t *codebook;
- int entries[6];
- int i, j, m, n;
- int mean, stages;
- unsigned x, y, width, height, level;
- uint32_t n1, n2, n3, n4;
-
- /* initialize list for breadth first processing of vectors */
- list[0] = pixels;
-
- /* recursively process vector */
- for (i=0, m=1, n=1, level=5; i < n; i++) {
- SVQ1_PROCESS_VECTOR();
-
- /* destination address and vector size */
- dst = (uint32_t *) list[i];
- width = 1 << ((4 + level) /2);
- height = 1 << ((3 + level) /2);
-
- /* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
-
- if (stages == -1) {
- for (y=0; y < height; y++) {
- memset (&dst[y*(pitch / 4)], 0, width);
- }
- continue; /* skip vector */
- }
-
- if ((stages > 0) && (level >= 4)) {
-#ifdef DEBUG_SVQ1
- printf("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level);
-#endif
- return -1; /* invalid vector */
- }
-
- mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
-
- if (stages == 0) {
- for (y=0; y < height; y++) {
- memset (&dst[y*(pitch / 4)], mean, width);
- }
- } else {
- SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
- SVQ1_DO_CODEBOOK_INTRA()
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) {
- uint32_t bit_cache;
- uint8_t *list[63];
- uint32_t *dst;
- const uint32_t *codebook;
- int entries[6];
- int i, j, m, n;
- int mean, stages;
- int x, y, width, height, level;
- uint32_t n1, n2, n3, n4;
-
- /* initialize list for breadth first processing of vectors */
- list[0] = pixels;
-
- /* recursively process vector */
- for (i=0, m=1, n=1, level=5; i < n; i++) {
- SVQ1_PROCESS_VECTOR();
-
- /* destination address and vector size */
- dst = (uint32_t *) list[i];
- width = 1 << ((4 + level) /2);
- height = 1 << ((3 + level) /2);
-
- /* get number of stages (-1 skips vector, 0 for mean only) */
- stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
-
- if (stages == -1) continue; /* skip vector */
-
- if ((stages > 0) && (level >= 4)) {
-#ifdef DEBUG_SVQ1
- printf("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level);
-#endif
- return -1; /* invalid vector */
- }
-
- mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
-
- SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
- SVQ1_DO_CODEBOOK_NONINTRA()
- }
- return 0;
-}
-
-static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) {
- int diff;
- int i;
-
- for (i=0; i < 2; i++) {
-
- /* get motion code */
- diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2) - 32;
-
- /* add median of motion vector predictors and clip result */
- if (i == 1)
- mv->y = ((diff + MEDIAN(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
- else
- mv->x = ((diff + MEDIAN(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
- }
-
- return 0;
-}
-
-static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- int i;
-
- src = &previous[x + y*pitch];
- dst = current;
-
- for (i=0; i < 16; i++) {
- memcpy (dst, src, 16);
- src += pitch;
- dst += pitch;
- }
-}
-
-static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion, int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- svq1_pmv_t mv;
- svq1_pmv_t *pmv[3];
- int result;
-
- /* predict and decode motion vector */
- pmv[0] = &motion[0];
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 2];
- pmv[2] = &motion[(x / 8) + 4];
- }
-
- result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
-
- if (result != 0)
- return result;
-
- motion[0].x =
- motion[(x / 8) + 2].x =
- motion[(x / 8) + 3].x = mv.x;
- motion[0].y =
- motion[(x / 8) + 2].y =
- motion[(x / 8) + 3].y = mv.y;
-
- if(y + (mv.y >> 1)<0)
- mv.y= 0;
- if(x + (mv.x >> 1)<0)
- mv.x= 0;
-
-#if 0
- int w= (s->width+15)&~15;
- int h= (s->height+15)&~15;
- if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h)
- printf("%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
-#endif
-
- src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
- dst = current;
-
- s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
-
- return 0;
-}
-
-static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion,int x, int y) {
- uint8_t *src;
- uint8_t *dst;
- svq1_pmv_t mv;
- svq1_pmv_t *pmv[4];
- int i, result;
-
- /* predict and decode motion vector (0) */
- pmv[0] = &motion[0];
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 2];
- pmv[2] = &motion[(x / 8) + 4];
- }
-
- result = svq1_decode_motion_vector (bitbuf, &mv, pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (1) */
- pmv[0] = &mv;
- if (y == 0) {
- pmv[1] =
- pmv[2] = pmv[0];
- }
- else {
- pmv[1] = &motion[(x / 8) + 3];
- }
- result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (2) */
- pmv[1] = &motion[0];
- pmv[2] = &motion[(x / 8) + 1];
-
- result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv);
-
- if (result != 0)
- return result;
-
- /* predict and decode motion vector (3) */
- pmv[2] = &motion[(x / 8) + 2];
- pmv[3] = &motion[(x / 8) + 3];
-
- result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv);
-
- if (result != 0)
- return result;
-
- /* form predictions */
- for (i=0; i < 4; i++) {
- int mvx= pmv[i]->x + (i&1)*16;
- int mvy= pmv[i]->y + (i>>1)*16;
-
- ///XXX /FIXME cliping or padding?
- if(y + (mvy >> 1)<0)
- mvy= 0;
- if(x + (mvx >> 1)<0)
- mvx= 0;
-
-#if 0
- int w= (s->width+15)&~15;
- int h= (s->height+15)&~15;
- if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h)
- printf("%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1));
-#endif
- src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
- dst = current;
-
- s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
-
- /* select next block */
- if (i & 1) {
- current += 8*(pitch - 1);
- } else {
- current += 8;
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf,
- uint8_t *current, uint8_t *previous, int pitch,
- svq1_pmv_t *motion, int x, int y) {
- uint32_t block_type;
- int result = 0;
-
- /* get block type */
- block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2);
-
- /* reset motion vectors */
- if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
- motion[0].x =
- motion[0].y =
- motion[(x / 8) + 2].x =
- motion[(x / 8) + 2].y =
- motion[(x / 8) + 3].x =
- motion[(x / 8) + 3].y = 0;
- }
-
- switch (block_type) {
- case SVQ1_BLOCK_SKIP:
- svq1_skip_block (current, previous, pitch, x, y);
- break;
-
- case SVQ1_BLOCK_INTER:
- result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- printf("Error in svq1_motion_inter_block %i\n",result);
-#endif
- break;
- }
- result = svq1_decode_block_non_intra (bitbuf, current, pitch);
- break;
-
- case SVQ1_BLOCK_INTER_4V:
- result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- printf("Error in svq1_motion_inter_4v_block %i\n",result);
-#endif
- break;
- }
- result = svq1_decode_block_non_intra (bitbuf, current, pitch);
- break;
-
- case SVQ1_BLOCK_INTRA:
- result = svq1_decode_block_intra (bitbuf, current, pitch);
- break;
- }
-
- return result;
-}
-
-/* standard video sizes */
-static struct { int width; int height; } svq1_frame_size_table[8] = {
- { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 },
- { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 }
-};
-
-static uint16_t svq1_packet_checksum (uint8_t *data, int length, int value) {
- int i;
-
- for (i=0; i < length; i++) {
- value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
- }
-
- return value;
-}
-
-static uint16_t svq1_component_checksum (uint16_t *pixels, int pitch,
- int width, int height, int value) {
- int x, y;
-
- for (y=0; y < height; y++) {
- for (x=0; x < width; x++) {
- value = checksum_table[pixels[x] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
- }
-
- pixels += pitch;
- }
-
- return value;
-}
-
-static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) {
- uint8_t seed;
- int i;
-
- out[0] = get_bits (bitbuf, 8);
-
- seed = string_table[out[0]];
-
- for (i=1; i < out[0]; i++) {
- out[i] = get_bits (bitbuf, 8) ^ seed;
- seed = string_table[out[i] ^ seed];
- }
-}
-
-static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) {
- int frame_size_code;
- int temporal_reference;
-
- temporal_reference = get_bits (bitbuf, 8);
-
- /* frame type */
- s->pict_type= get_bits (bitbuf, 2)+1;
- if(s->pict_type==4)
- return -1;
-
- if (s->pict_type == I_TYPE) {
-
- /* unknown fields */
- if (s->f_code == 0x50 || s->f_code == 0x60) {
- int csum = get_bits (bitbuf, 16);
-
- csum = svq1_packet_checksum ((uint8_t *)bitbuf->buffer, bitbuf->size_in_bits>>3, csum);
-
-// printf ("%s checksum (%02x) for packet data\n",
-// (csum == 0) ? "correct" : "incorrect", csum);
- }
-
- if ((s->f_code ^ 0x10) >= 0x50) {
- char msg[256];
-
- svq1_parse_string (bitbuf, (char *) msg);
-
- printf ("embedded message: \"%s\"\n", (char *) msg);
- }
-
- skip_bits (bitbuf, 2);
- skip_bits (bitbuf, 2);
- skip_bits1 (bitbuf);
-
- /* load frame size */
- frame_size_code = get_bits (bitbuf, 3);
-
- if (frame_size_code == 7) {
- /* load width, height (12 bits each) */
- s->width = get_bits (bitbuf, 12);
- s->height = get_bits (bitbuf, 12);
-
- if (!s->width || !s->height)
- return -1;
- } else {
- /* get width, height from table */
- s->width = svq1_frame_size_table[frame_size_code].width;
- s->height = svq1_frame_size_table[frame_size_code].height;
- }
- }
-
- /* unknown fields */
- if (get_bits (bitbuf, 1) == 1) {
- skip_bits1 (bitbuf); /* use packet checksum if (1) */
- skip_bits1 (bitbuf); /* component checksums after image data if (1) */
-
- if (get_bits (bitbuf, 2) != 0)
- return -1;
- }
-
- if (get_bits (bitbuf, 1) == 1) {
- skip_bits1 (bitbuf);
- skip_bits (bitbuf, 4);
- skip_bits1 (bitbuf);
- skip_bits (bitbuf, 2);
-
- while (get_bits (bitbuf, 1) == 1) {
- skip_bits (bitbuf, 8);
- }
- }
-
- return 0;
-}
-
-static int svq1_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- MpegEncContext *s=avctx->priv_data;
- uint8_t *current, *previous;
- int result, i, x, y, width, height;
- AVFrame *pict = data;
-
- /* initialize bit buffer */
- init_get_bits(&s->gb,buf,buf_size*8);
-
- /* decode frame header */
- s->f_code = get_bits (&s->gb, 22);
-
- if ((s->f_code & ~0x70) || !(s->f_code & 0x60))
- return -1;
-
- /* swap some header bytes (why?) */
- if (s->f_code != 0x20) {
- uint32_t *src = (uint32_t *) (buf + 4);
-
- for (i=0; i < 4; i++) {
- src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
- }
- }
-
- result = svq1_decode_frame_header (&s->gb, s);
-
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- printf("Error in svq1_decode_frame_header %i\n",result);
-#endif
- return result;
- }
-
- //FIXME this avoids some confusion for "B frames" without 2 references
- //this should be removed after libavcodec can handle more flaxible picture types & ordering
- if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size;
-
- if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size;
-
- if(MPV_frame_start(s, avctx) < 0)
- return -1;
-
- /* decode y, u and v components */
- for (i=0; i < 3; i++) {
- int linesize;
- if (i == 0) {
- width = (s->width+15)&~15;
- height = (s->height+15)&~15;
- linesize= s->linesize;
- } else {
- if(s->flags&CODEC_FLAG_GRAY) break;
- width = (s->width/4+15)&~15;
- height = (s->height/4+15)&~15;
- linesize= s->uvlinesize;
- }
-
- current = s->current_picture.data[i];
-
- if(s->pict_type==B_TYPE){
- previous = s->next_picture.data[i];
- }else{
- previous = s->last_picture.data[i];
- }
-
- if (s->pict_type == I_TYPE) {
- /* keyframe */
- for (y=0; y < height; y+=16) {
- for (x=0; x < width; x+=16) {
- result = svq1_decode_block_intra (&s->gb, ¤t[x], linesize);
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- printf("Error in svq1_decode_block %i (keyframe)\n",result);
-#endif
- return result;
- }
- }
- current += 16*linesize;
- }
- } else {
- svq1_pmv_t pmv[width/8+3];
- /* delta frame */
- memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t));
-
- for (y=0; y < height; y+=16) {
- for (x=0; x < width; x+=16) {
- result = svq1_decode_delta_block (s, &s->gb, ¤t[x], previous,
- linesize, pmv, x, y);
- if (result != 0)
- {
-#ifdef DEBUG_SVQ1
- printf("Error in svq1_decode_delta_block %i\n",result);
-#endif
- return result;
- }
- }
-
- pmv[0].x =
- pmv[0].y = 0;
-
- current += 16*linesize;
- }
- }
- }
-
- *pict = *(AVFrame*)&s->current_picture;
-
-
- MPV_frame_end(s);
-
- *data_size=sizeof(AVFrame);
- return buf_size;
-}
-
-static int svq1_decode_init(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
- int i;
-
- s->avctx = avctx;
- s->width = (avctx->width+3)&~3;
- s->height = (avctx->height+3)&~3;
- s->codec_id= avctx->codec->id;
- avctx->pix_fmt = PIX_FMT_YUV410P;
- avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames
- s->flags= avctx->flags;
- if (MPV_common_init(s) < 0) return -1;
-
- init_vlc(&svq1_block_type, 2, 4,
- &svq1_block_type_vlc[0][1], 2, 1,
- &svq1_block_type_vlc[0][0], 2, 1);
-
- init_vlc(&svq1_motion_component, 7, 65,
- &svq1_motion_component_vlc[0][1], 4, 2,
- &svq1_motion_component_vlc[0][0], 4, 2);
-
- for (i = 0; i < 6; i++) {
- init_vlc(&svq1_intra_multistage[i], 3, 8,
- &svq1_intra_multistage_vlc[i][0][1], 2, 1,
- &svq1_intra_multistage_vlc[i][0][0], 2, 1);
- init_vlc(&svq1_inter_multistage[i], 3, 8,
- &svq1_inter_multistage_vlc[i][0][1], 2, 1,
- &svq1_inter_multistage_vlc[i][0][0], 2, 1);
- }
-
- init_vlc(&svq1_intra_mean, 8, 256,
- &svq1_intra_mean_vlc[0][1], 4, 2,
- &svq1_intra_mean_vlc[0][0], 4, 2);
-
- init_vlc(&svq1_inter_mean, 9, 512,
- &svq1_inter_mean_vlc[0][1], 4, 2,
- &svq1_inter_mean_vlc[0][0], 4, 2);
-
- return 0;
-}
-
-static int svq1_decode_end(AVCodecContext *avctx)
-{
- MpegEncContext *s = avctx->priv_data;
-
- MPV_common_end(s);
- return 0;
-}
-
-AVCodec svq1_decoder = {
- "svq1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SVQ1,
- sizeof(MpegEncContext),
- svq1_decode_init,
- NULL,
- svq1_decode_end,
- svq1_decode_frame,
- CODEC_CAP_DR1,
- .flush= ff_mpeg_flush,
-};
+++ /dev/null
-/*
- *
- * Copyright (C) 2002 the xine project
- * Copyright (C) 2002 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Ported to mplayer by Arpi <arpi@thot.banki.hu>
- * Ported to libavcodec by Nick Kurshev <nickols_k@mail.ru>
- *
- */
-
-/**
- * @file svq1_cb.h
- * svq1 code books.
- */
-
-/* 6x16-entry codebook for inter-coded 4x2 vectors */
-static const int8_t svq1_inter_codebook_4x2[768] = {
- 7, 2, -6, -7, 7, 3, -3, -4, -7, -2, 7, 8, -8, -4, 3, 4,
- 19, 17, 9, 3,-14,-16,-12, -8,-18,-16, -8, -3, 11, 14, 12, 8,
- 7,-16,-10, 20, 7,-17,-10, 20, -6, 18, 8,-21, -7, 18, 9,-20,
- 25, 3,-20,-14, 29, 7,-18,-13,-29, -4, 21, 14,-31, -6, 20, 14,
- -19,-26,-28,-24, 31, 32, 22, 10, 15, 24, 31, 28,-32,-32,-22,-13,
- 2, -8,-23,-26, -9, 3, 27, 35, 3, 11, 21, 21, 8, -4,-27,-34,
- -30,-31, 12, 47,-29,-30, 13, 47, 38, 30,-17,-46, 34, 26,-19,-46,
- -42,-50,-51,-43, 34, 48, 55, 48, 48, 54, 51, 42,-44,-52,-53,-47,
- 4, 5, 0, -6, -2, -2, 0, 1,-11, -6, -1, -2, 1, 8, 9, 1,
- 0, 1, -6, 5, 8, 1,-12, 2, 7,-14, -7, 8, 5, -8, 0, 8,
- 1, 4, 11, 8,-12, -8, 0, -5, -1, 1, 0, 4,-15, -8, 3, 16,
- 17, 8, -4, -6, 9, -4,-13, -8, 2, 6, 1,-18, -1, 11, 11,-12,
- 6, 0, 2, 0, 14, 6, -7,-21, 1, -1,-13,-20, 1, 1, 10, 21,
- -22, -5, 7, 13,-11, -1, 4, 12, -7, 0, 14, 19, -4, 3, -5,-19,
- -26,-14, 10, 15, 18, 4, -6, -2, 25, 19, -5,-18,-20, -7, 4, 2,
- -13, -6, -1, -4, 25, 37, -2,-35, 5, 4, 1, 1,-21,-36, 2, 43,
- 2, -2, -1, 3, 8, -2, -6, -1, -2, -3, 2, 12, -5, -2, -2, -1,
- -3, -1, -1, -5, -1, 7, 8, -2, 2, 7, 5, -3, 1, 1, -3, -8,
- -3, -1, -3, -2, -2, -3, 2, 13, 15, 0,-11, -6, 3, 0, 0, 0,
- -6, -9, -5, -4, 18, 4, 1, 3, 12, 3, 0, 4,-16, -3, 3, -3,
- -17, 3, 18, 2, -1, -3, -1, -1, -6, 16, -8, 0, -9, 14, -7, 0,
- 3,-13, 14, -5, 3,-13, 14, -4, -7, 20, 14,-23, 8, -7, -8, 4,
- 8,-15,-19, 16,-10, 13, 11, -3, 9, -1, 1, 26, 5,-15,-27, 2,
- -20, 7, 16, -4,-40, 9, 31, 1, 26,-12,-30, -7, 40, -2,-19, 4,
- 6, 0, 0, 0, -6, -2, 1, 2, 0, -1, 0, -6, 9, 0, -2, -1,
- -7, 8, 2, -3, -1, 2, -3, 2, 7, -4, -2, 4, 2, 0, 0, -6,
- -3, -2, 9, 2, -2, -1, 0, -4, -3, -3, 0, -3, -6, 2, 10, 4,
- 3, 0,-10, 8, 0, 0, -4, 4, -1, 1, 4, 2, 3, -7, -9, 7,
- 2, 1, -9, -4, -1, 12, 0, 0, 3, -1, 7, -4, 3,-14, 4, 2,
- -12, -9, 1, 11, 2, 5, 1, 0, 3, 1, 0, 2, 0, 8, 6,-19,
- -6,-10, -7, -4, 9, 7, 5, 7, 6, 21, 3, -3,-11, -9, -5, -2,
- -4, -9,-16, -1, -2, -5, 1, 36, 8, 11, 19, 0, 2, 5, -4,-41,
- -1, -1, -2, -1, -2, -2, 1, 6, 0, 4, 1, -8, 1, 1, 1, 0,
- -2, -3, 4, 0, 2, -1, 3, -3, 1, 3, -4, 1, -1, 3, 0, -5,
- 3, 4, 2, 3, -2, -3, -6, -1, -2, -3, -2, 2, -4, 8, 1, 0,
- -7, 4, 2, 6, -7, -1, 1, 0, -2, 2, -4, 1, 8, -6, 2, -1,
- -6, 2, 0, 2, 5, 4, -8, -1, -1,-11, 0, 9, 0, -2, 2, 2,
- 17, -5, -4, -1, -1, -4, -2, -2, 0,-13, 9, -3, -1, 12, -7, 2,
- 0, -2, -5, 2, -7, -5, 20, -3, 7, 7, -1,-30, 3, 5, 8, 1,
- -6, 3, -1, -4, 2, -2,-11, 18, 0, -7, 3, 14, 20, -3,-18, -9,
- 7, -2, 0, -1, -2, 0, 0, -1, -4, -1, 1, 0, -2, 2, 0, 4,
- 1, -3, 2, 1, 3, 1, -5, 1, -3, 0, -1, -2, 7, 1, 0, -3,
- 2, 5, 0, -2, 2, -5, -1, 1, -1, -2, 4, -1, 0, -3, 5, 0,
- 0, 3, -1, -2, -4, 1, 5, -1, -1, 0, -1, 9, -1, -2, -1, -1,
- -2, 5, 5, -1, -2, 2, -3, -2, 1, 2,-11, 1, 2, 1, 3, 2,
- 2,-10, -1, -2, 4, 2, 4, 1, 4, 5, -5, 1, 0, 6,-11, 1,
- 1, 0, 6, 6, 0, 2, 1,-15, 7, 3, 5, 9,-30, 2, 2, 2,
- -34, 1, 9, 2, 5, 8, 8, 2, 7, 2, 6, 6, 2,-27, 1, 4
-};
-
-/* 6x16-entry codebook for inter-coded 4x4 vectors */
-static const int8_t svq1_inter_codebook_4x4[1536] = {
- 4, 0, -6, -7, -4, -8,-13, -9, -8, -8, -1, 6, -2, 5, 22, 27,
- -16, -7, 11, 10,-18, -7, 13, 10,-15, -4, 12, 8, -9, -1, 9, 5,
- -2, 2, 15,-16, -3, 2, 19,-19, -3, 2, 19,-19, -2, 3, 15,-14,
- 17, 22, 22, 16, -6, -7, -5, -2,-12,-16,-16,-12, 1, 1, -1, -3,
- 11,-17, 0, 8, 14,-21, -1, 9, 14,-21, -2, 8, 11,-16, -2, 6,
- 7, -2,-16, 11, 9, -2,-21, 14, 10, -1,-22, 14, 8, -1,-18, 10,
- -10, 16, 3, -9,-13, 20, 4,-11,-14, 21, 4,-10,-11, 16, 3, -8,
- 11, 4, -9, -9, 15, 6,-12,-14, 17, 8,-12,-14, 16, 10, -7,-11,
- 4, 10, 14, 13, -1, 7, 15, 16,-12, -7, 3, 8,-20,-23,-18,-10,
- -10,-18,-26,-25, 4, 1, -6,-11, 13, 15, 11, 3, 12, 15, 13, 8,
- -16,-19,-16,-11, 7, 12, 15, 11, 11, 16, 16, 11, -6, -9,-11,-10,
- 18, 19, 12, 5, 18, 16, 5, -4, 6, 0,-10,-15, -9,-17,-23,-22,
- -10,-14, -1, 21,-11,-17, 0, 29,-11,-16, 1, 30,-10,-14, 0, 23,
- -16,-17,-12, -6,-19,-19,-14, -7, -3, -1, 1, 2, 27, 35, 29, 19,
- -37, -8, 23, 23,-42, -9, 28, 29,-43,-10, 26, 28,-38,-11, 19, 22,
- 32, 16,-16,-33, 39, 20,-18,-37, 38, 19,-19,-38, 32, 15,-17,-34,
- 24, 9, -6, -4, -1,-10, -6, 3, -8, -9, -1, 3, 3, 7, 2, -6,
- -1, -3, -1, 0, -1, 4, 2, -7, -3, 11, 3,-16, 1, 20, 9,-18,
- -3, -8, 6, 12, -5,-10, 7, 13, -6, -9, 5, 7, -5, -5, 2, -1,
- -8, 12, -3, -1,-10, 15, -3, 1,-11, 13, -4, 1,-11, 8, -3, 2,
- 9, 6, -5,-12, 3, 0, -8,-13, -4, -4, -1, -1, -4, 1, 15, 18,
- 9, 13, 14, 12, 4, 3, -1, -2, -2, -5, -8, -5, -7,-11, -9, -4,
- 7, -5, -7, -4, 14, -2, -7, -4, 17, 0, -8, -5, 15, 1, -7, -5,
- -10, -1, 6, 4,-15, -9, 2, 4, 2, -1, -3, 0, 25, 13, -8,-10,
- 7, 11, -3,-16, 7, 11, -3,-15, 6, 7, -2, -9, 4, 2, -3, -5,
- -7, -1, -1, 0, -9, -2, 2, 6,-12, -4, 6, 14,-13, -6, 8, 19,
- -18,-18,-11, -5, -3, 0, 3, 4, 6, 8, 6, 6, 6, 6, 6, 6,
- -5, 3, 13,-10, -6, 1, 15, -9, -6, -3, 15, -6, -6, -6, 10, -3,
- 9, 1, -9, -9, 11, 9, 6, 5, 0, 3, 8, 7,-15,-14, -6, -5,
- -11, -6, 11, 19, -2, -5, -9, -8, 6, 2, -9,-10, 6, 5, 4, 5,
- -7, -3, 8, 15, -1, 3, 10, 15, 5, 5, -1, -2, 4, -2,-21,-25,
- 6, -6, -6, 5, 8, -9, -7, 9, 8,-12, -7, 13, 4,-14, -7, 14,
- -4, -3, 1, 1, -3, -5, -2, -3, 7, 0, -2, -4, 20, 7, -4, -4,
- -3,-20, -6, 10, 6, 0, 0, 1, 5, 8, 5, -1, -3, 0, 0, -2,
- 13, 6, -1, 2, 5, 3, 2, 3, -3, 0, 3, 0,-16, -8, -2, -5,
- -2, -7, -6, 0, -3, -6, -3, 1, -5, -1, 2, -1, -1, 12, 16, 5,
- -7, 1, 9, 8,-10, -2, 5, 3, -6, 2, 7, 3, -4, 0, -1, -7,
- 3, 4, -9,-24, 0, 2, 6, 3, -1, -1, 4, 7, 5, 3, -1, -2,
- 3, 6, -9, 2, 1, 6,-13, 1, 1, 8,-10, 2, 1, 8, -7, 1,
- -3, -3, 2, 22, -2, -3, -5, 12, -2, -3,-10, 2, -3, -1, -4, 2,
- 11, 12, 8, 2, -5, -5, -5, -8, -6, -4, 0, -3, -2, -1, 3, 3,
- 12, -6, -2, -1, 12, -8, -2, -2, 9, -7, 0, -3, 4, -6, 2, -2,
- -19, 1, 12, -3, -4, 4, 5, -4, 6, 1, -2, -1, 4, -4, -2, 7,
- -3, -4, -7, -8, -4, -4, -2, 0, -1, 2, 14, 16, -4, -2, 4, 4,
- -1, 7, 2, -5, -2, 0, -1, 1, 4, -3, -1, 13, 6,-12,-14, 8,
- -1, 5, 4, -5, -2, 5, 3, -9, -2, 7, 4,-12, -1, 7, 4, -9,
- -6, -3, 1, 1, 11, 11, 0, -6, 6, 4, -2, -7,-12,-10, 3, 10,
- -2, -3, -3, -2, 6, 11, 14, 10, -9,-11,-10,-10, 2, 2, 3, 2,
- -7, -5, -7, -1, -1, 2, 0, 7, -1, 1, 0, 9, 3, 4, -5, -1,
- 10, -1,-15, -1, 4, 1, -5, 2, -3, 1, -1, 1, -3, 1, 4, 4,
- 2, -1, 4, 10, 6, 2, -1, 0, 2, 2, -7,-12, -4, 2, 0, -3,
- -1, -4, -1, -8, 3, -1, 2, -9, 4, 0, 5, -5, 2, 0, 8, 3,
- 3, 2, 1, 1, 4, -2, 0, 3, 2, -1, 4, 1, 0, 6, -1,-25,
- -1, -2, -2, -4, -3, 0, -1, -4, -1, -1, -4, 2, 0, -6, 2, 25,
- -11, -1, 5, 0, 7, 0, -2, 2, 10, -1, -3, 4, -5, -5, -2, -1,
- 0, 6, 3, -1, -2, -1, -1, 1, -1, -7,-12, -5, 8, 6, 2, 4,
- 2, 6, -1, -6, 9, 10, -1, -4, 1, 0, -4, 0, 3, -2, -9, -5,
- -4, 3, 4, 0, -4, 3, 3, 0,-11, 0, 3, 2,-11, 3, 7, 2,
- 2, -4, 7, 3, 1, -8, 7, 1, -1,-12, 4, 1, 3, -9, 2, 2,
- 2, -2, -2, 9,-17, -3, 3, 1, -4, 7, 1, -6, 5, 4, -1, 3,
- -1, 2, 0, -4, -7, 8, 12, -1, -2, 5, 4, -5, 3, -5, -8, -2,
- 0, 0, -5, -2, -2, -8, 3, 27, -1, -4, -3, 6, -3, 1, -2, -7,
- 4, 4, 1, -1, -7,-10, -7, -3, 10, 10, 5, 3, -2, -2, -4, -3,
- 0, 1, 5, 7, 4, -2,-16,-20, 0, 4, 7, 8, 2, 0, -2, -1,
- -2, 1, 3, 17, -3, 1, -2, -1, -1, -2, -1, -2, -1, -5, -1, 0,
- 5, -3, 1, 0, 6, -2, 0, 0, -1, -2, 0, -3,-11, 1, 8, -1,
- 3, 0, 0, 0, 0, 2, 4, 1, 2, 0, 6, 1, -2,-18, -3, 2,
- -14, 0, 6, 1, -5, -2, -1, 1, -1, 1, 0, 1, 1, 7, 4, 0,
- -1, 0, 1, -4, 1, 8, 3, -4, -3, 4, 1, 3, -6, 1, -4, 1,
- 1,-12, 3, 3, -1,-10, 0, -1, 2, 0, 2, 1, 3, 2, 2, 4,
- 3, 0, 0, 3, 2, 0, -2, 1, 5, 2, -5, 0, 6, -1,-14, -1,
- -2, -6, -3, -3, 2, -1, 4, 5, 6, -1, -2, 0, 4, 4, -1, -5,
- -4, 1,-11, 0, -1, 2, -4, 1, 2, -3, 3, -1, 1, -2, 15, 0,
- 1, -1, 0, -2, 1, -4, -7, 1, -2, -6, -1, 21, -2, 2, -1, 1,
- 21, -1, -2, 0, -1, -3, 1, -2, -9, -2, 2, -1, 2, 1, -4, -1,
- 1, 8, 2, -6,-10, -1, 4, 0, -4, -3, 3, 3, 5, 0, -1, -1,
- 3, 2, 1, -2, -2, -2, 4, 3, 5, 2, -4,-17, 0, -2, 4, 3,
- -7, -4, 0, 3, 9, 9, 2, -1,-11, -6, 0, -1, 5, 1, 0, 1,
- 0, 17, 5,-11, 3, -2, -6, 0, 2, -2, -4, 1, -4, 1, 2, -1,
- -5, -1, -5, -3, -3, 5, -3, -2, 4, 16, 2, -5, -2, 5, -1, -1,
- 0, 0, -4, 1, -1, 2, 5, 11, -1, -1, -2, 1, -4, -2, -3, -1,
- -5, -1, 10, 0, 6, 1, 0, -3, 0, -4, 1, 0, -2, -4, 3, -1,
- 6, 9, 3, 0, -2, 1, -2, 0, -2, -3, -2, -2, 1, 0, 1, -6,
- 1, 0, 2, 1, -1, 3, -2, 1, 0, -1,-15, 0, -1, 5, 2, 6,
- 2, 0, 2, 2, 0,-12, -4, 6, 0, 1, 4, -1, 1, 2, 1, -4,
- 1, -2, -7, 0, 0, 0, 0, -1, -5, 2, 11, 3, 1, 3, 0, -6,
- 0, -3, -9, -4, 1, 3, -1, 0, 4, 1, -2, 0, 7, -3, -1, 6,
- 1, -2, 6, 2, 0, -1, 3, -2, -2, 4, 0, 2, -1, 2,-14, 2,
- 2, 2, 0, -1, -2, 3, -3,-14, 0, 2, 3, -3, 5, 1, 3, 2,
- 1, -3, 4,-14, 1, -2, 11, -1, 0, -1, 3, 0, -1, 1, 0, 2,
- -2, 3, -3, 2, -4, -1, -4, 3, -1, 2, 1, 3, -6, -2, 2, 7,
- -2, 1, 2, 0, -2, 0, 0, -1, 12, 5, -1, 2, -8, -1, 1, -7,
- 2, -2, -4, 2, 11, 0,-11, -2, 3, 1, -3, -1, 0, 3, 1, -1,
- 0, 3, 0, -2, 0, -6, -1, -3, 12, -7, -2, 0, 7, -2, 1, 1,
- 1, 2, 2, 2, -1, 2, 0, 2,-23, 0, 4, 0, 3, 2, 1, 3,
- -4, -5, -1, 5, -3, 5, 10, -1, 0, 0, 3, -4, 1, -1, 2, -5
-};
-
-/* 6x16-entry codebook for inter-coded 8x4 vectors */
-static const int8_t svq1_inter_codebook_8x4[3072] = {
- 9, 8, 4, 0, -3, -4, -4, -3, 9, 8, 4, -1, -4, -5, -5, -3,
- 8, 7, 3, -2, -5, -5, -5, -4, 6, 4, 1, -2, -4, -5, -4, -3,
- -12,-14,-11, -4, 1, 5, 6, 6, -8,-10, -7, -5, -2, 1, 1, 1,
- 5, 4, 3, 1, 0, 0, -1, -1, 13, 13, 9, 6, 3, 0, -1, -2,
- -4, -4, -3, -1, 1, 4, 8, 11, -5, -6, -4, -2, 0, 3, 8, 12,
- -7, -7, -6, -4, -2, 2, 7, 10, -7, -7, -5, -4, -2, 1, 5, 8,
- -3, -2, -1, 1, 3, 6, 7, 6, 2, 3, 5, 7, 8, 8, 6, 4,
- 4, 5, 4, 3, 1, -2, -6, -7, 1, 0, -2, -7,-10,-14,-17,-16,
- -5, -4, 1, 8, 9, 3, -3, -7, -7, -6, 1, 11, 12, 5, -3, -8,
- -8, -7, 0, 9, 11, 5, -3, -7, -8, -6, -1, 5, 8, 4, -2, -6,
- -4, -5, -7, -8, -9, -9, -8, -6, -4, -5, -6, -7, -7, -6, -4, -2,
- 0, 1, 2, 3, 5, 8, 10, 9, 1, 2, 3, 6, 9, 12, 14, 13,
- 5, 6, 6, 5, 4, 3, 2, 1, 5, 6, 7, 7, 6, 6, 6, 4,
- -1, 0, 1, 1, 3, 5, 5, 5,-13,-16,-17,-17,-14,-10, -6, -4,
- 9, 11, 13, 16, 15, 13, 12, 10, -4, -5, -6, -7, -7, -7, -6, -5,
- -6, -6, -7, -7, -7, -7, -6, -5, -2, -1, 0, 0, 0, 0, 0, -1,
- -11,-13,-15,-16,-16,-14,-12,-10, 2, 3, 4, 5, 4, 3, 3, 3,
- 6, 7, 8, 8, 8, 7, 6, 5, 3, 4, 3, 3, 3, 3, 3, 3,
- 3, 4, 4, 1, -2, -7,-13,-17, 5, 7, 7, 5, 1, -5,-13,-19,
- 6, 8, 9, 8, 5, -1, -9,-16, 6, 8, 10, 10, 7, 2, -4,-11,
- 18, 9, -1,-10,-13, -9, -4, 0, 22, 12, -1,-12,-15,-10, -4, 2,
- 23, 13, 0,-10,-13, -9, -3, 2, 20, 12, 2, -6, -9, -6, -2, 2,
- -6, -6, -6, -7, -7, -7, -7, -6, -6, -7, -8, -8, -9, -9, -9, -8,
- -3, -3, -3, -3, -3, -3, -3, -3, 12, 15, 18, 21, 21, 19, 17, 14,
- 14, 16, 18, 18, 18, 16, 15, 13, 5, 6, 6, 5, 5, 4, 4, 3,
- -6, -7, -9,-10,-10,-10, -9, -7,-10,-11,-13,-14,-14,-13,-12,-10,
- -27,-17, -4, 5, 9, 10, 10, 7,-32,-19, -3, 7, 11, 12, 11, 8,
- -30,-16, -2, 8, 12, 12, 10, 7,-23,-12, 0, 7, 10, 11, 9, 6,
- 16, 17, 16, 12, 6, -1, -8,-12, 17, 18, 15, 10, 1, -8,-15,-18,
- 15, 14, 10, 4, -5,-14,-20,-23, 10, 8, 4, -1, -9,-16,-21,-22,
- -10,-12,-12,-11, -5, 4, 14, 20,-11,-13,-15,-12, -4, 7, 19, 27,
- -11,-13,-14,-11, -3, 8, 21, 28,-10,-11,-12, -9, -2, 8, 18, 25,
- -1, -1, -1, 1, 4, 6, 6, 5, 0, 0, 0, 2, 4, 3, 1, -2,
- 0, 0, 2, 4, 4, -1, -7,-10, 0, 0, 3, 5, 3, -3,-11,-15,
- -14,-13, -8, -1, 3, 3, -1, -4, -5, -4, -1, 4, 8, 8, 3, 0,
- 3, 2, 2, 3, 4, 5, 3, 1, 5, 3, 0, -2, -2, -1, -1, -1,
- 9, 1, -6, -6, -5, -3, -2, -1, 12, 1, -6, -6, -4, -2, -1, 0,
- 14, 4, -4, -4, -2, -2, -1, -1, 14, 6, -1, -1, -1, -1, -1, -1,
- 4, 6, 8, 10, 11, 9, 7, 5, -1, -1, -1, 0, 0, -1, -1, -2,
- -2, -4, -4, -5, -5, -5, -5, -4, -2, -3, -3, -4, -4, -3, -2, -1,
- 2, 3, 4, 4, 3, 1, 0, 0, -1, 1, 4, 5, 6, 5, 4, 3,
- -8, -6, -2, 2, 3, 4, 4, 3,-14,-13, -9, -5, -2, -1, 0, 0,
- -3, -4, -5, -4, 0, 7, 12, 13, -3, -4, -5, -5, -2, 4, 9, 10,
- -2, -3, -4, -5, -4, -1, 3, 4, -1, -1, -2, -3, -3, -2, 0, 1,
- 9, 5, -2, -8,-11,-10, -7, -4, 12, 10, 6, 2, 0, -1, 0, 0,
- 2, 2, 3, 4, 3, 1, 1, 1, -9, -8, -4, 0, 1, 2, 1, 0,
- 6, 8, 8, 5, 1, -5,-11,-13, 0, 1, 2, 2, -1, -4, -8,-11,
- -3, -2, 1, 3, 3, 1, -1, -4, -2, -1, 2, 5, 6, 6, 4, 1,
- 3, 4, 5, 5, 4, 1, -3, -6, 5, 6, 4, 2, 2, 2, 0, -3,
- 6, 5, 0, -5, -5, -2, -1, -2, 7, 4, -3,-11,-12, -7, -3, -2,
- 1, 0, -1, -1, -1, 0, 0, 0, 2, 3, 4, 4, 5, 5, 4, 3,
- -7, -9, -9,-10,-10, -9, -7, -6, 3, 4, 5, 6, 5, 5, 5, 5,
- -7, -7, -7, -7, -6, -6, -5, -4, -5, -4, -3, -1, -1, -1, 0, 0,
- -3, -2, 1, 4, 5, 5, 5, 5, -2, -1, 3, 6, 9, 10, 10, 9,
- -14, 1, 10, 3, -2, 0, 1, 1,-16, 2, 13, 3, -3, -1, 1, 0,
- -15, 2, 12, 3, -4, -2, 1, 1,-10, 3, 10, 2, -3, -1, 1, 1,
- 0, 1, 4, 2, -5,-10, -3, 11, -1, 1, 4, 2, -6,-13, -2, 15,
- -1, 0, 3, 1, -6,-12, -1, 15, -1, 1, 2, 1, -4, -8, 0, 11,
- 10, 5, -2, -2, 2, 5, 1, -4, 7, 0, -8, -6, 1, 5, 2, -4,
- 2, -5,-12, -7, 2, 7, 4, -1, -1, -7,-10, -4, 4, 9, 7, 2,
- -5, -5, -4, -6, -6, -5, -5, -3, -1, -2, -2, -4, -5, -6, -5, -4,
- 6, 7, 7, 4, 0, -2, -3, -3, 13, 14, 13, 10, 5, 1, -1, -2,
- 1, 1, 2, 2, 2, 2, 2, 2, -5, -6, -8, -9, -9, -8, -7, -6,
- 7, 9, 10, 11, 11, 9, 7, 5, -1, -2, -3, -3, -4, -4, -4, -3,
- -1, -1, 0, 0, 0, 0, -1, -1, -3, -3, -4, -5, -4, -3, -3, -2,
- 2, 1, -1, -3, -3, -2, -1, 0, 12, 12, 8, 3, 1, 0, 0, 1,
- -6, -8, -8, -6, -2, 2, 6, 8, 1, 1, -1, -2, 0, 3, 5, 7,
- 3, 3, 1, -1, -1, 0, 0, 2, 0, 1, 0, -1, -1, -1, -2, -1,
- 1, 0, 0, 0, 0, 0, 2, 4, 2, 1, 3, 4, 3, 1, 0, 2,
- 2, 1, 0, 0, -1, -1, 0, 3, 5, 1, -6,-12,-13, -8, -1, 4,
- -2, 0, -1, -2, -1, 0, 2, 3, -6, -3, -2, 0, 1, 1, 1, 1,
- -9, -5, 0, 4, 5, 3, 1, 0, -8, -3, 3, 7, 8, 4, 1, 0,
- 1, 2, 2, 3, 3, 1, -1, -3, 4, 5, 5, 6, 6, 5, 2, 0,
- 0, 0, 0, 0, 1, 0, -2, -4, -3, -3, -4, -3, -3, -4, -7, -8,
- 14, 12, 6, -1, -3, -3, 0, 0, 7, 5, 1, -3, -5, -4, -2, -1,
- -2, -2, -2, -2, -2, -2, -1, -1, -6, -4, -1, 1, 1, 1, 0, -1,
- 2, 2, 1, -3, -6, -7, -6, -3, 1, 0, -1, -3, -2, 1, 4, 6,
- 0, 0, 1, 2, 4, 7, 8, 7, 0, 0, 0, 0, -1, -4, -7, -8,
- 0, 2, 1, -2, -3, -3, -2, -1, -1, 1, 0, -3, -5, -2, 0, 2,
- -2, -1, -2, -5, -4, 1, 6, 9, -3, -2, -3, -4, -2, 5, 11, 13,
- -4, -2, 2, 6, 4, -3,-10,-14, -2, -1, 1, 4, 4, 1, -1, -2,
- 0, 0, -1, -2, -2, 0, 4, 6, 2, 2, 0, -3, -3, 0, 5, 9,
- -4, -4, -2, 1, 6, 9, 3, -7, -2, -2, -2, -1, 4, 8, 0,-11,
- 1, 1, 0, 0, 2, 6, -1,-10, 2, 2, 1, 0, 2, 4, 0, -7,
- -1, -2, -3, -6, -7, -8, -8, -8, 2, 3, 3, 1, -1, -2, -3, -4,
- 5, 5, 5, 4, 3, 2, 0, -1, 3, 3, 3, 3, 2, 2, 1, 1,
- 3, 3, 2, -2, -3, 0, 7, 10, 1, 2, 2, -2, -5, -4, 0, 3,
- 0, 3, 4, 2, -3, -5, -6, -4, 0, 2, 4, 4, 1, -4, -7, -7,
- 2, 4, 5, 5, 5, 5, 6, 6, -4, -4, -3, -5, -5, -3, -3, -2,
- -3, -4, -4, -5, -4, -2, -2, -2, 1, 1, 0, 0, 2, 4, 5, 4,
- -2, 0, 3, 4, 4, 3, 2, 2, -9, -7, -4, 0, 3, 6, 6, 6,
- -5, -5, -3, -2, 0, 1, 3, 4, 5, 5, 2, -2, -4, -6, -5, -3,
- 1, -6, -4, 7, 5, -2, -2, 1, 5, -5, -4, 6, 4, -5, -4, 1,
- 5, -5, -4, 6, 4, -5, -3, 1, 1, -7, -3, 8, 7, -1, -3, 1,
- -8, -7, -4, 0, 2, 4, 5, 5, 5, 6, 5, 2, -1, -5, -7, -7,
- 5, 6, 4, 1, -3, -5, -6, -5, -7, -7, -5, -2, 1, 6, 9, 10,
- 6, 3, 0, 1, 3, 0, -8,-14, 3, 0, -1, 1, 4, 3, 0, -4,
- 1, 0, 0, 1, 2, 1, 1, 1, -1, -1, 1, 2, 1, -1, -1, 0,
- 1, 1, 1, 1, 0, -2, -3, 0, 1, 2, 1, 0, -2, -8, -9, -4,
- 1, 3, 3, 2, 1, -3, -3, 1, 0, 1, 1, 1, 1, 1, 4, 8,
- 2, 5, 9, 7, 2, -1, -1, 1, -4, -1, 1, 0, -3, -4, -1, 2,
- -3, 0, 3, 3, 0, -1, 0, 2, -4, -1, 1, 1, -2, -4, -5, -4,
- 1, -1, -2, -2, -1, 2, 4, 5, 2, 1, 1, 0, -1, -1, 0, 0,
- 2, 3, 4, 5, 4, 2, 1, 0, -9, -9, -6, -3, -1, -1, -1, -1,
- -6, -6, 4, 7, 0, -2, -1, -2, -1, -2, 5, 6, -1, -2, 0, -1,
- 4, -1, 1, 0, -4, -2, 0, -2, 7, 1, -1, -2, -3, 1, 3, 1,
- 4, 2, 1, 3, 3, 1, 1, 2, 2, -2, -4, 0, 3, 1, 0, 0,
- 1, -4, -8, -4, 1, 2, 1, 0, 2, -3, -9, -6, 0, 3, 3, 2,
- -1, -1, 0, -1, -1, 0, 1, 2, 3, 1, -4, -8, -7, -3, 1, 2,
- 2, -1, -3, -2, -1, 0, 1, 0, -1, 0, 5, 11, 9, 3, -1, -3,
- -1, -2, -2, -1, 1, 1, 1, 1, 0, -1, 0, 3, 6, 6, 5, 5,
- 2, 1, -1, -1, -2, -5, -6, -4, 2, 2, 2, 1, -1, -4, -5, -5,
- -1, -3, -6, -7, -6, -4, -1, 1, 5, 5, 3, 4, 4, 3, 4, 5,
- -1, -2, -3, -2, -2, -2, 0, 1, 0, 0, 0, 0, 0, 1, 2, 3,
- -6, -6, -4, -1, 2, 2, 2, 2, -6, -7, -5, -2, 0, -1, -1, 0,
- 2, 2, 2, 4, 4, 3, 3, 4, 2, 1, 0, -1, 0, 0, 2, 4,
- 12, 5, -5, -8, -5, 0, 2, 2, 2, -3, -6, -3, 0, 0, -1, -2,
- -2, -3, -1, 3, 4, 1, -2, -3, 2, 2, 3, 4, 3, 1, -1, -1,
- 3, 2, 1, 0, 1, 4, 3, 0, 4, 3, 0, -5, -6, 0, 3, 3,
- 2, 3, 1, -7,-12, -6, 1, 3, 1, 3, 4, -1, -6, -4, 0, 1,
- -9, -4, 2, 6, 7, 4, 1, 0, -7, -1, 4, 6, 4, 0, -3, -3,
- -6, 0, 4, 4, 1, -2, -3, -2, -4, 1, 3, 2, 0, -2, -1, 0,
- 0, 5, 2, -5, -3, 3, 1, -4, -2, 4, 2, -6, -3, 6, 4, -3,
- -1, 5, 3, -5, -1, 7, 3, -4, -1, 2, 0, -6, -3, 5, 3, -3,
- -8, -3, 3, 5, 3, 1, -2, -2, 2, 4, 4, -2, -4, -3, 1, 3,
- 2, 1, -3, -5, -3, 3, 4, 3, -5, -6, -5, 3, 10, 8, -1, -5,
- 0, 3, 2, -4, -9, -7, 0, 6, -5, -1, 5, 7, 4, -1, -3, -3,
- -5, -5, -2, 3, 6, 5, -1, -4, 9, 6, 0, -4, -2, 1, 1, -1,
- -1, -1, -1, 1, 1, 0, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0,
- 2, 1, -2, -1, 1, 1, 0, 0, 12, 8, 2, -1, -1, -4, -7, -7,
- 2, 1, 3, 6, 7, 4, 2, 0, 1, 0, -1, 0, -1, -4, -7, -8,
- 0, 0, -1, 0, 0, 0, -1, -3, 0, 0, 0, 0, 1, 1, 0, -2,
- -1, 0, 1, 1, 0, 0, -1, -2, 0, 0, -1, -3, -4, -3, -1, 1,
- -1, 0, 0, 0, 1, 4, 10, 12, -1, 0, -2, -2, -3, -3, -1, 1,
- -3, -1, -2, -4, 2, 9, 9, 7, -3, 0, -1, -3, 0, 2, -1, 1,
- -1, 1, -2, -3, 0, -1, -3, 0, 0, 0, -3, -2, 0, -1, -1, 1,
- -1, -2, -1, -1, -2, -1, -1, -2, 2, -1, -2, -1, 0, 1, 0, -2,
- 3, -1, -2, 2, 5, 3, -1, -3, 1, -5, -5, 1, 6, 6, 2, 0,
- 1, 2, 0, -1, 0, 1, 0, -2, -5, -3, -1, 0, 1, 2, 1, -2,
- -7, -5, -2, -2, -2, -2, 0, 1, -1, 0, 1, 1, 0, 3, 9, 12,
- 0, 6, 5, 1, -2, -3, 0, 3, 0, 6, 5, 1, 1, 1, 2, 3,
- -5, -2, -2, -3, 0, 0, 0, 0, -6, -3, -3, -2, 0, 0, -1, -2,
- 4, 4, 2, 1, 0, -1, -1, 0, -2, -2, 0, 1, 2, 1, 1, 0,
- 2, 2, 1, -1, -3, -5, -9,-10, 2, 1, -1, -1, 1, 4, 4, 1,
- 4, 0, -2, -2, -2, -2, -1, 0, 7, 1, -4, -3, -2, 0, 1, 1,
- 10, 5, -1, -2, 0, 1, 1, 0, 5, 1, -3, -4, -3, -1, -1, -2,
- 2, 1, -1, -3, -3, 1, 1, -1, -2, -1, 3, 0, -1, 1, 1, 0,
- -3, 1, 7, 2, -3, -2, -1, 0, -2, 4, 8, -1, -8, -5, 0, 2,
- -4, -1, 1, 2, 1, -3, -4, -2, -5, -3, -2, 1, 4, 4, 4, 6,
- -3, -2, -4, -3, 0, 1, 1, 2, 2, 2, 2, 1, 2, 1, -1, -1,
- -4, -1, 0, -1, -3, -3, -1, -1, 1, 4, 4, 2, 0, -1, -2, -3,
- 4, 6, 5, 3, 2, 1, -2, -4, 0, 1, 1, 1, 1, -1, -4, -6,
- 1, 2, 2, -1, -6, -5, -1, 2, -3, -2, 1, 1, -4, -3, 2, 5,
- -2, -1, 2, 2, -3, -4, 0, 3, -2, -2, 2, 6, 5, 2, 1, 2,
- 2, -3, -3, 0, 0, 2, 3, 1, 3, -1, 1, 3, 1, 2, -1, -5,
- -5, -7, -4, -2, 1, 8, 8, 1, -1, 0, 2, 0, -3, 0, 1, -3,
- -2, -5, -5, -2, -3, -1, 0, -2, -1, -4, 0, 4, 0, 2, 4, 0,
- 0, 0, 8, 10, 2, 1, 3, -1, -4, -3, 2, 3, -3, -3, 1, -1,
- 1, -2, -4, 2, 7, 3, -2, -1, 6, 4, -2, -1, 2, 0, -1, 3,
- 1, 1, -2, -2, -2, -5, -3, 4, -6, -2, 1, 1, -1, -4, -2, 4,
- -2, -1, -2, -2, 0, 1, 0, -2, -1, 1, 0, -1, 0, 0, -1, -3,
- 0, 1, -2, -4, -3, -1, 0, 0, 6, 8, 5, 0, 0, 1, 2, 3,
- -2, -2, 2, 5, 2, 0, 0, 1, 2, -2, -2, -1, -1, 1, 2, 4,
- 2, -1, 0, 1, 0, 0, 0, 1, -8, -7, -1, 1, -1, -1, 1, 3,
- 0, 3, 6, 2, -2, 1, 2, 0,-10, -7, -1, 0, -3, -1, 2, 1,
- 0, 0, 2, 2, 1, 1, 1, -1, 3, 0, -2, -2, 0, 2, 1, 0,
- 8, 1, 0, 0, -2, -3, -1, 0, 2, -2, 2, 5, 1, -2, -1, 1,
- -3, -6, -3, -1, -3, -3, -1, 2, 2, 0, 1, 2, 2, 1, 0, 0,
- 1, -1, -1, -2, -1, 0, 1, 0, 15, 9, 2, -1, -2, -3, -3, -3,
- 0, -3, -2, 0, 0, -1, -1, -1, 1, 0, 1, 0, 0, -1, -1, -1,
- 0, 2, 2, -2, -3, -3, -7, -8, 0, 2, 2, 0, 1, 2, 1, 1,
- 1, 2, 2, 2, 3, 1, 0, 3, 1, 0, -1, -2, -1, -2, 0, 5,
- -11, -6, -1, 1, 2, 3, 1, -3, 1, 4, 3, -1, -2, 1, 2, -1,
- 2, 2, 1, -1, -2, 0, 1, -1, 0, 0, -1, -1, 0, 2, 3, 2,
- 1, 1, 2, 1, -1, 1, 0, -4, 0, 0, 0, -2, -2, 2, 4, -2,
- -2, -3, 0, 0, -1, 2, 1, -6, 0, 2, 5, 5, 3, 2, -1, -7,
- 4, 2, 0, 0, 3, 3, 1, -1, 0, -1, -1, 3, 6, 4, 1, -1,
- -2, -2, 0, 2, 2, 0, -2, -2, -1, 0, -1, -5, -7, -5, -1, 1,
- 5, -1, -2, 0, 2, 4, 2, -5, 0, -5, -2, 2, 1, 2, 0, -6,
- 6, 1, 0, 1, -2, -1, 4, 2, 2, -3, -3, 0, -1, -2, 0, 0,
- 1, -1, 0, 2, 0, 0, 6, 11, 2, -1, -1, 0, -3, -2, 3, 5,
- 0, -2, -1, 0, -1, 0, 0, -3, 1, -1, -1, -1, -2, -1, -3, -7,
- 1, 1, -2, -2, 1, 3, 1, -2, -1, 2, 0, -1, -1, 1, 0, 0,
- -4, 2, 3, -1, -2, -2, 0, 1,-11, -2, 4, 5, 6, 2, -1, -2,
- -6, -2, 1, -1, -3, -4, 1, 9, -3, 0, 3, 3, 2, -3, -3, 3,
- 1, 1, 0, 0, 1, -1, -2, 3, 2, 0, -3, -3, 0, -1, -1, 3,
- 1, -1, -3, 1, 2, -6, -4, 6, 0, -2, -5, -2, 0, -3, -2, 3,
- 2, 2, 1, -2, -2, 1, 2, -1, -1, 1, 1, -2, -1, 6, 7, -1,
- 1, 0, -4, -2, 1, -2, -3, 1, -4, 0, -3, -2, 2, 0, -3, 0,
- -3, 4, 3, 1, 8, 7, 0, -1, -3, 4, 1, -4, 2, 3, -2, -3,
- -3, 6, 1, -4, 1, 1, -1, -1, -2, 4, -3, -3, 3, 0, -1, -1,
- 1, 2, -4, 2, 4, -3, -1, 2, 3, -1, -4, 5, 4, -6, -3, 2
-};
-
-/* 6x16-entry codebook for inter-coded 8x8 vectors */
-static const int8_t svq1_inter_codebook_8x8[6144] = {
- -4, -3, 4, 5, 2, 1, 1, 0, -5, -3, 5, 5, 2, 1, 0, 0,
- -6, -4, 5, 5, 2, 1, 0, 0, -7, -4, 4, 5, 2, 1, 0, 0,
- -8, -5, 3, 4, 2, 1, 0, 0, -8, -6, 3, 4, 1, 1, 1, 0,
- -8, -6, 2, 4, 2, 1, 1, 0, -8, -6, 2, 4, 1, 1, 1, 1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2,
- -2, -3, -3, -3, -3, -3, -3, -3, -2, -3, -3, -3, -3, -3, -4, -3,
- -2, -2, -2, -2, -2, -3, -3, -2, 1, 1, 1, 1, 1, 0, -1, -1,
- 4, 5, 5, 5, 4, 3, 3, 2, 7, 7, 8, 8, 8, 7, 6, 5,
- 2, 1, 2, 4, 4, 0, -4, -6, 1, 1, 2, 5, 5, 1, -5, -7,
- 1, 2, 1, 4, 5, 1, -5, -8, 1, 1, 1, 5, 5, 0, -6, -8,
- 0, 1, 1, 5, 6, 1, -6, -9, 0, 0, 1, 4, 5, 0, -5, -8,
- 0, 0, 1, 4, 5, 0, -5, -7, 0, 0, 1, 4, 4, 1, -4, -7,
- 1, 2, 3, 0, -3, -4, -3, -1, 1, 3, 4, 0, -3, -4, -3, -1,
- 2, 4, 5, 1, -3, -4, -3, -2, 2, 5, 6, 1, -3, -5, -4, -2,
- 3, 6, 6, 1, -3, -5, -4, -2, 3, 6, 6, 1, -3, -5, -4, -2,
- 3, 6, 6, 1, -3, -5, -4, -2, 3, 5, 5, 1, -3, -4, -4, -2,
- 2, 2, 2, 2, 1, 0, 0, -1, 4, 4, 4, 3, 2, 1, 1, 0,
- 4, 5, 4, 4, 3, 3, 2, 1, 4, 4, 4, 4, 4, 3, 2, 2,
- 2, 3, 3, 3, 3, 3, 2, 1, -1, -1, -1, -1, 0, 0, 0, 0,
- -5, -6, -6, -5, -5, -4, -3, -3, -7, -9, -9, -8, -7, -6, -6, -5,
- 6, 6, 6, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2,
- 0, -1, -1, -1, -2, -2, -1, -1, -3, -5, -6, -6, -6, -6, -5, -4,
- -3, -5, -6, -7, -6, -6, -5, -4, -1, -2, -2, -2, -2, -2, -1, -1,
- 0, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
- 2, 1, -2, -5, -4, 0, 2, 5, 2, 1, -2, -6, -5, 0, 3, 5,
- 2, 1, -2, -6, -6, -1, 3, 6, 3, 2, -2, -7, -6, 0, 4, 7,
- 2, 1, -2, -7, -5, 0, 5, 7, 2, 1, -2, -6, -5, 0, 4, 7,
- 2, 1, -2, -6, -4, 0, 4, 6, 1, 1, -2, -5, -4, 0, 3, 6,
- -10, -9, -6, -4, -1, 2, 3, 2,-10, -9, -5, -3, 0, 4, 4, 3,
- -9, -7, -3, -1, 2, 5, 5, 3, -7, -5, -2, 0, 3, 5, 5, 3,
- -6, -3, 0, 1, 4, 6, 5, 3, -4, -2, 1, 2, 3, 5, 4, 2,
- -2, 0, 1, 2, 2, 4, 3, 1, -1, 1, 2, 2, 2, 3, 3, 1,
- -4, -5, -5, -6, -6, -6, -6, -5, -3, -3, -4, -4, -4, -4, -4, -4,
- 0, 0, 0, 0, -1, -1, -1, -1, 5, 5, 6, 5, 5, 4, 3, 2,
- 5, 6, 7, 7, 7, 6, 5, 4, 3, 3, 4, 4, 4, 4, 3, 2,
- 0, -1, 0, 0, -1, -1, 0, -1, -3, -3, -4, -4, -4, -4, -3, -3,
- 1, -2, -5, 1, 5, 4, 2, 0, 1, -3, -6, 1, 6, 5, 2, 0,
- 0, -4, -7, 0, 6, 6, 2, 1, -1, -5, -9, -1, 6, 6, 3, 1,
- -1, -6,-10, -2, 6, 6, 3, 1, -1, -6, -9, -2, 5, 6, 3, 1,
- -2, -6, -9, -2, 5, 5, 3, 1, -2, -6, -7, -2, 4, 4, 2, 1,
- -5, -7, -8, -9, -9, -8, -7, -6, -5, -6, -6, -7, -7, -6, -6, -5,
- -3, -3, -3, -4, -5, -5, -4, -4, -1, 0, 0, -1, -1, -1, -1, -1,
- 0, 1, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 5, 5, 5, 4,
- 3, 4, 5, 6, 8, 8, 8, 7, 3, 4, 5, 6, 7, 7, 7, 6,
- 5, 6, 7, 8, 9, 10, 10, 9, 3, 4, 6, 7, 8, 9, 9, 8,
- 0, 1, 2, 3, 4, 5, 5, 5, -1, -2, -1, -1, 0, 1, 2, 2,
- -2, -3, -3, -3, -3, -2, -1, 0, -3, -4, -5, -5, -5, -5, -5, -4,
- -4, -5, -5, -6, -7, -7, -6, -5, -3, -4, -5, -6, -7, -7, -6, -6,
- 13, 7, 0, -3, -3, -4, -4, -5, 14, 7, 0, -3, -3, -4, -4, -4,
- 15, 8, -1, -4, -4, -4, -5, -4, 15, 8, -1, -4, -4, -5, -4, -3,
- 15, 7, -1, -4, -5, -5, -5, -4, 14, 7, -1, -4, -4, -4, -4, -3,
- 12, 6, -1, -4, -4, -4, -4, -3, 11, 5, -1, -4, -4, -4, -4, -3,
- -17, -4, 5, 4, 4, 4, 3, 3,-18, -5, 5, 4, 4, 4, 3, 3,
- -19, -5, 6, 4, 4, 4, 3, 2,-20, -5, 6, 4, 4, 4, 3, 3,
- -20, -4, 6, 4, 4, 5, 3, 3,-19, -5, 6, 4, 4, 5, 3, 3,
- -18, -4, 5, 4, 4, 4, 3, 2,-17, -5, 4, 3, 4, 4, 3, 3,
- -6, -6, -6, -4, -2, 1, 6, 11, -6, -7, -7, -4, -2, 2, 8, 13,
- -8, -8, -7, -4, -2, 3, 9, 14, -8, -8, -7, -5, -1, 4, 10, 16,
- -8, -8, -7, -5, -1, 4, 10, 17, -8, -8, -7, -4, 0, 5, 10, 16,
- -8, -8, -6, -3, 0, 4, 9, 15, -7, -7, -5, -3, 0, 4, 8, 12,
- 8, 7, 7, 5, 2, -2, -8,-14, 8, 8, 7, 5, 2, -2, -8,-15,
- 8, 8, 7, 5, 1, -3, -9,-16, 8, 8, 7, 5, 1, -3,-10,-17,
- 8, 9, 8, 5, 1, -3,-10,-17, 8, 8, 7, 4, 1, -4,-10,-16,
- 7, 7, 7, 4, 1, -3, -9,-14, 6, 7, 6, 3, 0, -3, -9,-13,
- 5, 1, -4, -4, -3, -1, 0, 0, 7, 2, -3, -3, -2, -1, 1, 0,
- 7, 1, -3, -3, -1, 0, 1, 1, 6, 1, -3, -2, -1, 1, 1, 0,
- 6, 0, -4, -2, -1, 0, 1, 0, 5, 0, -4, -3, -1, 0, 0, -1,
- 5, 0, -3, -1, 0, 0, 0, -2, 4, 1, -2, -1, 0, 1, 0, -1,
- 2, 2, 1, 1, -2, -6, -8, -8, 1, 1, 1, 1, -2, -5, -8, -8,
- 1, 1, 1, 0, -1, -3, -5, -5, 0, 0, 0, 0, -1, -1, -1, -2,
- 0, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 2, 3, 2,
- 2, 1, 1, 1, 2, 3, 4, 3, 3, 3, 3, 3, 4, 4, 5, 4,
- -4, -4, -3, -2, 0, 0, 1, 1, -4, -4, -3, -2, -1, 0, 0, 1,
- -2, -2, -2, -1, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1,
- 2, 2, 2, 2, 2, 2, 1, 1, 3, 4, 4, 4, 4, 4, 4, 3,
- 1, 1, 1, 3, 3, 4, 3, 3, -5, -6, -5, -4, -3, -3, -2, -2,
- -4, -2, -1, -1, -1, -1, 0, 1, -4, -2, -1, -1, -1, -1, 0, 1,
- -3, -2, -1, -1, -1, 0, 1, 2, -4, -3, -2, -1, -1, 1, 3, 3,
- -4, -3, -3, -1, -1, 1, 4, 5, -4, -3, -2, -2, -1, 1, 4, 7,
- -2, -2, -1, -1, 0, 2, 6, 8, -1, 0, 0, 1, 1, 4, 7, 8,
- -3, -3, -3, -2, -2, -1, -1, 0, -1, -1, 0, 1, 2, 2, 3, 3,
- 0, 1, 2, 4, 5, 6, 6, 5, -1, 0, 2, 3, 5, 6, 5, 3,
- -1, -1, 0, 2, 3, 3, 2, 1, -2, -2, -1, 0, -1, -3, -4, -4,
- 0, 0, -1, -1, -2, -4, -8, -7, 1, 2, 1, 0, -1, -4, -6, -7,
- -2, 4, 1, -6, 0, 3, 0, 0, -2, 5, 1, -7, 0, 3, 0, 0,
- -3, 5, 1, -8, 0, 3, -1, -1, -2, 6, 1, -9, 0, 3, 0, -1,
- -2, 6, 2, -8, 0, 4, 0, -1, -3, 5, 1, -7, 1, 4, 0, 0,
- -2, 4, 1, -7, 0, 4, 1, 0, -1, 4, 1, -6, 0, 3, 1, 0,
- 0, 0, 0, 3, 4, 5, 4, 1, 1, 1, 1, 2, 3, 3, 2, 0,
- 2, 2, 1, 2, 2, 1, -1, -2, 4, 3, 1, 1, 0, -1, -3, -5,
- 5, 3, 1, -1, -2, -3, -4, -6, 5, 3, 0, -2, -3, -5, -6, -7,
- 4, 3, 0, -2, -3, -4, -5, -5, 4, 3, 0, -1, -2, -2, -3, -3,
- 0, 0, 0, 0, -1, -5, -2, 6, 0, 0, 0, 1, -1, -6, -2, 8,
- 0, 0, 0, 2, 0, -6, -3, 9, 0, -1, 0, 2, 0, -7, -2, 10,
- 0, -1, 0, 2, -1, -8, -3, 10, 0, -1, -1, 2, -1, -7, -3, 9,
- 0, -1, 0, 1, -1, -6, -3, 8, 0, 0, 0, 1, 0, -5, -2, 7,
- 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 3, 2, 1, 0, -1, -2,
- 3, 4, 4, 2, 1, -1, -2, -3, 2, 3, 3, 2, 0, -1, -2, -3,
- -1, 0, 1, 1, 0, -1, -2, -2, -5, -4, -3, -1, 0, 1, 1, 1,
- -8, -8, -5, -1, 1, 3, 4, 3,-10, -9, -5, 0, 3, 5, 6, 5,
- -5, -1, 4, 5, 3, 1, 0, 0, -6, -1, 4, 5, 2, 0, -1, -2,
- -6, -1, 5, 4, 2, -1, -2, -2, -7, -1, 4, 4, 1, -2, -3, -3,
- -6, -1, 5, 4, 1, -2, -3, -3, -5, 0, 4, 4, 1, -1, -2, -2,
- -4, 0, 5, 4, 1, -1, -1, -2, -3, 1, 4, 3, 1, -1, -1, -2,
- -2, -3, -2, 1, 4, 6, 5, 3, -3, -4, -4, 0, 3, 5, 4, 2,
- -3, -5, -5, -1, 2, 4, 3, 1, -4, -6, -4, -1, 2, 4, 2, -1,
- -2, -4, -3, 1, 2, 4, 2, -1, -2, -4, -2, 1, 3, 3, 1, -2,
- -2, -3, -2, 1, 3, 3, 1, -2, -2, -2, -1, 1, 3, 3, 0, -2,
- -4, -4, -3, -2, -1, 2, 5, 7, -4, -4, -3, -3, -2, 1, 5, 7,
- -2, -3, -2, -3, -3, -1, 3, 5, -1, -1, 0, -2, -3, -2, 2, 4,
- 1, 1, 1, -1, -4, -3, 1, 3, 4, 3, 2, -1, -4, -3, -1, 1,
- 6, 4, 3, 0, -3, -3, -2, 0, 6, 5, 3, 1, -2, -3, -2, -1,
- 12, 11, 8, 4, 0, -2, -2, -1, 10, 9, 6, 2, -1, -2, -1, 0,
- 4, 3, 2, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, 0, 1, 2,
- -3, -5, -4, -2, -2, 0, 2, 3, -5, -5, -4, -2, -1, 0, 1, 2,
- -5, -5, -4, -2, -1, 0, 1, 1, -4, -4, -3, -2, -2, -1, 0, 0,
- 3, 3, 2, -1, -3, -4, -3, -2, 3, 2, 0, -2, -4, -4, -3, -2,
- 2, 2, 1, -1, -3, -5, -4, -3, 3, 3, 3, 1, -2, -3, -3, -3,
- 4, 4, 4, 3, 0, -2, -2, -2, 5, 5, 5, 3, 0, -1, -2, -2,
- 5, 5, 4, 2, -1, -2, -3, -2, 3, 3, 3, 0, -2, -4, -4, -4,
- -1, -1, 4, -2, -2, 6, 2, -5, -1, 0, 4, -2, -3, 6, 2, -6,
- -1, 0, 4, -2, -3, 7, 3, -7, -1, -1, 4, -3, -4, 8, 3, -7,
- 0, -1, 4, -3, -4, 7, 3, -6, -1, -1, 4, -3, -4, 7, 3, -6,
- -1, -1, 3, -3, -4, 6, 3, -6, -1, 0, 3, -2, -3, 6, 3, -5,
- 1, -2, -7, 2, 5, -2, -1, 1, 1, -2, -8, 3, 6, -3, -1, 2,
- 2, -2, -9, 4, 7, -4, -2, 2, 3, -1, -9, 5, 7, -4, -1, 3,
- 3, -1, -9, 4, 7, -4, -2, 2, 3, -1, -7, 4, 6, -4, -2, 1,
- 2, 0, -6, 4, 6, -4, -1, 1, 2, 0, -5, 3, 4, -3, -1, 1,
- -2, 2, 2, 0, 0, -1, -3, -4, -2, 2, 2, 1, 1, 0, -2, -4,
- -2, 2, 2, 2, 2, 1, -1, -2, -3, 2, 3, 3, 4, 2, 0, -2,
- -3, 2, 3, 2, 4, 2, 0, -3, -4, 1, 2, 1, 2, 1, -1, -3,
- -5, 0, 1, 0, 1, 1, -2, -3, -4, 0, 0, 0, 1, 0, -2, -3,
- 0, 0, -1, -2, -2, 2, 7, 8, 0, 0, -1, -3, -2, 1, 6, 7,
- 0, 1, -1, -3, -3, 0, 4, 5, 0, 1, 0, -1, -1, 0, 1, 3,
- 0, 2, 1, 1, 0, -1, 0, 1, -2, 0, 1, 2, 1, 0, -1, -1,
- -5, -2, 0, 1, 1, 0, -3, -3, -6, -4, -1, 1, 1, -1, -3, -4,
- -4, -2, 2, 5, 6, 4, 3, 2, -5, -3, 1, 4, 4, 2, 0, 0,
- -4, -2, 0, 2, 1, -1, -2, -2, -2, -1, 0, 1, 0, -2, -3, -2,
- -2, 0, 0, 0, -1, -1, -2, -1, -2, -1, -1, 0, 0, 0, 1, 2,
- -2, -2, -1, -1, 0, 1, 3, 4, -2, -3, -2, -1, 0, 2, 4, 5,
- 2, 1, -2, -2, -1, 0, 1, 0, 1, 0, -3, -3, -1, 0, 1, 0,
- 0, -1, -3, -3, -1, 1, 1, 1, 0, 0, -3, -1, 1, 2, 3, 3,
- 0, -1, -3, -1, 1, 3, 3, 3, -2, -2, -4, -2, 1, 3, 4, 4,
- -3, -3, -4, -2, 1, 3, 3, 4, -2, -3, -5, -2, 1, 2, 3, 3,
- 4, 5, 3, 4, 4, 4, 4, 5, 3, 3, 1, 0, 0, 0, 0, 1,
- 1, 1, -1, -2, -3, -4, -3, -2, 2, 2, 0, -2, -2, -4, -3, -2,
- 2, 3, 1, -1, -1, -3, -3, -2, 1, 2, 0, 0, -1, -2, -2, -1,
- 0, 1, 0, -1, -1, -3, -2, -1, 1, 1, 0, -1, -1, -2, -2, -2,
- -2, -1, -1, 0, 1, 2, 1, 0, 1, 2, 3, 5, 6, 5, 5, 3,
- 1, 2, 3, 4, 5, 5, 4, 3, -2, -2, -3, -3, -2, -1, 0, 0,
- -3, -3, -4, -5, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0,
- 0, 1, 0, -1, -1, 0, 0, 1, -1, 0, -1, -2, -3, -2, -2, -1,
- 7, 7, 6, 5, 4, 2, -1, -2, 3, 3, 2, 2, 1, 0, -2, -3,
- 0, -1, -1, -1, 0, -1, -2, -2, -1, -3, -2, -1, 0, 0, 0, 1,
- 0, -2, -2, -1, -1, 1, 2, 2, 3, 1, -1, -1, -1, 1, 2, 2,
- 3, 1, -2, -3, -2, -1, 1, 2, 1, -2, -5, -6, -5, -3, -2, 0,
- 0, -1, -2, -3, -1, 0, -2, -2, 0, 0, -1, -1, 0, 1, -1, -2,
- 0, 0, -2, -1, 0, 0, 0, -2, -1, -2, -3, -3, -2, -1, -3, -3,
- -1, -2, -3, -3, -2, -2, -3, -4, 2, 2, 0, 0, 0, 0, -1, -2,
- 5, 5, 3, 2, 2, 2, 0, -1, 8, 8, 6, 5, 4, 4, 2, 1,
- -7, -8, -6, -3, -1, -1, -2, -1, -5, -5, -3, 0, 2, 1, 0, 0,
- -1, -1, 0, 3, 4, 3, 1, 1, 2, 1, 1, 3, 4, 3, 2, 2,
- 3, 2, 0, 2, 3, 2, 1, 2, 4, 2, -1, -1, 0, 1, 1, 1,
- 3, 2, -2, -3, -2, -1, 0, 1, 3, 1, -3, -4, -3, -2, 0, 1,
- -4, -2, -1, 2, 3, 3, 1, 0, -7, -5, -4, -2, 0, 0, -1, -2,
- -6, -5, -5, -4, -2, -2, -2, -3, -1, 0, -1, -1, 0, 0, 0, -1,
- 2, 3, 2, 2, 2, 2, 1, 0, 3, 5, 4, 3, 1, 0, 1, 0,
- 3, 4, 3, 2, 0, -1, -1, -1, 5, 5, 3, 1, 0, -1, -1, -1,
- 1, 1, 0, -1, -3, -5, -6, -4, 1, 1, 0, 0, 0, -3, -3, -1,
- 0, -1, -1, 0, 1, 0, 1, 3, -2, -2, -3, -1, 2, 2, 4, 7,
- -2, -2, -2, 0, 2, 2, 3, 6, -1, 0, 0, 1, 1, 0, 0, 3,
- 0, 3, 3, 3, 1, -2, -3, -1, 1, 3, 4, 3, 0, -3, -5, -4,
- 0, 2, 0, -1, -3, -4, -2, -2, 1, 4, 2, 0, -2, -3, -2, -1,
- 3, 6, 3, 1, -2, -2, 0, -1, 4, 7, 4, 1, -2, -3, -1, 0,
- 3, 6, 3, 0, -3, -3, -1, 0, 1, 3, 0, -1, -3, -2, 1, 1,
- 0, 1, -1, -2, -3, -1, 2, 2, -2, -1, -3, -3, -3, -1, 1, 2,
- 3, 1, -1, 0, 1, 0, 0, 0, 2, -1, -2, -1, 1, 0, -1, -1,
- 1, -1, -2, 0, 1, 0, -2, -3, 0, -2, -1, 1, 3, 1, -3, -5,
- 0, -2, -1, 2, 5, 2, -3, -5, 0, -2, -1, 4, 6, 3, -2, -5,
- 0, -2, 0, 4, 7, 4, -2, -4, 0, -2, 0, 4, 6, 4, -2, -4,
- -2, -2, -3, -4, -3, -2, -1, 0, 1, 1, 0, -1, -1, -1, 0, 1,
- 3, 3, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 0, 0, 1,
- 0, 0, 0, 0, -1, -1, -1, -1, -4, -4, -4, -4, -4, -4, -4, -3,
- -3, -3, -2, -3, -2, -1, -1, 0, 3, 4, 4, 5, 5, 6, 6, 7,
- -1, -2, 7, -2, -4, -1, -1, 0, -1, -2, 9, -1, -4, -1, -1, 0,
- -1, -3, 10, -1, -4, -1, -1, 1, -1, -3, 10, -2, -3, -1, -1, 2,
- -1, -2, 10, -2, -4, -1, -1, 2, -1, -2, 9, -2, -4, -1, -1, 2,
- -1, -2, 8, -2, -4, 0, -1, 1, 0, -2, 7, -2, -3, -1, 0, 2,
- 3, -4, 1, 3, -3, -2, 1, 0, 3, -5, 1, 4, -3, -2, 1, 0,
- 3, -6, 2, 5, -3, -1, 3, 0, 3, -6, 2, 5, -3, -1, 2, 0,
- 3, -6, 1, 5, -4, -2, 3, 0, 3, -6, 1, 5, -3, -2, 2, 0,
- 2, -6, 1, 4, -3, -1, 1, 0, 2, -6, 1, 4, -2, -1, 1, 0,
- 0, 0, 1, 1, 1, 0, 0, 2, 0, -1, 1, 1, 1, 0, 0, 2,
- 0, -1, 0, 0, 0, 0, 0, 2, 0, -1, 0, 0, 0, 0, -1, 0,
- 1, 0, 1, 0, 0, -1, -2, -1, 3, 1, 1, 0, 0, -2, -4, -3,
- 5, 3, 2, 1, 0, -3, -5, -4, 5, 4, 2, 0, -1, -4, -5, -5,
- 1, 0, -1, -2, -2, -3, -6, -9, 2, 0, -1, -1, 0, 0, -3, -6,
- 1, 0, 0, -1, 0, 0, -2, -5, 2, 1, 1, 1, 1, 2, -1, -3,
- 1, 1, 2, 1, 2, 2, 1, -1, 1, 1, 2, 1, 1, 1, 1, 1,
- 0, 0, 2, 1, 0, 0, 2, 2, 0, 1, 2, 2, 0, 0, 2, 2,
- -4, -3, 0, 1, 4, 6, 4, 3, -3, -2, 0, 0, 2, 4, 1, 0,
- -1, -1, 0, 0, 1, 1, -2, -3, 1, 1, 1, 0, 1, 1, -3, -5,
- 1, 1, 1, 0, 1, 1, -3, -5, -1, 0, 0, -1, 1, 1, -2, -4,
- -1, 0, 0, -1, 1, 2, 0, -2, -1, 0, 0, 0, 2, 3, 1, 0,
- -1, 0, 3, 4, 0, -4, -5, -5, 0, 0, 4, 5, 2, -2, -3, -2,
- 0, -1, 2, 4, 2, -1, -1, 0, 0, -2, -1, 1, 0, -2, 0, 1,
- 1, -2, -2, 0, 0, -1, -1, 1, 1, -2, -3, 0, 1, 0, -1, 0,
- 1, -2, -2, 1, 3, 1, 0, 0, 1, -2, -1, 2, 4, 2, 0, 0,
- 1, 2, 3, 2, 0, 2, 2, 1, -1, 0, 1, 0, -3, 1, 1, 1,
- -1, 0, 0, -2, -4, 0, 2, 1, -1, 2, 2, -1, -5, 0, 2, 1,
- -1, 3, 4, -1, -5, 0, 2, 1, -2, 2, 4, 0, -4, -1, 0, 0,
- -4, 0, 2, 0, -4, -2, 0, 0, -5, -1, 2, 1, -2, 1, 3, 2,
- 1, 0, 1, 0, 1, 2, -1, -2, 2, 0, -1, -2, 1, 3, 0, -1,
- 3, 0, -2, -4, 0, 3, 1, 0, 5, 1, -3, -5, -2, 2, 1, 1,
- 6, 1, -2, -5, -2, 1, 0, 1, 5, 1, -1, -5, -2, 0, -1, 0,
- 3, 0, -2, -4, -2, 0, -1, 0, 1, -1, 0, -2, 0, 1, 0, 1,
- 1, 1, 2, 3, 2, 1, 1, 2, -1, -1, 0, 1, 1, 0, 1, 1,
- -4, -3, 0, 0, 1, 1, 1, 2, -4, -3, 0, 2, 2, 2, 3, 2,
- -5, -4, 0, 1, 1, 1, 1, 2, -5, -4, -1, -1, -2, -2, -1, 0,
- -3, -2, 0, 0, -2, -3, -2, -1, 2, 3, 4, 4, 2, 0, 0, 0,
- -4, -2, 0, 1, 0, 0, 0, 0, -3, -1, 1, 1, 0, 0, 0, 0,
- -2, 0, 2, 2, 0, 0, 0, 2, -1, 1, 2, 1, -1, 0, 3, 5,
- 0, 2, 1, -1, -2, 0, 5, 6, 0, 1, 0, -3, -3, 0, 4, 6,
- 1, 1, -2, -4, -4, -3, 1, 2, 1, 0, -2, -4, -5, -4, -2, 0,
- -1, -3, -3, -3, -3, -2, -1, -1, 3, 2, 1, 0, 0, 1, 1, 1,
- 5, 4, 3, 2, 1, 1, 2, 2, 2, 1, 0, -2, -2, -2, -1, -1,
- 0, 0, 0, -1, -2, -2, -2, -2, 0, 1, 3, 3, 2, 1, -1, -1,
- 0, 1, 3, 4, 3, 2, 1, -1, -4, -3, -1, 1, 0, -2, -3, -3,
- -3, -4, -7, -8, -7, -4, -1, 2, 0, -1, -3, -4, -4, -2, 0, 2,
- 1, 0, 0, -1, -3, -2, 0, 2, 2, 1, 1, 0, -1, -1, 0, 2,
- 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 1, 2, 3, 3, 2, 2, 0, 0, 1, 3, 4, 4, 3, 2,
- 3, 3, 3, 0, -1, 0, 1, 2, 1, 1, 1, -1, -2, -1, -1, 1,
- -2, -2, -1, -3, -3, -2, -2, 0, -4, -4, -2, -2, -2, -2, -3, 0,
- -4, -4, -1, 1, 1, 0, -1, 2, -3, -1, 2, 3, 4, 3, 3, 5,
- -2, 0, 2, 3, 3, 3, 3, 3, -2, -2, 0, 0, 0, 0, 0, 1,
- 0, 2, 1, -1, -3, -1, 3, -2, -1, 0, -1, -1, -3, 0, 4, -2,
- -2, -2, -2, -2, -2, 1, 5, -2, -3, -2, -3, -1, -2, 1, 4, -3,
- -2, 0, -1, 0, -1, 0, 3, -5, 1, 2, 1, 2, 0, 0, 2, -5,
- 2, 4, 2, 3, 1, 1, 3, -3, 1, 2, 1, 1, 0, 1, 4, -2,
- 4, -3, -4, -1, 3, 3, 1, 3, 4, -4, -4, -1, 3, 2, 0, 2,
- 4, -3, -4, 0, 2, 2, -1, 1, 4, -3, -2, 1, 2, 1, -2, 0,
- 2, -4, -2, 1, 2, 0, -3, 0, 2, -3, -2, 0, 1, 0, -2, 2,
- 3, -1, -1, 0, 0, 0, 0, 3, 2, -2, -2, -2, -1, -1, -1, 2,
- 2, 2, 3, 4, 3, 1, 0, -1, 1, 0, 1, 2, 1, -1, -2, -2,
- 2, 1, 2, 1, 1, 0, -1, -1, 4, 3, 4, 3, 2, 1, 1, 1,
- 3, 2, 2, 2, 1, 1, 1, 1, -1, -2, -1, 0, -1, -1, -1, -1,
- -3, -3, -2, -1, -2, -2, -2, -2, -4, -4, -3, -3, -4, -4, -3, -3,
- 2, 1, -1, -3, -4, -2, 3, 4, 2, 2, 1, -1, -3, -2, 1, 2,
- 1, 2, 3, 3, 0, -2, -1, -2, -1, 0, 2, 4, 2, 0, -1, -3,
- -2, -2, 0, 3, 3, 2, 0, -3, 0, -2, -3, -1, 1, 2, 2, -1,
- 3, -1, -4, -5, -3, 0, 2, 0, 6, 3, -2, -6, -5, 0, 3, 1,
- -2, 3, -2, 0, 3, -2, -2, 1, -3, 4, -3, 0, 3, -2, -1, 2,
- -3, 5, -3, 0, 4, -2, -1, 2, -2, 4, -4, -1, 3, -3, -2, 2,
- -3, 4, -3, 0, 3, -3, -1, 2, -2, 5, -2, 0, 3, -3, -1, 2,
- -2, 4, -3, 1, 3, -2, -1, 2, -2, 3, -2, 1, 3, -2, 0, 2,
- 1, 0, 0, -1, 1, 2, -4, -1, 2, 0, 0, -1, 1, 2, -4, -2,
- 1, 1, 1, -1, 2, 4, -2, 0, 0, -1, 1, -1, 2, 5, -1, 1,
- 0, -1, 0, -2, 1, 5, -1, 1, 0, -1, -1, -2, 0, 3, -3, -1,
- 1, 1, 0, -2, 0, 3, -3, -1, 1, 1, 0, -3, 0, 3, -2, 0,
- 1, 0, -1, 1, 1, 2, 4, 5, 1, 0, -1, 1, 1, 1, 5, 7,
- 0, 0, -2, -1, -1, 0, 3, 5, 0, -1, -2, -1, -1, -1, 2, 3,
- 0, -1, -3, -1, -1, -1, 1, 2, -1, -2, -4, -2, -2, -2, 0, 0,
- -1, -2, -2, -1, -2, -2, 0, 0, 0, -1, -1, 0, -1, -1, 0, 0,
- 3, 3, 0, -1, -1, 1, 4, 4, 2, 3, 0, -2, -2, 0, 1, 1,
- 2, 3, 1, -1, -1, 0, 1, 0, 1, 2, 0, -1, -1, -1, 0, -2,
- 0, 1, 0, -1, -2, -1, 0, -2, 0, 1, 0, -1, -2, -1, 1, 0,
- 1, 1, -1, -3, -4, -3, 1, 3, 1, 2, -1, -3, -5, -4, 1, 3,
- -3, -2, 0, 1, 1, 1, 0, -2, 0, 1, 1, 1, 0, 0, -1, -3,
- 1, 2, 1, 1, 0, -1, -1, -2, 0, -1, -3, -1, -1, -1, 0, -1,
- 0, -3, -6, -3, -2, -1, 1, 1, 2, -1, -4, -3, -2, 0, 2, 2,
- 5, 4, 1, 1, 0, 1, 3, 2, 5, 4, 2, 1, 0, -1, 0, 1,
- -2, 0, -2, -5, -6, -3, 0, 0, -2, 0, 1, 0, -1, 1, 2, 2,
- -2, 0, 1, 3, 2, 2, 2, 1, -2, 0, 2, 4, 3, 2, 1, 1,
- -2, 0, 2, 3, 2, 0, -1, 0, -3, -1, 1, 1, 0, -1, -1, 1,
- -4, -1, 1, 0, -1, -2, 0, 2, -4, -1, 0, -1, -1, -2, 1, 4,
- -3, 0, 0, -1, 1, 1, 1, 0, -3, 1, 0, -1, 0, 0, -1, -1,
- -1, 3, 3, 0, 1, 0, 0, 1, -3, 2, 2, -2, -1, 0, 0, 1,
- -5, 0, 0, -2, -1, 1, 0, 2, -7, -2, 1, 0, 1, 2, 2, 2,
- -5, 0, 3, 2, 3, 3, 2, 2, -3, 2, 4, 1, 0, 0, -2, -3,
- 5, 2, -2, -2, 0, -1, -1, -1, 2, -1, -4, -3, -1, -2, -1, -1,
- 0, -2, -2, 1, 2, -1, 0, 1, -1, -2, -1, 3, 3, -1, 0, 2,
- 1, 0, 0, 3, 3, -2, -1, 2, 2, 1, 1, 3, 2, -2, -2, 0,
- 1, 0, -1, 1, 1, -3, -3, -2, 1, 0, 1, 2, 3, 0, 0, 0,
- -4, -5, -3, 0, 1, -1, -2, -1, -2, -3, -1, 1, 2, 0, 0, 0,
- 1, 1, 2, 1, 2, 1, 1, 1, 3, 4, 3, 1, 0, -2, -1, -1,
- 3, 3, 2, 0, -2, -3, -3, -2, 1, 1, 0, -1, -2, -4, -2, -2,
- 2, 1, 0, 0, 0, -1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 3,
- 0, 0, 0, -1, -2, -1, 1, 0, -2, -1, -1, -2, -3, -2, 0, 0,
- -1, 0, 0, -1, -2, 0, 1, 1, 1, 1, 0, -1, -1, 1, 3, 1,
- 2, 2, 0, -2, -1, 2, 3, 0, 3, 1, -1, -1, 1, 4, 2, -2,
- 2, 0, -3, -1, 3, 5, 0, -5, 1, -1, -2, 0, 3, 3, -1, -6,
- -1, 0, 3, 4, 2, 0, 1, 2, -2, -1, 0, 1, -1, -2, 0, 1,
- -2, -3, -2, -3, -6, -7, -6, -3, 2, 2, 3, 1, -1, -2, -3, -2,
- 2, 2, 3, 1, 0, 0, 0, 0, 2, 1, 1, 0, 1, 1, 0, 1,
- 1, 0, 0, 0, 0, 1, 1, 2, 1, 0, -1, 0, 0, 2, 2, 1,
- 1, 1, 3, 1, -1, -1, -1, 1, -2, -1, 0, 0, -2, -2, -1, 2,
- -2, -2, 1, 1, 1, 0, 1, 3, -2, -2, 0, -1, 0, -1, 0, 2,
- 0, 0, 1, 0, -1, -1, -2, 1, 3, 2, 2, 1, 0, -2, -2, 1,
- 5, 3, 3, 2, 1, 1, 1, 4, 0, -3, -4, -5, -4, -3, -1, 1,
- -6, -4, -1, 2, 2, 0, 0, -1, -4, -2, 1, 3, 3, 2, 2, 0,
- -3, -2, -1, 2, 3, 3, 2, 0, -3, -2, -2, 1, 2, 1, 1, -1,
- -2, -2, -2, 0, 2, 2, 1, -1, -1, -1, -1, 1, 2, 3, 2, 0,
- -1, -1, -2, 1, 2, 2, 2, -1, 0, -1, -2, 0, 2, 1, 0, -1,
- 6, 4, 2, 1, 0, 0, 0, 1, 4, 2, -1, -2, -2, -2, -1, -1,
- 2, 1, -1, -2, -2, -2, -2, -1, 2, 2, 0, -2, -2, -2, -1, 0,
- 0, 0, -1, -2, -2, -1, 0, 1, -3, -3, -2, -1, -1, -2, -1, 0,
- -3, -2, 2, 3, 2, 0, -1, -2, -2, 0, 4, 5, 5, 2, 0, -1,
- 5, 4, 2, 0, -1, -2, -1, -1, 4, 3, 2, 1, 0, -1, 0, -1,
- 1, 1, 0, 1, 1, 0, 1, -1, -2, -1, -1, 0, 0, -2, -2, -3,
- -1, 0, 0, 0, -1, -3, -3, -5, 0, 1, 1, -1, -1, -2, -2, -3,
- -1, -1, -1, -2, -1, 1, 3, 1, -1, -2, -2, -1, 2, 5, 6, 5,
- -3, -3, -2, 1, 1, -2, -1, -1, 1, 2, 3, 4, 1, -3, -1, -3,
- 3, 2, 0, 1, -1, -3, -1, -3, 1, 0, -1, 0, -1, -1, 1, 0,
- 1, 1, 0, 1, 2, 2, 5, 3, 1, 1, 1, 2, 2, 2, 3, 0,
- -3, -1, -2, -2, -3, -3, -1, -3, -1, 1, 1, 0, -1, -1, 0, -2,
- 2, 0, -2, -2, 2, 4, 1, -2, 1, 0, -2, -1, 3, 5, 2, -1,
- -1, -2, -3, -2, 1, 3, 1, -2, -1, -2, -1, -1, 0, 2, 1, -1,
- 0, 0, 1, 1, 1, 2, 2, 0, 0, 1, 4, 4, 2, 2, 3, 1,
- -2, -1, 2, 1, -2, -3, -2, -3, -1, 0, 1, 0, -3, -4, -4, -5,
- 4, 0, -3, -4, -4, -4, -2, -1, 5, 0, -1, 0, -1, -3, -2, -1,
- 4, 0, 0, 1, 1, 0, 0, 0, 0, -3, -2, -1, 0, 0, 1, 0,
- 0, -2, 0, 0, 1, 1, 2, 1, 2, 0, 0, 0, 1, 1, 1, 0,
- 2, 0, -1, -1, 1, 1, 1, 0, 1, -1, -2, -2, 0, 2, 2, 2,
- -3, -5, -2, 0, -1, -3, -3, 0, 0, -2, 0, 2, 2, 0, 0, 3,
- 2, -1, -2, 0, 0, -1, -1, 2, 5, 2, -1, -1, -1, -1, -1, 2,
- 5, 2, 0, -1, -1, 0, -1, 2, 2, 1, 0, 0, 0, 1, 0, 2,
- -1, -1, 1, 1, 2, 2, 1, 2, -3, -2, 0, 0, 0, 0, -2, -1,
- 0, 3, 2, 0, -2, -3, -3, -3, 0, 3, 3, 1, 0, 0, 1, 2,
- -1, 0, -1, -2, -1, -1, 1, 3, -1, 0, -1, -2, -1, -1, 0, 2,
- -1, 0, -1, -2, 0, 0, -1, 2, -1, 0, -1, -2, -1, -1, -2, 1,
- 0, 1, 0, -3, -1, -1, -1, 2, 5, 5, 2, -1, -1, -1, 1, 3,
- 0, 0, 1, -1, -3, -2, 0, 2, 1, 1, 3, 0, -2, -2, 0, 1,
- 1, 1, 3, 1, 0, 0, -1, -1, 0, -1, 2, 1, 1, 0, -1, -3,
- -1, -2, 1, 1, 1, 0, -2, -4, -1, 0, 2, 1, 1, 0, -1, -3,
- 1, 1, 3, 2, 1, 0, -2, -3, 2, 2, 4, 2, 1, -1, -2, -4,
- 1, 2, 2, 2, 0, -2, 0, 2, -1, -1, -2, -3, -4, -5, -3, 1,
- 0, 1, 1, 0, -1, -1, -1, 1, 0, 1, 1, 1, 0, 0, 0, 2,
- 0, 1, 1, 2, 1, 1, 1, 2, -1, -1, 0, 2, 2, 2, 2, 3,
- -2, -4, -4, -1, -2, -2, -2, 0, 1, 0, 0, 1, 0, 0, 0, 1,
- 0, -1, -3, -2, 0, 2, 2, 1, 0, -1, -2, -3, 0, 1, 1, 2,
- 1, 0, -2, -3, -1, 0, 0, 1, -1, 0, -1, -2, 0, 0, -1, 0,
- -1, 1, 1, 0, 2, 2, 0, 0, 0, 2, 3, 1, 3, 5, 3, 2,
- -1, 1, 1, -2, 0, 3, 1, 1, -1, 0, 0, -4, -4, -1, -1, -1,
- -1, 1, 1, 0, 1, 2, 1, 2, -3, 0, 1, 0, 1, 1, 0, 2,
- -5, -3, -1, -1, 0, 1, 0, 1, -4, -3, -2, -3, -2, -1, -1, 0,
- 0, 0, -1, -2, -2, -2, -2, 0, 3, 4, 2, 0, 0, 0, 0, 1,
- 2, 1, 0, 0, 0, 0, -1, 0, 0, 1, 2, 3, 4, 4, 3, 2,
- -1, 4, 7, 4, 0, 0, 0, 0, -1, 4, 6, 3, 0, 1, 1, 1,
- 0, 3, 4, 0, -1, 0, 0, 1, 0, 1, 1, -2, -1, 0, -1, -1,
- -1, 0, -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
- -1, -3, -3, 0, 1, -1, -2, -1, -3, -4, -4, -2, -1, -2, -2, -1,
- 2, 2, 1, 0, 1, 1, 0, -3, -2, -1, 0, 0, 1, 1, 0, -3,
- -2, -1, 0, 1, 2, 1, 1, -2, 1, 2, 2, 2, 3, 3, 2, -1,
- 1, 2, 1, 0, 1, 1, 2, -1, 0, 1, -2, -4, -2, 0, 1, -1,
- 1, 1, -1, -3, -2, 0, -1, -3, 1, 2, 0, -1, 0, 1, -1, -4,
- -1, -1, -2, -2, 0, 3, 4, 3, 1, 1, -1, -3, -2, 0, 0, 0,
- 2, 2, 2, 2, 2, 1, -1, -1, 1, 1, 1, 3, 3, 0, -2, -2,
- 0, -1, -1, -1, 0, -2, -1, -1, -1, -3, -4, -3, -2, -2, 0, 2,
- -1, -1, 0, 1, 2, 2, 3, 5, -2, -1, -1, 0, 0, 0, 0, 1,
- -2, -3, 2, 0, 0, 1, 1, -1, -1, -4, 1, -2, -1, 2, 2, 0,
- 1, -4, 0, -2, -2, 1, 1, -1, 2, -3, 1, -1, -1, 1, 1, -1,
- 3, -2, 3, 1, 0, 1, 1, -1, 1, -3, 2, 1, 0, 1, 0, -1,
- -1, -5, 1, 0, -1, 0, 1, 1, 0, -3, 3, 3, 1, 2, 3, 3,
- 0, -1, -2, 1, 5, 5, 2, -1, 1, -1, -2, -1, 1, 1, -2, -5,
- 1, 1, -1, -2, -1, -1, -1, -3, 1, 1, -1, -1, -1, 2, 4, 3,
- -1, -1, -1, -1, -1, 0, 4, 3, -1, -1, 0, 1, -1, -3, -1, -1,
- 0, 0, 0, 2, 2, 0, 0, -1, 0, -2, -3, 0, 1, 1, 3, 2,
- 2, 3, 2, 1, 0, 0, -2, -2, 2, 3, 0, 1, 1, 3, 3, 2,
- 0, 0, -3, -1, -1, 2, 2, 3, -2, -2, -3, 1, 1, 2, 1, 1,
- -2, -1, -2, 2, 1, 1, -1, -2, 0, 1, 0, 2, 0, 0, -2, -2,
- 0, 1, 0, 2, 0, 0, -2, -2, -3, -2, -2, 0, -1, -2, -2, -3,
- 0, 1, -1, 3, -1, 1, 3, -1, 0, 1, -1, 3, -1, -1, 2, -3,
- 1, 1, -2, 3, -1, -3, 0, -3, 2, 2, -2, 3, 0, -2, 1, -2,
- 1, 1, -3, 3, -1, -2, 1, -3, 1, 1, -3, 3, 0, -1, 1, -2,
- 1, 2, -1, 4, 0, -1, 1, -2, 0, 1, -1, 3, -1, -3, 0, -3,
- -3, -3, -1, 1, 2, 1, -1, -2, -2, -2, 0, 2, 1, 0, -2, -2,
- -3, -2, 1, 2, 1, -1, -2, -1, -3, -2, 2, 4, 0, -2, -2, 1,
- -3, -1, 2, 4, 0, -2, -2, 2, -1, 1, 4, 3, -1, -3, -2, 2,
- 0, 2, 4, 2, -1, -2, -1, 2, 0, 1, 2, 0, -1, 0, 1, 3,
- 3, 0, -5, 1, 4, 0, 0, 1, 1, -2, -5, 2, 5, -1, -2, 1,
- -1, 0, 0, 3, 3, 1, 0, -1, -2, 3, 4, -2, -3, -1, 0, -2,
- -3, 3, 5, -3, -3, 0, 0, -2, -1, 3, 2, -2, -2, 2, 2, -1,
- 2, 0, 0, -1, 0, 0, 0, 0, 0, -3, -2, 1, 3, 0, -2, -2
-};
-
-/* list of codebooks for inter-coded vectors */
-static const uint8_t* const svq1_inter_codebooks[4] = {
- svq1_inter_codebook_4x2, svq1_inter_codebook_4x4,
- svq1_inter_codebook_8x4, svq1_inter_codebook_8x8
-};
-
-/* 6x16-entry codebook for intra-coded 4x2 vectors */
-static const int8_t svq1_intra_codebook_4x2[768] = {
- 12, 13, 13, 11, -7,-10,-15,-17,-16,-15,-12,-10, 11, 15, 15, 12,
- 2, 17, 20, 15,-45,-24, 2, 13, 21, 20, -6,-36, 12, 16, -1,-27,
- -18,-21, 10, 45,-11,-20, -7, 21, 43, -8,-28, 0, 33,-16,-28, 3,
- -12,-18,-18, -6,-20,-10, 28, 55, -5,-18,-21,-18, 56, 30, -6,-20,
- -34, 27, 29,-22,-30, 29, 26,-25, 30, 34, 33, 26,-25,-31,-35,-33,
- -31,-35,-36,-32, 29, 36, 37, 31,-71,-12, 38, 34,-63, -1, 42, 33,
- 58, 37,-31,-60, 55, 34,-33,-61,-57,-57, 22, 93,-57,-58, 21, 93,
- 59, 69, 70, 62,-63,-68,-68,-60,-64,-71,-71,-64, 63, 73, 72, 62,
- -2, 0, 7, 15,-11,-10, -3, 5, -5, -8,-10,-10, 1, 9, 14, 9,
- 15, 8, -4,-11, 12, 2,-11,-12, -8, 0, 19, 28, 4, -1,-15,-26,
- -15, 27, 2,-14,-14, 22, 1, -9, -4, -6,-13,-10, -6,-14, 6, 47,
- -35,-20, 6, 23, 6, 9, 6, 4, -6, 2, 23,-22, -7, 4, 28,-21,
- 20,-22, -2, 6, 22,-28, -5, 8,-10,-18,-16,-12, 36, 19, 2, -1,
- -3, 0, 4, 8,-45,-10, 23, 23, 40, 15,-20,-35, -4, -1, 4, 1,
- 9, -5,-33, 24, 8, 3,-26, 19, -1, 4, 6, -3, 32, 25,-13,-49,
- 24, 24, 15, 7,-17,-27,-19, -7,-47, 0, 39, 24,-21, -6, 7, 4,
- -1, 0,-10,-13, 1, 1, 5, 16, 20, 5, -3, -9, -1, -4, -2, -6,
- -17, -7, 1, 4, 12, 7, 0, 0, 3, 0, 12, 11, -3, 1, 0,-23,
- 4, 17, -6, 0, 6, 3,-25, 0,-17, 10, 8, 5,-14, 4, 1, 4,
- 13, 10, 4, 2,-23, -9, 1, 2, 3, -3, 1, 7, 1,-23, -7, 20,
- -7,-18, 2, 12, -5, -4, 10, 9, 4, 10, 7,-24, 6, 3, 4,-10,
- 22,-14,-22, 6, 0, 5, 5, -1, -4, 3,-11, -4, -7, 31, 7,-14,
- -5,-16, -1, 42, -4, -2, -9, -5, 5, -8, -6, -3, 42, -4,-21, -5,
- -18, 12, 20,-12, 13,-13,-10, 7, -8, -9, -2,-18,-16, 6, 40, 8,
- 10, -1, 0, 4, -3, 4, -1,-13, -2, 6, 1,-15, 5, 3, 1, 2,
- -4, -2, 1, 3, 15, 0, -9, -4, -3, -4, -4, -4, -3, 5, 16, -3,
- 2, 13, 3, 4, -3, -8,-10, 0, -6, -2, -4, -1, -2, -3, -6, 23,
- 6, -6, 7, 1, 4,-18, 5, 1, -1, 1,-15, 14, -5, 6, -4, 4,
- 2, 2, 2, 6,-24, 2, 7, 3,-26, 0, 3, 3, 5, 7, 1, 6,
- 14, -2,-18, -3, 7, 5, -4, 2, -6, 3, 32, 1, -6, -6, -6,-12,
- 5,-36, 7, 6, 9, -1, 11, 0, 4, 4, 5, 3, 4, 15, 3,-38,
- 10, 23, -5,-42, 0, 4, 4, 4, 23, 17, -6,-13,-13,-37, 1, 29,
- 5,-14, -1, 1, 5, 0, 3, 1, 0, 4, -5, 2, 8, 0, 0,-10,
- 4, 7, -2, -3,-10, 3, 1, 1,-12, -1, 13, 3, 0, -1, 1, -3,
- 0, -1, 3, 1, -6, -9, 3, 9, -6, 1, -4, -6, 8, -1, 0, 8,
- -3, -3, 0, 18, -5, -1, -4, -1, -8, -2, 3, -4, 0, 17, -1, -5,
- 5, -2, 9,-10, 1, -5, 6, -5, 4, 2, 2, 3, 10,-14, -8, 1,
- -1, -2,-18, -1, -1, 20, 1, 2, -1, 1, -9, 1, -1, -9, 22, -4,
- 6, -4, 8, -3, -1, 7,-19, 5, -7, 31, -4, -4, -6, 0, -5, -5,
- -7, -8,-19, -4, 1, 1, 4, 32, 38, -1, -8, 4, -7, -8, -6,-12,
- -1, 0, -7, 1, -1, 9, -1, 0, 9, -1, -1, 0, 2, -6, 1, -3,
- -12, 0, 2, 1, 1, 1, 8, 0, 9, 1, 0, 2, -2, 1,-11, 0,
- 0, 8, 2,-10, -1, 2, -1, 0, -2, -4, 0, -5, -2, -1, -1, 14,
- -3, 7, -1, 5, 0,-10, 1, 1, -1, -5, 14, -1, -2, 1, -3, -2,
- -6, 0, 0, 6, 2, 3, -9, 4, 4, -5, -1, -1, -7, 3, 8, -1,
- 2, -4, -1,-11, 11, 2, 1, 0, -1, 2, 3, 9, 0, 2, 0,-15,
- 3, 5,-20, 3, 3, -1, 3, 3, 1, -1, 16, 1, 2,-29, 9, 2,
- -13, -6, -1, -3, 36, -1, -8, -3, 2, 5, 4, 2,-37, 9, 11, 3
-};
-
-/* 6x16-entry codebook for intra-coded 4x4 vectors */
-static const int8_t svq1_intra_codebook_4x4[1536] = {
- -11, -3, 3, 6,-10, -1, 5, 7, -9, -1, 6, 7, -9, -1, 4, 6,
- 5, 7, 0,-14, 6, 9, 2,-15, 6, 9, 2,-15, 4, 6, 0,-14,
- 16, 3, -5, -6, 16, 1, -8, -8, 14, -1, -9, -9, 12, 0, -8, -8,
- 8, 12, 16, 17, -2, 2, 6, 9,-10, -8, -4, 0,-15,-14,-11, -7,
- -7,-10, -2, 16, -7,-11, -3, 18, -7,-11, -1, 20, -6, -8, 1, 19,
- -9,-13,-16,-17, 2, -2, -7, -9, 11, 8, 4, -1, 16, 15, 11, 7,
- -22, -2, 13, 15,-24, -2, 14, 16,-25, -4, 13, 15,-25, -6, 10, 13,
- 26, 26, 22, 16, 17, 15, 9, 3, -2, -6,-11,-14,-20,-25,-28,-28,
- -27,-27,-25,-21,-16,-15,-11, -7, 3, 8, 12, 13, 23, 28, 31, 30,
- 20, 16, -7,-33, 22, 19, -6,-35, 22, 19, -6,-34, 20, 17, -6,-32,
- -20,-20, 2, 38,-21,-22, 2, 40,-21,-22, 2, 40,-20,-20, 3, 38,
- -47, -4, 24, 26,-50, -3, 26, 27,-50, -3, 26, 27,-47, -4, 24, 26,
- 45, 6,-23,-27, 48, 5,-25,-28, 48, 5,-26,-28, 44, 6,-24,-27,
- -30,-36,-10, 76,-31,-37,-11, 78,-31,-37,-11, 78,-31,-36,-10, 77,
- -53,-32, 35, 52,-54,-34, 36, 52,-54,-34, 36, 52,-53,-33, 34, 51,
- -93,-34, 62, 65,-93,-34, 62, 66,-93,-34, 62, 65,-93,-34, 60, 64,
- -7, 0, 2, 2, -8, -1, 3, 3, -8, 0, 4, 5, -6, 1, 5, 5,
- 3, 7, 11, 11, 2, 2, 3, 3, 1, -2, -6, -7, 1, -5,-11,-13,
- 3, -2, -4, -3, 7, 0, -5, -5, 12, 4, -5, -7, 14, 6, -4, -7,
- 18, 14, 3, -2, 6, 4, 0, -3, -8, -5, -2, 0,-16,-11, -2, 2,
- -8, -6, 7, 18, -7, -8, 2, 13, -4, -6, -2, 6, 0, -4, -3, 1,
- 1, -3,-13,-18, 0, -1, -5, -7, -1, 1, 6, 7, -2, 4, 15, 17,
- -15,-14, -7, -2, -6, -5, -1, 0, 6, 6, 3, 1, 15, 13, 6, 1,
- 2, -2,-11, 10, 2, -1,-12, 11, 3, -1,-12, 11, 2, -2,-11, 11,
- -9, 14, -1, -5, -9, 15, -2, -5, -8, 16, -2, -5, -7, 15, -1, -4,
- 2, 6, 8, 8, -2, 3, 9, 12,-11, -5, 4, 10,-19,-16, -8, 0,
- 14, 8, -7,-15, 12, 7, -7,-14, 8, 5, -4, -9, 5, 3, -1, -4,
- 12,-14, -2, 2, 13,-15, -1, 3, 14,-15, -1, 3, 13,-14, -1, 3,
- 0, 6, 10,-13, 0, 6, 10,-15, 0, 7, 9,-17, 1, 6, 8,-16,
- -8, -5, 15, -2, -8, -6, 17, -2, -8, -6, 16, -3, -8, -5, 15, -2,
- -9,-11,-11,-10, 9, 10, 9, 8, 8, 10, 10, 9, -8, -9, -8, -7,
- 9, 10, 9, 7, -8,-10,-10,-10, -7,-10,-11,-11, 11, 12, 11, 8,
- 0, 10, 7, 0, 0, 7, 0, -6, 0, 2, -5, -6, -2, -1, -4, -1,
- 5, 0, -6, -9, 2, 2, 2, 1, -2, 0, 5, 7, -6, -5, 1, 4,
- 3, -8, 2, -1, 4, -9, 3, 0, 5, -7, 3, 0, 7, -5, 3, 0,
- -5, -3, 2, 9, -6, -3, 1, 8, -6, -3, 1, 7, -5, -2, 0, 4,
- 13, 8, 3, 1, -3, -5, -4, -1, -8, -7, -3, 0, -1, 1, 3, 2,
- 3, 2, -5,-12, 4, 3, -2, -9, 3, 4, 1, -4, 3, 5, 4, -1,
- -9, -8, -4, 0, 8, 6, 2, 0, 10, 8, 3, 0, -6, -5, -3, -1,
- -3, -9,-12, -5, 0, -3, -5, 0, 2, 3, 2, 4, 5, 8, 7, 6,
- -1, -2, 5, 12, -1, -1, 5, 9, 2, 1, -1, -2, 2, -1,-11,-17,
- -7, 3, 3, -1, -9, 3, 4, -1,-10, 4, 6, -1, -9, 5, 7, 0,
- -18, -7, 2, 2, -8, 1, 5, 3, 3, 4, 1, 0, 9, 5, -2, -3,
- -2, 0, 6, 8, -4, -5, -5, -3, 1, -2, -6, -8, 10, 9, 3, -1,
- 0, -2, -2, 0, 0, -4, -5, 0, -2, -8, -4, 8, -5, -7, 6, 24,
- 9, 1, -7, 1, 9, 1, -8, 1, 8, 0,-10, 1, 8, -1,-11, -1,
- 8, 8, 6, 3, 5, 4, 3, 2, -2, -3, -1, 0,-10,-13, -8, -4,
- 0, 4, 2, -3, 0, 6, 3, -5, 3, 10, 2,-12, 5, 10, -4,-22,
- 0, -4, -1, 3, 1, -4, -1, 5, 1, -5, 0, 8, -1, -6, -2, 7,
- -1, -1, -2, -4, -1, -2, -4, -6, -1, -1, -1, -2, 1, 5, 10, 9,
- 10, 3, 0, -2, 6, -1, -2, -5, 3, -1, -2, -6, 2, 0, 0, -5,
- 6, 3, 0, 0, 6, 3, 1, 1, 4, -2, -2, 1, 0, -9, -9, -2,
- -11, -3, 1, 2, -6, 2, 4, 5, -3, 2, 3, 4, -2, 1, 1, 2,
- -6, -4, -1, -2, 2, -1, -1, -2, 10, 2, -2, -2, 11, 2, -4, -1,
- 6, 0, -2, 2, 3, 3, 0, 0, -6, 3, 3, 0,-17, -1, 5, 0,
- -1, 4, 10, 11, -3, -2, 0, 1, -3, -4, -5, -3, -1, -2, -2, -1,
- 2, -3, -9,-12, 3, 3, 3, 2, 2, 2, 4, 4, 2, 1, -1, -2,
- -2, 9, 5,-10, -3, 5, 5, -5, -2, 1, 2, 0, -1, -2, -2, 1,
- -2, -3, 7, -2, -1, -3, 7, -3, -1, -2, 8, -4, -2, -2, 7, -3,
- 1, -8, -3, 12, 2, -2, -2, 4, 1, 3, 0, -5, -1, 5, 2, -7,
- -1, 3, 1, -5, -7, -2, 3, 1, -2, -7, -2, 2, 20, 3, -5, -1,
- 5, 0, -3, -2, -7, -7, 0, 6, -6, 0, 7, 6, 2, 6, 0, -7,
- -2, 6, -7, 1, -2, 7, -8, 3, -2, 7, -7, 3, -1, 7, -6, 2,
- -5, -2, 5, 7, 4, 1, -4, -8, 6, 3, -2, -5, -7, -5, 3, 7,
- -1, -1, 6, 5, 0, -1, 1, -4, 2, 1, 0, -7, 1, 0, 0, -4,
- -8, 0, 3, 1, -2, 1, -1, -1, 1, -1, -3, 1, 1, -2, 1, 9,
- 5, 2, -3, -4, -1, 0, -1, -3, -3, 1, 3, 1, -4, 0, 4, 2,
- 2, -2, -2, 12, 0, -2, -5, 3, -1, 0, -3, 1, -3, -1, -2, 1,
- 1, 5, 3, 0, -6, -4, -2, 1, 0, -2, -2, 2, 6, 1, -4, -1,
- -3, -5, -5, -1, 3, 5, 5, 4, 0, 3, 1, -1, -2, 1, -2, -3,
- 2, -4, -5, -3, 4, -2, -3, -2, 6, 0, -1, -1, 7, 1, 0, 0,
- -3, -2, -2, 0, -2, -3, -5, -1, -2, 2, 0, -1, -1, 11, 9, -1,
- 0, 1, -1,-10, -1, 1, 0, -6, 1, 0, 1, 4, 2, -5, -1, 13,
- -2, 4, 5, 0, -5, 1, 6, 3, -6, -2, 3, 2, -5, -2, 0, -2,
- -1, 1, 1, -2, -1, -2, 0, 2, 5, 5, 5, 7, 0, -4, -8, -7,
- 0, 2, -1, -5, -1, 2, 2, -3, 0, 5, 3, -5, 3, 8, 2,-12,
- 8, 4, 0, -2, 10, -1, -4, -1, 3, -6, -3, 0, -4, -5, 0, 0,
- 0,-10, -4, 2, -1, -6, 3, 5, -1, -3, 6, 4, 0, -2, 4, 2,
- 0, 8, 1, -1, 0, 11, 1, -3, -1, 6, -2, -4, -3, -2, -7, -4,
- 0, -1, -1, -1, 4, 5, 6, 5, -5, -9, -8, -5, 2, 2, 3, 2,
- 0, 2, 6, 1, 2, 0, 3, 0, 1, -2, -1, -2, 0, -1, -3, -6,
- 0, 0, 2, 0, 4, 0, 2, 1, 5, -2, 0, 0, -2, -9, -1, 2,
- 0, 1, 0,-10, -1, 1, 8, 0, -1, -2, 4, 0, 1, -1, 2, -1,
- -3, -2, 2, -1, -3, -1, 2, -3, 0, -1, 1, 0, 8, 1, -1, 3,
- 0, 1, 1, 2, 0, -4, -2, 0, -1, -5, 1, -1, -2, -1, 11, 2,
- 1, 5, -2, -2, 0, 2, -4, 0, -2, 1, -5, 1, 0, 5, 0, 1,
- -5, -3, 0, 6, -4, 2, 0, 0, -3, 5, 1, 0, -3, 3, 0, 0,
- 3, -2, -3, 1, 1, -4, 0, 8, -2, -3, -2, 3, 1, 2, -1, -1,
- 1, 1, 0, 2, 2, 0, 1, 6, 1, -1, 2, 1, 0, 3, 0,-19,
- 1, -3, -2, 2, 6, 5, -2, -7, -3, 1, 3, 1, -1, -1, 0, 2,
- -8, -1, -1, -4, 1, 1, -1, 2, 4, 3, 2, 3, -5, 1, 3, 0,
- 0, 2, -1, 1, -3, 0, 0, 5, -5, -2, 0, 8, -4, -4, -4, 6,
- 1, 2, 1, 2, 2, 2, -3, 2, 4, 0, -9, 0, 7, 0,-11, 1,
- 0, 0, 0, -2, 3, 3, -1, -6, 4, 3, -3,-10, -1, 2, 6, 2,
- 7, -2, -3, 5, -4, 0, 3, -1, -4, 2, 1, -7, 2, -1, -1, 3,
- 3, 2, 2, 2, -5, -7, -7, -5, 5, 6, 4, 2, -2, -1, 0, 1
-};
-
-/* 6x16-entry codebook for intra-coded 8x4 vectors */
-static const int8_t svq1_intra_codebook_8x4[3072] = {
- 5, 6, 6, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 1, 2, 3,
- -3, -4, -4, -5, -5, -4, -3, -2, -4, -4, -4, -5, -4, -4, -3, -3,
- 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 3, 4, 4, 5, 5, 5,
- -1, 0, 1, 1, 2, 3, 4, 4, -9,-10, -9, -9, -8, -7, -6, -5,
- -4, -4, -5, -6, -6, -7, -7, -7, 0, -1, -2, -2, -3, -3, -4, -4,
- 4, 4, 3, 3, 2, 1, 1, 0, 7, 7, 7, 6, 6, 5, 4, 4,
- 2, 4, 5, 6, 4, 1, -3, -6, 3, 4, 5, 5, 4, 0, -5, -8,
- 2, 3, 4, 4, 2, -2, -7,-10, 2, 2, 2, 1, 0, -4, -9,-12,
- -9, -7, -3, 1, 4, 4, 3, 3,-10, -7, -2, 3, 5, 5, 3, 3,
- -9, -6, -2, 3, 6, 5, 4, 3, -8, -6, -1, 3, 4, 4, 3, 2,
- -5, -5, -5, -5, -3, 1, 4, 7, -5, -5, -5, -4, -2, 1, 6, 8,
- -4, -5, -4, -3, -1, 3, 8, 10, -3, -4, -3, -2, 1, 5, 9, 11,
- -2, -2, -2, -2, -2, -2, -2, -2, -4, -5, -5, -5, -5, -5, -5, -4,
- -3, -4, -4, -4, -4, -4, -4, -3, 9, 10, 10, 11, 11, 11, 10, 10,
- 7, 4, 1, -2, -4, -6, -9,-10, 9, 7, 3, 0, -2, -4, -8, -9,
- 11, 8, 4, 2, 0, -3, -6, -8, 11, 9, 5, 3, 1, -2, -5, -7,
- -13,-13,-13,-12,-11,-10, -8, -8, 0, 1, 2, 3, 4, 4, 4, 3,
- 3, 4, 5, 6, 6, 6, 5, 4, 3, 4, 4, 4, 3, 3, 3, 2,
- 10, 10, 11, 10, 9, 9, 8, 7, 6, 6, 6, 6, 5, 4, 3, 2,
- 0, 0, 0, -1, -2, -3, -4, -4,-10,-10,-11,-12,-13,-14,-14,-14,
- 16, 16, 17, 16, 15, 13, 12, 11, -1, -2, -3, -4, -4, -4, -4, -3,
- -4, -5, -6, -6, -6, -6, -6, -6, -5, -6, -6, -6, -6, -6, -5, -5,
- -13,-13,-13,-12,-11,-10, -8, -6, -9, -8, -7, -6, -4, -2, 0, 1,
- -2, -1, 1, 3, 5, 7, 8, 9, 5, 7, 9, 11, 13, 14, 15, 15,
- 16, 14, 11, 7, 2, -3, -7, -9, 14, 12, 8, 3, -1, -6, -9,-11,
- 11, 9, 4, 0, -4, -8,-11,-13, 8, 5, 1, -3, -6,-10,-12,-14,
- -18,-15, -9, -3, 1, 6, 9, 11,-17,-13, -7, -1, 3, 7, 11, 12,
- -15,-11, -5, 1, 5, 9, 12, 13,-13, -9, -3, 2, 5, 9, 11, 13,
- 22, 21, 19, 15, 10, 3, -4, -9, 20, 18, 15, 9, 2, -5,-12,-17,
- 16, 13, 8, 1, -7,-14,-20,-24, 10, 6, -1, -8,-15,-21,-25,-27,
- -25,-23,-20,-14, -7, 1, 9, 14,-23,-21,-16, -9, 0, 9, 16, 21,
- -20,-16,-10, -1, 8, 16, 22, 25,-15,-11, -3, 6, 14, 20, 25, 27,
- -4, -2, 0, 1, 2, 2, 2, 2, -5, -2, 0, 2, 3, 3, 3, 3,
- -6, -4, -1, 1, 2, 3, 3, 3, -7, -5, -2, 0, 1, 1, 2, 2,
- 2, 1, 1, 1, 1, 0, -2, -3, 3, 3, 2, 1, 0, -1, -3, -4,
- 4, 3, 2, 1, 0, -2, -4, -6, 5, 4, 3, 1, -1, -3, -5, -6,
- 5, 6, 6, 4, 2, 0, -2, -3, 3, 4, 4, 4, 3, 1, 0, -1,
- -2, -2, -1, -1, -1, -1, -2, -2, -5, -4, -3, -2, -2, -2, -3, -3,
- -1, -1, -1, -1, -1, -1, -1, -1, -3, -4, -4, -4, -3, -3, -3, -3,
- -1, -1, -1, -1, -1, -1, -1, -2, 5, 6, 6, 6, 6, 5, 4, 3,
- 4, 4, 4, 4, 4, 5, 6, 7, 0, -1, -1, -1, -1, 0, 1, 2,
- -2, -3, -3, -3, -3, -2, -1, 0, -3, -3, -4, -4, -4, -3, -2, -1,
- 0, -2, -4, -4, -2, 0, 2, 3, 0, -2, -3, -3, -1, 2, 4, 5,
- -1, -2, -4, -3, 0, 3, 5, 6, -2, -3, -4, -3, -1, 2, 4, 5,
- 9, 4, 0, -3, -3, -1, 0, 1, 8, 4, -1, -4, -3, -1, 1, 2,
- 6, 2, -3, -5, -4, -2, 0, 1, 5, 1, -3, -4, -4, -2, 0, 1,
- 5, 3, 1, -1, -4, -8,-10,-10, 3, 3, 2, 1, 0, -2, -3, -4,
- 1, 1, 1, 2, 3, 2, 1, 0, -1, 0, 1, 2, 3, 4, 3, 2,
- 0, 1, 2, 2, 1, -1, -3, -3, 0, 1, 1, 1, -1, -2, -4, -3,
- -3, -3, -3, -3, -3, -3, -1, 2, -4, -4, -3, 0, 3, 7, 12, 14,
- -5, -5, -6, -6, -6, -6, -6, -5, 2, 2, 2, 1, 0, 0, 0, 0,
- 4, 4, 3, 2, 1, 0, 0, 0, 6, 6, 5, 4, 2, 2, 1, 1,
- -7, -7, -6, -3, 0, 4, 7, 8, -1, -2, -3, -3, -2, -1, 1, 2,
- 3, 3, 1, -1, -2, -2, -2, -1, 6, 6, 4, 2, 0, -2, -2, -2,
- -6, -5, -2, 2, 5, 9, 11, 12, -4, -4, -2, 0, 2, 4, 5, 6,
- -3, -2, -2, -2, -2, -1, 0, 1, -2, -2, -2, -3, -3, -3, -3, -2,
- -7, -3, 1, 3, 3, 0, -3, -5, -6, -2, 3, 5, 4, 1, -3, -5,
- -5, -1, 4, 6, 5, 2, -3, -4, -4, 0, 5, 7, 6, 3, -1, -3,
- 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -3, -3, -3, -3, -2, -1,
- 6, 7, 8, 9, 9, 8, 7, 6, -4, -4, -5, -5, -6, -6, -5, -4,
- -9, -8, -6, -4, 0, 3, 6, 6, -5, -4, -1, 3, 5, 6, 5, 3,
- 1, 3, 6, 6, 4, 1, -2, -5, 6, 7, 5, 1, -3, -7,-10,-11,
- 10, 9, 5, 1, -3, -6, -6, -4, 5, 3, -1, -5, -6, -5, -2, 2,
- -2, -4, -6, -6, -4, 1, 6, 10, -6, -7, -7, -4, 1, 7, 11, 12,
- 6, 5, 3, 2, 0, 0, 0, 0, 2, 1, -1, -2, -3, -2, -1, -1,
- 0, -1, -2, -4, -4, -2, -1, 1, 0, 0, -1, -2, -1, 0, 2, 3,
- 0, -1, -2, -2, -2, -2, -1, -1, 5, 4, 2, 1, 0, 0, 0, 0,
- 6, 5, 3, 1, 0, 0, 0, 0, 2, 0, -2, -4, -4, -3, -2, -2,
- -7, -4, 0, 2, 2, 2, 2, 1, -7, -3, 0, 0, 0, 0, 0, 0,
- -4, -1, 1, 1, 0, 0, 0, 1, -1, 1, 2, 2, 2, 2, 3, 3,
- -2, 0, 2, 2, 1, 1, 1, 1, -1, 1, 2, 2, 1, 0, 0, -1,
- 0, 2, 4, 2, 0, -1, -2, -3, 1, 2, 3, 1, -2, -4, -6, -6,
- 1, 2, 2, 4, 5, 6, 4, 1, 0, -1, -1, -1, 0, 0, -2, -4,
- 0, 0, -1, -2, -2, -2, -4, -6, 2, 1, 0, 0, 1, 1, -1, -3,
- 1, 1, 1, 1, 1, 2, 3, 3, 0, 0, 1, 0, 1, 2, 4, 4,
- -1, -1, -1, -1, 0, 1, 2, 3, -4, -4, -5, -5, -5, -3, -1, 0,
- -6, -5, -5, -4, -3, -2, -1, -1, -1, 0, 0, 1, 1, 2, 3, 3,
- 0, 1, 1, 1, 2, 2, 3, 4, 0, 0, -1, -1, 0, 1, 2, 3,
- 0, 1, 1, 1, 0, 0, -1, -1, 1, 3, 3, 2, 1, -1, -2, -2,
- -2, 0, 2, 2, 2, 2, 1, 1, -9, -8, -4, -2, 1, 3, 3, 3,
- -1, -1, -1, -2, -3, -3, -3, -4, 0, 0, 0, -1, -2, -2, -3, -3,
- 2, 2, 2, 0, -1, -1, -1, -1, 5, 5, 4, 3, 2, 2, 2, 2,
- 6, 3, -1, -4, -3, -1, 1, 1, 2, -1, -3, -4, -1, 2, 2, 0,
- -1, -2, -2, 1, 4, 4, 1, -3, -2, -1, 1, 4, 6, 3, -3, -8,
- 3, 3, 2, 1, -1, -2, -2, -2, -4, -4, -2, -1, 1, 3, 4, 4,
- -4, -5, -5, -4, -2, 0, 2, 2, 7, 7, 4, 1, -1, -2, -3, -2,
- -1, 1, 3, 0, -4, -6, 0, 6, -2, 1, 4, 1, -4, -6, -1, 7,
- -3, 1, 4, 2, -3, -6, -1, 6, -2, 0, 3, 2, -2, -5, -1, 4,
- 1, -1, -2, 1, 4, 4, -1, -7, 1, -1, -4, -1, 5, 6, 0, -6,
- 3, 0, -4, -3, 3, 6, 2, -4, 3, 0, -5, -4, 1, 4, 1, -3,
- 2, 2, 3, 3, 3, 3, 2, 2, -4, -5, -6, -7, -7, -7, -7, -6,
- 1, 2, 3, 3, 3, 3, 2, 2, 0, 0, 1, 1, 1, 2, 2, 1,
- 3, -3, -3, 3, 4, -2, -2, 2, 3, -4, -4, 4, 4, -4, -4, 2,
- 4, -4, -4, 4, 4, -4, -3, 3, 3, -3, -4, 3, 3, -3, -3, 3,
- -2, -2, -2, -2, -2, -2, -1, -1, 6, 7, 8, 8, 8, 7, 6, 5,
- -5, -6, -7, -7, -8, -7, -6, -5, 1, 1, 2, 2, 2, 2, 1, 1,
- 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0,
- -2, -3, -2, -2, -2, -3, -3, -3, 2, 3, 5, 6, 4, 2, 1, 0,
- 8, 6, 2, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, -1, -1, -1,
- 1, -1, 0, 0, 0, -1, -2, -3, -2, -2, -1, 0, 0, -2, -4, -5,
- 3, 1, -1, -2, -3, -4, -5, -5, 2, 1, 0, 0, 1, 1, 0, 0,
- 0, -1, -1, 0, 2, 2, 2, 2, -1, -2, -1, 1, 2, 2, 2, 2,
- 0, -1, -2, -1, -1, -1, -1, 0, -1, -2, -2, -1, -1, 0, 0, 1,
- 2, 1, 1, 2, 2, 1, 1, 0, 6, 5, 3, 1, 0, -2, -4, -4,
- -3, -2, -1, 0, 1, 1, 0, -1, 0, 1, 3, 4, 5, 5, 3, 1,
- -1, -1, -1, 0, 1, 0, -1, -2, -2, -2, -2, -1, 0, -1, -2, -3,
- 0, -1, -2, -2, -1, -1, 0, 2, 1, -1, -2, -1, -1, -1, 0, 2,
- 1, 0, -2, -2, -2, -2, 1, 5, 1, -1, -2, -2, -2, 0, 5, 10,
- 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 1, 2,
- 1, 2, 2, 3, 4, 4, 6, 5, -3, -3, -3, -2, -2, -3, -3, -3,
- 1, -1, -2, -2, 0, 3, 5, 7, 2, 0, -2, -3, -2, 0, 2, 3,
- 3, 1, -2, -3, -3, -2, -1, -1, 3, 1, 0, -1, -1, -1, -1, -1,
- 1, 3, 5, 4, 2, -1, -3, -4, -3, -2, 1, 2, 1, 0, -1, -2,
- -5, -3, 0, 2, 2, 1, 0, 0, -3, -1, 1, 2, 2, 1, 0, 0,
- 0, -1, -1, -1, 1, 2, 3, 4, -3, -4, -4, -3, -1, 0, 0, 1,
- -2, -3, -2, -1, 1, 1, 1, 1, -2, -2, 0, 3, 4, 4, 3, 2,
- -4, -4, -3, -2, -1, 1, 2, 3, 0, 1, 1, 1, -1, -2, -3, -3,
- 3, 4, 5, 4, 2, -1, -3, -3, -2, -2, 0, 2, 2, 2, 1, 0,
- -4, 0, 5, 7, 4, -1, -4, -4, -1, 2, 4, 3, 0, -3, -3, -2,
- 2, 1, 0, -1, -2, -2, 0, 1, 0, 0, -1, -2, -2, -1, 1, 2,
- -4, -3, -2, -1, 0, 1, 2, 2, 10, 9, 5, 0, -3, -4, -3, -2,
- 1, -1, -2, -2, -1, 0, 0, 0, -2, -2, -1, 1, 1, 1, 0, -1,
- -5, -3, 0, 3, 4, 2, 0, -2, -2, -1, 0, 1, 1, 0, -1, -1,
- 3, 2, -1, -2, -2, -1, 1, 1, 7, 5, -1, -5, -6, -2, 2, 4,
- -2, 3, 3, -3, -4, 1, 2, -2, -3, 3, 4, -3, -4, 2, 3, -2,
- -3, 3, 4, -3, -4, 2, 3, -2, -4, 2, 4, -2, -3, 1, 2, -1,
- 4, 3, -1, -3, -3, -1, 1, 2, -4, -6, -4, 0, 4, 5, 4, 1,
- 0, 2, 5, 6, 2, -3, -5, -4, 1, 1, -1, -3, -5, -2, 2, 4,
- -1, 0, 1, 2, 2, 3, 3, 4, -1, 0, 1, 1, 0, -1, -1, -1,
- -1, 0, 1, 2, 2, 1, -1, -2, -3, -2, -1, 0, 0, -1, -2, -3,
- 1, 1, 1, 1, 0, 0, 1, 2, 1, 0, -1, 0, 0, 1, 1, 0,
- 1, -2, -4, -1, 1, 2, 1, 0, 1, -4, -7, -3, 1, 3, 2, 1,
- 1, 1, 1, 1, 1, 1, 0, -1, 1, 1, 1, 0, 1, 2, 2, 0,
- 1, 1, 0, 0, 0, 2, 0, -3, 3, 2, 0, -1, -1, -2, -6, -9,
- 0, 0, 0, 1, 0, 0, 1, 2, 1, 0, 0, 0, -1, -1, 0, 2,
- 0, 1, 1, 1, -1, -3, -2, 0, -7, -5, 1, 6, 6, 2, -1, -1,
- 3, 1, -1, -3, -4, -2, 1, 4, 2, 0, -2, -3, -4, -3, -1, 2,
- 2, 2, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1,
- -1, 1, 1, -2, -5, -6, -4, -1, -1, 1, 4, 3, 2, 0, 1, 2,
- -1, 0, 2, 3, 1, 0, 0, 1, -1, 0, 1, 0, 0, -1, -1, 0,
- 0, 1, 2, 2, 0, -2, -1, 1, -2, -1, -1, -2, -1, 2, 6, 8,
- -1, -1, -2, -3, -2, 0, 1, 2, -1, 0, 0, -1, -1, 0, -1, -1,
- 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, -1, -1, 1,
- -1, 0, 2, 2, -1, -3, -2, 3, 0, 2, 3, 0, -5, -7, -2, 4,
- -1, 0, 0, 0, -1, -2, -3, -3, -1, 0, -1, -2, -2, -2, -2, -2,
- 1, 1, 0, 0, 1, 2, 0, -1, 1, 2, 1, 2, 5, 6, 2, 0,
- -2, -4, -3, 0, 2, 2, 0, -3, 3, 1, 0, 1, 2, 1, -2, -3,
- 3, 1, 0, 0, 0, 0, 0, -1, 1, -1, -2, -2, -1, 1, 3, 3,
- 3, 2, 1, 2, 4, 3, 1, -2, -2, -4, -4, -3, -1, 0, -2, -3,
- 1, 0, -1, -1, 0, 1, 0, -1, 3, 2, 0, 0, 0, 1, 1, 0,
- 1, 1, 0, 0, 0, 0, 0, 0, 2, 3, 3, 2, 2, 2, 1, 1,
- 0, -1, -2, -3, -5, -5, -5, -4, 1, 1, 0, -1, 0, 1, 3, 3,
- -9, -6, -2, 0, 1, 1, 2, 2, -6, -2, 1, 2, 1, 1, 0, 1,
- -2, 1, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 0, 1, 1, 1,
- 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, -3, -2, 0,
- -3, -3, -3, -2, -1, 3, 7, 9, 1, 2, 2, 2, 0, -2, -4, -3,
- 2, 0, -2, -1, 3, 4, -1, -6, 1, 0, -2, -3, -1, 3, 3, 0,
- 0, 3, 3, 0, -2, -1, 1, 1, -6, -1, 3, 2, -1, -2, 0, 1,
- 5, 3, 0, -2, -3, 0, 2, 1, 1, 1, 2, 2, 0, -2, -4, -7,
- -3, -2, 1, 2, 2, 1, -1, -4, 2, 2, 0, -2, -2, 0, 2, 2,
- 0, 0, -2, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2,
- -2, -1, 0, 1, 0, 1, 2, 3, -4, -2, 0, 0, -1, 0, 2, 3,
- -2, -2, -2, -1, -1, 0, 2, 4, 0, 0, 0, 0, -1, -1, 0, 1,
- 0, -1, -1, -1, -1, -1, 0, 0, 6, 4, 2, 0, -1, -2, -1, -1,
- 0, 1, 1, 1, 1, -1, -5,-10, 1, 1, 1, 1, 1, 1, 0, -4,
- 1, 0, 1, 1, 1, 1, 1, -1, 2, 1, 1, 1, 0, 0, 0, 0,
- -3, 1, 4, 3, 3, 1, -1, 0, -4, 0, 1, 0, -1, 0, 0, 0,
- -5, 0, 2, 1, 1, 1, 0, -1, -1, 2, 1, -2, -2, -1, 0, -1,
- 2, 4, 5, 3, 0, -1, 1, 2, 0, 0, 1, 0, -2, -2, -1, -1,
- -2, -2, -2, -2, -3, -2, -1, 0, 0, 0, 1, 0, 0, 0, 1, 2,
- 0, -2, -2, -3, -1, 2, 2, -1, 1, 0, 0, 0, 1, 5, 3, -2,
- -1, -1, 0, -1, 0, 2, 0, -5, -1, 0, 1, 0, 0, 2, 2, -2,
- 3, 1, -1, -1, 0, 1, 1, 2, 1, 0, 0, 1, 1, 1, 1, 1,
- -10, -8, -2, 1, 2, 1, 1, 1, -1, 1, 2, 1, 0, 0, 0, 0,
- -1, -1, 0, 1, 2, 2, 2, 1, -1, -1, -1, 0, -1, -3, -5, -4,
- 1, 1, 2, 1, 1, 0, 0, 2, -1, -2, -1, -1, -1, 0, 2, 4,
- -3, -7, -5, 0, 2, 0, 0, 0, 3, -1, -2, 1, 2, 1, 1, 2,
- 1, -2, -1, 1, 2, 1, 0, 1, 0, -1, 0, 3, 2, -1, -1, -1,
- 2, 1, 1, 0, 0, 0, 0, 0, -9, -7, -2, 3, 3, 2, 1, 1,
- 3, 2, 0, -2, -2, -1, 1, 1, 0, -1, 0, 0, 1, 1, 0, 0,
- -2, -1, 1, 1, 1, 0, 0, 0, 1, 2, 1, -2, -4, -3, 1, 2,
- 1, 2, 1, -2, -3, 0, 3, 1, -1, -1, 0, 0, 1, 3, 0, -4,
- 2, 0, -1, 1, 2, -2, -2, 3, 2, 0, -1, 2, 3, -2, -4, 1,
- 0, 1, 1, 1, 2, -2, -6, -2, -1, 0, 0, 0, 2, 0, -2, -1,
- -1, -1, 1, 2, 1, -2, -3, -2, 3, -1, -2, -1, -1, 0, 1, 2,
- 10, 4, 0, 0, -1, -2, -2, -1, 3, -1, -2, -1, 0, -1, -1, 0,
- -5, 2, 7, 1, -4, -2, 1, 0, -2, 2, 3, -1, -3, 0, 2, 0,
- 2, 1, 0, 0, 1, 1, -1, -2, 1, -2, -2, -1, -1, -2, 0, 0,
- 0, 3, -2, -7, -1, 3, 0, 0, 1, 3, -3, -5, 2, 3, -1, 0,
- 0, 2, -2, -2, 4, 2, -2, 0, -1, 1, -1, 0, 2, -1, -2, 1,
- 4, 0, -3, -4, -2, 1, 2, 1, 0, 0, 3, 5, 3, 1, -1, -2,
- 1, 1, 1, -1, -3, -1, 1, 1, 1, -1, -2, -2, 0, 0, -1, -2
-};
-
-/* 6x16-entry codebook for intra-coded 8x8 vectors */
-static const int8_t svq1_intra_codebook_8x8[6144] = {
- 4, 4, 3, 2, 2, 1, 0, -1, 4, 3, 3, 2, 1, 0, -1, -1,
- 3, 3, 2, 2, 1, 0, -1, -2, 3, 2, 2, 1, 0, -1, -2, -3,
- 2, 2, 1, 0, -1, -1, -2, -3, 2, 1, 0, 0, -1, -2, -3, -4,
- 1, 0, 0, -1, -2, -3, -4, -4, 0, 0, -1, -2, -2, -3, -4, -4,
- 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3,
- 1, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1,
- -1, 0, 0, 0, 0, 0, 1, 1, -2, -2, -1, -1, -1, -1, -1, -1,
- -3, -3, -3, -3, -3, -3, -2, -2, -5, -4, -4, -4, -4, -4, -4, -3,
- -4, -2, -1, 0, 1, 2, 2, 3, -4, -2, -1, 0, 1, 2, 3, 3,
- -4, -3, -1, 0, 1, 2, 3, 3, -4, -3, -1, 0, 1, 2, 3, 3,
- -5, -3, -1, 0, 1, 2, 3, 3, -5, -3, -1, 0, 1, 2, 3, 3,
- -5, -3, -1, 0, 1, 1, 2, 3, -5, -3, -2, -1, 0, 1, 2, 3,
- 4, 4, 5, 5, 6, 6, 7, 7, 2, 2, 2, 3, 3, 4, 4, 4,
- 0, 0, 0, 0, 1, 1, 1, 2, -2, -2, -2, -2, -1, -1, -1, 0,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- -1, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -2, -2, -2, -2,
- 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3,
- 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3,
- 5, 4, 1, 0, -2, -3, -3, -3, 6, 4, 2, 0, -2, -2, -3, -3,
- 6, 4, 2, 0, -1, -2, -2, -3, 6, 4, 2, 1, -1, -2, -2, -2,
- -1, 1, 3, 3, 2, 0, -3, -6, -1, 1, 3, 4, 3, 0, -3, -6,
- -1, 1, 4, 4, 3, 1, -3, -6, -1, 1, 3, 4, 3, 1, -3, -6,
- -2, 1, 3, 4, 3, 1, -3, -6, -2, 1, 3, 4, 3, 1, -3, -7,
- -2, 1, 3, 3, 2, 0, -3, -7, -2, 0, 2, 3, 2, 0, -3, -6,
- 10, 9, 8, 6, 6, 5, 4, 4, 6, 5, 4, 3, 2, 2, 2, 1,
- 2, 1, 0, -1, -2, -2, -2, -1, -1, -2, -3, -4, -4, -4, -4, -3,
- -2, -3, -4, -4, -5, -4, -4, -3, -2, -2, -3, -3, -3, -3, -2, -2,
- -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 2,
- -2, -1, 1, 2, 4, 5, 7, 8, -3, -2, 0, 1, 3, 5, 7, 8,
- -4, -3, -1, 0, 2, 4, 6, 7, -5, -4, -2, -1, 1, 3, 5, 7,
- -6, -5, -3, -2, 0, 2, 4, 6, -6, -5, -4, -2, -1, 1, 3, 5,
- -7, -6, -5, -3, -2, 0, 2, 3, -8, -7, -5, -4, -3, -1, 1, 2,
- 11, 9, 7, 5, 3, 1, -1, -1, 10, 8, 6, 3, 1, 0, -2, -2,
- 9, 7, 5, 2, 0, -2, -3, -4, 8, 6, 3, 1, -1, -3, -4, -4,
- 6, 4, 2, -1, -3, -4, -5, -5, 5, 3, 0, -2, -4, -5, -6, -6,
- 3, 1, -1, -3, -5, -6, -7, -7, 2, 0, -2, -4, -6, -6, -7, -7,
- 5, 6, 7, 7, 7, 8, 8, 8, 3, 4, 5, 5, 6, 6, 6, 6,
- 0, 2, 2, 3, 4, 4, 4, 5, -2, -1, 0, 1, 2, 2, 3, 3,
- -4, -3, -2, -1, 0, 1, 1, 2, -6, -5, -4, -3, -2, -2, -1, 0,
- -8, -7, -6, -6, -5, -4, -3, -3,-10, -9, -8, -8, -7, -6, -6, -5,
- 6, 5, 3, 1, -1, -3, -6, -8, 6, 5, 4, 2, -1, -3, -6, -8,
- 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8,
- 6, 6, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8,
- 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, -1, -3, -5, -8,
- 11, 10, 9, 8, 7, 6, 5, 4, 8, 8, 7, 6, 5, 4, 3, 2,
- 6, 5, 4, 4, 2, 2, 1, 0, 3, 3, 2, 1, 0, 0, -1, -2,
- 1, 1, 0, -1, -2, -2, -3, -3, -1, -1, -2, -3, -4, -4, -5, -5,
- -3, -4, -4, -5, -6, -6, -7, -7, -5, -5, -6, -7, -8, -8, -8, -8,
- -14,-13,-12,-11, -9, -7, -6, -4,-12,-11,-10, -9, -7, -5, -3, -1,
- -10, -9, -7, -6, -3, -2, 0, 2, -8, -6, -4, -2, 0, 2, 4, 5,
- -5, -3, 0, 2, 4, 5, 7, 8, -2, 0, 2, 4, 6, 8, 9, 10,
- 0, 3, 5, 7, 8, 10, 11, 12, 3, 5, 7, 8, 10, 11, 12, 12,
- -19,-19,-18,-18,-17,-16,-15,-14,-15,-15,-14,-13,-12,-11,-10, -9,
- -11,-10, -9, -8, -6, -5, -4, -3, -6, -5, -3, -2, -1, 0, 1, 2,
- -1, 0, 2, 3, 4, 5, 6, 6, 4, 6, 7, 8, 9, 10, 10, 10,
- 9, 10, 11, 12, 13, 14, 14, 14, 12, 14, 14, 15, 16, 16, 16, 16,
- 22, 21, 19, 17, 14, 11, 9, 5, 20, 19, 17, 14, 11, 8, 4, 1,
- 17, 15, 13, 10, 6, 3, 0, -4, 13, 11, 8, 5, 1, -2, -5, -9,
- 9, 6, 3, -1, -4, -7,-11,-13, 4, 0, -3, -6, -9,-12,-15,-17,
- -2, -5, -8,-11,-14,-16,-18,-20, -8,-10,-13,-16,-17,-19,-21,-22,
- 17, 18, 18, 18, 17, 16, 16, 14, 16, 16, 15, 15, 14, 13, 12, 11,
- 12, 12, 11, 10, 9, 8, 7, 5, 7, 6, 6, 4, 3, 2, 1, -1,
- 1, 0, -1, -2, -3, -4, -5, -6, -5, -6, -7, -8, -9,-10,-11,-12,
- -11,-12,-13,-14,-15,-16,-16,-17,-16,-17,-17,-18,-19,-20,-20,-20,
- 0, 0, 0, 0, -1, -1, -2, -3, 1, 0, 0, 0, 0, -1, -2, -3,
- 1, 1, 0, 0, -1, -1, -2, -2, 1, 1, 1, 0, 0, -1, -1, -2,
- 2, 1, 1, 1, 0, -1, -1, -2, 2, 2, 1, 1, 0, 0, -1, -2,
- 2, 2, 1, 1, 1, 0, -1, -1, 2, 2, 1, 1, 1, 0, 0, -2,
- 0, -1, -1, 0, 0, 1, 2, 3, 0, -1, -1, 0, 1, 1, 2, 2,
- -1, -1, -1, -1, 0, 1, 2, 2, -1, -1, -2, -1, 0, 1, 1, 2,
- -1, -2, -2, -1, 0, 0, 1, 2, -1, -2, -2, -2, -1, 0, 1, 2,
- -1, -1, -2, -1, 0, 0, 1, 2, -1, -1, -1, -1, 0, 1, 1, 2,
- 3, 2, 2, 2, 1, 1, 0, 0, 3, 2, 2, 2, 2, 1, 0, 0,
- 2, 2, 2, 1, 1, 1, 0, 0, 2, 2, 1, 1, 1, 0, 0, -1,
- 1, 1, 1, 0, 0, 0, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -2, -2, -2, -2,
- 5, 2, 0, 0, -1, 0, 0, 0, 4, 2, 0, -1, -1, -1, 0, -1,
- 4, 1, -1, -1, -2, -1, -1, -1, 4, 1, -1, -1, -2, -1, -1, -1,
- 4, 1, -1, -2, -2, -1, -1, -1, 4, 1, -1, -2, -2, -1, -1, -1,
- 4, 1, -1, -1, -1, -1, -1, -1, 4, 2, 0, -1, 0, 0, 0, -1,
- -2, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1,
- -3, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1,
- -3, -2, 0, 1, 2, 2, 1, 1, -4, -2, 0, 1, 2, 2, 2, 2,
- -5, -3, -1, 1, 1, 2, 1, 2, -5, -3, -2, 0, 1, 1, 1, 1,
- 3, 3, 1, 0, -2, -4, -4, -5, 3, 3, 2, 0, -1, -2, -3, -4,
- 2, 2, 1, 1, 0, -1, -2, -2, 1, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 0, 1, 1, 1, 1, 1, -2, -1, -1, 0, 0, 1, 2, 2,
- -3, -2, -2, -1, 0, 1, 2, 3, -3, -3, -2, -1, 0, 1, 2, 3,
- -3, -3, -3, -3, -3, -2, -2, -2, -3, -3, -2, -2, -2, -1, -1, -1,
- -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2,
- 1, 1, 1, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3,
- -8, -7, -5, -3, -2, -1, 0, -1, -4, -3, -1, 0, 1, 2, 1, 1,
- -1, 1, 2, 3, 3, 2, 2, 1, 1, 2, 3, 3, 2, 2, 1, 0,
- 2, 3, 3, 2, 1, 0, 0, -1, 1, 2, 1, 0, -1, -1, -1, -1,
- 1, 1, 0, -1, -1, -2, -2, -1, 1, 1, 0, 0, -1, -1, 0, -1,
- -4, -3, -2, 0, 1, 2, 3, 3, -4, -3, -2, 0, 1, 2, 2, 2,
- -3, -3, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, -1, 0, 0, 0,
- 0, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 0, 0, -1, -1, -2,
- 3, 3, 3, 1, 0, -1, -2, -2, 5, 4, 4, 2, 1, 0, -1, -2,
- 0, 0, 0, 0, 1, 2, 3, 3, 0, -1, 0, 0, 1, 2, 3, 3,
- 0, -1, 0, 0, 1, 2, 3, 2, 0, 0, 0, 1, 1, 2, 2, 2,
- 2, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 0, 0, -1, -2,
- 2, 1, 0, 0, -2, -3, -5, -6, 0, -1, -1, -3, -5, -6, -8, -9,
- -2, 0, 1, 2, 2, 1, -1, -4, -2, 0, 2, 2, 2, 1, -1, -4,
- -2, 0, 2, 2, 2, 1, -1, -3, -2, 0, 2, 2, 2, 1, -1, -3,
- -2, -1, 2, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3,
- -3, -1, 1, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3,
- -1, 1, 1, -1, -3, -3, 0, 4, -1, 1, 1, -1, -3, -3, 0, 4,
- -1, 1, 1, 0, -3, -3, 0, 4, -1, 1, 2, 0, -3, -3, 0, 5,
- 0, 1, 2, 0, -3, -4, 0, 4, 0, 1, 2, 0, -3, -4, 0, 5,
- 0, 1, 2, 0, -3, -3, 0, 4, 0, 1, 2, -1, -2, -2, 0, 4,
- 6, 6, 5, 6, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2,
- 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2,
- -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
- -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 0, 0, 0, 0, 0,
- -1, -2, -2, -2, -2, -2, -2, -1, -3, -3, -3, -3, -3, -3, -3, -2,
- -3, -4, -4, -3, -3, -3, -2, -2, -2, -2, -2, -2, -1, -1, 0, 0,
- 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6,
- 4, 1, -2, -3, -3, -1, 1, 3, 4, 1, -2, -4, -3, -1, 1, 3,
- 5, 1, -2, -4, -3, -1, 1, 4, 5, 1, -2, -3, -3, -1, 2, 4,
- 5, 1, -2, -3, -3, -1, 2, 4, 4, 0, -3, -4, -3, -1, 2, 4,
- 4, 0, -3, -3, -3, -1, 1, 3, 3, 0, -2, -3, -2, -1, 1, 3,
- -3, -4, -4, -4, -4, -4, -4, -4, -1, -1, -1, -1, -1, -1, -2, -2,
- 2, 1, 1, 2, 2, 1, 1, 1, 3, 3, 3, 4, 4, 3, 3, 3,
- 3, 3, 3, 4, 4, 4, 3, 3, 1, 2, 1, 2, 2, 2, 2, 2,
- -2, -2, -2, -1, -1, -1, 0, 0, -4, -4, -4, -4, -3, -3, -3, -3,
- -1, -2, -3, -3, -2, -2, -1, 0, 0, -1, -2, -2, -2, -1, 0, 1,
- 2, 1, -1, -1, -1, -1, 0, 1, 3, 1, 0, -1, -1, 0, 0, 1,
- 3, 2, 0, -1, 0, 0, 0, 1, 3, 1, 0, -1, 0, 0, 0, 1,
- 3, 1, 0, -1, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 1,
- 0, 0, 0, 1, 1, 2, 3, 4, 0, 0, -1, 0, 0, 0, 2, 3,
- 0, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, 0,
- 0, 0, -1, -1, -1, -2, -2, -1, 1, 0, 0, -1, -1, -2, -2, -1,
- 2, 2, 1, 0, -1, -1, -1, -1, 3, 3, 2, 1, 0, -1, -1, 0,
- 1, 0, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, -1, -1, -2, -1,
- 0, -1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0,
- -1, -1, -1, 0, 0, 0, 1, 1, -1, -1, -1, 0, 1, 1, 2, 3,
- -2, -2, -1, 0, 1, 2, 3, 4, -2, -2, -1, 0, 1, 2, 4, 5,
- -3, -1, 1, 0, 0, -1, 0, 1, -3, 0, 1, 0, -1, -1, 0, 2,
- -3, 0, 1, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2,
- -2, 1, 2, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2,
- -1, 2, 2, 0, -1, -1, 0, 2, -1, 1, 1, 0, -1, -1, -1, 1,
- -2, -2, -1, 1, 3, 4, 3, 1, -2, -2, -1, 0, 2, 3, 2, 0,
- -2, -2, -1, 0, 1, 2, 1, -1, -1, -1, -1, 0, 1, 2, 1, -1,
- -1, -1, -1, 0, 1, 1, 0, -2, 0, -1, -1, 0, 1, 1, 0, -1,
- 0, -1, -1, 0, 1, 1, 1, -1, 0, -1, -1, 0, 0, 1, 0, -1,
- -2, -1, 0, 1, 1, 1, 1, 1, -2, -1, 0, 0, 0, 0, 0, 0,
- -2, -1, -1, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -2, -2, -3,
- -1, 0, 1, 1, 0, -1, -2, -2, 1, 2, 3, 3, 2, 1, 0, 0,
- 1, 2, 3, 3, 3, 2, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0,
- 0, -1, -1, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, -1, 0, 0, 1, 1, 0, 0, 0,
- -3, -2, -1, -1, -1, -1, 0, -1, -5, -5, -4, -3, -2, -2, -2, -1,
- 1, 1, 1, 1, 2, 1, 0, -1, 1, 1, 1, 2, 1, 1, 0, -1,
- 1, 1, 1, 1, 1, 1, 0, -2, 2, 1, 1, 1, 1, 1, 0, -2,
- 1, 1, 0, 0, 0, 0, -1, -3, 1, 1, 0, 0, 0, -1, -2, -3,
- 1, 1, 0, 0, -1, -1, -2, -4, 1, 0, 0, -1, -2, -2, -3, -4,
- 8, 7, 5, 3, 2, 1, 1, 1, 2, 1, 0, 0, -1, -1, -2, -1,
- -1, -1, -1, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, -1, -1, 0,
- 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
- -1, 0, 0, 0, 0, 0, -1, -1, -2, -2, -1, -1, -1, -2, -2, -1,
- 9, 4, 0, -2, -2, -2, -1, -1, 7, 2, -1, -2, -2, -1, 0, 0,
- 4, 0, -2, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, 0, 1, 1,
- -1, -2, -2, -1, 0, 1, 1, 1, -1, -2, -1, 0, 1, 1, 1, 0,
- -1, -1, 0, 1, 1, 1, 0, -1, 0, -1, 0, 1, 0, 0, -1, -1,
- 0, 1, 1, 1, 1, 1, 0, 0, 1, 2, 2, 2, 1, 0, 0, 0,
- 2, 2, 2, 2, 1, 0, -1, -1, 1, 1, 1, 0, -1, -2, -2, -2,
- 0, 0, 0, -1, -2, -3, -2, -2, -1, -1, -1, -2, -2, -2, -1, 0,
- -1, -1, -1, -1, 0, 0, 1, 2, -1, -1, -1, 0, 1, 2, 3, 4,
- -1, -1, 0, 0, -1, -2, -3, -3, -1, -1, 0, 0, 0, -1, -1, -1,
- -2, -2, -1, 0, 1, 1, 1, 1, -2, -2, -2, 0, 1, 2, 3, 3,
- -1, -1, -1, 0, 1, 3, 3, 3, 1, 0, 0, 0, 1, 1, 2, 2,
- 2, 2, 1, 0, 0, -1, -1, -1, 3, 2, 1, 0, -1, -2, -3, -3,
- -1, -1, -1, -2, -2, -3, -4, -5, 0, 0, 0, -1, -1, -3, -3, -4,
- 1, 1, 1, 0, 0, -1, -2, -3, 2, 2, 2, 1, 1, 0, -1, -1,
- 2, 2, 2, 2, 1, 1, 0, -1, 2, 2, 2, 2, 2, 1, 0, 0,
- 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, -1,
- -2, 2, 3, 1, -1, 1, 1, -1, -3, 2, 3, 0, -1, 1, 1, -1,
- -3, 2, 3, 0, -1, 1, 1, -1, -4, 2, 3, 0, -1, 1, 1, -2,
- -4, 1, 3, 0, -1, 1, 1, -2, -4, 1, 3, -1, -2, 1, 1, -2,
- -3, 1, 2, 0, -1, 1, 1, -2, -3, 1, 2, 0, -1, 1, 1, -1,
- -1, -1, -1, -2, -2, -2, -2, -2, 1, 1, 1, 1, 0, 0, 0, 0,
- 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 2, 2, 2,
- -2, -2, -1, -1, -1, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, -2,
- -1, -1, -1, -1, -2, -2, -2, -2, 4, 4, 4, 4, 4, 3, 3, 2,
- -3, -3, -2, -1, 0, 1, 2, 5, -3, -3, -3, -2, -1, 1, 3, 6,
- -3, -3, -2, -2, 0, 2, 3, 5, -3, -2, -2, -2, 0, 1, 3, 5,
- -2, -2, -2, -1, -1, 1, 3, 5, -2, -2, -1, -1, 0, 1, 2, 4,
- -1, -1, -1, -1, 0, 1, 1, 4, -1, -1, -1, -1, 0, 1, 2, 3,
- 0, -1, 0, 1, 1, 0, -1, -1, 0, 0, 0, 1, 2, 0, -1, -1,
- 1, 0, -1, 0, 1, 0, 0, 0, 1, -1, -2, -1, 0, 0, 0, 0,
- 1, -2, -3, -1, 0, 0, 0, 1, 1, -1, -3, -2, 0, 1, 1, 2,
- 1, -1, -2, -1, 0, 1, 1, 2, 2, 0, -1, 0, 1, 1, 2, 2,
- 1, 1, 1, 1, 0, 0, 1, 2, -1, 0, 0, -1, 0, 0, 0, 1,
- -3, -2, -1, -1, -1, 0, 1, 1, -4, -2, -1, 0, 0, 1, 1, 1,
- -3, -2, 0, 0, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 0, 0,
- -1, 0, 1, 1, 1, 0, 0, -1, 0, 1, 2, 2, 1, 0, 0, -1,
- -4, -4, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0, 0, 0,
- -1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
- 0, 0, 1, 1, 2, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0,
- 0, 0, 0, 1, 1, 1, 1, 0, -1, 0, 0, 1, 1, 1, 0, 0,
- 1, 2, 2, 2, 1, -1, -2, -4, 1, 1, 2, 2, 1, 0, -2, -4,
- 0, 1, 1, 1, 1, 0, -1, -3, -1, 0, 1, 1, 0, 0, -1, -2,
- -1, 0, 1, 1, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, -1,
- -1, -1, 0, 1, 1, 0, 0, 0, -1, 0, 1, 1, 1, 1, 1, 0,
- 2, 2, 0, -1, -2, -1, -1, -2, 1, 1, -1, -2, -2, -1, -1, -2,
- 1, 1, -1, -2, -2, 0, 0, -1, 1, 1, 0, -2, -1, 1, 1, 0,
- 1, 1, 0, -1, -1, 1, 2, 1, 1, 1, 0, -1, -1, 1, 2, 1,
- 1, 1, 0, -1, -1, 1, 1, 1, 1, 1, 0, -1, 0, 1, 1, 1,
- 0, 0, -1, -2, -4, -4, -4, -4, 3, 3, 3, 2, 1, 0, 0, 0,
- 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1,
- -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0,
- -1, -1, 0, -1, -1, 1, 2, -1, 1, 1, 0, 0, 0, 2, 3, -1,
- 1, 1, 0, -1, -1, 1, 3, -1, 1, 1, 0, -2, -2, 0, 1, -2,
- 1, 0, 0, -2, -2, 0, 1, -3, 0, 0, 0, 0, -1, 1, 1, -3,
- 0, 1, 1, 0, 1, 2, 1, -3, -1, 0, 1, 1, 1, 2, 1, -4,
- -4, -3, 0, 1, 1, 1, 0, 0, -4, -2, 0, 1, 1, 1, 0, -1,
- -3, -1, 1, 1, 1, 0, -1, -1, -1, 1, 1, 1, 1, 0, -1, 0,
- 1, 2, 2, 1, 0, -1, 0, 0, 2, 2, 1, 0, -1, -1, 0, 1,
- 2, 1, 0, -1, -2, -1, 0, 1, 2, 2, 0, -1, -2, -1, 1, 1,
- 1, 1, 0, 0, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1,
- 1, 0, 0, -1, -1, -1, -1, -1, 2, 1, 0, 0, -1, -1, -1, -1,
- 5, 3, 2, 1, 0, 0, 0, 0, 6, 5, 3, 2, 1, 0, 0, 0,
- 4, 4, 3, 1, 0, 0, 0, 1, 3, 3, 2, 1, 0, 0, 0, 1,
- 2, 2, 1, 0, -1, -1, 0, 1, 0, 0, 0, -1, -1, -1, 0, 1,
- 0, 0, -1, -1, -2, -1, 0, 2, 0, -1, -1, -2, -2, -2, 0, 1,
- 0, -1, -1, -2, -2, -2, -1, 0, 0, 0, -1, -2, -2, -2, -1, 0,
- 0, 0, -1, -1, -1, 0, 2, 3, 0, -1, -2, -2, -1, -1, 1, 2,
- 1, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1,
- 1, 2, 1, 0, 0, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1,
- -3, -2, -1, -1, 0, 1, 1, 2, -4, -3, -1, 1, 2, 3, 5, 5,
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, -1, 0, 0, 0, 1, -1, -1, -2, -2, -2, -1, -1, 0,
- 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3,
- 1, 1, 1, 1, 2, 2, 1, 1, -4, -3, -4, -4, -4, -4, -3, -3,
- -1, 0, 1, 2, 2, 3, 3, 3, -1, -1, -1, -1, 0, 0, 0, 0,
- 0, 0, -1, -2, -2, -3, -3, -2, 3, 2, 1, 0, -1, -2, -2, -2,
- 4, 3, 2, 1, 1, 0, 0, 0, 2, 2, 1, 1, 0, 1, 1, 1,
- 0, -1, -1, -1, -1, 0, 0, 1, -2, -2, -2, -2, -2, -1, 0, 0,
- 1, -1, 0, 2, 1, -2, -1, 1, 1, -1, 0, 2, 1, -2, -2, 1,
- 1, -1, 0, 3, 2, -2, -1, 1, 0, -2, 0, 3, 2, -2, -2, 1,
- 0, -2, 0, 3, 2, -2, -2, 1, 0, -2, 0, 3, 1, -2, -1, 1,
- 0, -2, 0, 2, 1, -2, -2, 1, 0, -1, 0, 2, 1, -2, -1, 1,
- 0, 1, 2, 2, 3, 3, 2, 2, 0, 1, 1, 2, 3, 3, 2, 1,
- 0, 0, 1, 2, 2, 2, 2, 1, -1, 0, 0, 1, 1, 1, 1, 1,
- -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1,
- -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -2, -2, -2, -2, -2, -1,
- 0, 0, -1, -2, -1, 0, 3, 5, 0, 0, -1, -1, -1, 0, 2, 4,
- 1, 1, 0, 0, -1, -1, 1, 2, 1, 2, 1, 1, 0, -1, -1, 0,
- 0, 1, 2, 1, 0, -1, -2, -2, -1, 0, 1, 2, 1, 0, -3, -3,
- -2, -1, 1, 2, 2, 0, -2, -4, -2, -1, 0, 2, 2, 1, -1, -3,
- 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 0,
- -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0,
- -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0,
- 0, 0, 1, 1, 0, 0, 0, 1, 3, 3, 3, 4, 3, 3, 3, 3,
- 5, 1, -2, -2, 0, 0, 0, -1, 4, -1, -3, -1, 0, 0, 0, -1,
- 3, -1, -1, 0, 1, 1, 0, -1, 2, 0, 0, 1, 1, 1, 0, -2,
- 1, 0, 0, 1, 1, 1, 0, -2, 0, -1, -1, -1, 0, 0, 0, -1,
- 0, -1, -1, -1, -1, 0, 0, -1, 2, 1, 0, 0, 0, 1, 0, 0,
- 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0,
- 1, -1, -1, 0, 0, 0, 0, 0, 2, 0, -1, -1, -1, -1, -1, 0,
- 3, 1, -1, -1, -2, -2, -2, -1, 4, 2, 1, 0, -1, -2, -2, -1,
- 2, 1, 0, 0, -1, -1, 0, 0, 0, -1, -1, -1, -1, 0, 1, 1,
- 0, 1, 2, 2, 2, 1, -1, -3, 0, 0, 1, 1, 1, 0, -1, -2,
- 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 1, 1, 0,
- 0, 0, -1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0,
- 0, 0, 1, 1, 2, 1, -1, -3, 0, 0, 0, 1, 1, -1, -4, -5,
- -2, -2, -2, -1, 0, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0,
- 1, 1, 1, 1, 1, 0, -2, -3, 0, 0, 1, 1, 0, -1, -3, -4,
- -1, -1, 0, 1, 0, 0, -2, -3, -1, -1, 0, 1, 1, 1, 0, -1,
- 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
- 0, 1, 0, 0, 1, 1, 1, 2, 1, 2, 0, 0, 0, 0, -1, 1,
- 0, 2, 0, -1, 1, 0, -1, 0, 0, 1, 0, 0, 2, 1, 0, 1,
- 0, 1, -1, 0, 2, 2, 0, 1, -1, 0, -1, -1, 2, 1, 1, 2,
- -2, -2, -3, -2, 0, 1, 1, 1, -2, -2, -3, -3, -1, -1, -1, 0,
- -3, -1, 0, 1, 2, 1, 1, 0, -3, -1, 0, 1, 2, 1, 1, 1,
- -2, 0, 0, 1, 1, 1, 1, 1, -1, 0, 0, 0, 0, 0, 0, 0,
- -2, 0, 0, 0, 0, -1, -1, 0, -2, 0, 0, 0, 0, 0, -1, -1,
- -3, 0, 1, 1, 1, 1, 0, 1, -5, -2, 0, 1, 2, 2, 1, 2,
- -2, -1, -1, 0, 0, 1, 2, 3, 0, 0, 1, 1, 0, 0, 1, 2,
- 0, 0, 1, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, -2, -1, 0,
- -2, -2, -2, -2, -2, -1, 0, 1, 0, 0, 0, -1, 0, 1, 2, 2,
- 2, 1, 0, 0, 0, 1, 2, 2, 2, 1, 0, -1, -1, -1, 0, 0,
- 0, 1, 1, 1, 1, 1, -1, -4, -1, -1, 0, 1, 1, 1, 0, -3,
- -2, -1, 0, 0, 1, 2, 2, -2, -1, 0, 0, 0, 0, 2, 3, -1,
- -1, 0, 0, 0, 0, 1, 2, 0, 0, 0, -1, -2, -1, 1, 1, 0,
- 0, 0, -1, -2, -2, 0, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2,
- 1, 0, 0, 0, -2, -3, -2, -3, 0, 0, 1, 0, -2, -2, -1, -1,
- 0, -1, 1, 1, -1, -1, 0, 0, 0, -1, 1, 1, -1, -1, 0, 0,
- 0, 1, 2, 1, -1, -1, 0, 1, 1, 2, 3, 2, 0, 0, 1, 2,
- -1, 0, 2, 1, 0, 0, 2, 3, -2, -1, 0, 0, -1, 0, 1, 2,
- 1, 1, 0, -1, -2, -2, -1, 1, 1, 1, 1, -1, -2, -2, 0, 2,
- 1, 1, 1, -1, -1, -1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 2,
- -1, -1, -1, 0, 0, 0, 1, 2, -1, -2, -1, 1, 1, 1, 0, 0,
- -1, -2, -1, 1, 2, 2, 0, -1, -1, -2, -1, 2, 2, 2, 0, -1,
- -1, -1, -1, -2, -1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, 2,
- 1, 0, 0, 0, 0, 1, 1, 2, 1, 1, 0, 0, 1, 1, 1, 1,
- 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1,
- 1, 2, 1, 0, -1, -2, -2, -3, 2, 2, 1, 0, -2, -3, -4, -4,
- -4, -2, 1, 1, 1, 1, 0, 0, -2, 0, 1, 0, 0, 0, 0, 0,
- 0, 1, 1, -2, -2, -1, 0, 1, 2, 2, 1, -2, -2, -1, 1, 2,
- 1, 2, 1, -2, -2, -1, 1, 2, -1, 1, 1, -1, -1, -1, 0, 1,
- -2, 0, 1, 1, 0, -1, -1, 0, -2, 0, 2, 2, 1, -1, -1, 0,
- 1, 1, 0, 0, 0, 1, 0, 0, -2, -3, -3, -2, -2, -1, 0, 0,
- -3, -4, -3, -2, -1, 0, 0, 0, -1, -1, 0, 1, 2, 3, 2, 1,
- 0, 1, 2, 3, 3, 3, 2, 1, 1, 1, 1, 2, 1, 0, 0, -1,
- 0, 0, 0, 0, -1, -1, -1, -1, 0, -1, -1, 0, 0, 0, 0, 0,
- 1, 1, 0, 0, -1, -1, 0, 2, 0, 0, 1, 0, -1, -1, 1, 1,
- -2, -1, 0, 1, 1, 1, 1, 1, -3, -3, 0, 2, 2, 1, 1, 0,
- -2, -2, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, -1,
- 3, 1, -1, -3, -2, -1, 0, 1, 4, 2, -1, -3, -3, -1, 1, 2,
- 0, 0, 0, -1, -1, -1, -1, -1, 1, 2, 1, 0, 0, 0, -1, -1,
- 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 4, 2, 1, 0, -1, -2,
- 3, 3, 2, 1, 0, -1, -2, -2, 1, 1, 0, -1, -1, -2, -2, -3,
- 0, 0, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -1, -2, -2, -1,
- 1, 2, 2, 2, 2, 1, 2, 2, 0, 1, 1, 1, 1, 0, 0, 0,
- 0, 0, 0, 1, 1, 0, -1, -2, 0, 0, 0, 0, 1, 0, -1, -4,
- 1, 0, 0, 0, 0, 0, -2, -5, 1, 0, 0, 0, 0, 0, -1, -4,
- 1, 0, -1, 0, 0, 0, -1, -3, 0, -1, -1, 0, 1, 1, 1, -1,
- -2, -1, 0, 0, -1, -1, -1, -2, -1, 0, 0, 0, -1, -1, -2, -2,
- 0, 1, 1, 0, -1, -1, -1, -2, 0, 1, 1, 0, 0, 0, -1, -1,
- 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 2, 2, 1,
- 1, 1, 0, 0, 1, 2, 2, 1, 1, 1, 0, -1, 0, 1, 1, 0,
- 4, 2, 1, 0, 0, 1, 1, 1, 4, 2, 1, 0, 0, 0, 0, 1,
- 3, 1, 0, 0, -1, -1, -1, 0, 1, 0, 0, -1, -1, -2, -1, 0,
- 0, 0, 0, 0, -1, -1, -1, 0, -1, -1, 0, 0, -1, -1, 0, 1,
- -2, -1, 0, -1, -1, 0, 0, 1, -2, -2, -1, -2, -1, 0, 0, 1,
- 0, 1, 1, 1, 2, 1, 0, -1, -1, -1, -1, 0, 0, -1, -2, -2,
- -1, 0, -1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2,
- 0, 0, 0, 0, 0, 0, 2, 3, -1, 0, -1, -1, -1, -1, 0, 3,
- -1, 0, 0, -1, -1, -2, 0, 3, 0, 0, 0, 0, -1, -1, 1, 4,
- 2, 2, 0, 0, 0, 0, 0, 1, 1, 1, -1, -2, -1, -2, -1, 1,
- -1, -1, -2, -2, -2, -3, -2, 0, -1, 0, -1, -1, -1, -2, -1, 1,
- 1, 1, 0, 0, 1, 0, 0, 1, 2, 2, 0, 0, 1, 0, 0, 1,
- 2, 2, 0, 0, 0, 0, -1, -1, 2, 2, 0, 0, 1, 0, -1, -1,
- -1, 0, 1, 1, 0, -1, -1, -1, 1, 2, 3, 2, 1, 0, 0, 0,
- 0, 1, 1, 1, 0, -1, 0, 0, -2, -2, -1, 0, 1, 0, 0, 0,
- -2, -2, -1, 2, 2, 2, 1, 0, -2, -1, 0, 1, 1, 0, 0, -1,
- -1, -1, 0, 0, -1, -2, -1, -2, 0, 1, 1, 1, 0, 0, 1, 1,
- -3, -3, -3, -2, -1, -1, -2, -2, -1, -1, 0, 1, 2, 1, 0, 0,
- 1, 1, 1, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1, 0, -1, 1,
- 1, 0, -1, -1, 0, 0, -1, 1, 0, -1, -1, -1, 0, -1, -1, 1,
- 1, 0, -1, 0, 0, -1, 0, 2, 2, 0, -1, 0, 0, 0, 0, 2,
- 1, 0, -2, -1, 0, 1, 1, 0, 2, 0, -1, -1, 0, 1, 1, 0,
- 1, 0, -2, -1, 0, 1, 0, -1, 1, 0, -1, -1, 0, 1, 0, -1,
- 0, 1, 1, 0, 1, 1, 0, 0, -2, 1, 2, 1, 0, 0, 0, 1,
- -5, 0, 2, 1, 0, -1, 0, 1, -6, -1, 2, 1, 0, -1, 0, 0,
- 5, 3, 0, -1, -2, -1, -1, -1, 1, 1, 0, -1, -1, 0, -1, -1,
- -1, 0, 1, 1, 2, 2, 1, 0, -2, -1, 0, 1, 2, 1, 1, 1,
- -2, -1, -1, -1, 0, -1, 0, 1, 0, 1, 0, 0, -1, -1, 0, 0,
- 0, 1, 1, 1, 1, 0, 0, 0, -3, -2, 0, 1, 1, 0, 0, -1,
- -1, 0, 1, 0, -1, 0, 2, 3, -1, 0, 0, -2, -4, -2, -1, 0,
- 0, 1, 1, 0, -2, -1, 0, -1, 1, 2, 3, 1, 0, 1, 1, 0,
- -1, 0, 1, 1, 1, 1, 1, 0, -2, -3, -2, 0, 0, 0, 1, 0,
- -1, -2, -2, 0, 1, 0, 0, -1, 3, 1, 0, 0, 1, 0, -1, -1,
- -2, -1, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 1, 1, 1,
- -1, -1, -1, 0, 1, 1, 1, 1, 0, -2, -3, -1, 1, 0, 0, 0,
- 1, -1, -3, -1, 1, 1, 0, -1, 3, 1, -1, 1, 2, 2, 0, -1,
- 3, 1, 0, 1, 2, 1, 1, 0, 0, -2, -2, -1, -1, 0, 0, 0,
- 1, 0, -1, -1, 1, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2, 1,
- -1, -1, -1, 0, 0, 1, 2, 0, -2, 0, 0, 0, 0, 0, 1, -1,
- -1, 0, 1, 0, -1, -1, -1, -1, 0, 1, 1, 2, 0, -2, -1, 0,
- 1, 2, 2, 2, 1, -1, -1, 0, 0, 1, 1, 1, 0, -2, -2, -1,
- 0, 0, -1, -1, -1, -1, -2, -2, 0, 0, -1, 0, 1, 2, 2, 1,
- 0, 0, -1, -1, 0, 1, 2, 2, 1, 1, -1, -2, -1, -1, -1, -1,
- 2, 2, 1, 0, 0, -1, -2, -2, 1, 2, 2, 1, 0, 0, -2, -2,
- 0, 0, 0, 0, 1, 1, 0, -1, 0, -1, -1, -1, 2, 3, 2, 1,
- 0, -2, 1, 2, -1, 0, 0, 1, -1, -2, 2, 3, -1, 0, 0, 0,
- 0, -2, 2, 3, -1, -1, 0, 0, 0, -1, 3, 2, -2, 0, 1, 0,
- 0, -1, 3, 1, -2, 0, 1, 0, 0, -1, 2, 1, -1, 1, 0, -1,
- 0, 0, 1, -1, -2, 0, 0, -1, 1, 0, 0, -2, -2, -1, -1, -1,
- 1, 1, 1, 1, 1, -1, -1, -2, 0, 0, 0, 1, 1, 1, 1, 1,
- 0, 0, 0, 1, 1, 1, 2, 3, 1, 0, 0, -1, 0, 0, 1, 2,
- 0, -1, -1, -2, -1, 0, 1, 2, -2, -2, -2, -2, -1, 0, 1, 1,
- -1, -1, -1, -1, 0, 0, 0, -1, 2, 2, 2, 0, -1, -1, -2, -4,
- -1, -2, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 0, 1, 2, 3,
- 1, 0, -1, 0, -1, 0, 1, 2, 1, 0, 0, 0, -1, 0, 2, 2,
- 1, 0, -1, -1, -2, 0, 1, 2, 0, -2, -2, -2, -3, -1, 0, 1,
- 0, -2, -2, -2, -2, -1, 1, 1, 0, 0, 0, 0, 0, 1, 2, 2
-};
-
-/* list of codebooks for intra-coded vectors */
-static const uint8_t* const svq1_intra_codebooks[4] = {
- svq1_intra_codebook_4x2, svq1_intra_codebook_4x4,
- svq1_intra_codebook_8x4, svq1_intra_codebook_8x8
-};
+++ /dev/null
-#ifndef SVQ1_VLC_H
-#define SVQ1_VLC_H
-
-/* values in this table range from 0..3; adjust retrieved value by +0 */
-static const uint8_t svq1_block_type_vlc[4][2] = {
- /* { code, length } */
- { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 }
-
-};
-
-/* values in this table range from -32..32; adjust retrieved value by -32 */
-static const uint16_t svq1_motion_component_vlc[65][2] = {
- /* { code, length } */
- { 0x5, 13 }, { 0x7, 13 }, { 0x5, 12 }, { 0x7, 12 },
- { 0x9, 12 }, { 0xB, 12 }, { 0xD, 12 }, { 0xF, 12 },
- { 0x9, 11 }, { 0xB, 11 }, { 0xD, 11 }, { 0xF, 11 },
- { 0x11, 11 }, { 0x13, 11 }, { 0x15, 11 }, { 0x17, 11 },
- { 0x19, 11 }, { 0x1B, 11 }, { 0x1D, 11 }, { 0x1F, 11 },
- { 0x21, 11 }, { 0x23, 11 }, { 0x13, 10 }, { 0x15, 10 },
- { 0x17, 10 }, { 0x7, 8 }, { 0x9, 8 }, { 0xB, 8 },
- { 0x7, 7 }, { 0x3, 5 }, { 0x3, 4 }, { 0x3, 3 },
- { 0x1, 1 }, { 0x2, 3 }, { 0x2, 4 }, { 0x2, 5 },
- { 0x6, 7 }, { 0xA, 8 }, { 0x8, 8 }, { 0x6, 8 },
- { 0x16, 10 }, { 0x14, 10 }, { 0x12, 10 }, { 0x22, 11 },
- { 0x20, 11 }, { 0x1E, 11 }, { 0x1C, 11 }, { 0x1A, 11 },
- { 0x18, 11 }, { 0x16, 11 }, { 0x14, 11 }, { 0x12, 11 },
- { 0x10, 11 }, { 0xE, 11 }, { 0xC, 11 }, { 0xA, 11 },
- { 0x8, 11 }, { 0xE, 12 }, { 0xC, 12 }, { 0xA, 12 },
- { 0x8, 12 }, { 0x6, 12 }, { 0x4, 12 }, { 0x6, 13 },
- { 0x4, 13 }
-};
-
-/* values in this table range from -1..6; adjust retrieved value by -1 */
-static const uint8_t svq1_intra_multistage_vlc[6][8][2] = {
- /* { code, length } */
-{
- { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 },
- { 0x3, 4 }, { 0x2, 4 }, { 0x0, 5 }, { 0x1, 4 }
-},{
- { 0x1, 4 }, { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 },
- { 0x3, 3 }, { 0x2, 3 }, { 0x0, 4 }, { 0x1, 3 }
-},{
- { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x0, 5 },
- { 0x3, 4 }, { 0x2, 3 }, { 0x2, 4 }, { 0x1, 4 }
-},{
- { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x0, 6 },
- { 0x3, 4 }, { 0x2, 4 }, { 0x1, 5 }, { 0x1, 4 }
-},{
- { 0x1, 6 }, { 0x1, 1 }, { 0x1, 2 }, { 0x3, 5 },
- { 0x2, 5 }, { 0x0, 6 }, { 0x1, 5 }, { 0x1, 3 }
-},{
- { 0x1, 7 }, { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 },
- { 0x1, 4 }, { 0x1, 6 }, { 0x0, 7 }, { 0x1, 5 }
-}
-};
-
-/* values in this table range from -1..6; adjust retrieved value by -1 */
-static const uint8_t svq1_inter_multistage_vlc[6][8][2] = {
- /* { code, length } */
-{
- { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
- { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 }
-},{
- { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 },
- { 0x2, 3 }, { 0x1, 3 }, { 0x1, 4 }, { 0x0, 4 }
-},{
- { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
- { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
-},{
- { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
- { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
-},{
- { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, { 0x3, 4 },
- { 0x2, 4 }, { 0x1, 4 }, { 0x1, 5 }, { 0x0, 5 }
-},{
- { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x3, 5 },
- { 0x2, 5 }, { 0x1, 5 }, { 0x1, 6 }, { 0x0, 6 }
-}
-};
-
-/* values in this table range from 0..255; adjust retrieved value by +0 */
-static const uint16_t svq1_intra_mean_vlc[256][2] = {
- /* { code, length } */
- { 0x37, 6 }, { 0x56, 7 }, { 0x1, 17 }, { 0x1, 20 },
- { 0x2, 20 }, { 0x3, 20 }, { 0x0, 20 }, { 0x4, 20 },
- { 0x5, 20 }, { 0x3, 19 }, { 0x15, 11 }, { 0x42, 9 },
- { 0x14, 11 }, { 0x3, 14 }, { 0x2, 14 }, { 0x1, 15 },
- { 0x1, 16 }, { 0x1, 12 }, { 0x2B, 10 }, { 0x18, 11 },
- { 0xC, 11 }, { 0x41, 9 }, { 0x78, 8 }, { 0x6C, 8 },
- { 0x55, 7 }, { 0xF, 4 }, { 0xE, 4 }, { 0x34, 6 },
- { 0x51, 7 }, { 0x72, 8 }, { 0x6E, 8 }, { 0x40, 9 },
- { 0x3F, 9 }, { 0x3E, 9 }, { 0x3D, 9 }, { 0x3C, 9 },
- { 0x3B, 9 }, { 0x3A, 9 }, { 0x39, 9 }, { 0x38, 9 },
- { 0x37, 9 }, { 0x43, 9 }, { 0x46, 9 }, { 0x47, 9 },
- { 0x45, 9 }, { 0x44, 9 }, { 0x49, 9 }, { 0x48, 9 },
- { 0x4A, 8 }, { 0x79, 8 }, { 0x76, 8 }, { 0x77, 8 },
- { 0x71, 8 }, { 0x75, 8 }, { 0x74, 8 }, { 0x73, 8 },
- { 0x6A, 8 }, { 0x55, 8 }, { 0x70, 8 }, { 0x6F, 8 },
- { 0x52, 8 }, { 0x6D, 8 }, { 0x4C, 8 }, { 0x6B, 8 },
- { 0x40, 7 }, { 0x69, 8 }, { 0x68, 8 }, { 0x67, 8 },
- { 0x66, 8 }, { 0x65, 8 }, { 0x64, 8 }, { 0x63, 8 },
- { 0x62, 8 }, { 0x61, 8 }, { 0x60, 8 }, { 0x5F, 8 },
- { 0x5E, 8 }, { 0x5D, 8 }, { 0x5C, 8 }, { 0x5B, 8 },
- { 0x5A, 8 }, { 0x59, 8 }, { 0x58, 8 }, { 0x57, 8 },
- { 0x56, 8 }, { 0x3D, 7 }, { 0x54, 8 }, { 0x53, 8 },
- { 0x3F, 7 }, { 0x51, 8 }, { 0x50, 8 }, { 0x4F, 8 },
- { 0x4E, 8 }, { 0x4D, 8 }, { 0x41, 7 }, { 0x4B, 8 },
- { 0x53, 7 }, { 0x3E, 7 }, { 0x48, 8 }, { 0x4F, 7 },
- { 0x52, 7 }, { 0x45, 8 }, { 0x50, 7 }, { 0x43, 8 },
- { 0x42, 8 }, { 0x41, 8 }, { 0x42, 7 }, { 0x43, 7 },
- { 0x3E, 8 }, { 0x44, 7 }, { 0x3C, 8 }, { 0x45, 7 },
- { 0x46, 7 }, { 0x47, 7 }, { 0x48, 7 }, { 0x49, 7 },
- { 0x4A, 7 }, { 0x4B, 7 }, { 0x4C, 7 }, { 0x4D, 7 },
- { 0x4E, 7 }, { 0x58, 7 }, { 0x59, 7 }, { 0x5A, 7 },
- { 0x5B, 7 }, { 0x5C, 7 }, { 0x5D, 7 }, { 0x44, 8 },
- { 0x49, 8 }, { 0x29, 8 }, { 0x3F, 8 }, { 0x3D, 8 },
- { 0x3B, 8 }, { 0x2C, 8 }, { 0x28, 8 }, { 0x25, 8 },
- { 0x26, 8 }, { 0x5E, 7 }, { 0x57, 7 }, { 0x54, 7 },
- { 0x5F, 7 }, { 0x62, 7 }, { 0x63, 7 }, { 0x64, 7 },
- { 0x61, 7 }, { 0x65, 7 }, { 0x67, 7 }, { 0x66, 7 },
- { 0x35, 6 }, { 0x36, 6 }, { 0x60, 7 }, { 0x39, 8 },
- { 0x3A, 8 }, { 0x38, 8 }, { 0x37, 8 }, { 0x36, 8 },
- { 0x35, 8 }, { 0x34, 8 }, { 0x33, 8 }, { 0x32, 8 },
- { 0x31, 8 }, { 0x30, 8 }, { 0x2D, 8 }, { 0x2B, 8 },
- { 0x2A, 8 }, { 0x27, 8 }, { 0x40, 8 }, { 0x46, 8 },
- { 0x47, 8 }, { 0x26, 9 }, { 0x25, 9 }, { 0x24, 9 },
- { 0x23, 9 }, { 0x22, 9 }, { 0x2E, 8 }, { 0x2F, 8 },
- { 0x1F, 9 }, { 0x36, 9 }, { 0x1D, 9 }, { 0x21, 9 },
- { 0x1B, 9 }, { 0x1C, 9 }, { 0x19, 9 }, { 0x1A, 9 },
- { 0x18, 9 }, { 0x17, 9 }, { 0x16, 9 }, { 0x1E, 9 },
- { 0x20, 9 }, { 0x27, 9 }, { 0x28, 9 }, { 0x29, 9 },
- { 0x2A, 9 }, { 0x2B, 9 }, { 0x2C, 9 }, { 0x2D, 9 },
- { 0x2E, 9 }, { 0x2F, 9 }, { 0x30, 9 }, { 0x35, 9 },
- { 0x31, 9 }, { 0x32, 9 }, { 0x33, 9 }, { 0x34, 9 },
- { 0x19, 10 }, { 0x2A, 10 }, { 0x17, 10 }, { 0x16, 10 },
- { 0x15, 10 }, { 0x28, 10 }, { 0x26, 10 }, { 0x25, 10 },
- { 0x22, 10 }, { 0x21, 10 }, { 0x18, 10 }, { 0x14, 10 },
- { 0x29, 10 }, { 0x12, 10 }, { 0xD, 10 }, { 0xE, 10 },
- { 0xF, 10 }, { 0x10, 10 }, { 0x11, 10 }, { 0x1A, 10 },
- { 0x1B, 10 }, { 0x1C, 10 }, { 0x1D, 10 }, { 0x1E, 10 },
- { 0x1F, 10 }, { 0x20, 10 }, { 0x13, 10 }, { 0x23, 10 },
- { 0x24, 10 }, { 0x9, 11 }, { 0x8, 11 }, { 0x7, 11 },
- { 0x27, 10 }, { 0x5, 11 }, { 0xB, 11 }, { 0x6, 11 },
- { 0x4, 11 }, { 0x3, 11 }, { 0x2, 11 }, { 0x1, 11 },
- { 0xA, 11 }, { 0x16, 11 }, { 0x19, 11 }, { 0x17, 11 },
- { 0xD, 11 }, { 0xE, 11 }, { 0xF, 11 }, { 0x10, 11 },
- { 0x11, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1, 14 }
-};
-
-/* values in this table range from -256..255; adjust retrieved value by -256 */
-static const uint16_t svq1_inter_mean_vlc[512][2] = {
- /* { code, length } */
- { 0x5A, 22 }, { 0xD4, 22 }, { 0xD5, 22 }, { 0xD6, 22 },
- { 0xD7, 22 }, { 0xD8, 22 }, { 0xD9, 22 }, { 0xDA, 22 },
- { 0xDB, 22 }, { 0xDC, 22 }, { 0xDD, 22 }, { 0xDE, 22 },
- { 0xDF, 22 }, { 0xE0, 22 }, { 0xE1, 22 }, { 0xE2, 22 },
- { 0xE3, 22 }, { 0xE4, 22 }, { 0xE5, 22 }, { 0xE6, 22 },
- { 0xE8, 22 }, { 0xCB, 22 }, { 0xE9, 22 }, { 0xEA, 22 },
- { 0xE7, 22 }, { 0xEC, 22 }, { 0xED, 22 }, { 0xEE, 22 },
- { 0xEF, 22 }, { 0xF0, 22 }, { 0xF1, 22 }, { 0xF2, 22 },
- { 0xF3, 22 }, { 0xF4, 22 }, { 0xF5, 22 }, { 0xF6, 22 },
- { 0xF7, 22 }, { 0xF8, 22 }, { 0x102, 22 }, { 0xEB, 22 },
- { 0xF9, 22 }, { 0xFC, 22 }, { 0xFD, 22 }, { 0xFE, 22 },
- { 0x100, 22 }, { 0x5C, 22 }, { 0x60, 22 }, { 0x101, 22 },
- { 0x71, 22 }, { 0x104, 22 }, { 0x105, 22 }, { 0xFB, 22 },
- { 0xFF, 22 }, { 0x86, 21 }, { 0xFA, 22 }, { 0x7C, 22 },
- { 0x75, 22 }, { 0x103, 22 }, { 0x78, 22 }, { 0xD3, 22 },
- { 0x7B, 22 }, { 0x82, 22 }, { 0xD2, 22 }, { 0xD1, 22 },
- { 0xD0, 22 }, { 0xCF, 22 }, { 0xCE, 22 }, { 0xCD, 22 },
- { 0xCC, 22 }, { 0xC3, 22 }, { 0xCA, 22 }, { 0xC9, 22 },
- { 0xC8, 22 }, { 0xC7, 22 }, { 0xC6, 22 }, { 0xC5, 22 },
- { 0x8B, 22 }, { 0xC4, 22 }, { 0xC2, 22 }, { 0xC1, 22 },
- { 0xC0, 22 }, { 0xBF, 22 }, { 0xBE, 22 }, { 0xBD, 22 },
- { 0xBC, 22 }, { 0xBB, 22 }, { 0xBA, 22 }, { 0xB9, 22 },
- { 0x61, 22 }, { 0x84, 22 }, { 0x85, 22 }, { 0x86, 22 },
- { 0x87, 22 }, { 0x88, 22 }, { 0x89, 22 }, { 0x8A, 22 },
- { 0x8C, 22 }, { 0x8D, 22 }, { 0x8E, 22 }, { 0x8F, 22 },
- { 0x90, 22 }, { 0x91, 22 }, { 0x92, 22 }, { 0x93, 22 },
- { 0x94, 22 }, { 0x95, 22 }, { 0x96, 22 }, { 0x97, 22 },
- { 0x98, 22 }, { 0x99, 22 }, { 0x9A, 22 }, { 0x9B, 22 },
- { 0x9C, 22 }, { 0x9D, 22 }, { 0x9E, 22 }, { 0x9F, 22 },
- { 0xA0, 22 }, { 0xA1, 22 }, { 0xA2, 22 }, { 0xA3, 22 },
- { 0xA4, 22 }, { 0xA5, 22 }, { 0xA6, 22 }, { 0xA7, 22 },
- { 0xA8, 22 }, { 0xA9, 22 }, { 0xAA, 22 }, { 0xAB, 22 },
- { 0x7F, 22 }, { 0x8F, 21 }, { 0xAC, 22 }, { 0xAD, 22 },
- { 0xAE, 22 }, { 0xAF, 22 }, { 0xB0, 22 }, { 0xB1, 22 },
- { 0x53, 20 }, { 0x90, 21 }, { 0xB2, 22 }, { 0x91, 21 },
- { 0xB3, 22 }, { 0xB4, 22 }, { 0x54, 20 }, { 0xB5, 22 },
- { 0xB6, 22 }, { 0x8C, 21 }, { 0x34, 19 }, { 0x3D, 18 },
- { 0x55, 20 }, { 0xB7, 22 }, { 0xB8, 22 }, { 0x8B, 21 },
- { 0x56, 20 }, { 0x3D, 19 }, { 0x57, 20 }, { 0x58, 20 },
- { 0x40, 19 }, { 0x43, 19 }, { 0x47, 19 }, { 0x2A, 18 },
- { 0x2E, 19 }, { 0x2C, 18 }, { 0x46, 19 }, { 0x59, 20 },
- { 0x49, 19 }, { 0x2D, 19 }, { 0x38, 18 }, { 0x36, 18 },
- { 0x39, 18 }, { 0x45, 19 }, { 0x28, 18 }, { 0x30, 18 },
- { 0x35, 18 }, { 0x20, 17 }, { 0x44, 19 }, { 0x32, 18 },
- { 0x31, 18 }, { 0x1F, 17 }, { 0x2F, 18 }, { 0x2E, 18 },
- { 0x2D, 18 }, { 0x21, 17 }, { 0x22, 17 }, { 0x23, 17 },
- { 0x24, 17 }, { 0x27, 16 }, { 0x23, 16 }, { 0x20, 16 },
- { 0x1D, 16 }, { 0x25, 16 }, { 0x1E, 16 }, { 0x24, 16 },
- { 0x2A, 16 }, { 0x26, 16 }, { 0x21, 15 }, { 0x29, 16 },
- { 0x22, 15 }, { 0x23, 15 }, { 0x24, 15 }, { 0x1B, 15 },
- { 0x1A, 15 }, { 0x1D, 15 }, { 0x1F, 15 }, { 0x27, 15 },
- { 0x17, 14 }, { 0x18, 14 }, { 0x19, 14 }, { 0x1B, 14 },
- { 0x1C, 14 }, { 0x1E, 14 }, { 0x25, 14 }, { 0x20, 14 },
- { 0x21, 14 }, { 0x13, 13 }, { 0x14, 13 }, { 0x15, 13 },
- { 0x16, 13 }, { 0x17, 13 }, { 0x18, 13 }, { 0x19, 13 },
- { 0x1A, 13 }, { 0x18, 12 }, { 0x17, 12 }, { 0x15, 12 },
- { 0x14, 12 }, { 0x13, 12 }, { 0x12, 12 }, { 0xF, 11 },
- { 0x10, 11 }, { 0x12, 11 }, { 0x13, 11 }, { 0x1B, 11 },
- { 0x1A, 11 }, { 0xE, 10 }, { 0x13, 10 }, { 0xF, 10 },
- { 0x10, 10 }, { 0x11, 10 }, { 0x12, 10 }, { 0xD, 9 },
- { 0x14, 9 }, { 0x15, 9 }, { 0xC, 9 }, { 0x13, 9 },
- { 0xF, 8 }, { 0xE, 8 }, { 0x10, 8 }, { 0x11, 8 },
- { 0xC, 7 }, { 0x9, 7 }, { 0xA, 7 }, { 0x8, 6 },
- { 0x9, 6 }, { 0x9, 5 }, { 0x8, 5 }, { 0x5, 4 },
- { 0x1, 1 }, { 0x3, 3 }, { 0x7, 5 }, { 0x6, 5 },
- { 0xB, 6 }, { 0xA, 6 }, { 0xE, 7 }, { 0xF, 7 },
- { 0xB, 7 }, { 0xD, 7 }, { 0xB, 8 }, { 0xD, 8 },
- { 0xC, 8 }, { 0xF, 9 }, { 0x10, 9 }, { 0x11, 9 },
- { 0xE, 9 }, { 0x12, 9 }, { 0x17, 10 }, { 0x14, 10 },
- { 0x16, 10 }, { 0x15, 10 }, { 0x19, 11 }, { 0x18, 11 },
- { 0x17, 11 }, { 0x16, 11 }, { 0x15, 11 }, { 0x14, 11 },
- { 0x11, 11 }, { 0x19, 12 }, { 0x1A, 12 }, { 0x16, 12 },
- { 0x1D, 12 }, { 0x1B, 12 }, { 0x1C, 12 }, { 0x20, 13 },
- { 0x1C, 13 }, { 0x23, 13 }, { 0x22, 13 }, { 0x21, 13 },
- { 0x1F, 13 }, { 0x1E, 13 }, { 0x1B, 13 }, { 0x1D, 13 },
- { 0x24, 14 }, { 0x16, 14 }, { 0x1A, 14 }, { 0x22, 14 },
- { 0x1D, 14 }, { 0x1F, 14 }, { 0x15, 14 }, { 0x23, 14 },
- { 0x18, 15 }, { 0x20, 15 }, { 0x29, 15 }, { 0x28, 15 },
- { 0x26, 15 }, { 0x25, 15 }, { 0x19, 15 }, { 0x1C, 15 },
- { 0x1E, 15 }, { 0x17, 15 }, { 0x2C, 16 }, { 0x2B, 16 },
- { 0x1C, 16 }, { 0x21, 16 }, { 0x2D, 16 }, { 0x28, 16 },
- { 0x1F, 16 }, { 0x1B, 16 }, { 0x1A, 16 }, { 0x22, 16 },
- { 0x2D, 17 }, { 0x32, 17 }, { 0x2C, 17 }, { 0x27, 17 },
- { 0x31, 17 }, { 0x33, 17 }, { 0x2F, 17 }, { 0x2B, 17 },
- { 0x37, 18 }, { 0x2A, 17 }, { 0x2E, 17 }, { 0x30, 17 },
- { 0x29, 17 }, { 0x28, 17 }, { 0x26, 17 }, { 0x25, 17 },
- { 0x2F, 19 }, { 0x33, 18 }, { 0x34, 18 }, { 0x30, 19 },
- { 0x3A, 18 }, { 0x3B, 18 }, { 0x31, 19 }, { 0x3C, 18 },
- { 0x2B, 18 }, { 0x29, 18 }, { 0x48, 19 }, { 0x27, 18 },
- { 0x42, 19 }, { 0x41, 19 }, { 0x26, 18 }, { 0x52, 20 },
- { 0x51, 20 }, { 0x3F, 19 }, { 0x3E, 19 }, { 0x39, 19 },
- { 0x3C, 19 }, { 0x3B, 19 }, { 0x3A, 19 }, { 0x25, 18 },
- { 0x38, 19 }, { 0x50, 20 }, { 0x37, 19 }, { 0x36, 19 },
- { 0x87, 21 }, { 0x4F, 20 }, { 0x35, 19 }, { 0x4E, 20 },
- { 0x33, 19 }, { 0x32, 19 }, { 0x4D, 20 }, { 0x4C, 20 },
- { 0x83, 22 }, { 0x4B, 20 }, { 0x81, 22 }, { 0x80, 22 },
- { 0x8E, 21 }, { 0x7E, 22 }, { 0x7D, 22 }, { 0x84, 21 },
- { 0x8D, 21 }, { 0x7A, 22 }, { 0x79, 22 }, { 0x4A, 20 },
- { 0x77, 22 }, { 0x76, 22 }, { 0x89, 21 }, { 0x74, 22 },
- { 0x73, 22 }, { 0x72, 22 }, { 0x49, 20 }, { 0x70, 22 },
- { 0x6F, 22 }, { 0x6E, 22 }, { 0x6D, 22 }, { 0x6C, 22 },
- { 0x6B, 22 }, { 0x6A, 22 }, { 0x69, 22 }, { 0x68, 22 },
- { 0x67, 22 }, { 0x66, 22 }, { 0x65, 22 }, { 0x64, 22 },
- { 0x63, 22 }, { 0x62, 22 }, { 0x8A, 21 }, { 0x88, 21 },
- { 0x5F, 22 }, { 0x5E, 22 }, { 0x5D, 22 }, { 0x85, 21 },
- { 0x5B, 22 }, { 0x83, 21 }, { 0x59, 22 }, { 0x58, 22 },
- { 0x57, 22 }, { 0x56, 22 }, { 0x55, 22 }, { 0x54, 22 },
- { 0x53, 22 }, { 0x52, 22 }, { 0x51, 22 }, { 0x50, 22 },
- { 0x4F, 22 }, { 0x4E, 22 }, { 0x4D, 22 }, { 0x4C, 22 },
- { 0x4B, 22 }, { 0x4A, 22 }, { 0x49, 22 }, { 0x48, 22 },
- { 0x47, 22 }, { 0x46, 22 }, { 0x45, 22 }, { 0x44, 22 },
- { 0x43, 22 }, { 0x42, 22 }, { 0x41, 22 }, { 0x40, 22 },
- { 0x3F, 22 }, { 0x3E, 22 }, { 0x3D, 22 }, { 0x3C, 22 },
- { 0x3B, 22 }, { 0x3A, 22 }, { 0x39, 22 }, { 0x38, 22 },
- { 0x37, 22 }, { 0x36, 22 }, { 0x35, 22 }, { 0x34, 22 },
- { 0x33, 22 }, { 0x32, 22 }, { 0x31, 22 }, { 0x30, 22 },
- { 0x2F, 22 }, { 0x2E, 22 }, { 0x2D, 22 }, { 0x2C, 22 },
- { 0x2B, 22 }, { 0x2A, 22 }, { 0x29, 22 }, { 0x28, 22 },
- { 0x27, 22 }, { 0x26, 22 }, { 0x25, 22 }, { 0x24, 22 },
- { 0x23, 22 }, { 0x22, 22 }, { 0x21, 22 }, { 0x20, 22 },
- { 0x1F, 22 }, { 0x1E, 22 }, { 0x1D, 22 }, { 0x1C, 22 },
- { 0x1B, 22 }, { 0x1A, 22 }, { 0x19, 22 }, { 0x18, 22 },
- { 0x17, 22 }, { 0x16, 22 }, { 0x15, 22 }, { 0x14, 22 },
- { 0x13, 22 }, { 0x12, 22 }, { 0x11, 22 }, { 0x10, 22 },
- { 0xF, 22 }, { 0xE, 22 }, { 0xD, 22 }, { 0xC, 22 },
- { 0xB, 22 }, { 0xA, 22 }, { 0x9, 22 }, { 0x8, 22 },
- { 0x7, 22 }, { 0x6, 22 }, { 0x5, 22 }, { 0x4, 22 },
- { 0x3, 22 }, { 0x2, 22 }, { 0x1, 22 }, { 0x0, 22 }
-};
-
-#endif
+++ /dev/null
-/*
- * Copyright (c) 2003 The FFmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *
- * How to use this decoder:
- * SVQ3 data is transported within Apple Quicktime files. Quicktime files
- * have stsd atoms to describe media trak properties. A stsd atom for a
- * video trak contains 1 or more ImageDescription atoms. These atoms begin
- * with the 4-byte length of the atom followed by the codec fourcc. Some
- * decoders need information in this atom to operate correctly. Such
- * is the case with SVQ3. In order to get the best use out of this decoder,
- * the calling app must make the SVQ3 ImageDescription atom available
- * via the AVCodecContext's extradata[_size] field:
- *
- * AVCodecContext.extradata = pointer to ImageDescription, first characters
- * are expected to be 'S', 'V', 'Q', and '3', NOT the 4-byte atom length
- * AVCodecContext.extradata_size = size of ImageDescription atom memory
- * buffer (which will be the same as the ImageDescription atom size field
- * from the QT file, minus 4 bytes since the length is missing)
- *
- * You will know you have these parameters passed correctly when the decoder
- * correctly decodes this file:
- * ftp://ftp.mplayerhq.hu/MPlayer/samples/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov
- *
- */
-
-/**
- * @file svq3.c
- * svq3 decoder.
- */
-
-#define FULLPEL_MODE 1
-#define HALFPEL_MODE 2
-#define THIRDPEL_MODE 3
-#define PREDICT_MODE 4
-
-/* dual scan (from some older h264 draft)
- o-->o-->o o
- | /|
- o o o / o
- | / | |/ |
- o o o o
- /
- o-->o-->o-->o
-*/
-static const uint8_t svq3_scan[16]={
- 0+0*4, 1+0*4, 2+0*4, 2+1*4,
- 2+2*4, 3+0*4, 3+1*4, 3+2*4,
- 0+1*4, 0+2*4, 1+1*4, 1+2*4,
- 0+3*4, 1+3*4, 2+3*4, 3+3*4,
-};
-
-static const uint8_t svq3_pred_0[25][2] = {
- { 0, 0 },
- { 1, 0 }, { 0, 1 },
- { 0, 2 }, { 1, 1 }, { 2, 0 },
- { 3, 0 }, { 2, 1 }, { 1, 2 }, { 0, 3 },
- { 0, 4 }, { 1, 3 }, { 2, 2 }, { 3, 1 }, { 4, 0 },
- { 4, 1 }, { 3, 2 }, { 2, 3 }, { 1, 4 },
- { 2, 4 }, { 3, 3 }, { 4, 2 },
- { 4, 3 }, { 3, 4 },
- { 4, 4 }
-};
-
-static const int8_t svq3_pred_1[6][6][5] = {
- { { 2,-1,-1,-1,-1 }, { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 },
- { 2, 1,-1,-1,-1 }, { 1, 2,-1,-1,-1 }, { 1, 2,-1,-1,-1 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 4, 3 }, { 0, 1, 2, 4, 3 },
- { 0, 2, 1, 4, 3 }, { 2, 0, 1, 3, 4 }, { 0, 4, 2, 1, 3 } },
- { { 2, 0,-1,-1,-1 }, { 2, 1, 0, 4, 3 }, { 1, 2, 4, 0, 3 },
- { 2, 1, 0, 4, 3 }, { 2, 1, 4, 3, 0 }, { 1, 2, 4, 0, 3 } },
- { { 2, 0,-1,-1,-1 }, { 2, 0, 1, 4, 3 }, { 1, 2, 0, 4, 3 },
- { 2, 1, 0, 4, 3 }, { 2, 1, 3, 4, 0 }, { 2, 4, 1, 0, 3 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 1, 3, 4 }, { 1, 2, 3, 0, 4 },
- { 2, 0, 1, 3, 4 }, { 2, 1, 3, 0, 4 }, { 2, 0, 4, 3, 1 } },
- { { 0, 2,-1,-1,-1 }, { 0, 2, 4, 1, 3 }, { 1, 4, 2, 0, 3 },
- { 4, 2, 0, 1, 3 }, { 2, 0, 1, 4, 3 }, { 4, 2, 1, 0, 3 } },
-};
-
-static const struct { uint8_t run; uint8_t level; } svq3_dct_tables[2][16] = {
- { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 2, 1 }, { 0, 2 }, { 3, 1 }, { 4, 1 }, { 5, 1 },
- { 0, 3 }, { 1, 2 }, { 2, 2 }, { 6, 1 }, { 7, 1 }, { 8, 1 }, { 9, 1 }, { 0, 4 } },
- { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 2, 1 }, { 0, 3 }, { 0, 4 }, { 0, 5 },
- { 3, 1 }, { 4, 1 }, { 1, 2 }, { 1, 3 }, { 0, 6 }, { 0, 7 }, { 0, 8 }, { 0, 9 } }
-};
-
-static const uint32_t svq3_dequant_coeff[32] = {
- 3881, 4351, 4890, 5481, 6154, 6914, 7761, 8718,
- 9781, 10987, 12339, 13828, 15523, 17435, 19561, 21873,
- 24552, 27656, 30847, 34870, 38807, 43747, 49103, 54683,
- 61694, 68745, 77615, 89113,100253,109366,126635,141533
-};
-
-
-static void svq3_luma_dc_dequant_idct_c(DCTELEM *block, int qp){
- const int qmul= svq3_dequant_coeff[qp];
-#define stride 16
- int i;
- int temp[16];
- static const int x_offset[4]={0, 1*stride, 4* stride, 5*stride};
- static const int y_offset[4]={0, 2*stride, 8* stride, 10*stride};
-
- for(i=0; i<4; i++){
- const int offset= y_offset[i];
- const int z0= 13*(block[offset+stride*0] + block[offset+stride*4]);
- const int z1= 13*(block[offset+stride*0] - block[offset+stride*4]);
- const int z2= 7* block[offset+stride*1] - 17*block[offset+stride*5];
- const int z3= 17* block[offset+stride*1] + 7*block[offset+stride*5];
-
- temp[4*i+0]= z0+z3;
- temp[4*i+1]= z1+z2;
- temp[4*i+2]= z1-z2;
- temp[4*i+3]= z0-z3;
- }
-
- for(i=0; i<4; i++){
- const int offset= x_offset[i];
- const int z0= 13*(temp[4*0+i] + temp[4*2+i]);
- const int z1= 13*(temp[4*0+i] - temp[4*2+i]);
- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i];
- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i];
-
- block[stride*0 +offset]= ((z0 + z3)*qmul + 0x80000)>>20;
- block[stride*2 +offset]= ((z1 + z2)*qmul + 0x80000)>>20;
- block[stride*8 +offset]= ((z1 - z2)*qmul + 0x80000)>>20;
- block[stride*10+offset]= ((z0 - z3)*qmul + 0x80000)>>20;
- }
-}
-#undef stride
-
-static void svq3_add_idct_c (uint8_t *dst, DCTELEM *block, int stride, int qp, int dc){
- const int qmul= svq3_dequant_coeff[qp];
- int i;
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-
- if (dc) {
- dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2));
- block[0] = 0;
- }
-
- for (i=0; i < 4; i++) {
- const int z0= 13*(block[0 + 4*i] + block[2 + 4*i]);
- const int z1= 13*(block[0 + 4*i] - block[2 + 4*i]);
- const int z2= 7* block[1 + 4*i] - 17*block[3 + 4*i];
- const int z3= 17* block[1 + 4*i] + 7*block[3 + 4*i];
-
- block[0 + 4*i]= z0 + z3;
- block[1 + 4*i]= z1 + z2;
- block[2 + 4*i]= z1 - z2;
- block[3 + 4*i]= z0 - z3;
- }
-
- for (i=0; i < 4; i++) {
- const int z0= 13*(block[i + 4*0] + block[i + 4*2]);
- const int z1= 13*(block[i + 4*0] - block[i + 4*2]);
- const int z2= 7* block[i + 4*1] - 17*block[i + 4*3];
- const int z3= 17* block[i + 4*1] + 7*block[i + 4*3];
- const int rr= (dc + 0x80000);
-
- dst[i + stride*0]= cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ];
- dst[i + stride*1]= cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ];
- dst[i + stride*2]= cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ];
- dst[i + stride*3]= cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ];
- }
-}
-
-static void pred4x4_down_left_svq3_c(uint8_t *src, uint8_t *topright, int stride){
- LOAD_TOP_EDGE
- LOAD_LEFT_EDGE
- const __attribute__((unused)) int unu0= t0;
- const __attribute__((unused)) int unu1= l0;
-
- src[0+0*stride]=(l1 + t1)>>1;
- src[1+0*stride]=
- src[0+1*stride]=(l2 + t2)>>1;
- src[2+0*stride]=
- src[1+1*stride]=
- src[0+2*stride]=
- src[3+0*stride]=
- src[2+1*stride]=
- src[1+2*stride]=
- src[0+3*stride]=
- src[3+1*stride]=
- src[2+2*stride]=
- src[1+3*stride]=
- src[3+2*stride]=
- src[2+3*stride]=
- src[3+3*stride]=(l3 + t3)>>1;
-}
-
-static void pred16x16_plane_svq3_c(uint8_t *src, int stride){
- pred16x16_plane_compat_c(src, stride, 1);
-}
-
-static inline int svq3_decode_block (GetBitContext *gb, DCTELEM *block,
- int index, const int type) {
-
- static const uint8_t *const scan_patterns[4] =
- { luma_dc_zigzag_scan, zigzag_scan, svq3_scan, chroma_dc_scan };
-
- int run, level, sign, vlc, limit;
- const int intra = (3 * type) >> 2;
- const uint8_t *const scan = scan_patterns[type];
-
- for (limit=(16 >> intra); index < 16; index=limit, limit+=8) {
- for (; (vlc = svq3_get_ue_golomb (gb)) != 0; index++) {
-
- if (vlc == INVALID_VLC)
- return -1;
-
- sign = (vlc & 0x1) - 1;
- vlc = (vlc + 1) >> 1;
-
- if (type == 3) {
- if (vlc < 3) {
- run = 0;
- level = vlc;
- } else if (vlc < 4) {
- run = 1;
- level = 1;
- } else {
- run = (vlc & 0x3);
- level = ((vlc + 9) >> 2) - run;
- }
- } else {
- if (vlc < 16) {
- run = svq3_dct_tables[intra][vlc].run;
- level = svq3_dct_tables[intra][vlc].level;
- } else if (intra) {
- run = (vlc & 0x7);
- level = (vlc >> 3) + ((run == 0) ? 8 : ((run < 2) ? 2 : ((run < 5) ? 0 : -1)));
- } else {
- run = (vlc & 0xF);
- level = (vlc >> 4) + ((run == 0) ? 4 : ((run < 3) ? 2 : ((run < 10) ? 1 : 0)));
- }
- }
-
- if ((index += run) >= limit)
- return -1;
-
- block[scan[index]] = (level ^ sign) - sign;
- }
-
- if (type != 2) {
- break;
- }
- }
-
- return 0;
-}
-
-static inline void svq3_mc_dir_part (MpegEncContext *s,
- int x, int y, int width, int height,
- int mx, int my, int dxy,
- int thirdpel, int dir, int avg) {
-
- const Picture *pic = (dir == 0) ? &s->last_picture : &s->next_picture;
- uint8_t *src, *dest;
- int i, emu = 0;
- int blocksize= 2 - (width>>3); //16->0, 8->1, 4->2
-
- mx += x;
- my += y;
-
- if (mx < 0 || mx >= (s->h_edge_pos - width - 1) ||
- my < 0 || my >= (s->v_edge_pos - height - 1)) {
-
- if ((s->flags & CODEC_FLAG_EMU_EDGE)) {
- emu = 1;
- }
-
- mx = clip (mx, -16, (s->h_edge_pos - width + 15));
- my = clip (my, -16, (s->v_edge_pos - height + 15));
- }
-
- /* form component predictions */
- dest = s->current_picture.data[0] + x + y*s->linesize;
- src = pic->data[0] + mx + my*s->linesize;
-
- if (emu) {
- ff_emulated_edge_mc (s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1),
- mx, my, s->h_edge_pos, s->v_edge_pos);
- src = s->edge_emu_buffer;
- }
- if(thirdpel)
- (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->linesize, width, height);
- else
- (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->linesize, height);
-
- if (!(s->flags & CODEC_FLAG_GRAY)) {
- mx = (mx + (mx < (int) x)) >> 1;
- my = (my + (my < (int) y)) >> 1;
- width = (width >> 1);
- height = (height >> 1);
- blocksize++;
-
- for (i=1; i < 3; i++) {
- dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize;
- src = pic->data[i] + mx + my*s->uvlinesize;
-
- if (emu) {
- ff_emulated_edge_mc (s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1),
- mx, my, (s->h_edge_pos >> 1), (s->v_edge_pos >> 1));
- src = s->edge_emu_buffer;
- }
- if(thirdpel)
- (avg ? s->dsp.avg_tpel_pixels_tab : s->dsp.put_tpel_pixels_tab)[dxy](dest, src, s->uvlinesize, width, height);
- else
- (avg ? s->dsp.avg_pixels_tab : s->dsp.put_pixels_tab)[blocksize][dxy](dest, src, s->uvlinesize, height);
- }
- }
-}
-
-static inline int svq3_mc_dir (H264Context *h, int size, int mode, int dir, int avg) {
-
- int i, j, k, mx, my, dx, dy, x, y;
- MpegEncContext *const s = (MpegEncContext *) h;
- const int part_width = ((size & 5) == 4) ? 4 : 16 >> (size & 1);
- const int part_height = 16 >> ((unsigned) (size + 1) / 3);
- const int extra_width = (mode == PREDICT_MODE) ? -16*6 : 0;
- const int h_edge_pos = 6*(s->h_edge_pos - part_width ) - extra_width;
- const int v_edge_pos = 6*(s->v_edge_pos - part_height) - extra_width;
-
- for (i=0; i < 16; i+=part_height) {
- for (j=0; j < 16; j+=part_width) {
- const int b_xy = (4*s->mb_x+(j>>2)) + (4*s->mb_y+(i>>2))*h->b_stride;
- int dxy;
- x = 16*s->mb_x + j;
- y = 16*s->mb_y + i;
- k = ((j>>2)&1) + ((i>>1)&2) + ((j>>1)&4) + (i&8);
-
- if (mode != PREDICT_MODE) {
- pred_motion (h, k, (part_width >> 2), dir, 1, &mx, &my);
- } else {
- mx = s->next_picture.motion_val[0][b_xy][0]<<1;
- my = s->next_picture.motion_val[0][b_xy][1]<<1;
-
- if (dir == 0) {
- mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
- my = ((my * h->frame_num_offset) / h->prev_frame_num_offset + 1)>>1;
- } else {
- mx = ((mx * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
- my = ((my * (h->frame_num_offset - h->prev_frame_num_offset)) / h->prev_frame_num_offset + 1)>>1;
- }
- }
-
- /* clip motion vector prediction to frame border */
- mx = clip (mx, extra_width - 6*x, h_edge_pos - 6*x);
- my = clip (my, extra_width - 6*y, v_edge_pos - 6*y);
-
- /* get (optional) motion vector differential */
- if (mode == PREDICT_MODE) {
- dx = dy = 0;
- } else {
- dy = svq3_get_se_golomb (&s->gb);
- dx = svq3_get_se_golomb (&s->gb);
-
- if (dx == INVALID_VLC || dy == INVALID_VLC) {
- return -1;
- }
- }
-
- /* compute motion vector */
- if (mode == THIRDPEL_MODE) {
- int fx, fy;
- mx = ((mx + 1)>>1) + dx;
- my = ((my + 1)>>1) + dy;
- fx= ((unsigned)(mx + 0x3000))/3 - 0x1000;
- fy= ((unsigned)(my + 0x3000))/3 - 0x1000;
- dxy= (mx - 3*fx) + 4*(my - 3*fy);
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, fx, fy, dxy, 1, dir, avg);
- mx += mx;
- my += my;
- } else if (mode == HALFPEL_MODE || mode == PREDICT_MODE) {
- mx = ((unsigned)(mx + 1 + 0x3000))/3 + dx - 0x1000;
- my = ((unsigned)(my + 1 + 0x3000))/3 + dy - 0x1000;
- dxy= (mx&1) + 2*(my&1);
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, mx>>1, my>>1, dxy, 0, dir, avg);
- mx *= 3;
- my *= 3;
- } else {
- mx = ((unsigned)(mx + 3 + 0x6000))/6 + dx - 0x1000;
- my = ((unsigned)(my + 3 + 0x6000))/6 + dy - 0x1000;
-
- svq3_mc_dir_part (s, x, y, part_width, part_height, mx, my, 0, 0, dir, avg);
- mx *= 6;
- my *= 6;
- }
-
- /* update mv_cache */
- if (mode != PREDICT_MODE) {
- int32_t mv = pack16to32(mx,my);
-
- if (part_height == 8 && i < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1*8] = mv;
-
- if (part_width == 8 && j < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1 + 1*8] = mv;
- }
- }
- if (part_width == 8 && j < 8) {
- *(int32_t *) h->mv_cache[dir][scan8[k] + 1] = mv;
- }
- if (part_width == 4 || part_height == 4) {
- *(int32_t *) h->mv_cache[dir][scan8[k]] = mv;
- }
- }
-
- /* write back motion vectors */
- fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4);
- }
- }
-
- return 0;
-}
-
-static int svq3_decode_mb (H264Context *h, unsigned int mb_type) {
- int i, j, k, m, dir, mode;
- int cbp = 0;
- uint32_t vlc;
- int8_t *top, *left;
- MpegEncContext *const s = (MpegEncContext *) h;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
-
- h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
- h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
- h->topright_samples_available = 0xFFFF;
-
- if (mb_type == 0) { /* SKIP */
- if (s->pict_type == P_TYPE || s->next_picture.mb_type[mb_xy] == -1) {
- svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0);
-
- if (s->pict_type == B_TYPE) {
- svq3_mc_dir_part (s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1);
- }
-
- mb_type = MB_TYPE_SKIP;
- } else {
- svq3_mc_dir (h, s->next_picture.mb_type[mb_xy], PREDICT_MODE, 0, 0);
- svq3_mc_dir (h, s->next_picture.mb_type[mb_xy], PREDICT_MODE, 1, 1);
-
- mb_type = MB_TYPE_16x16;
- }
- } else if (mb_type < 8) { /* INTER */
- if (h->thirdpel_flag && h->halfpel_flag == !get_bits (&s->gb, 1)) {
- mode = THIRDPEL_MODE;
- } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits (&s->gb, 1)) {
- mode = HALFPEL_MODE;
- } else {
- mode = FULLPEL_MODE;
- }
-
- /* fill caches */
- /* note ref_cache should contain here:
- ????????
- ???11111
- N??11111
- N??11111
- N??11111
- N
- */
-
- for (m=0; m < 2; m++) {
- if (s->mb_x > 0 && h->intra4x4_pred_mode[mb_xy - 1][0] != -1) {
- for (i=0; i < 4; i++) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - 1 + i*h->b_stride];
- }
- } else {
- for (i=0; i < 4; i++) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = 0;
- }
- }
- if (s->mb_y > 0) {
- memcpy (h->mv_cache[m][scan8[0] - 1*8], s->current_picture.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t));
- memset (&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[mb_xy - s->mb_stride][4] == -1) ? PART_NOT_AVAILABLE : 1, 4);
-
- if (s->mb_x < (s->mb_width - 1)) {
- *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride + 4];
- h->ref_cache[m][scan8[0] + 4 - 1*8] =
- (h->intra4x4_pred_mode[mb_xy - s->mb_stride + 1][0] == -1 ||
- h->intra4x4_pred_mode[mb_xy - s->mb_stride][4] == -1) ? PART_NOT_AVAILABLE : 1;
- }else
- h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE;
- if (s->mb_x > 0) {
- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride - 1];
- h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] == -1) ? PART_NOT_AVAILABLE : 1;
- }else
- h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE;
- }else
- memset (&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8);
-
- if (s->pict_type != B_TYPE)
- break;
- }
-
- /* decode motion vector(s) and form prediction(s) */
- if (s->pict_type == P_TYPE) {
- svq3_mc_dir (h, (mb_type - 1), mode, 0, 0);
- } else { /* B_TYPE */
- if (mb_type != 2) {
- svq3_mc_dir (h, 0, mode, 0, 0);
- } else {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- if (mb_type != 1) {
- svq3_mc_dir (h, 0, mode, 1, (mb_type == 3));
- } else {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- }
-
- mb_type = MB_TYPE_16x16;
- } else if (mb_type == 8 || mb_type == 33) { /* INTRA4x4 */
- memset (h->intra4x4_pred_mode_cache, -1, 8*5*sizeof(int8_t));
-
- if (mb_type == 8) {
- if (s->mb_x > 0) {
- for (i=0; i < 4; i++) {
- h->intra4x4_pred_mode_cache[scan8[0] - 1 + i*8] = h->intra4x4_pred_mode[mb_xy - 1][i];
- }
- if (h->intra4x4_pred_mode_cache[scan8[0] - 1] == -1) {
- h->left_samples_available = 0x5F5F;
- }
- }
- if (s->mb_y > 0) {
- h->intra4x4_pred_mode_cache[4+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][4];
- h->intra4x4_pred_mode_cache[5+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][5];
- h->intra4x4_pred_mode_cache[6+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][6];
- h->intra4x4_pred_mode_cache[7+8*0] = h->intra4x4_pred_mode[mb_xy - s->mb_stride][3];
-
- if (h->intra4x4_pred_mode_cache[4+8*0] == -1) {
- h->top_samples_available = 0x33FF;
- }
- }
-
- /* decode prediction codes for luma blocks */
- for (i=0; i < 16; i+=2) {
- vlc = svq3_get_ue_golomb (&s->gb);
-
- if (vlc >= 25)
- return -1;
-
- left = &h->intra4x4_pred_mode_cache[scan8[i] - 1];
- top = &h->intra4x4_pred_mode_cache[scan8[i] - 8];
-
- left[1] = svq3_pred_1[top[0] + 1][left[0] + 1][svq3_pred_0[vlc][0]];
- left[2] = svq3_pred_1[top[1] + 1][left[1] + 1][svq3_pred_0[vlc][1]];
-
- if (left[1] == -1 || left[2] == -1)
- return -1;
- }
- } else { /* mb_type == 33, DC_128_PRED block type */
- for (i=0; i < 4; i++) {
- memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_PRED, 4);
- }
- }
-
- write_back_intra_pred_mode (h);
-
- if (mb_type == 8) {
- check_intra4x4_pred_mode (h);
-
- h->top_samples_available = (s->mb_y == 0) ? 0x33FF : 0xFFFF;
- h->left_samples_available = (s->mb_x == 0) ? 0x5F5F : 0xFFFF;
- } else {
- for (i=0; i < 4; i++) {
- memset (&h->intra4x4_pred_mode_cache[scan8[0] + 8*i], DC_128_PRED, 4);
- }
-
- h->top_samples_available = 0x33FF;
- h->left_samples_available = 0x5F5F;
- }
-
- mb_type = MB_TYPE_INTRA4x4;
- } else { /* INTRA16x16 */
- dir = i_mb_type_info[mb_type - 8].pred_mode;
- dir = (dir >> 1) ^ 3*(dir & 1) ^ 1;
-
- if ((h->intra16x16_pred_mode = check_intra_pred_mode (h, dir)) == -1)
- return -1;
-
- cbp = i_mb_type_info[mb_type - 8].cbp;
- mb_type = MB_TYPE_INTRA16x16;
- }
-
- if (!IS_INTER(mb_type) && s->pict_type != I_TYPE) {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- if (s->pict_type == B_TYPE) {
- for (i=0; i < 4; i++) {
- memset (s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t));
- }
- }
- }
- if (!IS_INTRA4x4(mb_type)) {
- memset (h->intra4x4_pred_mode[mb_xy], DC_PRED, 8);
- }
- if (!IS_SKIP(mb_type) || s->pict_type == B_TYPE) {
- memset (h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t));
- s->dsp.clear_blocks(h->mb);
- }
-
- if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == B_TYPE)) {
- if ((vlc = svq3_get_ue_golomb (&s->gb)) >= 48)
- return -1;
-
- cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc];
- }
- if (IS_INTRA16x16(mb_type) || (s->pict_type != I_TYPE && s->adaptive_quant && cbp)) {
- s->qscale += svq3_get_se_golomb (&s->gb);
-
- if (s->qscale > 31)
- return -1;
- }
- if (IS_INTRA16x16(mb_type)) {
- if (svq3_decode_block (&s->gb, h->mb, 0, 0))
- return -1;
- }
-
- if (cbp) {
- const int index = IS_INTRA16x16(mb_type) ? 1 : 0;
- const int type = ((s->qscale < 24 && IS_INTRA4x4(mb_type)) ? 2 : 1);
-
- for (i=0; i < 4; i++) {
- if ((cbp & (1 << i))) {
- for (j=0; j < 4; j++) {
- k = index ? ((j&1) + 2*(i&1) + 2*(j&2) + 4*(i&2)) : (4*i + j);
- h->non_zero_count_cache[ scan8[k] ] = 1;
-
- if (svq3_decode_block (&s->gb, &h->mb[16*k], index, type))
- return -1;
- }
- }
- }
-
- if ((cbp & 0x30)) {
- for (i=0; i < 2; ++i) {
- if (svq3_decode_block (&s->gb, &h->mb[16*(16 + 4*i)], 0, 3))
- return -1;
- }
-
- if ((cbp & 0x20)) {
- for (i=0; i < 8; i++) {
- h->non_zero_count_cache[ scan8[16+i] ] = 1;
-
- if (svq3_decode_block (&s->gb, &h->mb[16*(16 + i)], 1, 1))
- return -1;
- }
- }
- }
- }
-
- s->current_picture.mb_type[mb_xy] = mb_type;
-
- if (IS_INTRA(mb_type)) {
- h->chroma_pred_mode = check_intra_pred_mode (h, DC_PRED8x8);
- }
-
- return 0;
-}
-
-static int svq3_decode_slice_header (H264Context *h) {
- MpegEncContext *const s = (MpegEncContext *) h;
- const int mb_xy = s->mb_x + s->mb_y*s->mb_stride;
- int i, header;
-
- header = get_bits (&s->gb, 8);
-
- if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) {
- /* TODO: what? */
- fprintf (stderr, "unsupported slice header (%02X)\n", header);
- return -1;
- } else {
- int length = (header >> 5) & 3;
-
- h->next_slice_index = s->gb.index + 8*show_bits (&s->gb, 8*length) + 8*length;
-
- if (h->next_slice_index > s->gb.size_in_bits)
- return -1;
-
- s->gb.size_in_bits = h->next_slice_index - 8*(length - 1);
- s->gb.index += 8;
-
- if (length > 0) {
- memcpy ((uint8_t *) &s->gb.buffer[s->gb.index >> 3],
- &s->gb.buffer[s->gb.size_in_bits >> 3], (length - 1));
- }
- }
-
- if ((i = svq3_get_ue_golomb (&s->gb)) == INVALID_VLC || i >= 3)
- return -1;
-
- h->slice_type = golomb_to_pict_type[i];
-
- if ((header & 0x9F) == 2) {
- i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1));
- s->mb_skip_run = get_bits (&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width));
- } else {
- get_bits1 (&s->gb);
- s->mb_skip_run = 0;
- }
-
- h->slice_num = get_bits (&s->gb, 8);
- s->qscale = get_bits (&s->gb, 5);
- s->adaptive_quant = get_bits1 (&s->gb);
-
- /* unknown fields */
- get_bits1 (&s->gb);
-
- if (h->unknown_svq3_flag) {
- get_bits1 (&s->gb);
- }
-
- get_bits1 (&s->gb);
- get_bits (&s->gb, 2);
-
- while (get_bits1 (&s->gb)) {
- get_bits (&s->gb, 8);
- }
-
- /* reset intra predictors and invalidate motion vector references */
- if (s->mb_x > 0) {
- memset (h->intra4x4_pred_mode[mb_xy - 1], -1, 4*sizeof(int8_t));
- memset (h->intra4x4_pred_mode[mb_xy - s->mb_x], -1, 8*sizeof(int8_t)*s->mb_x);
- }
- if (s->mb_y > 0) {
- memset (h->intra4x4_pred_mode[mb_xy - s->mb_stride], -1, 8*sizeof(int8_t)*(s->mb_width - s->mb_x));
-
- if (s->mb_x > 0) {
- h->intra4x4_pred_mode[mb_xy - s->mb_stride - 1][3] = -1;
- }
- }
-
- return 0;
-}
-
-static int svq3_decode_frame (AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size) {
- MpegEncContext *const s = avctx->priv_data;
- H264Context *const h = avctx->priv_data;
- int m, mb_type;
-
- *data_size = 0;
-
- s->flags = avctx->flags;
-
- if (!s->context_initialized) {
- s->width = avctx->width;
- s->height = avctx->height;
- h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c;
- h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c;
- h->halfpel_flag = 1;
- h->thirdpel_flag = 1;
- h->unknown_svq3_flag = 0;
- h->chroma_qp = 4;
-
- if (MPV_common_init (s) < 0)
- return -1;
-
- h->b_stride = 4*s->mb_width;
-
- alloc_tables (h);
-
- if (avctx->extradata && avctx->extradata_size >= 0x64
- && !memcmp (avctx->extradata, "SVQ3", 4)) {
-
- GetBitContext gb;
-
- init_get_bits (&gb, (uint8_t *) avctx->extradata + 0x62,
- 8*(avctx->extradata_size - 0x62));
-
- /* 'frame size code' and optional 'width, height' */
- if (get_bits (&gb, 3) == 7) {
- get_bits (&gb, 12);
- get_bits (&gb, 12);
- }
-
- h->halfpel_flag = get_bits1 (&gb);
- h->thirdpel_flag = get_bits1 (&gb);
-
- /* unknown fields */
- get_bits1 (&gb);
- get_bits1 (&gb);
- get_bits1 (&gb);
- get_bits1 (&gb);
-
- s->low_delay = get_bits1 (&gb);
-
- /* unknown field */
- get_bits1 (&gb);
-
- while (get_bits1 (&gb)) {
- get_bits (&gb, 8);
- }
-
- h->unknown_svq3_flag = get_bits1 (&gb);
- avctx->has_b_frames = !s->low_delay;
- }
- }
-
- /* special case for last picture */
- if (buf_size == 0) {
- if (s->next_picture_ptr && !s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->next_picture;
- *data_size = sizeof(AVFrame);
- }
- return 0;
- }
-
- init_get_bits (&s->gb, buf, 8*buf_size);
-
- s->mb_x = s->mb_y = 0;
-
- if (svq3_decode_slice_header (h))
- return -1;
-
- s->pict_type = h->slice_type;
- s->picture_number = h->slice_num;
-
- if(avctx->debug&FF_DEBUG_PICT_INFO){
- printf("%c hpel:%d, tpel:%d aqp:%d qp:%d\n",
- av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag,
- s->adaptive_quant, s->qscale
- );
- }
-
- /* for hurry_up==5 */
- s->current_picture.pict_type = s->pict_type;
- s->current_picture.key_frame = (s->pict_type == I_TYPE);
-
- /* skip b frames if we dont have reference frames */
- if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0;
- /* skip b frames if we are in a hurry */
- if (avctx->hurry_up && s->pict_type == B_TYPE) return 0;
- /* skip everything if we are in a hurry >= 5 */
- if (avctx->hurry_up >= 5) return 0;
-
- if (s->next_p_frame_damaged) {
- if (s->pict_type == B_TYPE)
- return 0;
- else
- s->next_p_frame_damaged = 0;
- }
-
- frame_start (h);
-
- if (s->pict_type == B_TYPE) {
- h->frame_num_offset = (h->slice_num - h->prev_frame_num);
-
- if (h->frame_num_offset < 0) {
- h->frame_num_offset += 256;
- }
- if (h->frame_num_offset == 0 || h->frame_num_offset >= h->prev_frame_num_offset) {
- printf ("error in B-frame picture id\n");
- return -1;
- }
- } else {
- h->prev_frame_num = h->frame_num;
- h->frame_num = h->slice_num;
- h->prev_frame_num_offset = (h->frame_num - h->prev_frame_num);
-
- if (h->prev_frame_num_offset < 0) {
- h->prev_frame_num_offset += 256;
- }
- }
-
- for(m=0; m<2; m++){
- int i;
- for(i=0; i<4; i++){
- int j;
- for(j=-1; j<4; j++)
- h->ref_cache[m][scan8[0] + 8*i + j]= 1;
- h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE;
- }
- }
-
- for (s->mb_y=0; s->mb_y < s->mb_height; s->mb_y++) {
- for (s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) {
-
- if ( (s->gb.index + 7) >= s->gb.size_in_bits &&
- ((s->gb.index & 7) == 0 || show_bits (&s->gb, (-s->gb.index & 7)) == 0)) {
-
- s->gb.index = h->next_slice_index;
- s->gb.size_in_bits = 8*buf_size;
-
- if (svq3_decode_slice_header (h))
- return -1;
-
- /* TODO: support s->mb_skip_run */
- }
-
- mb_type = svq3_get_ue_golomb (&s->gb);
-
- if (s->pict_type == I_TYPE) {
- mb_type += 8;
- } else if (s->pict_type == B_TYPE && mb_type >= 4) {
- mb_type += 4;
- }
- if (mb_type > 33 || svq3_decode_mb (h, mb_type)) {
- fprintf (stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
-
- if (mb_type != 0) {
- hl_decode_mb (h);
- }
-
- if (s->pict_type != B_TYPE && !s->low_delay) {
- s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] =
- (s->pict_type == P_TYPE && mb_type < 8) ? (mb_type - 1) : -1;
- }
- }
-
- ff_draw_horiz_band(s, 16*s->mb_y, 16);
- }
-
- MPV_frame_end(s);
-
- if (s->pict_type == B_TYPE || s->low_delay) {
- *(AVFrame *) data = *(AVFrame *) &s->current_picture;
- } else {
- *(AVFrame *) data = *(AVFrame *) &s->last_picture;
- }
-
- avctx->frame_number = s->picture_number - 1;
-
- /* dont output the last pic after seeking */
- if (s->last_picture_ptr || s->low_delay) {
- *data_size = sizeof(AVFrame);
- }
-
- return buf_size;
-}
-
-
-AVCodec svq3_decoder = {
- "svq3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_SVQ3,
- sizeof(H264Context),
- decode_init,
- NULL,
- decode_end,
- svq3_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
-};
+++ /dev/null
-/*
- * utils for libavcodec
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file utils.c
- * utils.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-void *av_mallocz(unsigned int size)
-{
- void *ptr;
-
- ptr = av_malloc(size);
- if (!ptr)
- return NULL;
- memset(ptr, 0, size);
- return ptr;
-}
-
-char *av_strdup(const char *s)
-{
- char *ptr;
- int len;
- len = strlen(s) + 1;
- ptr = av_malloc(len);
- if (!ptr)
- return NULL;
- memcpy(ptr, s, len);
- return ptr;
-}
-
-/**
- * realloc which does nothing if the block is large enough
- */
-void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
-{
- if(min_size < *size)
- return ptr;
-
- *size= min_size + 10*1024;
-
- return av_realloc(ptr, *size);
-}
-
-
-/* allocation of static arrays - do not use for normal allocation */
-static unsigned int last_static = 0;
-static char*** array_static = NULL;
-static const unsigned int grow_static = 64; // ^2
-void *__av_mallocz_static(void** location, unsigned int size)
-{
- unsigned int l = (last_static + grow_static) & ~(grow_static - 1);
- void *ptr = av_mallocz(size);
- if (!ptr)
- return NULL;
-
- if (location)
- {
- if (l > last_static)
- array_static = av_realloc(array_static, l);
- array_static[last_static++] = (char**) location;
- *location = ptr;
- }
- return ptr;
-}
-/* free all static arrays and reset pointers to 0 */
-void av_free_static(void)
-{
- if (array_static)
- {
- unsigned i;
- for (i = 0; i < last_static; i++)
- {
- av_free(*array_static[i]);
- *array_static[i] = NULL;
- }
- av_free(array_static);
- array_static = 0;
- }
- last_static = 0;
-}
-
-/* cannot call it directly because of 'void **' casting is not automatic */
-void __av_freep(void **ptr)
-{
- av_free(*ptr);
- *ptr = NULL;
-}
-
-/* encoder management */
-AVCodec *first_avcodec;
-
-void register_avcodec(AVCodec *format)
-{
- AVCodec **p;
- p = &first_avcodec;
- while (*p != NULL) p = &(*p)->next;
- *p = format;
- format->next = NULL;
-}
-
-typedef struct InternalBuffer{
- int last_pic_num;
- uint8_t *base[4];
- uint8_t *data[4];
-}InternalBuffer;
-
-#define INTERNAL_BUFFER_SIZE 32
-
-int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
- int i;
- const int width = s->width;
- const int height= s->height;
- InternalBuffer *buf;
-
- assert(pic->data[0]==NULL);
- assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
-
- if(s->internal_buffer==NULL){
- s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
- }
-#if 0
- s->internal_buffer= av_fast_realloc(
- s->internal_buffer,
- &s->internal_buffer_size,
- sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
- );
-#endif
-
- buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
-
- if(buf->base[0]){
- pic->age= pic->coded_picture_number - buf->last_pic_num;
- buf->last_pic_num= pic->coded_picture_number;
- }else{
- int align, h_chroma_shift, v_chroma_shift;
- int w, h, pixel_size;
-
- avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
- switch(s->pix_fmt){
- case PIX_FMT_RGB555:
- case PIX_FMT_RGB565:
- case PIX_FMT_YUV422:
- pixel_size=2;
- break;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- pixel_size=3;
- break;
- case PIX_FMT_RGBA32:
- pixel_size=4;
- break;
- default:
- pixel_size=1;
- }
-
- if(s->codec_id==CODEC_ID_SVQ1) align=63;
- else align=15;
-
- w= (width +align)&~align;
- h= (height+align)&~align;
-
- if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
- w+= EDGE_WIDTH*2;
- h+= EDGE_WIDTH*2;
- }
-
- buf->last_pic_num= -256*256*256*64;
-
- for(i=0; i<3; i++){
- const int h_shift= i==0 ? 0 : h_chroma_shift;
- const int v_shift= i==0 ? 0 : v_chroma_shift;
-
- pic->linesize[i]= pixel_size*w>>h_shift;
-
- buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16
- if(buf->base[i]==NULL) return -1;
- memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift);
-
- if(s->flags&CODEC_FLAG_EMU_EDGE)
- buf->data[i] = buf->base[i];
- else
- buf->data[i] = buf->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift);
- }
- pic->age= 256*256*256*64;
- pic->type= FF_BUFFER_TYPE_INTERNAL;
- }
-
- for(i=0; i<4; i++){
- pic->base[i]= buf->base[i];
- pic->data[i]= buf->data[i];
- }
- s->internal_buffer_count++;
-
- return 0;
-}
-
-void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
- int i;
- InternalBuffer *buf, *last, temp;
-
- assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
- assert(s->internal_buffer_count);
-
- buf = NULL; /* avoids warning */
- for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
- buf= &((InternalBuffer*)s->internal_buffer)[i];
- if(buf->data[0] == pic->data[0])
- break;
- }
- assert(i < s->internal_buffer_count);
- s->internal_buffer_count--;
- last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
-
- temp= *buf;
- *buf= *last;
- *last= temp;
-
- for(i=0; i<3; i++){
- pic->data[i]=NULL;
-// pic->base[i]=NULL;
- }
-//printf("R%X\n", pic->opaque);
-}
-
-enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum PixelFormat * fmt){
- return fmt[0];
-}
-
-void avcodec_get_context_defaults(AVCodecContext *s){
- s->bit_rate= 800*1000;
- s->bit_rate_tolerance= s->bit_rate*10;
- s->qmin= 2;
- s->qmax= 31;
- s->mb_qmin= 2;
- s->mb_qmax= 31;
- s->rc_eq= "tex^qComp";
- s->qcompress= 0.5;
- s->max_qdiff= 3;
- s->b_quant_factor=1.25;
- s->b_quant_offset=1.25;
- s->i_quant_factor=-0.8;
- s->i_quant_offset=0.0;
- s->error_concealment= 3;
- s->error_resilience= 1;
- s->workaround_bugs= FF_BUG_AUTODETECT;
- s->frame_rate_base= 1;
- s->frame_rate = 25;
- s->gop_size= 50;
- s->me_method= ME_EPZS;
- s->get_buffer= avcodec_default_get_buffer;
- s->release_buffer= avcodec_default_release_buffer;
- s->get_format= avcodec_default_get_format;
- s->me_subpel_quality=8;
-
- s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
- s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
-}
-
-/**
- * allocates a AVCodecContext and set it to defaults.
- * this can be deallocated by simply calling free()
- */
-AVCodecContext *avcodec_alloc_context(void){
- AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext));
-
- if(avctx==NULL) return NULL;
-
- avcodec_get_context_defaults(avctx);
-
- return avctx;
-}
-
-/**
- * allocates a AVPFrame and set it to defaults.
- * this can be deallocated by simply calling free()
- */
-AVFrame *avcodec_alloc_frame(void){
- AVFrame *pic= av_mallocz(sizeof(AVFrame));
-
- return pic;
-}
-
-int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
-{
- int ret;
-
- if(avctx->codec)
- return -1;
-
- avctx->codec = codec;
- avctx->codec_id = codec->id;
- avctx->frame_number = 0;
- if (codec->priv_data_size > 0) {
- avctx->priv_data = av_mallocz(codec->priv_data_size);
- if (!avctx->priv_data)
- return -ENOMEM;
- } else {
- avctx->priv_data = NULL;
- }
- ret = avctx->codec->init(avctx);
- if (ret < 0) {
- av_freep(&avctx->priv_data);
- return ret;
- }
- return 0;
-}
-
-int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const short *samples)
-{
- int ret;
-
- ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
- avctx->frame_number++;
- return ret;
-}
-
-int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
- const AVFrame *pict)
-{
- int ret;
-
- ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
-
- emms_c(); //needed to avoid a emms_c() call before every return;
-
- avctx->frame_number++;
- return ret;
-}
-
-/**
- * decode a frame.
- * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
- * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
- * @param buf_size the size of the buffer in bytes
- * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
- * @return -1 if error, otherwise return the number of
- * bytes used.
- */
-int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
- int *got_picture_ptr,
- uint8_t *buf, int buf_size)
-{
- int ret;
-
- ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
- buf, buf_size);
-
- emms_c(); //needed to avoid a emms_c() call before every return;
-
- if (*got_picture_ptr)
- avctx->frame_number++;
- return ret;
-}
-
-/* decode an audio frame. return -1 if error, otherwise return the
- *number of bytes used. If no frame could be decompressed,
- *frame_size_ptr is zero. Otherwise, it is the decompressed frame
- *size in BYTES. */
-int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
- int *frame_size_ptr,
- uint8_t *buf, int buf_size)
-{
- int ret;
-
- ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
- buf, buf_size);
- avctx->frame_number++;
- return ret;
-}
-
-int avcodec_close(AVCodecContext *avctx)
-{
- if (avctx->codec->close)
- avctx->codec->close(avctx);
- av_freep(&avctx->priv_data);
- avctx->codec = NULL;
- return 0;
-}
-
-AVCodec *avcodec_find_encoder(enum CodecID id)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->encode != NULL && p->id == id)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_encoder_by_name(const char *name)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->encode != NULL && strcmp(name,p->name) == 0)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_decoder(enum CodecID id)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->decode != NULL && p->id == id)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find_decoder_by_name(const char *name)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->decode != NULL && strcmp(name,p->name) == 0)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-AVCodec *avcodec_find(enum CodecID id)
-{
- AVCodec *p;
- p = first_avcodec;
- while (p) {
- if (p->id == id)
- return p;
- p = p->next;
- }
- return NULL;
-}
-
-void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
-{
- const char *codec_name;
- AVCodec *p;
- char buf1[32];
- char channels_str[100];
- int bitrate;
-
- if (encode)
- p = avcodec_find_encoder(enc->codec_id);
- else
- p = avcodec_find_decoder(enc->codec_id);
-
- if (p) {
- codec_name = p->name;
- if (!encode && enc->codec_id == CODEC_ID_MP3) {
- if (enc->sub_id == 2)
- codec_name = "mp2";
- else if (enc->sub_id == 1)
- codec_name = "mp1";
- }
- } else if (enc->codec_name[0] != '\0') {
- codec_name = enc->codec_name;
- } else {
- /* output avi tags */
- if (enc->codec_type == CODEC_TYPE_VIDEO) {
- snprintf(buf1, sizeof(buf1), "%c%c%c%c",
- enc->codec_tag & 0xff,
- (enc->codec_tag >> 8) & 0xff,
- (enc->codec_tag >> 16) & 0xff,
- (enc->codec_tag >> 24) & 0xff);
- } else {
- snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
- }
- codec_name = buf1;
- }
-
- switch(enc->codec_type) {
- case CODEC_TYPE_VIDEO:
- snprintf(buf, buf_size,
- "Video: %s%s",
- codec_name, enc->mb_decision ? " (hq)" : "");
- if (enc->codec_id == CODEC_ID_RAWVIDEO) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %s",
- avcodec_get_pix_fmt_name(enc->pix_fmt));
- }
- if (enc->width) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %dx%d, %0.2f fps",
- enc->width, enc->height,
- (float)enc->frame_rate / enc->frame_rate_base);
- }
- if (encode) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", q=%d-%d", enc->qmin, enc->qmax);
- }
- bitrate = enc->bit_rate;
- break;
- case CODEC_TYPE_AUDIO:
- snprintf(buf, buf_size,
- "Audio: %s",
- codec_name);
- switch (enc->channels) {
- case 1:
- strcpy(channels_str, "mono");
- break;
- case 2:
- strcpy(channels_str, "stereo");
- break;
- case 6:
- strcpy(channels_str, "5:1");
- break;
- default:
- sprintf(channels_str, "%d channels", enc->channels);
- break;
- }
- if (enc->sample_rate) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d Hz, %s",
- enc->sample_rate,
- channels_str);
- }
-
- /* for PCM codecs, compute bitrate directly */
- switch(enc->codec_id) {
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- bitrate = enc->sample_rate * enc->channels * 16;
- break;
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- bitrate = enc->sample_rate * enc->channels * 8;
- break;
- default:
- bitrate = enc->bit_rate;
- break;
- }
- break;
- default:
- av_abort();
- }
- if (encode) {
- if (enc->flags & CODEC_FLAG_PASS1)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", pass 1");
- if (enc->flags & CODEC_FLAG_PASS2)
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", pass 2");
- }
- if (bitrate != 0) {
- snprintf(buf + strlen(buf), buf_size - strlen(buf),
- ", %d kb/s", bitrate / 1000);
- }
-}
-
-unsigned avcodec_version( void )
-{
- return LIBAVCODEC_VERSION_INT;
-}
-
-unsigned avcodec_build( void )
-{
- return LIBAVCODEC_BUILD;
-}
-
-/* must be called before any other functions */
-void avcodec_init(void)
-{
- static int inited = 0;
-
- if (inited != 0)
- return;
- inited = 1;
-
- dsputil_static_init();
-}
-
-/**
- * Flush buffers, should be called when seeking or when swicthing to a different stream.
- */
-void avcodec_flush_buffers(AVCodecContext *avctx)
-{
- if(avctx->codec->flush)
- avctx->codec->flush(avctx);
-}
-
-void avcodec_default_free_buffers(AVCodecContext *s){
- int i, j;
-
- if(s->internal_buffer==NULL) return;
-
- for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
- InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
- for(j=0; j<4; j++){
- av_freep(&buf->base[j]);
- buf->data[j]= NULL;
- }
- }
- av_freep(&s->internal_buffer);
-
- s->internal_buffer_count=0;
-}
-
-char av_get_pict_type_char(int pict_type){
- switch(pict_type){
- case I_TYPE: return 'I';
- case P_TYPE: return 'P';
- case B_TYPE: return 'B';
- case S_TYPE: return 'S';
- case SI_TYPE:return 'i';
- case SP_TYPE:return 'p';
- default: return '?';
- }
-}
-
-int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){
- int exact=1, sign=0;
- int64_t gcd, larger;
-
- assert(den != 0);
-
- if(den < 0){
- den= -den;
- nom= -nom;
- }
-
- if(nom < 0){
- nom= -nom;
- sign= 1;
- }
-
- for(;;){ //note is executed 1 or 2 times
- gcd = ff_gcd(nom, den);
- nom /= gcd;
- den /= gcd;
-
- larger= FFMAX(nom, den);
-
- if(larger > max){
- int64_t div= (larger + max - 1) / max;
- nom = (nom + div/2)/div;
- den = (den + div/2)/div;
- exact=0;
- }else
- break;
- }
-
- if(sign) nom= -nom;
-
- *dst_nom = nom;
- *dst_den = den;
-
- return exact;
-}
-
-int64_t av_rescale(int64_t a, int b, int c){
- uint64_t h, l;
- assert(c > 0);
- assert(b >=0);
-
- if(a<0) return -av_rescale(-a, b, c);
-
- h= a>>32;
- if(h==0) return a*b/c;
-
- l= a&0xFFFFFFFF;
- l *= b;
- h *= b;
-
- l += (h%c)<<32;
-
- return ((h/c)<<32) + l/c;
-}
+++ /dev/null
-/*
- * ATI VCR1 codec
- * Copyright (c) 2003 Michael Niedermayer
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file vcr1.c
- * ati vcr1 codec.
- */
-
-#include "avcodec.h"
-#include "mpegvideo.h"
-
-//#undef NDEBUG
-//#include <assert.h>
-
-typedef struct VCR1Context{
- AVCodecContext *avctx;
- AVFrame picture;
- int delta[16];
- int offset[4];
-} VCR1Context;
-
-static int decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- VCR1Context * const a = avctx->priv_data;
- AVFrame *picture = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- uint8_t *bytestream= buf;
- int i, x, y;
-
- *data_size = 0;
-
- /* special case for last picture */
- if (buf_size == 0) {
- return 0;
- }
-
- if(p->data[0])
- avctx->release_buffer(avctx, p);
-
- p->reference= 0;
- if(avctx->get_buffer(avctx, p) < 0){
- fprintf(stderr, "get_buffer() failed\n");
- return -1;
- }
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- for(i=0; i<16; i++){
- a->delta[i]= *(bytestream++);
- bytestream++;
- }
-
- for(y=0; y<avctx->height; y++){
- int offset;
- uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
-
- if((y&3) == 0){
- uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
- uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
-
- for(i=0; i<4; i++)
- a->offset[i]= *(bytestream++);
-
- offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
- for(x=0; x<avctx->width; x+=4){
- luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
- luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
- luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
- luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
- luma += 4;
-
- *(cb++) = bytestream[3];
- *(cr++) = bytestream[1];
-
- bytestream+= 4;
- }
- }else{
- offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
-
- for(x=0; x<avctx->width; x+=8){
- luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
- luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
- luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
- luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
- luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
- luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
- luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
- luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
- luma += 8;
- bytestream+= 4;
- }
- }
- }
-
- *picture= *(AVFrame*)&a->picture;
- *data_size = sizeof(AVPicture);
-
- emms_c();
-
- return buf_size;
-}
-
-#if 0
-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
- VCR1Context * const a = avctx->priv_data;
- AVFrame *pict = data;
- AVFrame * const p= (AVFrame*)&a->picture;
- int size;
- int mb_x, mb_y;
-
- *p = *pict;
- p->pict_type= I_TYPE;
- p->key_frame= 1;
-
- emms_c();
-
- align_put_bits(&a->pb);
- while(get_bit_count(&a->pb)&31)
- put_bits(&a->pb, 8, 0);
-
- size= get_bit_count(&a->pb)/32;
-
- return size*4;
-}
-#endif
-
-static void common_init(AVCodecContext *avctx){
- VCR1Context * const a = avctx->priv_data;
-
- avctx->coded_frame= (AVFrame*)&a->picture;
- a->avctx= avctx;
-}
-
-static int decode_init(AVCodecContext *avctx){
-
- common_init(avctx);
-
- avctx->pix_fmt= PIX_FMT_YUV410P;
-
- return 0;
-}
-
-static int encode_init(AVCodecContext *avctx){
-
- common_init(avctx);
-
- return 0;
-}
-
-static int decode_end(AVCodecContext *avctx){
-
- avcodec_default_free_buffers(avctx);
-
- return 0;
-}
-
-AVCodec vcr1_decoder = {
- "vcr1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VCR1,
- sizeof(VCR1Context),
- decode_init,
- NULL,
- decode_end,
- decode_frame,
- CODEC_CAP_DR1,
-};
-#if 0
-#ifdef CONFIG_ENCODERS
-
-AVCodec vcr1_encoder = {
- "vcr1",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VCR1,
- sizeof(VCR1Context),
- encode_init,
- encode_frame,
- //encode_end,
-};
-
-#endif //CONFIG_ENCODERS
-#endif
+++ /dev/null
-/*
- *
- * Copyright (C) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * VP3 Video Decoder by Mike Melanson (melanson@pcisys.net)
- * For more information about the VP3 coding process, visit:
- * http://www.pcisys.net/~melanson/codecs/
- *
- */
-
-/**
- * @file vp3.c
- * On2 VP3 Video Decoder
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-#include "dsputil.h"
-
-#include "vp3data.h"
-
-#define FRAGMENT_PIXELS 8
-
-/*
- * Debugging Variables
- *
- * Define one or more of the following compile-time variables to 1 to obtain
- * elaborate information about certain aspects of the decoding process.
- *
- * KEYFRAMES_ONLY: set this to 1 to only see keyframes (VP3 slideshow mode)
- * DEBUG_VP3: high-level decoding flow
- * DEBUG_INIT: initialization parameters
- * DEBUG_DEQUANTIZERS: display how the dequanization tables are built
- * DEBUG_BLOCK_CODING: unpacking the superblock/macroblock/fragment coding
- * DEBUG_MODES: unpacking the coding modes for individual fragments
- * DEBUG_VECTORS: display the motion vectors
- * DEBUG_TOKEN: display exhaustive information about each DCT token
- * DEBUG_VLC: display the VLCs as they are extracted from the stream
- * DEBUG_DC_PRED: display the process of reversing DC prediction
- * DEBUG_IDCT: show every detail of the IDCT process
- */
-
-#define KEYFRAMES_ONLY 0
-
-#define DEBUG_VP3 0
-#define DEBUG_INIT 0
-#define DEBUG_DEQUANTIZERS 0
-#define DEBUG_BLOCK_CODING 0
-#define DEBUG_MODES 0
-#define DEBUG_VECTORS 0
-#define DEBUG_TOKEN 0
-#define DEBUG_VLC 0
-#define DEBUG_DC_PRED 0
-#define DEBUG_IDCT 0
-
-#if DEBUG_VP3
-#define debug_vp3 printf
-#else
-static inline void debug_vp3(const char *format, ...) { }
-#endif
-
-#if DEBUG_INIT
-#define debug_init printf
-#else
-static inline void debug_init(const char *format, ...) { }
-#endif
-
-#if DEBUG_DEQUANTIZERS
-#define debug_dequantizers printf
-#else
-static inline void debug_dequantizers(const char *format, ...) { }
-#endif
-
-#if DEBUG_BLOCK_CODING
-#define debug_block_coding printf
-#else
-static inline void debug_block_coding(const char *format, ...) { }
-#endif
-
-#if DEBUG_MODES
-#define debug_modes printf
-#else
-static inline void debug_modes(const char *format, ...) { }
-#endif
-
-#if DEBUG_VECTORS
-#define debug_vectors printf
-#else
-static inline void debug_vectors(const char *format, ...) { }
-#endif
-
-#if DEBUG_TOKEN
-#define debug_token printf
-#else
-static inline void debug_token(const char *format, ...) { }
-#endif
-
-#if DEBUG_VLC
-#define debug_vlc printf
-#else
-static inline void debug_vlc(const char *format, ...) { }
-#endif
-
-#if DEBUG_DC_PRED
-#define debug_dc_pred printf
-#else
-static inline void debug_dc_pred(const char *format, ...) { }
-#endif
-
-#if DEBUG_IDCT
-#define debug_idct printf
-#else
-static inline void debug_idct(const char *format, ...) { }
-#endif
-
-typedef struct Vp3Fragment {
- DCTELEM coeffs[64];
- int coding_method;
- int coeff_count;
- int last_coeff;
- int motion_x;
- int motion_y;
- /* address of first pixel taking into account which plane the fragment
- * lives on as well as the plane stride */
- int first_pixel;
- /* this is the macroblock that the fragment belongs to */
- int macroblock;
-} Vp3Fragment;
-
-#define SB_NOT_CODED 0
-#define SB_PARTIALLY_CODED 1
-#define SB_FULLY_CODED 2
-
-#define MODE_INTER_NO_MV 0
-#define MODE_INTRA 1
-#define MODE_INTER_PLUS_MV 2
-#define MODE_INTER_LAST_MV 3
-#define MODE_INTER_PRIOR_LAST 4
-#define MODE_USING_GOLDEN 5
-#define MODE_GOLDEN_MV 6
-#define MODE_INTER_FOURMV 7
-#define CODING_MODE_COUNT 8
-
-/* special internal mode */
-#define MODE_COPY 8
-
-/* There are 6 preset schemes, plus a free-form scheme */
-static int ModeAlphabet[7][CODING_MODE_COUNT] =
-{
- /* this is the custom scheme */
- { 0, 0, 0, 0, 0, 0, 0, 0 },
-
- /* scheme 1: Last motion vector dominates */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 2 */
- { MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_NO_MV, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 3 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_NO_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 4 */
- { MODE_INTER_LAST_MV, MODE_INTER_PLUS_MV,
- MODE_INTER_NO_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 5: No motion vector dominates */
- { MODE_INTER_NO_MV, MODE_INTER_LAST_MV,
- MODE_INTER_PRIOR_LAST, MODE_INTER_PLUS_MV,
- MODE_INTRA, MODE_USING_GOLDEN,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
- /* scheme 6 */
- { MODE_INTER_NO_MV, MODE_USING_GOLDEN,
- MODE_INTER_LAST_MV, MODE_INTER_PRIOR_LAST,
- MODE_INTER_PLUS_MV, MODE_INTRA,
- MODE_GOLDEN_MV, MODE_INTER_FOURMV },
-
-};
-
-#define MIN_DEQUANT_VAL 2
-
-typedef struct Vp3DecodeContext {
- AVCodecContext *avctx;
- int width, height;
- AVFrame golden_frame;
- AVFrame last_frame;
- AVFrame current_frame;
- int keyframe;
- DSPContext dsp;
-
- int quality_index;
- int last_quality_index;
-
- int superblock_count;
- int superblock_width;
- int superblock_height;
- int y_superblock_width;
- int y_superblock_height;
- int c_superblock_width;
- int c_superblock_height;
- int u_superblock_start;
- int v_superblock_start;
- unsigned char *superblock_coding;
-
- int macroblock_count;
- int macroblock_width;
- int macroblock_height;
-
- int fragment_count;
- int fragment_width;
- int fragment_height;
-
- Vp3Fragment *all_fragments;
- int u_fragment_start;
- int v_fragment_start;
-
- /* this is a list of indices into the all_fragments array indicating
- * which of the fragments are coded */
- int *coded_fragment_list;
- int coded_fragment_list_index;
- int pixel_addresses_inited;
-
- VLC dc_vlc[16];
- VLC ac_vlc_1[16];
- VLC ac_vlc_2[16];
- VLC ac_vlc_3[16];
- VLC ac_vlc_4[16];
-
- int16_t intra_y_dequant[64];
- int16_t intra_c_dequant[64];
- int16_t inter_dequant[64];
-
- /* This table contains superblock_count * 16 entries. Each set of 16
- * numbers corresponds to the fragment indices 0..15 of the superblock.
- * An entry will be -1 to indicate that no entry corresponds to that
- * index. */
- int *superblock_fragments;
-
- /* This table contains superblock_count * 4 entries. Each set of 4
- * numbers corresponds to the macroblock indices 0..3 of the superblock.
- * An entry will be -1 to indicate that no entry corresponds to that
- * index. */
- int *superblock_macroblocks;
-
- /* This table contains macroblock_count * 6 entries. Each set of 6
- * numbers corresponds to the fragment indices 0..5 which comprise
- * the macroblock (4 Y fragments and 2 C fragments). */
- int *macroblock_fragments;
- /* This is an array that indicates how a particular macroblock
- * is coded. */
- unsigned char *macroblock_coding;
-
- int first_coded_y_fragment;
- int first_coded_c_fragment;
- int last_coded_y_fragment;
- int last_coded_c_fragment;
-
- uint8_t edge_emu_buffer[9*2048]; //FIXME dynamic alloc
- uint8_t qscale_table[2048]; //FIXME dynamic alloc (width+15)/16
-} Vp3DecodeContext;
-
-/************************************************************************
- * VP3 I/DCT
- ************************************************************************/
-
-#define IdctAdjustBeforeShift 8
-#define xC1S7 64277
-#define xC2S6 60547
-#define xC3S5 54491
-#define xC4S4 46341
-#define xC5S3 36410
-#define xC6S2 25080
-#define xC7S1 12785
-
-void vp3_idct_c(int16_t *input_data, int16_t *dequant_matrix,
- int16_t *output_data)
-{
- int32_t intermediate_data[64];
- int32_t *ip = intermediate_data;
- int16_t *op = output_data;
-
- int32_t A_, B_, C_, D_, _Ad, _Bd, _Cd, _Dd, E_, F_, G_, H_;
- int32_t _Ed, _Gd, _Add, _Bdd, _Fd, _Hd;
- int32_t t1, t2;
-
- int i, j;
-
- debug_idct("raw coefficient block:\n");
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- debug_idct(" %5d", input_data[i * 8 + j]);
- }
- debug_idct("\n");
- }
- debug_idct("\n");
-
- for (i = 0; i < 64; i++) {
- j = dezigzag_index[i];
- intermediate_data[j] = dequant_matrix[i] * input_data[i];
- }
-
- debug_idct("dequantized block:\n");
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- debug_idct(" %5d", intermediate_data[i * 8 + j]);
- }
- debug_idct("\n");
- }
- debug_idct("\n");
-
- /* Inverse DCT on the rows now */
- for (i = 0; i < 8; i++) {
- /* Check for non-zero values */
- if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
- t1 = (int32_t)(xC1S7 * ip[1]);
- t2 = (int32_t)(xC7S1 * ip[7]);
- t1 >>= 16;
- t2 >>= 16;
- A_ = t1 + t2;
-
- t1 = (int32_t)(xC7S1 * ip[1]);
- t2 = (int32_t)(xC1S7 * ip[7]);
- t1 >>= 16;
- t2 >>= 16;
- B_ = t1 - t2;
-
- t1 = (int32_t)(xC3S5 * ip[3]);
- t2 = (int32_t)(xC5S3 * ip[5]);
- t1 >>= 16;
- t2 >>= 16;
- C_ = t1 + t2;
-
- t1 = (int32_t)(xC3S5 * ip[5]);
- t2 = (int32_t)(xC5S3 * ip[3]);
- t1 >>= 16;
- t2 >>= 16;
- D_ = t1 - t2;
-
-
- t1 = (int32_t)(xC4S4 * (A_ - C_));
- t1 >>= 16;
- _Ad = t1;
-
- t1 = (int32_t)(xC4S4 * (B_ - D_));
- t1 >>= 16;
- _Bd = t1;
-
-
- _Cd = A_ + C_;
- _Dd = B_ + D_;
-
- t1 = (int32_t)(xC4S4 * (ip[0] + ip[4]));
- t1 >>= 16;
- E_ = t1;
-
- t1 = (int32_t)(xC4S4 * (ip[0] - ip[4]));
- t1 >>= 16;
- F_ = t1;
-
- t1 = (int32_t)(xC2S6 * ip[2]);
- t2 = (int32_t)(xC6S2 * ip[6]);
- t1 >>= 16;
- t2 >>= 16;
- G_ = t1 + t2;
-
- t1 = (int32_t)(xC6S2 * ip[2]);
- t2 = (int32_t)(xC2S6 * ip[6]);
- t1 >>= 16;
- t2 >>= 16;
- H_ = t1 - t2;
-
-
- _Ed = E_ - G_;
- _Gd = E_ + G_;
-
- _Add = F_ + _Ad;
- _Bdd = _Bd - H_;
-
- _Fd = F_ - _Ad;
- _Hd = _Bd + H_;
-
- /* Final sequence of operations over-write original inputs. */
- ip[0] = (int16_t)((_Gd + _Cd ) >> 0);
- ip[7] = (int16_t)((_Gd - _Cd ) >> 0);
-
- ip[1] = (int16_t)((_Add + _Hd ) >> 0);
- ip[2] = (int16_t)((_Add - _Hd ) >> 0);
-
- ip[3] = (int16_t)((_Ed + _Dd ) >> 0);
- ip[4] = (int16_t)((_Ed - _Dd ) >> 0);
-
- ip[5] = (int16_t)((_Fd + _Bdd ) >> 0);
- ip[6] = (int16_t)((_Fd - _Bdd ) >> 0);
-
- }
-
- ip += 8; /* next row */
- }
-
- ip = intermediate_data;
-
- for ( i = 0; i < 8; i++) {
- /* Check for non-zero values (bitwise or faster than ||) */
- if ( ip[0 * 8] | ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
- ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
-
- t1 = (int32_t)(xC1S7 * ip[1*8]);
- t2 = (int32_t)(xC7S1 * ip[7*8]);
- t1 >>= 16;
- t2 >>= 16;
- A_ = t1 + t2;
-
- t1 = (int32_t)(xC7S1 * ip[1*8]);
- t2 = (int32_t)(xC1S7 * ip[7*8]);
- t1 >>= 16;
- t2 >>= 16;
- B_ = t1 - t2;
-
- t1 = (int32_t)(xC3S5 * ip[3*8]);
- t2 = (int32_t)(xC5S3 * ip[5*8]);
- t1 >>= 16;
- t2 >>= 16;
- C_ = t1 + t2;
-
- t1 = (int32_t)(xC3S5 * ip[5*8]);
- t2 = (int32_t)(xC5S3 * ip[3*8]);
- t1 >>= 16;
- t2 >>= 16;
- D_ = t1 - t2;
-
-
- t1 = (int32_t)(xC4S4 * (A_ - C_));
- t1 >>= 16;
- _Ad = t1;
-
- t1 = (int32_t)(xC4S4 * (B_ - D_));
- t1 >>= 16;
- _Bd = t1;
-
-
- _Cd = A_ + C_;
- _Dd = B_ + D_;
-
- t1 = (int32_t)(xC4S4 * (ip[0*8] + ip[4*8]));
- t1 >>= 16;
- E_ = t1;
-
- t1 = (int32_t)(xC4S4 * (ip[0*8] - ip[4*8]));
- t1 >>= 16;
- F_ = t1;
-
- t1 = (int32_t)(xC2S6 * ip[2*8]);
- t2 = (int32_t)(xC6S2 * ip[6*8]);
- t1 >>= 16;
- t2 >>= 16;
- G_ = t1 + t2;
-
- t1 = (int32_t)(xC6S2 * ip[2*8]);
- t2 = (int32_t)(xC2S6 * ip[6*8]);
- t1 >>= 16;
- t2 >>= 16;
- H_ = t1 - t2;
-
-
- _Ed = E_ - G_;
- _Gd = E_ + G_;
-
- _Add = F_ + _Ad;
- _Bdd = _Bd - H_;
-
- _Fd = F_ - _Ad;
- _Hd = _Bd + H_;
-
- _Gd += IdctAdjustBeforeShift;
- _Add += IdctAdjustBeforeShift;
- _Ed += IdctAdjustBeforeShift;
- _Fd += IdctAdjustBeforeShift;
-
- /* Final sequence of operations over-write original inputs. */
- op[0*8] = (int16_t)((_Gd + _Cd ) >> 4);
- op[7*8] = (int16_t)((_Gd - _Cd ) >> 4);
-
- op[1*8] = (int16_t)((_Add + _Hd ) >> 4);
- op[2*8] = (int16_t)((_Add - _Hd ) >> 4);
-
- op[3*8] = (int16_t)((_Ed + _Dd ) >> 4);
- op[4*8] = (int16_t)((_Ed - _Dd ) >> 4);
-
- op[5*8] = (int16_t)((_Fd + _Bdd ) >> 4);
- op[6*8] = (int16_t)((_Fd - _Bdd ) >> 4);
-
- } else {
-
- op[0*8] = 0;
- op[7*8] = 0;
- op[1*8] = 0;
- op[2*8] = 0;
- op[3*8] = 0;
- op[4*8] = 0;
- op[5*8] = 0;
- op[6*8] = 0;
- }
-
- ip++; /* next column */
- op++;
- }
-}
-
-void vp3_idct_put(int16_t *input_data, int16_t *dequant_matrix,
- uint8_t *dest, int stride)
-{
- int16_t transformed_data[64];
- int16_t *op;
- int i, j;
-
- vp3_idct_c(input_data, dequant_matrix, transformed_data);
-
- /* place in final output */
- op = transformed_data;
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- if (*op < -128)
- *dest = 0;
- else if (*op > 127)
- *dest = 255;
- else
- *dest = (uint8_t)(*op + 128);
- op++;
- dest++;
- }
- dest += (stride - 8);
- }
-}
-
-void vp3_idct_add(int16_t *input_data, int16_t *dequant_matrix,
- uint8_t *dest, int stride)
-{
- int16_t transformed_data[64];
- int16_t *op;
- int i, j;
- int16_t sample;
-
- vp3_idct_c(input_data, dequant_matrix, transformed_data);
-
- /* place in final output */
- op = transformed_data;
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- sample = *dest + *op;
- if (sample < 0)
- *dest = 0;
- else if (sample > 255)
- *dest = 255;
- else
- *dest = (uint8_t)(sample & 0xFF);
- op++;
- dest++;
- }
- dest += (stride - 8);
- }
-}
-
-/************************************************************************
- * VP3 specific functions
- ************************************************************************/
-
-/*
- * This function sets up all of the various blocks mappings:
- * superblocks <-> fragments, macroblocks <-> fragments,
- * superblocks <-> macroblocks
- *
- * Returns 0 is successful; returns 1 if *anything* went wrong.
- */
-static int init_block_mapping(Vp3DecodeContext *s)
-{
- int i, j;
- signed int hilbert_walk_y[16];
- signed int hilbert_walk_c[16];
- signed int hilbert_walk_mb[4];
-
- int current_fragment = 0;
- int current_width = 0;
- int current_height = 0;
- int right_edge = 0;
- int bottom_edge = 0;
- int superblock_row_inc = 0;
- int *hilbert = NULL;
- int mapping_index = 0;
-
- int current_macroblock;
- int c_fragment;
-
- signed char travel_width[16] = {
- 1, 1, 0, -1,
- 0, 0, 1, 0,
- 1, 0, 1, 0,
- 0, -1, 0, 1
- };
-
- signed char travel_height[16] = {
- 0, 0, 1, 0,
- 1, 1, 0, -1,
- 0, 1, 0, -1,
- -1, 0, -1, 0
- };
-
- signed char travel_width_mb[4] = {
- 1, 0, 1, 0
- };
-
- signed char travel_height_mb[4] = {
- 0, 1, 0, -1
- };
-
- debug_vp3(" vp3: initialize block mapping tables\n");
-
- /* figure out hilbert pattern per these frame dimensions */
- hilbert_walk_y[0] = 1;
- hilbert_walk_y[1] = 1;
- hilbert_walk_y[2] = s->fragment_width;
- hilbert_walk_y[3] = -1;
- hilbert_walk_y[4] = s->fragment_width;
- hilbert_walk_y[5] = s->fragment_width;
- hilbert_walk_y[6] = 1;
- hilbert_walk_y[7] = -s->fragment_width;
- hilbert_walk_y[8] = 1;
- hilbert_walk_y[9] = s->fragment_width;
- hilbert_walk_y[10] = 1;
- hilbert_walk_y[11] = -s->fragment_width;
- hilbert_walk_y[12] = -s->fragment_width;
- hilbert_walk_y[13] = -1;
- hilbert_walk_y[14] = -s->fragment_width;
- hilbert_walk_y[15] = 1;
-
- hilbert_walk_c[0] = 1;
- hilbert_walk_c[1] = 1;
- hilbert_walk_c[2] = s->fragment_width / 2;
- hilbert_walk_c[3] = -1;
- hilbert_walk_c[4] = s->fragment_width / 2;
- hilbert_walk_c[5] = s->fragment_width / 2;
- hilbert_walk_c[6] = 1;
- hilbert_walk_c[7] = -s->fragment_width / 2;
- hilbert_walk_c[8] = 1;
- hilbert_walk_c[9] = s->fragment_width / 2;
- hilbert_walk_c[10] = 1;
- hilbert_walk_c[11] = -s->fragment_width / 2;
- hilbert_walk_c[12] = -s->fragment_width / 2;
- hilbert_walk_c[13] = -1;
- hilbert_walk_c[14] = -s->fragment_width / 2;
- hilbert_walk_c[15] = 1;
-
- hilbert_walk_mb[0] = 1;
- hilbert_walk_mb[1] = s->macroblock_width;
- hilbert_walk_mb[2] = 1;
- hilbert_walk_mb[3] = -s->macroblock_width;
-
- /* iterate through each superblock (all planes) and map the fragments */
- for (i = 0; i < s->superblock_count; i++) {
- debug_init(" superblock %d (u starts @ %d, v starts @ %d)\n",
- i, s->u_superblock_start, s->v_superblock_start);
-
- /* time to re-assign the limits? */
- if (i == 0) {
-
- /* start of Y superblocks */
- right_edge = s->fragment_width;
- bottom_edge = s->fragment_height;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * s->fragment_width -
- (s->y_superblock_width * 4 - s->fragment_width);
- hilbert = hilbert_walk_y;
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = -1;
-
- } else if (i == s->u_superblock_start) {
-
- /* start of U superblocks */
- right_edge = s->fragment_width / 2;
- bottom_edge = s->fragment_height / 2;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * (s->fragment_width / 2) -
- (s->c_superblock_width * 4 - s->fragment_width / 2);
- hilbert = hilbert_walk_c;
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = s->u_fragment_start - 1;
-
- } else if (i == s->v_superblock_start) {
-
- /* start of V superblocks */
- right_edge = s->fragment_width / 2;
- bottom_edge = s->fragment_height / 2;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = 3 * (s->fragment_width / 2) -
- (s->c_superblock_width * 4 - s->fragment_width / 2);
- hilbert = hilbert_walk_c;
-
- /* the first operation for this variable is to advance by 1 */
- current_fragment = s->v_fragment_start - 1;
-
- }
-
- if (current_width >= right_edge - 1) {
- /* reset width and move to next superblock row */
- current_width = -1;
- current_height += 4;
-
- /* fragment is now at the start of a new superblock row */
- current_fragment += superblock_row_inc;
- }
-
- /* iterate through all 16 fragments in a superblock */
- for (j = 0; j < 16; j++) {
- current_fragment += hilbert[j];
- current_width += travel_width[j];
- current_height += travel_height[j];
-
- /* check if the fragment is in bounds */
- if ((current_width < right_edge) &&
- (current_height < bottom_edge)) {
- s->superblock_fragments[mapping_index] = current_fragment;
- debug_init(" mapping fragment %d to superblock %d, position %d (%d/%d x %d/%d)\n",
- s->superblock_fragments[mapping_index], i, j,
- current_width, right_edge, current_height, bottom_edge);
- } else {
- s->superblock_fragments[mapping_index] = -1;
- debug_init(" superblock %d, position %d has no fragment (%d/%d x %d/%d)\n",
- i, j,
- current_width, right_edge, current_height, bottom_edge);
- }
-
- mapping_index++;
- }
- }
-
- /* initialize the superblock <-> macroblock mapping; iterate through
- * all of the Y plane superblocks to build this mapping */
- right_edge = s->macroblock_width;
- bottom_edge = s->macroblock_height;
- current_width = -1;
- current_height = 0;
- superblock_row_inc = s->macroblock_width -
- (s->y_superblock_width * 2 - s->macroblock_width);;
- hilbert = hilbert_walk_mb;
- mapping_index = 0;
- current_macroblock = -1;
- for (i = 0; i < s->u_superblock_start; i++) {
-
- if (current_width >= right_edge - 1) {
- /* reset width and move to next superblock row */
- current_width = -1;
- current_height += 2;
-
- /* macroblock is now at the start of a new superblock row */
- current_macroblock += superblock_row_inc;
- }
-
- /* iterate through each potential macroblock in the superblock */
- for (j = 0; j < 4; j++) {
- current_macroblock += hilbert_walk_mb[j];
- current_width += travel_width_mb[j];
- current_height += travel_height_mb[j];
-
- /* check if the macroblock is in bounds */
- if ((current_width < right_edge) &&
- (current_height < bottom_edge)) {
- s->superblock_macroblocks[mapping_index] = current_macroblock;
- debug_init(" mapping macroblock %d to superblock %d, position %d (%d/%d x %d/%d)\n",
- s->superblock_macroblocks[mapping_index], i, j,
- current_width, right_edge, current_height, bottom_edge);
- } else {
- s->superblock_macroblocks[mapping_index] = -1;
- debug_init(" superblock %d, position %d has no macroblock (%d/%d x %d/%d)\n",
- i, j,
- current_width, right_edge, current_height, bottom_edge);
- }
-
- mapping_index++;
- }
- }
-
- /* initialize the macroblock <-> fragment mapping */
- current_fragment = 0;
- current_macroblock = 0;
- mapping_index = 0;
- for (i = 0; i < s->fragment_height; i += 2) {
-
- for (j = 0; j < s->fragment_width; j += 2) {
-
- debug_init(" macroblock %d contains fragments: ", current_macroblock);
- s->all_fragments[current_fragment].macroblock = current_macroblock;
- s->macroblock_fragments[mapping_index++] = current_fragment;
- debug_init("%d ", current_fragment);
-
- if (j + 1 < s->fragment_width) {
- s->all_fragments[current_fragment + 1].macroblock = current_macroblock;
- s->macroblock_fragments[mapping_index++] = current_fragment + 1;
- debug_init("%d ", current_fragment + 1);
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- if (i + 1 < s->fragment_height) {
- s->all_fragments[current_fragment + s->fragment_width].macroblock =
- current_macroblock;
- s->macroblock_fragments[mapping_index++] =
- current_fragment + s->fragment_width;
- debug_init("%d ", current_fragment + s->fragment_width);
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- if ((j + 1 < s->fragment_width) && (i + 1 < s->fragment_height)) {
- s->all_fragments[current_fragment + s->fragment_width + 1].macroblock =
- current_macroblock;
- s->macroblock_fragments[mapping_index++] =
- current_fragment + s->fragment_width + 1;
- debug_init("%d ", current_fragment + s->fragment_width + 1);
- } else
- s->macroblock_fragments[mapping_index++] = -1;
-
- /* C planes */
- c_fragment = s->u_fragment_start +
- (i * s->fragment_width / 4) + (j / 2);
- s->all_fragments[c_fragment].macroblock = s->macroblock_count;
- s->macroblock_fragments[mapping_index++] = c_fragment;
- debug_init("%d ", c_fragment);
-
- c_fragment = s->v_fragment_start +
- (i * s->fragment_width / 4) + (j / 2);
- s->all_fragments[c_fragment].macroblock = s->macroblock_count;
- s->macroblock_fragments[mapping_index++] = c_fragment;
- debug_init("%d ", c_fragment);
-
- debug_init("\n");
-
- if (j + 2 <= s->fragment_width)
- current_fragment += 2;
- else
- current_fragment++;
- current_macroblock++;
- }
-
- current_fragment += s->fragment_width;
- }
-
- return 0; /* successful path out */
-}
-
-/*
- * This function unpacks a single token (which should be in the range 0..31)
- * and returns a zero run (number of zero coefficients in current DCT matrix
- * before next non-zero coefficient), the next DCT coefficient, and the
- * number of consecutive, non-EOB'd DCT blocks to EOB.
- */
-static void unpack_token(GetBitContext *gb, int token, int *zero_run,
- DCTELEM *coeff, int *eob_run)
-{
- int sign;
-
- *zero_run = 0;
- *eob_run = 0;
- *coeff = 0;
-
- debug_token(" vp3 token %d: ", token);
- switch (token) {
-
- case 0:
- debug_token("DCT_EOB_TOKEN, EOB next block\n");
- *eob_run = 1;
- break;
-
- case 1:
- debug_token("DCT_EOB_PAIR_TOKEN, EOB next 2 blocks\n");
- *eob_run = 2;
- break;
-
- case 2:
- debug_token("DCT_EOB_TRIPLE_TOKEN, EOB next 3 blocks\n");
- *eob_run = 3;
- break;
-
- case 3:
- debug_token("DCT_REPEAT_RUN_TOKEN, ");
- *eob_run = get_bits(gb, 2) + 4;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 4:
- debug_token("DCT_REPEAT_RUN2_TOKEN, ");
- *eob_run = get_bits(gb, 3) + 8;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 5:
- debug_token("DCT_REPEAT_RUN3_TOKEN, ");
- *eob_run = get_bits(gb, 4) + 16;
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 6:
- debug_token("DCT_REPEAT_RUN4_TOKEN, ");
- *eob_run = get_bits(gb, 12);
- debug_token("EOB the next %d blocks\n", *eob_run);
- break;
-
- case 7:
- debug_token("DCT_SHORT_ZRL_TOKEN, ");
- /* note that this token actually indicates that (3 extra bits) + 1 0s
- * should be output; this case specifies a run of (3 EBs) 0s and a
- * coefficient of 0. */
- *zero_run = get_bits(gb, 3);
- *coeff = 0;
- debug_token("skip the next %d positions in output matrix\n", *zero_run + 1);
- break;
-
- case 8:
- debug_token("DCT_ZRL_TOKEN, ");
- /* note that this token actually indicates that (6 extra bits) + 1 0s
- * should be output; this case specifies a run of (6 EBs) 0s and a
- * coefficient of 0. */
- *zero_run = get_bits(gb, 6);
- *coeff = 0;
- debug_token("skip the next %d positions in output matrix\n", *zero_run + 1);
- break;
-
- case 9:
- debug_token("ONE_TOKEN, output 1\n");
- *coeff = 1;
- break;
-
- case 10:
- debug_token("MINUS_ONE_TOKEN, output -1\n");
- *coeff = -1;
- break;
-
- case 11:
- debug_token("TWO_TOKEN, output 2\n");
- *coeff = 2;
- break;
-
- case 12:
- debug_token("MINUS_TWO_TOKEN, output -2\n");
- *coeff = -2;
- break;
-
- case 13:
- case 14:
- case 15:
- case 16:
- debug_token("LOW_VAL_TOKENS, ");
- if (get_bits(gb, 1))
- *coeff = -(3 + (token - 13));
- else
- *coeff = 3 + (token - 13);
- debug_token("output %d\n", *coeff);
- break;
-
- case 17:
- debug_token("DCT_VAL_CATEGORY3, ");
- sign = get_bits(gb, 1);
- *coeff = 7 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 18:
- debug_token("DCT_VAL_CATEGORY4, ");
- sign = get_bits(gb, 1);
- *coeff = 9 + get_bits(gb, 2);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 19:
- debug_token("DCT_VAL_CATEGORY5, ");
- sign = get_bits(gb, 1);
- *coeff = 13 + get_bits(gb, 3);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 20:
- debug_token("DCT_VAL_CATEGORY6, ");
- sign = get_bits(gb, 1);
- *coeff = 21 + get_bits(gb, 4);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 21:
- debug_token("DCT_VAL_CATEGORY7, ");
- sign = get_bits(gb, 1);
- *coeff = 37 + get_bits(gb, 5);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 22:
- debug_token("DCT_VAL_CATEGORY8, ");
- sign = get_bits(gb, 1);
- *coeff = 69 + get_bits(gb, 9);
- if (sign)
- *coeff = -(*coeff);
- debug_token("output %d\n", *coeff);
- break;
-
- case 23:
- case 24:
- case 25:
- case 26:
- case 27:
- debug_token("DCT_RUN_CATEGORY1, ");
- *zero_run = token - 22;
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 28:
- debug_token("DCT_RUN_CATEGORY1B, ");
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- *zero_run = 6 + get_bits(gb, 2);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 29:
- debug_token("DCT_RUN_CATEGORY1C, ");
- if (get_bits(gb, 1))
- *coeff = -1;
- else
- *coeff = 1;
- *zero_run = 10 + get_bits(gb, 3);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 30:
- debug_token("DCT_RUN_CATEGORY2, ");
- sign = get_bits(gb, 1);
- *coeff = 2 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- *zero_run = 1;
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- case 31:
- debug_token("DCT_RUN_CATEGORY2, ");
- sign = get_bits(gb, 1);
- *coeff = 2 + get_bits(gb, 1);
- if (sign)
- *coeff = -(*coeff);
- *zero_run = 2 + get_bits(gb, 1);
- debug_token("output %d 0s, then %d\n", *zero_run, *coeff);
- break;
-
- default:
- printf (" vp3: help! Got a bad token: %d > 31\n", token);
- break;
-
- }
-}
-
-/*
- * This function wipes out all of the fragment data.
- */
-static void init_frame(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i;
-
- /* zero out all of the fragment information */
- s->coded_fragment_list_index = 0;
- for (i = 0; i < s->fragment_count; i++) {
- memset(s->all_fragments[i].coeffs, 0, 64 * sizeof(DCTELEM));
- s->all_fragments[i].coeff_count = 0;
- s->all_fragments[i].last_coeff = 0;
-s->all_fragments[i].motion_x = 0xbeef;
-s->all_fragments[i].motion_y = 0xbeef;
- }
-}
-
-/*
- * This function sets of the dequantization tables used for a particular
- * frame.
- */
-static void init_dequantizer(Vp3DecodeContext *s)
-{
-
- int quality_scale = vp31_quality_threshold[s->quality_index];
- int dc_scale_factor = vp31_dc_scale_factor[s->quality_index];
- int i, j;
-
- debug_vp3(" vp3: initializing dequantization tables\n");
-
- /*
- * Scale dequantizers:
- *
- * quantizer * sf
- * --------------
- * 100
- *
- * where sf = dc_scale_factor for DC quantizer
- * or quality_scale for AC quantizer
- *
- * Then, saturate the result to a lower limit of MIN_DEQUANT_VAL.
- */
-#define SCALER 4
-
- /* scale DC quantizers */
- s->intra_y_dequant[0] = vp31_intra_y_dequant[0] * dc_scale_factor / 100;
- if (s->intra_y_dequant[0] < MIN_DEQUANT_VAL * 2)
- s->intra_y_dequant[0] = MIN_DEQUANT_VAL * 2;
- s->intra_y_dequant[0] *= SCALER;
-
- s->intra_c_dequant[0] = vp31_intra_c_dequant[0] * dc_scale_factor / 100;
- if (s->intra_c_dequant[0] < MIN_DEQUANT_VAL * 2)
- s->intra_c_dequant[0] = MIN_DEQUANT_VAL * 2;
- s->intra_c_dequant[0] *= SCALER;
-
- s->inter_dequant[0] = vp31_inter_dequant[0] * dc_scale_factor / 100;
- if (s->inter_dequant[0] < MIN_DEQUANT_VAL * 4)
- s->inter_dequant[0] = MIN_DEQUANT_VAL * 4;
- s->inter_dequant[0] *= SCALER;
-
- /* scale AC quantizers, zigzag at the same time in preparation for
- * the dequantization phase */
- for (i = 1; i < 64; i++) {
-
- j = zigzag_index[i];
-
- s->intra_y_dequant[j] = vp31_intra_y_dequant[i] * quality_scale / 100;
- if (s->intra_y_dequant[j] < MIN_DEQUANT_VAL)
- s->intra_y_dequant[j] = MIN_DEQUANT_VAL;
- s->intra_y_dequant[j] *= SCALER;
-
- s->intra_c_dequant[j] = vp31_intra_c_dequant[i] * quality_scale / 100;
- if (s->intra_c_dequant[j] < MIN_DEQUANT_VAL)
- s->intra_c_dequant[j] = MIN_DEQUANT_VAL;
- s->intra_c_dequant[j] *= SCALER;
-
- s->inter_dequant[j] = vp31_inter_dequant[i] * quality_scale / 100;
- if (s->inter_dequant[j] < MIN_DEQUANT_VAL * 2)
- s->inter_dequant[j] = MIN_DEQUANT_VAL * 2;
- s->inter_dequant[j] *= SCALER;
- }
-
- memset(s->qscale_table, (FFMAX(s->intra_y_dequant[1], s->intra_c_dequant[1])+8)/16, 512); //FIXME finetune
-
- /* print debug information as requested */
- debug_dequantizers("intra Y dequantizers:\n");
- for (i = 0; i < 8; i++) {
- for (j = i * 8; j < i * 8 + 8; j++) {
- debug_dequantizers(" %4d,", s->intra_y_dequant[j]);
- }
- debug_dequantizers("\n");
- }
- debug_dequantizers("\n");
-
- debug_dequantizers("intra C dequantizers:\n");
- for (i = 0; i < 8; i++) {
- for (j = i * 8; j < i * 8 + 8; j++) {
- debug_dequantizers(" %4d,", s->intra_c_dequant[j]);
- }
- debug_dequantizers("\n");
- }
- debug_dequantizers("\n");
-
- debug_dequantizers("interframe dequantizers:\n");
- for (i = 0; i < 8; i++) {
- for (j = i * 8; j < i * 8 + 8; j++) {
- debug_dequantizers(" %4d,", s->inter_dequant[j]);
- }
- debug_dequantizers("\n");
- }
- debug_dequantizers("\n");
-}
-
-/*
- * This function is used to fetch runs of 1s or 0s from the bitstream for
- * use in determining which superblocks are fully and partially coded.
- *
- * Codeword RunLength
- * 0 1
- * 10x 2-3
- * 110x 4-5
- * 1110xx 6-9
- * 11110xxx 10-17
- * 111110xxxx 18-33
- * 111111xxxxxxxxxxxx 34-4129
- */
-static int get_superblock_run_length(GetBitContext *gb)
-{
-
- if (get_bits(gb, 1) == 0)
- return 1;
-
- else if (get_bits(gb, 1) == 0)
- return (2 + get_bits(gb, 1));
-
- else if (get_bits(gb, 1) == 0)
- return (4 + get_bits(gb, 1));
-
- else if (get_bits(gb, 1) == 0)
- return (6 + get_bits(gb, 2));
-
- else if (get_bits(gb, 1) == 0)
- return (10 + get_bits(gb, 3));
-
- else if (get_bits(gb, 1) == 0)
- return (18 + get_bits(gb, 4));
-
- else
- return (34 + get_bits(gb, 12));
-
-}
-
-/*
- * This function is used to fetch runs of 1s or 0s from the bitstream for
- * use in determining which particular fragments are coded.
- *
- * Codeword RunLength
- * 0x 1-2
- * 10x 3-4
- * 110x 5-6
- * 1110xx 7-10
- * 11110xx 11-14
- * 11111xxxx 15-30
- */
-static int get_fragment_run_length(GetBitContext *gb)
-{
-
- if (get_bits(gb, 1) == 0)
- return (1 + get_bits(gb, 1));
-
- else if (get_bits(gb, 1) == 0)
- return (3 + get_bits(gb, 1));
-
- else if (get_bits(gb, 1) == 0)
- return (5 + get_bits(gb, 1));
-
- else if (get_bits(gb, 1) == 0)
- return (7 + get_bits(gb, 2));
-
- else if (get_bits(gb, 1) == 0)
- return (11 + get_bits(gb, 2));
-
- else
- return (15 + get_bits(gb, 4));
-
-}
-
-/*
- * This function decodes a VLC from the bitstream and returns a number
- * that ranges from 0..7. The number indicates which of the 8 coding
- * modes to use.
- *
- * VLC Number
- * 0 0
- * 10 1
- * 110 2
- * 1110 3
- * 11110 4
- * 111110 5
- * 1111110 6
- * 1111111 7
- *
- */
-static int get_mode_code(GetBitContext *gb)
-{
-
- if (get_bits(gb, 1) == 0)
- return 0;
-
- else if (get_bits(gb, 1) == 0)
- return 1;
-
- else if (get_bits(gb, 1) == 0)
- return 2;
-
- else if (get_bits(gb, 1) == 0)
- return 3;
-
- else if (get_bits(gb, 1) == 0)
- return 4;
-
- else if (get_bits(gb, 1) == 0)
- return 5;
-
- else if (get_bits(gb, 1) == 0)
- return 6;
-
- else
- return 7;
-
-}
-
-/*
- * This function extracts a motion vector from the bitstream using a VLC
- * scheme. 3 bits are fetched from the bitstream and 1 of 8 actions is
- * taken depending on the value on those 3 bits:
- *
- * 0: return 0
- * 1: return 1
- * 2: return -1
- * 3: if (next bit is 1) return -2, else return 2
- * 4: if (next bit is 1) return -3, else return 3
- * 5: return 4 + (next 2 bits), next bit is sign
- * 6: return 8 + (next 3 bits), next bit is sign
- * 7: return 16 + (next 4 bits), next bit is sign
- */
-static int get_motion_vector_vlc(GetBitContext *gb)
-{
- int bits;
-
- bits = get_bits(gb, 3);
-
- switch(bits) {
-
- case 0:
- bits = 0;
- break;
-
- case 1:
- bits = 1;
- break;
-
- case 2:
- bits = -1;
- break;
-
- case 3:
- if (get_bits(gb, 1) == 0)
- bits = 2;
- else
- bits = -2;
- break;
-
- case 4:
- if (get_bits(gb, 1) == 0)
- bits = 3;
- else
- bits = -3;
- break;
-
- case 5:
- bits = 4 + get_bits(gb, 2);
- if (get_bits(gb, 1) == 1)
- bits = -bits;
- break;
-
- case 6:
- bits = 8 + get_bits(gb, 3);
- if (get_bits(gb, 1) == 1)
- bits = -bits;
- break;
-
- case 7:
- bits = 16 + get_bits(gb, 4);
- if (get_bits(gb, 1) == 1)
- bits = -bits;
- break;
-
- }
-
- return bits;
-}
-
-/*
- * This function fetches a 5-bit number from the stream followed by
- * a sign and calls it a motion vector.
- */
-static int get_motion_vector_fixed(GetBitContext *gb)
-{
-
- int bits;
-
- bits = get_bits(gb, 5);
-
- if (get_bits(gb, 1) == 1)
- bits = -bits;
-
- return bits;
-}
-
-/*
- * This function unpacks all of the superblock/macroblock/fragment coding
- * information from the bitstream.
- */
-static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int bit = 0;
- int current_superblock = 0;
- int current_run = 0;
- int decode_fully_flags = 0;
- int decode_partial_blocks = 0;
- int first_c_fragment_seen;
-
- int i, j;
- int current_fragment;
-
- debug_vp3(" vp3: unpacking superblock coding\n");
-
- if (s->keyframe) {
-
- debug_vp3(" keyframe-- all superblocks are fully coded\n");
- memset(s->superblock_coding, SB_FULLY_CODED, s->superblock_count);
-
- } else {
-
- /* unpack the list of partially-coded superblocks */
- bit = get_bits(gb, 1);
- /* toggle the bit because as soon as the first run length is
- * fetched the bit will be toggled again */
- bit ^= 1;
- while (current_superblock < s->superblock_count) {
- if (current_run == 0) {
- bit ^= 1;
- current_run = get_superblock_run_length(gb);
- debug_block_coding(" setting superblocks %d..%d to %s\n",
- current_superblock,
- current_superblock + current_run - 1,
- (bit) ? "partially coded" : "not coded");
-
- /* if any of the superblocks are not partially coded, flag
- * a boolean to decode the list of fully-coded superblocks */
- if (bit == 0) {
- decode_fully_flags = 1;
- } else {
-
- /* make a note of the fact that there are partially coded
- * superblocks */
- decode_partial_blocks = 1;
- }
- }
- s->superblock_coding[current_superblock++] =
- (bit) ? SB_PARTIALLY_CODED : SB_NOT_CODED;
- current_run--;
- }
-
- /* unpack the list of fully coded superblocks if any of the blocks were
- * not marked as partially coded in the previous step */
- if (decode_fully_flags) {
-
- current_superblock = 0;
- current_run = 0;
- bit = get_bits(gb, 1);
- /* toggle the bit because as soon as the first run length is
- * fetched the bit will be toggled again */
- bit ^= 1;
- while (current_superblock < s->superblock_count) {
-
- /* skip any superblocks already marked as partially coded */
- if (s->superblock_coding[current_superblock] == SB_NOT_CODED) {
-
- if (current_run == 0) {
- bit ^= 1;
- current_run = get_superblock_run_length(gb);
- }
-
- debug_block_coding(" setting superblock %d to %s\n",
- current_superblock,
- (bit) ? "fully coded" : "not coded");
- s->superblock_coding[current_superblock] =
- (bit) ? SB_FULLY_CODED : SB_NOT_CODED;
- current_run--;
- }
- current_superblock++;
- }
- }
-
- /* if there were partial blocks, initialize bitstream for
- * unpacking fragment codings */
- if (decode_partial_blocks) {
-
- current_run = 0;
- bit = get_bits(gb, 1);
- /* toggle the bit because as soon as the first run length is
- * fetched the bit will be toggled again */
- bit ^= 1;
- }
- }
-
- /* figure out which fragments are coded; iterate through each
- * superblock (all planes) */
- s->coded_fragment_list_index = 0;
- s->first_coded_y_fragment = s->first_coded_c_fragment = 0;
- s->last_coded_y_fragment = s->last_coded_c_fragment = -1;
- first_c_fragment_seen = 0;
- memset(s->macroblock_coding, MODE_COPY, s->macroblock_count);
- for (i = 0; i < s->superblock_count; i++) {
-
- /* iterate through all 16 fragments in a superblock */
- for (j = 0; j < 16; j++) {
-
- /* if the fragment is in bounds, check its coding status */
- current_fragment = s->superblock_fragments[i * 16 + j];
- if (current_fragment >= s->fragment_count) {
- printf (" vp3:unpack_superblocks(): bad fragment number (%d >= %d)\n",
- current_fragment, s->fragment_count);
- return 1;
- }
- if (current_fragment != -1) {
- if (s->superblock_coding[i] == SB_NOT_CODED) {
-
- /* copy all the fragments from the prior frame */
- s->all_fragments[current_fragment].coding_method =
- MODE_COPY;
-
- } else if (s->superblock_coding[i] == SB_PARTIALLY_CODED) {
-
- /* fragment may or may not be coded; this is the case
- * that cares about the fragment coding runs */
- if (current_run == 0) {
- bit ^= 1;
- current_run = get_fragment_run_length(gb);
- }
-
- if (bit) {
- /* default mode; actual mode will be decoded in
- * the next phase */
- s->all_fragments[current_fragment].coding_method =
- MODE_INTER_NO_MV;
- s->coded_fragment_list[s->coded_fragment_list_index] =
- current_fragment;
- if ((current_fragment >= s->u_fragment_start) &&
- (s->last_coded_y_fragment == -1) &&
- (!first_c_fragment_seen)) {
- s->first_coded_c_fragment = s->coded_fragment_list_index;
- s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
- first_c_fragment_seen = 1;
- }
- s->coded_fragment_list_index++;
- s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV;
- debug_block_coding(" superblock %d is partially coded, fragment %d is coded\n",
- i, current_fragment);
- } else {
- /* not coded; copy this fragment from the prior frame */
- s->all_fragments[current_fragment].coding_method =
- MODE_COPY;
- debug_block_coding(" superblock %d is partially coded, fragment %d is not coded\n",
- i, current_fragment);
- }
-
- current_run--;
-
- } else {
-
- /* fragments are fully coded in this superblock; actual
- * coding will be determined in next step */
- s->all_fragments[current_fragment].coding_method =
- MODE_INTER_NO_MV;
- s->coded_fragment_list[s->coded_fragment_list_index] =
- current_fragment;
- if ((current_fragment >= s->u_fragment_start) &&
- (s->last_coded_y_fragment == -1) &&
- (!first_c_fragment_seen)) {
- s->first_coded_c_fragment = s->coded_fragment_list_index;
- s->last_coded_y_fragment = s->first_coded_c_fragment - 1;
- first_c_fragment_seen = 1;
- }
- s->coded_fragment_list_index++;
- s->macroblock_coding[s->all_fragments[current_fragment].macroblock] = MODE_INTER_NO_MV;
- debug_block_coding(" superblock %d is fully coded, fragment %d is coded\n",
- i, current_fragment);
- }
- }
- }
- }
-
- if (!first_c_fragment_seen)
- /* only Y fragments coded in this frame */
- s->last_coded_y_fragment = s->coded_fragment_list_index - 1;
- else
- /* end the list of coded C fragments */
- s->last_coded_c_fragment = s->coded_fragment_list_index - 1;
-
- debug_block_coding(" %d total coded fragments, y: %d -> %d, c: %d -> %d\n",
- s->coded_fragment_list_index,
- s->first_coded_y_fragment,
- s->last_coded_y_fragment,
- s->first_coded_c_fragment,
- s->last_coded_c_fragment);
-
- return 0;
-}
-
-/*
- * This function unpacks all the coding mode data for individual macroblocks
- * from the bitstream.
- */
-static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i, j, k;
- int scheme;
- int current_macroblock;
- int current_fragment;
- int coding_mode;
-
- debug_vp3(" vp3: unpacking encoding modes\n");
-
- if (s->keyframe) {
- debug_vp3(" keyframe-- all blocks are coded as INTRA\n");
-
- for (i = 0; i < s->fragment_count; i++)
- s->all_fragments[i].coding_method = MODE_INTRA;
-
- } else {
-
- /* fetch the mode coding scheme for this frame */
- scheme = get_bits(gb, 3);
- debug_modes(" using mode alphabet %d\n", scheme);
-
- /* is it a custom coding scheme? */
- if (scheme == 0) {
- debug_modes(" custom mode alphabet ahead:\n");
- for (i = 0; i < 8; i++)
- ModeAlphabet[scheme][get_bits(gb, 3)] = i;
- }
-
- for (i = 0; i < 8; i++)
- debug_modes(" mode[%d][%d] = %d\n", scheme, i,
- ModeAlphabet[scheme][i]);
-
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (i = 0; i < s->u_superblock_start; i++) {
-
- for (j = 0; j < 4; j++) {
- current_macroblock = s->superblock_macroblocks[i * 4 + j];
- if ((current_macroblock == -1) ||
- (s->macroblock_coding[current_macroblock] == MODE_COPY))
- continue;
- if (current_macroblock >= s->macroblock_count) {
- printf (" vp3:unpack_modes(): bad macroblock number (%d >= %d)\n",
- current_macroblock, s->macroblock_count);
- return 1;
- }
-
- /* mode 7 means get 3 bits for each coding mode */
- if (scheme == 7)
- coding_mode = get_bits(gb, 3);
- else
- coding_mode = ModeAlphabet[scheme][get_mode_code(gb)];
-
- s->macroblock_coding[current_macroblock] = coding_mode;
- for (k = 0; k < 6; k++) {
- current_fragment =
- s->macroblock_fragments[current_macroblock * 6 + k];
- if (current_fragment == -1)
- continue;
- if (current_fragment >= s->fragment_count) {
- printf (" vp3:unpack_modes(): bad fragment number (%d >= %d)\n",
- current_fragment, s->fragment_count);
- return 1;
- }
- if (s->all_fragments[current_fragment].coding_method !=
- MODE_COPY)
- s->all_fragments[current_fragment].coding_method =
- coding_mode;
- }
-
- debug_modes(" coding method for macroblock starting @ fragment %d = %d\n",
- s->macroblock_fragments[current_macroblock * 6], coding_mode);
- }
- }
- }
-
- return 0;
-}
-
-/*
- * This function unpacks all the motion vectors for the individual
- * macroblocks from the bitstream.
- */
-static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i, j, k;
- int coding_mode;
- int motion_x[6];
- int motion_y[6];
- int last_motion_x = 0;
- int last_motion_y = 0;
- int prior_last_motion_x = 0;
- int prior_last_motion_y = 0;
- int current_macroblock;
- int current_fragment;
-
- debug_vp3(" vp3: unpacking motion vectors\n");
- if (s->keyframe) {
-
- debug_vp3(" keyframe-- there are no motion vectors\n");
-
- } else {
-
- memset(motion_x, 0, 6 * sizeof(int));
- memset(motion_y, 0, 6 * sizeof(int));
-
- /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */
- coding_mode = get_bits(gb, 1);
- debug_vectors(" using %s scheme for unpacking motion vectors\n",
- (coding_mode == 0) ? "VLC" : "fixed-length");
-
- /* iterate through all of the macroblocks that contain 1 or more
- * coded fragments */
- for (i = 0; i < s->u_superblock_start; i++) {
-
- for (j = 0; j < 4; j++) {
- current_macroblock = s->superblock_macroblocks[i * 4 + j];
- if ((current_macroblock == -1) ||
- (s->macroblock_coding[current_macroblock] == MODE_COPY))
- continue;
- if (current_macroblock >= s->macroblock_count) {
- printf (" vp3:unpack_vectors(): bad macroblock number (%d >= %d)\n",
- current_macroblock, s->macroblock_count);
- return 1;
- }
-
- current_fragment = s->macroblock_fragments[current_macroblock * 6];
- if (current_fragment >= s->fragment_count) {
- printf (" vp3:unpack_vectors(): bad fragment number (%d >= %d\n",
- current_fragment, s->fragment_count);
- return 1;
- }
- switch (s->macroblock_coding[current_macroblock]) {
-
- case MODE_INTER_PLUS_MV:
- case MODE_GOLDEN_MV:
- /* all 6 fragments use the same motion vector */
- if (coding_mode == 0) {
- motion_x[0] = get_motion_vector_vlc(gb);
- motion_y[0] = get_motion_vector_vlc(gb);
- } else {
- motion_x[0] = get_motion_vector_fixed(gb);
- motion_y[0] = get_motion_vector_fixed(gb);
- }
- for (k = 1; k < 6; k++) {
- motion_x[k] = motion_x[0];
- motion_y[k] = motion_y[0];
- }
-
- /* vector maintenance, only on MODE_INTER_PLUS_MV */
- if (s->macroblock_coding[current_macroblock] ==
- MODE_INTER_PLUS_MV) {
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- }
- break;
-
- case MODE_INTER_FOURMV:
- /* fetch 4 vectors from the bitstream, one for each
- * Y fragment, then average for the C fragment vectors */
- motion_x[4] = motion_y[4] = 0;
- for (k = 0; k < 4; k++) {
- if (coding_mode == 0) {
- motion_x[k] = get_motion_vector_vlc(gb);
- motion_y[k] = get_motion_vector_vlc(gb);
- } else {
- motion_x[k] = get_motion_vector_fixed(gb);
- motion_y[k] = get_motion_vector_fixed(gb);
- }
- motion_x[4] += motion_x[k];
- motion_y[4] += motion_y[k];
- }
-
- if (motion_x[4] >= 0)
- motion_x[4] = (motion_x[4] + 2) / 4;
- else
- motion_x[4] = (motion_x[4] - 2) / 4;
- motion_x[5] = motion_x[4];
-
- if (motion_y[4] >= 0)
- motion_y[4] = (motion_y[4] + 2) / 4;
- else
- motion_y[4] = (motion_y[4] - 2) / 4;
- motion_y[5] = motion_y[4];
-
- /* vector maintenance; vector[3] is treated as the
- * last vector in this case */
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[3];
- last_motion_y = motion_y[3];
- break;
-
- case MODE_INTER_LAST_MV:
- /* all 6 fragments use the last motion vector */
- motion_x[0] = last_motion_x;
- motion_y[0] = last_motion_y;
- for (k = 1; k < 6; k++) {
- motion_x[k] = motion_x[0];
- motion_y[k] = motion_y[0];
- }
-
- /* no vector maintenance (last vector remains the
- * last vector) */
- break;
-
- case MODE_INTER_PRIOR_LAST:
- /* all 6 fragments use the motion vector prior to the
- * last motion vector */
- motion_x[0] = prior_last_motion_x;
- motion_y[0] = prior_last_motion_y;
- for (k = 1; k < 6; k++) {
- motion_x[k] = motion_x[0];
- motion_y[k] = motion_y[0];
- }
-
- /* vector maintenance */
- prior_last_motion_x = last_motion_x;
- prior_last_motion_y = last_motion_y;
- last_motion_x = motion_x[0];
- last_motion_y = motion_y[0];
- break;
-
- default:
- /* covers intra, inter without MV, golden without MV */
- memset(motion_x, 0, 6 * sizeof(int));
- memset(motion_y, 0, 6 * sizeof(int));
-
- /* no vector maintenance */
- break;
- }
-
- /* assign the motion vectors to the correct fragments */
- debug_vectors(" vectors for macroblock starting @ fragment %d (coding method %d):\n",
- current_fragment,
- s->macroblock_coding[current_macroblock]);
- for (k = 0; k < 6; k++) {
- current_fragment =
- s->macroblock_fragments[current_macroblock * 6 + k];
- if (current_fragment == -1)
- continue;
- if (current_fragment >= s->fragment_count) {
- printf (" vp3:unpack_vectors(): bad fragment number (%d >= %d)\n",
- current_fragment, s->fragment_count);
- return 1;
- }
- s->all_fragments[current_fragment].motion_x = motion_x[k];
- s->all_fragments[current_fragment].motion_y = motion_y[k];
- debug_vectors(" vector %d: fragment %d = (%d, %d)\n",
- k, current_fragment, motion_x[k], motion_y[k]);
- }
- }
- }
- }
-
- return 0;
-}
-
-/*
- * This function is called by unpack_dct_coeffs() to extract the VLCs from
- * the bitstream. The VLCs encode tokens which are used to unpack DCT
- * data. This function unpacks all the VLCs for either the Y plane or both
- * C planes, and is called for DC coefficients or different AC coefficient
- * levels (since different coefficient types require different VLC tables.
- *
- * This function returns a residual eob run. E.g, if a particular token gave
- * instructions to EOB the next 5 fragments and there were only 2 fragments
- * left in the current fragment range, 3 would be returned so that it could
- * be passed into the next call to this same function.
- */
-static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
- VLC *table, int coeff_index,
- int first_fragment, int last_fragment,
- int eob_run)
-{
- int i;
- int token;
- int zero_run;
- DCTELEM coeff;
- Vp3Fragment *fragment;
-
- if ((first_fragment >= s->fragment_count) ||
- (last_fragment >= s->fragment_count)) {
-
- printf (" vp3:unpack_vlcs(): bad fragment number (%d -> %d ?)\n",
- first_fragment, last_fragment);
- return 0;
- }
-
- for (i = first_fragment; i <= last_fragment; i++) {
-
- fragment = &s->all_fragments[s->coded_fragment_list[i]];
- if (fragment->coeff_count > coeff_index)
- continue;
-
- if (!eob_run) {
- /* decode a VLC into a token */
- token = get_vlc2(gb, table->table, 5, 3);
- debug_vlc(" token = %2d, ", token);
- /* use the token to get a zero run, a coefficient, and an eob run */
- unpack_token(gb, token, &zero_run, &coeff, &eob_run);
- }
-
- if (!eob_run) {
- fragment->coeff_count += zero_run;
- if (fragment->coeff_count < 64)
- fragment->coeffs[fragment->coeff_count++] = coeff;
- debug_vlc(" fragment %d coeff = %d\n",
- s->coded_fragment_list[i], fragment->coeffs[coeff_index]);
- } else {
- fragment->last_coeff = fragment->coeff_count;
- fragment->coeff_count = 64;
- debug_vlc(" fragment %d eob with %d coefficients\n",
- s->coded_fragment_list[i], fragment->last_coeff);
- eob_run--;
- }
- }
-
- return eob_run;
-}
-
-/*
- * This function unpacks all of the DCT coefficient data from the
- * bitstream.
- */
-static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
-{
- int i;
- int dc_y_table;
- int dc_c_table;
- int ac_y_table;
- int ac_c_table;
- int residual_eob_run = 0;
-
- /* fetch the DC table indices */
- dc_y_table = get_bits(gb, 4);
- dc_c_table = get_bits(gb, 4);
-
- /* unpack the Y plane DC coefficients */
- debug_vp3(" vp3: unpacking Y plane DC coefficients using table %d\n",
- dc_y_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0,
- s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
-
- /* unpack the C plane DC coefficients */
- debug_vp3(" vp3: unpacking C plane DC coefficients using table %d\n",
- dc_c_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
- s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
-
- /* fetch the AC table indices */
- ac_y_table = get_bits(gb, 4);
- ac_c_table = get_bits(gb, 4);
-
- /* unpack the group 1 AC coefficients (coeffs 1-5) */
- for (i = 1; i <= 5; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_y_table], i,
- s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_1[ac_c_table], i,
- s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
- }
-
- /* unpack the group 2 AC coefficients (coeffs 6-14) */
- for (i = 6; i <= 14; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_y_table], i,
- s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_2[ac_c_table], i,
- s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
- }
-
- /* unpack the group 3 AC coefficients (coeffs 15-27) */
- for (i = 15; i <= 27; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_y_table], i,
- s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_3[ac_c_table], i,
- s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
- }
-
- /* unpack the group 4 AC coefficients (coeffs 28-63) */
- for (i = 28; i <= 63; i++) {
-
- debug_vp3(" vp3: unpacking level %d Y plane AC coefficients using table %d\n",
- i, ac_y_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_y_table], i,
- s->first_coded_y_fragment, s->last_coded_y_fragment, residual_eob_run);
-
- debug_vp3(" vp3: unpacking level %d C plane AC coefficients using table %d\n",
- i, ac_c_table);
- residual_eob_run = unpack_vlcs(s, gb, &s->ac_vlc_4[ac_c_table], i,
- s->first_coded_c_fragment, s->last_coded_c_fragment, residual_eob_run);
- }
-
- return 0;
-}
-
-/*
- * This function reverses the DC prediction for each coded fragment in
- * the frame. Much of this function is adapted directly from the original
- * VP3 source code.
- */
-#define COMPATIBLE_FRAME(x) \
- (compatible_frame[s->all_fragments[x].coding_method] == current_frame_type)
-#define FRAME_CODED(x) (s->all_fragments[x].coding_method != MODE_COPY)
-static inline int iabs (int x) { return ((x < 0) ? -x : x); }
-
-static void reverse_dc_prediction(Vp3DecodeContext *s,
- int first_fragment,
- int fragment_width,
- int fragment_height)
-{
-
-#define PUL 8
-#define PU 4
-#define PUR 2
-#define PL 1
-
- int x, y;
- int i = first_fragment;
-
- /*
- * Fragment prediction groups:
- *
- * 32222222226
- * 10000000004
- * 10000000004
- * 10000000004
- * 10000000004
- *
- * Note: Groups 5 and 7 do not exist as it would mean that the
- * fragment's x coordinate is both 0 and (width - 1) at the same time.
- */
- int predictor_group;
- short predicted_dc;
-
- /* validity flags for the left, up-left, up, and up-right fragments */
- int fl, ful, fu, fur;
-
- /* DC values for the left, up-left, up, and up-right fragments */
- int vl, vul, vu, vur;
-
- /* indices for the left, up-left, up, and up-right fragments */
- int l, ul, u, ur;
-
- /*
- * The 6 fields mean:
- * 0: up-left multiplier
- * 1: up multiplier
- * 2: up-right multiplier
- * 3: left multiplier
- * 4: mask
- * 5: right bit shift divisor (e.g., 7 means >>=7, a.k.a. div by 128)
- */
- int predictor_transform[16][6] = {
- { 0, 0, 0, 0, 0, 0 },
- { 0, 0, 0, 1, 0, 0 }, // PL
- { 0, 0, 1, 0, 0, 0 }, // PUR
- { 0, 0, 53, 75, 127, 7 }, // PUR|PL
- { 0, 1, 0, 0, 0, 0 }, // PU
- { 0, 1, 0, 1, 1, 1 }, // PU|PL
- { 0, 1, 0, 0, 0, 0 }, // PU|PUR
- { 0, 0, 53, 75, 127, 7 }, // PU|PUR|PL
- { 1, 0, 0, 0, 0, 0 }, // PUL
- { 0, 0, 0, 1, 0, 0 }, // PUL|PL
- { 1, 0, 1, 0, 1, 1 }, // PUL|PUR
- { 0, 0, 53, 75, 127, 7 }, // PUL|PUR|PL
- { 0, 1, 0, 0, 0, 0 }, // PUL|PU
- {-26, 29, 0, 29, 31, 5 }, // PUL|PU|PL
- { 3, 10, 3, 0, 15, 4 }, // PUL|PU|PUR
- {-26, 29, 0, 29, 31, 5 } // PUL|PU|PUR|PL
- };
-
- /* This table shows which types of blocks can use other blocks for
- * prediction. For example, INTRA is the only mode in this table to
- * have a frame number of 0. That means INTRA blocks can only predict
- * from other INTRA blocks. There are 2 golden frame coding types;
- * blocks encoding in these modes can only predict from other blocks
- * that were encoded with these 1 of these 2 modes. */
- unsigned char compatible_frame[8] = {
- 1, /* MODE_INTER_NO_MV */
- 0, /* MODE_INTRA */
- 1, /* MODE_INTER_PLUS_MV */
- 1, /* MODE_INTER_LAST_MV */
- 1, /* MODE_INTER_PRIOR_MV */
- 2, /* MODE_USING_GOLDEN */
- 2, /* MODE_GOLDEN_MV */
- 1 /* MODE_INTER_FOUR_MV */
- };
- int current_frame_type;
-
- /* there is a last DC predictor for each of the 3 frame types */
- short last_dc[3];
-
- int transform = 0;
-
- debug_vp3(" vp3: reversing DC prediction\n");
-
- vul = vu = vur = vl = 0;
- last_dc[0] = last_dc[1] = last_dc[2] = 0;
-
- /* for each fragment row... */
- for (y = 0; y < fragment_height; y++) {
-
- /* for each fragment in a row... */
- for (x = 0; x < fragment_width; x++, i++) {
-
- /* reverse prediction if this block was coded */
- if (s->all_fragments[i].coding_method != MODE_COPY) {
-
- current_frame_type =
- compatible_frame[s->all_fragments[i].coding_method];
- predictor_group = (x == 0) + ((y == 0) << 1) +
- ((x + 1 == fragment_width) << 2);
- debug_dc_pred(" frag %d: group %d, orig DC = %d, ",
- i, predictor_group, s->all_fragments[i].coeffs[0]);
-
- switch (predictor_group) {
-
- case 0:
- /* main body of fragments; consider all 4 possible
- * fragments for prediction */
-
- /* calculate the indices of the predicting fragments */
- ul = i - fragment_width - 1;
- u = i - fragment_width;
- ur = i - fragment_width + 1;
- l = i - 1;
-
- /* fetch the DC values for the predicting fragments */
- vul = s->all_fragments[ul].coeffs[0];
- vu = s->all_fragments[u].coeffs[0];
- vur = s->all_fragments[ur].coeffs[0];
- vl = s->all_fragments[l].coeffs[0];
-
- /* figure out which fragments are valid */
- ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul);
- fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);
- fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur);
- fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);
-
- /* decide which predictor transform to use */
- transform = (fl*PL) | (fu*PU) | (ful*PUL) | (fur*PUR);
-
- break;
-
- case 1:
- /* left column of fragments, not including top corner;
- * only consider up and up-right fragments */
-
- /* calculate the indices of the predicting fragments */
- u = i - fragment_width;
- ur = i - fragment_width + 1;
-
- /* fetch the DC values for the predicting fragments */
- vu = s->all_fragments[u].coeffs[0];
- vur = s->all_fragments[ur].coeffs[0];
-
- /* figure out which fragments are valid */
- fur = FRAME_CODED(ur) && COMPATIBLE_FRAME(ur);
- fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);
-
- /* decide which predictor transform to use */
- transform = (fu*PU) | (fur*PUR);
-
- break;
-
- case 2:
- case 6:
- /* top row of fragments, not including top-left frag;
- * only consider the left fragment for prediction */
-
- /* calculate the indices of the predicting fragments */
- l = i - 1;
-
- /* fetch the DC values for the predicting fragments */
- vl = s->all_fragments[l].coeffs[0];
-
- /* figure out which fragments are valid */
- fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);
-
- /* decide which predictor transform to use */
- transform = (fl*PL);
-
- break;
-
- case 3:
- /* top-left fragment */
-
- /* nothing to predict from in this case */
- transform = 0;
-
- break;
-
- case 4:
- /* right column of fragments, not including top corner;
- * consider up-left, up, and left fragments for
- * prediction */
-
- /* calculate the indices of the predicting fragments */
- ul = i - fragment_width - 1;
- u = i - fragment_width;
- l = i - 1;
-
- /* fetch the DC values for the predicting fragments */
- vul = s->all_fragments[ul].coeffs[0];
- vu = s->all_fragments[u].coeffs[0];
- vl = s->all_fragments[l].coeffs[0];
-
- /* figure out which fragments are valid */
- ful = FRAME_CODED(ul) && COMPATIBLE_FRAME(ul);
- fu = FRAME_CODED(u) && COMPATIBLE_FRAME(u);
- fl = FRAME_CODED(l) && COMPATIBLE_FRAME(l);
-
- /* decide which predictor transform to use */
- transform = (fl*PL) | (fu*PU) | (ful*PUL);
-
- break;
-
- }
-
- debug_dc_pred("transform = %d, ", transform);
-
- if (transform == 0) {
-
- /* if there were no fragments to predict from, use last
- * DC saved */
- s->all_fragments[i].coeffs[0] += last_dc[current_frame_type];
- debug_dc_pred("from last DC (%d) = %d\n",
- current_frame_type, s->all_fragments[i].coeffs[0]);
-
- } else {
-
- /* apply the appropriate predictor transform */
- predicted_dc =
- (predictor_transform[transform][0] * vul) +
- (predictor_transform[transform][1] * vu) +
- (predictor_transform[transform][2] * vur) +
- (predictor_transform[transform][3] * vl);
-
- /* if there is a shift value in the transform, add
- * the sign bit before the shift */
- if (predictor_transform[transform][5] != 0) {
- predicted_dc += ((predicted_dc >> 15) &
- predictor_transform[transform][4]);
- predicted_dc >>= predictor_transform[transform][5];
- }
-
- /* check for outranging on the [ul u l] and
- * [ul u ur l] predictors */
- if ((transform == 13) || (transform == 15)) {
- if (iabs(predicted_dc - vu) > 128)
- predicted_dc = vu;
- else if (iabs(predicted_dc - vl) > 128)
- predicted_dc = vl;
- else if (iabs(predicted_dc - vul) > 128)
- predicted_dc = vul;
- }
-
- /* at long last, apply the predictor */
- s->all_fragments[i].coeffs[0] += predicted_dc;
- debug_dc_pred("from pred DC = %d\n",
- s->all_fragments[i].coeffs[0]);
- }
-
- /* save the DC */
- last_dc[current_frame_type] = s->all_fragments[i].coeffs[0];
- }
- }
- }
-}
-
-/*
- * This function performs the final rendering of each fragment's data
- * onto the output frame.
- */
-static void render_fragments(Vp3DecodeContext *s,
- int first_fragment,
- int width,
- int height,
- int plane /* 0 = Y, 1 = U, 2 = V */)
-{
- int x, y;
- int m, n;
- int i = first_fragment;
- int16_t *dequantizer;
- unsigned char *output_plane;
- unsigned char *last_plane;
- unsigned char *golden_plane;
- int stride;
- int motion_x, motion_y;
- int upper_motion_limit, lower_motion_limit;
- int motion_halfpel_index;
- uint8_t *motion_source;
-
- debug_vp3(" vp3: rendering final fragments for %s\n",
- (plane == 0) ? "Y plane" : (plane == 1) ? "U plane" : "V plane");
-
- /* set up plane-specific parameters */
- if (plane == 0) {
- dequantizer = s->intra_y_dequant;
- output_plane = s->current_frame.data[0];
- last_plane = s->last_frame.data[0];
- golden_plane = s->golden_frame.data[0];
- stride = -s->current_frame.linesize[0];
- upper_motion_limit = 7 * s->current_frame.linesize[0];
- lower_motion_limit = height * s->current_frame.linesize[0] + width - 8;
- } else if (plane == 1) {
- dequantizer = s->intra_c_dequant;
- output_plane = s->current_frame.data[1];
- last_plane = s->last_frame.data[1];
- golden_plane = s->golden_frame.data[1];
- stride = -s->current_frame.linesize[1];
- upper_motion_limit = 7 * s->current_frame.linesize[1];
- lower_motion_limit = height * s->current_frame.linesize[1] + width - 8;
- } else {
- dequantizer = s->intra_c_dequant;
- output_plane = s->current_frame.data[2];
- last_plane = s->last_frame.data[2];
- golden_plane = s->golden_frame.data[2];
- stride = -s->current_frame.linesize[2];
- upper_motion_limit = 7 * s->current_frame.linesize[2];
- lower_motion_limit = height * s->current_frame.linesize[2] + width - 8;
- }
-
- /* for each fragment row... */
- for (y = 0; y < height; y += 8) {
-
- /* for each fragment in a row... */
- for (x = 0; x < width; x += 8, i++) {
-
- if ((i < 0) || (i >= s->fragment_count)) {
- printf (" vp3:render_fragments(): bad fragment number (%d)\n", i);
- return;
- }
-
- /* transform if this block was coded */
- if (s->all_fragments[i].coding_method != MODE_COPY) {
-
- if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) ||
- (s->all_fragments[i].coding_method == MODE_GOLDEN_MV))
- motion_source= golden_plane;
- else
- motion_source= last_plane;
-
- motion_source += s->all_fragments[i].first_pixel;
- motion_halfpel_index = 0;
-
- /* sort out the motion vector if this fragment is coded
- * using a motion vector method */
- if ((s->all_fragments[i].coding_method > MODE_INTRA) &&
- (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) {
- int src_x, src_y;
- motion_x = s->all_fragments[i].motion_x;
- motion_y = s->all_fragments[i].motion_y;
- if(plane){
- motion_x= (motion_x>>1) | (motion_x&1);
- motion_y= (motion_y>>1) | (motion_y&1);
- }
-
- src_x= (motion_x>>1) + x;
- src_y= (motion_y>>1) + y;
-if ((motion_x == 0xbeef) || (motion_y == 0xbeef))
-printf (" help! got beefy vector! (%X, %X)\n", motion_x, motion_y);
-
- motion_halfpel_index = motion_x & 0x01;
- motion_source += (motion_x >> 1);
-
-// motion_y = -motion_y;
- motion_halfpel_index |= (motion_y & 0x01) << 1;
- motion_source += ((motion_y >> 1) * stride);
-
- if(src_x<0 || src_y<0 || src_x + 9 >= width || src_y + 9 >= height){
- uint8_t *temp= s->edge_emu_buffer;
- if(stride<0) temp -= 9*stride;
-
- ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, width, height);
- motion_source= temp;
- }
- }
-
- /* first, take care of copying a block from either the
- * previous or the golden frame */
- if (s->all_fragments[i].coding_method != MODE_INTRA) {
-
- s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index](
- output_plane + s->all_fragments[i].first_pixel,
- motion_source,
- stride, 8);
- }
-
- /* dequantize the DCT coefficients */
- debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n",
- i, s->all_fragments[i].coding_method,
- s->all_fragments[i].coeffs[0], dequantizer[0]);
-
- /* invert DCT and place (or add) in final output */
- if (s->all_fragments[i].coding_method == MODE_INTRA) {
- vp3_idct_put(s->all_fragments[i].coeffs, dequantizer,
- output_plane + s->all_fragments[i].first_pixel,
- stride);
- } else {
- vp3_idct_add(s->all_fragments[i].coeffs, dequantizer,
- output_plane + s->all_fragments[i].first_pixel,
- stride);
- }
-
- debug_idct("block after idct_%s():\n",
- (s->all_fragments[i].coding_method == MODE_INTRA)?
- "put" : "add");
- for (m = 0; m < 8; m++) {
- for (n = 0; n < 8; n++) {
- debug_idct(" %3d", *(output_plane +
- s->all_fragments[i].first_pixel + (m * stride + n)));
- }
- debug_idct("\n");
- }
- debug_idct("\n");
-
- } else {
-
- /* copy directly from the previous frame */
- s->dsp.put_pixels_tab[1][0](
- output_plane + s->all_fragments[i].first_pixel,
- last_plane + s->all_fragments[i].first_pixel,
- stride, 8);
-
- }
- }
- }
-
- emms_c();
-
-}
-
-/*
- * This function computes the first pixel addresses for each fragment.
- * This function needs to be invoked after the first frame is allocated
- * so that it has access to the plane strides.
- */
-static void vp3_calculate_pixel_addresses(Vp3DecodeContext *s)
-{
-
- int i, x, y;
-
- /* figure out the first pixel addresses for each of the fragments */
- /* Y plane */
- i = 0;
- for (y = s->fragment_height; y > 0; y--) {
- for (x = 0; x < s->fragment_width; x++) {
- s->all_fragments[i++].first_pixel =
- s->golden_frame.linesize[0] * y * FRAGMENT_PIXELS -
- s->golden_frame.linesize[0] +
- x * FRAGMENT_PIXELS;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* U plane */
- i = s->u_fragment_start;
- for (y = s->fragment_height / 2; y > 0; y--) {
- for (x = 0; x < s->fragment_width / 2; x++) {
- s->all_fragments[i++].first_pixel =
- s->golden_frame.linesize[1] * y * FRAGMENT_PIXELS -
- s->golden_frame.linesize[1] +
- x * FRAGMENT_PIXELS;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-
- /* V plane */
- i = s->v_fragment_start;
- for (y = s->fragment_height / 2; y > 0; y--) {
- for (x = 0; x < s->fragment_width / 2; x++) {
- s->all_fragments[i++].first_pixel =
- s->golden_frame.linesize[2] * y * FRAGMENT_PIXELS -
- s->golden_frame.linesize[2] +
- x * FRAGMENT_PIXELS;
- debug_init(" fragment %d, first pixel @ %d\n",
- i-1, s->all_fragments[i-1].first_pixel);
- }
- }
-}
-
-/*
- * This is the ffmpeg/libavcodec API init function.
- */
-static int vp3_decode_init(AVCodecContext *avctx)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- int i;
- int c_width;
- int c_height;
- int y_superblock_count;
- int c_superblock_count;
-
- s->avctx = avctx;
-#if 0
- s->width = avctx->width;
- s->height = avctx->height;
-#else
- s->width = (avctx->width + 15) & 0xFFFFFFF0;
- s->height = (avctx->height + 15) & 0xFFFFFFF0;
-#endif
- avctx->pix_fmt = PIX_FMT_YUV420P;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- /* initialize to an impossible value which will force a recalculation
- * in the first frame decode */
- s->quality_index = -1;
-
- s->y_superblock_width = (s->width + 31) / 32;
- s->y_superblock_height = (s->height + 31) / 32;
- y_superblock_count = s->y_superblock_width * s->y_superblock_height;
-
- /* work out the dimensions for the C planes */
- c_width = s->width / 2;
- c_height = s->height / 2;
- s->c_superblock_width = (c_width + 31) / 32;
- s->c_superblock_height = (c_height + 31) / 32;
- c_superblock_count = s->c_superblock_width * s->c_superblock_height;
-
- s->superblock_count = y_superblock_count + (c_superblock_count * 2);
- s->u_superblock_start = y_superblock_count;
- s->v_superblock_start = s->u_superblock_start + c_superblock_count;
- s->superblock_coding = av_malloc(s->superblock_count);
-
- s->macroblock_width = (s->width + 15) / 16;
- s->macroblock_height = (s->height + 15) / 16;
- s->macroblock_count = s->macroblock_width * s->macroblock_height;
-
- s->fragment_width = s->width / FRAGMENT_PIXELS;
- s->fragment_height = s->height / FRAGMENT_PIXELS;
-
- /* fragment count covers all 8x8 blocks for all 3 planes */
- s->fragment_count = s->fragment_width * s->fragment_height * 3 / 2;
- s->u_fragment_start = s->fragment_width * s->fragment_height;
- s->v_fragment_start = s->fragment_width * s->fragment_height * 5 / 4;
-
- debug_init(" Y plane: %d x %d\n", s->width, s->height);
- debug_init(" C plane: %d x %d\n", c_width, c_height);
- debug_init(" Y superblocks: %d x %d, %d total\n",
- s->y_superblock_width, s->y_superblock_height, y_superblock_count);
- debug_init(" C superblocks: %d x %d, %d total\n",
- s->c_superblock_width, s->c_superblock_height, c_superblock_count);
- debug_init(" total superblocks = %d, U starts @ %d, V starts @ %d\n",
- s->superblock_count, s->u_superblock_start, s->v_superblock_start);
- debug_init(" macroblocks: %d x %d, %d total\n",
- s->macroblock_width, s->macroblock_height, s->macroblock_count);
- debug_init(" %d fragments, %d x %d, u starts @ %d, v starts @ %d\n",
- s->fragment_count,
- s->fragment_width,
- s->fragment_height,
- s->u_fragment_start,
- s->v_fragment_start);
-
- s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment));
- s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int));
- s->pixel_addresses_inited = 0;
-
- /* init VLC tables */
- for (i = 0; i < 16; i++) {
-
- /* DC histograms */
- init_vlc(&s->dc_vlc[i], 5, 32,
- &dc_bias[i][0][1], 4, 2,
- &dc_bias[i][0][0], 4, 2);
-
- /* group 1 AC histograms */
- init_vlc(&s->ac_vlc_1[i], 5, 32,
- &ac_bias_0[i][0][1], 4, 2,
- &ac_bias_0[i][0][0], 4, 2);
-
- /* group 2 AC histograms */
- init_vlc(&s->ac_vlc_2[i], 5, 32,
- &ac_bias_1[i][0][1], 4, 2,
- &ac_bias_1[i][0][0], 4, 2);
-
- /* group 3 AC histograms */
- init_vlc(&s->ac_vlc_3[i], 5, 32,
- &ac_bias_2[i][0][1], 4, 2,
- &ac_bias_2[i][0][0], 4, 2);
-
- /* group 4 AC histograms */
- init_vlc(&s->ac_vlc_4[i], 5, 32,
- &ac_bias_3[i][0][1], 4, 2,
- &ac_bias_3[i][0][0], 4, 2);
- }
-
- /* build quantization zigzag table */
- for (i = 0; i < 64; i++)
- zigzag_index[dezigzag_index[i]] = i;
-
- /* work out the block mapping tables */
- s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int));
- s->superblock_macroblocks = av_malloc(s->superblock_count * 4 * sizeof(int));
- s->macroblock_fragments = av_malloc(s->macroblock_count * 6 * sizeof(int));
- s->macroblock_coding = av_malloc(s->macroblock_count + 1);
- init_block_mapping(s);
-
- for (i = 0; i < 3; i++) {
- s->current_frame.data[i] = NULL;
- s->last_frame.data[i] = NULL;
- s->golden_frame.data[i] = NULL;
- }
-
- return 0;
-}
-
-/*
- * This is the ffmpeg/libavcodec API frame decode function.
- */
-static int vp3_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- Vp3DecodeContext *s = avctx->priv_data;
- GetBitContext gb;
- static int counter = 0;
-
- *data_size = 0;
-
- init_get_bits(&gb, buf, buf_size * 8);
-
- s->keyframe = get_bits(&gb, 1);
- s->keyframe ^= 1;
- skip_bits(&gb, 1);
- s->last_quality_index = s->quality_index;
- s->quality_index = get_bits(&gb, 6);
-
- debug_vp3(" VP3 frame #%d: Q index = %d", counter, s->quality_index);
- counter++;
-
- if (s->quality_index != s->last_quality_index)
- init_dequantizer(s);
-
- if (s->keyframe) {
-
- debug_vp3(", keyframe\n");
- /* skip the other 2 header bytes for now */
- skip_bits(&gb, 16);
- if (s->last_frame.data[0] == s->golden_frame.data[0]) {
- if (s->golden_frame.data[0])
- avctx->release_buffer(avctx, &s->golden_frame);
- s->last_frame= s->golden_frame; /* ensure that we catch any access to this released frame */
- } else {
- if (s->golden_frame.data[0])
- avctx->release_buffer(avctx, &s->golden_frame);
- if (s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->last_frame);
- }
-
- s->golden_frame.reference = 3;
- if(avctx->get_buffer(avctx, &s->golden_frame) < 0) {
- printf("vp3: get_buffer() failed\n");
- return -1;
- }
-
- /* golden frame is also the current frame */
- memcpy(&s->current_frame, &s->golden_frame, sizeof(AVFrame));
-
- /* time to figure out pixel addresses? */
- if (!s->pixel_addresses_inited)
- vp3_calculate_pixel_addresses(s);
-
- } else {
-
- debug_vp3("\n");
-
- /* allocate a new current frame */
- s->current_frame.reference = 3;
- if(avctx->get_buffer(avctx, &s->current_frame) < 0) {
- printf("vp3: get_buffer() failed\n");
- return -1;
- }
- }
-
- s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame
- s->current_frame.qstride= 0;
-
- init_frame(s, &gb);
-
-#if KEYFRAMES_ONLY
-if (!s->keyframe) {
-
- memcpy(s->current_frame.data[0], s->golden_frame.data[0],
- s->current_frame.linesize[0] * s->height);
- memcpy(s->current_frame.data[1], s->golden_frame.data[1],
- s->current_frame.linesize[1] * s->height / 2);
- memcpy(s->current_frame.data[2], s->golden_frame.data[2],
- s->current_frame.linesize[2] * s->height / 2);
-
-} else {
-#endif
-
- if (unpack_superblocks(s, &gb) ||
- unpack_modes(s, &gb) ||
- unpack_vectors(s, &gb) ||
- unpack_dct_coeffs(s, &gb)) {
-
- printf(" vp3: could not decode frame\n");
- return -1;
- }
-
- reverse_dc_prediction(s, 0, s->fragment_width, s->fragment_height);
- render_fragments(s, 0, s->width, s->height, 0);
-
- if ((avctx->flags & CODEC_FLAG_GRAY) == 0) {
- reverse_dc_prediction(s, s->u_fragment_start,
- s->fragment_width / 2, s->fragment_height / 2);
- reverse_dc_prediction(s, s->v_fragment_start,
- s->fragment_width / 2, s->fragment_height / 2);
- render_fragments(s, s->u_fragment_start, s->width / 2, s->height / 2, 1);
- render_fragments(s, s->v_fragment_start, s->width / 2, s->height / 2, 2);
- } else {
- memset(s->current_frame.data[1], 0x80, s->width * s->height / 4);
- memset(s->current_frame.data[2], 0x80, s->width * s->height / 4);
- }
-
-#if KEYFRAMES_ONLY
-}
-#endif
-
- *data_size=sizeof(AVFrame);
- *(AVFrame*)data= s->current_frame;
-
- /* release the last frame, if it is allocated and if it is not the
- * golden frame */
- if ((s->last_frame.data[0]) &&
- (s->last_frame.data[0] != s->golden_frame.data[0]))
- avctx->release_buffer(avctx, &s->last_frame);
-
- /* shuffle frames (last = current) */
- memcpy(&s->last_frame, &s->current_frame, sizeof(AVFrame));
- s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */
-
- return buf_size;
-}
-
-/*
- * This is the ffmpeg/libavcodec API module cleanup function.
- */
-static int vp3_decode_end(AVCodecContext *avctx)
-{
- Vp3DecodeContext *s = avctx->priv_data;
-
- av_free(s->all_fragments);
- av_free(s->coded_fragment_list);
- av_free(s->superblock_fragments);
- av_free(s->superblock_macroblocks);
- av_free(s->macroblock_fragments);
- av_free(s->macroblock_coding);
-
- /* release all frames */
- if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->golden_frame);
- if (s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->last_frame);
- /* no need to release the current_frame since it will always be pointing
- * to the same frame as either the golden or last frame */
-
- return 0;
-}
-
-AVCodec vp3_decoder = {
- "vp3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_VP3,
- sizeof(Vp3DecodeContext),
- vp3_decode_init,
- NULL,
- vp3_decode_end,
- vp3_decode_frame,
- 0,
- NULL
-};
+++ /dev/null
-#ifndef VP3DATA_H
-#define VP3DATA_H
-
-/* these coefficients dequantize intraframe Y plane coefficients */
-static int16_t vp31_intra_y_dequant[64] =
-{ 16, 11, 10, 16, 24, 40, 51, 61,
- 12, 12, 14, 19, 26, 58, 60, 55,
- 14, 13, 16, 24, 40, 57, 69, 56,
- 14, 17, 22, 29, 51, 87, 80, 62,
- 18, 22, 37, 58, 68, 109, 103, 77,
- 24, 35, 55, 64, 81, 104, 113, 92,
- 49, 64, 78, 87, 103, 121, 120, 101,
- 72, 92, 95, 98, 112, 100, 103, 99
-};
-
-/* these coefficients dequantize intraframe C plane coefficients */
-static int16_t vp31_intra_c_dequant[64] =
-{ 17, 18, 24, 47, 99, 99, 99, 99,
- 18, 21, 26, 66, 99, 99, 99, 99,
- 24, 26, 56, 99, 99, 99, 99, 99,
- 47, 66, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99,
- 99, 99, 99, 99, 99, 99, 99, 99
-};
-
-/* these coefficients dequantize interframe coefficients (all planes) */
-static int16_t vp31_inter_dequant[64] =
-{ 16, 16, 16, 20, 24, 28, 32, 40,
- 16, 16, 20, 24, 28, 32, 40, 48,
- 16, 20, 24, 28, 32, 40, 48, 64,
- 20, 24, 28, 32, 40, 48, 64, 64,
- 24, 28, 32, 40, 48, 64, 64, 64,
- 28, 32, 40, 48, 64, 64, 64, 96,
- 32, 40, 48, 64, 64, 64, 96, 128,
- 40, 48, 64, 64, 64, 96, 128, 128
-};
-
-static int16_t vp31_dc_scale_factor[64] =
-{ 220, 200, 190, 180, 170, 170, 160, 160,
- 150, 150, 140, 140, 130, 130, 120, 120,
- 110, 110, 100, 100, 90, 90, 90, 80,
- 80, 80, 70, 70, 70, 60, 60, 60,
- 60, 50, 50, 50, 50, 40, 40, 40,
- 40, 40, 30, 30, 30, 30, 30, 30,
- 30, 20, 20, 20, 20, 20, 20, 20,
- 20, 10, 10, 10, 10, 10, 10, 10
-};
-
-static uint32_t vp31_quality_threshold[64] =
-{ 500, 450, 400, 370, 340, 310, 285, 265,
- 245, 225, 210, 195, 185, 180, 170, 160,
- 150, 145, 135, 130, 125, 115, 110, 107,
- 100, 96, 93, 89, 85, 82, 75, 74,
- 70, 68, 64, 60, 57, 56, 52, 50,
- 49, 45, 44, 43, 40, 38, 37, 35,
- 33, 32, 30, 29, 28, 25, 24, 22,
- 21, 19, 18, 17, 15, 13, 12, 10
-};
-
-/* table used to convert natural order <-> zigzag order */
-static const int dezigzag_index[64] =
-{ 0, 1, 8, 16, 9, 2, 3, 10,
- 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34,
- 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36,
- 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46,
- 53, 60, 61, 54, 47, 55, 62, 63
-};
-
-/* inverse of dezigzag index */
-static int zigzag_index[64];
-
-static const uint16_t dc_bias[16][32][2] = {
- { /* DC bias table 0 */
- { 0x2D, 6 },
- { 0x26, 7 },
- { 0x166, 9 },
- { 0x4E, 8 },
- { 0x2CE, 10 },
- { 0x59E, 11 },
- { 0x27D, 11 },
- { 0x8, 5 },
- { 0x4F9, 12 },
- { 0xF, 4 },
- { 0xE, 4 },
- { 0x1B, 5 },
- { 0x6, 4 },
- { 0x8, 4 },
- { 0x5, 4 },
- { 0x1A, 5 },
- { 0x15, 5 },
- { 0x7, 4 },
- { 0xC, 4 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0x9, 4 },
- { 0x17, 5 },
- { 0x29, 6 },
- { 0x28, 6 },
- { 0xB2, 8 },
- { 0x4F8, 12 },
- { 0x59F, 11 },
- { 0x9E, 9 },
- { 0x13F, 10 },
- { 0x12, 6 },
- { 0x58, 7 }
- },
- { /* DC bias table 1 */
- { 0x10, 5 },
- { 0x47, 7 },
- { 0x1FF, 9 },
- { 0x8C, 8 },
- { 0x3FC, 10 },
- { 0x46A, 11 },
- { 0x469, 11 },
- { 0x22, 6 },
- { 0x11A1, 13 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0x4, 4 },
- { 0x5, 4 },
- { 0x9, 4 },
- { 0x6, 4 },
- { 0x1E, 5 },
- { 0x16, 5 },
- { 0x7, 4 },
- { 0xC, 4 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xA, 4 },
- { 0x17, 5 },
- { 0x7D, 7 },
- { 0x7E, 7 },
- { 0x11B, 9 },
- { 0x8D1, 12 },
- { 0x3FD, 10 },
- { 0x46B, 11 },
- { 0x11A0, 13 },
- { 0x7C, 7 },
- { 0xFE, 8 }
- },
- { /* DC bias table 2 */
- { 0x16, 5 },
- { 0x20, 6 },
- { 0x86, 8 },
- { 0x87, 8 },
- { 0x367, 10 },
- { 0x6CC, 11 },
- { 0x6CB, 11 },
- { 0x6E, 7 },
- { 0x366D, 14 },
- { 0xF, 4 },
- { 0xE, 4 },
- { 0x4, 4 },
- { 0x5, 4 },
- { 0xA, 4 },
- { 0x6, 4 },
- { 0x1A, 5 },
- { 0x11, 5 },
- { 0x7, 4 },
- { 0xC, 4 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0x9, 4 },
- { 0x17, 5 },
- { 0x6F, 7 },
- { 0x6D, 7 },
- { 0x364, 10 },
- { 0xD9A, 12 },
- { 0x6CA, 11 },
- { 0x1B37, 13 },
- { 0x366C, 14 },
- { 0x42, 7 },
- { 0xD8, 8 }
- },
- { /* DC bias table 3 */
- { 0x0, 4 },
- { 0x2D, 6 },
- { 0xF7, 8 },
- { 0x58, 7 },
- { 0x167, 9 },
- { 0x2CB, 10 },
- { 0x2CA, 10 },
- { 0xE, 6 },
- { 0x1661, 13 },
- { 0x3, 3 },
- { 0x2, 3 },
- { 0x8, 4 },
- { 0x9, 4 },
- { 0xD, 4 },
- { 0x2, 4 },
- { 0x1F, 5 },
- { 0x17, 5 },
- { 0x1, 4 },
- { 0xC, 4 },
- { 0xE, 4 },
- { 0xA, 4 },
- { 0x6, 5 },
- { 0x78, 7 },
- { 0xF, 6 },
- { 0x7A, 7 },
- { 0x164, 9 },
- { 0x599, 11 },
- { 0x2CD, 10 },
- { 0xB31, 12 },
- { 0x1660, 13 },
- { 0x79, 7 },
- { 0xF6, 8 }
- },
- { /* DC bias table 4 */
- { 0x3, 4 },
- { 0x3C, 6 },
- { 0xF, 7 },
- { 0x7A, 7 },
- { 0x1D, 8 },
- { 0x20, 9 },
- { 0x72, 10 },
- { 0x6, 6 },
- { 0x399, 13 },
- { 0x4, 3 },
- { 0x5, 3 },
- { 0x5, 4 },
- { 0x6, 4 },
- { 0xE, 4 },
- { 0x4, 4 },
- { 0x0, 4 },
- { 0x19, 5 },
- { 0x2, 4 },
- { 0xD, 4 },
- { 0x7, 4 },
- { 0x1F, 5 },
- { 0x30, 6 },
- { 0x11, 8 },
- { 0x31, 6 },
- { 0x5, 6 },
- { 0x21, 9 },
- { 0xE7, 11 },
- { 0x38, 9 },
- { 0x1CD, 12 },
- { 0x398, 13 },
- { 0x7B, 7 },
- { 0x9, 7 }
- },
- { /* DC bias table 5 */
- { 0x9, 4 },
- { 0x2, 5 },
- { 0x74, 7 },
- { 0x7, 6 },
- { 0xEC, 8 },
- { 0xD1, 9 },
- { 0x1A6, 10 },
- { 0x6, 6 },
- { 0xD21, 13 },
- { 0x5, 3 },
- { 0x6, 3 },
- { 0x8, 4 },
- { 0x7, 4 },
- { 0xF, 4 },
- { 0x4, 4 },
- { 0x0, 4 },
- { 0x1C, 5 },
- { 0x2, 4 },
- { 0x5, 4 },
- { 0x3, 4 },
- { 0xC, 5 },
- { 0x35, 7 },
- { 0x1A7, 10 },
- { 0x1B, 6 },
- { 0x77, 7 },
- { 0x1A5, 10 },
- { 0x349, 11 },
- { 0xD0, 9 },
- { 0x691, 12 },
- { 0xD20, 13 },
- { 0x75, 7 },
- { 0xED, 8 }
- },
- { /* DC bias table 6 */
- { 0xA, 4 },
- { 0xC, 5 },
- { 0x12, 6 },
- { 0x1B, 6 },
- { 0xB7, 8 },
- { 0x16C, 9 },
- { 0x99, 9 },
- { 0x5A, 7 },
- { 0x16D8, 13 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x0, 3 },
- { 0x5, 4 },
- { 0x17, 5 },
- { 0xE, 5 },
- { 0x2, 4 },
- { 0x3, 4 },
- { 0xF, 5 },
- { 0x1A, 6 },
- { 0x4D, 8 },
- { 0x2DB3, 14 },
- { 0x2C, 6 },
- { 0x11, 6 },
- { 0x2DA, 10 },
- { 0x5B7, 11 },
- { 0x98, 9 },
- { 0xB6D, 12 },
- { 0x2DB2, 14 },
- { 0x10, 6 },
- { 0x27, 7 }
- },
- { /* DC bias table 7 */
- { 0xD, 4 },
- { 0xF, 5 },
- { 0x1D, 6 },
- { 0x8, 5 },
- { 0x51, 7 },
- { 0x56, 8 },
- { 0xAF, 9 },
- { 0x2A, 7 },
- { 0x148A, 13 },
- { 0x7, 3 },
- { 0x0, 2 },
- { 0x8, 4 },
- { 0x9, 4 },
- { 0xC, 4 },
- { 0x6, 4 },
- { 0x17, 5 },
- { 0xB, 5 },
- { 0x16, 5 },
- { 0x15, 5 },
- { 0x9, 5 },
- { 0x50, 7 },
- { 0xAE, 9 },
- { 0x2917, 14 },
- { 0x1C, 6 },
- { 0x14, 6 },
- { 0x290, 10 },
- { 0x523, 11 },
- { 0x149, 9 },
- { 0xA44, 12 },
- { 0x2916, 14 },
- { 0x53, 7 },
- { 0xA5, 8 }
- },
- { /* DC bias table 8 */
- { 0x1, 4 },
- { 0x1D, 6 },
- { 0xF5, 8 },
- { 0xF4, 8 },
- { 0x24D, 10 },
- { 0x499, 11 },
- { 0x498, 11 },
- { 0x1, 5 },
- { 0x21, 6 },
- { 0x6, 3 },
- { 0x5, 3 },
- { 0x6, 4 },
- { 0x5, 4 },
- { 0x2, 4 },
- { 0x7, 5 },
- { 0x25, 6 },
- { 0x7B, 7 },
- { 0x1C, 6 },
- { 0x20, 6 },
- { 0xD, 6 },
- { 0x48, 7 },
- { 0x92, 8 },
- { 0x127, 9 },
- { 0xE, 4 },
- { 0x4, 4 },
- { 0x11, 5 },
- { 0xC, 6 },
- { 0x3C, 6 },
- { 0xF, 5 },
- { 0x0, 5 },
- { 0x1F, 5 },
- { 0x13, 5 }
- },
- { /* DC bias table 9 */
- { 0x5, 4 },
- { 0x3C, 6 },
- { 0x40, 7 },
- { 0xD, 7 },
- { 0x31, 9 },
- { 0x61, 10 },
- { 0x60, 10 },
- { 0x2, 5 },
- { 0xF5, 8 },
- { 0x6, 3 },
- { 0x5, 3 },
- { 0x7, 4 },
- { 0x6, 4 },
- { 0x2, 4 },
- { 0x9, 5 },
- { 0x25, 6 },
- { 0x7, 6 },
- { 0x21, 6 },
- { 0x24, 6 },
- { 0x10, 6 },
- { 0x41, 7 },
- { 0xF4, 8 },
- { 0x19, 8 },
- { 0xE, 4 },
- { 0x3, 4 },
- { 0x11, 5 },
- { 0x11, 6 },
- { 0x3F, 6 },
- { 0x3E, 6 },
- { 0x7B, 7 },
- { 0x0, 4 },
- { 0x13, 5 }
- },
- { /* DC bias table 10 */
- { 0xA, 4 },
- { 0x7, 5 },
- { 0x1, 6 },
- { 0x9, 6 },
- { 0x131, 9 },
- { 0x261, 10 },
- { 0x260, 10 },
- { 0x15, 6 },
- { 0x1, 7 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x8, 4 },
- { 0x7, 4 },
- { 0x6, 4 },
- { 0x12, 5 },
- { 0x2F, 6 },
- { 0x14, 6 },
- { 0x27, 6 },
- { 0x2D, 6 },
- { 0x16, 6 },
- { 0x4D, 7 },
- { 0x99, 8 },
- { 0x0, 7 },
- { 0x4, 4 },
- { 0x1, 4 },
- { 0x5, 5 },
- { 0x17, 6 },
- { 0x2E, 6 },
- { 0x2C, 6 },
- { 0x8, 6 },
- { 0x6, 5 },
- { 0x1, 5 }
- },
- { /* DC bias table 11 */
- { 0x0, 3 },
- { 0xE, 5 },
- { 0x17, 6 },
- { 0x2A, 6 },
- { 0x10, 7 },
- { 0xF9, 10 },
- { 0xF8, 10 },
- { 0x1E, 7 },
- { 0x3F, 8 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x6, 4 },
- { 0xF, 5 },
- { 0x5, 5 },
- { 0x16, 6 },
- { 0x29, 6 },
- { 0x2B, 6 },
- { 0x15, 6 },
- { 0x50, 7 },
- { 0x11, 7 },
- { 0x7D, 9 },
- { 0x4, 4 },
- { 0x17, 5 },
- { 0x6, 5 },
- { 0x14, 6 },
- { 0x2C, 6 },
- { 0x2D, 6 },
- { 0xE, 6 },
- { 0x9, 6 },
- { 0x51, 7 }
- },
- { /* DC bias table 12 */
- { 0x2, 3 },
- { 0x18, 5 },
- { 0x2F, 6 },
- { 0xD, 5 },
- { 0x53, 7 },
- { 0x295, 10 },
- { 0x294, 10 },
- { 0xA4, 8 },
- { 0x7C, 8 },
- { 0x0, 2 },
- { 0x7, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x1B, 5 },
- { 0xC, 5 },
- { 0x28, 6 },
- { 0x6A, 7 },
- { 0x1E, 6 },
- { 0x1D, 6 },
- { 0x69, 7 },
- { 0xD7, 8 },
- { 0x7D, 8 },
- { 0x14B, 9 },
- { 0x19, 5 },
- { 0x16, 5 },
- { 0x2E, 6 },
- { 0x1C, 6 },
- { 0x2B, 6 },
- { 0x2A, 6 },
- { 0x68, 7 },
- { 0x3F, 7 },
- { 0xD6, 8 }
- },
- { /* DC bias table 13 */
- { 0x2, 3 },
- { 0x1B, 5 },
- { 0xC, 5 },
- { 0x18, 5 },
- { 0x29, 6 },
- { 0x7F, 8 },
- { 0x2F0, 10 },
- { 0x198, 9 },
- { 0x179, 9 },
- { 0x0, 2 },
- { 0x7, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x1A, 5 },
- { 0xD, 5 },
- { 0x2A, 6 },
- { 0x64, 7 },
- { 0x1E, 6 },
- { 0x67, 7 },
- { 0x5F, 7 },
- { 0xCD, 8 },
- { 0x7E, 8 },
- { 0x2F1, 10 },
- { 0x16, 5 },
- { 0xE, 5 },
- { 0x2E, 6 },
- { 0x65, 7 },
- { 0x2B, 6 },
- { 0x28, 6 },
- { 0x3E, 7 },
- { 0xBD, 8 },
- { 0x199, 9 }
- },
- { /* DC bias table 14 */
- { 0x2, 3 },
- { 0x7, 4 },
- { 0x16, 5 },
- { 0x6, 4 },
- { 0x36, 6 },
- { 0x5C, 7 },
- { 0x15D, 9 },
- { 0x15C, 9 },
- { 0x2BF, 10 },
- { 0x0, 2 },
- { 0x7, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x18, 5 },
- { 0x34, 6 },
- { 0x2A, 6 },
- { 0x5E, 7 },
- { 0x6A, 7 },
- { 0x64, 7 },
- { 0x5D, 7 },
- { 0xCB, 8 },
- { 0xAD, 8 },
- { 0x2BE, 10 },
- { 0x14, 5 },
- { 0x33, 6 },
- { 0x6E, 7 },
- { 0x5F, 7 },
- { 0x6F, 7 },
- { 0x6B, 7 },
- { 0xCA, 8 },
- { 0xAC, 8 },
- { 0x15E, 9 }
- },
- { /* DC bias table 15 */
- { 0xF, 4 },
- { 0x1D, 5 },
- { 0x18, 5 },
- { 0xB, 4 },
- { 0x19, 5 },
- { 0x29, 6 },
- { 0xD6, 8 },
- { 0x551, 11 },
- { 0xAA1, 12 },
- { 0x1, 2 },
- { 0x0, 2 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x1B, 5 },
- { 0x38, 6 },
- { 0x28, 6 },
- { 0x57, 7 },
- { 0x6A, 7 },
- { 0x68, 7 },
- { 0x56, 7 },
- { 0xE5, 8 },
- { 0x155, 9 },
- { 0xAA0, 12 },
- { 0x73, 7 },
- { 0x69, 7 },
- { 0xD7, 8 },
- { 0xAB, 8 },
- { 0xE4, 8 },
- { 0xA9, 8 },
- { 0x151, 9 },
- { 0x150, 9 },
- { 0x2A9, 10 }
- }
-};
-
-static const uint16_t ac_bias_0[16][32][2] = {
- { /* AC bias group 1, table 0 */
- { 0x8, 5 },
- { 0x25, 7 },
- { 0x17A, 9 },
- { 0x2F7, 10 },
- { 0xBDB, 12 },
- { 0x17B4, 13 },
- { 0x2F6B, 14 },
- { 0x1D, 5 },
- { 0x2F6A, 14 },
- { 0x8, 4 },
- { 0x7, 4 },
- { 0x1, 4 },
- { 0x2, 4 },
- { 0xA, 4 },
- { 0x6, 4 },
- { 0x0, 4 },
- { 0x1C, 5 },
- { 0x9, 4 },
- { 0xD, 4 },
- { 0xF, 4 },
- { 0xC, 4 },
- { 0x3, 4 },
- { 0xA, 5 },
- { 0x16, 5 },
- { 0x13, 6 },
- { 0x5D, 7 },
- { 0x24, 7 },
- { 0xBC, 8 },
- { 0x5C, 7 },
- { 0x5EC, 11 },
- { 0xB, 5 },
- { 0x5F, 7 }
- },
- { /* AC bias group 1, table 1 */
- { 0xF, 5 },
- { 0x10, 6 },
- { 0x4B, 8 },
- { 0xC6, 8 },
- { 0x31D, 10 },
- { 0xC71, 12 },
- { 0xC70, 12 },
- { 0x1, 4 },
- { 0xC73, 12 },
- { 0x8, 4 },
- { 0x9, 4 },
- { 0x2, 4 },
- { 0x3, 4 },
- { 0xB, 4 },
- { 0x6, 4 },
- { 0x0, 4 },
- { 0x1C, 5 },
- { 0x5, 4 },
- { 0xD, 4 },
- { 0xF, 4 },
- { 0xA, 4 },
- { 0x19, 5 },
- { 0x13, 6 },
- { 0x1D, 5 },
- { 0x30, 6 },
- { 0x62, 7 },
- { 0x24, 7 },
- { 0x4A, 8 },
- { 0x18F, 9 },
- { 0xC72, 12 },
- { 0xE, 5 },
- { 0x11, 6 }
- },
- { /* AC bias group 1, table 2 */
- { 0x1B, 5 },
- { 0x3, 6 },
- { 0x8D, 8 },
- { 0x40, 7 },
- { 0x239, 10 },
- { 0x471, 11 },
- { 0x8E0, 12 },
- { 0x3, 4 },
- { 0x11C3, 13 },
- { 0xA, 4 },
- { 0x9, 4 },
- { 0x4, 4 },
- { 0x5, 4 },
- { 0xE, 4 },
- { 0x7, 4 },
- { 0x1, 4 },
- { 0x1E, 5 },
- { 0x6, 4 },
- { 0xC, 4 },
- { 0xB, 4 },
- { 0x2, 4 },
- { 0x0, 5 },
- { 0x41, 7 },
- { 0x1F, 5 },
- { 0x22, 6 },
- { 0x2, 6 },
- { 0x8F, 8 },
- { 0x8C, 8 },
- { 0x11D, 9 },
- { 0x11C2, 13 },
- { 0x1A, 5 },
- { 0x21, 6 }
- },
- { /* AC bias group 1, table 3 */
- { 0x1F, 5 },
- { 0x3, 6 },
- { 0x3, 7 },
- { 0x43, 7 },
- { 0xB, 9 },
- { 0x15, 10 },
- { 0x51, 12 },
- { 0x3, 4 },
- { 0x50, 12 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x4, 4 },
- { 0x6, 4 },
- { 0xE, 4 },
- { 0xA, 4 },
- { 0x1, 4 },
- { 0x1E, 5 },
- { 0x5, 4 },
- { 0x9, 4 },
- { 0x7, 4 },
- { 0x11, 5 },
- { 0x2, 6 },
- { 0x4, 8 },
- { 0x2, 4 },
- { 0x2D, 6 },
- { 0x20, 6 },
- { 0x42, 7 },
- { 0x1, 7 },
- { 0x0, 7 },
- { 0x29, 11 },
- { 0x17, 5 },
- { 0x2C, 6 }
- },
- { /* AC bias group 1, table 4 */
- { 0x3, 4 },
- { 0x1F, 6 },
- { 0x3A, 7 },
- { 0x5D, 7 },
- { 0x173, 9 },
- { 0x2E4, 10 },
- { 0x172D, 13 },
- { 0x4, 4 },
- { 0x172C, 13 },
- { 0xF, 4 },
- { 0xE, 4 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0xC, 4 },
- { 0xA, 4 },
- { 0x1, 4 },
- { 0x16, 5 },
- { 0x2, 4 },
- { 0x5, 4 },
- { 0x1A, 5 },
- { 0x2F, 6 },
- { 0x38, 7 },
- { 0x5CA, 11 },
- { 0x6, 4 },
- { 0x37, 6 },
- { 0x1E, 6 },
- { 0x3B, 7 },
- { 0x39, 7 },
- { 0xB8, 8 },
- { 0xB97, 12 },
- { 0x0, 4 },
- { 0x36, 6 }
- },
- { /* AC bias group 1, table 5 */
- { 0x6, 4 },
- { 0x37, 6 },
- { 0x5D, 7 },
- { 0xC, 6 },
- { 0xB9, 8 },
- { 0x2E3, 10 },
- { 0x5C4, 11 },
- { 0x4, 4 },
- { 0x1715, 13 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0x8, 4 },
- { 0x7, 4 },
- { 0xC, 4 },
- { 0x9, 4 },
- { 0x1D, 5 },
- { 0x16, 5 },
- { 0x1C, 5 },
- { 0x1A, 5 },
- { 0xB, 5 },
- { 0x5E, 7 },
- { 0x170, 9 },
- { 0x1714, 13 },
- { 0xA, 4 },
- { 0xA, 5 },
- { 0x36, 6 },
- { 0x5F, 7 },
- { 0x1B, 7 },
- { 0x1A, 7 },
- { 0xB8B, 12 },
- { 0x2, 4 },
- { 0x7, 5 }
- },
- { /* AC bias group 1, table 6 */
- { 0xC, 4 },
- { 0xB, 5 },
- { 0x79, 7 },
- { 0x22, 6 },
- { 0xF0, 8 },
- { 0x119, 9 },
- { 0x230, 10 },
- { 0x1D, 5 },
- { 0x8C4, 12 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xA, 4 },
- { 0x9, 4 },
- { 0xB, 4 },
- { 0x7, 4 },
- { 0x1C, 5 },
- { 0x3D, 6 },
- { 0xD, 5 },
- { 0x8, 5 },
- { 0x15, 6 },
- { 0x8D, 8 },
- { 0x118B, 13 },
- { 0x118A, 13 },
- { 0xD, 4 },
- { 0x10, 5 },
- { 0x9, 5 },
- { 0x14, 6 },
- { 0x47, 7 },
- { 0xF1, 8 },
- { 0x463, 11 },
- { 0x1F, 5 },
- { 0xC, 5 }
- },
- { /* AC bias group 1, table 7 */
- { 0x0, 3 },
- { 0x1A, 5 },
- { 0x33, 6 },
- { 0xC, 5 },
- { 0x46, 7 },
- { 0x1E3, 9 },
- { 0x3C5, 10 },
- { 0x17, 5 },
- { 0x1E21, 13 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x9, 4 },
- { 0xA, 4 },
- { 0x7, 4 },
- { 0x1B, 5 },
- { 0x3D, 6 },
- { 0x1B, 6 },
- { 0x22, 6 },
- { 0x79, 7 },
- { 0xF0, 8 },
- { 0x1E20, 13 },
- { 0x1E23, 13 },
- { 0x1E22, 13 },
- { 0xE, 4 },
- { 0x16, 5 },
- { 0x18, 5 },
- { 0x32, 6 },
- { 0x1A, 6 },
- { 0x47, 7 },
- { 0x789, 11 },
- { 0x1F, 5 },
- { 0x10, 5 }
- },
- { /* AC bias group 1, table 8 */
- { 0x1D, 5 },
- { 0x61, 7 },
- { 0x4E, 8 },
- { 0x9E, 9 },
- { 0x27C, 11 },
- { 0x9F5, 13 },
- { 0x9F4, 13 },
- { 0x3, 4 },
- { 0x60, 7 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0xB, 4 },
- { 0xA, 4 },
- { 0x9, 4 },
- { 0x5, 4 },
- { 0xD, 5 },
- { 0x31, 6 },
- { 0x8, 5 },
- { 0x38, 6 },
- { 0x12, 6 },
- { 0x26, 7 },
- { 0x13F, 10 },
- { 0x4FB, 12 },
- { 0xD, 4 },
- { 0x2, 4 },
- { 0xC, 5 },
- { 0x39, 6 },
- { 0x1C, 6 },
- { 0xF, 5 },
- { 0x1D, 6 },
- { 0x8, 4 },
- { 0x19, 5 }
- },
- { /* AC bias group 1, table 9 */
- { 0x7, 4 },
- { 0x19, 6 },
- { 0xAB, 8 },
- { 0xAA, 8 },
- { 0x119, 10 },
- { 0x461, 12 },
- { 0x460, 12 },
- { 0x1B, 5 },
- { 0x47, 8 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xC, 4 },
- { 0xB, 4 },
- { 0x9, 4 },
- { 0x5, 4 },
- { 0xD, 5 },
- { 0x35, 6 },
- { 0x3D, 6 },
- { 0x3C, 6 },
- { 0x18, 6 },
- { 0x22, 7 },
- { 0x8D, 9 },
- { 0x231, 11 },
- { 0xE, 4 },
- { 0x1F, 5 },
- { 0x9, 5 },
- { 0x2B, 6 },
- { 0x10, 6 },
- { 0x34, 6 },
- { 0x54, 7 },
- { 0x8, 4 },
- { 0x14, 5 }
- },
- { /* AC bias group 1, table 10 */
- { 0xC, 4 },
- { 0x5, 5 },
- { 0x8, 6 },
- { 0x5B, 7 },
- { 0x4D, 9 },
- { 0x131, 11 },
- { 0x261, 12 },
- { 0x1A, 5 },
- { 0x12, 7 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0xA, 4 },
- { 0x9, 4 },
- { 0x6, 4 },
- { 0x1B, 5 },
- { 0x6, 5 },
- { 0x1C, 6 },
- { 0x2C, 6 },
- { 0x15, 6 },
- { 0x5A, 7 },
- { 0x27, 8 },
- { 0x99, 10 },
- { 0x260, 12 },
- { 0xE, 4 },
- { 0x4, 4 },
- { 0xF, 5 },
- { 0x7, 5 },
- { 0x1D, 6 },
- { 0xB, 5 },
- { 0x14, 6 },
- { 0x8, 4 },
- { 0x17, 5 }
- },
- { /* AC bias group 1, table 11 */
- { 0xF, 4 },
- { 0x13, 5 },
- { 0x75, 7 },
- { 0x24, 6 },
- { 0x95, 8 },
- { 0x251, 10 },
- { 0x4A0, 11 },
- { 0x10, 5 },
- { 0xC8, 8 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x1, 4 },
- { 0x0, 4 },
- { 0x1A, 5 },
- { 0x11, 5 },
- { 0x2C, 6 },
- { 0x65, 7 },
- { 0x74, 7 },
- { 0x4B, 7 },
- { 0xC9, 8 },
- { 0x129, 9 },
- { 0x943, 12 },
- { 0x942, 12 },
- { 0x3, 3 },
- { 0xA, 4 },
- { 0x1C, 5 },
- { 0x18, 5 },
- { 0x33, 6 },
- { 0x17, 5 },
- { 0x2D, 6 },
- { 0x1B, 5 },
- { 0x3B, 6 }
- },
- { /* AC bias group 1, table 12 */
- { 0x3, 3 },
- { 0x1A, 5 },
- { 0x2D, 6 },
- { 0x38, 6 },
- { 0x28, 7 },
- { 0x395, 10 },
- { 0xE51, 12 },
- { 0x37, 6 },
- { 0xE4, 8 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0x1F, 5 },
- { 0x1E, 5 },
- { 0x17, 5 },
- { 0x3A, 6 },
- { 0x73, 7 },
- { 0x2A, 7 },
- { 0x2B, 7 },
- { 0x29, 7 },
- { 0x1CB, 9 },
- { 0x729, 11 },
- { 0x1CA1, 13 },
- { 0x1CA0, 13 },
- { 0x4, 3 },
- { 0xA, 4 },
- { 0x4, 4 },
- { 0x18, 5 },
- { 0x36, 6 },
- { 0xB, 5 },
- { 0x2C, 6 },
- { 0x19, 5 },
- { 0x3B, 6 }
- },
- { /* AC bias group 1, table 13 */
- { 0x4, 3 },
- { 0x4, 4 },
- { 0x3F, 6 },
- { 0x17, 5 },
- { 0x75, 7 },
- { 0x1F5, 9 },
- { 0x7D1, 11 },
- { 0x17, 6 },
- { 0x1F6, 9 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0x1B, 5 },
- { 0x1A, 5 },
- { 0xA, 5 },
- { 0x32, 6 },
- { 0x74, 7 },
- { 0xF8, 8 },
- { 0xF9, 8 },
- { 0x1F7, 9 },
- { 0x3E9, 10 },
- { 0xFA0, 12 },
- { 0x1F43, 13 },
- { 0x1F42, 13 },
- { 0x3, 3 },
- { 0xA, 4 },
- { 0x1E, 5 },
- { 0x1C, 5 },
- { 0x3B, 6 },
- { 0x18, 5 },
- { 0x16, 6 },
- { 0x16, 5 },
- { 0x33, 6 }
- },
- { /* AC bias group 1, table 14 */
- { 0x4, 3 },
- { 0x7, 4 },
- { 0x18, 5 },
- { 0x1E, 5 },
- { 0x36, 6 },
- { 0x31, 7 },
- { 0x177, 9 },
- { 0x77, 7 },
- { 0x176, 9 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0x1A, 5 },
- { 0x19, 5 },
- { 0x3A, 6 },
- { 0x19, 6 },
- { 0x5C, 7 },
- { 0xBA, 8 },
- { 0x61, 8 },
- { 0xC1, 9 },
- { 0x180, 10 },
- { 0x302, 11 },
- { 0x607, 12 },
- { 0x606, 12 },
- { 0x2, 3 },
- { 0xA, 4 },
- { 0x1F, 5 },
- { 0x1C, 5 },
- { 0x37, 6 },
- { 0x16, 5 },
- { 0x76, 7 },
- { 0xD, 5 },
- { 0x2F, 6 }
- },
- { /* AC bias group 1, table 15 */
- { 0x0, 3 },
- { 0xA, 4 },
- { 0x1A, 5 },
- { 0xC, 4 },
- { 0x1D, 5 },
- { 0x39, 6 },
- { 0x78, 7 },
- { 0x5E, 7 },
- { 0x393, 11 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x16, 5 },
- { 0xF, 5 },
- { 0x2E, 6 },
- { 0x5F, 7 },
- { 0x73, 8 },
- { 0xE5, 9 },
- { 0x1C8, 10 },
- { 0xE4A, 13 },
- { 0x1C97, 14 },
- { 0x1C96, 14 },
- { 0xE49, 13 },
- { 0xE48, 13 },
- { 0x4, 3 },
- { 0x6, 4 },
- { 0x1F, 5 },
- { 0x1B, 5 },
- { 0x1D, 6 },
- { 0x38, 6 },
- { 0x38, 7 },
- { 0x3D, 6 },
- { 0x79, 7 }
- }
-};
-
-static const uint16_t ac_bias_1[16][32][2] = {
- { /* AC bias group 2, table 0 */
- { 0xB, 5 },
- { 0x2B, 7 },
- { 0x54, 8 },
- { 0x1B7, 9 },
- { 0x6D9, 11 },
- { 0xDB1, 12 },
- { 0xDB0, 12 },
- { 0x2, 4 },
- { 0xAB, 9 },
- { 0x9, 4 },
- { 0xA, 4 },
- { 0x7, 4 },
- { 0x8, 4 },
- { 0xF, 4 },
- { 0xC, 4 },
- { 0x3, 4 },
- { 0x1D, 5 },
- { 0x4, 4 },
- { 0xB, 4 },
- { 0x6, 4 },
- { 0x1A, 5 },
- { 0x3, 6 },
- { 0xAA, 9 },
- { 0x1, 4 },
- { 0x0, 5 },
- { 0x14, 6 },
- { 0x6C, 7 },
- { 0xDA, 8 },
- { 0x2, 6 },
- { 0x36D, 10 },
- { 0x1C, 5 },
- { 0x37, 6 }
- },
- { /* AC bias group 2, table 1 */
- { 0x1D, 5 },
- { 0x4, 6 },
- { 0xB6, 8 },
- { 0x6A, 8 },
- { 0x5B9, 11 },
- { 0x16E1, 13 },
- { 0x16E0, 13 },
- { 0x7, 4 },
- { 0x16F, 9 },
- { 0xC, 4 },
- { 0xD, 4 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0xF, 4 },
- { 0xA, 4 },
- { 0x3, 4 },
- { 0x17, 5 },
- { 0x2, 4 },
- { 0x4, 4 },
- { 0x1C, 5 },
- { 0x2C, 6 },
- { 0x6B, 8 },
- { 0xB71, 12 },
- { 0x5, 4 },
- { 0x3, 5 },
- { 0x1B, 6 },
- { 0x5A, 7 },
- { 0x34, 7 },
- { 0x5, 6 },
- { 0x2DD, 10 },
- { 0x0, 4 },
- { 0xC, 5 }
- },
- { /* AC bias group 2, table 2 */
- { 0x3, 4 },
- { 0x7F, 7 },
- { 0xA1, 8 },
- { 0xA0, 8 },
- { 0x20C, 10 },
- { 0x834, 12 },
- { 0x106B, 13 },
- { 0x7, 4 },
- { 0x82, 8 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0x0, 3 },
- { 0x9, 4 },
- { 0x2, 4 },
- { 0x11, 5 },
- { 0x1E, 5 },
- { 0x15, 5 },
- { 0x3E, 6 },
- { 0x40, 7 },
- { 0x41B, 11 },
- { 0x106A, 13 },
- { 0x6, 4 },
- { 0xA, 5 },
- { 0x29, 6 },
- { 0x7E, 7 },
- { 0x51, 7 },
- { 0x21, 6 },
- { 0x107, 9 },
- { 0x4, 4 },
- { 0xB, 5 }
- },
- { /* AC bias group 2, table 3 */
- { 0x7, 4 },
- { 0x1B, 6 },
- { 0xF6, 8 },
- { 0xE9, 8 },
- { 0x3A1, 10 },
- { 0x740, 11 },
- { 0xE82, 12 },
- { 0x1F, 5 },
- { 0x1EF, 9 },
- { 0x1, 3 },
- { 0x2, 3 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0xD, 4 },
- { 0x8, 4 },
- { 0x1C, 5 },
- { 0x3, 5 },
- { 0x12, 5 },
- { 0x2, 5 },
- { 0x75, 7 },
- { 0x1D1, 9 },
- { 0x1D07, 13 },
- { 0x1D06, 13 },
- { 0xA, 4 },
- { 0x13, 5 },
- { 0x3B, 6 },
- { 0x1A, 6 },
- { 0x7A, 7 },
- { 0x3C, 6 },
- { 0x1EE, 9 },
- { 0x0, 4 },
- { 0xC, 5 }
- },
- { /* AC bias group 2, table 4 */
- { 0xD, 4 },
- { 0x3D, 6 },
- { 0x42, 7 },
- { 0x37, 7 },
- { 0xD9, 9 },
- { 0x362, 11 },
- { 0x6C6, 12 },
- { 0x1F, 5 },
- { 0x86, 8 },
- { 0x1, 3 },
- { 0x2, 3 },
- { 0xC, 4 },
- { 0xB, 4 },
- { 0xA, 4 },
- { 0x1, 4 },
- { 0xF, 5 },
- { 0x25, 6 },
- { 0x3C, 6 },
- { 0x1A, 6 },
- { 0x87, 8 },
- { 0x1B0, 10 },
- { 0xD8F, 13 },
- { 0xD8E, 13 },
- { 0xE, 4 },
- { 0x13, 5 },
- { 0xC, 5 },
- { 0x24, 6 },
- { 0x20, 6 },
- { 0x11, 5 },
- { 0x6D, 8 },
- { 0x0, 4 },
- { 0xE, 5 }
- },
- { /* AC bias group 2, table 5 */
- { 0x0, 3 },
- { 0x12, 5 },
- { 0x76, 7 },
- { 0x77, 7 },
- { 0x14D, 9 },
- { 0x533, 11 },
- { 0x14C9, 13 },
- { 0x13, 5 },
- { 0xA5, 8 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0x8, 4 },
- { 0x1A, 5 },
- { 0x2B, 6 },
- { 0x75, 7 },
- { 0x74, 7 },
- { 0xA7, 8 },
- { 0x298, 10 },
- { 0x14C8, 13 },
- { 0x14CB, 13 },
- { 0x14CA, 13 },
- { 0xF, 4 },
- { 0x1C, 5 },
- { 0x7, 5 },
- { 0x2A, 6 },
- { 0x28, 6 },
- { 0x1B, 5 },
- { 0xA4, 8 },
- { 0x2, 4 },
- { 0x6, 5 }
- },
- { /* AC bias group 2, table 6 */
- { 0x2, 3 },
- { 0x1A, 5 },
- { 0x2B, 6 },
- { 0x3A, 6 },
- { 0xED, 8 },
- { 0x283, 10 },
- { 0xA0A, 12 },
- { 0x4, 5 },
- { 0xA1, 8 },
- { 0x4, 3 },
- { 0x3, 3 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0x1F, 5 },
- { 0x6, 5 },
- { 0x77, 7 },
- { 0xA3, 8 },
- { 0xA2, 8 },
- { 0x140, 9 },
- { 0x1417, 13 },
- { 0x1416, 13 },
- { 0xA09, 12 },
- { 0xA08, 12 },
- { 0x0, 3 },
- { 0x1E, 5 },
- { 0x7, 5 },
- { 0x2A, 6 },
- { 0x29, 6 },
- { 0x1C, 5 },
- { 0xEC, 8 },
- { 0x1B, 5 },
- { 0x5, 5 }
- },
- { /* AC bias group 2, table 7 */
- { 0x2, 3 },
- { 0x2, 4 },
- { 0x18, 5 },
- { 0x1D, 5 },
- { 0x35, 6 },
- { 0xE4, 8 },
- { 0x1CF, 11 },
- { 0x1D, 7 },
- { 0x72, 9 },
- { 0x4, 3 },
- { 0x5, 3 },
- { 0x6, 4 },
- { 0x7, 4 },
- { 0x6, 5 },
- { 0x73, 7 },
- { 0x38, 8 },
- { 0x1CE, 11 },
- { 0x39B, 12 },
- { 0x398, 12 },
- { 0x733, 13 },
- { 0x732, 13 },
- { 0x735, 13 },
- { 0x734, 13 },
- { 0x0, 3 },
- { 0x1F, 5 },
- { 0x1B, 5 },
- { 0x34, 6 },
- { 0xF, 6 },
- { 0x1E, 5 },
- { 0xE5, 8 },
- { 0x19, 5 },
- { 0x38, 6 }
- },
- { /* AC bias group 2, table 8 */
- { 0x16, 5 },
- { 0x50, 7 },
- { 0x172, 9 },
- { 0x2E7, 10 },
- { 0x1732, 13 },
- { 0x2E67, 14 },
- { 0x2E66, 14 },
- { 0x6, 4 },
- { 0x51, 7 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x9, 4 },
- { 0x1C, 5 },
- { 0x9, 5 },
- { 0x1C, 6 },
- { 0x1D, 6 },
- { 0x5D, 7 },
- { 0xB8, 8 },
- { 0x5CD, 11 },
- { 0x1731, 13 },
- { 0x1730, 13 },
- { 0xF, 4 },
- { 0x5, 4 },
- { 0xF, 5 },
- { 0x8, 5 },
- { 0x29, 6 },
- { 0x1D, 5 },
- { 0x2F, 6 },
- { 0x8, 4 },
- { 0x15, 5 }
- },
- { /* AC bias group 2, table 9 */
- { 0x9, 4 },
- { 0x21, 6 },
- { 0x40, 7 },
- { 0xAD, 8 },
- { 0x2B0, 10 },
- { 0x1589, 13 },
- { 0x1588, 13 },
- { 0x1C, 5 },
- { 0x5F, 7 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x6, 4 },
- { 0x11, 5 },
- { 0x2A, 6 },
- { 0x57, 7 },
- { 0x5E, 7 },
- { 0x41, 7 },
- { 0x159, 9 },
- { 0x563, 11 },
- { 0x158B, 13 },
- { 0x158A, 13 },
- { 0x1, 3 },
- { 0x5, 4 },
- { 0x14, 5 },
- { 0x3B, 6 },
- { 0x2E, 6 },
- { 0x4, 4 },
- { 0x3A, 6 },
- { 0x7, 4 },
- { 0x16, 5 }
- },
- { /* AC bias group 2, table 10 */
- { 0xE, 4 },
- { 0x7, 5 },
- { 0x46, 7 },
- { 0x45, 7 },
- { 0x64, 9 },
- { 0x32A, 12 },
- { 0x657, 13 },
- { 0x18, 5 },
- { 0xD, 6 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0xA, 4 },
- { 0xB, 4 },
- { 0x1A, 5 },
- { 0x36, 6 },
- { 0x47, 7 },
- { 0x44, 7 },
- { 0x18, 7 },
- { 0x33, 8 },
- { 0xCB, 10 },
- { 0x656, 13 },
- { 0x329, 12 },
- { 0x328, 12 },
- { 0x2, 3 },
- { 0x6, 4 },
- { 0x19, 5 },
- { 0xE, 5 },
- { 0x37, 6 },
- { 0x9, 4 },
- { 0xF, 5 },
- { 0x2, 4 },
- { 0x10, 5 }
- },
- { /* AC bias group 2, table 11 */
- { 0x3, 3 },
- { 0x18, 5 },
- { 0x23, 6 },
- { 0x77, 7 },
- { 0x194, 9 },
- { 0x1956, 13 },
- { 0x32AF, 14 },
- { 0x3A, 6 },
- { 0x76, 7 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x1F, 5 },
- { 0x1E, 5 },
- { 0x14, 5 },
- { 0x22, 6 },
- { 0x64, 7 },
- { 0x197, 9 },
- { 0x196, 9 },
- { 0x32B, 10 },
- { 0x654, 11 },
- { 0x32AE, 14 },
- { 0x1955, 13 },
- { 0x1954, 13 },
- { 0x0, 3 },
- { 0x9, 4 },
- { 0x1C, 5 },
- { 0x15, 5 },
- { 0x10, 5 },
- { 0xD, 4 },
- { 0x17, 5 },
- { 0x16, 5 },
- { 0x33, 6 }
- },
- { /* AC bias group 2, table 12 */
- { 0x5, 3 },
- { 0x6, 4 },
- { 0x3E, 6 },
- { 0x10, 5 },
- { 0x48, 7 },
- { 0x93F, 12 },
- { 0x24FA, 14 },
- { 0x32, 6 },
- { 0x67, 7 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x1B, 5 },
- { 0x1E, 5 },
- { 0x34, 6 },
- { 0x66, 7 },
- { 0x92, 8 },
- { 0x126, 9 },
- { 0x24E, 10 },
- { 0x49E, 11 },
- { 0x49F7, 15 },
- { 0x49F6, 15 },
- { 0x24F9, 14 },
- { 0x24F8, 14 },
- { 0x0, 3 },
- { 0x7, 4 },
- { 0x18, 5 },
- { 0x11, 5 },
- { 0x3F, 6 },
- { 0xE, 4 },
- { 0x13, 5 },
- { 0x35, 6 },
- { 0x25, 6 }
- },
- { /* AC bias group 2, table 13 */
- { 0x5, 3 },
- { 0x8, 4 },
- { 0x12, 5 },
- { 0x1C, 5 },
- { 0x1C, 6 },
- { 0xEA, 9 },
- { 0x1D75, 14 },
- { 0x1E, 6 },
- { 0x66, 7 },
- { 0x1, 3 },
- { 0x2, 3 },
- { 0x1B, 5 },
- { 0x1A, 5 },
- { 0x1F, 6 },
- { 0x3B, 7 },
- { 0x74, 8 },
- { 0x1D6, 10 },
- { 0x3AF, 11 },
- { 0x1D74, 14 },
- { 0x1D77, 14 },
- { 0x1D76, 14 },
- { 0xEB9, 13 },
- { 0xEB8, 13 },
- { 0xF, 4 },
- { 0x6, 4 },
- { 0x13, 5 },
- { 0x3B, 6 },
- { 0x3A, 6 },
- { 0x0, 3 },
- { 0x18, 5 },
- { 0x32, 6 },
- { 0x67, 7 }
- },
- { /* AC bias group 2, table 14 */
- { 0x4, 3 },
- { 0xA, 4 },
- { 0x1B, 5 },
- { 0xC, 4 },
- { 0xD, 5 },
- { 0xE6, 8 },
- { 0x684, 11 },
- { 0x72, 7 },
- { 0xE7, 8 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x17, 5 },
- { 0x16, 5 },
- { 0x18, 6 },
- { 0xD1, 8 },
- { 0x1A0, 9 },
- { 0x686, 11 },
- { 0xD0F, 12 },
- { 0xD0A, 12 },
- { 0x1A17, 13 },
- { 0x1A16, 13 },
- { 0x1A1D, 13 },
- { 0x1A1C, 13 },
- { 0xF, 4 },
- { 0x1D, 5 },
- { 0xE, 5 },
- { 0x35, 6 },
- { 0x38, 6 },
- { 0x0, 3 },
- { 0xF, 5 },
- { 0x19, 6 },
- { 0x69, 7 }
- },
- { /* AC bias group 2, table 15 */
- { 0x3, 3 },
- { 0xC, 4 },
- { 0x1B, 5 },
- { 0x0, 3 },
- { 0x3, 4 },
- { 0x2E, 6 },
- { 0x51, 9 },
- { 0xBC, 8 },
- { 0x53, 9 },
- { 0x4, 3 },
- { 0x2, 3 },
- { 0x16, 5 },
- { 0x15, 5 },
- { 0x15, 7 },
- { 0x50, 9 },
- { 0xA4, 10 },
- { 0x294, 12 },
- { 0x52B, 13 },
- { 0x52A, 13 },
- { 0x52D, 13 },
- { 0x52C, 13 },
- { 0x52F, 13 },
- { 0x52E, 13 },
- { 0xE, 4 },
- { 0x1A, 5 },
- { 0x4, 5 },
- { 0x28, 6 },
- { 0x29, 6 },
- { 0xF, 4 },
- { 0xB, 6 },
- { 0x5F, 7 },
- { 0xBD, 8 }
- }
-};
-
-static const uint16_t ac_bias_2[16][32][2] = {
- { /* AC bias group 3, table 0 */
- { 0x3, 4 },
- { 0x9, 6 },
- { 0xD0, 8 },
- { 0x1A3, 9 },
- { 0x344, 10 },
- { 0xD14, 12 },
- { 0x1A2B, 13 },
- { 0x4, 4 },
- { 0x15, 7 },
- { 0x0, 3 },
- { 0xF, 4 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0xE, 4 },
- { 0x9, 4 },
- { 0x1B, 5 },
- { 0xA, 5 },
- { 0x14, 5 },
- { 0xD, 5 },
- { 0x2A, 6 },
- { 0x14, 7 },
- { 0x68B, 11 },
- { 0x1A2A, 13 },
- { 0x8, 4 },
- { 0xB, 5 },
- { 0x2B, 6 },
- { 0xB, 6 },
- { 0x69, 7 },
- { 0x35, 6 },
- { 0x8, 6 },
- { 0x7, 4 },
- { 0xC, 5 }
- },
- { /* AC bias group 3, table 1 */
- { 0xA, 4 },
- { 0x3C, 6 },
- { 0x32, 7 },
- { 0x30, 7 },
- { 0xC5, 9 },
- { 0x621, 12 },
- { 0x620, 12 },
- { 0x1F, 5 },
- { 0x33, 7 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x4, 4 },
- { 0xD, 5 },
- { 0x26, 6 },
- { 0x27, 6 },
- { 0x14, 6 },
- { 0x63, 8 },
- { 0x189, 10 },
- { 0x623, 12 },
- { 0x622, 12 },
- { 0xB, 4 },
- { 0x12, 5 },
- { 0x3D, 6 },
- { 0x22, 6 },
- { 0x15, 6 },
- { 0xB, 5 },
- { 0x23, 6 },
- { 0x7, 4 },
- { 0x10, 5 }
- },
- { /* AC bias group 3, table 2 */
- { 0xF, 4 },
- { 0xC, 5 },
- { 0x43, 7 },
- { 0x10, 6 },
- { 0x44, 8 },
- { 0x114, 10 },
- { 0x455, 12 },
- { 0x18, 5 },
- { 0x23, 7 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0x9, 4 },
- { 0x19, 5 },
- { 0x9, 5 },
- { 0x17, 6 },
- { 0x16, 6 },
- { 0x42, 7 },
- { 0x8B, 9 },
- { 0x454, 12 },
- { 0x457, 12 },
- { 0x456, 12 },
- { 0xB, 4 },
- { 0x15, 5 },
- { 0xA, 5 },
- { 0x29, 6 },
- { 0x20, 6 },
- { 0xD, 5 },
- { 0x28, 6 },
- { 0x7, 4 },
- { 0x11, 5 }
- },
- { /* AC bias group 3, table 3 */
- { 0x1, 3 },
- { 0x1A, 5 },
- { 0x29, 6 },
- { 0x2A, 6 },
- { 0xA0, 8 },
- { 0x285, 10 },
- { 0x1425, 13 },
- { 0x2, 5 },
- { 0x0, 7 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0xC, 4 },
- { 0xB, 4 },
- { 0x8, 4 },
- { 0x12, 5 },
- { 0x1, 6 },
- { 0x51, 7 },
- { 0x1, 7 },
- { 0x143, 9 },
- { 0x508, 11 },
- { 0x1424, 13 },
- { 0x1427, 13 },
- { 0x1426, 13 },
- { 0xF, 4 },
- { 0x1C, 5 },
- { 0x3, 5 },
- { 0x37, 6 },
- { 0x2B, 6 },
- { 0x13, 5 },
- { 0x36, 6 },
- { 0x1D, 5 },
- { 0x1, 5 }
- },
- { /* AC bias group 3, table 4 */
- { 0x4, 3 },
- { 0x1F, 5 },
- { 0x3D, 6 },
- { 0x6, 5 },
- { 0x16, 7 },
- { 0x53, 9 },
- { 0x14A, 11 },
- { 0x34, 6 },
- { 0x2A, 8 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0xB, 4 },
- { 0xC, 4 },
- { 0x1C, 5 },
- { 0x37, 6 },
- { 0x17, 7 },
- { 0x2B, 8 },
- { 0x28, 8 },
- { 0xA4, 10 },
- { 0x52D, 13 },
- { 0x52C, 13 },
- { 0x52F, 13 },
- { 0x52E, 13 },
- { 0x0, 3 },
- { 0x1D, 5 },
- { 0x7, 5 },
- { 0x4, 5 },
- { 0x35, 6 },
- { 0x14, 5 },
- { 0x36, 6 },
- { 0x15, 5 },
- { 0x3C, 6 }
- },
- { /* AC bias group 3, table 5 */
- { 0x4, 3 },
- { 0xA, 4 },
- { 0x7, 5 },
- { 0x1D, 5 },
- { 0x9, 6 },
- { 0x1F3, 9 },
- { 0x7C7, 11 },
- { 0x8, 6 },
- { 0x1F0, 9 },
- { 0x3, 3 },
- { 0x2, 3 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x17, 5 },
- { 0x7D, 7 },
- { 0x1F2, 9 },
- { 0x7C6, 11 },
- { 0x7C5, 11 },
- { 0x1F12, 13 },
- { 0x3E27, 14 },
- { 0x3E26, 14 },
- { 0x1F11, 13 },
- { 0x1F10, 13 },
- { 0x0, 3 },
- { 0x1E, 5 },
- { 0x6, 5 },
- { 0x39, 6 },
- { 0x38, 6 },
- { 0x3F, 6 },
- { 0x2C, 6 },
- { 0x5, 5 },
- { 0x2D, 6 }
- },
- { /* AC bias group 3, table 6 */
- { 0x2, 3 },
- { 0x7, 4 },
- { 0x18, 5 },
- { 0x3, 4 },
- { 0x5, 5 },
- { 0x35, 7 },
- { 0x4F, 9 },
- { 0x12, 7 },
- { 0x4E5, 13 },
- { 0x5, 3 },
- { 0x4, 3 },
- { 0xD, 4 },
- { 0xE, 4 },
- { 0x33, 6 },
- { 0x26, 8 },
- { 0x9D, 10 },
- { 0x4E4, 13 },
- { 0x4E7, 13 },
- { 0x4E6, 13 },
- { 0x4E1, 13 },
- { 0x4E0, 13 },
- { 0x4E3, 13 },
- { 0x4E2, 13 },
- { 0x0, 3 },
- { 0x1F, 5 },
- { 0xC, 5 },
- { 0x3D, 6 },
- { 0x3C, 6 },
- { 0x32, 6 },
- { 0x34, 7 },
- { 0x1B, 6 },
- { 0x8, 6 }
- },
- { /* AC bias group 3, table 7 */
- { 0x0, 3 },
- { 0x4, 4 },
- { 0x1C, 5 },
- { 0xF, 4 },
- { 0x2, 4 },
- { 0x7, 5 },
- { 0x75, 7 },
- { 0xE8, 8 },
- { 0x1D2A, 13 },
- { 0x5, 3 },
- { 0x4, 3 },
- { 0xD, 4 },
- { 0xC, 4 },
- { 0x77, 7 },
- { 0xE96, 12 },
- { 0x3A57, 14 },
- { 0x3A56, 14 },
- { 0x3A5D, 14 },
- { 0x3A5C, 14 },
- { 0x3A5F, 14 },
- { 0x3A5E, 14 },
- { 0x1D29, 13 },
- { 0x1D28, 13 },
- { 0x3, 3 },
- { 0x6, 5 },
- { 0xA, 5 },
- { 0x2C, 7 },
- { 0x17, 6 },
- { 0x76, 7 },
- { 0x1D3, 9 },
- { 0x3A4, 10 },
- { 0x2D, 7 }
- },
- { /* AC bias group 3, table 8 */
- { 0xA, 4 },
- { 0x24, 6 },
- { 0xBF, 8 },
- { 0x85, 8 },
- { 0x211, 10 },
- { 0x842, 12 },
- { 0x1087, 13 },
- { 0x18, 5 },
- { 0x20, 6 },
- { 0x1, 3 },
- { 0x2, 3 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0x7, 4 },
- { 0x13, 5 },
- { 0x25, 6 },
- { 0x5E, 7 },
- { 0x43, 7 },
- { 0xBE, 8 },
- { 0x109, 9 },
- { 0x1086, 13 },
- { 0x841, 12 },
- { 0x840, 12 },
- { 0xF, 4 },
- { 0x1, 4 },
- { 0x11, 5 },
- { 0x0, 5 },
- { 0x2E, 6 },
- { 0x19, 5 },
- { 0x1, 5 },
- { 0x6, 4 },
- { 0x16, 5 }
- },
- { /* AC bias group 3, table 9 */
- { 0x2, 3 },
- { 0xF, 5 },
- { 0x6F, 7 },
- { 0x61, 7 },
- { 0x374, 10 },
- { 0x1BA8, 13 },
- { 0x3753, 14 },
- { 0x12, 5 },
- { 0x36, 6 },
- { 0x0, 3 },
- { 0x1, 3 },
- { 0xA, 4 },
- { 0xB, 4 },
- { 0x1A, 5 },
- { 0x31, 6 },
- { 0x60, 7 },
- { 0xDC, 8 },
- { 0x1BB, 9 },
- { 0x6EB, 11 },
- { 0x1BAB, 13 },
- { 0x3752, 14 },
- { 0x3755, 14 },
- { 0x3754, 14 },
- { 0xE, 4 },
- { 0x6, 4 },
- { 0x13, 5 },
- { 0xE, 5 },
- { 0x3E, 6 },
- { 0x8, 4 },
- { 0x1E, 5 },
- { 0x19, 5 },
- { 0x3F, 6 }
- },
- { /* AC bias group 3, table 10 */
- { 0x3, 3 },
- { 0x1C, 5 },
- { 0x25, 6 },
- { 0x24, 6 },
- { 0x1DA, 9 },
- { 0x1DBD, 13 },
- { 0x3B7C, 14 },
- { 0x3C, 6 },
- { 0x3D, 6 },
- { 0x0, 3 },
- { 0x1, 3 },
- { 0xB, 4 },
- { 0xA, 4 },
- { 0xB, 5 },
- { 0x77, 7 },
- { 0xEC, 8 },
- { 0x3B6, 10 },
- { 0x76E, 11 },
- { 0x1DBF, 13 },
- { 0x76FB, 15 },
- { 0x76FA, 15 },
- { 0x3B79, 14 },
- { 0x3B78, 14 },
- { 0xD, 4 },
- { 0x1F, 5 },
- { 0x13, 5 },
- { 0xA, 5 },
- { 0x8, 5 },
- { 0xC, 4 },
- { 0x8, 4 },
- { 0x9, 5 },
- { 0x3A, 6 }
- },
- { /* AC bias group 3, table 11 */
- { 0x5, 3 },
- { 0x3, 4 },
- { 0x4, 5 },
- { 0x10, 5 },
- { 0x8F, 8 },
- { 0x475, 11 },
- { 0x11D1, 13 },
- { 0x79, 7 },
- { 0x27, 6 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0x1, 4 },
- { 0x0, 4 },
- { 0x26, 6 },
- { 0x46, 7 },
- { 0x11C, 9 },
- { 0x477, 11 },
- { 0x8ED, 12 },
- { 0x11D0, 13 },
- { 0x11D3, 13 },
- { 0x11D2, 13 },
- { 0x11D9, 13 },
- { 0x11D8, 13 },
- { 0xD, 4 },
- { 0x1F, 5 },
- { 0x12, 5 },
- { 0x5, 5 },
- { 0x3D, 6 },
- { 0xC, 4 },
- { 0xE, 4 },
- { 0x22, 6 },
- { 0x78, 7 }
- },
- { /* AC bias group 3, table 12 */
- { 0x5, 3 },
- { 0xC, 4 },
- { 0x1B, 5 },
- { 0x0, 4 },
- { 0x6, 6 },
- { 0x3E2, 10 },
- { 0x3E3D, 14 },
- { 0xF, 7 },
- { 0x34, 6 },
- { 0x3, 3 },
- { 0x2, 3 },
- { 0x1E, 5 },
- { 0x1D, 5 },
- { 0x7D, 7 },
- { 0x1F0, 9 },
- { 0x7C6, 11 },
- { 0x3E3C, 14 },
- { 0x3E3F, 14 },
- { 0x3E3E, 14 },
- { 0x3E39, 14 },
- { 0x3E38, 14 },
- { 0x3E3B, 14 },
- { 0x3E3A, 14 },
- { 0x8, 4 },
- { 0x1C, 5 },
- { 0x2, 5 },
- { 0x3F, 6 },
- { 0x35, 6 },
- { 0x9, 4 },
- { 0x1, 3 },
- { 0xE, 7 },
- { 0xF9, 8 }
- },
- { /* AC bias group 3, table 13 */
- { 0x4, 3 },
- { 0xB, 4 },
- { 0x1, 4 },
- { 0xA, 4 },
- { 0x1E, 6 },
- { 0xE0, 9 },
- { 0xE1E, 13 },
- { 0x71, 8 },
- { 0x39, 7 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0xD, 5 },
- { 0xC, 5 },
- { 0x20, 7 },
- { 0x1C2, 10 },
- { 0x1C3F, 14 },
- { 0x1C3E, 14 },
- { 0xE19, 13 },
- { 0xE18, 13 },
- { 0xE1B, 13 },
- { 0xE1A, 13 },
- { 0xE1D, 13 },
- { 0xE1C, 13 },
- { 0x0, 4 },
- { 0x9, 5 },
- { 0x1D, 6 },
- { 0x1F, 6 },
- { 0x11, 6 },
- { 0x5, 4 },
- { 0x1, 3 },
- { 0x43, 8 },
- { 0x42, 8 }
- },
- { /* AC bias group 3, table 14 */
- { 0x4, 3 },
- { 0xD, 4 },
- { 0x7, 4 },
- { 0x2, 3 },
- { 0x14, 5 },
- { 0x16C, 9 },
- { 0x16D1, 13 },
- { 0x2DF, 10 },
- { 0x16E, 9 },
- { 0x0, 2 },
- { 0x7, 3 },
- { 0x2C, 6 },
- { 0x2B, 6 },
- { 0x2DE, 10 },
- { 0x16D0, 13 },
- { 0x16D3, 13 },
- { 0x16D2, 13 },
- { 0x2DB5, 14 },
- { 0x2DB4, 14 },
- { 0x2DB7, 14 },
- { 0x2DB6, 14 },
- { 0x16D9, 13 },
- { 0x16D8, 13 },
- { 0xC, 5 },
- { 0x2A, 6 },
- { 0x5A, 7 },
- { 0x1B, 6 },
- { 0x1A, 6 },
- { 0x17, 5 },
- { 0xC, 4 },
- { 0x5B7, 11 },
- { 0x5B5, 11 }
- },
- { /* AC bias group 3, table 15 */
- { 0x2, 2 },
- { 0xF, 4 },
- { 0x1C, 5 },
- { 0xC, 4 },
- { 0x3B, 6 },
- { 0x1AC, 9 },
- { 0x1AD8, 13 },
- { 0x35B3, 14 },
- { 0x35B2, 14 },
- { 0x1, 2 },
- { 0x0, 2 },
- { 0x69, 7 },
- { 0x68, 7 },
- { 0x35BD, 14 },
- { 0x35BC, 14 },
- { 0x35BF, 14 },
- { 0x35BE, 14 },
- { 0x35B9, 14 },
- { 0x35B8, 14 },
- { 0x35BB, 14 },
- { 0x35BA, 14 },
- { 0x35B5, 14 },
- { 0x35B4, 14 },
- { 0x1A9, 9 },
- { 0x1A8, 9 },
- { 0x35A, 10 },
- { 0xD7, 8 },
- { 0xD5, 8 },
- { 0x3A, 6 },
- { 0x1B, 5 },
- { 0x35B7, 14 },
- { 0x35B6, 14 }
- }
-};
-
-static const uint16_t ac_bias_3[16][32][2] = {
- { /* AC bias group 4, table 0 */
- { 0x0, 3 },
- { 0x10, 5 },
- { 0x72, 7 },
- { 0x71, 7 },
- { 0x154, 9 },
- { 0xAAB, 12 },
- { 0xAA8, 12 },
- { 0x14, 5 },
- { 0x70, 7 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0xC, 4 },
- { 0xB, 4 },
- { 0x3, 4 },
- { 0x11, 5 },
- { 0x73, 7 },
- { 0x54, 7 },
- { 0xAB, 8 },
- { 0x2AB, 10 },
- { 0x1553, 13 },
- { 0x1552, 13 },
- { 0x1555, 13 },
- { 0x1554, 13 },
- { 0xD, 4 },
- { 0x1E, 5 },
- { 0x12, 5 },
- { 0x3E, 6 },
- { 0x2B, 6 },
- { 0x2, 4 },
- { 0x3F, 6 },
- { 0x1D, 5 },
- { 0x13, 5 }
- },
- { /* AC bias group 4, table 1 */
- { 0x3, 3 },
- { 0x1F, 5 },
- { 0x29, 6 },
- { 0x3D, 6 },
- { 0xC, 7 },
- { 0x69, 10 },
- { 0x345, 13 },
- { 0x2, 5 },
- { 0x28, 6 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0xE, 4 },
- { 0xC, 4 },
- { 0x15, 5 },
- { 0x7, 6 },
- { 0x1B, 8 },
- { 0x6B, 10 },
- { 0x6A, 10 },
- { 0x344, 13 },
- { 0x347, 13 },
- { 0x346, 13 },
- { 0x1A1, 12 },
- { 0x1A0, 12 },
- { 0xB, 4 },
- { 0x1A, 5 },
- { 0x12, 5 },
- { 0x0, 5 },
- { 0x3C, 6 },
- { 0x8, 4 },
- { 0x1B, 5 },
- { 0x13, 5 },
- { 0x1, 5 }
- },
- { /* AC bias group 4, table 2 */
- { 0x4, 3 },
- { 0x4, 4 },
- { 0x3F, 6 },
- { 0x14, 5 },
- { 0x56, 7 },
- { 0x15C, 9 },
- { 0x15D5, 13 },
- { 0x3C, 6 },
- { 0x2A, 6 },
- { 0x0, 3 },
- { 0x1, 3 },
- { 0xE, 4 },
- { 0xD, 4 },
- { 0xC, 5 },
- { 0xAF, 8 },
- { 0x2BB, 10 },
- { 0x15D4, 13 },
- { 0x15D7, 13 },
- { 0x15D6, 13 },
- { 0x15D1, 13 },
- { 0x15D0, 13 },
- { 0x15D3, 13 },
- { 0x15D2, 13 },
- { 0xB, 4 },
- { 0x19, 5 },
- { 0xD, 5 },
- { 0x3E, 6 },
- { 0x31, 6 },
- { 0x7, 4 },
- { 0x5, 4 },
- { 0x3D, 6 },
- { 0x30, 6 }
- },
- { /* AC bias group 4, table 3 */
- { 0x5, 3 },
- { 0x8, 4 },
- { 0x1A, 5 },
- { 0x0, 4 },
- { 0x36, 6 },
- { 0x11, 8 },
- { 0x106, 12 },
- { 0xA, 7 },
- { 0x6E, 7 },
- { 0x2, 3 },
- { 0x3, 3 },
- { 0x3, 4 },
- { 0x2, 4 },
- { 0x6F, 7 },
- { 0x21, 9 },
- { 0x20F, 13 },
- { 0x20E, 13 },
- { 0x101, 12 },
- { 0x100, 12 },
- { 0x103, 12 },
- { 0x102, 12 },
- { 0x105, 12 },
- { 0x104, 12 },
- { 0xC, 4 },
- { 0x1E, 5 },
- { 0x3, 5 },
- { 0x3E, 6 },
- { 0x3F, 6 },
- { 0x9, 4 },
- { 0xE, 4 },
- { 0xB, 7 },
- { 0x9, 7 }
- },
- { /* AC bias group 4, table 4 */
- { 0x2, 3 },
- { 0xE, 4 },
- { 0x1E, 5 },
- { 0xC, 4 },
- { 0x1F, 5 },
- { 0x6E, 7 },
- { 0xAD, 10 },
- { 0xAF, 10 },
- { 0x14, 7 },
- { 0x4, 3 },
- { 0x3, 3 },
- { 0x1A, 5 },
- { 0x17, 5 },
- { 0x2A, 8 },
- { 0x576, 13 },
- { 0xAEF, 14 },
- { 0xAEE, 14 },
- { 0x571, 13 },
- { 0x570, 13 },
- { 0x573, 13 },
- { 0x572, 13 },
- { 0x575, 13 },
- { 0x574, 13 },
- { 0x3, 4 },
- { 0x16, 5 },
- { 0x4, 5 },
- { 0x36, 6 },
- { 0xB, 6 },
- { 0xA, 4 },
- { 0x0, 3 },
- { 0x6F, 7 },
- { 0xAC, 10 }
- },
- { /* AC bias group 4, table 5 */
- { 0x4, 3 },
- { 0x5, 4 },
- { 0x3, 3 },
- { 0x1, 3 },
- { 0x4, 4 },
- { 0x2F, 6 },
- { 0x526, 11 },
- { 0x1495, 13 },
- { 0xA6, 8 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x2D, 6 },
- { 0x2C, 6 },
- { 0x1494, 13 },
- { 0x1497, 13 },
- { 0x1496, 13 },
- { 0x1491, 13 },
- { 0x1490, 13 },
- { 0x1493, 13 },
- { 0x1492, 13 },
- { 0x293D, 14 },
- { 0x293C, 14 },
- { 0x293F, 14 },
- { 0x0, 3 },
- { 0x28, 6 },
- { 0xA5, 8 },
- { 0x148, 9 },
- { 0xA7, 8 },
- { 0x2E, 6 },
- { 0x15, 5 },
- { 0xA4E, 12 },
- { 0x293E, 14 }
- },
- { /* AC bias group 4, table 6 */
- { 0x4, 3 },
- { 0x5, 4 },
- { 0x3, 3 },
- { 0x1, 3 },
- { 0x4, 4 },
- { 0x2F, 6 },
- { 0x526, 11 },
- { 0x1495, 13 },
- { 0xA6, 8 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x2D, 6 },
- { 0x2C, 6 },
- { 0x1494, 13 },
- { 0x1497, 13 },
- { 0x1496, 13 },
- { 0x1491, 13 },
- { 0x1490, 13 },
- { 0x1493, 13 },
- { 0x1492, 13 },
- { 0x293D, 14 },
- { 0x293C, 14 },
- { 0x293F, 14 },
- { 0x0, 3 },
- { 0x28, 6 },
- { 0xA5, 8 },
- { 0x148, 9 },
- { 0xA7, 8 },
- { 0x2E, 6 },
- { 0x15, 5 },
- { 0xA4E, 12 },
- { 0x293E, 14 }
- },
- { /* AC bias group 4, table 7 */
- { 0x4, 3 },
- { 0x5, 4 },
- { 0x3, 3 },
- { 0x1, 3 },
- { 0x4, 4 },
- { 0x2F, 6 },
- { 0x526, 11 },
- { 0x1495, 13 },
- { 0xA6, 8 },
- { 0x7, 3 },
- { 0x6, 3 },
- { 0x2D, 6 },
- { 0x2C, 6 },
- { 0x1494, 13 },
- { 0x1497, 13 },
- { 0x1496, 13 },
- { 0x1491, 13 },
- { 0x1490, 13 },
- { 0x1493, 13 },
- { 0x1492, 13 },
- { 0x293D, 14 },
- { 0x293C, 14 },
- { 0x293F, 14 },
- { 0x0, 3 },
- { 0x28, 6 },
- { 0xA5, 8 },
- { 0x148, 9 },
- { 0xA7, 8 },
- { 0x2E, 6 },
- { 0x15, 5 },
- { 0xA4E, 12 },
- { 0x293E, 14 }
- },
- { /* AC bias group 4, table 8 */
- { 0x3, 3 },
- { 0x11, 5 },
- { 0x20, 6 },
- { 0x74, 7 },
- { 0x10D, 9 },
- { 0x863, 12 },
- { 0x860, 12 },
- { 0xA, 5 },
- { 0x75, 7 },
- { 0x1, 3 },
- { 0x0, 3 },
- { 0xB, 4 },
- { 0xA, 4 },
- { 0x18, 5 },
- { 0x38, 6 },
- { 0x42, 7 },
- { 0x10F, 9 },
- { 0x10E, 9 },
- { 0x219, 10 },
- { 0x10C3, 13 },
- { 0x10C2, 13 },
- { 0x10C5, 13 },
- { 0x10C4, 13 },
- { 0xF, 4 },
- { 0x4, 4 },
- { 0x19, 5 },
- { 0xB, 5 },
- { 0x39, 6 },
- { 0x9, 4 },
- { 0x1B, 5 },
- { 0x1A, 5 },
- { 0x3B, 6 }
- },
- { /* AC bias group 4, table 9 */
- { 0x5, 3 },
- { 0x1, 4 },
- { 0x3E, 6 },
- { 0x1, 5 },
- { 0xE2, 8 },
- { 0x1C6F, 13 },
- { 0x38D9, 14 },
- { 0x39, 6 },
- { 0x1F, 6 },
- { 0x2, 3 },
- { 0x1, 3 },
- { 0x9, 4 },
- { 0x8, 4 },
- { 0x0, 5 },
- { 0x70, 7 },
- { 0x1C7, 9 },
- { 0x38C, 10 },
- { 0x71A, 11 },
- { 0x38D8, 14 },
- { 0x38DB, 14 },
- { 0x38DA, 14 },
- { 0x38DD, 14 },
- { 0x38DC, 14 },
- { 0xD, 4 },
- { 0x1D, 5 },
- { 0xE, 5 },
- { 0x3F, 6 },
- { 0x3C, 6 },
- { 0xC, 4 },
- { 0x6, 4 },
- { 0x3D, 6 },
- { 0x1E, 6 }
- },
- { /* AC bias group 4, table 10 */
- { 0x6, 3 },
- { 0xB, 4 },
- { 0x11, 5 },
- { 0x1E, 5 },
- { 0x74, 7 },
- { 0x3AA, 10 },
- { 0x1D5C, 13 },
- { 0x1, 6 },
- { 0x21, 6 },
- { 0x1, 3 },
- { 0x2, 3 },
- { 0x7, 4 },
- { 0x6, 4 },
- { 0x3E, 6 },
- { 0xEB, 8 },
- { 0x1D4, 9 },
- { 0xEAF, 12 },
- { 0x3ABB, 14 },
- { 0x3ABA, 14 },
- { 0x1D59, 13 },
- { 0x1D58, 13 },
- { 0x1D5B, 13 },
- { 0x1D5A, 13 },
- { 0xA, 4 },
- { 0x1C, 5 },
- { 0x1, 5 },
- { 0x3F, 6 },
- { 0x3B, 6 },
- { 0x1, 4 },
- { 0x9, 4 },
- { 0x20, 6 },
- { 0x0, 6 }
- },
- { /* AC bias group 4, table 11 */
- { 0x4, 3 },
- { 0xA, 4 },
- { 0x17, 5 },
- { 0x4, 4 },
- { 0x16, 6 },
- { 0x16A, 9 },
- { 0x16B1, 13 },
- { 0x17, 7 },
- { 0x5B, 7 },
- { 0x6, 3 },
- { 0x7, 3 },
- { 0x1, 4 },
- { 0x0, 4 },
- { 0xA, 6 },
- { 0x2D7, 10 },
- { 0xB5A, 12 },
- { 0x16B0, 13 },
- { 0x16B3, 13 },
- { 0x16B2, 13 },
- { 0x2D6D, 14 },
- { 0x2D6C, 14 },
- { 0x2D6F, 14 },
- { 0x2D6E, 14 },
- { 0x6, 4 },
- { 0xA, 5 },
- { 0x4, 5 },
- { 0x2C, 6 },
- { 0x17, 6 },
- { 0x3, 4 },
- { 0x7, 4 },
- { 0x16, 7 },
- { 0xB4, 8 }
- },
- { /* AC bias group 4, table 12 */
- { 0x5, 3 },
- { 0xD, 4 },
- { 0x5, 4 },
- { 0x9, 4 },
- { 0x33, 6 },
- { 0x193, 9 },
- { 0x192C, 13 },
- { 0x61, 8 },
- { 0x31, 7 },
- { 0x0, 2 },
- { 0x7, 3 },
- { 0x10, 5 },
- { 0x11, 5 },
- { 0xC8, 8 },
- { 0x192F, 13 },
- { 0x325B, 14 },
- { 0x325A, 14 },
- { 0x1929, 13 },
- { 0x1928, 13 },
- { 0x192B, 13 },
- { 0x192A, 13 },
- { 0x325D, 14 },
- { 0x325C, 14 },
- { 0x18, 5 },
- { 0x1A, 6 },
- { 0x1B, 6 },
- { 0x65, 7 },
- { 0x19, 6 },
- { 0x4, 4 },
- { 0x7, 4 },
- { 0x60, 8 },
- { 0x324, 10 }
- },
- { /* AC bias group 4, table 13 */
- { 0x6, 3 },
- { 0x0, 3 },
- { 0x2, 4 },
- { 0xF, 4 },
- { 0x39, 6 },
- { 0x1D9, 9 },
- { 0x1D82, 13 },
- { 0x761, 11 },
- { 0x3BE, 10 },
- { 0x1, 2 },
- { 0x2, 2 },
- { 0xF, 6 },
- { 0xE, 6 },
- { 0x762, 11 },
- { 0x3B07, 14 },
- { 0x3B06, 14 },
- { 0x3B1D, 14 },
- { 0x3B1C, 14 },
- { 0x3B1F, 14 },
- { 0x3B1E, 14 },
- { 0x3B19, 14 },
- { 0x3B18, 14 },
- { 0x3B1B, 14 },
- { 0x38, 6 },
- { 0x1DE, 9 },
- { 0xED, 8 },
- { 0x3BF, 10 },
- { 0xEE, 8 },
- { 0x3A, 6 },
- { 0x6, 5 },
- { 0xEC0, 12 },
- { 0x3B1A, 14 }
- },
- { /* AC bias group 4, table 14 */
- { 0x0, 2 },
- { 0x2, 3 },
- { 0xF, 5 },
- { 0x6, 4 },
- { 0x1C, 6 },
- { 0x1D0, 10 },
- { 0xE8C, 13 },
- { 0x1D1B, 14 },
- { 0x1D1A, 14 },
- { 0x3, 2 },
- { 0x2, 2 },
- { 0xEA, 9 },
- { 0xE9, 9 },
- { 0xE89, 13 },
- { 0xE88, 13 },
- { 0xE8B, 13 },
- { 0xE8A, 13 },
- { 0x1D65, 14 },
- { 0x1D64, 14 },
- { 0x1D67, 14 },
- { 0x1D66, 14 },
- { 0x1D61, 14 },
- { 0x1D60, 14 },
- { 0x3AD, 11 },
- { 0x1D63, 14 },
- { 0x1D62, 14 },
- { 0x1D1D, 14 },
- { 0x1D1C, 14 },
- { 0x3B, 7 },
- { 0x1D7, 10 },
- { 0x1D1F, 14 },
- { 0x1D1E, 14 }
- },
- { /* AC bias group 4, table 15 */
- { 0x2, 2 },
- { 0xF, 4 },
- { 0x1C, 5 },
- { 0xC, 4 },
- { 0x3B, 6 },
- { 0x1AC, 9 },
- { 0x1AD8, 13 },
- { 0x35B3, 14 },
- { 0x35B2, 14 },
- { 0x1, 2 },
- { 0x0, 2 },
- { 0x69, 7 },
- { 0x68, 7 },
- { 0x35BD, 14 },
- { 0x35BC, 14 },
- { 0x35BF, 14 },
- { 0x35BE, 14 },
- { 0x35B9, 14 },
- { 0x35B8, 14 },
- { 0x35BB, 14 },
- { 0x35BA, 14 },
- { 0x35B5, 14 },
- { 0x35B4, 14 },
- { 0x1A9, 9 },
- { 0x1A8, 9 },
- { 0x35A, 10 },
- { 0xD7, 8 },
- { 0xD5, 8 },
- { 0x3A, 6 },
- { 0x1B, 5 },
- { 0x35B7, 14 },
- { 0x35B6, 14 }
- }
-};
-
-#endif /* VP3DATA_H */
+++ /dev/null
-/**
- * @file wmadata.h
- * Various WMA tables.
- */
-
-static const uint16_t wma_critical_freqs[25] = {
- 100, 200, 300, 400, 510, 630, 770, 920,
- 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150,
- 3700, 4400, 5300, 6400, 7700, 9500, 12000, 15500,
- 24500,
-};
-
-/* first value is number of bands */
-static const uint8_t exponent_band_22050[3][25] = {
- { 10, 4, 8, 4, 8, 8, 12, 20, 24, 24, 16, },
- { 14, 4, 8, 8, 4, 12, 12, 16, 24, 16, 20, 24, 32, 40, 36, },
- { 23, 4, 4, 4, 8, 4, 4, 8, 8, 8, 8, 8, 12, 12, 16, 16, 24, 24, 32, 44, 48, 60, 84, 72, },
-};
-
-static const uint8_t exponent_band_32000[3][25] = {
- { 11, 4, 4, 8, 4, 4, 12, 16, 24, 20, 28, 4, },
- { 15, 4, 8, 4, 4, 8, 8, 16, 20, 12, 20, 20, 28, 40, 56, 8, },
- { 16, 8, 4, 8, 8, 12, 16, 20, 24, 40, 32, 32, 44, 56, 80, 112, 16, },
-};
-
-static const uint8_t exponent_band_44100[3][25] = {
- { 12, 4, 4, 4, 4, 4, 8, 8, 8, 12, 16, 20, 36, },
- { 15, 4, 8, 4, 8, 8, 4, 8, 8, 12, 12, 12, 24, 28, 40, 76, },
- { 17, 4, 8, 8, 4, 12, 12, 8, 8, 24, 16, 20, 24, 32, 40, 60, 80, 152, },
-};
-
-static const uint16_t hgain_huffcodes[37] = {
- 0x00003, 0x002e7, 0x00001, 0x005cd, 0x0005d, 0x005c9, 0x0005e, 0x00003,
- 0x00016, 0x0000b, 0x00001, 0x00006, 0x00001, 0x00006, 0x00004, 0x00005,
- 0x00004, 0x00007, 0x00003, 0x00007, 0x00004, 0x0000a, 0x0000a, 0x00002,
- 0x00003, 0x00000, 0x00005, 0x00002, 0x0005f, 0x00004, 0x00003, 0x00002,
- 0x005c8, 0x000b8, 0x005ca, 0x005cb, 0x005cc,
-};
-
-static const uint8_t hgain_huffbits[37] = {
- 10, 12, 10, 13, 9, 13, 9, 8,
- 7, 5, 5, 4, 4, 3, 3, 3,
- 4, 3, 4, 4, 5, 5, 6, 8,
- 7, 10, 8, 10, 9, 8, 9, 9,
- 13, 10, 13, 13, 13,
-};
-
-static const float lsp_codebook[NB_LSP_COEFS][16] = {
- { 1.98732877, 1.97944528, 1.97179088, 1.96260549, 1.95038374, 1.93336114, 1.90719232, 1.86191415, },
- { 1.97260000, 1.96083160, 1.94982586, 1.93806164, 1.92516608, 1.91010199, 1.89232331, 1.87149812,
- 1.84564818, 1.81358067, 1.77620070, 1.73265264, 1.67907855, 1.60959081, 1.50829650, 1.33120330, },
- { 1.90109110, 1.86482426, 1.83419671, 1.80168452, 1.76650116, 1.72816320, 1.68502700, 1.63738256,
- 1.58501580, 1.51795181, 1.43679906, 1.33950585, 1.24176208, 1.12260729, 0.96749668, 0.74048265, },
- { 1.76943864, 1.67822463, 1.59946365, 1.53560582, 1.47470796, 1.41210167, 1.34509536, 1.27339507,
- 1.19303814, 1.09765169, 0.98818722, 0.87239446, 0.74369172, 0.59768184, 0.43168630, 0.17977021, },
- { 1.43428349, 1.32038354, 1.21074086, 1.10577988, 1.00561746, 0.90335924, 0.80437489, 0.70709671,
- 0.60427395, 0.49814048, 0.38509539, 0.27106800, 0.14407416, 0.00219910, -0.16725141, -0.36936085, },
- { 0.99895687, 0.84188166, 0.70753739, 0.57906595, 0.47055563, 0.36966965, 0.26826648, 0.17163380,
- 0.07208392, -0.03062936, -1.40037388, -0.25128968, -0.37213937, -0.51075646, -0.64887512, -0.80308031, },
- { 0.26515280, 0.06313551, -0.08872080, -0.21103548, -0.31069678, -0.39680323, -0.47223474, -0.54167135,
- -0.61444740, -0.68943343, -0.76580211, -0.85170082, -0.95289061, -1.06514703, -1.20510707, -1.37617746, },
- { -0.53940301, -0.73770929, -0.88424876, -1.01117930, -1.13389091, -1.26830073, -1.42041987, -1.62033919,
- -1.10158808, -1.16512566, -1.23337128, -1.30414401, -1.37663312, -1.46853845, -1.57625798, -1.66893638, },
- { -0.38601997, -0.56009350, -0.66978483, -0.76028471, -0.83846064, -0.90868087, -0.97408881, -1.03694962, },
- { -1.56144989, -1.65944032, -1.72689685, -1.77857740, -1.82203011, -1.86220079, -1.90283983, -1.94820479, },
-};
-
-static const uint32_t scale_huffcodes[121] = {
- 0x3ffe8, 0x3ffe6, 0x3ffe7, 0x3ffe5, 0x7fff5, 0x7fff1, 0x7ffed, 0x7fff6,
- 0x7ffee, 0x7ffef, 0x7fff0, 0x7fffc, 0x7fffd, 0x7ffff, 0x7fffe, 0x7fff7,
- 0x7fff8, 0x7fffb, 0x7fff9, 0x3ffe4, 0x7fffa, 0x3ffe3, 0x1ffef, 0x1fff0,
- 0x0fff5, 0x1ffee, 0x0fff2, 0x0fff3, 0x0fff4, 0x0fff1, 0x07ff6, 0x07ff7,
- 0x03ff9, 0x03ff5, 0x03ff7, 0x03ff3, 0x03ff6, 0x03ff2, 0x01ff7, 0x01ff5,
- 0x00ff9, 0x00ff7, 0x00ff6, 0x007f9, 0x00ff4, 0x007f8, 0x003f9, 0x003f7,
- 0x003f5, 0x001f8, 0x001f7, 0x000fa, 0x000f8, 0x000f6, 0x00079, 0x0003a,
- 0x00038, 0x0001a, 0x0000b, 0x00004, 0x00000, 0x0000a, 0x0000c, 0x0001b,
- 0x00039, 0x0003b, 0x00078, 0x0007a, 0x000f7, 0x000f9, 0x001f6, 0x001f9,
- 0x003f4, 0x003f6, 0x003f8, 0x007f5, 0x007f4, 0x007f6, 0x007f7, 0x00ff5,
- 0x00ff8, 0x01ff4, 0x01ff6, 0x01ff8, 0x03ff8, 0x03ff4, 0x0fff0, 0x07ff4,
- 0x0fff6, 0x07ff5, 0x3ffe2, 0x7ffd9, 0x7ffda, 0x7ffdb, 0x7ffdc, 0x7ffdd,
- 0x7ffde, 0x7ffd8, 0x7ffd2, 0x7ffd3, 0x7ffd4, 0x7ffd5, 0x7ffd6, 0x7fff2,
- 0x7ffdf, 0x7ffe7, 0x7ffe8, 0x7ffe9, 0x7ffea, 0x7ffeb, 0x7ffe6, 0x7ffe0,
- 0x7ffe1, 0x7ffe2, 0x7ffe3, 0x7ffe4, 0x7ffe5, 0x7ffd7, 0x7ffec, 0x7fff4,
- 0x7fff3,
-};
-
-static const uint8_t scale_huffbits[121] = {
- 18, 18, 18, 18, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 18, 19, 18, 17, 17,
- 16, 17, 16, 16, 16, 16, 15, 15,
- 14, 14, 14, 14, 14, 14, 13, 13,
- 12, 12, 12, 11, 12, 11, 10, 10,
- 10, 9, 9, 8, 8, 8, 7, 6,
- 6, 5, 4, 3, 1, 4, 4, 5,
- 6, 6, 7, 7, 8, 8, 9, 9,
- 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 13, 13, 13, 14, 14, 16, 15,
- 16, 15, 18, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 19,
-};
-
-static const uint32_t coef0_huffcodes[666] = {
- 0x00258, 0x0003d, 0x00000, 0x00005, 0x00008, 0x00008, 0x0000c, 0x0001b,
- 0x0001f, 0x00015, 0x00024, 0x00032, 0x0003a, 0x00026, 0x0002c, 0x0002f,
- 0x0004a, 0x0004d, 0x00061, 0x00070, 0x00073, 0x00048, 0x00052, 0x0005a,
- 0x0005d, 0x0006e, 0x00099, 0x0009e, 0x000c1, 0x000ce, 0x000e4, 0x000f0,
- 0x00093, 0x0009e, 0x000a2, 0x000a1, 0x000b8, 0x000d2, 0x000d3, 0x0012e,
- 0x00130, 0x000de, 0x0012d, 0x0019b, 0x001e4, 0x00139, 0x0013a, 0x0013f,
- 0x0014f, 0x0016d, 0x001a2, 0x0027c, 0x0027e, 0x00332, 0x0033c, 0x0033f,
- 0x0038b, 0x00396, 0x003c5, 0x00270, 0x0027c, 0x0025a, 0x00395, 0x00248,
- 0x004bd, 0x004fb, 0x00662, 0x00661, 0x0071b, 0x004e6, 0x004ff, 0x00666,
- 0x0071c, 0x0071a, 0x0071f, 0x00794, 0x00536, 0x004e2, 0x0078e, 0x004ee,
- 0x00518, 0x00535, 0x004fb, 0x0078d, 0x00530, 0x00680, 0x0068f, 0x005cb,
- 0x00965, 0x006a6, 0x00967, 0x0097f, 0x00682, 0x006ae, 0x00cd0, 0x00e28,
- 0x00f13, 0x00f1f, 0x009f5, 0x00cd3, 0x00f11, 0x00926, 0x00964, 0x00f32,
- 0x00f12, 0x00f30, 0x00966, 0x00d0b, 0x00a68, 0x00b91, 0x009c7, 0x00b73,
- 0x012fa, 0x0131d, 0x013f9, 0x01ca0, 0x0199c, 0x01c7a, 0x0198c, 0x01248,
- 0x01c74, 0x01c64, 0x0139e, 0x012fd, 0x00a77, 0x012fc, 0x01c7b, 0x012ca,
- 0x014cc, 0x014d2, 0x014e3, 0x014dc, 0x012dc, 0x03344, 0x02598, 0x0263c,
- 0x0333b, 0x025e6, 0x01a1c, 0x01e3c, 0x014e2, 0x033d4, 0x01a11, 0x03349,
- 0x03cce, 0x014e1, 0x01a34, 0x0273e, 0x02627, 0x0273f, 0x038ee, 0x03971,
- 0x03c67, 0x03c61, 0x0333d, 0x038c2, 0x0263f, 0x038cd, 0x02638, 0x02e41,
- 0x0351f, 0x03348, 0x03c66, 0x03562, 0x02989, 0x027d5, 0x0333c, 0x02e4f,
- 0x0343b, 0x02ddf, 0x04bc8, 0x029c0, 0x02e57, 0x04c72, 0x025b7, 0x03547,
- 0x03540, 0x029d3, 0x04c45, 0x025bb, 0x06600, 0x04c73, 0x04bce, 0x0357b,
- 0x029a6, 0x029d2, 0x0263e, 0x0298a, 0x07183, 0x06602, 0x07958, 0x04b66,
- 0x0537d, 0x05375, 0x04fe9, 0x04b67, 0x0799f, 0x04bc9, 0x051fe, 0x06a3b,
- 0x05bb6, 0x04fa8, 0x0728f, 0x05376, 0x0492c, 0x0537e, 0x0795a, 0x06a3c,
- 0x0e515, 0x07887, 0x0683a, 0x051f9, 0x051fd, 0x0cc6a, 0x06a8a, 0x0cc6d,
- 0x05bb3, 0x0683b, 0x051fc, 0x05378, 0x0728e, 0x07886, 0x05bb7, 0x0f2a4,
- 0x0795b, 0x0683c, 0x09fc1, 0x0683d, 0x0b752, 0x09678, 0x0a3e8, 0x06ac7,
- 0x051f0, 0x0b759, 0x06af3, 0x04b6b, 0x0f2a0, 0x0f2ad, 0x096c3, 0x0e518,
- 0x0b75c, 0x0d458, 0x0cc6b, 0x0537c, 0x067aa, 0x04fea, 0x0343a, 0x0cc71,
- 0x0967f, 0x09fc4, 0x096c2, 0x0e516, 0x0f2a1, 0x0d45c, 0x0d45d, 0x0d45e,
- 0x12fb9, 0x0967e, 0x1982f, 0x09883, 0x096c4, 0x0b753, 0x12fb8, 0x0f2a8,
- 0x1ca21, 0x096c5, 0x0e51a, 0x1ca27, 0x12f3c, 0x0d471, 0x0f2aa, 0x0b75b,
- 0x12fbb, 0x0f2a9, 0x0f2ac, 0x0d45a, 0x0b74f, 0x096c8, 0x16e91, 0x096ca,
- 0x12fbf, 0x0d0a7, 0x13103, 0x0d516, 0x16e99, 0x12cbd, 0x0a3ea, 0x19829,
- 0x0b755, 0x29ba7, 0x1ca28, 0x29ba5, 0x16e93, 0x1982c, 0x19828, 0x25994,
- 0x0a3eb, 0x1ca29, 0x16e90, 0x1ca25, 0x1982d, 0x1ca26, 0x16e9b, 0x0b756,
- 0x0967c, 0x25997, 0x0b75f, 0x198d3, 0x0b757, 0x19a2a, 0x0d45b, 0x0e517,
- 0x1ca24, 0x1ca23, 0x1ca22, 0x0b758, 0x16e97, 0x0cd14, 0x13100, 0x00007,
- 0x0003b, 0x0006b, 0x00097, 0x00138, 0x00125, 0x00173, 0x00258, 0x00335,
- 0x0028e, 0x004c6, 0x00715, 0x00729, 0x004ef, 0x00519, 0x004ed, 0x00532,
- 0x0068c, 0x00686, 0x00978, 0x00e5d, 0x00e31, 0x009f4, 0x00b92, 0x012f8,
- 0x00d06, 0x00a67, 0x00d44, 0x00a76, 0x00d59, 0x012cd, 0x01c78, 0x01c75,
- 0x0199f, 0x0198f, 0x01c67, 0x014c6, 0x01c79, 0x01c76, 0x00b94, 0x00d1b,
- 0x01e32, 0x01e31, 0x01ab0, 0x01a05, 0x01aa1, 0x0333a, 0x025e5, 0x02626,
- 0x03541, 0x03544, 0x03421, 0x03546, 0x02e55, 0x02e56, 0x0492d, 0x02dde,
- 0x0299b, 0x02ddc, 0x0357a, 0x0249c, 0x0668b, 0x1c77f, 0x1ca20, 0x0d45f,
- 0x09886, 0x16e9a, 0x0f2a7, 0x0b751, 0x0a3ee, 0x0cf59, 0x0cf57, 0x0b754,
- 0x0d0a6, 0x16e98, 0x0b760, 0x06ac6, 0x0a3f0, 0x12fbe, 0x13104, 0x0f2a5,
- 0x0a3ef, 0x0d472, 0x12cba, 0x1982e, 0x16e9c, 0x1c77e, 0x198d0, 0x13105,
- 0x16e92, 0x0b75d, 0x0d459, 0x0001a, 0x000c0, 0x0016c, 0x003cd, 0x00350,
- 0x0067b, 0x0051e, 0x006a9, 0x009f4, 0x00b72, 0x00d09, 0x01249, 0x01e3d,
- 0x01ca1, 0x01a1f, 0x01721, 0x01a8a, 0x016e8, 0x03347, 0x01a35, 0x0249d,
- 0x0299a, 0x02596, 0x02e4e, 0x0298b, 0x07182, 0x04c46, 0x025ba, 0x02e40,
- 0x027d6, 0x04fe8, 0x06607, 0x05310, 0x09884, 0x072e1, 0x06a3d, 0x04b6a,
- 0x04c7a, 0x06603, 0x04c7b, 0x03428, 0x06605, 0x09664, 0x09fc0, 0x071de,
- 0x06601, 0x05bb2, 0x09885, 0x0a3e2, 0x1c61f, 0x12cbb, 0x0b750, 0x0cf58,
- 0x0967d, 0x25995, 0x668ad, 0x0b75a, 0x09fc2, 0x0537f, 0x0b75e, 0x13fae,
- 0x12fbc, 0x00031, 0x001c4, 0x004c5, 0x005b8, 0x00cf4, 0x0096f, 0x00d46,
- 0x01e57, 0x01a04, 0x02625, 0x03346, 0x028f9, 0x04c47, 0x072e0, 0x04b69,
- 0x03420, 0x07957, 0x06639, 0x0799e, 0x07959, 0x07881, 0x04b68, 0x09fc3,
- 0x09fd6, 0x0cc70, 0x0a3f1, 0x12cbe, 0x0e30e, 0x0e51b, 0x06af2, 0x12cbc,
- 0x1c77d, 0x0f2ab, 0x12fbd, 0x1aa2f, 0x0a3ec, 0x0d473, 0x05377, 0x0a3e9,
- 0x1982b, 0x0e300, 0x12f3f, 0x0cf5f, 0x096c0, 0x38c3c, 0x16e94, 0x16e95,
- 0x12f3d, 0x29ba4, 0x29ba6, 0x1c77c, 0x6a8ba, 0x3545c, 0x33457, 0x668ac,
- 0x6a8bb, 0x16e9d, 0x0e519, 0x25996, 0x12f3e, 0x00036, 0x0033e, 0x006ad,
- 0x00d03, 0x012c8, 0x0124a, 0x03c42, 0x03ccd, 0x06606, 0x07880, 0x06852,
- 0x06a3a, 0x05bb4, 0x0f2a2, 0x09fc7, 0x12cb9, 0x0cc6c, 0x0a6e8, 0x096c1,
- 0x0004a, 0x00355, 0x012f9, 0x014e8, 0x01abe, 0x025b6, 0x0492e, 0x09fc6,
- 0x051ff, 0x0cc6f, 0x096cb, 0x0d071, 0x198d1, 0x12cb8, 0x38c3d, 0x13faf,
- 0x096c9, 0x0009d, 0x00539, 0x012ce, 0x0341f, 0x029c1, 0x04b33, 0x0a3e3,
- 0x0d070, 0x16e96, 0x0b763, 0x000a0, 0x009ce, 0x038cc, 0x0343d, 0x051fa,
- 0x09888, 0x12fba, 0x000df, 0x00a75, 0x029a7, 0x09fc5, 0x0e301, 0x0967b,
- 0x001e7, 0x012c9, 0x051fb, 0x09889, 0x0f2a6, 0x0016f, 0x01cb9, 0x0cf5a,
- 0x12cbf, 0x09679, 0x00272, 0x01a15, 0x0967a, 0x003cb, 0x025f6, 0x0b762,
- 0x0028d, 0x03c60, 0x0cf5e, 0x00352, 0x03ccc, 0x0072f, 0x07186, 0x004ec,
- 0x05379, 0x0068e, 0x09887, 0x006a7, 0x06af1, 0x00e29, 0x0cf5b, 0x00f31,
- 0x0d470, 0x009c6, 0x013fb, 0x13102, 0x019a5, 0x13101, 0x01983, 0x01c65,
- 0x0124f, 0x014c7, 0x01726, 0x01abf, 0x03304, 0x02624, 0x03c41, 0x027d7,
- 0x02ddd, 0x02e54, 0x0343c, 0x06604, 0x07181, 0x0663a, 0x04fa9, 0x0663b,
- 0x05311, 0x0537a, 0x06839, 0x05bb5, 0x0492f, 0x06af0, 0x096c7, 0x0cc6e,
- 0x0537b, 0x0cf5c, 0x0cf56, 0x198d2, 0x0cf5d, 0x0a3ed, 0x0f2a3, 0x1982a,
- 0x0b761, 0x096c6,
-};
-
-static const uint8_t coef0_huffbits[666] = {
- 11, 6, 2, 3, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 7, 7, 7,
- 7, 7, 7, 7, 7, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 9, 9, 9, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 10, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 12, 12, 11, 12,
- 12, 12, 12, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 13, 13, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 13, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 14, 14, 15, 15, 15, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 14, 15, 15, 15, 15, 16,
- 16, 16, 15, 16, 15, 15, 16, 16,
- 16, 16, 15, 16, 16, 16, 15, 16,
- 16, 15, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 15, 15, 16, 16,
- 15, 16, 16, 16, 17, 17, 17, 16,
- 16, 17, 16, 16, 16, 16, 17, 16,
- 17, 17, 16, 16, 15, 15, 15, 16,
- 17, 16, 17, 16, 16, 17, 17, 17,
- 17, 17, 17, 16, 17, 17, 17, 16,
- 17, 17, 16, 17, 17, 17, 16, 17,
- 17, 16, 16, 17, 17, 17, 18, 17,
- 17, 17, 17, 17, 18, 18, 17, 17,
- 17, 19, 17, 19, 18, 17, 17, 18,
- 17, 17, 18, 17, 17, 17, 18, 17,
- 17, 18, 17, 17, 17, 17, 17, 16,
- 17, 17, 17, 17, 18, 16, 17, 4,
- 6, 8, 9, 9, 10, 10, 10, 10,
- 11, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 14, 13, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 15, 15, 15, 15, 15, 15, 16, 15,
- 15, 15, 15, 15, 15, 17, 17, 17,
- 16, 18, 16, 17, 17, 16, 16, 17,
- 17, 18, 17, 16, 17, 17, 17, 16,
- 17, 17, 18, 17, 18, 17, 17, 17,
- 18, 17, 17, 5, 8, 10, 10, 11,
- 11, 12, 12, 12, 13, 13, 14, 13,
- 13, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 16, 16, 15, 16, 16,
- 15, 15, 15, 15, 15, 16, 16, 15,
- 15, 16, 16, 17, 17, 18, 17, 16,
- 17, 18, 19, 17, 16, 16, 17, 17,
- 17, 6, 9, 11, 12, 12, 13, 13,
- 13, 14, 14, 14, 15, 15, 15, 16,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 16, 16, 17, 18, 16, 16, 16, 18,
- 17, 16, 17, 18, 17, 17, 16, 17,
- 17, 16, 17, 16, 17, 18, 18, 18,
- 17, 19, 19, 17, 20, 19, 18, 19,
- 20, 18, 16, 18, 17, 7, 10, 12,
- 13, 13, 14, 14, 14, 15, 15, 16,
- 16, 16, 16, 16, 18, 16, 17, 17,
- 8, 11, 13, 14, 14, 15, 16, 16,
- 16, 16, 17, 17, 17, 18, 18, 17,
- 17, 8, 12, 14, 15, 15, 15, 17,
- 17, 18, 17, 9, 12, 14, 15, 16,
- 16, 17, 9, 13, 15, 16, 16, 17,
- 9, 13, 16, 16, 16, 10, 13, 16,
- 18, 17, 10, 14, 17, 10, 14, 17,
- 11, 14, 16, 11, 14, 11, 15, 12,
- 16, 12, 16, 12, 16, 12, 16, 12,
- 17, 13, 13, 17, 13, 17, 13, 13,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 15, 15, 15, 15, 16, 15,
- 16, 16, 16, 16, 16, 16, 17, 16,
- 16, 16, 16, 17, 16, 17, 16, 17,
- 17, 17,
-};
-
-static const uint32_t coef1_huffcodes[555] = {
- 0x00115, 0x00002, 0x00001, 0x00000, 0x0000d, 0x00007, 0x00013, 0x0001d,
- 0x00008, 0x0000c, 0x00023, 0x0002b, 0x0003f, 0x00017, 0x0001b, 0x00043,
- 0x00049, 0x00050, 0x00055, 0x00054, 0x00067, 0x00064, 0x0007b, 0x0002d,
- 0x00028, 0x0002a, 0x00085, 0x00089, 0x0002b, 0x00035, 0x00090, 0x00091,
- 0x00094, 0x00088, 0x000c1, 0x000c6, 0x000f2, 0x000e3, 0x000c5, 0x000e2,
- 0x00036, 0x000f0, 0x000a7, 0x000cd, 0x000fb, 0x00059, 0x00116, 0x00103,
- 0x00108, 0x0012b, 0x0012d, 0x00188, 0x0012e, 0x0014c, 0x001c3, 0x00187,
- 0x001e7, 0x0006f, 0x00094, 0x00069, 0x001e6, 0x001ca, 0x00147, 0x00195,
- 0x000a7, 0x00213, 0x00209, 0x00303, 0x00295, 0x00289, 0x0028c, 0x0028d,
- 0x00312, 0x00330, 0x0029b, 0x00308, 0x00328, 0x0029a, 0x0025e, 0x003c5,
- 0x00384, 0x0039f, 0x00397, 0x00296, 0x0032e, 0x00332, 0x003c6, 0x003e6,
- 0x0012d, 0x000d1, 0x00402, 0x000dd, 0x00161, 0x0012b, 0x00127, 0x0045d,
- 0x00601, 0x004ab, 0x0045f, 0x00410, 0x004bf, 0x00528, 0x0045c, 0x00424,
- 0x00400, 0x00511, 0x00618, 0x0073d, 0x0063a, 0x00614, 0x0073c, 0x007c0,
- 0x007cf, 0x00802, 0x00966, 0x00964, 0x00951, 0x008a0, 0x00346, 0x00803,
- 0x00a52, 0x0024a, 0x007c1, 0x0063f, 0x00126, 0x00406, 0x00789, 0x008a2,
- 0x00960, 0x00967, 0x00c05, 0x00c70, 0x00c79, 0x00a5d, 0x00c26, 0x00c4d,
- 0x00372, 0x008a5, 0x00c08, 0x002c5, 0x00f11, 0x00cc4, 0x00f8e, 0x00e16,
- 0x00496, 0x00e77, 0x00f9c, 0x00c25, 0x00f1e, 0x00c27, 0x00f1f, 0x00e17,
- 0x00ccd, 0x00355, 0x00c09, 0x00c78, 0x00f90, 0x00521, 0x00357, 0x00356,
- 0x0068e, 0x00f9d, 0x00c04, 0x00e58, 0x00a20, 0x00a2c, 0x00c4c, 0x0052f,
- 0x00f8d, 0x01178, 0x01053, 0x01097, 0x0180f, 0x0180d, 0x012fb, 0x012aa,
- 0x0202a, 0x00a40, 0x018ed, 0x01ceb, 0x01455, 0x018e3, 0x012a1, 0x00354,
- 0x00353, 0x00f1c, 0x00c7b, 0x00c37, 0x0101d, 0x012cb, 0x01142, 0x0197d,
- 0x01095, 0x01e3b, 0x0186b, 0x00588, 0x01c2a, 0x014b8, 0x01e3a, 0x018ec,
- 0x01f46, 0x012fa, 0x00a53, 0x01ce8, 0x00a55, 0x01c29, 0x0117b, 0x01052,
- 0x012a0, 0x00589, 0x00950, 0x01c2b, 0x00a50, 0x0208b, 0x0180e, 0x02027,
- 0x02556, 0x01e20, 0x006e7, 0x01c28, 0x0197a, 0x00684, 0x020a2, 0x01f22,
- 0x03018, 0x039cf, 0x03e25, 0x02557, 0x0294c, 0x028a6, 0x00d11, 0x028a9,
- 0x02979, 0x00d46, 0x00a56, 0x039ce, 0x030cc, 0x0329a, 0x0149d, 0x0510f,
- 0x0451c, 0x02028, 0x03299, 0x01ced, 0x014b9, 0x00f85, 0x00c7a, 0x01800,
- 0x00341, 0x012ca, 0x039c8, 0x0329d, 0x00d0d, 0x03e20, 0x05144, 0x00d45,
- 0x030d0, 0x0186d, 0x030d5, 0x00d0f, 0x00d40, 0x04114, 0x020a1, 0x0297f,
- 0x03e24, 0x032f1, 0x04047, 0x030d4, 0x028a8, 0x00d0e, 0x0451d, 0x04044,
- 0x0297e, 0x04042, 0x030d2, 0x030cf, 0x03e21, 0x03e26, 0x028a5, 0x0451a,
- 0x00d48, 0x01a16, 0x00d44, 0x04518, 0x0149b, 0x039ca, 0x01498, 0x0403d,
- 0x0451b, 0x0149c, 0x032f3, 0x030cb, 0x08073, 0x03e22, 0x0529a, 0x020aa,
- 0x039cc, 0x0738a, 0x06530, 0x07389, 0x06193, 0x08071, 0x04043, 0x030ce,
- 0x05147, 0x07388, 0x05145, 0x08072, 0x04521, 0x00d47, 0x0297c, 0x030cd,
- 0x030ca, 0x0000b, 0x0000c, 0x00083, 0x000e4, 0x00048, 0x00102, 0x001cc,
- 0x001f5, 0x00097, 0x0020b, 0x00124, 0x00453, 0x00627, 0x00639, 0x00605,
- 0x00517, 0x001b8, 0x00663, 0x00667, 0x007c3, 0x00823, 0x00961, 0x00963,
- 0x00e5a, 0x00e59, 0x00a2b, 0x00cbf, 0x00292, 0x00a2d, 0x007d0, 0x00953,
- 0x00cc5, 0x00f84, 0x004ab, 0x014a7, 0x0068a, 0x0117a, 0x0052e, 0x01442,
- 0x0052c, 0x00c77, 0x00f8f, 0x004aa, 0x01094, 0x01801, 0x012c4, 0x0297b,
- 0x00952, 0x01f19, 0x006a5, 0x01149, 0x012c5, 0x01803, 0x022f2, 0x0329b,
- 0x04520, 0x0149e, 0x00d13, 0x01f16, 0x01ce9, 0x0101c, 0x006e6, 0x039c9,
- 0x06191, 0x07c8e, 0x06192, 0x0ca63, 0x039cd, 0x06190, 0x06884, 0x06885,
- 0x07382, 0x00d49, 0x00d41, 0x0450c, 0x0149a, 0x030d1, 0x08077, 0x03e23,
- 0x01a15, 0x0e701, 0x0e702, 0x08079, 0x0822a, 0x0a218, 0x07887, 0x0403f,
- 0x0520b, 0x0529b, 0x0e700, 0x04519, 0x00007, 0x000e0, 0x000d0, 0x0039b,
- 0x003e5, 0x00163, 0x0063e, 0x007c9, 0x00806, 0x00954, 0x01044, 0x01f44,
- 0x0197c, 0x01f45, 0x00a51, 0x01f47, 0x00951, 0x0052d, 0x02291, 0x0092f,
- 0x00a54, 0x00d12, 0x0297d, 0x00d0c, 0x01499, 0x0329e, 0x032f0, 0x02025,
- 0x039c6, 0x00a57, 0x03e46, 0x00d42, 0x0738b, 0x05146, 0x04046, 0x08078,
- 0x0510e, 0x07886, 0x02904, 0x04156, 0x04157, 0x06032, 0x030d3, 0x08bce,
- 0x04040, 0x0403e, 0x0a414, 0x10457, 0x08075, 0x06887, 0x07c8f, 0x039c7,
- 0x07387, 0x08070, 0x08bcf, 0x1482a, 0x10456, 0x1482b, 0x01a17, 0x06886,
- 0x0450d, 0x00013, 0x0006b, 0x00615, 0x0080b, 0x0082b, 0x00952, 0x00e5b,
- 0x018e2, 0x0186c, 0x01f18, 0x0329f, 0x00d43, 0x03e29, 0x05140, 0x05141,
- 0x0ca62, 0x06033, 0x03c42, 0x03e28, 0x0450f, 0x0a21a, 0x07384, 0x0a219,
- 0x0e703, 0x0a21b, 0x01a14, 0x07383, 0x045e6, 0x0007a, 0x0012c, 0x00ccc,
- 0x0068f, 0x01802, 0x00a52, 0x00953, 0x04045, 0x01a20, 0x0451f, 0x000a4,
- 0x00735, 0x01cec, 0x02029, 0x020a3, 0x0451e, 0x00069, 0x00c24, 0x02024,
- 0x032f2, 0x05142, 0x00196, 0x00523, 0x000a6, 0x0197b, 0x0030b, 0x0092e,
- 0x003e9, 0x03e27, 0x00160, 0x05143, 0x00652, 0x04041, 0x00734, 0x028a7,
- 0x0080f, 0x01483, 0x0097c, 0x00340, 0x0068b, 0x00522, 0x01054, 0x01096,
- 0x01f17, 0x0202b, 0x01cea, 0x020a0, 0x02978, 0x02026, 0x0297a, 0x039cb,
- 0x03e2b, 0x0149f, 0x0329c, 0x07385, 0x08074, 0x0450e, 0x03e2a, 0x05149,
- 0x08076, 0x07386, 0x05148,
-};
-
-static const uint8_t coef1_huffbits[555] = {
- 9, 5, 2, 4, 4, 5, 5, 5,
- 6, 6, 6, 6, 6, 7, 7, 7,
- 7, 7, 7, 7, 7, 7, 7, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 9, 8, 8, 8, 8, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 10, 10, 10, 10, 10,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 11, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 13, 12, 12, 12, 12, 12, 12, 12,
- 13, 12, 12, 12, 12, 12, 12, 12,
- 12, 13, 12, 12, 12, 13, 13, 13,
- 13, 12, 12, 12, 12, 12, 12, 13,
- 12, 13, 13, 13, 13, 13, 13, 13,
- 14, 14, 13, 13, 13, 13, 13, 13,
- 13, 12, 12, 12, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 14, 13, 14, 13, 13, 13,
- 13, 13, 14, 13, 14, 14, 13, 14,
- 14, 13, 14, 13, 13, 14, 14, 13,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 15, 14, 14, 14, 14, 15, 15,
- 15, 14, 14, 13, 13, 12, 12, 13,
- 13, 13, 14, 14, 15, 14, 15, 15,
- 14, 13, 14, 15, 15, 15, 14, 14,
- 14, 14, 15, 14, 14, 15, 15, 15,
- 14, 15, 14, 14, 14, 14, 14, 15,
- 15, 16, 15, 15, 15, 14, 15, 15,
- 15, 15, 14, 14, 16, 14, 15, 14,
- 14, 15, 15, 15, 15, 16, 15, 14,
- 15, 15, 15, 16, 15, 15, 14, 14,
- 14, 4, 7, 8, 8, 9, 9, 9,
- 9, 10, 10, 11, 11, 11, 11, 11,
- 11, 12, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 11, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 12, 12, 13, 13, 13, 13, 14,
- 14, 13, 14, 13, 13, 13, 14, 14,
- 15, 15, 14, 13, 13, 13, 14, 14,
- 15, 15, 15, 16, 14, 15, 17, 17,
- 15, 15, 15, 15, 15, 14, 16, 14,
- 16, 16, 16, 16, 16, 16, 15, 15,
- 17, 15, 16, 15, 6, 8, 10, 10,
- 10, 11, 11, 11, 12, 12, 13, 13,
- 13, 13, 14, 13, 14, 13, 14, 14,
- 14, 14, 14, 15, 15, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 15, 16,
- 15, 15, 16, 15, 15, 15, 14, 16,
- 15, 15, 18, 17, 16, 17, 15, 14,
- 15, 16, 16, 19, 17, 19, 16, 17,
- 15, 7, 10, 11, 12, 12, 12, 12,
- 13, 13, 13, 14, 15, 14, 15, 15,
- 16, 15, 14, 14, 15, 16, 15, 16,
- 16, 16, 16, 15, 15, 7, 11, 12,
- 13, 13, 14, 14, 15, 15, 15, 8,
- 11, 13, 14, 14, 15, 9, 12, 14,
- 14, 15, 9, 13, 10, 13, 10, 14,
- 10, 14, 11, 15, 11, 15, 11, 14,
- 12, 15, 12, 13, 13, 13, 13, 13,
- 13, 14, 13, 14, 14, 14, 14, 14,
- 14, 15, 14, 15, 16, 15, 14, 15,
- 16, 15, 15,
-};
-
-static const uint32_t coef2_huffcodes[1336] = {
- 0x003e6, 0x000f6, 0x00000, 0x00002, 0x00006, 0x0000f, 0x0001b, 0x00028,
- 0x00039, 0x0003f, 0x0006b, 0x00076, 0x000b7, 0x000e8, 0x000ef, 0x00169,
- 0x001a7, 0x001d4, 0x001dc, 0x002c4, 0x00349, 0x00355, 0x00391, 0x003dc,
- 0x00581, 0x005b2, 0x00698, 0x0070c, 0x00755, 0x0073a, 0x00774, 0x007cf,
- 0x00b0a, 0x00b66, 0x00d2e, 0x00d5e, 0x00e1b, 0x00eac, 0x00e5a, 0x00f7e,
- 0x00fa1, 0x0163e, 0x01a37, 0x01a52, 0x01c39, 0x01ab3, 0x01d5f, 0x01cb6,
- 0x01f52, 0x01dd9, 0x02c04, 0x02c2e, 0x02c2d, 0x02c23, 0x03467, 0x034a3,
- 0x0351b, 0x03501, 0x03a5d, 0x0351c, 0x03875, 0x03dea, 0x0397b, 0x039db,
- 0x03df1, 0x039d8, 0x03bb4, 0x0580a, 0x0584d, 0x05842, 0x05b13, 0x058ea,
- 0x0697d, 0x06a06, 0x068cc, 0x06ac7, 0x06a96, 0x072f4, 0x07543, 0x072b4,
- 0x07d20, 0x0b003, 0x073b5, 0x07be6, 0x0d180, 0x07bd1, 0x07cb8, 0x07d06,
- 0x07d25, 0x0d2f2, 0x0d19a, 0x0d334, 0x0e1dc, 0x0d529, 0x0d584, 0x0e1d2,
- 0x0e5e3, 0x0eec4, 0x0e564, 0x0fa49, 0x16001, 0x0eedc, 0x0f7fa, 0x1a32c,
- 0x16131, 0x16003, 0x0f9c8, 0x1ef80, 0x1d2a0, 0x1aa4b, 0x0f7ce, 0x1abfe,
- 0x1aa50, 0x1a458, 0x1a816, 0x1cae4, 0x1d2fe, 0x1d52e, 0x1aa4c, 0x2c245,
- 0x1d2a1, 0x1a35d, 0x1ca1b, 0x1d5d8, 0x1f531, 0x1ca1c, 0x1f389, 0x1f4af,
- 0x3a5e7, 0x351fb, 0x2c24b, 0x34bce, 0x2c24d, 0x2c249, 0x2c24a, 0x72dfc,
- 0x357ef, 0x35002, 0x3a5e6, 0x39431, 0x5843b, 0x34a77, 0x58431, 0x3a5f3,
- 0x3a5dd, 0x3e5e5, 0x356bd, 0x3976e, 0x6a3d2, 0x3500d, 0x694c4, 0x580bd,
- 0x3e5e8, 0x74b95, 0x34a6e, 0x3977c, 0x39432, 0x5b0d2, 0x6a3d8, 0x580b8,
- 0x5b0cb, 0x5b0d7, 0x72dee, 0x72ded, 0x72dec, 0x74b9c, 0x3977f, 0x72dea,
- 0x74b9e, 0x7be7d, 0x580bf, 0x5b0d5, 0x7cba8, 0x74b91, 0x3e5dd, 0xb6171,
- 0xd46b3, 0xd46b9, 0x7cba1, 0x74b9f, 0x72de1, 0xe59f5, 0x3e5eb, 0x00004,
- 0x00015, 0x00038, 0x00075, 0x000e8, 0x001d3, 0x00347, 0x0039c, 0x00690,
- 0x0074a, 0x00b60, 0x00e93, 0x00f74, 0x0163d, 0x01a5a, 0x01d24, 0x01cbe,
- 0x01f4b, 0x03468, 0x03562, 0x03947, 0x03e82, 0x05804, 0x05b12, 0x05803,
- 0x0696d, 0x06a9e, 0x0697c, 0x06978, 0x06afb, 0x074b2, 0x072f5, 0x073c0,
- 0x07541, 0x06944, 0x074b7, 0x070d3, 0x07ba9, 0x0b0b1, 0x0d1af, 0x0e1dd,
- 0x0e5e2, 0x0e1a3, 0x0eec3, 0x1612f, 0x0e961, 0x0eeda, 0x0e78e, 0x0fa48,
- 0x1612c, 0x0e511, 0x0e565, 0x0e953, 0x1aa4a, 0x0e59d, 0x1d52c, 0x1a811,
- 0x1cae7, 0x1abfc, 0x1d52d, 0x1cacf, 0x1cf05, 0x2c254, 0x34a72, 0x1f4ac,
- 0x3976b, 0x34a71, 0x2c6d9, 0x2d873, 0x34a6a, 0x357e7, 0x3464c, 0x3e5f5,
- 0x58433, 0x1f53a, 0x3500a, 0x357ea, 0x34a73, 0x3942f, 0x357e5, 0x39775,
- 0x694cd, 0x39772, 0x7cba5, 0x6a3ef, 0x35483, 0x74b98, 0x5b0c1, 0x39770,
- 0x3a5d7, 0x39433, 0x39434, 0x694ce, 0x580be, 0x3e5ff, 0x6a3ec, 0xb616f,
- 0xd46b1, 0x6a3d1, 0x72de5, 0x74b6e, 0x72de9, 0x3e700, 0xd46b6, 0x6a3e9,
- 0x74b69, 0xe5675, 0xd46b8, 0x7cbaa, 0x3a5d1, 0x0000c, 0x0003c, 0x000eb,
- 0x001f1, 0x003a4, 0x006a8, 0x007d5, 0x00d43, 0x00e77, 0x016c5, 0x01cb1,
- 0x02c5d, 0x03a55, 0x03a56, 0x03e51, 0x03bb5, 0x05b0a, 0x06a9f, 0x074b8,
- 0x07d28, 0x0d187, 0x0d40e, 0x0d52e, 0x0d425, 0x0eae3, 0x0e1d3, 0x1612e,
- 0x0e59e, 0x0eec2, 0x0e578, 0x0e51a, 0x0e579, 0x0e515, 0x0e960, 0x0d183,
- 0x0d220, 0x0d2cb, 0x0e512, 0x16c3e, 0x16002, 0x16c42, 0x1cae9, 0x3461a,
- 0x1d2fa, 0x1a308, 0x1a849, 0x1cf07, 0x1f38f, 0x34b65, 0x2c253, 0x1ef9e,
- 0x1cbc3, 0x1cbc1, 0x2c255, 0x1f384, 0x58435, 0x2c5cd, 0x3a5f7, 0x2c252,
- 0x3959c, 0x2c6d8, 0x3a5d3, 0x6ad78, 0x6a3f2, 0x7cba9, 0xb6176, 0x72deb,
- 0x39764, 0x3e5f6, 0x3a5d8, 0x74a8c, 0x6a3e6, 0x694d1, 0x6ad79, 0x1a4592,
- 0xe59fb, 0x7cbb3, 0x5b0cd, 0x00017, 0x000b5, 0x002c3, 0x005b7, 0x00b1c,
- 0x00e5c, 0x0163f, 0x01ab2, 0x01efa, 0x0348a, 0x0396e, 0x058da, 0x06963,
- 0x06a30, 0x072cd, 0x073cf, 0x07ce7, 0x0d2ca, 0x0d2d8, 0x0e764, 0x0e794,
- 0x16008, 0x16167, 0x1617e, 0x1aa49, 0x1a30b, 0x1a813, 0x2c6da, 0x1a580,
- 0x1cbc2, 0x0f9ca, 0x1617f, 0x1d2fe, 0x0f7fc, 0x16c40, 0x0e513, 0x0eec5,
- 0x0f7c3, 0x1d508, 0x1a81e, 0x1d2fd, 0x39430, 0x35486, 0x3e5fd, 0x2c24c,
- 0x2c75a, 0x34a74, 0x3a5f4, 0x3464d, 0x694ca, 0x3a5f1, 0x1d509, 0x1d5c0,
- 0x34648, 0x3464e, 0x6a3d5, 0x6a3e8, 0x6a3e7, 0x5b0c3, 0x2c248, 0x1f38a,
- 0x3a5f2, 0x6a3e5, 0x00029, 0x00168, 0x0058c, 0x00b67, 0x00f9d, 0x01c3d,
- 0x01cbf, 0x02c20, 0x0351d, 0x03df6, 0x06af9, 0x072b5, 0x0b1d7, 0x0b0b2,
- 0x0d40a, 0x0d52b, 0x0e952, 0x0e797, 0x163c3, 0x1c3a0, 0x1f386, 0x1ca21,
- 0x34655, 0x2c247, 0x1f53b, 0x2c250, 0x2c24f, 0x1f385, 0x1ef5d, 0x1cf15,
- 0x1caea, 0x1ab0a, 0x1cf19, 0x1f53d, 0x1d5c2, 0x1d2fb, 0x1ef58, 0x34a78,
- 0x357ec, 0x1f533, 0x3a5e1, 0x694d2, 0x58482, 0x3a5ee, 0x2c6dc, 0x357eb,
- 0x5b0c4, 0x39778, 0x6a3e1, 0x7cbb4, 0x3a5e1, 0x74b68, 0x3a5ef, 0x3a5d2,
- 0x39424, 0x72de2, 0xe59f6, 0xe59f7, 0x3e702, 0x3e5ec, 0x1f38b, 0x0003b,
- 0x001f0, 0x00777, 0x00fa8, 0x01cb2, 0x02d84, 0x03a57, 0x03dd6, 0x06917,
- 0x06a11, 0x07d07, 0x0eae2, 0x0e796, 0x0f9c9, 0x0f7fb, 0x16166, 0x16160,
- 0x1ab1b, 0x1abfa, 0x2d87b, 0x1d2f7, 0x39768, 0x1f38c, 0x34653, 0x34651,
- 0x6a3d9, 0x35001, 0x3abbd, 0x38742, 0x39426, 0x34a76, 0x3a5ec, 0x34a75,
- 0x35000, 0x35488, 0x1cf10, 0x2c6db, 0x357ed, 0x357e8, 0x357e9, 0x3a5f0,
- 0x694c2, 0xb6178, 0x72df5, 0x39425, 0x3942b, 0x74b6d, 0x74b6f, 0xb6177,
- 0xb6179, 0x74b6a, 0xb6172, 0x58487, 0x3e5ee, 0x3e5ed, 0x72df2, 0x72df4,
- 0x7cbae, 0x6a3ca, 0x70e86, 0x34bcf, 0x6a3c8, 0x00059, 0x00384, 0x00d5b,
- 0x01c38, 0x03560, 0x0395b, 0x0584e, 0x06964, 0x073cd, 0x0b1e7, 0x0e798,
- 0x0e78d, 0x0fa43, 0x1a848, 0x1a32f, 0x1aa4e, 0x3464a, 0x1f4ab, 0x1f38d,
- 0x3a5eb, 0x3a5d4, 0x3548a, 0x6a3c7, 0x5b0d0, 0x6a3c5, 0x7cbb0, 0x694cb,
- 0x3a5e5, 0x3e5e2, 0x3942c, 0x2d872, 0x1f4ae, 0x3a5d5, 0x694d3, 0x58481,
- 0x35009, 0x39774, 0x58432, 0xb616c, 0x5b0db, 0x3548b, 0xb6174, 0x1d5d95,
- 0xb004c, 0x7cbb2, 0x3a5e5, 0x74a8f, 0xe59f9, 0x72df6, 0xe59fd, 0x7cbad,
- 0xd427d, 0x72cff, 0x3977a, 0x5b0d9, 0xb616d, 0xb616b, 0x1a4593, 0x7cbaf,
- 0x5b0da, 0x00071, 0x003eb, 0x01603, 0x02c6c, 0x03961, 0x068c8, 0x06a31,
- 0x072bd, 0x0d2c2, 0x0e51b, 0x0e5e6, 0x1abfb, 0x1d2ff, 0x1cae5, 0x1ef5c,
- 0x1ef5e, 0x1cf13, 0x34a6d, 0x3976d, 0xb616a, 0x3e5f2, 0x6a3c4, 0xb6169,
- 0x3e5dc, 0x580b9, 0x74b99, 0x75764, 0x58434, 0x3a5d9, 0x6945a, 0x69459,
- 0x3548c, 0x3a5e9, 0x69457, 0x72df1, 0x6945e, 0x6a35e, 0x3e701, 0xb6168,
- 0x5b0dd, 0x3a5de, 0x6a3c2, 0xd4278, 0x6a3cc, 0x72dfd, 0xb6165, 0x16009a,
- 0x7cbb1, 0xd427c, 0xb6162, 0xe765e, 0x1cecbe, 0x7cbb6, 0x69454, 0xb6160,
- 0xd427a, 0x1d5d96, 0xb1d6d, 0xe59f4, 0x72de8, 0x3a5db, 0x0007a, 0x006ae,
- 0x01c3c, 0x03aba, 0x058e9, 0x072cc, 0x0d2dd, 0x0d22d, 0x0eec1, 0x0eedb,
- 0x1d2a2, 0x1ef5b, 0x357e2, 0x3abbf, 0x1d2f9, 0x35004, 0x3a5dc, 0x351fc,
- 0x3976c, 0x6a3c6, 0x6a3cb, 0x3e5ea, 0xe59f3, 0x6a3ce, 0x69452, 0xe59f0,
- 0x74b90, 0xd4279, 0xd427b, 0x7cbb5, 0x5b0c5, 0x3a5e3, 0x3a5e2, 0x000d0,
- 0x00775, 0x01efe, 0x03dd5, 0x0728c, 0x07cb9, 0x0e1a2, 0x0ea85, 0x0eed8,
- 0x1a30a, 0x1aa4f, 0x3a5df, 0x35008, 0x3a5e0, 0x3e5f4, 0x3e5f7, 0xb1d6c,
- 0x5843e, 0x34a70, 0x72df8, 0x74b6b, 0xd427f, 0x72df0, 0x5b0bf, 0x5b0c0,
- 0xd46b0, 0x72def, 0xe59f8, 0x162e64, 0xb1d6f, 0x3a5e0, 0x39427, 0x69166,
- 0x6a3e2, 0x6a3e3, 0x74a8d, 0xd427e, 0x1d5d97, 0xd46b4, 0x5b0d8, 0x6a3d3,
- 0x000e0, 0x00b63, 0x034cc, 0x06a33, 0x073c9, 0x0e1a0, 0x0f7fd, 0x0f9cc,
- 0x1617d, 0x1caeb, 0x1f4a9, 0x3abb3, 0x69450, 0x39420, 0x39777, 0x3e5e0,
- 0x6a3d4, 0x6a3ed, 0xb6166, 0xe59f1, 0xb1d6e, 0xe5676, 0x6a3ea, 0xe5674,
- 0xb6163, 0xd46b7, 0x7cba6, 0xd46ba, 0x1d5d94, 0xb6164, 0x6a3f1, 0x7cba2,
- 0x69451, 0x72dfa, 0xd46bb, 0x72df7, 0x74b94, 0x1cecbf, 0xe59fa, 0x16009b,
- 0x6a3e4, 0x000e6, 0x00e94, 0x03876, 0x070ef, 0x0d52a, 0x16015, 0x16014,
- 0x1abf9, 0x1cf17, 0x34a79, 0x34650, 0x3e705, 0x6a3d0, 0x58430, 0x74b9d,
- 0x7be7e, 0x5b0be, 0x39773, 0x6a3de, 0x000fb, 0x00f7b, 0x03dd7, 0x07bd0,
- 0x0e59c, 0x0f9cd, 0x1cf18, 0x1d2ff, 0x34a7a, 0x39429, 0x3500c, 0x72de0,
- 0x69456, 0x7be7c, 0xd46b5, 0xd46b2, 0x6a3dd, 0x001a2, 0x0163b, 0x06913,
- 0x0b016, 0x0fa42, 0x1a32d, 0x1cf06, 0x34a7c, 0x34a7d, 0xb6161, 0x35481,
- 0x3e5fa, 0x7cba0, 0x7be7f, 0x7cba3, 0x7cba7, 0x5b0d3, 0x72de6, 0x6a3dc,
- 0x001a9, 0x01ab4, 0x06a34, 0x0d46a, 0x16130, 0x1ef5f, 0x1f532, 0x1f536,
- 0x3942e, 0x58436, 0x6a3db, 0x6945b, 0x001c9, 0x01ca0, 0x0728b, 0x0eed9,
- 0x1f539, 0x1ca1d, 0x39765, 0x39766, 0x58439, 0x6945d, 0x39767, 0x001d3,
- 0x01f2c, 0x07bfc, 0x16161, 0x34652, 0x3a5ed, 0x3548d, 0x58438, 0x6a3da,
- 0x002c1, 0x02c5e, 0x0d335, 0x1ab1a, 0x2d874, 0x35006, 0x35484, 0x5b0cc,
- 0x74b9a, 0x72df3, 0x6a3d6, 0x002da, 0x034b3, 0x0d5ae, 0x1caee, 0x2d871,
- 0x357e3, 0x74b97, 0x72df9, 0x580ba, 0x5b0d4, 0x0034d, 0x0354e, 0x0f750,
- 0x1cbc0, 0x3a5e7, 0x3a5e4, 0x00385, 0x03a58, 0x16c41, 0x2c5cf, 0x3e5e1,
- 0x74b6c, 0xe5677, 0x6a3df, 0x00390, 0x03e50, 0x163c2, 0x2d876, 0x35482,
- 0x5b0d6, 0x5843a, 0x0039f, 0x0585e, 0x1a583, 0x3500f, 0x74b93, 0x39771,
- 0x003e4, 0x06912, 0x16c43, 0x357e1, 0x0058a, 0x0696f, 0x1f538, 0x5b0c9,
- 0x6a3cf, 0x005b6, 0x06af8, 0x1f534, 0x58483, 0x6a3e0, 0x00695, 0x07d02,
- 0x1cae8, 0x58485, 0x006a2, 0x0754a, 0x357ee, 0x3977b, 0x00748, 0x074b2,
- 0x34a7b, 0x00729, 0x0b1e0, 0x34649, 0x3e5e3, 0x0073d, 0x0d2c4, 0x3e5e6,
- 0x007bb, 0x0b099, 0x39762, 0x5b0ce, 0x6945f, 0x007d1, 0x0d5ab, 0x39779,
- 0x007d3, 0x0d52f, 0x39763, 0x6945c, 0x00b1a, 0x0d2c5, 0x35489, 0x00d23,
- 0x0eaed, 0x3e5f8, 0x00d32, 0x16016, 0x3e5fb, 0x00d41, 0x0e768, 0x3a5ed,
- 0x00e1f, 0x16017, 0x58027, 0x00ead, 0x0fa07, 0x69455, 0x00e54, 0x1612b,
- 0x00e55, 0x1a581, 0x00f78, 0x1a32b, 0x580bc, 0x6a3ee, 0x00f79, 0x1abfd,
- 0x00f95, 0x1ab18, 0x6a3f0, 0x01637, 0x1aa4d, 0x0162d, 0x1f53c, 0x6a3f3,
- 0x01a31, 0x1a810, 0x39769, 0x01a50, 0x1caef, 0x01a36, 0x1a32e, 0x01a67,
- 0x1f38e, 0x01a85, 0x1ef59, 0x01aa6, 0x1ef83, 0x01d51, 0x2c012, 0x01d53,
- 0x2d879, 0x01d5e, 0x35005, 0x01cba, 0x1cf04, 0x69453, 0x01d2d, 0x351ff,
- 0x01f2d, 0x2d86f, 0x01f29, 0x35007, 0x02c22, 0x351fa, 0x02c03, 0x3a5ec,
- 0x02c5f, 0x3a5eb, 0x02c58, 0x34a6b, 0x03469, 0x356be, 0x02c59, 0x34a6c,
- 0x0346a, 0x3a5ea, 0x034bd, 0x034bf, 0x356bf, 0x0386a, 0x03ab9, 0x5843f,
- 0x0386b, 0x3a5f5, 0x03a4b, 0x39421, 0x03aa4, 0x3a5e9, 0x03a5a, 0x03960,
- 0x3977e, 0x03de9, 0x03958, 0x03df7, 0x039e1, 0x3e5e4, 0x0395f, 0x69458,
- 0x03e91, 0x03df2, 0x39428, 0x058f2, 0x03e80, 0x6a3c3, 0x03e93, 0x694c0,
- 0x058b8, 0x5b0ca, 0x0584f, 0x694c1, 0x058f1, 0x068d6, 0x06a10, 0x06ac3,
- 0x06a32, 0x070d2, 0x06911, 0x074b1, 0x07494, 0x06ad4, 0x06ad6, 0x072b8,
- 0x06afa, 0x074b3, 0x07540, 0x073ce, 0x0b005, 0x074b3, 0x07495, 0x074b9,
- 0x0d336, 0x07bff, 0x07763, 0x073c8, 0x07d29, 0x0b622, 0x0d221, 0x0d181,
- 0x0b1d1, 0x074b8, 0x0b1d0, 0x0d19b, 0x0d2c3, 0x0b172, 0x0d2dc, 0x0b623,
- 0x0d5aa, 0x0d426, 0x0d182, 0x0e795, 0x0e1d1, 0x0d337, 0x0e96c, 0x0e5e4,
- 0x0e514, 0x0eaee, 0x16000, 0x0e767, 0x0e1a1, 0x0e78f, 0x16004, 0x0f7c2,
- 0x0e799, 0x0e5e7, 0x0e566, 0x0e769, 0x0f751, 0x0eede, 0x0fa06, 0x16005,
- 0x0fa9f, 0x1a5e6, 0x0e766, 0x1636f, 0x0eedd, 0x0eec0, 0x1a309, 0x1ceca,
- 0x163cd, 0x0f9cb, 0x0eedf, 0x1a582, 0x1612d, 0x0e5e5, 0x1abf8, 0x1a30c,
- 0x1ca1f, 0x163cc, 0x1a35c, 0x1ca1e, 0x1aa51, 0x163ac, 0x1a84e, 0x1a53f,
- 0x1cf16, 0x1d2fc, 0x1a5b3, 0x1ab19, 0x1a81f, 0x1d5c3, 0x16c3f, 0x1d5c1,
- 0x1d2fc, 0x1f4aa, 0x1a812, 0x1f535, 0x1cf12, 0x1a817, 0x1617c, 0x1ab0b,
- 0x1d2f8, 0x1ef82, 0x2d87a, 0x1d52f, 0x1f530, 0x1aa48, 0x35487, 0x1d2fd,
- 0x1f4ad, 0x1cf11, 0x3461b, 0x35485, 0x1ca20, 0x1caed, 0x1cae6, 0x1abff,
- 0x3464f, 0x34a6f, 0x1ef81, 0x3464b, 0x39d96, 0x1f383, 0x1f537, 0x1cf14,
- 0x2c5ce, 0x3500e, 0x2c251, 0x1caec, 0x1f387, 0x34654, 0x357e4, 0x2d878,
- 0x3500b, 0x35480, 0x3a5e8, 0x3548e, 0x34b64, 0x1f4a8, 0x35003, 0x3e5df,
- 0x2d870, 0x357e6, 0x3e5f0, 0x1ef5a, 0x3a5ea, 0x1f388, 0x3e703, 0x2c24e,
- 0x3a5e2, 0x351fd, 0x2c6dd, 0x3e704, 0x351fe, 0x2d875, 0x5b0c7, 0x3976a,
- 0x3a5e6, 0x39423, 0x58480, 0x2c246, 0x3a5e3, 0x2d877, 0x3e5f1, 0x3abbe,
- 0x58489, 0x3e5f9, 0x357e0, 0x3abbc, 0x5b0c6, 0x69167, 0x69165, 0x3e5e9,
- 0x39422, 0x3976f, 0x3977d, 0x3e5de, 0x6a3c9, 0x58b98, 0x3a5f6, 0x3a5d0,
- 0x58486, 0x6a3c1, 0x3e5fc, 0x5b0dc, 0x3548f, 0x3942d, 0x694c9, 0x58484,
- 0x3a5e8, 0x74b9b, 0x74b96, 0x694d0, 0x58488, 0x3a5e4, 0x3942a, 0x72ec2,
- 0x39776, 0x5b0d1, 0x5b0cf, 0x3a5d6, 0xe59fc, 0x5b0c8, 0x3e5e7, 0x7cbb7,
- 0x70e87, 0x7cbab, 0x5b0c2, 0x694c3, 0x74a8e, 0x3e5f3, 0x6a3cd, 0x72dfe,
- 0x73b2e, 0x72ec0, 0x694c5, 0x58437, 0x694c8, 0x72dff, 0x39435, 0x5843d,
- 0x6a3d7, 0x72ec1, 0xd22c8, 0x694cf, 0xb6173, 0x3e5fe, 0x580bb, 0xe59f2,
- 0xb616e, 0xb6175, 0x3a5da, 0x5b0bd, 0x694cc, 0x5843c, 0x694c7, 0x74b92,
- 0x72ec3, 0x694c6, 0xb6170, 0x7cbac, 0xb1733, 0x7cba4, 0xb6167, 0x72de7,
- 0x72de4, 0x6a3c0, 0x3e5ef, 0x162e65, 0x72de3, 0x72dfb, 0x6a35f, 0x6a3eb,
-};
-
-static const uint8_t coef2_huffbits[1336] = {
- 11, 9, 2, 3, 4, 4, 5, 6,
- 6, 7, 7, 8, 8, 8, 9, 9,
- 9, 9, 10, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 16, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 18, 17, 17, 17, 17,
- 17, 17, 17, 18, 18, 17, 17, 18,
- 17, 17, 18, 17, 18, 18, 18, 18,
- 19, 18, 18, 18, 18, 18, 18, 20,
- 18, 18, 18, 19, 19, 18, 19, 18,
- 19, 19, 18, 19, 19, 18, 19, 19,
- 19, 19, 18, 19, 19, 19, 19, 19,
- 19, 19, 20, 20, 20, 19, 19, 20,
- 19, 20, 19, 19, 20, 19, 19, 20,
- 20, 20, 20, 19, 20, 21, 19, 3,
- 5, 7, 8, 9, 9, 10, 11, 11,
- 12, 12, 12, 13, 13, 13, 13, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 15, 15, 15, 15, 16, 16, 16, 16,
- 17, 16, 17, 17, 16, 17, 17, 17,
- 17, 17, 17, 16, 17, 17, 17, 17,
- 18, 17, 17, 18, 18, 18, 18, 18,
- 19, 18, 18, 18, 18, 18, 18, 19,
- 19, 18, 18, 18, 18, 19, 18, 19,
- 19, 19, 20, 19, 18, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 20,
- 20, 19, 20, 19, 20, 19, 20, 19,
- 19, 21, 20, 20, 19, 4, 7, 8,
- 10, 11, 11, 12, 12, 13, 13, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 17, 17, 17, 17, 17, 17, 16, 16,
- 16, 16, 17, 17, 17, 17, 18, 18,
- 18, 17, 17, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 19, 18, 18, 18,
- 19, 18, 19, 19, 19, 20, 20, 20,
- 19, 19, 19, 19, 19, 19, 19, 21,
- 21, 20, 19, 5, 8, 10, 11, 12,
- 13, 13, 13, 14, 14, 15, 15, 15,
- 15, 16, 16, 16, 16, 16, 17, 17,
- 17, 17, 17, 17, 17, 17, 18, 17,
- 18, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 19, 18, 19, 18,
- 18, 18, 18, 18, 19, 18, 17, 17,
- 18, 18, 19, 19, 19, 19, 18, 18,
- 18, 19, 6, 9, 11, 12, 13, 13,
- 14, 14, 14, 15, 15, 16, 16, 16,
- 16, 16, 16, 17, 17, 17, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 17, 18, 18, 17, 18, 18, 18,
- 18, 18, 18, 19, 19, 18, 18, 18,
- 19, 19, 19, 20, 19, 19, 18, 19,
- 19, 20, 21, 21, 19, 19, 18, 6,
- 10, 12, 13, 14, 14, 14, 15, 15,
- 15, 16, 16, 17, 17, 17, 17, 17,
- 17, 17, 18, 18, 19, 18, 18, 18,
- 19, 18, 18, 18, 19, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 19, 20, 20, 19, 19, 19, 19, 20,
- 20, 19, 20, 19, 19, 19, 20, 20,
- 20, 19, 19, 18, 19, 7, 10, 12,
- 13, 14, 15, 15, 15, 16, 16, 17,
- 17, 17, 17, 17, 17, 18, 18, 18,
- 18, 19, 18, 19, 19, 19, 20, 19,
- 18, 19, 19, 18, 18, 19, 19, 19,
- 18, 19, 19, 20, 19, 18, 20, 21,
- 20, 20, 19, 19, 21, 20, 21, 20,
- 20, 20, 19, 19, 20, 20, 21, 20,
- 19, 7, 11, 13, 14, 15, 15, 15,
- 16, 16, 17, 17, 17, 17, 18, 18,
- 18, 18, 18, 19, 20, 19, 19, 20,
- 19, 19, 19, 19, 19, 19, 19, 19,
- 18, 18, 19, 20, 19, 19, 19, 20,
- 19, 19, 19, 20, 19, 20, 20, 21,
- 20, 20, 20, 21, 22, 20, 19, 20,
- 20, 21, 20, 21, 20, 19, 8, 11,
- 13, 14, 15, 16, 16, 16, 17, 17,
- 17, 18, 18, 18, 18, 18, 19, 18,
- 19, 19, 19, 19, 21, 19, 19, 21,
- 19, 20, 20, 20, 19, 18, 18, 8,
- 12, 14, 15, 16, 16, 16, 16, 17,
- 17, 17, 19, 18, 18, 19, 19, 20,
- 19, 18, 20, 19, 20, 20, 19, 19,
- 20, 20, 21, 21, 20, 19, 19, 19,
- 19, 19, 19, 20, 21, 20, 19, 19,
- 8, 12, 14, 15, 16, 16, 17, 17,
- 17, 18, 18, 18, 19, 19, 19, 19,
- 19, 19, 20, 21, 20, 21, 19, 21,
- 20, 20, 20, 20, 21, 20, 19, 20,
- 19, 20, 20, 20, 19, 22, 21, 21,
- 19, 9, 12, 14, 15, 16, 17, 17,
- 17, 18, 18, 18, 19, 19, 19, 19,
- 20, 19, 19, 19, 9, 13, 15, 16,
- 17, 17, 18, 18, 18, 19, 18, 20,
- 19, 20, 20, 20, 19, 9, 13, 15,
- 16, 17, 17, 18, 18, 18, 20, 18,
- 19, 20, 20, 20, 20, 19, 20, 19,
- 9, 13, 15, 16, 17, 18, 18, 18,
- 19, 19, 19, 19, 10, 14, 16, 17,
- 18, 18, 19, 19, 19, 19, 19, 10,
- 14, 16, 17, 18, 18, 18, 19, 19,
- 10, 14, 16, 17, 18, 18, 18, 19,
- 19, 20, 19, 10, 14, 16, 18, 18,
- 18, 19, 20, 19, 19, 10, 14, 17,
- 18, 18, 18, 10, 15, 17, 18, 19,
- 19, 21, 19, 11, 15, 17, 18, 18,
- 19, 19, 11, 15, 17, 18, 19, 19,
- 11, 15, 17, 18, 11, 15, 18, 19,
- 19, 11, 15, 18, 19, 19, 11, 16,
- 18, 19, 11, 15, 18, 19, 11, 16,
- 18, 12, 16, 18, 19, 12, 16, 19,
- 12, 16, 19, 19, 19, 12, 16, 19,
- 12, 16, 19, 19, 12, 16, 18, 12,
- 16, 19, 12, 17, 19, 12, 17, 19,
- 12, 17, 19, 12, 17, 19, 13, 17,
- 13, 17, 13, 17, 19, 19, 13, 17,
- 13, 17, 19, 13, 17, 13, 18, 19,
- 13, 17, 19, 13, 18, 13, 17, 13,
- 18, 13, 18, 13, 18, 13, 18, 13,
- 18, 13, 18, 14, 18, 19, 14, 18,
- 14, 18, 14, 18, 14, 18, 14, 19,
- 14, 19, 14, 18, 14, 18, 14, 18,
- 14, 19, 14, 14, 18, 14, 14, 19,
- 14, 18, 14, 19, 14, 19, 14, 15,
- 19, 15, 15, 15, 15, 19, 15, 19,
- 15, 15, 19, 15, 15, 19, 15, 19,
- 15, 19, 15, 19, 15, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 15, 16,
- 15, 15, 15, 16, 16, 16, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 17, 16, 16, 16, 17,
- 17, 16, 17, 17, 16, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 18,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 18, 17, 17, 18, 17, 17, 17, 17,
- 18, 18, 17, 17, 17, 17, 17, 17,
- 17, 18, 17, 18, 18, 17, 17, 17,
- 18, 18, 18, 17, 18, 17, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 17,
- 18, 18, 18, 18, 19, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 18, 18, 18, 18, 18, 19,
- 18, 18, 19, 18, 18, 18, 19, 18,
- 19, 18, 18, 19, 18, 18, 19, 19,
- 19, 19, 19, 18, 19, 18, 19, 18,
- 19, 19, 18, 18, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 18, 19,
- 19, 19, 19, 19, 18, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 20,
- 19, 19, 19, 19, 21, 19, 19, 20,
- 19, 20, 19, 19, 19, 19, 19, 20,
- 20, 20, 19, 19, 19, 20, 19, 19,
- 19, 20, 20, 19, 20, 19, 19, 21,
- 20, 20, 19, 19, 19, 19, 19, 19,
- 20, 19, 20, 20, 20, 20, 20, 20,
- 20, 19, 19, 21, 20, 20, 19, 19,
-};
-
-static const uint32_t coef3_huffcodes[1072] = {
- 0x001b2, 0x00069, 0x00000, 0x00004, 0x00006, 0x0000e, 0x00014, 0x00019,
- 0x00016, 0x0002b, 0x00030, 0x0003d, 0x0003c, 0x0005a, 0x0005f, 0x0006d,
- 0x0007e, 0x0005f, 0x0007f, 0x000b6, 0x000bc, 0x000d8, 0x000f2, 0x000fe,
- 0x000bc, 0x000fc, 0x00161, 0x0016e, 0x00174, 0x00176, 0x001a2, 0x001e3,
- 0x001f3, 0x00174, 0x0017a, 0x001ea, 0x002a8, 0x002c4, 0x002e6, 0x00314,
- 0x00346, 0x00367, 0x003e9, 0x002e5, 0x002ee, 0x003d6, 0x00555, 0x00554,
- 0x00557, 0x005c3, 0x005d6, 0x006e0, 0x0062f, 0x006e2, 0x00799, 0x00789,
- 0x007fa, 0x005ce, 0x007fe, 0x005ec, 0x007cc, 0x007af, 0x00aa7, 0x00b19,
- 0x00b94, 0x00b85, 0x00b9f, 0x00c48, 0x00c45, 0x00dd8, 0x00c4c, 0x00c4b,
- 0x00d99, 0x00d1f, 0x00dc2, 0x00f95, 0x00fa2, 0x00bb5, 0x00b9f, 0x00f5d,
- 0x00bbf, 0x00f47, 0x0154a, 0x00fd5, 0x00f45, 0x00f7f, 0x0160d, 0x01889,
- 0x01757, 0x01722, 0x018b3, 0x0172d, 0x01a39, 0x01a18, 0x01bb3, 0x01b30,
- 0x01e63, 0x0173c, 0x01b35, 0x01723, 0x01e80, 0x01fee, 0x01761, 0x01ffc,
- 0x01f7f, 0x02c7c, 0x01fa1, 0x0177b, 0x01755, 0x0175a, 0x01fa6, 0x02eab,
- 0x0310a, 0x02c69, 0x03669, 0x03127, 0x03103, 0x02e43, 0x03662, 0x03165,
- 0x03124, 0x0313b, 0x03111, 0x03668, 0x0343b, 0x03c52, 0x03efc, 0x02e6c,
- 0x03fda, 0x03ef8, 0x02e7b, 0x03ee2, 0x03cc5, 0x03d72, 0x058c0, 0x03df8,
- 0x02ea9, 0x03e7e, 0x0556d, 0x05c82, 0x03d71, 0x03e7b, 0x03c42, 0x058d7,
- 0x03f4e, 0x06200, 0x03d70, 0x05cb2, 0x05c96, 0x05cb0, 0x03f45, 0x05cb1,
- 0x02e6d, 0x03110, 0x02f68, 0x05c90, 0x07ca6, 0x07c88, 0x06204, 0x062c8,
- 0x078a6, 0x07986, 0x079d5, 0x0b1ad, 0x07989, 0x0b079, 0x05cdd, 0x0aad4,
- 0x05de8, 0x07dcd, 0x07987, 0x05d67, 0x05d99, 0x0b91d, 0x07cf1, 0x05d9b,
- 0x079d7, 0x0b07b, 0x05c85, 0x05d9a, 0x07dcc, 0x07ebf, 0x07dce, 0x07dfb,
- 0x07ec0, 0x07d1a, 0x07a07, 0x05c84, 0x0c471, 0x07cf2, 0x0baef, 0x0b9d2,
- 0x05deb, 0x07bd6, 0x0b845, 0x05d98, 0x0b91a, 0x0bae8, 0x0c4e0, 0x0dc31,
- 0x0f93d, 0x0bbce, 0x0d1d2, 0x0f7a9, 0x0d9b9, 0x0bbcb, 0x0b900, 0x0aad7,
- 0x0babd, 0x0c4e1, 0x0f46f, 0x0c588, 0x0c58b, 0x160e6, 0x0bbcf, 0x0bac3,
- 0x0f945, 0x0f7a3, 0x0d1c1, 0x0fb8e, 0x0f7a4, 0x0fb8c, 0x0f40c, 0x0c473,
- 0x0fd72, 0x0bbcd, 0x0fffa, 0x0f940, 0x0bbc9, 0x0f7a8, 0x1a1ed, 0x0bbc5,
- 0x1f26f, 0x163fd, 0x160c7, 0x1a1f5, 0x0f947, 0x163fc, 0x154b3, 0x0fff6,
- 0x163f6, 0x160e9, 0x1a1f0, 0x0bab9, 0x0baba, 0x17086, 0x0b903, 0x0fd75,
- 0x0f308, 0x176f3, 0x163ff, 0x0fd7d, 0x1bb78, 0x163fb, 0x188db, 0x1a1f7,
- 0x154b2, 0x172fd, 0x163f4, 0x1bb73, 0x172ff, 0x0babc, 0x0f97d, 0x1a1f3,
- 0x1bb6d, 0x1ffd5, 0x1a1f4, 0x1f272, 0x17380, 0x17382, 0x1ffe7, 0x0bac8,
- 0x0bbc4, 0x188d3, 0x160e0, 0x0fd7b, 0x1725f, 0x172f5, 0x1bb79, 0x1fad9,
- 0x1f269, 0x188d0, 0x0bac4, 0x0bac5, 0x31185, 0x188d2, 0x188cc, 0x31187,
- 0x3e7fe, 0x188d1, 0x1bb6c, 0x1f268, 0x1fad2, 0x1ffd9, 0x1a1ea, 0x1bb68,
- 0x1facb, 0x3fdb2, 0x1e81a, 0x188ce, 0x172fb, 0x1a1ef, 0x1face, 0x1bb70,
- 0x0bac1, 0x1bb6b, 0x172f8, 0x1bb66, 0x1ffdf, 0x1bb6a, 0x1ffd7, 0x1f266,
- 0x176f8, 0x37653, 0x1fa7e, 0x31182, 0x1fac8, 0x2c7e3, 0x370ee, 0x176ec,
- 0x176e9, 0x2e4bc, 0x160c5, 0x3765a, 0x3ce9c, 0x17373, 0x176e8, 0x188d4,
- 0x176f1, 0x176ef, 0x37659, 0x1bb7c, 0x1ffde, 0x176f2, 0x3118b, 0x2c7d4,
- 0x37651, 0x5ce9f, 0x37650, 0x31191, 0x3f4f6, 0x3f4f5, 0x7a06c, 0x1fac1,
- 0x5c97b, 0x2c7e0, 0x79d3a, 0x3e7fd, 0x2c7df, 0x3f4f0, 0x7a06d, 0x376c1,
- 0x79d3b, 0x00004, 0x00014, 0x00059, 0x000ab, 0x000b8, 0x00177, 0x001f5,
- 0x001f2, 0x00315, 0x003fc, 0x005bd, 0x0062d, 0x006e8, 0x007dd, 0x00b04,
- 0x007cd, 0x00b1e, 0x00d1e, 0x00f15, 0x00f3b, 0x00f41, 0x01548, 0x018b0,
- 0x0173b, 0x01884, 0x01a1c, 0x01bb4, 0x01f25, 0x017b5, 0x0176d, 0x01ef8,
- 0x02e73, 0x03107, 0x03125, 0x03105, 0x02e49, 0x03ce8, 0x03ef9, 0x03e5e,
- 0x02e72, 0x03471, 0x03fd9, 0x0623f, 0x078a0, 0x06867, 0x05cb3, 0x06272,
- 0x068ec, 0x06e9a, 0x079d4, 0x06e98, 0x0b1aa, 0x06e1a, 0x07985, 0x068ee,
- 0x06e9b, 0x05c88, 0x0b1ac, 0x07dfa, 0x05d65, 0x07cf0, 0x07cbf, 0x0c475,
- 0x160eb, 0x1bb7e, 0x0f7a6, 0x1fedd, 0x160e3, 0x0fffb, 0x0fb8d, 0x0fff9,
- 0x0d1c0, 0x0c58c, 0x1a1e9, 0x0bab8, 0x0f5cf, 0x0fff5, 0x376c5, 0x1a1ec,
- 0x160ed, 0x1fede, 0x1fac9, 0x1a1eb, 0x1f224, 0x176ee, 0x0fd79, 0x17080,
- 0x17387, 0x1bb7a, 0x1ffe9, 0x176f7, 0x17385, 0x17781, 0x2c7d5, 0x17785,
- 0x1ffe3, 0x163f5, 0x1fac2, 0x3e7f9, 0x3118d, 0x3fdb1, 0x1ffe2, 0x1f226,
- 0x3118a, 0x2c7d9, 0x31190, 0x3118c, 0x3f4f3, 0x1bb7f, 0x1bb72, 0x31184,
- 0xb92f4, 0x3e7fb, 0x6e1d9, 0x1faca, 0x62300, 0x3fdb8, 0x3d037, 0x3e7fc,
- 0x62301, 0x3f4f2, 0x1f26a, 0x0000e, 0x00063, 0x000f8, 0x001ee, 0x00377,
- 0x003f7, 0x006e3, 0x005cc, 0x00b05, 0x00dd2, 0x00fd4, 0x0172e, 0x0172a,
- 0x01e23, 0x01f2d, 0x01763, 0x01769, 0x0176c, 0x02e75, 0x03104, 0x02ec1,
- 0x03e58, 0x0583f, 0x03f62, 0x03f44, 0x058c5, 0x0623c, 0x05cf4, 0x07bd7,
- 0x05d9d, 0x0aad2, 0x05d66, 0x0b1a9, 0x0b078, 0x07cfe, 0x0b918, 0x0c46f,
- 0x0b919, 0x0b847, 0x06e1b, 0x0b84b, 0x0aad8, 0x0fd74, 0x172f4, 0x17081,
- 0x0f97c, 0x1f273, 0x0f7a0, 0x0fd7c, 0x172f7, 0x0fd7a, 0x1bb77, 0x172fe,
- 0x1f270, 0x0fd73, 0x1bb7b, 0x1a1bc, 0x1bb7d, 0x0bbc3, 0x172f6, 0x0baeb,
- 0x0fb8f, 0x3f4f4, 0x3fdb4, 0x376c8, 0x3e7fa, 0x1ffd0, 0x62303, 0xb92f5,
- 0x1f261, 0x31189, 0x3fdb5, 0x2c7db, 0x376c9, 0x1fad6, 0x1fad1, 0x00015,
- 0x000f0, 0x002e0, 0x0058e, 0x005d7, 0x00c4d, 0x00fa1, 0x00bdb, 0x01756,
- 0x01f70, 0x02c19, 0x0313c, 0x0370f, 0x03cc0, 0x02ea8, 0x058c6, 0x058c7,
- 0x02eb7, 0x058d0, 0x07d18, 0x0aa58, 0x0b848, 0x05d9e, 0x05d6c, 0x0b84c,
- 0x0c589, 0x0b901, 0x163f8, 0x0bac9, 0x0b9c5, 0x0f93c, 0x188d8, 0x0bbc7,
- 0x160ec, 0x0fd6f, 0x188d9, 0x160ea, 0x0f7a7, 0x0f944, 0x0baab, 0x0dc3a,
- 0x188cf, 0x176fb, 0x2c7d8, 0x2c7d7, 0x1bb75, 0x5ce9e, 0x62302, 0x370ed,
- 0x176f4, 0x1ffd1, 0x370ef, 0x3f4f8, 0x376c7, 0x1ffe1, 0x376c6, 0x176ff,
- 0x6e1d8, 0x176f6, 0x17087, 0x0f5cd, 0x00035, 0x001a0, 0x0058b, 0x00aac,
- 0x00b9a, 0x0175f, 0x01e22, 0x01e8c, 0x01fb2, 0x0310b, 0x058d1, 0x0552e,
- 0x05c27, 0x0686e, 0x07ca7, 0x0c474, 0x0dc33, 0x07bf2, 0x05de9, 0x07a35,
- 0x0baaa, 0x0b9eb, 0x0fb95, 0x0b9b8, 0x17381, 0x1f262, 0x188cd, 0x17088,
- 0x172fa, 0x0f7a2, 0x1fad3, 0x0bac0, 0x3765c, 0x1fedf, 0x1f225, 0x1fad4,
- 0x2c7da, 0x5ce9d, 0x3e7f8, 0x1e203, 0x188d7, 0x00054, 0x002c0, 0x007a1,
- 0x00f78, 0x01b36, 0x01fa3, 0x0313a, 0x03436, 0x0343a, 0x07d1d, 0x07bd8,
- 0x05cdf, 0x0b846, 0x0b189, 0x0d9b8, 0x0fff8, 0x0d9be, 0x0c58a, 0x05dea,
- 0x0d1d3, 0x160e4, 0x1f26b, 0x188da, 0x1e202, 0x2c7d2, 0x163fe, 0x31193,
- 0x17782, 0x376c2, 0x2c7d1, 0x3fdb0, 0x3765d, 0x2c7d0, 0x1fad0, 0x1e201,
- 0x188dd, 0x2c7e2, 0x37657, 0x37655, 0x376c4, 0x376c0, 0x176ea, 0x0006f,
- 0x003cf, 0x00dd5, 0x01f23, 0x02c61, 0x02ed0, 0x05d54, 0x0552d, 0x07883,
- 0x0b1a8, 0x0b91c, 0x0babf, 0x0b902, 0x0f7aa, 0x0f7a5, 0x1a1e8, 0x1ffd6,
- 0x0babe, 0x1a1bf, 0x163f3, 0x1ffd8, 0x1fad7, 0x1f275, 0x1ffdc, 0x0007d,
- 0x005bc, 0x01549, 0x02a99, 0x03def, 0x06273, 0x079d6, 0x07d1b, 0x0aad3,
- 0x0d0fc, 0x2c7dd, 0x188d6, 0x0bac2, 0x2c7e1, 0x1bb76, 0x1a1bd, 0x31186,
- 0x0fd78, 0x1a1be, 0x31183, 0x3fdb6, 0x3f4f1, 0x37652, 0x1fad5, 0x3f4f9,
- 0x3e7ff, 0x5ce9c, 0x3765b, 0x31188, 0x17372, 0x000bd, 0x0078b, 0x01f21,
- 0x03c43, 0x03ded, 0x0aad6, 0x07ec1, 0x0f942, 0x05c86, 0x17089, 0x0babb,
- 0x1ffe8, 0x2c7de, 0x1f26e, 0x1fac4, 0x3f4f7, 0x37656, 0x1fa7d, 0x376c3,
- 0x3fdb3, 0x3118f, 0x1fac6, 0x000f8, 0x007ed, 0x01efd, 0x03e7a, 0x05c91,
- 0x0aad9, 0x0baec, 0x0dc32, 0x0f46e, 0x1e200, 0x176fa, 0x3765e, 0x3fdb7,
- 0x2c7d6, 0x3fdb9, 0x37654, 0x37658, 0x3118e, 0x1ffdb, 0x000f6, 0x00c43,
- 0x03106, 0x068ef, 0x0b84d, 0x0b188, 0x0bbcc, 0x1f264, 0x1bb69, 0x17386,
- 0x1fac0, 0x00171, 0x00f39, 0x03e41, 0x068ed, 0x0d9bc, 0x0f7a1, 0x1bb67,
- 0x1ffdd, 0x176f9, 0x001b9, 0x00f7d, 0x03f63, 0x0d0fd, 0x0b9ea, 0x188dc,
- 0x1fac3, 0x1a1f2, 0x31192, 0x1ffe4, 0x001f6, 0x01754, 0x06865, 0x0f309,
- 0x160e5, 0x176f5, 0x3765f, 0x1facc, 0x001e9, 0x01a1a, 0x06201, 0x0f105,
- 0x176f0, 0x002df, 0x01756, 0x05d6d, 0x163fa, 0x176ed, 0x00342, 0x02e40,
- 0x0d0ff, 0x17082, 0x003cd, 0x02a98, 0x0fffc, 0x2c7dc, 0x1fa7f, 0x003fe,
- 0x03764, 0x0fffd, 0x176fc, 0x1fac5, 0x002f7, 0x02ed1, 0x0fb97, 0x0058a,
- 0x02edc, 0x0bbc8, 0x005d4, 0x0623d, 0x160e8, 0x0062e, 0x05830, 0x163f9,
- 0x006eb, 0x06205, 0x1f274, 0x007de, 0x062c9, 0x1f265, 0x005c9, 0x05cde,
- 0x1ffd3, 0x005d4, 0x07988, 0x007ce, 0x0b849, 0x00b1b, 0x05c89, 0x1fac7,
- 0x00b93, 0x05c83, 0x00b9e, 0x0f14f, 0x00c4a, 0x0b9c7, 0x00dd4, 0x0c470,
- 0x1f271, 0x00f38, 0x0fb96, 0x176eb, 0x00fa0, 0x163f7, 0x00bb2, 0x0b91b,
- 0x00bbe, 0x0f102, 0x00f44, 0x0f946, 0x1facd, 0x00f79, 0x0d9bd, 0x0154d,
- 0x0bbc6, 0x00fd2, 0x160e7, 0x0172b, 0x188cb, 0x0175e, 0x0fd76, 0x0175c,
- 0x1bb71, 0x0189f, 0x1a1ee, 0x01f24, 0x1a1f6, 0x01ba7, 0x0bbca, 0x01f7d,
- 0x0ffff, 0x01f2e, 0x1bb65, 0x01bb5, 0x172f9, 0x01fef, 0x1f26c, 0x01f3e,
- 0x0fd77, 0x01762, 0x1bb6e, 0x01ef9, 0x172fc, 0x01fa0, 0x02ab7, 0x02e4a,
- 0x1f267, 0x01fb3, 0x1ffda, 0x02e42, 0x03101, 0x17780, 0x0313d, 0x03475,
- 0x17784, 0x03126, 0x1facf, 0x03c51, 0x17783, 0x03e40, 0x1ffe5, 0x03663,
- 0x1ffe0, 0x03e8f, 0x1f26d, 0x0343c, 0x03cc1, 0x176fd, 0x03e45, 0x02ec0,
- 0x03f61, 0x03dee, 0x03fd8, 0x0583e, 0x02e45, 0x03e59, 0x03d02, 0x05ce8,
- 0x05568, 0x176fe, 0x02f69, 0x1fad8, 0x058c1, 0x05c83, 0x1ffe6, 0x06271,
- 0x06e1c, 0x062c7, 0x068e1, 0x0552f, 0x06864, 0x06866, 0x06e99, 0x05cbc,
- 0x07ca5, 0x078a1, 0x05c82, 0x07dcf, 0x0623b, 0x0623e, 0x068e8, 0x07a36,
- 0x05d9c, 0x0b077, 0x07cf3, 0x07a34, 0x07ca4, 0x07d19, 0x079d2, 0x07d1c,
- 0x07bd9, 0x0b84a, 0x0fb94, 0x0aad5, 0x0dc30, 0x07bf3, 0x0baee, 0x0b07a,
- 0x0c472, 0x0b91e, 0x0d9ba, 0x05d9f, 0x0d0fe, 0x0b9c6, 0x05c87, 0x0f14e,
- 0x0baed, 0x0b92e, 0x0f103, 0x0b9c4, 0x0fb91, 0x0d9bb, 0x0b1ab, 0x0c58d,
- 0x0fffe, 0x0f93b, 0x0f941, 0x0baea, 0x0b91f, 0x0f5cc, 0x0d9bf, 0x0f943,
- 0x0f104, 0x1f260, 0x0fb92, 0x0f93f, 0x0f3a6, 0x0bac7, 0x0f7ab, 0x0bac6,
- 0x17383, 0x0fd6d, 0x0bae9, 0x0fd6e, 0x1e74f, 0x188ca, 0x1f227, 0x0fb93,
- 0x0fb90, 0x0fff7, 0x17085, 0x17083, 0x160e1, 0x17084, 0x0f93e, 0x160e2,
- 0x160c6, 0x1a1f1, 0x1bb6f, 0x17384, 0x0fd70, 0x1f263, 0x188d5, 0x173a6,
- 0x0f5ce, 0x163f2, 0x0fd71, 0x1ffd2, 0x160c4, 0x1ffd4, 0x2c7d3, 0x1bb74,
-};
-
-static const uint8_t coef3_huffbits[1072] = {
- 9, 7, 2, 3, 4, 4, 5, 5,
- 6, 6, 6, 6, 7, 7, 7, 7,
- 7, 8, 8, 8, 8, 8, 8, 8,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 10, 10, 10, 10, 10, 10, 10,
- 10, 10, 10, 11, 11, 11, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 11,
- 11, 12, 11, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13,
- 13, 14, 13, 14, 14, 13, 14, 13,
- 13, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 14, 14, 15, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 14, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 14, 15, 15, 15, 15, 15, 15,
- 15, 15, 15, 16, 15, 16, 16, 16,
- 16, 15, 15, 16, 16, 16, 16, 16,
- 15, 16, 16, 16, 15, 16, 15, 15,
- 16, 15, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 16, 17, 16, 17, 17, 16,
- 17, 16, 17, 16, 16, 17, 17, 17,
- 16, 17, 16, 16, 17, 16, 17, 16,
- 17, 17, 16, 16, 17, 17, 17, 17,
- 17, 17, 17, 17, 16, 17, 17, 16,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 16, 18, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 18,
- 17, 17, 17, 17, 18, 17, 17, 18,
- 19, 17, 17, 17, 18, 17, 17, 17,
- 18, 18, 18, 17, 17, 17, 18, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 18, 18, 18, 18, 18, 18, 18, 18,
- 18, 18, 17, 18, 18, 18, 18, 17,
- 18, 18, 18, 17, 17, 18, 18, 18,
- 18, 19, 18, 18, 19, 19, 20, 18,
- 19, 18, 19, 19, 18, 19, 20, 18,
- 19, 4, 6, 7, 8, 9, 9, 9,
- 10, 10, 10, 11, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14, 14,
- 14, 14, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 15, 15,
- 15, 15, 15, 15, 16, 15, 15, 15,
- 15, 16, 16, 15, 16, 16, 15, 16,
- 17, 17, 17, 17, 17, 16, 16, 16,
- 16, 16, 17, 17, 17, 16, 18, 17,
- 17, 17, 18, 17, 17, 18, 17, 17,
- 17, 17, 17, 18, 17, 18, 18, 18,
- 17, 17, 18, 19, 18, 18, 17, 17,
- 18, 18, 18, 18, 19, 17, 17, 18,
- 20, 19, 19, 18, 19, 18, 19, 19,
- 19, 19, 17, 5, 7, 9, 10, 10,
- 11, 11, 12, 12, 12, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 15,
- 14, 15, 15, 15, 15, 15, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 15, 16, 16, 17, 17, 17,
- 16, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 17, 16,
- 16, 19, 18, 18, 19, 17, 19, 20,
- 17, 18, 18, 18, 18, 18, 18, 6,
- 8, 10, 11, 12, 12, 12, 13, 13,
- 13, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 16, 16, 16, 16, 16,
- 16, 17, 17, 17, 16, 16, 17, 17,
- 17, 17, 17, 17, 17, 16, 16, 16,
- 17, 18, 18, 18, 17, 19, 19, 18,
- 18, 17, 18, 19, 18, 17, 18, 18,
- 19, 18, 17, 17, 6, 9, 11, 12,
- 13, 13, 13, 14, 14, 14, 15, 15,
- 15, 15, 15, 16, 16, 16, 16, 16,
- 16, 17, 16, 17, 17, 17, 17, 17,
- 17, 17, 18, 17, 18, 17, 17, 18,
- 18, 19, 19, 17, 17, 7, 10, 12,
- 13, 13, 14, 14, 14, 14, 15, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 17, 17, 17, 18, 17, 18,
- 18, 18, 18, 18, 18, 18, 18, 17,
- 17, 18, 18, 18, 18, 18, 18, 7,
- 10, 12, 13, 14, 15, 15, 15, 15,
- 16, 16, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 18, 17, 17, 8,
- 11, 13, 14, 15, 15, 15, 15, 16,
- 16, 18, 17, 17, 18, 17, 17, 18,
- 17, 17, 18, 18, 19, 18, 18, 19,
- 19, 19, 18, 18, 18, 8, 11, 13,
- 14, 15, 16, 16, 16, 16, 17, 17,
- 17, 18, 17, 18, 19, 18, 18, 18,
- 18, 18, 18, 8, 12, 14, 15, 15,
- 16, 16, 16, 17, 17, 18, 18, 18,
- 18, 18, 18, 18, 18, 17, 9, 12,
- 14, 15, 16, 16, 17, 17, 17, 17,
- 18, 9, 12, 14, 15, 16, 17, 17,
- 17, 18, 9, 13, 15, 16, 17, 17,
- 18, 17, 18, 17, 9, 13, 15, 16,
- 17, 18, 18, 18, 10, 13, 15, 16,
- 18, 10, 14, 16, 17, 18, 10, 14,
- 16, 17, 10, 14, 16, 18, 18, 10,
- 14, 16, 18, 18, 11, 15, 16, 11,
- 15, 17, 11, 15, 17, 11, 15, 17,
- 11, 15, 17, 11, 15, 17, 12, 16,
- 17, 12, 15, 12, 16, 12, 16, 18,
- 12, 16, 12, 16, 12, 16, 12, 16,
- 17, 12, 16, 18, 12, 17, 13, 16,
- 13, 16, 13, 16, 18, 13, 16, 13,
- 17, 13, 17, 13, 17, 13, 17, 13,
- 17, 13, 17, 13, 17, 13, 17, 13,
- 16, 13, 17, 13, 17, 13, 17, 14,
- 17, 14, 17, 14, 17, 14, 14, 14,
- 17, 14, 17, 14, 14, 18, 14, 14,
- 18, 14, 18, 14, 18, 14, 17, 14,
- 17, 14, 17, 14, 14, 18, 14, 15,
- 15, 15, 14, 15, 15, 14, 15, 15,
- 15, 18, 15, 18, 15, 15, 17, 15,
- 15, 15, 15, 15, 15, 15, 15, 15,
- 15, 15, 16, 15, 15, 15, 15, 16,
- 16, 16, 16, 16, 15, 15, 15, 15,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 17, 16, 16,
- 16, 17, 16, 16, 16, 17, 17, 17,
- 17, 17, 16, 17, 17, 17, 17, 16,
- 16, 16, 17, 17, 17, 17, 16, 17,
- 17, 17, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 17, 17, 17, 18, 17,
-};
-
-static const uint32_t coef4_huffcodes[476] = {
- 0x00f01, 0x0001e, 0x00000, 0x00004, 0x00006, 0x0000d, 0x0000a, 0x00017,
- 0x0001d, 0x00017, 0x0002c, 0x00031, 0x00039, 0x0003e, 0x00039, 0x0005a,
- 0x00066, 0x00070, 0x0007b, 0x00070, 0x00077, 0x000af, 0x000c9, 0x000f2,
- 0x000f4, 0x000b2, 0x000e3, 0x0015b, 0x0015d, 0x00181, 0x0019d, 0x001e3,
- 0x001c5, 0x002b5, 0x002db, 0x00338, 0x003c3, 0x003cc, 0x003f0, 0x002cd,
- 0x003fa, 0x003a1, 0x005b4, 0x00657, 0x007ab, 0x0074d, 0x0074c, 0x00ac1,
- 0x00ac5, 0x0076b, 0x00ca8, 0x00f04, 0x00f00, 0x00fe3, 0x00f3c, 0x00f10,
- 0x00f39, 0x00fe6, 0x00e26, 0x00e90, 0x016c5, 0x01827, 0x01954, 0x015c5,
- 0x01958, 0x01f8a, 0x01c4a, 0x02b0f, 0x02b41, 0x02b0e, 0x033c6, 0x03050,
- 0x01c4f, 0x02d88, 0x0305c, 0x03c18, 0x02b4f, 0x02cc2, 0x03a47, 0x05680,
- 0x0569d, 0x06442, 0x06443, 0x06446, 0x0656e, 0x06444, 0x07120, 0x0748a,
- 0x0c1ba, 0x07e22, 0x07aa6, 0x07f25, 0x07aa7, 0x07e20, 0x0c11b, 0x0c118,
- 0x07aa5, 0x0ad0a, 0x0f389, 0x19ebb, 0x0caad, 0x0fe42, 0x0fe40, 0x16c34,
- 0x2b4e5, 0x33d65, 0x16c30, 0x1e7ae, 0x1e25c, 0x18370, 0x1e703, 0x19eba,
- 0x16c37, 0x0e234, 0x16c6e, 0x00004, 0x0002a, 0x00061, 0x00075, 0x000cb,
- 0x000ff, 0x00190, 0x001eb, 0x001d1, 0x002b9, 0x00307, 0x00339, 0x0033f,
- 0x003fb, 0x003b4, 0x0060c, 0x00679, 0x00645, 0x0067d, 0x0078a, 0x007e3,
- 0x00749, 0x00ac4, 0x00ad2, 0x00ae3, 0x00c10, 0x00c16, 0x00ad1, 0x00cf4,
- 0x00fe2, 0x01586, 0x00e9d, 0x019f1, 0x01664, 0x01e26, 0x01d38, 0x02b4d,
- 0x033c5, 0x01fc2, 0x01fc3, 0x01d28, 0x03c1d, 0x0598e, 0x0f094, 0x07aa4,
- 0x0ad38, 0x0ac0c, 0x0c11a, 0x079ea, 0x0c881, 0x0fe44, 0x0b635, 0x0ac0d,
- 0x0b61e, 0x05987, 0x07121, 0x0f382, 0x0f387, 0x0e237, 0x0fe47, 0x0f383,
- 0x0f091, 0x0f385, 0x0e233, 0x182ee, 0x19eb8, 0x1663e, 0x0f093, 0x00014,
- 0x00058, 0x00159, 0x00167, 0x00300, 0x003d4, 0x005b5, 0x0079d, 0x0076a,
- 0x00b67, 0x00b60, 0x00f05, 0x00cf0, 0x00f17, 0x00e95, 0x01822, 0x01913,
- 0x016c2, 0x0182f, 0x01959, 0x01fcb, 0x01e27, 0x01c40, 0x033c7, 0x01e7b,
- 0x01c49, 0x02d89, 0x01e23, 0x01660, 0x03f12, 0x02cc6, 0x033e1, 0x05b34,
- 0x0609a, 0x06569, 0x07488, 0x07e21, 0x0cf5f, 0x0712c, 0x0389d, 0x067cf,
- 0x07f28, 0x1663f, 0x33d67, 0x1663d, 0x1e25d, 0x3c1ab, 0x15c44, 0x16c36,
- 0x0001f, 0x000ec, 0x00323, 0x005b2, 0x0079f, 0x00ac2, 0x00f16, 0x00e9e,
- 0x01956, 0x01e0f, 0x019ea, 0x01666, 0x02b89, 0x02b02, 0x02d8c, 0x03c1b,
- 0x03c19, 0x032b5, 0x03f9c, 0x02ccf, 0x03897, 0x05b35, 0x0ad02, 0x07f29,
- 0x06441, 0x03884, 0x07888, 0x0784e, 0x06568, 0x0c1bb, 0x05986, 0x067cc,
- 0x0fe49, 0x0fe48, 0x0c1bc, 0x0fe41, 0x18371, 0x1663c, 0x0e231, 0x0711e,
- 0x0ad09, 0x0f092, 0x0002d, 0x001db, 0x00781, 0x00c1a, 0x00f55, 0x01580,
- 0x01ea8, 0x02d9b, 0x032af, 0x03f16, 0x03c1c, 0x07834, 0x03c45, 0x0389c,
- 0x067ce, 0x06445, 0x0c1b9, 0x07889, 0x07f3a, 0x0784f, 0x07f2b, 0x0ad0b,
- 0x0f090, 0x0c11d, 0x0e94e, 0x0711f, 0x0e9f1, 0x0f38e, 0x079e9, 0x0ad03,
- 0x0f09b, 0x0caae, 0x0fe46, 0x2b4e6, 0x0e9f0, 0x19eb6, 0x67ac1, 0x67ac0,
- 0x33d66, 0x0f388, 0x00071, 0x003a0, 0x00ca9, 0x01829, 0x01d39, 0x02b43,
- 0x02cc4, 0x06554, 0x0f09a, 0x0b61f, 0x067cd, 0x0711c, 0x0b636, 0x07f2a,
- 0x0b634, 0x0c11f, 0x0cf5e, 0x0b61d, 0x0f06b, 0x0caab, 0x0c1be, 0x0e94c,
- 0x0f099, 0x182ed, 0x0e94f, 0x0c119, 0x0e232, 0x2b4e4, 0x0f38a, 0x19eb4,
- 0x1e25f, 0x0e94d, 0x000b7, 0x00785, 0x016cc, 0x03051, 0x033c4, 0x0656f,
- 0x03891, 0x0711d, 0x0caaf, 0x0f097, 0x07489, 0x0f098, 0x0c880, 0x0caaa,
- 0x0f386, 0x19eb7, 0x16c6f, 0x0f384, 0x182e8, 0x182e9, 0x0e230, 0x1e700,
- 0x33d62, 0x33d63, 0x33d64, 0x16c33, 0x0e216, 0x000fd, 0x00c15, 0x01665,
- 0x03c4a, 0x07f3b, 0x07896, 0x0c11c, 0x0e215, 0x16c32, 0x0f38b, 0x0f38d,
- 0x182ea, 0x1e701, 0x712df, 0x15c46, 0x00194, 0x00fe0, 0x03f13, 0x0748b,
- 0x0f096, 0x0cf80, 0x1e25e, 0xe25bd, 0x33d61, 0x16c31, 0x001f9, 0x01912,
- 0x05710, 0x0f3d0, 0x0c1bf, 0x00301, 0x01e24, 0x0ad08, 0x003cd, 0x01c41,
- 0x0c1bd, 0x00563, 0x03a52, 0x0f3d1, 0x00570, 0x02cce, 0x0e217, 0x0067b,
- 0x0655d, 0x0074b, 0x06447, 0x00c12, 0x074fb, 0x00f08, 0x0b61c, 0x00e22,
- 0x0fe43, 0x016c7, 0x01836, 0x019f2, 0x01c43, 0x01d3f, 0x01fcf, 0x02b4c,
- 0x0304c, 0x032b6, 0x03a46, 0x05607, 0x03f17, 0x02cc5, 0x0609b, 0x0655c,
- 0x07e23, 0x067c1, 0x07f26, 0x07f27, 0x0f095, 0x0e9f3, 0x0cf81, 0x0c11e,
- 0x0caac, 0x0f38f, 0x0e9f2, 0x074fa, 0x0e236, 0x0fe45, 0x1c428, 0x0e235,
- 0x182ef, 0x19eb5, 0x0f3d6, 0x182ec, 0x16c35, 0x0f38c, 0x2b4e7, 0x15c47,
- 0xe25bc, 0x1e702, 0x1c4b6, 0x0e25a, 0x3c1aa, 0x15c45, 0x1c429, 0x19eb9,
- 0x1e7af, 0x182eb, 0x1e0d4, 0x3896e,
-};
-
-static const uint8_t coef4_huffbits[476] = {
- 12, 6, 2, 3, 4, 4, 5, 5,
- 5, 6, 6, 6, 6, 6, 7, 7,
- 7, 7, 7, 8, 8, 8, 8, 8,
- 8, 9, 9, 9, 9, 9, 9, 9,
- 10, 10, 10, 10, 10, 10, 10, 11,
- 10, 11, 11, 11, 11, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 13, 13, 13, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 14, 14, 14, 14, 14, 15, 15, 15,
- 15, 15, 15, 15, 15, 15, 16, 16,
- 16, 15, 15, 15, 15, 15, 16, 16,
- 15, 16, 16, 17, 16, 16, 16, 17,
- 18, 18, 17, 17, 17, 17, 17, 17,
- 17, 17, 17, 4, 6, 7, 8, 8,
- 8, 9, 9, 10, 10, 10, 10, 10,
- 10, 11, 11, 11, 11, 11, 11, 11,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 13, 13, 13, 14, 13, 14, 14,
- 14, 13, 13, 14, 14, 16, 16, 15,
- 16, 16, 16, 15, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 17, 16, 16,
- 16, 16, 17, 17, 17, 18, 16, 5,
- 8, 9, 10, 10, 10, 11, 11, 12,
- 12, 12, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 14, 14, 13,
- 14, 14, 13, 14, 14, 15, 14, 15,
- 15, 15, 16, 15, 16, 16, 15, 15,
- 15, 18, 18, 18, 17, 18, 17, 17,
- 6, 9, 10, 11, 11, 12, 12, 13,
- 13, 13, 13, 14, 14, 14, 14, 14,
- 14, 14, 14, 15, 15, 15, 16, 15,
- 15, 15, 15, 15, 15, 16, 16, 15,
- 16, 16, 16, 16, 17, 18, 17, 16,
- 16, 16, 7, 10, 11, 12, 12, 13,
- 13, 14, 14, 14, 14, 15, 14, 15,
- 15, 15, 16, 15, 15, 15, 15, 16,
- 16, 16, 17, 16, 17, 16, 15, 16,
- 16, 16, 16, 18, 17, 17, 19, 19,
- 18, 16, 7, 11, 12, 13, 14, 14,
- 15, 15, 16, 16, 15, 16, 16, 15,
- 16, 16, 16, 16, 16, 16, 16, 17,
- 16, 17, 17, 16, 17, 18, 16, 17,
- 17, 17, 8, 11, 13, 14, 14, 15,
- 15, 16, 16, 16, 16, 16, 16, 16,
- 16, 17, 17, 16, 17, 17, 17, 17,
- 18, 18, 18, 17, 17, 8, 12, 14,
- 14, 15, 15, 16, 17, 17, 16, 16,
- 17, 17, 20, 17, 9, 12, 14, 16,
- 16, 16, 17, 21, 18, 17, 9, 13,
- 15, 16, 16, 10, 13, 16, 10, 14,
- 16, 11, 15, 16, 11, 15, 17, 11,
- 15, 12, 15, 12, 16, 12, 16, 13,
- 16, 13, 13, 13, 14, 14, 13, 14,
- 14, 14, 15, 15, 14, 15, 15, 15,
- 15, 15, 15, 15, 16, 17, 16, 16,
- 16, 16, 17, 16, 17, 16, 18, 17,
- 17, 17, 16, 17, 17, 16, 18, 17,
- 21, 17, 18, 17, 18, 17, 18, 17,
- 17, 17, 17, 19,
-};
-
-static const uint32_t coef5_huffcodes[435] = {
- 0x00347, 0x0000b, 0x00001, 0x00001, 0x0000c, 0x00004, 0x00010, 0x00015,
- 0x0001f, 0x0000b, 0x00023, 0x00026, 0x00029, 0x00035, 0x00037, 0x00001,
- 0x00015, 0x0001a, 0x0001d, 0x0001c, 0x0001e, 0x0004e, 0x00049, 0x00051,
- 0x00078, 0x00004, 0x00000, 0x00008, 0x0000d, 0x0007b, 0x00005, 0x00032,
- 0x00095, 0x00091, 0x00096, 0x000a1, 0x000d9, 0x00003, 0x00019, 0x00061,
- 0x00066, 0x00060, 0x00017, 0x0000e, 0x00063, 0x001a0, 0x001b7, 0x001e6,
- 0x001e7, 0x001b6, 0x00018, 0x001e8, 0x00038, 0x00031, 0x00005, 0x0003d,
- 0x00027, 0x001ea, 0x0001a, 0x000c5, 0x000f9, 0x000ff, 0x000db, 0x00250,
- 0x000fc, 0x0025c, 0x00008, 0x00075, 0x003d7, 0x003d3, 0x001b0, 0x0007c,
- 0x003ca, 0x00036, 0x00189, 0x004a6, 0x004a2, 0x004fb, 0x000c0, 0x0007f,
- 0x0009a, 0x00311, 0x0006e, 0x0009b, 0x0068c, 0x006c0, 0x00484, 0x00012,
- 0x000c3, 0x0094f, 0x00979, 0x009f9, 0x00d09, 0x00da6, 0x00da8, 0x00901,
- 0x000c1, 0x00373, 0x00d08, 0x009fa, 0x00d8b, 0x00d85, 0x00d86, 0x000df,
- 0x006e2, 0x000ce, 0x00f24, 0x009fe, 0x001f7, 0x007c1, 0x000cf, 0x009fc,
- 0x009ff, 0x00d89, 0x00da9, 0x009fd, 0x001f8, 0x01a36, 0x0128c, 0x0129d,
- 0x01a37, 0x00196, 0x003ea, 0x00f8b, 0x00d93, 0x01e45, 0x01e58, 0x01e4b,
- 0x01e59, 0x013f1, 0x00309, 0x00265, 0x00308, 0x0243a, 0x027e1, 0x00f89,
- 0x00324, 0x03cbc, 0x03c86, 0x03695, 0x0243c, 0x0243b, 0x0243e, 0x01e4a,
- 0x003a5, 0x03468, 0x03428, 0x03c84, 0x027e0, 0x025e2, 0x01880, 0x00197,
- 0x00325, 0x03cb7, 0x0791e, 0x007ec, 0x06c75, 0x004c8, 0x04bc7, 0x004c6,
- 0x00983, 0x0481e, 0x01b53, 0x0251b, 0x01b58, 0x00984, 0x04fa8, 0x03cbb,
- 0x00f8a, 0x00322, 0x0346a, 0x0243d, 0x00326, 0x03469, 0x0481f, 0x0481d,
- 0x00746, 0x09032, 0x01b50, 0x01d13, 0x0d8e4, 0x0481b, 0x06c74, 0x0796b,
- 0x07969, 0x00985, 0x0d8e3, 0x00986, 0x00fa2, 0x01301, 0x06c7c, 0x00987,
- 0x03cb8, 0x0f4af, 0x00e88, 0x1b1c0, 0x00fce, 0x033eb, 0x03f6a, 0x03f69,
- 0x00fcf, 0x0791f, 0x004c9, 0x04871, 0x00fcd, 0x00982, 0x00fcc, 0x00fa3,
- 0x01d12, 0x0796c, 0x01b47, 0x00321, 0x0796a, 0x0d8e2, 0x04872, 0x04873,
- 0x0000e, 0x00014, 0x0000a, 0x000a0, 0x00012, 0x0007d, 0x001a2, 0x0003b,
- 0x0025f, 0x000dd, 0x0027c, 0x00343, 0x00368, 0x0036b, 0x0003e, 0x001fa,
- 0x00485, 0x001b3, 0x0007f, 0x001b1, 0x0019e, 0x004ba, 0x007ad, 0x00339,
- 0x00066, 0x007a4, 0x00793, 0x006c6, 0x0007e, 0x000f1, 0x00372, 0x009fb,
- 0x00d83, 0x00d8a, 0x00947, 0x009f4, 0x001d0, 0x01b09, 0x01b4b, 0x007ec,
- 0x003e1, 0x000ca, 0x003ec, 0x02539, 0x04fa9, 0x01b57, 0x03429, 0x03d2a,
- 0x00d97, 0x003a7, 0x00dc0, 0x00d96, 0x00dc1, 0x007eb, 0x03cba, 0x00c43,
- 0x00c41, 0x01b52, 0x007ef, 0x00323, 0x03cb9, 0x03c83, 0x007d0, 0x007ed,
- 0x06c7f, 0x09033, 0x03f6c, 0x36383, 0x1e95d, 0x06c78, 0x00747, 0x01b51,
- 0x00022, 0x00016, 0x00039, 0x00252, 0x00079, 0x00486, 0x00338, 0x00369,
- 0x00d88, 0x00026, 0x00d87, 0x00f4b, 0x00d82, 0x00027, 0x001e1, 0x01a15,
- 0x007c7, 0x012f0, 0x001e0, 0x006d0, 0x01a16, 0x01e44, 0x01e5f, 0x03690,
- 0x00d90, 0x00c42, 0x00daf, 0x00d92, 0x00f80, 0x00cfb, 0x0342f, 0x0487f,
- 0x01b46, 0x07968, 0x00d95, 0x00d91, 0x01b55, 0x03f68, 0x04bc6, 0x03cbd,
- 0x00f81, 0x00320, 0x00069, 0x000fe, 0x006d5, 0x0033f, 0x000de, 0x007c6,
- 0x01e40, 0x00d94, 0x00f88, 0x03c8e, 0x03694, 0x00dae, 0x00dad, 0x00267,
- 0x003a6, 0x00327, 0x0487e, 0x007ee, 0x00749, 0x004c7, 0x03692, 0x01b56,
- 0x00fd1, 0x07a56, 0x06c77, 0x09031, 0x00748, 0x06c7a, 0x0796d, 0x033ea,
- 0x06c76, 0x00fd0, 0x36382, 0x1e417, 0x00745, 0x04faf, 0x0d8e1, 0x03f6b,
- 0x1e95c, 0x04fad, 0x0009e, 0x004bd, 0x0067c, 0x01b08, 0x003eb, 0x01b45,
- 0x03691, 0x0d8e5, 0x07904, 0x00981, 0x007ea, 0x019f4, 0x06c7d, 0x04fab,
- 0x04fac, 0x06c7e, 0x01300, 0x06c7b, 0x0006f, 0x003f7, 0x03c85, 0x004c4,
- 0x0001e, 0x006e1, 0x03693, 0x01b44, 0x00241, 0x01e46, 0x0019d, 0x00266,
- 0x004bb, 0x02538, 0x007ac, 0x01b54, 0x00902, 0x04870, 0x00da7, 0x00900,
- 0x00185, 0x06c79, 0x006e3, 0x003e9, 0x01e94, 0x003ed, 0x003f2, 0x0342e,
- 0x0346b, 0x0251a, 0x004c5, 0x01881, 0x0481c, 0x01b59, 0x03c87, 0x04fae,
- 0x007e9, 0x03f6d, 0x0f20a, 0x09030, 0x04faa, 0x0d8e6, 0x03f6f, 0x0481a,
- 0x03f6e, 0x1e416, 0x0d8e7,
-};
-
-static const uint8_t coef5_huffbits[435] = {
- 10, 4, 2, 4, 4, 5, 5, 5,
- 5, 6, 6, 6, 6, 6, 6, 7,
- 7, 7, 7, 7, 7, 7, 7, 7,
- 7, 8, 8, 8, 8, 7, 8, 8,
- 8, 8, 8, 8, 8, 9, 9, 9,
- 9, 9, 9, 9, 9, 9, 9, 9,
- 9, 9, 10, 9, 10, 10, 10, 10,
- 10, 9, 10, 10, 10, 10, 10, 10,
- 10, 10, 11, 11, 10, 10, 11, 11,
- 10, 11, 11, 11, 11, 11, 12, 12,
- 12, 12, 12, 12, 11, 11, 11, 12,
- 12, 12, 12, 12, 12, 12, 12, 12,
- 12, 12, 12, 12, 12, 12, 12, 13,
- 13, 13, 12, 12, 13, 13, 13, 12,
- 12, 12, 12, 12, 13, 13, 13, 13,
- 13, 14, 14, 14, 14, 13, 13, 13,
- 13, 13, 14, 14, 14, 14, 14, 14,
- 15, 14, 14, 14, 14, 14, 14, 13,
- 14, 14, 14, 14, 14, 14, 15, 14,
- 15, 14, 15, 15, 15, 15, 15, 15,
- 16, 15, 15, 14, 15, 16, 15, 14,
- 14, 15, 14, 14, 15, 14, 15, 15,
- 15, 16, 15, 17, 16, 15, 15, 15,
- 15, 16, 16, 16, 16, 17, 15, 16,
- 14, 16, 16, 17, 16, 16, 16, 16,
- 16, 15, 15, 15, 16, 16, 16, 16,
- 17, 15, 15, 15, 15, 16, 15, 15,
- 4, 7, 8, 8, 9, 9, 9, 10,
- 10, 10, 10, 10, 10, 10, 11, 11,
- 11, 11, 11, 11, 11, 11, 11, 12,
- 12, 11, 11, 11, 12, 12, 12, 12,
- 12, 12, 12, 12, 13, 13, 13, 13,
- 12, 13, 14, 14, 15, 15, 14, 14,
- 14, 14, 14, 14, 14, 15, 14, 14,
- 14, 15, 15, 15, 14, 14, 15, 15,
- 15, 16, 16, 18, 17, 15, 15, 15,
- 6, 9, 10, 10, 11, 11, 12, 12,
- 12, 13, 12, 12, 12, 13, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 14,
- 14, 14, 14, 14, 14, 14, 14, 15,
- 15, 15, 14, 14, 15, 16, 15, 14,
- 14, 15, 7, 10, 11, 12, 13, 13,
- 13, 14, 14, 14, 14, 14, 14, 14,
- 14, 15, 15, 15, 15, 15, 14, 15,
- 16, 15, 15, 16, 15, 15, 15, 16,
- 15, 16, 18, 17, 15, 15, 16, 16,
- 17, 15, 8, 11, 13, 13, 14, 15,
- 14, 16, 15, 16, 15, 15, 15, 15,
- 15, 15, 17, 15, 9, 12, 14, 15,
- 10, 13, 14, 15, 10, 13, 11, 14,
- 11, 14, 11, 15, 12, 15, 12, 12,
- 13, 15, 13, 14, 13, 14, 14, 14,
- 14, 14, 15, 15, 15, 15, 14, 15,
- 15, 16, 16, 16, 15, 16, 16, 15,
- 16, 17, 16,
-};
-
-static const uint16_t levels0[60] = {
-317, 92, 62, 60, 19, 17, 10, 7,
- 6, 5, 5, 3, 3, 3, 2, 2,
- 2, 2, 2, 2, 2, 1, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels1[40] = {
-311, 91, 61, 28, 10, 6, 5, 2,
- 2, 2, 2, 2, 2, 2, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const uint16_t levels2[340] = {
-181,110, 78, 63, 61, 62, 60, 61,
- 33, 41, 41, 19, 17, 19, 12, 11,
- 9, 11, 10, 6, 8, 7, 6, 4,
- 5, 5, 4, 4, 3, 4, 3, 5,
- 3, 4, 3, 3, 3, 3, 3, 3,
- 2, 2, 4, 2, 3, 2, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 3, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 1, 2, 1, 2, 2,
- 2, 2, 1, 2, 1, 1, 1, 2,
- 2, 1, 2, 1, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels3[180] = {
-351,122, 76, 61, 41, 42, 24, 30,
- 22, 19, 11, 9, 10, 8, 5, 5,
- 4, 5, 5, 3, 3, 3, 3, 3,
- 3, 3, 2, 2, 3, 2, 2, 2,
- 3, 3, 2, 2, 2, 3, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 1, 1,
- 2, 2, 1, 2, 1, 2, 2, 2,
- 2, 2, 2, 1, 2, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 2,
- 2, 1, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1,
-};
-
-static const uint16_t levels4[70] = {
-113, 68, 49, 42, 40, 32, 27, 15,
- 10, 5, 3, 3, 3, 3, 2, 2,
- 2, 2, 2, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1,
-};
-
-static const uint16_t levels5[40] = {
-214, 72, 42, 40, 18, 4, 4, 2,
- 2, 2, 2, 2, 1, 1, 2, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-static const CoefVLCTable coef_vlcs[6] = {
- {
- sizeof(coef0_huffbits), coef0_huffcodes, coef0_huffbits, levels0,
- },
- {
- sizeof(coef1_huffbits), coef1_huffcodes, coef1_huffbits, levels1,
- },
- {
- sizeof(coef2_huffbits), coef2_huffcodes, coef2_huffbits, levels2,
- },
- {
- sizeof(coef3_huffbits), coef3_huffcodes, coef3_huffbits, levels3,
- },
- {
- sizeof(coef4_huffbits), coef4_huffcodes, coef4_huffbits, levels4,
- },
- {
- sizeof(coef5_huffbits), coef5_huffcodes, coef5_huffbits, levels5,
- },
-};
+++ /dev/null
-/*
- * WMA compatible decoder
- * Copyright (c) 2002 The FFmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file wmadec.c
- * WMA compatible decoder.
- */
-
-#include "avcodec.h"
-#include "dsputil.h"
-
-/* size of blocks */
-#define BLOCK_MIN_BITS 7
-#define BLOCK_MAX_BITS 11
-#define BLOCK_MAX_SIZE (1 << BLOCK_MAX_BITS)
-
-#define BLOCK_NB_SIZES (BLOCK_MAX_BITS - BLOCK_MIN_BITS + 1)
-
-/* XXX: find exact max size */
-#define HIGH_BAND_MAX_SIZE 16
-
-#define NB_LSP_COEFS 10
-
-/* XXX: is it a suitable value ? */
-#define MAX_CODED_SUPERFRAME_SIZE 4096
-
-#define MAX_CHANNELS 2
-
-#define NOISE_TAB_SIZE 8192
-
-#define LSP_POW_BITS 7
-
-typedef struct WMADecodeContext {
- GetBitContext gb;
- int sample_rate;
- int nb_channels;
- int bit_rate;
- int version; /* 1 = 0x160 (WMAV1), 2 = 0x161 (WMAV2) */
- int block_align;
- int use_bit_reservoir;
- int use_variable_block_len;
- int use_exp_vlc; /* exponent coding: 0 = lsp, 1 = vlc + delta */
- int use_noise_coding; /* true if perceptual noise is added */
- int byte_offset_bits;
- VLC exp_vlc;
- int exponent_sizes[BLOCK_NB_SIZES];
- uint16_t exponent_bands[BLOCK_NB_SIZES][25];
- int high_band_start[BLOCK_NB_SIZES]; /* index of first coef in high band */
- int coefs_start; /* first coded coef */
- int coefs_end[BLOCK_NB_SIZES]; /* max number of coded coefficients */
- int exponent_high_sizes[BLOCK_NB_SIZES];
- int exponent_high_bands[BLOCK_NB_SIZES][HIGH_BAND_MAX_SIZE];
- VLC hgain_vlc;
-
- /* coded values in high bands */
- int high_band_coded[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
- int high_band_values[MAX_CHANNELS][HIGH_BAND_MAX_SIZE];
-
- /* there are two possible tables for spectral coefficients */
- VLC coef_vlc[2];
- uint16_t *run_table[2];
- uint16_t *level_table[2];
- /* frame info */
- int frame_len; /* frame length in samples */
- int frame_len_bits; /* frame_len = 1 << frame_len_bits */
- int nb_block_sizes; /* number of block sizes */
- /* block info */
- int reset_block_lengths;
- int block_len_bits; /* log2 of current block length */
- int next_block_len_bits; /* log2 of next block length */
- int prev_block_len_bits; /* log2 of prev block length */
- int block_len; /* block length in samples */
- int block_num; /* block number in current frame */
- int block_pos; /* current position in frame */
- uint8_t ms_stereo; /* true if mid/side stereo mode */
- uint8_t channel_coded[MAX_CHANNELS]; /* true if channel is coded */
- float exponents[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16)));
- float max_exponent[MAX_CHANNELS];
- int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
- float coefs[MAX_CHANNELS][BLOCK_MAX_SIZE] __attribute__((aligned(16)));
- MDCTContext mdct_ctx[BLOCK_NB_SIZES];
- float *windows[BLOCK_NB_SIZES];
- FFTSample mdct_tmp[BLOCK_MAX_SIZE] __attribute__((aligned(16))); /* temporary storage for imdct */
- /* output buffer for one frame and the last for IMDCT windowing */
- float frame_out[MAX_CHANNELS][BLOCK_MAX_SIZE * 2] __attribute__((aligned(16)));
- /* last frame info */
- uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */
- int last_bitoffset;
- int last_superframe_len;
- float noise_table[NOISE_TAB_SIZE];
- int noise_index;
- float noise_mult; /* XXX: suppress that and integrate it in the noise array */
- /* lsp_to_curve tables */
- float lsp_cos_table[BLOCK_MAX_SIZE];
- float lsp_pow_e_table[256];
- float lsp_pow_m_table1[(1 << LSP_POW_BITS)];
- float lsp_pow_m_table2[(1 << LSP_POW_BITS)];
-
-#ifdef TRACE
- int frame_count;
-#endif
-} WMADecodeContext;
-
-typedef struct CoefVLCTable {
- int n; /* total number of codes */
- const uint32_t *huffcodes; /* VLC bit values */
- const uint8_t *huffbits; /* VLC bit size */
- const uint16_t *levels; /* table to build run/level tables */
-} CoefVLCTable;
-
-static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len);
-
-#include "wmadata.h"
-
-#ifdef TRACE
-static void dump_shorts(const char *name, const short *tab, int n)
-{
- int i;
-
- tprintf("%s[%d]:\n", name, n);
- for(i=0;i<n;i++) {
- if ((i & 7) == 0)
- tprintf("%4d: ", i);
- tprintf(" %5d.0", tab[i]);
- if ((i & 7) == 7)
- tprintf("\n");
- }
-}
-
-static void dump_floats(const char *name, int prec, const float *tab, int n)
-{
- int i;
-
- tprintf("%s[%d]:\n", name, n);
- for(i=0;i<n;i++) {
- if ((i & 7) == 0)
- tprintf("%4d: ", i);
- tprintf(" %8.*f", prec, tab[i]);
- if ((i & 7) == 7)
- tprintf("\n");
- }
- if ((i & 7) != 0)
- tprintf("\n");
-}
-#endif
-
-/* XXX: use same run/length optimization as mpeg decoders */
-static void init_coef_vlc(VLC *vlc,
- uint16_t **prun_table, uint16_t **plevel_table,
- const CoefVLCTable *vlc_table)
-{
- int n = vlc_table->n;
- const uint8_t *table_bits = vlc_table->huffbits;
- const uint32_t *table_codes = vlc_table->huffcodes;
- const uint16_t *levels_table = vlc_table->levels;
- uint16_t *run_table, *level_table;
- const uint16_t *p;
- int i, l, j, level;
-
- init_vlc(vlc, 9, n, table_bits, 1, 1, table_codes, 4, 4);
-
- run_table = av_malloc(n * sizeof(uint16_t));
- level_table = av_malloc(n * sizeof(uint16_t));
- p = levels_table;
- i = 2;
- level = 1;
- while (i < n) {
- l = *p++;
- for(j=0;j<l;j++) {
- run_table[i] = j;
- level_table[i] = level;
- i++;
- }
- level++;
- }
- *prun_table = run_table;
- *plevel_table = level_table;
-}
-
-static int wma_decode_init(AVCodecContext * avctx)
-{
- WMADecodeContext *s = avctx->priv_data;
- int i, flags1, flags2;
- float *window;
- uint8_t *extradata;
- float bps1, high_freq, bps;
- int sample_rate1;
- int coef_vlc_table;
-
- s->sample_rate = avctx->sample_rate;
- s->nb_channels = avctx->channels;
- s->bit_rate = avctx->bit_rate;
- s->block_align = avctx->block_align;
-
- if (avctx->codec->id == CODEC_ID_WMAV1) {
- s->version = 1;
- } else {
- s->version = 2;
- }
-
- /* extract flag infos */
- flags1 = 0;
- flags2 = 0;
- extradata = avctx->extradata;
- if (s->version == 1 && avctx->extradata_size >= 4) {
- flags1 = extradata[0] | (extradata[1] << 8);
- flags2 = extradata[2] | (extradata[3] << 8);
- } else if (s->version == 2 && avctx->extradata_size >= 6) {
- flags1 = extradata[0] | (extradata[1] << 8) |
- (extradata[2] << 16) | (extradata[3] << 24);
- flags2 = extradata[4] | (extradata[5] << 8);
- }
- s->use_exp_vlc = flags2 & 0x0001;
- s->use_bit_reservoir = flags2 & 0x0002;
- s->use_variable_block_len = flags2 & 0x0004;
-
- /* compute MDCT block size */
- if (s->sample_rate <= 16000) {
- s->frame_len_bits = 9;
- } else if (s->sample_rate <= 22050 ||
- (s->sample_rate <= 32000 && s->version == 1)) {
- s->frame_len_bits = 10;
- } else {
- s->frame_len_bits = 11;
- }
- s->frame_len = 1 << s->frame_len_bits;
- if (s->use_variable_block_len) {
- int nb_max, nb;
- nb = ((flags2 >> 3) & 3) + 1;
- if ((s->bit_rate / s->nb_channels) >= 32000)
- nb += 2;
- nb_max = s->frame_len_bits - BLOCK_MIN_BITS;
- if (nb > nb_max)
- nb = nb_max;
- s->nb_block_sizes = nb + 1;
- } else {
- s->nb_block_sizes = 1;
- }
-
- /* init rate dependant parameters */
- s->use_noise_coding = 1;
- high_freq = s->sample_rate * 0.5;
-
- /* if version 2, then the rates are normalized */
- sample_rate1 = s->sample_rate;
- if (s->version == 2) {
- if (sample_rate1 >= 44100)
- sample_rate1 = 44100;
- else if (sample_rate1 >= 22050)
- sample_rate1 = 22050;
- else if (sample_rate1 >= 16000)
- sample_rate1 = 16000;
- else if (sample_rate1 >= 11025)
- sample_rate1 = 11025;
- else if (sample_rate1 >= 8000)
- sample_rate1 = 8000;
- }
-
- bps = (float)s->bit_rate / (float)(s->nb_channels * s->sample_rate);
- s->byte_offset_bits = av_log2((int)(bps * s->frame_len / 8.0)) + 2;
-
- /* compute high frequency value and choose if noise coding should
- be activated */
- bps1 = bps;
- if (s->nb_channels == 2)
- bps1 = bps * 1.6;
- if (sample_rate1 == 44100) {
- if (bps1 >= 0.61)
- s->use_noise_coding = 0;
- else
- high_freq = high_freq * 0.4;
- } else if (sample_rate1 == 22050) {
- if (bps1 >= 1.16)
- s->use_noise_coding = 0;
- else if (bps1 >= 0.72)
- high_freq = high_freq * 0.7;
- else
- high_freq = high_freq * 0.6;
- } else if (sample_rate1 == 16000) {
- if (bps > 0.5)
- high_freq = high_freq * 0.5;
- else
- high_freq = high_freq * 0.3;
- } else if (sample_rate1 == 11025) {
- high_freq = high_freq * 0.7;
- } else if (sample_rate1 == 8000) {
- if (bps <= 0.625) {
- high_freq = high_freq * 0.5;
- } else if (bps > 0.75) {
- s->use_noise_coding = 0;
- } else {
- high_freq = high_freq * 0.65;
- }
- } else {
- if (bps >= 0.8) {
- high_freq = high_freq * 0.75;
- } else if (bps >= 0.6) {
- high_freq = high_freq * 0.6;
- } else {
- high_freq = high_freq * 0.5;
- }
- }
- dprintf("flags1=0x%x flags2=0x%x\n", flags1, flags2);
- dprintf("version=%d channels=%d sample_rate=%d bitrate=%d block_align=%d\n",
- s->version, s->nb_channels, s->sample_rate, s->bit_rate,
- s->block_align);
- dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n",
- bps, bps1, high_freq, s->byte_offset_bits);
- dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n",
- s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes);
-
- /* compute the scale factor band sizes for each MDCT block size */
- {
- int a, b, pos, lpos, k, block_len, i, j, n;
- const uint8_t *table;
-
- if (s->version == 1) {
- s->coefs_start = 3;
- } else {
- s->coefs_start = 0;
- }
- for(k = 0; k < s->nb_block_sizes; k++) {
- block_len = s->frame_len >> k;
-
- if (s->version == 1) {
- lpos = 0;
- for(i=0;i<25;i++) {
- a = wma_critical_freqs[i];
- b = s->sample_rate;
- pos = ((block_len * 2 * a) + (b >> 1)) / b;
- if (pos > block_len)
- pos = block_len;
- s->exponent_bands[0][i] = pos - lpos;
- if (pos >= block_len) {
- i++;
- break;
- }
- lpos = pos;
- }
- s->exponent_sizes[0] = i;
- } else {
- /* hardcoded tables */
- table = NULL;
- a = s->frame_len_bits - BLOCK_MIN_BITS - k;
- if (a < 3) {
- if (s->sample_rate >= 44100)
- table = exponent_band_44100[a];
- else if (s->sample_rate >= 32000)
- table = exponent_band_32000[a];
- else if (s->sample_rate >= 22050)
- table = exponent_band_22050[a];
- }
- if (table) {
- n = *table++;
- for(i=0;i<n;i++)
- s->exponent_bands[k][i] = table[i];
- s->exponent_sizes[k] = n;
- } else {
- j = 0;
- lpos = 0;
- for(i=0;i<25;i++) {
- a = wma_critical_freqs[i];
- b = s->sample_rate;
- pos = ((block_len * 2 * a) + (b << 1)) / (4 * b);
- pos <<= 2;
- if (pos > block_len)
- pos = block_len;
- if (pos > lpos)
- s->exponent_bands[k][j++] = pos - lpos;
- if (pos >= block_len)
- break;
- lpos = pos;
- }
- s->exponent_sizes[k] = j;
- }
- }
-
- /* max number of coefs */
- s->coefs_end[k] = (s->frame_len - ((s->frame_len * 9) / 100)) >> k;
- /* high freq computation */
- s->high_band_start[k] = (int)((block_len * 2 * high_freq) /
- s->sample_rate + 0.5);
- n = s->exponent_sizes[k];
- j = 0;
- pos = 0;
- for(i=0;i<n;i++) {
- int start, end;
- start = pos;
- pos += s->exponent_bands[k][i];
- end = pos;
- if (start < s->high_band_start[k])
- start = s->high_band_start[k];
- if (end > s->coefs_end[k])
- end = s->coefs_end[k];
- if (end > start)
- s->exponent_high_bands[k][j++] = end - start;
- }
- s->exponent_high_sizes[k] = j;
-#if 0
- tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ",
- s->frame_len >> k,
- s->coefs_end[k],
- s->high_band_start[k],
- s->exponent_high_sizes[k]);
- for(j=0;j<s->exponent_high_sizes[k];j++)
- tprintf(" %d", s->exponent_high_bands[k][j]);
- tprintf("\n");
-#endif
- }
- }
-
-#ifdef TRACE
- {
- int i, j;
- for(i = 0; i < s->nb_block_sizes; i++) {
- tprintf("%5d: n=%2d:",
- s->frame_len >> i,
- s->exponent_sizes[i]);
- for(j=0;j<s->exponent_sizes[i];j++)
- tprintf(" %d", s->exponent_bands[i][j]);
- tprintf("\n");
- }
- }
-#endif
-
- /* init MDCT */
- for(i = 0; i < s->nb_block_sizes; i++)
- ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 1);
-
- /* init MDCT windows : simple sinus window */
- for(i = 0; i < s->nb_block_sizes; i++) {
- int n, j;
- float alpha;
- n = 1 << (s->frame_len_bits - i);
- window = av_malloc(sizeof(float) * n);
- alpha = M_PI / (2.0 * n);
- for(j=0;j<n;j++) {
- window[n - j - 1] = sin((j + 0.5) * alpha);
- }
- s->windows[i] = window;
- }
-
- s->reset_block_lengths = 1;
-
- if (s->use_noise_coding) {
-
- /* init the noise generator */
- if (s->use_exp_vlc)
- s->noise_mult = 0.02;
- else
- s->noise_mult = 0.04;
-
-#ifdef TRACE
- for(i=0;i<NOISE_TAB_SIZE;i++)
- s->noise_table[i] = 1.0 * s->noise_mult;
-#else
- {
- unsigned int seed;
- float norm;
- seed = 1;
- norm = (1.0 / (float)(1LL << 31)) * sqrt(3) * s->noise_mult;
- for(i=0;i<NOISE_TAB_SIZE;i++) {
- seed = seed * 314159 + 1;
- s->noise_table[i] = (float)((int)seed) * norm;
- }
- }
-#endif
- init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits),
- hgain_huffbits, 1, 1,
- hgain_huffcodes, 2, 2);
- }
-
- if (s->use_exp_vlc) {
- init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits),
- scale_huffbits, 1, 1,
- scale_huffcodes, 4, 4);
- } else {
- wma_lsp_to_curve_init(s, s->frame_len);
- }
-
- /* choose the VLC tables for the coefficients */
- coef_vlc_table = 2;
- if (s->sample_rate >= 32000) {
- if (bps1 < 0.72)
- coef_vlc_table = 0;
- else if (bps1 < 1.16)
- coef_vlc_table = 1;
- }
-
- init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
- &coef_vlcs[coef_vlc_table * 2]);
- init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
- &coef_vlcs[coef_vlc_table * 2 + 1]);
- return 0;
-}
-
-/* interpolate values for a bigger or smaller block. The block must
- have multiple sizes */
-static void interpolate_array(float *scale, int old_size, int new_size)
-{
- int i, j, jincr, k;
- float v;
-
- if (new_size > old_size) {
- jincr = new_size / old_size;
- j = new_size;
- for(i = old_size - 1; i >=0; i--) {
- v = scale[i];
- k = jincr;
- do {
- scale[--j] = v;
- } while (--k);
- }
- } else if (new_size < old_size) {
- j = 0;
- jincr = old_size / new_size;
- for(i = 0; i < new_size; i++) {
- scale[i] = scale[j];
- j += jincr;
- }
- }
-}
-
-/* compute x^-0.25 with an exponent and mantissa table. We use linear
- interpolation to reduce the mantissa table size at a small speed
- expense (linear interpolation approximately doubles the number of
- bits of precision). */
-static inline float pow_m1_4(WMADecodeContext *s, float x)
-{
- union {
- float f;
- unsigned int v;
- } u, t;
- unsigned int e, m;
- float a, b;
-
- u.f = x;
- e = u.v >> 23;
- m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
- /* build interpolation scale: 1 <= t < 2. */
- t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
- a = s->lsp_pow_m_table1[m];
- b = s->lsp_pow_m_table2[m];
- return s->lsp_pow_e_table[e] * (a + b * t.f);
-}
-
-static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len)
-{
- float wdel, a, b;
- int i, e, m;
-
- wdel = M_PI / frame_len;
- for(i=0;i<frame_len;i++)
- s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
-
- /* tables for x^-0.25 computation */
- for(i=0;i<256;i++) {
- e = i - 126;
- s->lsp_pow_e_table[i] = pow(2.0, e * -0.25);
- }
-
- /* NOTE: these two tables are needed to avoid two operations in
- pow_m1_4 */
- b = 1.0;
- for(i=(1 << LSP_POW_BITS) - 1;i>=0;i--) {
- m = (1 << LSP_POW_BITS) + i;
- a = (float)m * (0.5 / (1 << LSP_POW_BITS));
- a = pow(a, -0.25);
- s->lsp_pow_m_table1[i] = 2 * a - b;
- s->lsp_pow_m_table2[i] = b - a;
- b = a;
- }
-#if 0
- for(i=1;i<20;i++) {
- float v, r1, r2;
- v = 5.0 / i;
- r1 = pow_m1_4(s, v);
- r2 = pow(v,-0.25);
- printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1);
- }
-#endif
-}
-
-/* NOTE: We use the same code as Vorbis here */
-/* XXX: optimize it further with SSE/3Dnow */
-static void wma_lsp_to_curve(WMADecodeContext *s,
- float *out, float *val_max_ptr,
- int n, float *lsp)
-{
- int i, j;
- float p, q, w, v, val_max;
-
- val_max = 0;
- for(i=0;i<n;i++) {
- p = 0.5f;
- q = 0.5f;
- w = s->lsp_cos_table[i];
- for(j=1;j<NB_LSP_COEFS;j+=2){
- q *= w - lsp[j - 1];
- p *= w - lsp[j];
- }
- p *= p * (2.0f - w);
- q *= q * (2.0f + w);
- v = p + q;
- v = pow_m1_4(s, v);
- if (v > val_max)
- val_max = v;
- out[i] = v;
- }
- *val_max_ptr = val_max;
-}
-
-/* decode exponents coded with LSP coefficients (same idea as Vorbis) */
-static void decode_exp_lsp(WMADecodeContext *s, int ch)
-{
- float lsp_coefs[NB_LSP_COEFS];
- int val, i;
-
- for(i = 0; i < NB_LSP_COEFS; i++) {
- if (i == 0 || i >= 8)
- val = get_bits(&s->gb, 3);
- else
- val = get_bits(&s->gb, 4);
- lsp_coefs[i] = lsp_codebook[i][val];
- }
-
- wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
- s->block_len, lsp_coefs);
-}
-
-/* decode exponents coded with VLC codes */
-static int decode_exp_vlc(WMADecodeContext *s, int ch)
-{
- int last_exp, n, code;
- const uint16_t *ptr, *band_ptr;
- float v, *q, max_scale, *q_end;
-
- band_ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
- ptr = band_ptr;
- q = s->exponents[ch];
- q_end = q + s->block_len;
- max_scale = 0;
- if (s->version == 1) {
- last_exp = get_bits(&s->gb, 5) + 10;
- /* XXX: use a table */
- v = pow(10, last_exp * (1.0 / 16.0));
- max_scale = v;
- n = *ptr++;
- do {
- *q++ = v;
- } while (--n);
- }
- last_exp = 36;
- while (q < q_end) {
- code = get_vlc(&s->gb, &s->exp_vlc);
- if (code < 0)
- return -1;
- /* NOTE: this offset is the same as MPEG4 AAC ! */
- last_exp += code - 60;
- /* XXX: use a table */
- v = pow(10, last_exp * (1.0 / 16.0));
- if (v > max_scale)
- max_scale = v;
- n = *ptr++;
- do {
- *q++ = v;
- } while (--n);
- }
- s->max_exponent[ch] = max_scale;
- return 0;
-}
-
-/* return 0 if OK. return 1 if last block of frame. return -1 if
- unrecorrable error. */
-static int wma_decode_block(WMADecodeContext *s)
-{
- int n, v, a, ch, code, bsize;
- int coef_nb_bits, total_gain, parse_exponents;
- float window[BLOCK_MAX_SIZE * 2];
- int nb_coefs[MAX_CHANNELS];
- float mdct_norm;
-
-#ifdef TRACE
- tprintf("***decode_block: %d:%d\n", s->frame_count - 1, s->block_num);
-#endif
-
- /* compute current block length */
- if (s->use_variable_block_len) {
- n = av_log2(s->nb_block_sizes - 1) + 1;
-
- if (s->reset_block_lengths) {
- s->reset_block_lengths = 0;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->prev_block_len_bits = s->frame_len_bits - v;
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->block_len_bits = s->frame_len_bits - v;
- } else {
- /* update block lengths */
- s->prev_block_len_bits = s->block_len_bits;
- s->block_len_bits = s->next_block_len_bits;
- }
- v = get_bits(&s->gb, n);
- if (v >= s->nb_block_sizes)
- return -1;
- s->next_block_len_bits = s->frame_len_bits - v;
- } else {
- /* fixed block len */
- s->next_block_len_bits = s->frame_len_bits;
- s->prev_block_len_bits = s->frame_len_bits;
- s->block_len_bits = s->frame_len_bits;
- }
-
- /* now check if the block length is coherent with the frame length */
- s->block_len = 1 << s->block_len_bits;
- if ((s->block_pos + s->block_len) > s->frame_len)
- return -1;
-
- if (s->nb_channels == 2) {
- s->ms_stereo = get_bits(&s->gb, 1);
- }
- v = 0;
- for(ch = 0; ch < s->nb_channels; ch++) {
- a = get_bits(&s->gb, 1);
- s->channel_coded[ch] = a;
- v |= a;
- }
- /* if no channel coded, no need to go further */
- /* XXX: fix potential framing problems */
- if (!v)
- goto next;
-
- bsize = s->frame_len_bits - s->block_len_bits;
-
- /* read total gain and extract corresponding number of bits for
- coef escape coding */
- total_gain = 1;
- for(;;) {
- a = get_bits(&s->gb, 7);
- total_gain += a;
- if (a != 127)
- break;
- }
-
- if (total_gain < 15)
- coef_nb_bits = 13;
- else if (total_gain < 32)
- coef_nb_bits = 12;
- else if (total_gain < 40)
- coef_nb_bits = 11;
- else if (total_gain < 45)
- coef_nb_bits = 10;
- else
- coef_nb_bits = 9;
-
- /* compute number of coefficients */
- n = s->coefs_end[bsize] - s->coefs_start;
- for(ch = 0; ch < s->nb_channels; ch++)
- nb_coefs[ch] = n;
-
- /* complex coding */
- if (s->use_noise_coding) {
-
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, n, a;
- n = s->exponent_high_sizes[bsize];
- for(i=0;i<n;i++) {
- a = get_bits(&s->gb, 1);
- s->high_band_coded[ch][i] = a;
- /* if noise coding, the coefficients are not transmitted */
- if (a)
- nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
- }
- }
- }
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int i, n, val, code;
-
- n = s->exponent_high_sizes[bsize];
- val = (int)0x80000000;
- for(i=0;i<n;i++) {
- if (s->high_band_coded[ch][i]) {
- if (val == (int)0x80000000) {
- val = get_bits(&s->gb, 7) - 19;
- } else {
- code = get_vlc(&s->gb, &s->hgain_vlc);
- if (code < 0)
- return -1;
- val += code - 18;
- }
- s->high_band_values[ch][i] = val;
- }
- }
- }
- }
- }
-
- /* exposant can be interpolated in short blocks. */
- parse_exponents = 1;
- if (s->block_len_bits != s->frame_len_bits) {
- parse_exponents = get_bits(&s->gb, 1);
- }
-
- if (parse_exponents) {
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- if (s->use_exp_vlc) {
- if (decode_exp_vlc(s, ch) < 0)
- return -1;
- } else {
- decode_exp_lsp(s, ch);
- }
- }
- }
- } else {
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits,
- s->block_len);
- }
- }
- }
-
- /* parse spectral coefficients : just RLE encoding */
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- VLC *coef_vlc;
- int level, run, sign, tindex;
- int16_t *ptr, *eptr;
- const int16_t *level_table, *run_table;
-
- /* special VLC tables are used for ms stereo because
- there is potentially less energy there */
- tindex = (ch == 1 && s->ms_stereo);
- coef_vlc = &s->coef_vlc[tindex];
- run_table = s->run_table[tindex];
- level_table = s->level_table[tindex];
- /* XXX: optimize */
- ptr = &s->coefs1[ch][0];
- eptr = ptr + nb_coefs[ch];
- memset(ptr, 0, s->block_len * sizeof(int16_t));
- for(;;) {
- code = get_vlc(&s->gb, coef_vlc);
- if (code < 0)
- return -1;
- if (code == 1) {
- /* EOB */
- break;
- } else if (code == 0) {
- /* escape */
- level = get_bits(&s->gb, coef_nb_bits);
- /* NOTE: this is rather suboptimal. reading
- block_len_bits would be better */
- run = get_bits(&s->gb, s->frame_len_bits);
- } else {
- /* normal code */
- run = run_table[code];
- level = level_table[code];
- }
- sign = get_bits(&s->gb, 1);
- if (!sign)
- level = -level;
- ptr += run;
- if (ptr >= eptr)
- return -1;
- *ptr++ = level;
- /* NOTE: EOB can be omitted */
- if (ptr >= eptr)
- break;
- }
- }
- if (s->version == 1 && s->nb_channels >= 2) {
- align_get_bits(&s->gb);
- }
- }
-
- /* normalize */
- {
- int n4 = s->block_len / 2;
- mdct_norm = 1.0 / (float)n4;
- if (s->version == 1) {
- mdct_norm *= sqrt(n4);
- }
- }
-
- /* finally compute the MDCT coefficients */
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- int16_t *coefs1;
- float *coefs, *exponents, mult, mult1, noise, *exp_ptr;
- int i, j, n, n1, last_high_band;
- float exp_power[HIGH_BAND_MAX_SIZE];
-
- coefs1 = s->coefs1[ch];
- exponents = s->exponents[ch];
- mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];
- mult *= mdct_norm;
- coefs = s->coefs[ch];
- if (s->use_noise_coding) {
- mult1 = mult;
- /* very low freqs : noise */
- for(i = 0;i < s->coefs_start; i++) {
- *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1;
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- }
-
- n1 = s->exponent_high_sizes[bsize];
-
- /* compute power of high bands */
- exp_ptr = exponents +
- s->high_band_start[bsize] -
- s->coefs_start;
- last_high_band = 0; /* avoid warning */
- for(j=0;j<n1;j++) {
- n = s->exponent_high_bands[s->frame_len_bits -
- s->block_len_bits][j];
- if (s->high_band_coded[ch][j]) {
- float e2, v;
- e2 = 0;
- for(i = 0;i < n; i++) {
- v = exp_ptr[i];
- e2 += v * v;
- }
- exp_power[j] = e2 / n;
- last_high_band = j;
- tprintf("%d: power=%f (%d)\n", j, exp_power[j], n);
- }
- exp_ptr += n;
- }
-
- /* main freqs and high freqs */
- for(j=-1;j<n1;j++) {
- if (j < 0) {
- n = s->high_band_start[bsize] -
- s->coefs_start;
- } else {
- n = s->exponent_high_bands[s->frame_len_bits -
- s->block_len_bits][j];
- }
- if (j >= 0 && s->high_band_coded[ch][j]) {
- /* use noise with specified power */
- mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
- /* XXX: use a table */
- mult1 = mult1 * pow(10, s->high_band_values[ch][j] * 0.05);
- mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
- mult1 *= mdct_norm;
- for(i = 0;i < n; i++) {
- noise = s->noise_table[s->noise_index];
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- *coefs++ = (*exponents++) * noise * mult1;
- }
- } else {
- /* coded values + small noise */
- for(i = 0;i < n; i++) {
- noise = s->noise_table[s->noise_index];
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult;
- }
- }
- }
-
- /* very high freqs : noise */
- n = s->block_len - s->coefs_end[bsize];
- mult1 = mult * exponents[-1];
- for(i = 0; i < n; i++) {
- *coefs++ = s->noise_table[s->noise_index] * mult1;
- s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
- }
- } else {
- /* XXX: optimize more */
- for(i = 0;i < s->coefs_start; i++)
- *coefs++ = 0.0;
- n = nb_coefs[ch];
- for(i = 0;i < n; i++) {
- *coefs++ = coefs1[i] * exponents[i] * mult;
- }
- n = s->block_len - s->coefs_end[bsize];
- for(i = 0;i < n; i++)
- *coefs++ = 0.0;
- }
- }
- }
-
-#ifdef TRACE
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- dump_floats("exponents", 3, s->exponents[ch], s->block_len);
- dump_floats("coefs", 1, s->coefs[ch], s->block_len);
- }
- }
-#endif
-
- if (s->ms_stereo && s->channel_coded[1]) {
- float a, b;
- int i;
-
- /* nominal case for ms stereo: we do it before mdct */
- /* no need to optimize this case because it should almost
- never happen */
- if (!s->channel_coded[0]) {
- tprintf("rare ms-stereo case happened\n");
- memset(s->coefs[0], 0, sizeof(float) * s->block_len);
- s->channel_coded[0] = 1;
- }
-
- for(i = 0; i < s->block_len; i++) {
- a = s->coefs[0][i];
- b = s->coefs[1][i];
- s->coefs[0][i] = a + b;
- s->coefs[1][i] = a - b;
- }
- }
-
- /* build the window : we ensure that when the windows overlap
- their squared sum is always 1 (MDCT reconstruction rule) */
- /* XXX: merge with output */
- {
- int i, next_block_len, block_len, prev_block_len, n;
- float *wptr;
-
- block_len = s->block_len;
- prev_block_len = 1 << s->prev_block_len_bits;
- next_block_len = 1 << s->next_block_len_bits;
-
- /* right part */
- wptr = window + block_len;
- if (block_len <= next_block_len) {
- for(i=0;i<block_len;i++)
- *wptr++ = s->windows[bsize][i];
- } else {
- /* overlap */
- n = (block_len / 2) - (next_block_len / 2);
- for(i=0;i<n;i++)
- *wptr++ = 1.0;
- for(i=0;i<next_block_len;i++)
- *wptr++ = s->windows[s->frame_len_bits - s->next_block_len_bits][i];
- for(i=0;i<n;i++)
- *wptr++ = 0.0;
- }
-
- /* left part */
- wptr = window + block_len;
- if (block_len <= prev_block_len) {
- for(i=0;i<block_len;i++)
- *--wptr = s->windows[bsize][i];
- } else {
- /* overlap */
- n = (block_len / 2) - (prev_block_len / 2);
- for(i=0;i<n;i++)
- *--wptr = 1.0;
- for(i=0;i<prev_block_len;i++)
- *--wptr = s->windows[s->frame_len_bits - s->prev_block_len_bits][i];
- for(i=0;i<n;i++)
- *--wptr = 0.0;
- }
- }
-
-
- for(ch = 0; ch < s->nb_channels; ch++) {
- if (s->channel_coded[ch]) {
- FFTSample output[BLOCK_MAX_SIZE * 2] __attribute__((aligned(16)));
- float *ptr;
- int i, n4, index, n;
-
- n = s->block_len;
- n4 = s->block_len / 2;
- ff_imdct_calc(&s->mdct_ctx[bsize],
- output, s->coefs[ch], s->mdct_tmp);
-
- /* XXX: optimize all that by build the window and
- multipying/adding at the same time */
- /* multiply by the window */
- for(i=0;i<n * 2;i++) {
- output[i] *= window[i];
- }
-
- /* add in the frame */
- index = (s->frame_len / 2) + s->block_pos - n4;
- ptr = &s->frame_out[ch][index];
- for(i=0;i<n * 2;i++) {
- *ptr += output[i];
- ptr++;
- }
-
- /* specific fast case for ms-stereo : add to second
- channel if it is not coded */
- if (s->ms_stereo && !s->channel_coded[1]) {
- ptr = &s->frame_out[1][index];
- for(i=0;i<n * 2;i++) {
- *ptr += output[i];
- ptr++;
- }
- }
- }
- }
- next:
- /* update block number */
- s->block_num++;
- s->block_pos += s->block_len;
- if (s->block_pos >= s->frame_len)
- return 1;
- else
- return 0;
-}
-
-/* decode a frame of frame_len samples */
-static int wma_decode_frame(WMADecodeContext *s, int16_t *samples)
-{
- int ret, i, n, a, ch, incr;
- int16_t *ptr;
- float *iptr;
-
-#ifdef TRACE
- tprintf("***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len);
-#endif
-
- /* read each block */
- s->block_num = 0;
- s->block_pos = 0;
- for(;;) {
- ret = wma_decode_block(s);
- if (ret < 0)
- return -1;
- if (ret)
- break;
- }
-
- /* convert frame to integer */
- n = s->frame_len;
- incr = s->nb_channels;
- for(ch = 0; ch < s->nb_channels; ch++) {
- ptr = samples + ch;
- iptr = s->frame_out[ch];
-
- for(i=0;i<n;i++) {
- a = lrintf(*iptr++);
- if (a > 32767)
- a = 32767;
- else if (a < -32768)
- a = -32768;
- *ptr = a;
- ptr += incr;
- }
- /* prepare for next block */
- memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
- s->frame_len * sizeof(float));
- /* XXX: suppress this */
- memset(&s->frame_out[ch][s->frame_len], 0,
- s->frame_len * sizeof(float));
- }
-
-#ifdef TRACE
- dump_shorts("samples", samples, n * s->nb_channels);
-#endif
- return 0;
-}
-
-static int wma_decode_superframe(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- WMADecodeContext *s = avctx->priv_data;
- int nb_frames, bit_offset, i, pos, len;
- uint8_t *q;
- int16_t *samples;
-
- tprintf("***decode_superframe:\n");
-
- samples = data;
-
- init_get_bits(&s->gb, buf, buf_size*8);
-
- if (s->use_bit_reservoir) {
- /* read super frame header */
- get_bits(&s->gb, 4); /* super frame index */
- nb_frames = get_bits(&s->gb, 4) - 1;
-
- bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
-
- if (s->last_superframe_len > 0) {
- // printf("skip=%d\n", s->last_bitoffset);
- /* add bit_offset bits to last frame */
- if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
- MAX_CODED_SUPERFRAME_SIZE)
- goto fail;
- q = s->last_superframe + s->last_superframe_len;
- len = bit_offset;
- while (len > 0) {
- *q++ = (get_bits)(&s->gb, 8);
- len -= 8;
- }
- if (len > 0) {
- *q++ = (get_bits)(&s->gb, len) << (8 - len);
- }
-
- /* XXX: bit_offset bits into last frame */
- init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8);
- /* skip unused bits */
- if (s->last_bitoffset > 0)
- skip_bits(&s->gb, s->last_bitoffset);
- /* this frame is stored in the last superframe and in the
- current one */
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
-
- /* read each frame starting from bit_offset */
- pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
- init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8);
- len = pos & 7;
- if (len > 0)
- skip_bits(&s->gb, len);
-
- s->reset_block_lengths = 1;
- for(i=0;i<nb_frames;i++) {
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
-
- /* we copy the end of the frame in the last frame buffer */
- pos = get_bits_count(&s->gb) + ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
- s->last_bitoffset = pos & 7;
- pos >>= 3;
- len = buf_size - pos;
- if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
- goto fail;
- }
- s->last_superframe_len = len;
- memcpy(s->last_superframe, buf + pos, len);
- } else {
- /* single frame decode */
- if (wma_decode_frame(s, samples) < 0)
- goto fail;
- samples += s->nb_channels * s->frame_len;
- }
- *data_size = (int8_t *)samples - (int8_t *)data;
- return s->block_align;
- fail:
- /* when error, we reset the bit reservoir */
- s->last_superframe_len = 0;
- return -1;
-}
-
-static int wma_decode_end(AVCodecContext *avctx)
-{
- WMADecodeContext *s = avctx->priv_data;
- int i;
-
- for(i = 0; i < s->nb_block_sizes; i++)
- ff_mdct_end(&s->mdct_ctx[i]);
- for(i = 0; i < s->nb_block_sizes; i++)
- av_free(s->windows[i]);
-
- if (s->use_exp_vlc) {
- free_vlc(&s->exp_vlc);
- }
- if (s->use_noise_coding) {
- free_vlc(&s->hgain_vlc);
- }
- for(i = 0;i < 2; i++) {
- free_vlc(&s->coef_vlc[i]);
- av_free(s->run_table[i]);
- av_free(s->level_table[i]);
- }
-
- return 0;
-}
-
-AVCodec wmav1_decoder =
-{
- "wmav1",
- CODEC_TYPE_AUDIO,
- CODEC_ID_WMAV1,
- sizeof(WMADecodeContext),
- wma_decode_init,
- NULL,
- wma_decode_end,
- wma_decode_superframe,
-};
-
-AVCodec wmav2_decoder =
-{
- "wmav2",
- CODEC_TYPE_AUDIO,
- CODEC_ID_WMAV2,
- sizeof(WMADecodeContext),
- wma_decode_init,
- NULL,
- wma_decode_end,
- wma_decode_superframe,
-};
+++ /dev/null
-/*
- * Copyright (c) 2002 The FFmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file wmv2.c
- * wmv2 codec.
- */
-
-#include "simple_idct.h"
-
-#define SKIP_TYPE_NONE 0
-#define SKIP_TYPE_MPEG 1
-#define SKIP_TYPE_ROW 2
-#define SKIP_TYPE_COL 3
-
-
-typedef struct Wmv2Context{
- MpegEncContext s;
- int j_type_bit;
- int j_type;
- int flag3;
- int flag63;
- int abt_flag;
- int abt_type;
- int abt_type_table[6];
- int per_mb_abt;
- int per_block_abt;
- int mspel_bit;
- int cbp_table_index;
- int top_left_mv_flag;
- int per_mb_rl_bit;
- int skip_type;
- int hshift;
-
- ScanTable abt_scantable[2];
- DCTELEM abt_block2[6][64] __align8;
-}Wmv2Context;
-
-static void wmv2_common_init(Wmv2Context * w){
- MpegEncContext * const s= &w->s;
-
- ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA);
- ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB);
-}
-
-static int encode_ext_header(Wmv2Context *w){
- MpegEncContext * const s= &w->s;
- PutBitContext pb;
- int code;
-
- init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size, NULL, NULL);
-
- put_bits(&pb, 5, s->avctx->frame_rate / s->avctx->frame_rate_base); //yes 29.97 -> 29
- put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));
-
- put_bits(&pb, 1, w->mspel_bit=1);
- put_bits(&pb, 1, w->flag3=1);
- put_bits(&pb, 1, w->abt_flag=1);
- put_bits(&pb, 1, w->j_type_bit=1);
- put_bits(&pb, 1, w->top_left_mv_flag=0);
- put_bits(&pb, 1, w->per_mb_rl_bit=1);
- put_bits(&pb, 3, code=1);
-
- flush_put_bits(&pb);
-
- s->slice_height = s->mb_height / code;
-
- return 0;
-}
-
-#ifdef CONFIG_ENCODERS
-static int wmv2_encode_init(AVCodecContext *avctx){
- Wmv2Context * const w= avctx->priv_data;
-
- if(MPV_encode_init(avctx) < 0)
- return -1;
-
- wmv2_common_init(w);
-
- avctx->extradata_size= 4;
- avctx->extradata= av_mallocz(avctx->extradata_size + 10);
- encode_ext_header(w);
-
- return 0;
-}
-
-static int wmv2_encode_end(AVCodecContext *avctx){
-
- if(MPV_encode_end(avctx) < 0)
- return -1;
-
- avctx->extradata_size= 0;
- av_freep(&avctx->extradata);
-
- return 0;
-}
-
-int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
-
- put_bits(&s->pb, 1, s->pict_type - 1);
- if(s->pict_type == I_TYPE){
- put_bits(&s->pb, 7, 0);
- }
- put_bits(&s->pb, 5, s->qscale);
-
- s->dc_table_index = 1;
- s->mv_table_index = 1; /* only if P frame */
-// s->use_skip_mb_code = 1; /* only if P frame */
- s->per_mb_rl_table = 0;
- s->mspel= 0;
- w->per_mb_abt=0;
- w->abt_type=0;
- w->j_type=0;
-
- assert(s->flipflop_rounding);
-
- if (s->pict_type == I_TYPE) {
- assert(s->no_rounding==1);
- if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type);
-
- if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_chroma_table_index);
- code012(&s->pb, s->rl_table_index);
- }
-
- put_bits(&s->pb, 1, s->dc_table_index);
-
- s->inter_intra_pred= 0;
- }else{
- int cbp_index;
-
- put_bits(&s->pb, 2, SKIP_TYPE_NONE);
-
- code012(&s->pb, cbp_index=0);
- if(s->qscale <= 10){
- int map[3]= {0,2,1};
- w->cbp_table_index= map[cbp_index];
- }else if(s->qscale <= 20){
- int map[3]= {1,0,2};
- w->cbp_table_index= map[cbp_index];
- }else{
- int map[3]= {2,1,0};
- w->cbp_table_index= map[cbp_index];
- }
-
- if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel);
-
- if(w->abt_flag){
- put_bits(&s->pb, 1, w->per_mb_abt^1);
- if(!w->per_mb_abt){
- code012(&s->pb, w->abt_type);
- }
- }
-
- if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table);
-
- if(!s->per_mb_rl_table){
- code012(&s->pb, s->rl_table_index);
- s->rl_chroma_table_index = s->rl_table_index;
- }
- put_bits(&s->pb, 1, s->dc_table_index);
- put_bits(&s->pb, 1, s->mv_table_index);
-
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- }
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
- return 0;
-}
-
-// nearly idential to wmv1 but thats just because we dont use the useless M$ crap features
-// its duplicated here in case someone wants to add support for these carp features
-void ff_wmv2_encode_mb(MpegEncContext * s,
- DCTELEM block[6][64],
- int motion_x, int motion_y)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int cbp, coded_cbp, i;
- int pred_x, pred_y;
- uint8_t *coded_block;
-
- handle_slices(s);
-
- if (!s->mb_intra) {
- /* compute cbp */
- set_stat(ST_INTER_MB);
- cbp = 0;
- for (i = 0; i < 6; i++) {
- if (s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
-
- put_bits(&s->pb,
- wmv2_inter_table[w->cbp_table_index][cbp + 64][1],
- wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
-
- /* motion vector */
- h263_pred_motion(s, 0, &pred_x, &pred_y);
- msmpeg4_encode_motion(s, motion_x - pred_x,
- motion_y - pred_y);
- } else {
- /* compute cbp */
- cbp = 0;
- coded_cbp = 0;
- for (i = 0; i < 6; i++) {
- int val, pred;
- val = (s->block_last_index[i] >= 1);
- cbp |= val << (5 - i);
- if (i < 4) {
- /* predict value for close blocks only for luma */
- pred = coded_block_pred(s, i, &coded_block);
- *coded_block = val;
- val = val ^ pred;
- }
- coded_cbp |= val << (5 - i);
- }
-#if 0
- if (coded_cbp)
- printf("cbp=%x %x\n", cbp, coded_cbp);
-#endif
-
- if (s->pict_type == I_TYPE) {
- set_stat(ST_INTRA_MB);
- put_bits(&s->pb,
- table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]);
- } else {
- put_bits(&s->pb,
- wmv2_inter_table[w->cbp_table_index][cbp][1],
- wmv2_inter_table[w->cbp_table_index][cbp][0]);
- }
- set_stat(ST_INTRA_MB);
- put_bits(&s->pb, 1, 0); /* no AC prediction yet */
- if(s->inter_intra_pred){
- s->h263_aic_dir=0;
- put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
- }
- }
-
- for (i = 0; i < 6; i++) {
- msmpeg4_encode_block(s, block[i], i);
- }
-}
-#endif //CONFIG_ENCODERS
-
-static void parse_mb_skip(Wmv2Context * w){
- int mb_x, mb_y;
- MpegEncContext * const s= &w->s;
- uint32_t * const mb_type= s->current_picture_ptr->mb_type;
-
- w->skip_type= get_bits(&s->gb, 2);
- switch(w->skip_type){
- case SKIP_TYPE_NONE:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- break;
- case SKIP_TYPE_MPEG:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- break;
- case SKIP_TYPE_ROW:
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- if(get_bits1(&s->gb)){
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }else{
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- }
- break;
- case SKIP_TYPE_COL:
- for(mb_x=0; mb_x<s->mb_width; mb_x++){
- if(get_bits1(&s->gb)){
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }else{
- for(mb_y=0; mb_y<s->mb_height; mb_y++){
- mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
- }
- }
- }
- break;
- }
-}
-
-static int decode_ext_header(Wmv2Context *w){
- MpegEncContext * const s= &w->s;
- GetBitContext gb;
- int fps;
- int code;
-
- if(s->avctx->extradata_size<4) return -1;
-
- init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8);
-
- fps = get_bits(&gb, 5);
- s->bit_rate = get_bits(&gb, 11)*1024;
- w->mspel_bit = get_bits1(&gb);
- w->flag3 = get_bits1(&gb);
- w->abt_flag = get_bits1(&gb);
- w->j_type_bit = get_bits1(&gb);
- w->top_left_mv_flag= get_bits1(&gb);
- w->per_mb_rl_bit = get_bits1(&gb);
- code = get_bits(&gb, 3);
-
- if(code==0) return -1;
-
- s->slice_height = s->mb_height / code;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d, slices:%d\n",
- fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, w->flag3,
- code);
- }
- return 0;
-}
-
-int ff_wmv2_decode_picture_header(MpegEncContext * s)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int code;
-
-#if 0
-{
-int i;
-for(i=0; i<s->gb.size*8; i++)
- printf("%d", get_bits1(&s->gb));
-// get_bits1(&s->gb);
-printf("END\n");
-return -1;
-}
-#endif
- if(s->picture_number==0)
- decode_ext_header(w);
-
- s->pict_type = get_bits(&s->gb, 1) + 1;
- if(s->pict_type == I_TYPE){
- code = get_bits(&s->gb, 7);
- printf("I7:%X/\n", code);
- }
- s->qscale = get_bits(&s->gb, 5);
- if(s->qscale < 0)
- return -1;
-
- return 0;
-}
-
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
-
- if (s->pict_type == I_TYPE) {
- if(w->j_type_bit) w->j_type= get_bits1(&s->gb);
- else w->j_type= 0; //FIXME check
-
- if(!w->j_type){
- if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_chroma_table_index = decode012(&s->gb);
- s->rl_table_index = decode012(&s->gb);
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- }
- s->inter_intra_pred= 0;
- s->no_rounding = 1;
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
- s->qscale,
- s->rl_chroma_table_index,
- s->rl_table_index,
- s->dc_table_index,
- s->per_mb_rl_table,
- w->j_type);
- }
- }else{
- int cbp_index;
- w->j_type=0;
-
- parse_mb_skip(w);
- cbp_index= decode012(&s->gb);
- if(s->qscale <= 10){
- int map[3]= {0,2,1};
- w->cbp_table_index= map[cbp_index];
- }else if(s->qscale <= 20){
- int map[3]= {1,0,2};
- w->cbp_table_index= map[cbp_index];
- }else{
- int map[3]= {2,1,0};
- w->cbp_table_index= map[cbp_index];
- }
-
- if(w->mspel_bit) s->mspel= get_bits1(&s->gb);
- else s->mspel= 0; //FIXME check
-
- if(w->abt_flag){
- w->per_mb_abt= get_bits1(&s->gb)^1;
- if(!w->per_mb_abt){
- w->abt_type= decode012(&s->gb);
- }
- }
-
- if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb);
- else s->per_mb_rl_table= 0;
-
- if(!s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- s->dc_table_index = get_bits1(&s->gb);
- s->mv_table_index = get_bits1(&s->gb);
-
- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
- s->no_rounding ^= 1;
-
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- printf("rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
- s->rl_table_index,
- s->rl_chroma_table_index,
- s->dc_table_index,
- s->mv_table_index,
- s->per_mb_rl_table,
- s->qscale,
- s->mspel,
- w->per_mb_abt,
- w->abt_type,
- w->cbp_table_index,
- s->inter_intra_pred);
- }
- }
- s->esc3_level_length= 0;
- s->esc3_run_length= 0;
-
-s->picture_number++; //FIXME ?
-
-
-// if(w->j_type)
-// return wmv2_decode_j_picture(w); //FIXME
-
- if(w->j_type){
- printf("J-type picture isnt supported\n");
- return -1;
- }
-
- return 0;
-}
-
-static void ff_wmv2_decode_init(MpegEncContext *s){
-}
-
-static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){
- MpegEncContext * const s= &w->s;
- int ret;
-
- ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr);
-
- if(ret<0) return -1;
-
- if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel)
- w->hshift= get_bits1(&s->gb);
- else
- w->hshift= 0;
-
-//printf("%d %d ", *mx_ptr, *my_ptr);
-
- return 0;
-}
-
-static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){
- MpegEncContext * const s= &w->s;
- int xy, wrap, diff, type;
- int16_t *A, *B, *C, *mot_val;
-
- wrap = s->block_wrap[0];
- xy = s->block_index[0];
-
- mot_val = s->motion_val[xy];
-
- A = s->motion_val[xy - 1];
- B = s->motion_val[xy - wrap];
- C = s->motion_val[xy + 2 - wrap];
-
- diff= FFMAX(ABS(A[0] - B[0]), ABS(A[1] - B[1]));
-
- if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag && diff >= 8)
- type= get_bits1(&s->gb);
- else
- type= 2;
-
- if(type == 0){
- *px= A[0];
- *py= A[1];
- }else if(type == 1){
- *px= B[0];
- *py= B[1];
- }else{
- /* special case for first (slice) line */
- if (s->first_slice_line) {
- *px = A[0];
- *py = A[1];
- } else {
- *px = mid_pred(A[0], B[0], C[0]);
- *py = mid_pred(A[1], B[1], C[1]);
- }
- }
-
- return mot_val;
-}
-
-static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){
- MpegEncContext * const s= &w->s;
- static const int sub_cbp_table[3]= {2,3,1};
- int sub_cbp;
-
- if(!cbp){
- s->block_last_index[n] = -1;
-
- return 0;
- }
-
- if(w->per_block_abt)
- w->abt_type= decode012(&s->gb);
-#if 0
- if(w->per_block_abt)
- printf("B%d", w->abt_type);
-#endif
- w->abt_type_table[n]= w->abt_type;
-
- if(w->abt_type){
-// const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated;
- const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable;
-// const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
-
- sub_cbp= sub_cbp_table[ decode012(&s->gb) ];
-// printf("S%d", sub_cbp);
-
- if(sub_cbp&1){
- if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0)
- return -1;
- }
-
- if(sub_cbp&2){
- if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0)
- return -1;
- }
- s->block_last_index[n] = 63;
-
- return 0;
- }else{
- return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated);
- }
-}
-
-static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){
- MpegEncContext * const s= &w->s;
-
- switch(w->abt_type_table[n]){
- case 0:
- if (s->block_last_index[n] >= 0) {
- s->dsp.idct_add (dst, stride, block1);
- }
- break;
- case 1:
- simple_idct84_add(dst , stride, block1);
- simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);
- memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
- break;
- case 2:
- simple_idct48_add(dst , stride, block1);
- simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);
- memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM));
- break;
- default:
- fprintf(stderr, "internal error in WMV2 abt\n");
- }
-}
-
-void ff_wmv2_add_mb(MpegEncContext *s, DCTELEM block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){
- Wmv2Context * const w= (Wmv2Context*)s;
-
- wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);
- wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);
- wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);
- wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);
- wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);
-}
-
-void ff_mspel_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h)
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- uint8_t *ptr;
- int dxy, offset, mx, my, src_x, src_y, v_edge_pos, linesize, uvlinesize;
- int emu=0;
-
- dxy = ((motion_y & 1) << 1) | (motion_x & 1);
- dxy = 2*dxy + w->hshift;
- src_x = s->mb_x * 16 + (motion_x >> 1);
- src_y = s->mb_y * 16 + (motion_y >> 1);
-
- /* WARNING: do no forget half pels */
- v_edge_pos = s->v_edge_pos;
- src_x = clip(src_x, -16, s->width);
- src_y = clip(src_y, -16, s->height);
- linesize = s->linesize;
- uvlinesize = s->uvlinesize;
- ptr = ref_picture[0] + (src_y * linesize) + src_x;
-
- if(s->flags&CODEC_FLAG_EMU_EDGE){
- if(src_x<1 || src_y<1 || src_x + 17 >= s->h_edge_pos
- || src_y + h+1 >= v_edge_pos){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr - 1 - s->linesize, s->linesize, 19, 19,
- src_x-1, src_y-1, s->h_edge_pos, s->v_edge_pos);
- ptr= s->edge_emu_buffer + 1 + s->linesize;
- emu=1;
- }
- }
-
- s->dsp.put_mspel_pixels_tab[dxy](dest_y , ptr , linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y+8 , ptr+8 , linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y +8*linesize, ptr +8*linesize, linesize);
- s->dsp.put_mspel_pixels_tab[dxy](dest_y+8+8*linesize, ptr+8+8*linesize, linesize);
-
- if(s->flags&CODEC_FLAG_GRAY) return;
-
- if (s->out_format == FMT_H263) {
- dxy = 0;
- if ((motion_x & 3) != 0)
- dxy |= 1;
- if ((motion_y & 3) != 0)
- dxy |= 2;
- mx = motion_x >> 2;
- my = motion_y >> 2;
- } else {
- mx = motion_x / 2;
- my = motion_y / 2;
- dxy = ((my & 1) << 1) | (mx & 1);
- mx >>= 1;
- my >>= 1;
- }
-
- src_x = s->mb_x * 8 + mx;
- src_y = s->mb_y * 8 + my;
- src_x = clip(src_x, -8, s->width >> 1);
- if (src_x == (s->width >> 1))
- dxy &= ~1;
- src_y = clip(src_y, -8, s->height >> 1);
- if (src_y == (s->height >> 1))
- dxy &= ~2;
- offset = (src_y * uvlinesize) + src_x;
- ptr = ref_picture[1] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
- src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[1][dxy](dest_cb, ptr, uvlinesize, h >> 1);
-
- ptr = ref_picture[2] + offset;
- if(emu){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9,
- src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
- ptr= s->edge_emu_buffer;
- }
- pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1);
-}
-
-
-static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
-{
- Wmv2Context * const w= (Wmv2Context*)s;
- int cbp, code, i;
- uint8_t *coded_val;
-
- if(w->j_type) return 0;
-
- if (s->pict_type == P_TYPE) {
- if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){
- /* skip mb */
- s->mb_intra = 0;
- for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skiped = 1;
- w->hshift=0;
- return 0;
- }
-
- code = get_vlc2(&s->gb, mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3);
- if (code < 0)
- return -1;
- s->mb_intra = (~code & 0x40) >> 6;
-
- cbp = code & 0x3f;
- } else {
- s->mb_intra = 1;
- code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2);
- if (code < 0){
- fprintf(stderr, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
- /* predict coded block pattern */
- cbp = 0;
- for(i=0;i<6;i++) {
- int val = ((code >> (5 - i)) & 1);
- if (i < 4) {
- int pred = coded_block_pred(s, i, &coded_val);
- val = val ^ pred;
- *coded_val = val;
- }
- cbp |= val << (5 - i);
- }
- }
-
- if (!s->mb_intra) {
- int mx, my;
-//printf("P at %d %d\n", s->mb_x, s->mb_y);
- wmv2_pred_motion(w, &mx, &my);
-
- if(cbp){
- if(s->per_mb_rl_table){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- if(w->abt_flag && w->per_mb_abt){
- w->per_block_abt= get_bits1(&s->gb);
- if(!w->per_block_abt)
- w->abt_type= decode012(&s->gb);
- }else
- w->per_block_abt=0;
- }
-
- if (wmv2_decode_motion(w, &mx, &my) < 0)
- return -1;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
-
- for (i = 0; i < 6; i++) {
- if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0)
- {
- fprintf(stderr,"\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
- } else {
-//if(s->pict_type==P_TYPE)
-// printf("%d%d ", s->inter_intra_pred, cbp);
-//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
- s->ac_pred = get_bits1(&s->gb);
- if(s->inter_intra_pred){
- s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
-// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
- }
- if(s->per_mb_rl_table && cbp){
- s->rl_table_index = decode012(&s->gb);
- s->rl_chroma_table_index = s->rl_table_index;
- }
-
- for (i = 0; i < 6; i++) {
- if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
- {
- fprintf(stderr,"\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
- return -1;
- }
- }
- }
-
- return 0;
-}
-
-static int wmv2_decode_init(AVCodecContext *avctx){
- Wmv2Context * const w= avctx->priv_data;
-
- if(ff_h263_decode_init(avctx) < 0)
- return -1;
-
- wmv2_common_init(w);
-
- return 0;
-}
-
-AVCodec wmv2_decoder = {
- "wmv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_decode_init,
- NULL,
- ff_h263_decode_end,
- ff_h263_decode_frame,
- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
-};
-
-#ifdef CONFIG_ENCODERS
-AVCodec wmv2_encoder = {
- "wmv2",
- CODEC_TYPE_VIDEO,
- CODEC_ID_WMV2,
- sizeof(Wmv2Context),
- wmv2_encode_init,
- MPV_encode_picture,
- MPV_encode_end,
-};
-#endif
+++ /dev/null
-/*
- * Wing Commander/Xan Video Decoder
- * Copyright (C) 2003 the ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-/**
- * @file xan.c
- * Xan video decoder for Wing Commander III & IV computer games
- * by Mario Brito (mbrito@student.dei.uc.pt)
- * and Mike Melanson (melanson@pcisys.net)
- *
- * The xan_wc3 decoder outputs the following colorspaces natively:
- * PAL8 (default), RGB555, RGB565, RGB24, BGR24, RGBA32, YUV444P
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-#include "avcodec.h"
-#include "dsputil.h"
-
-#define PALETTE_COUNT 256
-#define PALETTE_CONTROL_SIZE ((256 * 3) + 1)
-
-typedef struct XanContext {
-
- AVCodecContext *avctx;
- DSPContext dsp;
- AVFrame last_frame;
- AVFrame current_frame;
-
- unsigned char *buf;
- int size;
-
- unsigned char palette[PALETTE_COUNT * 4];
-
- /* scratch space */
- unsigned char *buffer1;
- unsigned char *buffer2;
-
-} XanContext;
-
-#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-/* RGB -> YUV conversion stuff */
-#define SCALEFACTOR 65536
-#define CENTERSAMPLE 128
-
-#define COMPUTE_Y(r, g, b) \
- (unsigned char) \
- ((y_r_table[r] + y_g_table[g] + y_b_table[b]) / SCALEFACTOR)
-#define COMPUTE_U(r, g, b) \
- (unsigned char) \
- ((u_r_table[r] + u_g_table[g] + u_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
-#define COMPUTE_V(r, g, b) \
- (unsigned char) \
- ((v_r_table[r] + v_g_table[g] + v_b_table[b]) / SCALEFACTOR + CENTERSAMPLE)
-
-#define Y_R (SCALEFACTOR * 0.29900)
-#define Y_G (SCALEFACTOR * 0.58700)
-#define Y_B (SCALEFACTOR * 0.11400)
-
-#define U_R (SCALEFACTOR * -0.16874)
-#define U_G (SCALEFACTOR * -0.33126)
-#define U_B (SCALEFACTOR * 0.50000)
-
-#define V_R (SCALEFACTOR * 0.50000)
-#define V_G (SCALEFACTOR * -0.41869)
-#define V_B (SCALEFACTOR * -0.08131)
-
-/*
- * Precalculate all of the YUV tables since it requires fewer than
- * 10 kilobytes to store them.
- */
-static int y_r_table[256];
-static int y_g_table[256];
-static int y_b_table[256];
-
-static int u_r_table[256];
-static int u_g_table[256];
-static int u_b_table[256];
-
-static int v_r_table[256];
-static int v_g_table[256];
-static int v_b_table[256];
-
-static int xan_decode_init(AVCodecContext *avctx)
-{
- XanContext *s = avctx->priv_data;
- int i;
-
- s->avctx = avctx;
-
- if ((avctx->codec->id == CODEC_ID_XAN_WC3) &&
- (s->avctx->extradata_size != sizeof(AVPaletteControl))) {
- printf (" WC3 Xan video: expected extradata_size of %d\n",
- sizeof(AVPaletteControl));
- return -1;
- }
-
- avctx->pix_fmt = PIX_FMT_PAL8;
- avctx->has_b_frames = 0;
- dsputil_init(&s->dsp, avctx);
-
- /* initialize the RGB -> YUV tables */
- for (i = 0; i < 256; i++) {
- y_r_table[i] = Y_R * i;
- y_g_table[i] = Y_G * i;
- y_b_table[i] = Y_B * i;
-
- u_r_table[i] = U_R * i;
- u_g_table[i] = U_G * i;
- u_b_table[i] = U_B * i;
-
- v_r_table[i] = V_R * i;
- v_g_table[i] = V_G * i;
- v_b_table[i] = V_B * i;
- }
-
- s->buffer1 = av_malloc(avctx->width * avctx->height);
- s->buffer2 = av_malloc(avctx->width * avctx->height);
- if (!s->buffer1 || !s->buffer2)
- return -1;
-
- return 0;
-}
-
-/* This function is used in lieu of memcpy(). This decoder can not use
- * memcpy because the memory locations often overlap and
- * memcpy doesn't like that; it's not uncommon, for example, for
- * dest = src+1, to turn byte A into pattern AAAAAAAA.
- * This was originally repz movsb in Intel x86 ASM. */
-static inline void bytecopy(unsigned char *dest, unsigned char *src, int count)
-{
- int i;
-
- for (i = 0; i < count; i++)
- dest[i] = src[i];
-}
-
-static int xan_huffman_decode(unsigned char *dest, unsigned char *src)
-{
- unsigned char byte = *src++;
- unsigned char ival = byte + 0x16;
- unsigned char * ptr = src + byte*2;
- unsigned char val = ival;
- int counter = 0;
-
- unsigned char bits = *ptr++;
-
- while ( val != 0x16 ) {
- if ( (1 << counter) & bits )
- val = src[byte + val - 0x17];
- else
- val = src[val - 0x17];
-
- if ( val < 0x16 ) {
- *dest++ = val;
- val = ival;
- }
-
- if (counter++ == 7) {
- counter = 0;
- bits = *ptr++;
- }
- }
-
- return 0;
-}
-
-static void xan_unpack(unsigned char *dest, unsigned char *src)
-{
- unsigned char opcode;
- int size;
- int offset;
- int byte1, byte2, byte3;
-
- for (;;) {
- opcode = *src++;
-
- if ( (opcode & 0x80) == 0 ) {
-
- offset = *src++;
-
- size = opcode & 3;
- bytecopy(dest, src, size); dest += size; src += size;
-
- size = ((opcode & 0x1c) >> 2) + 3;
- bytecopy (dest, dest - (((opcode & 0x60) << 3) + offset + 1), size);
- dest += size;
-
- } else if ( (opcode & 0x40) == 0 ) {
-
- byte1 = *src++;
- byte2 = *src++;
-
- size = byte1 >> 6;
- bytecopy (dest, src, size); dest += size; src += size;
-
- size = (opcode & 0x3f) + 4;
- bytecopy (dest, dest - (((byte1 & 0x3f) << 8) + byte2 + 1), size);
- dest += size;
-
- } else if ( (opcode & 0x20) == 0 ) {
-
- byte1 = *src++;
- byte2 = *src++;
- byte3 = *src++;
-
- size = opcode & 3;
- bytecopy (dest, src, size); dest += size; src += size;
-
- size = byte3 + 5 + ((opcode & 0xc) << 6);
- bytecopy (dest,
- dest - ((((opcode & 0x10) >> 4) << 0x10) + 1 + (byte1 << 8) + byte2),
- size);
- dest += size;
- } else {
- size = ((opcode & 0x1f) << 2) + 4;
-
- if (size > 0x70)
- break;
-
- bytecopy (dest, src, size); dest += size; src += size;
- }
- }
-
- size = opcode & 3;
- bytecopy(dest, src, size); dest += size; src += size;
-}
-
-static void inline xan_wc3_build_palette(XanContext *s,
- unsigned char *palette_data)
-{
- int i;
- unsigned char r, g, b;
- unsigned short *palette16;
- unsigned int *palette32;
-
- /* transform the palette passed through the palette control structure
- * into the necessary internal format depending on colorspace */
-
- switch (s->avctx->pix_fmt) {
-
- case PIX_FMT_RGB555:
- palette16 = (unsigned short *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette_data++;
- g = *palette_data++;
- b = *palette_data++;
- palette16[i] =
- ((r >> 3) << 10) |
- ((g >> 3) << 5) |
- ((b >> 3) << 0);
- }
- break;
-
- case PIX_FMT_RGB565:
- palette16 = (unsigned short *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette_data++;
- g = *palette_data++;
- b = *palette_data++;
- palette16[i] =
- ((r >> 3) << 11) |
- ((g >> 2) << 5) |
- ((b >> 3) << 0);
- }
- break;
-
- case PIX_FMT_RGB24:
- for (i = 0; i < PALETTE_COUNT; i++) {
- s->palette[i * 4 + 0] = *palette_data++;
- s->palette[i * 4 + 1] = *palette_data++;
- s->palette[i * 4 + 2] = *palette_data++;
- }
- break;
-
- case PIX_FMT_BGR24:
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette_data++;
- g = *palette_data++;
- b = *palette_data++;
- s->palette[i * 4 + 0] = b;
- s->palette[i * 4 + 1] = g;
- s->palette[i * 4 + 2] = r;
- }
- break;
-
- case PIX_FMT_PAL8:
- case PIX_FMT_RGBA32:
- palette32 = (unsigned int *)s->palette;
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette_data++;
- g = *palette_data++;
- b = *palette_data++;
- palette32[i] = (r << 16) | (g << 8) | (b);
- }
- break;
-
- case PIX_FMT_YUV444P:
- for (i = 0; i < PALETTE_COUNT; i++) {
- r = *palette_data++;
- g = *palette_data++;
- b = *palette_data++;
- s->palette[i * 4 + 0] = COMPUTE_Y(r, g, b);
- s->palette[i * 4 + 1] = COMPUTE_U(r, g, b);
- s->palette[i * 4 + 2] = COMPUTE_V(r, g, b);
- }
- break;
-
- default:
- printf (" Xan WC3: Unhandled colorspace\n");
- break;
- }
-}
-
-/* advance current_x variable; reset accounting variables if current_x
- * moves beyond width */
-#define ADVANCE_CURRENT_X() \
- current_x++; \
- if (current_x >= width) { \
- index += line_inc; \
- current_x = 0; \
- }
-
-static void inline xan_wc3_output_pixel_run(XanContext *s,
- unsigned char *pixel_buffer, int x, int y, int pixel_count)
-{
- int stride;
- int line_inc;
- int index;
- int current_x;
- int width = s->avctx->width;
- unsigned char pix;
- unsigned char *palette_plane;
- unsigned char *y_plane;
- unsigned char *u_plane;
- unsigned char *v_plane;
- unsigned char *rgb_plane;
- unsigned short *rgb16_plane;
- unsigned short *palette16;
- unsigned int *rgb32_plane;
- unsigned int *palette32;
-
- switch (s->avctx->pix_fmt) {
-
- case PIX_FMT_PAL8:
- palette_plane = s->current_frame.data[0];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width;
- index = y * stride + x;
- current_x = x;
- while(pixel_count--) {
-
- /* don't do a memcpy() here; keyframes generally copy an entire
- * frame of data and the stride needs to be accounted for */
- palette_plane[index++] = *pixel_buffer++;
-
- ADVANCE_CURRENT_X();
- }
- break;
-
- case PIX_FMT_RGB555:
- case PIX_FMT_RGB565:
- rgb16_plane = (unsigned short *)s->current_frame.data[0];
- palette16 = (unsigned short *)s->palette;
- stride = s->current_frame.linesize[0] / 2;
- line_inc = stride - width;
- index = y * stride + x;
- current_x = x;
- while(pixel_count--) {
-
- rgb16_plane[index++] = palette16[*pixel_buffer++];
-
- ADVANCE_CURRENT_X();
- }
- break;
-
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- rgb_plane = s->current_frame.data[0];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width * 3;
- index = y * stride + x * 3;
- current_x = x;
- while(pixel_count--) {
- pix = *pixel_buffer++;
-
- rgb_plane[index++] = s->palette[pix * 4 + 0];
- rgb_plane[index++] = s->palette[pix * 4 + 1];
- rgb_plane[index++] = s->palette[pix * 4 + 2];
-
- ADVANCE_CURRENT_X();
- }
- break;
-
- case PIX_FMT_RGBA32:
- rgb32_plane = (unsigned int *)s->current_frame.data[0];
- palette32 = (unsigned int *)s->palette;
- stride = s->current_frame.linesize[0] / 4;
- line_inc = stride - width;
- index = y * stride + x;
- current_x = x;
- while(pixel_count--) {
-
- rgb32_plane[index++] = palette32[*pixel_buffer++];
-
- ADVANCE_CURRENT_X();
- }
- break;
-
- case PIX_FMT_YUV444P:
- y_plane = s->current_frame.data[0];
- u_plane = s->current_frame.data[1];
- v_plane = s->current_frame.data[2];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width;
- index = y * stride + x;
- current_x = x;
- while(pixel_count--) {
- pix = *pixel_buffer++;
-
- y_plane[index] = s->palette[pix * 4 + 0];
- u_plane[index] = s->palette[pix * 4 + 1];
- v_plane[index] = s->palette[pix * 4 + 2];
-
- index++;
- ADVANCE_CURRENT_X();
- }
- break;
-
- default:
- printf (" Xan WC3: Unhandled colorspace\n");
- break;
- }
-}
-
-#define ADVANCE_CURFRAME_X() \
- curframe_x++; \
- if (curframe_x >= width) { \
- curframe_index += line_inc; \
- curframe_x = 0; \
- }
-
-#define ADVANCE_PREVFRAME_X() \
- prevframe_x++; \
- if (prevframe_x >= width) { \
- prevframe_index += line_inc; \
- prevframe_x = 0; \
- }
-
-static void inline xan_wc3_copy_pixel_run(XanContext *s,
- int x, int y, int pixel_count, int motion_x, int motion_y)
-{
- int stride;
- int line_inc;
- int curframe_index, prevframe_index;
- int curframe_x, prevframe_x;
- int width = s->avctx->width;
- unsigned char *palette_plane, *prev_palette_plane;
- unsigned char *y_plane, *u_plane, *v_plane;
- unsigned char *prev_y_plane, *prev_u_plane, *prev_v_plane;
- unsigned char *rgb_plane, *prev_rgb_plane;
- unsigned short *rgb16_plane, *prev_rgb16_plane;
- unsigned int *rgb32_plane, *prev_rgb32_plane;
-
- switch (s->avctx->pix_fmt) {
-
- case PIX_FMT_PAL8:
- palette_plane = s->current_frame.data[0];
- prev_palette_plane = s->last_frame.data[0];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width;
- curframe_index = y * stride + x;
- curframe_x = x;
- prevframe_index = (y + motion_y) * stride + x + motion_x;
- prevframe_x = x + motion_x;
- while(pixel_count--) {
-
- palette_plane[curframe_index++] =
- prev_palette_plane[prevframe_index++];
-
- ADVANCE_CURFRAME_X();
- ADVANCE_PREVFRAME_X();
- }
- break;
-
- case PIX_FMT_RGB555:
- case PIX_FMT_RGB565:
- rgb16_plane = (unsigned short *)s->current_frame.data[0];
- prev_rgb16_plane = (unsigned short *)s->last_frame.data[0];
- stride = s->current_frame.linesize[0] / 2;
- line_inc = stride - width;
- curframe_index = y * stride + x;
- curframe_x = x;
- prevframe_index = (y + motion_y) * stride + x + motion_x;
- prevframe_x = x + motion_x;
- while(pixel_count--) {
-
- rgb16_plane[curframe_index++] =
- prev_rgb16_plane[prevframe_index++];
-
- ADVANCE_CURFRAME_X();
- ADVANCE_PREVFRAME_X();
- }
- break;
-
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- rgb_plane = s->current_frame.data[0];
- prev_rgb_plane = s->last_frame.data[0];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width * 3;
- curframe_index = y * stride + x * 3;
- curframe_x = x;
- prevframe_index = (y + motion_y) * stride +
- (3 * (x + motion_x));
- prevframe_x = x + motion_x;
- while(pixel_count--) {
-
- rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++];
- rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++];
- rgb_plane[curframe_index++] = prev_rgb_plane[prevframe_index++];
-
- ADVANCE_CURFRAME_X();
- ADVANCE_PREVFRAME_X();
- }
- break;
-
- case PIX_FMT_RGBA32:
- rgb32_plane = (unsigned int *)s->current_frame.data[0];
- prev_rgb32_plane = (unsigned int *)s->last_frame.data[0];
- stride = s->current_frame.linesize[0] / 4;
- line_inc = stride - width;
- curframe_index = y * stride + x;
- curframe_x = x;
- prevframe_index = (y + motion_y) * stride + x + motion_x;
- prevframe_x = x + motion_x;
- while(pixel_count--) {
-
- rgb32_plane[curframe_index++] =
- prev_rgb32_plane[prevframe_index++];
-
- ADVANCE_CURFRAME_X();
- ADVANCE_PREVFRAME_X();
- }
- break;
-
- case PIX_FMT_YUV444P:
- y_plane = s->current_frame.data[0];
- u_plane = s->current_frame.data[1];
- v_plane = s->current_frame.data[2];
- prev_y_plane = s->last_frame.data[0];
- prev_u_plane = s->last_frame.data[1];
- prev_v_plane = s->last_frame.data[2];
- stride = s->current_frame.linesize[0];
- line_inc = stride - width;
- curframe_index = y * stride + x;
- curframe_x = x;
- prevframe_index = (y + motion_y) * stride + x + motion_x;
- prevframe_x = x + motion_x;
- while(pixel_count--) {
-
- y_plane[curframe_index] = prev_y_plane[prevframe_index];
- u_plane[curframe_index] = prev_u_plane[prevframe_index];
- v_plane[curframe_index] = prev_v_plane[prevframe_index];
-
- curframe_index++;
- ADVANCE_CURFRAME_X();
- prevframe_index++;
- ADVANCE_PREVFRAME_X();
- }
- break;
-
- default:
- printf (" Xan WC3: Unhandled colorspace\n");
- break;
- }
-}
-
-static void xan_wc3_decode_frame(XanContext *s) {
-
- int width = s->avctx->width;
- int height = s->avctx->height;
- int total_pixels = width * height;
- unsigned char opcode;
- unsigned char flag = 0;
- int size = 0;
- int motion_x, motion_y;
- int x, y;
-
- unsigned char *opcode_buffer = s->buffer1;
- unsigned char *imagedata_buffer = s->buffer2;
-
- /* pointers to segments inside the compressed chunk */
- unsigned char *huffman_segment;
- unsigned char *size_segment;
- unsigned char *vector_segment;
- unsigned char *imagedata_segment;
-
- huffman_segment = s->buf + LE_16(&s->buf[0]);
- size_segment = s->buf + LE_16(&s->buf[2]);
- vector_segment = s->buf + LE_16(&s->buf[4]);
- imagedata_segment = s->buf + LE_16(&s->buf[6]);
-
- xan_huffman_decode(opcode_buffer, huffman_segment);
-
- if (imagedata_segment[0] == 2)
- xan_unpack(imagedata_buffer, &imagedata_segment[1]);
- else
- imagedata_buffer = &imagedata_segment[1];
-
- /* use the decoded data segments to build the frame */
- x = y = 0;
- while (total_pixels) {
-
- opcode = *opcode_buffer++;
- size = 0;
-
- switch (opcode) {
-
- case 0:
- flag ^= 1;
- continue;
-
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- size = opcode;
- break;
-
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- size += (opcode - 10);
- break;
-
- case 9:
- case 19:
- size = *size_segment++;
- break;
-
- case 10:
- case 20:
- size = BE_16(&size_segment[0]);
- size_segment += 2;
- break;
-
- case 11:
- case 21:
- size = (size_segment[0] << 16) | (size_segment[1] << 8) |
- size_segment[2];
- size_segment += 3;
- break;
- }
-
- if (opcode < 12) {
- flag ^= 1;
- if (flag) {
- /* run of (size) pixels is unchanged from last frame */
- xan_wc3_copy_pixel_run(s, x, y, size, 0, 0);
- } else {
- /* output a run of pixels from imagedata_buffer */
- xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size);
- imagedata_buffer += size;
- }
- } else {
- /* run-based motion compensation from last frame */
- motion_x = (*vector_segment >> 4) & 0xF;
- motion_y = *vector_segment & 0xF;
- vector_segment++;
-
- /* sign extension */
- if (motion_x & 0x8)
- motion_x |= 0xFFFFFFF0;
- if (motion_y & 0x8)
- motion_y |= 0xFFFFFFF0;
-
- /* copy a run of pixels from the previous frame */
- xan_wc3_copy_pixel_run(s, x, y, size, motion_x, motion_y);
-
- flag = 0;
- }
-
- /* coordinate accounting */
- total_pixels -= size;
- while (size) {
- if (x + size >= width) {
- y++;
- size -= (width - x);
- x = 0;
- } else {
- x += size;
- size = 0;
- }
- }
- }
-
- /* for PAL8, make the palette available on the way out */
- if (s->avctx->pix_fmt == PIX_FMT_PAL8)
- memcpy(s->current_frame.data[1], s->palette, PALETTE_COUNT * 4);
-}
-
-static void xan_wc4_decode_frame(XanContext *s) {
-}
-
-static int xan_decode_frame(AVCodecContext *avctx,
- void *data, int *data_size,
- uint8_t *buf, int buf_size)
-{
- XanContext *s = avctx->priv_data;
- AVPaletteControl *palette_control = (AVPaletteControl *)avctx->extradata;
- int keyframe = 0;
-
- if (palette_control->palette_changed) {
- /* load the new palette and reset the palette control */
- xan_wc3_build_palette(s, palette_control->palette);
- palette_control->palette_changed = 0;
- keyframe = 1;
- }
-
- if (avctx->get_buffer(avctx, &s->current_frame)) {
- printf (" Xan Video: get_buffer() failed\n");
- return -1;
- }
- s->current_frame.reference = 3;
-
- s->buf = buf;
- s->size = buf_size;
-
- if (avctx->codec->id == CODEC_ID_XAN_WC3)
- xan_wc3_decode_frame(s);
- else if (avctx->codec->id == CODEC_ID_XAN_WC4)
- xan_wc4_decode_frame(s);
-
- /* release the last frame if it is allocated */
- if (s->last_frame.data[0])
- avctx->release_buffer(avctx, &s->last_frame);
-
- /* shuffle frames */
- s->last_frame = s->current_frame;
-
- *data_size = sizeof(AVFrame);
- *(AVFrame*)data = s->current_frame;
-
- /* always report that the buffer was completely consumed */
- return buf_size;
-}
-
-static int xan_decode_end(AVCodecContext *avctx)
-{
- XanContext *s = avctx->priv_data;
-
- /* release the last frame */
- avctx->release_buffer(avctx, &s->last_frame);
-
- av_free(s->buffer1);
- av_free(s->buffer2);
-
- return 0;
-}
-
-AVCodec xan_wc3_decoder = {
- "xan_wc3",
- CODEC_TYPE_VIDEO,
- CODEC_ID_XAN_WC3,
- sizeof(XanContext),
- xan_decode_init,
- NULL,
- xan_decode_end,
- xan_decode_frame,
- CODEC_CAP_DR1,
-};
-
-/*
-AVCodec xan_wc4_decoder = {
- "xan_wc4",
- CODEC_TYPE_VIDEO,
- CODEC_ID_XAN_WC4,
- sizeof(XanContext),
- xan_decode_init,
- NULL,
- xan_decode_end,
- xan_decode_frame,
- CODEC_CAP_DR1,
-};
-*/
+++ /dev/null
-/*
- * XVideo Motion Compensation
- * Copyright (c) 2003 Ivan Kalvachev
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <limits.h>
-
-//avcodec include
-#include "avcodec.h"
-#include "dsputil.h"
-#include "mpegvideo.h"
-
-#undef NDEBUG
-#include <assert.h>
-
-#ifdef USE_FASTMEMCPY
-#include "fastmemcpy.h"
-#endif
-
-#ifdef HAVE_XVMC
-
-//X11 includes are in the xvmc_render.h
-//by replacing it with none-X one
-//XvMC emulation could be performed
-
-#include "xvmc_render.h"
-
-//#include "xvmc_debug.h"
-
-static int calc_cbp(MpegEncContext *s, int blocknum){
-/* compute cbp */
-// for I420 bit_offset=5
-int i,cbp = 0;
- for(i=0; i<blocknum; i++) {
- if(s->block_last_index[i] >= 0)
- cbp |= 1 << (5 - i);
- }
- return cbp;
-}
-
-
-
-//these functions should be called on every new field or/and frame
-//They should be safe if they are called few times for same field!
-int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx){
-xvmc_render_state_t * render,* last, * next;
-
- assert(avctx != NULL);
-
- render = (xvmc_render_state_t*)s->current_picture.data[2];
- assert(render != NULL);
- if( (render == NULL) || (render->magic != MP_XVMC_RENDER_MAGIC) )
- return -1;//make sure that this is render packet
-
- render->picture_structure = s->picture_structure;
- render->flags = (s->first_field)? 0: XVMC_SECOND_FIELD;
-
-//make sure that all data is drawn by XVMC_end_frame
- assert(render->filled_mv_blocks_num==0);
-
- render->p_future_surface = NULL;
- render->p_past_surface = NULL;
-
- switch(s->pict_type){
- case I_TYPE:
- return 0;// no prediction from other frames
- case B_TYPE:
- next = (xvmc_render_state_t*)s->next_picture.data[2];
- assert(next!=NULL);
- assert(next->state & MP_XVMC_STATE_PREDICTION);
- if(next == NULL) return -1;
- if(next->magic != MP_XVMC_RENDER_MAGIC) return -1;
- render->p_future_surface = next->p_surface;
- //no return here, going to set forward prediction
- case P_TYPE:
- last = (xvmc_render_state_t*)s->last_picture.data[2];
- if(last == NULL)// && !s->first_field)
- last = render;//predict second field from the first
- if(last->magic != MP_XVMC_RENDER_MAGIC) return -1;
- assert(last->state & MP_XVMC_STATE_PREDICTION);
- render->p_past_surface = last->p_surface;
- return 0;
- }
-
-return -1;
-}
-
-void XVMC_field_end(MpegEncContext *s){
-xvmc_render_state_t * render;
- render = (xvmc_render_state_t*)s->current_picture.data[2];
- assert(render != NULL);
-
- if(render->filled_mv_blocks_num > 0){
-// printf("xvmcvideo.c: rendering %d left blocks after last slice!!!\n",render->filled_mv_blocks_num );
- ff_draw_horiz_band(s,0,0);
- }
-}
-
-void XVMC_decode_mb(MpegEncContext *s, DCTELEM block[6][64]){
-XvMCMacroBlock * mv_block;
-xvmc_render_state_t * render;
-int i,cbp,blocks_per_mb;
-
-const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
-
-
- if(s->encoding){
- fprintf(stderr,"XVMC doesn't support encoding!!!\n");
- assert(0);
- return;
- }
-
- //from MPV_decode_mb(),
- /* update DC predictors for P macroblocks */
- if (!s->mb_intra) {
- s->last_dc[0] =
- s->last_dc[1] =
- s->last_dc[2] = 128 << s->intra_dc_precision;
- }
-
- //MC doesn't skip blocks
- s->mb_skiped = 0;
-
-
- // do I need to export quant when I could not perform postprocessing?
- // anyway, it doesn't hurrt
- s->current_picture.qscale_table[mb_xy] = s->qscale;
-
-//START OF XVMC specific code
- render = (xvmc_render_state_t*)s->current_picture.data[2];
- assert(render!=NULL);
- assert(render->magic==MP_XVMC_RENDER_MAGIC);
- assert(render->mv_blocks);
-
- //take the next free macroblock
- mv_block = &render->mv_blocks[render->start_mv_blocks_num +
- render->filled_mv_blocks_num ];
-
-// memset(mv_block,0,sizeof(XvMCMacroBlock));
-
- mv_block->x = s->mb_x;
- mv_block->y = s->mb_y;
- mv_block->dct_type = s->interlaced_dct;//XVMC_DCT_TYPE_FRAME/FIELD;
-// mv_block->motion_type = 0; //zero to silense warnings
- if(s->mb_intra){
- mv_block->macroblock_type = XVMC_MB_TYPE_INTRA;//no MC, all done
- }else{
- mv_block->macroblock_type = XVMC_MB_TYPE_PATTERN;
-
- if(s->mv_dir & MV_DIR_FORWARD){
- mv_block->macroblock_type|= XVMC_MB_TYPE_MOTION_FORWARD;
- //pmv[n][dir][xy]=mv[dir][n][xy]
- mv_block->PMV[0][0][0] = s->mv[0][0][0];
- mv_block->PMV[0][0][1] = s->mv[0][0][1];
- mv_block->PMV[1][0][0] = s->mv[0][1][0];
- mv_block->PMV[1][0][1] = s->mv[0][1][1];
- }
- if(s->mv_dir & MV_DIR_BACKWARD){
- mv_block->macroblock_type|=XVMC_MB_TYPE_MOTION_BACKWARD;
- mv_block->PMV[0][1][0] = s->mv[1][0][0];
- mv_block->PMV[0][1][1] = s->mv[1][0][1];
- mv_block->PMV[1][1][0] = s->mv[1][1][0];
- mv_block->PMV[1][1][1] = s->mv[1][1][1];
- }
-
- switch(s->mv_type){
- case MV_TYPE_16X16:
- mv_block->motion_type = XVMC_PREDICTION_FRAME;
- break;
- case MV_TYPE_16X8:
- mv_block->motion_type = XVMC_PREDICTION_16x8;
- break;
- case MV_TYPE_FIELD:
- mv_block->motion_type = XVMC_PREDICTION_FIELD;
- if(s->picture_structure == PICT_FRAME){
- mv_block->PMV[0][0][1]<<=1;
- mv_block->PMV[1][0][1]<<=1;
- mv_block->PMV[0][1][1]<<=1;
- mv_block->PMV[1][1][1]<<=1;
- }
- break;
- case MV_TYPE_DMV:
- mv_block->motion_type = XVMC_PREDICTION_DUAL_PRIME;
- if(s->picture_structure == PICT_FRAME){
-
- mv_block->PMV[0][0][0] = s->mv[0][0][0];//top from top
- mv_block->PMV[0][0][1] = s->mv[0][0][1]<<1;
-
- mv_block->PMV[0][1][0] = s->mv[0][0][0];//bottom from bottom
- mv_block->PMV[0][1][1] = s->mv[0][0][1]<<1;
-
- mv_block->PMV[1][0][0] = s->mv[0][2][0];//dmv00, top from bottom
- mv_block->PMV[1][0][1] = s->mv[0][2][1]<<1;//dmv01
-
- mv_block->PMV[1][1][0] = s->mv[0][3][0];//dmv10, bottom from top
- mv_block->PMV[1][1][1] = s->mv[0][3][1]<<1;//dmv11
-
- }else{
- mv_block->PMV[0][1][0] = s->mv[0][2][0];//dmv00
- mv_block->PMV[0][1][1] = s->mv[0][2][1];//dmv01
- }
- break;
- default:
- assert(0);
- }
-
- mv_block->motion_vertical_field_select = 0;
-
-//set correct field referenses
- if(s->mv_type == MV_TYPE_FIELD || s->mv_type == MV_TYPE_16X8){
- if( s->field_select[0][0] ) mv_block->motion_vertical_field_select|=1;
- if( s->field_select[1][0] ) mv_block->motion_vertical_field_select|=2;
- if( s->field_select[0][1] ) mv_block->motion_vertical_field_select|=4;
- if( s->field_select[1][1] ) mv_block->motion_vertical_field_select|=8;
- }
- }//!intra
-//time to handle data blocks;
- mv_block->index = render->next_free_data_block_num;
- blocks_per_mb = 6;
-/*
- switch( s->chroma_format){
- case CHROMA_422:
- blocks_per_mb = 8;
- break;
- case CHROMA_444:
- blocks_per_mb = 12;
- break;
- }
-*/
- if(s->flags & CODEC_FLAG_GRAY){
- if(s->mb_intra){//intra frames are alwasy full chroma block
- memset(block[4],0,sizeof(short)*8*8);//so we need to clear them
- memset(block[5],0,sizeof(short)*8*8);
- if(!render->unsigned_intra)
- block[4][0] = block[5][0] = 1<<10;
- }
- else
- blocks_per_mb = 4;//Luminance blocks only
- };
- cbp = calc_cbp(s,blocks_per_mb);
- mv_block->coded_block_pattern = cbp;
- if(cbp == 0)
- mv_block->macroblock_type &= ~XVMC_MB_TYPE_PATTERN;
-
- for(i=0; i<blocks_per_mb; i++){
- if(s->block_last_index[i] >= 0){
- // i do not have unsigned_intra MOCO to test, hope it is OK
- if( (s->mb_intra) && ( render->idct || (!render->idct && !render->unsigned_intra)) )
- block[i][0]-=1<<10;
- if(!render->idct){
- s->dsp.idct(block[i]);
- //!!TODO!clip!!!
- }
-//TODO:avoid block copy by modifying s->block pointer
- memcpy(&render->data_blocks[(render->next_free_data_block_num++)*64],
- block[i],sizeof(short)*8*8);
- }
- }
- render->filled_mv_blocks_num++;
-
- assert(render->filled_mv_blocks_num <= render->total_number_of_mv_blocks);
- assert(render->next_free_data_block_num <= render->total_number_of_data_blocks);
-
-
- if(render->filled_mv_blocks_num >= render->total_number_of_mv_blocks)
- ff_draw_horiz_band(s,0,0);
-
-// DumpRenderInfo(render);
-// DumpMBlockInfo(mv_block);
-
-}
-
-#endif
+++ /dev/null
-/*
- * 4X Technologies .4xm File Demuxer (no muxer)
- * Copyright (c) 2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file 4xm.c
- * 4X Technologies file demuxer
- * by Mike Melanson (melanson@pcisys.net)
- * for more information on the .4xm file format, visit:
- * http://www.pcisys.net/~melanson/codecs/
- */
-
-#include "avformat.h"
-
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
- ( (long)(unsigned char)(ch0) | \
- ( (long)(unsigned char)(ch1) << 8 ) | \
- ( (long)(unsigned char)(ch2) << 16 ) | \
- ( (long)(unsigned char)(ch3) << 24 ) )
-
-#define RIFF_TAG FOURCC_TAG('R', 'I', 'F', 'F')
-#define _4XMV_TAG FOURCC_TAG('4', 'X', 'M', 'V')
-#define LIST_TAG FOURCC_TAG('L', 'I', 'S', 'T')
-#define HEAD_TAG FOURCC_TAG('H', 'E', 'A', 'D')
-#define TRK__TAG FOURCC_TAG('T', 'R', 'K', '_')
-#define MOVI_TAG FOURCC_TAG('M', 'O', 'V', 'I')
-#define VTRK_TAG FOURCC_TAG('V', 'T', 'R', 'K')
-#define STRK_TAG FOURCC_TAG('S', 'T', 'R', 'K')
-#define name_TAG FOURCC_TAG('n', 'a', 'm', 'e')
-#define vtrk_TAG FOURCC_TAG('v', 't', 'r', 'k')
-#define strk_TAG FOURCC_TAG('s', 't', 'r', 'k')
-#define ifrm_TAG FOURCC_TAG('i', 'f', 'r', 'm')
-#define pfrm_TAG FOURCC_TAG('p', 'f', 'r', 'm')
-#define cfrm_TAG FOURCC_TAG('c', 'f', 'r', 'm')
-#define snd__TAG FOURCC_TAG('s', 'n', 'd', '_')
-#define _TAG FOURCC_TAG('', '', '', '')
-
-#define vtrk_SIZE 0x44
-#define strk_SIZE 0x28
-
-#define GET_LIST_HEADER() \
- fourcc_tag = get_le32(pb); \
- size = get_le32(pb); \
- if (fourcc_tag != LIST_TAG) \
- return AVERROR_INVALIDDATA; \
- fourcc_tag = get_le32(pb);
-
-typedef struct AudioTrack {
- int sample_rate;
- int bits;
- int channels;
- int stream_index;
- int adpcm;
-} AudioTrack;
-
-typedef struct FourxmDemuxContext {
- int width;
- int height;
- int video_stream_index;
- int track_count;
- AudioTrack *tracks;
- int selected_track;
-
- int64_t pts;
- int last_chunk_was_audio;
- int last_audio_frame_count;
-} FourxmDemuxContext;
-
-static int fourxm_probe(AVProbeData *p)
-{
- if (p->buf_size < 12)
- return 0;
-
- if ((LE_32(&p->buf[0]) != RIFF_TAG) ||
- (LE_32(&p->buf[8]) != _4XMV_TAG))
- return 0;
-
- return AVPROBE_SCORE_MAX;
-}
-
-static int fourxm_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- ByteIOContext *pb = &s->pb;
- unsigned int fourcc_tag;
- unsigned int size;
- int header_size;
- FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data;
- unsigned char *header;
- int i;
- int current_track = -1;
- AVStream *st;
-
- fourxm->track_count = 0;
- fourxm->tracks = NULL;
- fourxm->selected_track = 0;
-
- /* skip the first 3 32-bit numbers */
- url_fseek(pb, 12, SEEK_CUR);
-
- /* check for LIST-HEAD */
- GET_LIST_HEADER();
- header_size = size - 4;
- if (fourcc_tag != HEAD_TAG)
- return AVERROR_INVALIDDATA;
-
- /* allocate space for the header and load the whole thing */
- header = av_malloc(header_size);
- if (!header)
- return AVERROR_NOMEM;
- if (get_buffer(pb, header, header_size) != header_size)
- return AVERROR_IO;
-
- /* take the lazy approach and search for any and all vtrk and strk chunks */
- for (i = 0; i < header_size - 8; i++) {
- fourcc_tag = LE_32(&header[i]);
- size = LE_32(&header[i + 4]);
-
- if (fourcc_tag == vtrk_TAG) {
- /* check that there is enough data */
- if (size != vtrk_SIZE) {
- av_free(header);
- return AVERROR_INVALIDDATA;
- }
- fourxm->width = LE_32(&header[i + 36]);
- fourxm->height = LE_32(&header[i + 40]);
- i += 8 + size;
-
- /* allocate a new AVStream */
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- fourxm->video_stream_index = st->index;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_4XM;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = fourxm->width;
- st->codec.height = fourxm->height;
-
- } else if (fourcc_tag == strk_TAG) {
- /* check that there is enough data */
- if (size != strk_SIZE) {
- av_free(header);
- return AVERROR_INVALIDDATA;
- }
- current_track = LE_32(&header[i + 8]);
- if (current_track + 1 > fourxm->track_count) {
- fourxm->track_count = current_track + 1;
- fourxm->tracks = av_realloc(fourxm->tracks,
- fourxm->track_count * sizeof(AudioTrack));
- if (!fourxm->tracks) {
- av_free(header);
- return AVERROR_NOMEM;
- }
- }
- fourxm->tracks[current_track].adpcm = LE_32(&header[i + 12]);
- fourxm->tracks[current_track].channels = LE_32(&header[i + 36]);
- fourxm->tracks[current_track].sample_rate = LE_32(&header[i + 40]);
- fourxm->tracks[current_track].bits = LE_32(&header[i + 44]);
- printf("bps:%d\n", fourxm->tracks[current_track].bits);
- i += 8 + size;
-
- /* allocate a new AVStream */
- st = av_new_stream(s, current_track);
- if (!st)
- return AVERROR_NOMEM;
-
- fourxm->tracks[current_track].stream_index = st->index;
-
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = 1;
- st->codec.channels = fourxm->tracks[current_track].channels;
- st->codec.sample_rate = fourxm->tracks[current_track].sample_rate;
- st->codec.bits_per_sample = fourxm->tracks[current_track].bits;
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
- st->codec.bits_per_sample;
- st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
- if (fourxm->tracks[current_track].adpcm)
- st->codec.codec_id = CODEC_ID_ADPCM_4XM;
- else if (st->codec.bits_per_sample == 8)
- st->codec.codec_id = CODEC_ID_PCM_U8;
- else
- st->codec.codec_id = CODEC_ID_PCM_S16LE;
- }
- }
-
- av_free(header);
-
- /* skip over the LIST-MOVI chunk (which is where the stream should be */
- GET_LIST_HEADER();
- if (fourcc_tag != MOVI_TAG)
- return AVERROR_INVALIDDATA;
-
- /* initialize context members */
- fourxm->pts = 0;
- fourxm->last_chunk_was_audio = 0;
- fourxm->last_audio_frame_count = 0;
-
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
- return 0;
-}
-
-static int fourxm_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- FourxmDemuxContext *fourxm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- unsigned int fourcc_tag;
- unsigned int size, out_size;
- int ret = 0;
- int track_number;
- int packet_read = 0;
- unsigned char header[8];
- int64_t pts_inc;
-
- while (!packet_read) {
-
- if ((ret = get_buffer(&s->pb, header, 8)) < 0)
- return ret;
- fourcc_tag = LE_32(&header[0]);
- size = LE_32(&header[4]);
- if (url_feof(pb))
- return -EIO;
- switch (fourcc_tag) {
-
- case LIST_TAG:
- /* skip the LIST-* tag and move on to the next fourcc */
- get_le32(pb);
- break;
-
- case ifrm_TAG:
- case pfrm_TAG:
- case cfrm_TAG:{
-
- /* bump the pts if the last data sent out was audio */
- if (fourxm->last_chunk_was_audio) {
- fourxm->last_chunk_was_audio = 0;
- pts_inc = fourxm->last_audio_frame_count;
- pts_inc *= 90000;
- pts_inc /= fourxm->tracks[fourxm->selected_track].sample_rate;
- fourxm->pts += pts_inc;
- }
-
- /* allocate 8 more bytes than 'size' to account for fourcc
- * and size */
- if (av_new_packet(pkt, size + 8))
- return -EIO;
- pkt->stream_index = fourxm->video_stream_index;
- pkt->pts = fourxm->pts;
- memcpy(pkt->data, header, 8);
- ret = get_buffer(&s->pb, &pkt->data[8], size);
-
- if (ret < 0)
- av_free_packet(pkt);
- else
- packet_read = 1;
- break;
- }
-
- case snd__TAG:
- track_number = get_le32(pb);
- out_size= get_le32(pb);
- size-=8;
-
- if (track_number == fourxm->selected_track) {
- if (av_new_packet(pkt, size))
- return -EIO;
- pkt->stream_index =
- fourxm->tracks[fourxm->selected_track].stream_index;
- pkt->pts = fourxm->pts;
- ret = get_buffer(&s->pb, pkt->data, size);
- if (ret < 0)
- av_free_packet(pkt);
- else
- packet_read = 1;
-
- /* maintain pts info for the benefit of the video track */
- fourxm->last_chunk_was_audio = 1;
- fourxm->last_audio_frame_count = size /
- ((fourxm->tracks[fourxm->selected_track].bits / 8) *
- fourxm->tracks[fourxm->selected_track].channels);
-
- } else {
- url_fseek(pb, size, SEEK_CUR);
- }
- break;
-
- default:
- url_fseek(pb, size, SEEK_CUR);
- break;
- }
- }
- return ret;
-}
-
-static int fourxm_read_close(AVFormatContext *s)
-{
- FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data;
-
- av_free(fourxm->tracks);
-
- return 0;
-}
-
-static AVInputFormat fourxm_iformat = {
- "4xm",
- "4X Technologies format",
- sizeof(FourxmDemuxContext),
- fourxm_probe,
- fourxm_read_header,
- fourxm_read_packet,
- fourxm_read_close,
-};
-
-int fourxm_init(void)
-{
- av_register_input_format(&fourxm_iformat);
- return 0;
-}
+++ /dev/null
-#
-# libavformat Makefile
-# (c) 2000-2003 Fabrice Bellard
-#
-include ../config.mak
-
-VPATH=$(SRC_PATH)/libavformat
-
-CFLAGS= $(OPTFLAGS) -Wall -I.. -I$(SRC_PATH) -I$(SRC_PATH)/libavcodec -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE
-
-OBJS= utils.o cutils.o os_support.o allformats.o
-PPOBJS=
-
-# mux and demuxes
-OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o raw.o rm.o \
- avienc.o avidec.o wav.o swf.o au.o gif.o mov.o mpjpeg.o dvcore.o dv.o \
- yuv4mpeg.o 4xm.o flvenc.o flvdec.o movenc.o psxstr.o idroq.o ipmovie.o \
- nut.o wc3movie.o mp3.o
-
-ifeq ($(CONFIG_RISKY),yes)
-OBJS+= asf.o
-endif
-
-ifeq ($(AMR_NB),yes)
-OBJS+= amr.o
-endif
-
-# image formats
-OBJS+= pnm.o yuv.o png.o jpeg.o gifdec.o
-# file I/O
-OBJS+= avio.o aviobuf.o file.o
-OBJS+= framehook.o
-
-ifeq ($(CONFIG_VIDEO4LINUX),yes)
-OBJS+= grab.o
-endif
-
-ifeq ($(CONFIG_DV1394),yes)
-OBJS+= dv1394.o
-endif
-
-ifeq ($(CONFIG_AUDIO_OSS),yes)
-OBJS+= audio.o
-endif
-
-ifeq ($(CONFIG_AUDIO_BEOS),yes)
-PPOBJS+= beosaudio.o
-EXTRALIBS+=-lbe -lmedia
-# this should be the default !
-EXTRALIBS+=-lavcodec -L../libavcodec
-endif
-
-ifeq ($(CONFIG_NETWORK),yes)
-OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o
-# BeOS and Darwin network stuff
-ifeq ($(NEED_INET_ATON),yes)
-OBJS+= barpainet.o
-endif
-endif
-
-ifeq ($(CONFIG_VORBIS),yes)
-OBJS+= ogg.o
-endif
-
-LIB= $(LIBPREF)avformat$(LIBSUF)
-ifeq ($(BUILD_SHARED),yes)
-SLIB= $(SLIBPREF)avformat$(SLIBSUF)
-endif
-
-SRCS := $(OBJS:.o=.c) $(PPOBJS:.o=.cpp)
-
-all: $(LIB) $(SLIB)
-
-$(LIB): $(OBJS) $(PPOBJS)
- rm -f $@
- $(AR) rc $@ $(OBJS) $(PPOBJS)
- $(RANLIB) $@
-
-$(SLIB): $(OBJS)
-ifeq ($(CONFIG_WIN32),yes)
- $(CC) $(SHFLAGS) -Wl,--output-def,$(@:.dll=.def) -o $@ $(OBJS) $(PPOBJS) $(EXTRALIBS) $(VPATH)/../libavcodec/avcodec.dll
- -lib /machine:i386 /def:$(@:.dll=.def)
-else
- $(CC) $(SHFLAGS) -o $@ $(OBJS) $(PPOBJS) $(EXTRALIBS)
-endif
-
-depend: $(SRCS)
- $(CC) -MM $(CFLAGS) $^ 1>.depend
-
-ifeq ($(BUILD_SHARED),yes)
-install: all install-headers
-ifeq ($(CONFIG_WIN32),yes)
- install -s -m 755 $(SLIB) "$(prefix)"
-else
- install -d $(prefix)/lib
- install -s -m 755 $(SLIB) $(prefix)/lib/libavformat-$(VERSION).so
- ln -sf libavformat-$(VERSION).so $(prefix)/lib/libavformat.so
- ldconfig || true
-endif
-else
-install:
-endif
-
-installlib: all install-headers
- install -m 644 $(LIB) $(prefix)/lib
-
-install-headers:
- mkdir -p "$(prefix)/include/ffmpeg"
- install -m 644 $(SRC_PATH)/libavformat/avformat.h $(SRC_PATH)/libavformat/avio.h \
- $(SRC_PATH)/libavformat/rtp.h $(SRC_PATH)/libavformat/rtsp.h \
- $(SRC_PATH)/libavformat/rtspcodes.h \
- "$(prefix)/include/ffmpeg"
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-# BeOS: remove -Wall to get rid of all the "multibyte constant" warnings
-%.o: %.cpp
- g++ $(subst -Wall,,$(CFLAGS)) -c -o $@ $<
-
-clean:
- rm -f *.o *.d .depend *~ *.a $(LIB)
-
-#
-# include dependency files if they exist
-#
-ifneq ($(wildcard .depend),)
-include .depend
-endif
+++ /dev/null
-EXTRA_DIST= *.nsh
+++ /dev/null
-/*
- * Register all the formats and protocols
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* If you do not call this function, then you can select exactly which
- formats you want to support */
-
-/**
- * Initialize libavcodec and register all the codecs and formats.
- */
-void av_register_all(void)
-{
- avcodec_init();
- avcodec_register_all();
-
- mpegps_init();
- mpegts_init();
- crc_init();
- img_init();
- raw_init();
- mp3_init();
- rm_init();
-#ifdef CONFIG_RISKY
- asf_init();
-#endif
- avienc_init();
- avidec_init();
- wav_init();
- swf_init();
- au_init();
- gif_init();
- mov_init();
- movenc_init();
- jpeg_init();
- dv_init();
- fourxm_init();
- flvenc_init();
- flvdec_init();
- str_init();
- roq_init();
- ipmovie_init();
- wc3_init();
-
-#ifdef AMR_NB
- amr_init();
-#endif
- yuv4mpeg_init();
-
-#ifdef CONFIG_VORBIS
- ogg_init();
-#endif
-
-#ifndef CONFIG_WIN32
- ffm_init();
-#endif
-#ifdef CONFIG_VIDEO4LINUX
- video_grab_init();
-#endif
-#if defined(CONFIG_AUDIO_OSS) || defined(CONFIG_AUDIO_BEOS)
- audio_init();
-#endif
-
-#ifdef CONFIG_DV1394
- dv1394_init();
-#endif
-
- nut_init();
-
- /* image formats */
- av_register_image_format(&pnm_image_format);
- av_register_image_format(&pbm_image_format);
- av_register_image_format(&pgm_image_format);
- av_register_image_format(&ppm_image_format);
- av_register_image_format(&pam_image_format);
- av_register_image_format(&pgmyuv_image_format);
- av_register_image_format(&yuv_image_format);
-#ifdef CONFIG_ZLIB
- av_register_image_format(&png_image_format);
-#endif
- av_register_image_format(&jpeg_image_format);
- av_register_image_format(&gif_image_format);
-
- /* file protocols */
- register_protocol(&file_protocol);
- register_protocol(&pipe_protocol);
-#ifdef CONFIG_NETWORK
- rtsp_init();
- rtp_init();
- register_protocol(&udp_protocol);
- register_protocol(&rtp_protocol);
- register_protocol(&tcp_protocol);
- register_protocol(&http_protocol);
-#endif
-}
+++ /dev/null
-/*
- * amr file format
- * Copyright (c) 2001 ffmpeg project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
-Write and read amr data according to RFC3267, http://www.ietf.org/rfc/rfc3267.txt?number=3267
-
-Only amr narrowband (not amr-wb) is supported for now.
-
-*/
-#include "avformat.h"
-#include "avi.h"
-
-static const unsigned char AMR_header [] = "#!AMR\n";
-
-/* AMR_FILE header */
-static int put_amr_header(ByteIOContext *pb, AVCodecContext *enc)
-{
- put_tag(pb, AMR_header); /* magic number */
- return 0;
-}
-
-static int amr_write_header(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- s->priv_data = NULL;
-
- /* format header */
- if (put_amr_header(pb, &s->streams[0]->codec) < 0) {
- return -1;
- }
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int amr_write_packet(AVFormatContext *s, int stream_index_ptr,
- uint8_t *buf, int size, int force_pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int amr_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-static int amr_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size < 6)
- return 0;
- if(memcmp(p->buf,AMR_header,6)==0)
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-/* amr input */
-static int amr_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- ByteIOContext *pb = &s->pb;
- AVStream *st;
- uint8_t header[6];
-
- get_buffer(pb, header, 6);
-
- if(memcmp(header,AMR_header,6)!=0)
- {
- return -1;
- }
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = CODEC_ID_AMR_NB;
- st->codec.codec_id = CODEC_ID_AMR_NB;
- st->codec.channels = 1;
- st->codec.sample_rate = 8000;
- return 0;
-}
-
-#define MAX_SIZE 32
-
-static int amr_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- static uint16_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0};
- uint8_t toc, q, ft;
- int read;
- int size;
-
- if (url_feof(&s->pb))
- return -EIO;
-
- toc=0;
-
- toc=get_byte(&s->pb);
-
- q = (toc >> 2) & 0x01;
- ft = (toc >> 3) & 0x0F;
-
- size=packed_size[ft];
- //printf("amr_read_packet size=%d\n",size);
-
- if (av_new_packet(pkt, size+1))
- return -EIO;
- pkt->stream_index = 0;
-
- pkt->data[0]=toc;
-
- read = get_buffer(&s->pb, pkt->data+1, size);
-
- if (read != size)
- {
- av_free_packet(pkt);
- return -EIO;
- }
-
- return 0;
-}
-
-static int amr_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVInputFormat amr_iformat = {
- "amr",
- "3gpp amr file format",
- 0,
- amr_probe,
- amr_read_header,
- amr_read_packet,
- amr_read_close,
-};
-
-static AVOutputFormat amr_oformat = {
- "amr",
- "3gpp amr file format",
- "audio/amr",
- "amr",
- 0,
- CODEC_ID_AMR_NB,
- CODEC_ID_NONE,
- amr_write_header,
- amr_write_packet,
- amr_write_trailer,
-};
-
-int amr_init(void)
-{
- av_register_input_format(&amr_iformat);
- av_register_output_format(&amr_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * ASF compatible encoder and decoder.
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-#include "mpegaudio.h"
-
-#define PACKET_SIZE 3200
-#define PACKET_HEADER_SIZE 12
-#define FRAME_HEADER_SIZE 17
-
-typedef struct {
- int num;
- int seq;
- /* use for reading */
- AVPacket pkt;
- int frag_offset;
- int timestamp;
- int64_t duration;
-
- int ds_span; /* descrambling */
- int ds_packet_size;
- int ds_chunk_size;
- int ds_data_size;
- int ds_silence_data;
-
-} ASFStream;
-
-typedef struct {
- uint32_t v1;
- uint16_t v2;
- uint16_t v3;
- uint8_t v4[8];
-} GUID;
-
-typedef struct {
- GUID guid; // generated by client computer
- uint64_t file_size; // in bytes
- // invalid if broadcasting
- uint64_t create_time; // time of creation, in 100-nanosecond units since 1.1.1601
- // invalid if broadcasting
- uint64_t packets_count; // how many packets are there in the file
- // invalid if broadcasting
- uint64_t play_time; // play time, in 100-nanosecond units
- // invalid if broadcasting
- uint64_t send_time; // time to send file, in 100-nanosecond units
- // invalid if broadcasting (could be ignored)
- uint32_t preroll; // timestamp of the first packet, in milliseconds
- // if nonzero - substract from time
- uint32_t ignore; // preroll is 64bit - but let's just ignore it
- uint32_t flags; // 0x01 - broadcast
- // 0x02 - seekable
- // rest is reserved should be 0
- uint32_t min_pktsize; // size of a data packet
- // invalid if broadcasting
- uint32_t max_pktsize; // shall be the same as for min_pktsize
- // invalid if broadcasting
- uint32_t max_bitrate; // bandwith of stream in bps
- // should be the sum of bitrates of the
- // individual media streams
-} ASFMainHeader;
-
-
-typedef struct {
- int seqno;
- int packet_size;
- int is_streamed;
- int asfid2avid[128]; /* conversion table from asf ID 2 AVStream ID */
- ASFStream streams[128]; /* it's max number and it's not that big */
- /* non streamed additonnal info */
- int64_t nb_packets;
- int64_t duration; /* in 100ns units */
- /* packet filling */
- int packet_size_left;
- int packet_timestamp_start;
- int packet_timestamp_end;
- int packet_nb_frames;
- uint8_t packet_buf[PACKET_SIZE];
- ByteIOContext pb;
- /* only for reading */
- uint64_t data_offset; /* begining of the first data packet */
-
- ASFMainHeader hdr;
-
- int packet_flags;
- int packet_property;
- int packet_timestamp;
- int packet_segsizetype;
- int packet_segments;
- int packet_seq;
- int packet_replic_size;
- int packet_key_frame;
- int packet_padsize;
- int packet_frag_offset;
- int packet_frag_size;
- int packet_frag_timestamp;
- int packet_multi_size;
- int packet_obj_size;
- int packet_time_delta;
- int packet_time_start;
-
- int stream_index;
- ASFStream* asf_st; /* currently decoded stream */
-} ASFContext;
-
-static const GUID asf_header = {
- 0x75B22630, 0x668E, 0x11CF, { 0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C },
-};
-
-static const GUID file_header = {
- 0x8CABDCA1, 0xA947, 0x11CF, { 0x8E, 0xE4, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
-};
-
-static const GUID stream_header = {
- 0xB7DC0791, 0xA9B7, 0x11CF, { 0x8E, 0xE6, 0x00, 0xC0, 0x0C, 0x20, 0x53, 0x65 },
-};
-
-static const GUID audio_stream = {
- 0xF8699E40, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-static const GUID audio_conceal_none = {
- // 0x49f1a440, 0x4ece, 0x11d0, { 0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
- // New value lifted from avifile
- 0x20fb5700, 0x5b55, 0x11cf, { 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b },
-};
-
-static const GUID video_stream = {
- 0xBC19EFC0, 0x5B4D, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-static const GUID video_conceal_none = {
- 0x20FB5700, 0x5B55, 0x11CF, { 0xA8, 0xFD, 0x00, 0x80, 0x5F, 0x5C, 0x44, 0x2B },
-};
-
-
-static const GUID comment_header = {
- 0x75b22633, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
-};
-
-static const GUID codec_comment_header = {
- 0x86D15240, 0x311D, 0x11D0, { 0xA3, 0xA4, 0x00, 0xA0, 0xC9, 0x03, 0x48, 0xF6 },
-};
-static const GUID codec_comment1_header = {
- 0x86d15241, 0x311d, 0x11d0, { 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6 },
-};
-
-static const GUID data_header = {
- 0x75b22636, 0x668e, 0x11cf, { 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c },
-};
-
-static const GUID index_guid = {
- 0x33000890, 0xe5b1, 0x11cf, { 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb },
-};
-
-static const GUID head1_guid = {
- 0x5fbf03b5, 0xa92e, 0x11cf, { 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
-};
-
-static const GUID head2_guid = {
- 0xabd3d211, 0xa9ba, 0x11cf, { 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65 },
-};
-
-/* I am not a number !!! This GUID is the one found on the PC used to
- generate the stream */
-static const GUID my_guid = {
- 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 },
-};
-
-static void put_guid(ByteIOContext *s, const GUID *g)
-{
- int i;
-
- put_le32(s, g->v1);
- put_le16(s, g->v2);
- put_le16(s, g->v3);
- for(i=0;i<8;i++)
- put_byte(s, g->v4[i]);
-}
-
-static void put_str16(ByteIOContext *s, const char *tag)
-{
- int c;
-
- put_le16(s,strlen(tag) + 1);
- for(;;) {
- c = (uint8_t)*tag++;
- put_le16(s, c);
- if (c == '\0')
- break;
- }
-}
-
-static void put_str16_nolen(ByteIOContext *s, const char *tag)
-{
- int c;
-
- for(;;) {
- c = (uint8_t)*tag++;
- put_le16(s, c);
- if (c == '\0')
- break;
- }
-}
-
-static int64_t put_header(ByteIOContext *pb, const GUID *g)
-{
- int64_t pos;
-
- pos = url_ftell(pb);
- put_guid(pb, g);
- put_le64(pb, 24);
- return pos;
-}
-
-/* update header size */
-static void end_header(ByteIOContext *pb, int64_t pos)
-{
- int64_t pos1;
-
- pos1 = url_ftell(pb);
- url_fseek(pb, pos + 16, SEEK_SET);
- put_le64(pb, pos1 - pos);
- url_fseek(pb, pos1, SEEK_SET);
-}
-
-/* write an asf chunk (only used in streaming case) */
-static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int length;
-
- length = payload_length + 8;
- put_le16(pb, type);
- put_le16(pb, length);
- put_le32(pb, asf->seqno);
- put_le16(pb, flags); /* unknown bytes */
- put_le16(pb, length);
- asf->seqno++;
-}
-
-/* convert from unix to windows time */
-static int64_t unix_to_file_time(int ti)
-{
- int64_t t;
-
- t = ti * int64_t_C(10000000);
- t += int64_t_C(116444736000000000);
- return t;
-}
-
-/* write the header (used two times if non streamed) */
-static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int header_size, n, extra_size, extra_size2, wav_extra_size, file_time;
- int has_title;
- AVCodecContext *enc;
- int64_t header_offset, cur_pos, hpos;
- int bit_rate;
-
- has_title = (s->title[0] || s->author[0] || s->copyright[0] || s->comment[0]);
-
- bit_rate = 0;
- for(n=0;n<s->nb_streams;n++) {
- enc = &s->streams[n]->codec;
-
- bit_rate += enc->bit_rate;
- }
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */
- }
-
- put_guid(pb, &asf_header);
- put_le64(pb, -1); /* header length, will be patched after */
- put_le32(pb, 3 + has_title + s->nb_streams); /* number of chunks in header */
- put_byte(pb, 1); /* ??? */
- put_byte(pb, 2); /* ??? */
-
- /* file header */
- header_offset = url_ftell(pb);
- hpos = put_header(pb, &file_header);
- put_guid(pb, &my_guid);
- put_le64(pb, file_size);
- file_time = 0;
- put_le64(pb, unix_to_file_time(file_time));
- put_le64(pb, asf->nb_packets); /* number of packets */
- put_le64(pb, asf->duration); /* end time stamp (in 100ns units) */
- put_le64(pb, asf->duration); /* duration (in 100ns units) */
- put_le32(pb, 0); /* start time stamp */
- put_le32(pb, 0); /* ??? */
- put_le32(pb, asf->is_streamed ? 1 : 0); /* ??? */
- put_le32(pb, asf->packet_size); /* packet size */
- put_le32(pb, asf->packet_size); /* packet size */
- put_le32(pb, bit_rate); /* Nominal data rate in bps */
- end_header(pb, hpos);
-
- /* unknown headers */
- hpos = put_header(pb, &head1_guid);
- put_guid(pb, &head2_guid);
- put_le32(pb, 6);
- put_le16(pb, 0);
- end_header(pb, hpos);
-
- /* title and other infos */
- if (has_title) {
- hpos = put_header(pb, &comment_header);
- put_le16(pb, 2 * (strlen(s->title) + 1));
- put_le16(pb, 2 * (strlen(s->author) + 1));
- put_le16(pb, 2 * (strlen(s->copyright) + 1));
- put_le16(pb, 2 * (strlen(s->comment) + 1));
- put_le16(pb, 0);
- put_str16_nolen(pb, s->title);
- put_str16_nolen(pb, s->author);
- put_str16_nolen(pb, s->copyright);
- put_str16_nolen(pb, s->comment);
- end_header(pb, hpos);
- }
-
- /* stream headers */
- for(n=0;n<s->nb_streams;n++) {
- int64_t es_pos;
- // ASFStream *stream = &asf->streams[n];
-
- enc = &s->streams[n]->codec;
- asf->streams[n].num = n + 1;
- asf->streams[n].seq = 0;
-
- switch(enc->codec_type) {
- case CODEC_TYPE_AUDIO:
- wav_extra_size = 0;
- extra_size = 18 + wav_extra_size;
- extra_size2 = 0;
- break;
- default:
- case CODEC_TYPE_VIDEO:
- wav_extra_size = 0;
- extra_size = 0x33;
- extra_size2 = 0;
- break;
- }
-
- hpos = put_header(pb, &stream_header);
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- put_guid(pb, &audio_stream);
- put_guid(pb, &audio_conceal_none);
- } else {
- put_guid(pb, &video_stream);
- put_guid(pb, &video_conceal_none);
- }
- put_le64(pb, 0); /* ??? */
- es_pos = url_ftell(pb);
- put_le32(pb, extra_size); /* wav header len */
- put_le32(pb, extra_size2); /* additional data len */
- put_le16(pb, n + 1); /* stream number */
- put_le32(pb, 0); /* ??? */
-
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- /* WAVEFORMATEX header */
- int wavsize = put_wav_header(pb, enc);
-
- if (wavsize < 0)
- return -1;
- if (wavsize != extra_size) {
- cur_pos = url_ftell(pb);
- url_fseek(pb, es_pos, SEEK_SET);
- put_le32(pb, wavsize); /* wav header len */
- url_fseek(pb, cur_pos, SEEK_SET);
- }
- } else {
- put_le32(pb, enc->width);
- put_le32(pb, enc->height);
- put_byte(pb, 2); /* ??? */
- put_le16(pb, 40); /* size */
-
- /* BITMAPINFOHEADER header */
- put_bmp_header(pb, enc, codec_bmp_tags, 1);
- }
- end_header(pb, hpos);
- }
-
- /* media comments */
-
- hpos = put_header(pb, &codec_comment_header);
- put_guid(pb, &codec_comment1_header);
- put_le32(pb, s->nb_streams);
- for(n=0;n<s->nb_streams;n++) {
- AVCodec *p;
-
- enc = &s->streams[n]->codec;
- p = avcodec_find_encoder(enc->codec_id);
-
- put_le16(pb, asf->streams[n].num);
- put_str16(pb, p ? p->name : enc->codec_name);
- put_le16(pb, 0); /* no parameters */
-
-
- /* id */
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- put_le16(pb, 2);
- if(!enc->codec_tag)
- enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
- if(!enc->codec_tag)
- return -1;
- put_le16(pb, enc->codec_tag);
- } else {
- put_le16(pb, 4);
- if(!enc->codec_tag)
- enc->codec_tag = codec_get_tag(codec_bmp_tags, enc->codec_id);
- if(!enc->codec_tag)
- return -1;
- put_le32(pb, enc->codec_tag);
- }
- }
- end_header(pb, hpos);
-
- /* patch the header size fields */
-
- cur_pos = url_ftell(pb);
- header_size = cur_pos - header_offset;
- if (asf->is_streamed) {
- header_size += 8 + 30 + 50;
-
- url_fseek(pb, header_offset - 10 - 30, SEEK_SET);
- put_le16(pb, header_size);
- url_fseek(pb, header_offset - 2 - 30, SEEK_SET);
- put_le16(pb, header_size);
-
- header_size -= 8 + 30 + 50;
- }
- header_size += 24 + 6;
- url_fseek(pb, header_offset - 14, SEEK_SET);
- put_le64(pb, header_size);
- url_fseek(pb, cur_pos, SEEK_SET);
-
- /* movie chunk, followed by packets of packet_size */
- asf->data_offset = cur_pos;
- put_guid(pb, &data_header);
- put_le64(pb, data_chunk_size);
- put_guid(pb, &my_guid);
- put_le64(pb, asf->nb_packets); /* nb packets */
- put_byte(pb, 1); /* ??? */
- put_byte(pb, 1); /* ??? */
- return 0;
-}
-
-static int asf_write_header(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
-
- av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
- asf->packet_size = PACKET_SIZE;
- asf->nb_packets = 0;
-
- if (asf_write_header1(s, 0, 50) < 0) {
- //av_free(asf);
- return -1;
- }
-
- put_flush_packet(&s->pb);
-
- asf->packet_nb_frames = 0;
- asf->packet_timestamp_start = -1;
- asf->packet_timestamp_end = -1;
- asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
- init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
- NULL, NULL, NULL, NULL);
-
- return 0;
-}
-
-static int asf_write_stream_header(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
-
- asf->is_streamed = 1;
-
- return asf_write_header(s);
-}
-
-/* write a fixed size packet */
-static int put_packet(AVFormatContext *s,
- unsigned int timestamp, unsigned int duration,
- int nb_frames, int padsize)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int flags;
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4424, asf->packet_size, 0);
- }
-
- put_byte(pb, 0x82);
- put_le16(pb, 0);
-
- flags = 0x01; /* nb segments present */
- if (padsize > 0) {
- if (padsize < 256)
- flags |= 0x08;
- else
- flags |= 0x10;
- }
- put_byte(pb, flags); /* flags */
- put_byte(pb, 0x5d);
- if (flags & 0x10)
- put_le16(pb, padsize - 2);
- if (flags & 0x08)
- put_byte(pb, padsize - 1);
- put_le32(pb, timestamp);
- put_le16(pb, duration);
- put_byte(pb, nb_frames | 0x80);
-
- return PACKET_HEADER_SIZE + ((flags & 0x18) >> 3);
-}
-
-static void flush_packet(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- int hdr_size, ptr;
-
- hdr_size = put_packet(s, asf->packet_timestamp_start,
- asf->packet_timestamp_end - asf->packet_timestamp_start,
- asf->packet_nb_frames, asf->packet_size_left);
-
- /* Clear out the padding bytes */
- ptr = asf->packet_size - hdr_size - asf->packet_size_left;
- memset(asf->packet_buf + ptr, 0, asf->packet_size_left);
-
- put_buffer(&s->pb, asf->packet_buf, asf->packet_size - hdr_size);
-
- put_flush_packet(&s->pb);
- asf->nb_packets++;
- asf->packet_nb_frames = 0;
- asf->packet_timestamp_start = -1;
- asf->packet_timestamp_end = -1;
- asf->packet_size_left = asf->packet_size - PACKET_HEADER_SIZE;
- init_put_byte(&asf->pb, asf->packet_buf, asf->packet_size, 1,
- NULL, NULL, NULL, NULL);
-}
-
-static void put_frame_header(AVFormatContext *s, ASFStream *stream, int timestamp,
- int payload_size, int frag_offset, int frag_len)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &asf->pb;
- int val;
-
- val = stream->num;
- if (s->streams[val - 1]->codec.coded_frame->key_frame /* && frag_offset == 0 */)
- val |= 0x80;
- put_byte(pb, val);
- put_byte(pb, stream->seq);
- put_le32(pb, frag_offset); /* fragment offset */
- put_byte(pb, 0x08); /* flags */
- put_le32(pb, payload_size);
- put_le32(pb, timestamp);
- put_le16(pb, frag_len);
-}
-
-
-/* Output a frame. We suppose that payload_size <= PACKET_SIZE.
-
- It is there that you understand that the ASF format is really
- crap. They have misread the MPEG Systems spec !
- */
-static void put_frame(AVFormatContext *s, ASFStream *stream, int timestamp,
- const uint8_t *buf, int payload_size)
-{
- ASFContext *asf = s->priv_data;
- int frag_pos, frag_len, frag_len1;
-
- frag_pos = 0;
- while (frag_pos < payload_size) {
- frag_len = payload_size - frag_pos;
- frag_len1 = asf->packet_size_left - FRAME_HEADER_SIZE;
- if (frag_len1 > 0) {
- if (frag_len > frag_len1)
- frag_len = frag_len1;
- put_frame_header(s, stream, timestamp+1, payload_size, frag_pos, frag_len);
- put_buffer(&asf->pb, buf, frag_len);
- asf->packet_size_left -= (frag_len + FRAME_HEADER_SIZE);
- asf->packet_timestamp_end = timestamp;
- if (asf->packet_timestamp_start == -1)
- asf->packet_timestamp_start = timestamp;
- asf->packet_nb_frames++;
- } else {
- frag_len = 0;
- }
- frag_pos += frag_len;
- buf += frag_len;
- /* output the frame if filled */
- if (asf->packet_size_left <= FRAME_HEADER_SIZE)
- flush_packet(s);
- }
- stream->seq++;
-}
-
-
-static int asf_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t timestamp)
-{
- ASFContext *asf = s->priv_data;
- ASFStream *stream;
- int64_t duration;
- AVCodecContext *codec;
-
- codec = &s->streams[stream_index]->codec;
- stream = &asf->streams[stream_index];
-
- if (codec->codec_type == CODEC_TYPE_AUDIO) {
- duration = (codec->frame_number * codec->frame_size * int64_t_C(10000000)) /
- codec->sample_rate;
- } else {
- duration = av_rescale(codec->frame_number * codec->frame_rate_base, 10000000, codec->frame_rate);
- }
- if (duration > asf->duration)
- asf->duration = duration;
-
- put_frame(s, stream, timestamp, buf, size);
- return 0;
-}
-
-static int asf_write_trailer(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- int64_t file_size;
-
- /* flush the current packet */
- if (asf->pb.buf_ptr > asf->pb.buffer)
- flush_packet(s);
-
- if (asf->is_streamed) {
- put_chunk(s, 0x4524, 0, 0); /* end of stream */
- } else {
- /* rewrite an updated header */
- file_size = url_ftell(&s->pb);
- url_fseek(&s->pb, 0, SEEK_SET);
- asf_write_header1(s, file_size, file_size - asf->data_offset);
- }
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-/**********************************/
-/* decoding */
-
-//#define DEBUG
-
-#ifdef DEBUG
-#define PRINT_IF_GUID(g,cmp) \
-if (!memcmp(g, &cmp, sizeof(GUID))) \
- printf("(GUID: %s) ", #cmp)
-
-static void print_guid(const GUID *g)
-{
- int i;
- PRINT_IF_GUID(g, asf_header);
- else PRINT_IF_GUID(g, file_header);
- else PRINT_IF_GUID(g, stream_header);
- else PRINT_IF_GUID(g, audio_stream);
- else PRINT_IF_GUID(g, audio_conceal_none);
- else PRINT_IF_GUID(g, video_stream);
- else PRINT_IF_GUID(g, video_conceal_none);
- else PRINT_IF_GUID(g, comment_header);
- else PRINT_IF_GUID(g, codec_comment_header);
- else PRINT_IF_GUID(g, codec_comment1_header);
- else PRINT_IF_GUID(g, data_header);
- else PRINT_IF_GUID(g, index_guid);
- else PRINT_IF_GUID(g, head1_guid);
- else PRINT_IF_GUID(g, head2_guid);
- else PRINT_IF_GUID(g, my_guid);
- else
- printf("(GUID: unknown) ");
- printf("0x%08x, 0x%04x, 0x%04x, {", g->v1, g->v2, g->v3);
- for(i=0;i<8;i++)
- printf(" 0x%02x,", g->v4[i]);
- printf("}\n");
-}
-#undef PRINT_IF_GUID(g,cmp)
-#endif
-
-static void get_guid(ByteIOContext *s, GUID *g)
-{
- int i;
-
- g->v1 = get_le32(s);
- g->v2 = get_le16(s);
- g->v3 = get_le16(s);
- for(i=0;i<8;i++)
- g->v4[i] = get_byte(s);
-}
-
-#if 0
-static void get_str16(ByteIOContext *pb, char *buf, int buf_size)
-{
- int len, c;
- char *q;
-
- len = get_le16(pb);
- q = buf;
- while (len > 0) {
- c = get_le16(pb);
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- len--;
- }
- *q = '\0';
-}
-#endif
-
-static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size)
-{
- int c;
- char *q;
-
- q = buf;
- while (len > 0) {
- c = get_le16(pb);
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- len-=2;
- }
- *q = '\0';
-}
-
-static int asf_probe(AVProbeData *pd)
-{
- GUID g;
- const unsigned char *p;
- int i;
-
- /* check file header */
- if (pd->buf_size <= 32)
- return 0;
- p = pd->buf;
- g.v1 = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
- p += 4;
- g.v2 = p[0] | (p[1] << 8);
- p += 2;
- g.v3 = p[0] | (p[1] << 8);
- p += 2;
- for(i=0;i<8;i++)
- g.v4[i] = *p++;
-
- if (!memcmp(&g, &asf_header, sizeof(GUID)))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- ASFContext *asf = s->priv_data;
- GUID g;
- ByteIOContext *pb = &s->pb;
- AVStream *st;
- ASFStream *asf_st;
- int size, i;
- int64_t gsize;
-
- av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
- get_guid(pb, &g);
- if (memcmp(&g, &asf_header, sizeof(GUID)))
- goto fail;
- get_le64(pb);
- get_le32(pb);
- get_byte(pb);
- get_byte(pb);
- memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
- for(;;) {
- get_guid(pb, &g);
- gsize = get_le64(pb);
-#ifdef DEBUG
- printf("%08Lx: ", url_ftell(pb) - 24);
- print_guid(&g);
- printf(" size=0x%Lx\n", gsize);
-#endif
- if (gsize < 24)
- goto fail;
- if (!memcmp(&g, &file_header, sizeof(GUID))) {
- get_guid(pb, &asf->hdr.guid);
- asf->hdr.file_size = get_le64(pb);
- asf->hdr.create_time = get_le64(pb);
- asf->hdr.packets_count = get_le64(pb);
- asf->hdr.play_time = get_le64(pb);
- asf->hdr.send_time = get_le64(pb);
- asf->hdr.preroll = get_le32(pb);
- asf->hdr.ignore = get_le32(pb);
- asf->hdr.flags = get_le32(pb);
- asf->hdr.min_pktsize = get_le32(pb);
- asf->hdr.max_pktsize = get_le32(pb);
- asf->hdr.max_bitrate = get_le32(pb);
- asf->packet_size = asf->hdr.max_pktsize;
- asf->nb_packets = asf->hdr.packets_count;
- } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
- int type, total_size, type_specific_size;
- unsigned int tag1;
- int64_t pos1, pos2;
-
- pos1 = url_ftell(pb);
-
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
- asf_st = av_mallocz(sizeof(ASFStream));
- if (!asf_st)
- goto fail;
- st->priv_data = asf_st;
- st->start_time = asf->hdr.preroll / (10000000 / AV_TIME_BASE);
- st->duration = (asf->hdr.send_time - asf->hdr.preroll) /
- (10000000 / AV_TIME_BASE);
- get_guid(pb, &g);
- if (!memcmp(&g, &audio_stream, sizeof(GUID))) {
- type = CODEC_TYPE_AUDIO;
- } else if (!memcmp(&g, &video_stream, sizeof(GUID))) {
- type = CODEC_TYPE_VIDEO;
- } else {
- goto fail;
- }
- get_guid(pb, &g);
- total_size = get_le64(pb);
- type_specific_size = get_le32(pb);
- get_le32(pb);
- st->id = get_le16(pb) & 0x7f; /* stream id */
- // mapping of asf ID to AV stream ID;
- asf->asfid2avid[st->id] = s->nb_streams - 1;
-
- get_le32(pb);
- st->codec.codec_type = type;
- st->codec.frame_rate = 15 * s->pts_den / s->pts_num; // 15 fps default
- if (type == CODEC_TYPE_AUDIO) {
- get_wav_header(pb, &st->codec, type_specific_size);
- /* We have to init the frame size at some point .... */
- pos2 = url_ftell(pb);
- if (gsize > (pos2 + 8 - pos1 + 24)) {
- asf_st->ds_span = get_byte(pb);
- asf_st->ds_packet_size = get_le16(pb);
- asf_st->ds_chunk_size = get_le16(pb);
- asf_st->ds_data_size = get_le16(pb);
- asf_st->ds_silence_data = get_byte(pb);
- }
- //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n",
- // asf_st->ds_packet_size, asf_st->ds_chunk_size,
- // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data);
- if (asf_st->ds_span > 1) {
- if (!asf_st->ds_chunk_size
- || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1))
- asf_st->ds_span = 0; // disable descrambling
- }
- switch (st->codec.codec_id) {
- case CODEC_ID_MP3:
- st->codec.frame_size = MPA_FRAME_SIZE;
- break;
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- case CODEC_ID_PCM_S8:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- st->codec.frame_size = 1;
- break;
- default:
- /* This is probably wrong, but it prevents a crash later */
- st->codec.frame_size = 1;
- break;
- }
- } else {
- get_le32(pb);
- get_le32(pb);
- get_byte(pb);
- size = get_le16(pb); /* size */
- get_le32(pb); /* size */
- st->codec.width = get_le32(pb);
- st->codec.height = get_le32(pb);
- /* not available for asf */
- get_le16(pb); /* panes */
- st->codec.bits_per_sample = get_le16(pb); /* depth */
- tag1 = get_le32(pb);
- url_fskip(pb, 20);
- if (size > 40) {
- st->codec.extradata_size = size - 40;
- st->codec.extradata = av_mallocz(st->codec.extradata_size);
- get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
- }
- st->codec.codec_tag = tag1;
- st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
- }
- pos2 = url_ftell(pb);
- url_fskip(pb, gsize - (pos2 - pos1 + 24));
- } else if (!memcmp(&g, &data_header, sizeof(GUID))) {
- break;
- } else if (!memcmp(&g, &comment_header, sizeof(GUID))) {
- int len1, len2, len3, len4, len5;
-
- len1 = get_le16(pb);
- len2 = get_le16(pb);
- len3 = get_le16(pb);
- len4 = get_le16(pb);
- len5 = get_le16(pb);
- get_str16_nolen(pb, len1, s->title, sizeof(s->title));
- get_str16_nolen(pb, len2, s->author, sizeof(s->author));
- get_str16_nolen(pb, len3, s->copyright, sizeof(s->copyright));
- get_str16_nolen(pb, len4, s->comment, sizeof(s->comment));
- url_fskip(pb, len5);
-#if 0
- } else if (!memcmp(&g, &head1_guid, sizeof(GUID))) {
- int v1, v2;
- get_guid(pb, &g);
- v1 = get_le32(pb);
- v2 = get_le16(pb);
- } else if (!memcmp(&g, &codec_comment_header, sizeof(GUID))) {
- int len, v1, n, num;
- char str[256], *q;
- char tag[16];
-
- get_guid(pb, &g);
- print_guid(&g);
-
- n = get_le32(pb);
- for(i=0;i<n;i++) {
- num = get_le16(pb); /* stream number */
- get_str16(pb, str, sizeof(str));
- get_str16(pb, str, sizeof(str));
- len = get_le16(pb);
- q = tag;
- while (len > 0) {
- v1 = get_byte(pb);
- if ((q - tag) < sizeof(tag) - 1)
- *q++ = v1;
- len--;
- }
- *q = '\0';
- }
-#endif
- } else if (url_feof(pb)) {
- goto fail;
- } else {
- url_fseek(pb, gsize - 24, SEEK_CUR);
- }
- }
- get_guid(pb, &g);
- get_le64(pb);
- get_byte(pb);
- get_byte(pb);
- if (url_feof(pb))
- goto fail;
- asf->data_offset = url_ftell(pb);
- asf->packet_size_left = 0;
-
- return 0;
-
- fail:
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = s->streams[i];
- if (st) {
- av_free(st->priv_data);
- av_free(st->codec.extradata);
- }
- av_free(st);
- }
- return -1;
-}
-
-#define DO_2BITS(bits, var, defval) \
- switch (bits & 3) \
- { \
- case 3: var = get_le32(pb); rsize += 4; break; \
- case 2: var = get_le16(pb); rsize += 2; break; \
- case 1: var = get_byte(pb); rsize++; break; \
- default: var = defval; break; \
- }
-
-static int asf_get_packet(AVFormatContext *s)
-{
- ASFContext *asf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- uint32_t packet_length, padsize;
- int rsize = 11;
- int c = get_byte(pb);
- if (c != 0x82) {
- if (!url_feof(pb))
- printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
- return -EIO;
- }
- if ((c & 0x0f) == 2) { // always true for now
- if (get_le16(pb) != 0) {
- if (!url_feof(pb))
- printf("ff asf bad non zero\n");
- return -EIO;
- }
- }
-
- asf->packet_flags = get_byte(pb);
- asf->packet_property = get_byte(pb);
-
- DO_2BITS(asf->packet_flags >> 5, packet_length, asf->packet_size);
- DO_2BITS(asf->packet_flags >> 1, padsize, 0); // sequence ignored
- DO_2BITS(asf->packet_flags >> 3, padsize, 0); // padding length
-
- asf->packet_timestamp = get_le32(pb);
- get_le16(pb); /* duration */
- // rsize has at least 11 bytes which have to be present
-
- if (asf->packet_flags & 0x01) {
- asf->packet_segsizetype = get_byte(pb); rsize++;
- asf->packet_segments = asf->packet_segsizetype & 0x3f;
- } else {
- asf->packet_segments = 1;
- asf->packet_segsizetype = 0x80;
- }
- asf->packet_size_left = packet_length - padsize - rsize;
- if (packet_length < asf->hdr.min_pktsize)
- padsize += asf->hdr.min_pktsize - packet_length;
- asf->packet_padsize = padsize;
-#ifdef DEBUG
- printf("packet: size=%d padsize=%d left=%d\n", asf->packet_size, asf->packet_padsize, asf->packet_size_left);
-#endif
- return 0;
-}
-
-static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- ASFContext *asf = s->priv_data;
- ASFStream *asf_st = 0;
- ByteIOContext *pb = &s->pb;
- //static int pc = 0;
- for (;;) {
- int rsize = 0;
- if (asf->packet_size_left < FRAME_HEADER_SIZE
- || asf->packet_segments < 1) {
- //asf->packet_size_left <= asf->packet_padsize) {
- int ret = asf->packet_size_left + asf->packet_padsize;
- //printf("PacketLeftSize:%d Pad:%d Pos:%Ld\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb));
- /* fail safe */
- url_fskip(pb, ret);
- ret = asf_get_packet(s);
- //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++);
- if (ret < 0 || url_feof(pb))
- return -EIO;
- asf->packet_time_start = 0;
- continue;
- }
- if (asf->packet_time_start == 0) {
- /* read frame header */
- int num = get_byte(pb);
- asf->packet_segments--;
- rsize++;
- asf->packet_key_frame = (num & 0x80) >> 7;
- asf->stream_index = asf->asfid2avid[num & 0x7f];
- // sequence should be ignored!
- DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
- DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
- DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
-
- if (asf->packet_replic_size > 1) {
- // it should be always at least 8 bytes - FIXME validate
- asf->packet_obj_size = get_le32(pb);
- asf->packet_frag_timestamp = get_le32(pb); // timestamp
- if (asf->packet_replic_size > 8)
- url_fskip(pb, asf->packet_replic_size - 8);
- rsize += asf->packet_replic_size; // FIXME - check validity
- } else {
- // multipacket - frag_offset is begining timestamp
- asf->packet_time_start = asf->packet_frag_offset;
- asf->packet_frag_offset = 0;
- asf->packet_frag_timestamp = asf->packet_timestamp;
-
- if (asf->packet_replic_size == 1) {
- asf->packet_time_delta = get_byte(pb);
- rsize++;
- }
- }
- if (asf->packet_flags & 0x01) {
- DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
-#undef DO_2BITS
- //printf("Fragsize %d\n", asf->packet_frag_size);
- } else {
- asf->packet_frag_size = asf->packet_size_left - rsize;
- //printf("Using rest %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
- }
- if (asf->packet_replic_size == 1) {
- asf->packet_multi_size = asf->packet_frag_size;
- if (asf->packet_multi_size > asf->packet_size_left) {
- asf->packet_segments = 0;
- continue;
- }
- }
- asf->packet_size_left -= rsize;
- //printf("___objsize____ %d %d rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
-
- if (asf->stream_index < 0) {
- asf->packet_time_start = 0;
- /* unhandled packet (should not happen) */
- url_fskip(pb, asf->packet_frag_size);
- asf->packet_size_left -= asf->packet_frag_size;
- printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
- continue;
- }
- asf->asf_st = s->streams[asf->stream_index]->priv_data;
- }
- asf_st = asf->asf_st;
-
- if ((asf->packet_frag_offset != asf_st->frag_offset
- || (asf->packet_frag_offset
- && asf->packet_seq != asf_st->seq)) // seq should be ignored
- ) {
- /* cannot continue current packet: free it */
- // FIXME better check if packet was already allocated
- printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
- asf_st->pkt.size,
- asf->packet_obj_size,
- asf->packet_frag_offset, asf_st->frag_offset,
- asf->packet_seq, asf_st->seq, asf->packet_frag_size);
- if (asf_st->pkt.size)
- av_free_packet(&asf_st->pkt);
- asf_st->frag_offset = 0;
- if (asf->packet_frag_offset != 0) {
- url_fskip(pb, asf->packet_frag_size);
- printf("ff asf parser skiping %db\n", asf->packet_frag_size);
- asf->packet_size_left -= asf->packet_frag_size;
- continue;
- }
- }
- if (asf->packet_replic_size == 1) {
- // frag_offset is here used as the begining timestamp
- asf->packet_frag_timestamp = asf->packet_time_start;
- asf->packet_time_start += asf->packet_time_delta;
- asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
- asf->packet_size_left--;
- asf->packet_multi_size--;
- if (asf->packet_multi_size < asf->packet_obj_size)
- {
- asf->packet_time_start = 0;
- url_fskip(pb, asf->packet_multi_size);
- asf->packet_size_left -= asf->packet_multi_size;
- continue;
- }
- asf->packet_multi_size -= asf->packet_obj_size;
- //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size);
- }
- if (asf_st->frag_offset == 0) {
- /* new packet */
- av_new_packet(&asf_st->pkt, asf->packet_obj_size);
- asf_st->seq = asf->packet_seq;
- asf_st->pkt.pts = asf->packet_frag_timestamp - asf->hdr.preroll;
- asf_st->pkt.stream_index = asf->stream_index;
- if (asf->packet_key_frame)
- asf_st->pkt.flags |= PKT_FLAG_KEY;
- }
-
- /* read data */
- //printf("READ PACKET s:%d os:%d o:%d,%d l:%d DATA:%p\n",
- // asf->packet_size, asf_st->pkt.size, asf->packet_frag_offset,
- // asf_st->frag_offset, asf->packet_frag_size, asf_st->pkt.data);
- asf->packet_size_left -= asf->packet_frag_size;
- if (asf->packet_size_left < 0)
- continue;
- get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
- asf->packet_frag_size);
- asf_st->frag_offset += asf->packet_frag_size;
- /* test if whole packet is read */
- if (asf_st->frag_offset == asf_st->pkt.size) {
- /* return packet */
- if (asf_st->ds_span > 1) {
- /* packet descrambling */
- char* newdata = av_malloc(asf_st->pkt.size);
- if (newdata) {
- int offset = 0;
- while (offset < asf_st->pkt.size) {
- int off = offset / asf_st->ds_chunk_size;
- int row = off / asf_st->ds_span;
- int col = off % asf_st->ds_span;
- int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
- //printf("off:%d row:%d col:%d idx:%d\n", off, row, col, idx);
- memcpy(newdata + offset,
- asf_st->pkt.data + idx * asf_st->ds_chunk_size,
- asf_st->ds_chunk_size);
- offset += asf_st->ds_chunk_size;
- }
- av_free(asf_st->pkt.data);
- asf_st->pkt.data = newdata;
- }
- }
- asf_st->frag_offset = 0;
- memcpy(pkt, &asf_st->pkt, sizeof(AVPacket));
- //printf("packet %d %d\n", asf_st->pkt.size, asf->packet_frag_size);
- asf_st->pkt.size = 0;
- asf_st->pkt.data = 0;
- break; // packet completed
- }
- }
- return 0;
-}
-
-static int asf_read_close(AVFormatContext *s)
-{
- int i;
-
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = s->streams[i];
- av_free(st->priv_data);
- av_free(st->codec.extradata);
- }
- return 0;
-}
-
-static int asf_read_seek(AVFormatContext *s, int64_t pts)
-{
- printf("SEEK TO %lld", pts);
- return -1;
-}
-
-static AVInputFormat asf_iformat = {
- "asf",
- "asf format",
- sizeof(ASFContext),
- asf_probe,
- asf_read_header,
- asf_read_packet,
- asf_read_close,
- asf_read_seek,
-};
-
-static AVOutputFormat asf_oformat = {
- "asf",
- "asf format",
- "video/x-ms-asf",
- "asf,wmv",
- sizeof(ASFContext),
-#ifdef CONFIG_MP3LAME
- CODEC_ID_MP3,
-#else
- CODEC_ID_MP2,
-#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_header,
- asf_write_packet,
- asf_write_trailer,
-};
-
-static AVOutputFormat asf_stream_oformat = {
- "asf_stream",
- "asf format",
- "video/x-ms-asf",
- "asf,wmv",
- sizeof(ASFContext),
-#ifdef CONFIG_MP3LAME
- CODEC_ID_MP3,
-#else
- CODEC_ID_MP2,
-#endif
- CODEC_ID_MSMPEG4V3,
- asf_write_stream_header,
- asf_write_packet,
- asf_write_trailer,
-};
-
-int asf_init(void)
-{
- av_register_input_format(&asf_iformat);
- av_register_output_format(&asf_oformat);
- av_register_output_format(&asf_stream_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * AU encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Reference documents:
- * http://www.opengroup.org/public/pubs/external/auformat.html
- * http://www.goice.co.jp/member/mo/formats/au.html
- */
-
-#include "avformat.h"
-#include "avi.h"
-
-/* if we don't know the size in advance */
-#define AU_UNKOWN_SIZE ((uint32_t)(~0))
-
-/* The ffmpeg codecs we support, and the IDs they have in the file */
-static const CodecTag codec_au_tags[] = {
- { CODEC_ID_PCM_MULAW, 1 },
- { CODEC_ID_PCM_S16BE, 3 },
- { CODEC_ID_PCM_ALAW, 27 },
- { 0, 0 },
-};
-
-/* AUDIO_FILE header */
-static int put_au_header(ByteIOContext *pb, AVCodecContext *enc)
-{
- if(!enc->codec_tag)
- enc->codec_tag = codec_get_tag(codec_au_tags, enc->codec_id);
- if(!enc->codec_tag)
- return -1;
- put_tag(pb, ".snd"); /* magic number */
- put_be32(pb, 24); /* header size */
- put_be32(pb, AU_UNKOWN_SIZE); /* data size */
- put_be32(pb, (uint32_t)enc->codec_tag); /* codec ID */
- put_be32(pb, enc->sample_rate);
- put_be32(pb, (uint32_t)enc->channels);
- return 0;
-}
-
-static int au_write_header(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- s->priv_data = NULL;
-
- /* format header */
- if (put_au_header(pb, &s->streams[0]->codec) < 0) {
- return -1;
- }
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int au_write_packet(AVFormatContext *s, int stream_index_ptr,
- const uint8_t *buf, int size, int64_t pts)
-{
- ByteIOContext *pb = &s->pb;
- put_buffer(pb, buf, size);
- return 0;
-}
-
-static int au_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- offset_t file_size;
-
- if (!url_is_streamed(&s->pb)) {
-
- /* update file size */
- file_size = url_ftell(pb);
- url_fseek(pb, 8, SEEK_SET);
- put_be32(pb, (uint32_t)(file_size - 24));
- url_fseek(pb, file_size, SEEK_SET);
-
- put_flush_packet(pb);
- }
-
- return 0;
-}
-
-static int au_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size <= 24)
- return 0;
- if (p->buf[0] == '.' && p->buf[1] == 's' &&
- p->buf[2] == 'n' && p->buf[3] == 'd')
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-/* au input */
-static int au_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- int size;
- unsigned int tag;
- ByteIOContext *pb = &s->pb;
- unsigned int id, codec, channels, rate;
- AVStream *st;
-
- /* check ".snd" header */
- tag = get_le32(pb);
- if (tag != MKTAG('.', 's', 'n', 'd'))
- return -1;
- size = get_be32(pb); /* header size */
- get_be32(pb); /* data size */
-
- id = get_be32(pb);
- rate = get_be32(pb);
- channels = get_be32(pb);
-
- codec = codec_get_id(codec_au_tags, id);
-
- if (size >= 24) {
- /* skip unused data */
- url_fseek(pb, size - 24, SEEK_CUR);
- }
-
- /* now we are ready: build format streams */
- st = av_new_stream(s, 0);
- if (!st)
- return -1;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = id;
- st->codec.codec_id = codec;
- st->codec.channels = channels;
- st->codec.sample_rate = rate;
- return 0;
-}
-
-#define MAX_SIZE 4096
-
-static int au_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- int ret;
-
- if (url_feof(&s->pb))
- return -EIO;
- if (av_new_packet(pkt, MAX_SIZE))
- return -EIO;
- pkt->stream_index = 0;
-
- ret = get_buffer(&s->pb, pkt->data, pkt->size);
- if (ret < 0)
- av_free_packet(pkt);
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- return 0;
-}
-
-static int au_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVInputFormat au_iformat = {
- "au",
- "SUN AU Format",
- 0,
- au_probe,
- au_read_header,
- au_read_packet,
- au_read_close,
-};
-
-static AVOutputFormat au_oformat = {
- "au",
- "SUN AU Format",
- "audio/basic",
- "au",
- 0,
- CODEC_ID_PCM_S16BE,
- CODEC_ID_NONE,
- au_write_header,
- au_write_packet,
- au_write_trailer,
-};
-
-int au_init(void)
-{
- av_register_input_format(&au_iformat);
- av_register_output_format(&au_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Linux audio play and grab interface
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/soundcard.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-
-#define AUDIO_BLOCK_SIZE 4096
-
-typedef struct {
- int fd;
- int sample_rate;
- int channels;
- int frame_size; /* in bytes ! */
- int codec_id;
- int flip_left : 1;
- uint8_t buffer[AUDIO_BLOCK_SIZE];
- int buffer_ptr;
-} AudioData;
-
-static int audio_open(AudioData *s, int is_output, const char *audio_device)
-{
- int audio_fd;
- int tmp, err;
- char *flip = getenv("AUDIO_FLIP_LEFT");
-
- /* open linux audio device */
- if (!audio_device)
- audio_device = "/dev/dsp";
-
- if (is_output)
- audio_fd = open(audio_device, O_WRONLY);
- else
- audio_fd = open(audio_device, O_RDONLY);
- if (audio_fd < 0) {
- perror(audio_device);
- return -EIO;
- }
-
- if (flip && *flip == '1') {
- s->flip_left = 1;
- }
-
- /* non blocking mode */
- if (!is_output)
- fcntl(audio_fd, F_SETFL, O_NONBLOCK);
-
- s->frame_size = AUDIO_BLOCK_SIZE;
-#if 0
- tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS;
- err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SETFRAGMENT");
- }
-#endif
-
- /* select format : favour native format */
- err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
-
-#ifdef WORDS_BIGENDIAN
- if (tmp & AFMT_S16_BE) {
- tmp = AFMT_S16_BE;
- } else if (tmp & AFMT_S16_LE) {
- tmp = AFMT_S16_LE;
- } else {
- tmp = 0;
- }
-#else
- if (tmp & AFMT_S16_LE) {
- tmp = AFMT_S16_LE;
- } else if (tmp & AFMT_S16_BE) {
- tmp = AFMT_S16_BE;
- } else {
- tmp = 0;
- }
-#endif
-
- switch(tmp) {
- case AFMT_S16_LE:
- s->codec_id = CODEC_ID_PCM_S16LE;
- break;
- case AFMT_S16_BE:
- s->codec_id = CODEC_ID_PCM_S16BE;
- break;
- default:
- fprintf(stderr, "Soundcard does not support 16 bit sample format\n");
- close(audio_fd);
- return -EIO;
- }
- err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SETFMT");
- goto fail;
- }
-
- tmp = (s->channels == 2);
- err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_STEREO");
- goto fail;
- }
- if (tmp)
- s->channels = 2;
-
- tmp = s->sample_rate;
- err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
- if (err < 0) {
- perror("SNDCTL_DSP_SPEED");
- goto fail;
- }
- s->sample_rate = tmp; /* store real sample rate */
- s->fd = audio_fd;
-
- return 0;
- fail:
- close(audio_fd);
- return -EIO;
-}
-
-static int audio_close(AudioData *s)
-{
- close(s->fd);
- return 0;
-}
-
-/* sound output support */
-static int audio_write_header(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
- AVStream *st;
- int ret;
-
- st = s1->streams[0];
- s->sample_rate = st->codec.sample_rate;
- s->channels = st->codec.channels;
- ret = audio_open(s, 1, NULL);
- if (ret < 0) {
- return -EIO;
- } else {
- return 0;
- }
-}
-
-static int audio_write_packet(AVFormatContext *s1, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- AudioData *s = s1->priv_data;
- int len, ret;
-
- while (size > 0) {
- len = AUDIO_BLOCK_SIZE - s->buffer_ptr;
- if (len > size)
- len = size;
- memcpy(s->buffer + s->buffer_ptr, buf, len);
- s->buffer_ptr += len;
- if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) {
- for(;;) {
- ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE);
- if (ret > 0)
- break;
- if (ret < 0 && (errno != EAGAIN && errno != EINTR))
- return -EIO;
- }
- s->buffer_ptr = 0;
- }
- buf += len;
- size -= len;
- }
- return 0;
-}
-
-static int audio_write_trailer(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-/* grab support */
-
-static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- AudioData *s = s1->priv_data;
- AVStream *st;
- int ret;
-
- if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
- return -1;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- return -ENOMEM;
- }
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
-
- ret = audio_open(s, 0, ap->device);
- if (ret < 0) {
- av_free(st);
- return -EIO;
- }
-
- /* take real parameters */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = s->codec_id;
- st->codec.sample_rate = s->sample_rate;
- st->codec.channels = s->channels;
-
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
- return 0;
-}
-
-static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- AudioData *s = s1->priv_data;
- int ret, bdelay;
- int64_t cur_time;
- struct audio_buf_info abufi;
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
- for(;;) {
- struct timeval tv;
- fd_set fds;
-
- tv.tv_sec = 0;
- tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */
-
- FD_ZERO(&fds);
- FD_SET(s->fd, &fds);
-
- /* This will block until data is available or we get a timeout */
- (void) select(s->fd + 1, &fds, 0, 0, &tv);
-
- ret = read(s->fd, pkt->data, pkt->size);
- if (ret > 0)
- break;
- if (ret == -1 && (errno == EAGAIN || errno == EINTR)) {
- av_free_packet(pkt);
- pkt->size = 0;
- return 0;
- }
- if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) {
- av_free_packet(pkt);
- return -EIO;
- }
- }
- pkt->size = ret;
-
- /* compute pts of the start of the packet */
- cur_time = av_gettime();
- bdelay = ret;
- if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
- bdelay += abufi.bytes;
- }
- /* substract time represented by the number of bytes in the audio fifo */
- cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels);
-
- /* convert to wanted units */
- pkt->pts = cur_time & ((1LL << 48) - 1);
-
- if (s->flip_left && s->channels == 2) {
- int i;
- short *p = (short *) pkt->data;
-
- for (i = 0; i < ret; i += 4) {
- *p = ~*p;
- p += 2;
- }
- }
- return 0;
-}
-
-static int audio_read_close(AVFormatContext *s1)
-{
- AudioData *s = s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-static AVInputFormat audio_in_format = {
- "audio_device",
- "audio grab and output",
- sizeof(AudioData),
- NULL,
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- .flags = AVFMT_NOFILE,
-};
-
-static AVOutputFormat audio_out_format = {
- "audio_device",
- "audio grab and output",
- "",
- "",
- sizeof(AudioData),
- /* XXX: we make the assumption that the soundcard accepts this format */
- /* XXX: find better solution with "preinit" method, needed also in
- other formats */
-#ifdef WORDS_BIGENDIAN
- CODEC_ID_PCM_S16BE,
-#else
- CODEC_ID_PCM_S16LE,
-#endif
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- audio_write_trailer,
- .flags = AVFMT_NOFILE,
-};
-
-int audio_init(void)
-{
- av_register_input_format(&audio_in_format);
- av_register_output_format(&audio_out_format);
- return 0;
-}
+++ /dev/null
-#ifndef AVFORMAT_H
-#define AVFORMAT_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define LIBAVFORMAT_BUILD 4608
-
-#define LIBAVFORMAT_VERSION_INT FFMPEG_VERSION_INT
-#define LIBAVFORMAT_VERSION FFMPEG_VERSION
-#define LIBAVFORMAT_IDENT "FFmpeg" FFMPEG_VERSION "b" AV_STRINGIFY(LIBAVFORMAT_BUILD)
-
-#include <time.h>
-
-#include "avcodec.h"
-
-#include "avio.h"
-
-/* packet functions */
-
-#ifndef MAXINT64
-#define MAXINT64 int64_t_C(0x7fffffffffffffff)
-#endif
-
-#ifndef MININT64
-#define MININT64 int64_t_C(0x8000000000000000)
-#endif
-
-#define AV_NOPTS_VALUE MININT64
-#define AV_TIME_BASE 1000000
-
-typedef struct AVPacket {
- int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
- uint8_t *data;
- int size;
- int stream_index;
- int flags;
- int duration;
- void (*destruct)(struct AVPacket *);
- void *priv;
-} AVPacket;
-#define PKT_FLAG_KEY 0x0001
-
-static inline void av_init_packet(AVPacket *pkt)
-{
- pkt->pts = AV_NOPTS_VALUE;
- pkt->flags = 0;
- pkt->stream_index = 0;
-}
-
-int av_new_packet(AVPacket *pkt, int size);
-
-/**
- * Free a packet
- *
- * @param pkt packet to free
- */
-static inline void av_free_packet(AVPacket *pkt)
-{
- if (pkt && pkt->destruct) {
- pkt->destruct(pkt);
- }
-}
-
-/*************************************************/
-/* fractional numbers for exact pts handling */
-
-/* the exact value of the fractional number is: 'val + num / den'. num
- is assumed to be such as 0 <= num < den */
-typedef struct AVFrac {
- int64_t val, num, den;
-} AVFrac;
-
-void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
-void av_frac_add(AVFrac *f, int64_t incr);
-void av_frac_set(AVFrac *f, int64_t val);
-
-/*************************************************/
-/* input/output formats */
-
-struct AVFormatContext;
-
-/* this structure contains the data a format has to probe a file */
-typedef struct AVProbeData {
- const char *filename;
- unsigned char *buf;
- int buf_size;
-} AVProbeData;
-
-#define AVPROBE_SCORE_MAX 100
-
-typedef struct AVFormatParameters {
- int frame_rate;
- int frame_rate_base;
- int sample_rate;
- int channels;
- int width;
- int height;
- enum PixelFormat pix_fmt;
- struct AVImageFormat *image_format;
- int channel; /* used to select dv channel */
- const char *device; /* video4linux, audio or DV device */
- const char *standard; /* tv standard, NTSC, PAL, SECAM */
-} AVFormatParameters;
-
-#define AVFMT_NOFILE 0x0001 /* no file should be opened */
-#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
-#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
- (streams are added dynamically) */
-#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
-#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
- raw picture data */
-
-typedef struct AVOutputFormat {
- const char *name;
- const char *long_name;
- const char *mime_type;
- const char *extensions; /* comma separated extensions */
- /* size of private data so that it can be allocated in the wrapper */
- int priv_data_size;
- /* output support */
- enum CodecID audio_codec; /* default audio codec */
- enum CodecID video_codec; /* default video codec */
- int (*write_header)(struct AVFormatContext *);
- int (*write_packet)(struct AVFormatContext *,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts);
- int (*write_trailer)(struct AVFormatContext *);
- /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
- int flags;
- /* currently only used to set pixel format if not YUV420P */
- int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
- /* private fields */
- struct AVOutputFormat *next;
-} AVOutputFormat;
-
-typedef struct AVInputFormat {
- const char *name;
- const char *long_name;
- /* size of private data so that it can be allocated in the wrapper */
- int priv_data_size;
- /* tell if a given file has a chance of being parsing by this format */
- int (*read_probe)(AVProbeData *);
- /* read the format header and initialize the AVFormatContext
- structure. Return 0 if OK. 'ap' if non NULL contains
- additionnal paramters. Only used in raw format right
- now. 'av_new_stream' should be called to create new streams. */
- int (*read_header)(struct AVFormatContext *,
- AVFormatParameters *ap);
- /* read one packet and put it in 'pkt'. pts and flags are also
- set. 'av_new_stream' can be called only if the flag
- AVFMT_NOHEADER is used. */
- int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
- /* close the stream. The AVFormatContext and AVStreams are not
- freed by this function */
- int (*read_close)(struct AVFormatContext *);
- /* seek at or before a given pts (given in microsecond). The pts
- origin is defined by the stream */
- int (*read_seek)(struct AVFormatContext *, int64_t pts);
- /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
- int flags;
- /* if extensions are defined, then no probe is done. You should
- usually not use extension format guessing because it is not
- reliable enough */
- const char *extensions;
- /* general purpose read only value that the format can use */
- int value;
- /* private fields */
- struct AVInputFormat *next;
-} AVInputFormat;
-
-typedef struct AVStream {
- int index; /* stream index in AVFormatContext */
- int id; /* format specific stream id */
- AVCodecContext codec; /* codec context */
- int r_frame_rate; /* real frame rate of the stream */
- int r_frame_rate_base;/* real frame rate base of the stream */
- void *priv_data;
- /* internal data used in av_find_stream_info() */
- int codec_info_state;
- int codec_info_nb_repeat_frames;
- int codec_info_nb_real_frames;
- /* PTS generation when outputing stream */
- AVFrac pts;
- /* ffmpeg.c private use */
- int stream_copy; /* if TRUE, just copy stream */
- /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
- * MN:dunno if thats the right place, for it */
- float quality;
- /* decoding: position of the first frame of the component, in
- AV_TIME_BASE fractional seconds. */
- int64_t start_time;
- /* decoding: duration of the stream, in AV_TIME_BASE fractional
- seconds. */
- int64_t duration;
-} AVStream;
-
-#define MAX_STREAMS 20
-
-/* format I/O context */
-typedef struct AVFormatContext {
- /* can only be iformat or oformat, not both at the same time */
- struct AVInputFormat *iformat;
- struct AVOutputFormat *oformat;
- void *priv_data;
- ByteIOContext pb;
- int nb_streams;
- AVStream *streams[MAX_STREAMS];
- char filename[1024]; /* input or output filename */
- /* stream info */
- char title[512];
- char author[512];
- char copyright[512];
- char comment[512];
- char album[512];
- int year; /* ID3 year, 0 if none */
- int track; /* track number, 0 if none */
- char genre[32]; /* ID3 genre */
-
- int flags; /* format specific flags */
- /* private data for pts handling (do not modify directly) */
- int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
- int pts_num, pts_den; /* value to convert to seconds */
- /* This buffer is only needed when packets were already buffered but
- not decoded, for example to get the codec parameters in mpeg
- streams */
- struct AVPacketList *packet_buffer;
-
- /* decoding: position of the first frame of the component, in
- AV_TIME_BASE fractional seconds. NEVER set this value directly:
- it is deduced from the AVStream values. */
- int64_t start_time;
- /* decoding: duration of the stream, in AV_TIME_BASE fractional
- seconds. NEVER set this value directly: it is deduced from the
- AVStream values. */
- int64_t duration;
- /* decoding: total file size. 0 if unknown */
- int64_t file_size;
- /* decoding: total stream bitrate in bit/s, 0 if not
- available. Never set it directly if the file_size and the
- duration are known as ffmpeg can compute it automatically. */
- int bit_rate;
-} AVFormatContext;
-
-typedef struct AVPacketList {
- AVPacket pkt;
- struct AVPacketList *next;
-} AVPacketList;
-
-extern AVInputFormat *first_iformat;
-extern AVOutputFormat *first_oformat;
-
-/* still image support */
-struct AVInputImageContext;
-typedef struct AVInputImageContext AVInputImageContext;
-
-typedef struct AVImageInfo {
- enum PixelFormat pix_fmt; /* requested pixel format */
- int width; /* requested width */
- int height; /* requested height */
- int interleaved; /* image is interleaved (e.g. interleaved GIF) */
- AVPicture pict; /* returned allocated image */
-} AVImageInfo;
-
-/* AVImageFormat.flags field constants */
-#define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
-
-typedef struct AVImageFormat {
- const char *name;
- const char *extensions;
- /* tell if a given file has a chance of being parsing by this format */
- int (*img_probe)(AVProbeData *);
- /* read a whole image. 'alloc_cb' is called when the image size is
- known so that the caller can allocate the image. If 'allo_cb'
- returns non zero, then the parsing is aborted. Return '0' if
- OK. */
- int (*img_read)(ByteIOContext *,
- int (*alloc_cb)(void *, AVImageInfo *info), void *);
- /* write the image */
- int supported_pixel_formats; /* mask of supported formats for output */
- int (*img_write)(ByteIOContext *, AVImageInfo *);
- int flags;
- struct AVImageFormat *next;
-} AVImageFormat;
-
-void av_register_image_format(AVImageFormat *img_fmt);
-AVImageFormat *av_probe_image_format(AVProbeData *pd);
-AVImageFormat *guess_image_format(const char *filename);
-int av_read_image(ByteIOContext *pb, const char *filename,
- AVImageFormat *fmt,
- int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
-int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
-
-extern AVImageFormat *first_image_format;
-
-extern AVImageFormat pnm_image_format;
-extern AVImageFormat pbm_image_format;
-extern AVImageFormat pgm_image_format;
-extern AVImageFormat ppm_image_format;
-extern AVImageFormat pam_image_format;
-extern AVImageFormat pgmyuv_image_format;
-extern AVImageFormat yuv_image_format;
-#ifdef CONFIG_ZLIB
-extern AVImageFormat png_image_format;
-#endif
-extern AVImageFormat jpeg_image_format;
-extern AVImageFormat gif_image_format;
-
-/* XXX: use automatic init with either ELF sections or C file parser */
-/* modules */
-
-/* mpeg.c */
-extern AVInputFormat mpegps_demux;
-int mpegps_init(void);
-
-/* mpegts.c */
-extern AVInputFormat mpegts_demux;
-int mpegts_init(void);
-
-/* rm.c */
-int rm_init(void);
-
-/* crc.c */
-int crc_init(void);
-
-/* img.c */
-int img_init(void);
-
-/* asf.c */
-int asf_init(void);
-
-/* avienc.c */
-int avienc_init(void);
-
-/* avidec.c */
-int avidec_init(void);
-
-/* swf.c */
-int swf_init(void);
-
-/* mov.c */
-int mov_init(void);
-
-/* movenc.c */
-int movenc_init(void);
-
-/* flvenc.c */
-int flvenc_init(void);
-
-/* flvdec.c */
-int flvdec_init(void);
-
-/* jpeg.c */
-int jpeg_init(void);
-
-/* gif.c */
-int gif_init(void);
-
-/* au.c */
-int au_init(void);
-
-/* amr.c */
-int amr_init(void);
-
-/* wav.c */
-int wav_init(void);
-
-/* raw.c */
-int raw_init(void);
-
-/* mp3.c */
-int mp3_init(void);
-
-/* yuv4mpeg.c */
-int yuv4mpeg_init(void);
-
-/* ogg.c */
-int ogg_init(void);
-
-/* dv.c */
-int dv_init(void);
-
-/* ffm.c */
-int ffm_init(void);
-
-/* rtsp.c */
-extern AVInputFormat redir_demux;
-int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
-
-/* 4xm.c */
-int fourxm_init(void);
-
-/* psxstr.c */
-int str_init(void);
-
-/* idroq.c */
-int roq_init(void);
-
-/* ipmovie.c */
-int ipmovie_init(void);
-
-/* nut.c */
-int nut_init(void);
-
-/* wc3movie.c */
-int wc3_init(void);
-
-#include "rtp.h"
-
-#include "rtsp.h"
-
-/* yuv4mpeg.c */
-extern AVOutputFormat yuv4mpegpipe_oformat;
-
-/* utils.c */
-void av_register_input_format(AVInputFormat *format);
-void av_register_output_format(AVOutputFormat *format);
-AVOutputFormat *guess_stream_format(const char *short_name,
- const char *filename, const char *mime_type);
-AVOutputFormat *guess_format(const char *short_name,
- const char *filename, const char *mime_type);
-
-void av_hex_dump(uint8_t *buf, int size);
-
-void av_register_all(void);
-
-typedef struct FifoBuffer {
- uint8_t *buffer;
- uint8_t *rptr, *wptr, *end;
-} FifoBuffer;
-
-int fifo_init(FifoBuffer *f, int size);
-void fifo_free(FifoBuffer *f);
-int fifo_size(FifoBuffer *f, uint8_t *rptr);
-int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
-void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
-
-/* media file input */
-AVInputFormat *av_find_input_format(const char *short_name);
-AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
-int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
- AVInputFormat *fmt,
- int buf_size,
- AVFormatParameters *ap);
-
-#define AVERROR_UNKNOWN (-1) /* unknown error */
-#define AVERROR_IO (-2) /* i/o error */
-#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
-#define AVERROR_INVALIDDATA (-4) /* invalid data found */
-#define AVERROR_NOMEM (-5) /* not enough memory */
-#define AVERROR_NOFMT (-6) /* unknown format */
-
-int av_find_stream_info(AVFormatContext *ic);
-int av_read_packet(AVFormatContext *s, AVPacket *pkt);
-void av_close_input_file(AVFormatContext *s);
-AVStream *av_new_stream(AVFormatContext *s, int id);
-void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
- int pts_num, int pts_den);
-
-/* media file output */
-int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
-int av_write_header(AVFormatContext *s);
-int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
- int size);
-int av_write_trailer(AVFormatContext *s);
-
-void dump_format(AVFormatContext *ic,
- int index,
- const char *url,
- int is_output);
-int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
-int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
-int64_t parse_date(const char *datestr, int duration);
-
-int64_t av_gettime(void);
-
-/* ffm specific for ffserver */
-#define FFM_PACKET_SIZE 4096
-offset_t ffm_read_write_index(int fd);
-void ffm_write_write_index(int fd, offset_t pos);
-void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
-
-int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
-
-int get_frame_filename(char *buf, int buf_size,
- const char *path, int number);
-int filename_number_test(const char *filename);
-
-/* grab specific */
-int video_grab_init(void);
-int audio_init(void);
-
-/* DV1394 */
-int dv1394_init(void);
-
-#ifdef HAVE_AV_CONFIG_H
-
-#include "os_support.h"
-
-int strstart(const char *str, const char *val, const char **ptr);
-int stristart(const char *str, const char *val, const char **ptr);
-void pstrcpy(char *buf, int buf_size, const char *str);
-char *pstrcat(char *buf, int buf_size, const char *s);
-
-void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
-
-#ifdef __GNUC__
-#define dynarray_add(tab, nb_ptr, elem)\
-do {\
- typeof(tab) _tab = (tab);\
- typeof(elem) _elem = (elem);\
- (void)sizeof(**_tab == _elem); /* check that types are compatible */\
- __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
-} while(0)
-#else
-#define dynarray_add(tab, nb_ptr, elem)\
-do {\
- __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
-} while(0)
-#endif
-
-time_t mktimegm(struct tm *tm);
-const char *small_strptime(const char *p, const char *fmt,
- struct tm *dt);
-
-struct in_addr;
-int resolve_host(struct in_addr *sin_addr, const char *hostname);
-
-void url_split(char *proto, int proto_size,
- char *hostname, int hostname_size,
- int *port_ptr,
- char *path, int path_size,
- const char *url);
-
-int match_ext(const char *filename, const char *extensions);
-
-#endif /* HAVE_AV_CONFIG_H */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* AVFORMAT_H */
+++ /dev/null
-#ifndef FFMPEG_AVI_H
-#define FFMPEG_AVI_H
-
-#include "avcodec.h"
-
-#define AVIF_HASINDEX 0x00000010 // Index at end of file?
-#define AVIF_MUSTUSEINDEX 0x00000020
-#define AVIF_ISINTERLEAVED 0x00000100
-#define AVIF_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
-#define AVIF_WASCAPTUREFILE 0x00010000
-#define AVIF_COPYRIGHTED 0x00020000
-
-#define AVI_MAX_RIFF_SIZE 0x40000000LL
-#define AVI_MASTER_INDEX_SIZE 256
-
-offset_t start_tag(ByteIOContext *pb, const char *tag);
-void end_tag(ByteIOContext *pb, offset_t start);
-
-typedef struct CodecTag {
- int id;
- unsigned int tag;
- unsigned int invalid_asf : 1;
-} CodecTag;
-
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf);
-int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
-int wav_codec_get_id(unsigned int tag, int bps);
-void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size);
-
-extern const CodecTag codec_bmp_tags[];
-extern const CodecTag codec_wav_tags[];
-
-unsigned int codec_get_tag(const CodecTag *tags, int id);
-enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag);
-unsigned int codec_get_bmp_tag(int id);
-unsigned int codec_get_wav_tag(int id);
-enum CodecID codec_get_bmp_id(unsigned int tag);
-enum CodecID codec_get_wav_id(unsigned int tag);
-
-#endif /* FFMPEG_AVI_H */
+++ /dev/null
-/*
- * AVI decoder.
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-//#define DEBUG
-
-static const struct AVI1Handler {
- enum CodecID vcid;
- enum CodecID acid;
- uint32_t tag;
-} AVI1Handlers[] = {
- { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'd') },
- { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'h', 'd') },
- { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'l') },
- /* This is supposed to be the last one */
- { CODEC_ID_NONE, CODEC_ID_NONE, 0 },
-};
-
-typedef struct AVIIndex {
- unsigned char tag[4];
- unsigned int flags, pos, len;
- struct AVIIndex *next;
-} AVIIndex;
-
-typedef struct {
- int64_t riff_end;
- int64_t movi_end;
- int type;
- uint8_t *buf;
- int buf_size;
- int stream_index;
- offset_t movi_list;
- AVIIndex *first, *last;
-} AVIContext;
-
-#ifdef DEBUG
-static void print_tag(const char *str, unsigned int tag, int size)
-{
- printf("%s: tag=%c%c%c%c size=0x%x\n",
- str, tag & 0xff,
- (tag >> 8) & 0xff,
- (tag >> 16) & 0xff,
- (tag >> 24) & 0xff,
- size);
-}
-#endif
-
-static int get_riff(AVIContext *avi, ByteIOContext *pb)
-{
- uint32_t tag;
- /* check RIFF header */
- tag = get_le32(pb);
-
- if (tag != MKTAG('R', 'I', 'F', 'F'))
- return -1;
- avi->riff_end = get_le32(pb); /* RIFF chunk size */
- avi->riff_end += url_ftell(pb); /* RIFF chunk end */
- tag = get_le32(pb);
- if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X'))
- return -1;
-
- return 0;
-}
-
-static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- uint32_t tag, tag1, handler;
- int codec_type, stream_index, frame_period, bit_rate, scale, rate;
- unsigned int size, nb_frames;
- int i, n;
- AVStream *st;
- int xan_video = 0; /* hack to support Xan A/V */
-
- if (get_riff(avi, pb) < 0)
- return -1;
-
- /* first list tag */
- stream_index = -1;
- codec_type = -1;
- frame_period = 0;
- avi->type = 2;
- avi->buf = av_malloc(1);
- if (!avi->buf)
- return -1;
- avi->buf_size = 1;
- for(;;) {
- if (url_feof(pb))
- goto fail;
- tag = get_le32(pb);
- size = get_le32(pb);
-#ifdef DEBUG
- print_tag("tag", tag, size);
-#endif
-
- switch(tag) {
- case MKTAG('L', 'I', 'S', 'T'):
- /* ignored, except when start of video packets */
- tag1 = get_le32(pb);
-#ifdef DEBUG
- print_tag("list", tag1, 0);
-#endif
- if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
- avi->movi_end = url_ftell(pb) + size - 4;
-#ifdef DEBUG
- printf("movi end=%Lx\n", avi->movi_end);
-#endif
- goto end_of_header;
- }
- break;
- case MKTAG('a', 'v', 'i', 'h'):
- /* avi header */
- /* using frame_period is bad idea */
- frame_period = get_le32(pb);
- bit_rate = get_le32(pb) * 8;
- url_fskip(pb, 4 * 4);
- n = get_le32(pb);
- for(i=0;i<n;i++) {
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
- }
- url_fskip(pb, size - 7 * 4);
- break;
- case MKTAG('s', 't', 'r', 'h'):
- /* stream header */
- stream_index++;
- tag1 = get_le32(pb);
- switch(tag1) {
- case MKTAG('i', 'a', 'v', 's'):
- case MKTAG('i', 'v', 'a', 's'):
- if (s->nb_streams != 1)
- goto fail;
- avi->type = 1;
- avi->stream_index = 0;
- case MKTAG('v', 'i', 'd', 's'):
- codec_type = CODEC_TYPE_VIDEO;
-
- if (stream_index >= s->nb_streams) {
- url_fskip(pb, size - 4);
- break;
- }
-
- st = s->streams[stream_index];
-
- handler = get_le32(pb); /* codec tag */
- get_le32(pb); /* flags */
- get_le16(pb); /* priority */
- get_le16(pb); /* language */
- get_le32(pb); /* XXX: initial frame ? */
- scale = get_le32(pb); /* scale */
- rate = get_le32(pb); /* rate */
-
- if(scale && rate){
- st->codec.frame_rate = rate;
- st->codec.frame_rate_base = scale;
- }else if(frame_period){
- st->codec.frame_rate = 1000000;
- st->codec.frame_rate_base = frame_period;
- }else{
- st->codec.frame_rate = 25;
- st->codec.frame_rate_base = 1;
- }
- get_le32(pb); /* start */
- nb_frames = get_le32(pb);
- st->start_time = 0;
- st->duration = (double)nb_frames *
- st->codec.frame_rate_base * AV_TIME_BASE /
- st->codec.frame_rate;
-
- if (avi->type == 1) {
- AVStream *st;
-
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
-
- stream_index++;
-
- for (i=0; AVI1Handlers[i].tag != 0; ++i)
- if (AVI1Handlers[i].tag == handler)
- break;
-
- if (AVI1Handlers[i].tag != 0) {
- s->streams[0]->codec.codec_type = CODEC_TYPE_VIDEO;
- s->streams[0]->codec.codec_id = AVI1Handlers[i].vcid;
- s->streams[1]->codec.codec_type = CODEC_TYPE_AUDIO;
- s->streams[1]->codec.codec_id = AVI1Handlers[i].acid;
- } else {
- goto fail;
- }
- }
-
- url_fskip(pb, size - 9 * 4);
- break;
- case MKTAG('a', 'u', 'd', 's'):
- {
- unsigned int length, rate;
-
- codec_type = CODEC_TYPE_AUDIO;
-
- if (stream_index >= s->nb_streams) {
- url_fskip(pb, size - 4);
- break;
- }
- st = s->streams[stream_index];
-
- get_le32(pb); /* tag */
- get_le32(pb); /* flags */
- get_le16(pb); /* priority */
- get_le16(pb); /* language */
- get_le32(pb); /* initial frame */
- get_le32(pb); /* scale */
- rate = get_le32(pb);
- get_le32(pb); /* start */
- length = get_le32(pb); /* length, in samples or bytes */
- st->start_time = 0;
- if (rate != 0)
- st->duration = (int64_t)length * AV_TIME_BASE / rate;
- url_fskip(pb, size - 9 * 4);
- }
- break;
- default:
- goto fail;
- }
- break;
- case MKTAG('s', 't', 'r', 'f'):
- /* stream header */
- if (stream_index >= s->nb_streams || avi->type == 1) {
- url_fskip(pb, size);
- } else {
- st = s->streams[stream_index];
- switch(codec_type) {
- case CODEC_TYPE_VIDEO:
- get_le32(pb); /* size */
- st->codec.width = get_le32(pb);
- st->codec.height = get_le32(pb);
- get_le16(pb); /* panes */
- st->codec.bits_per_sample= get_le16(pb); /* depth */
- tag1 = get_le32(pb);
- get_le32(pb); /* ImageSize */
- get_le32(pb); /* XPelsPerMeter */
- get_le32(pb); /* YPelsPerMeter */
- get_le32(pb); /* ClrUsed */
- get_le32(pb); /* ClrImportant */
-
- st->codec.extradata_size= size - 10*4;
- st->codec.extradata= av_malloc(st->codec.extradata_size);
- get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
-
- if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
- get_byte(pb);
-
-#ifdef DEBUG
- print_tag("video", tag1, 0);
-#endif
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_tag = tag1;
- st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1);
- if (st->codec.codec_id == CODEC_ID_XAN_WC4)
- xan_video = 1;
-// url_fskip(pb, size - 5 * 4);
- break;
- case CODEC_TYPE_AUDIO:
- get_wav_header(pb, &st->codec, size);
- if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
- url_fskip(pb, 1);
- /* special case time: To support Xan DPCM, hardcode
- * the format if Xxan is the video codec */
- if (xan_video)
- st->codec.codec_id = CODEC_ID_XAN_DPCM;
- break;
- default:
- url_fskip(pb, size);
- break;
- }
- }
- break;
- default:
- /* skip tag */
- size += (size & 1);
- url_fskip(pb, size);
- break;
- }
- }
- end_of_header:
- /* check stream number */
- if (stream_index != s->nb_streams - 1) {
- fail:
- av_free(avi->buf);
- for(i=0;i<s->nb_streams;i++) {
- av_freep(&s->streams[i]->codec.extradata);
- av_freep(&s->streams[i]);
- }
- return -1;
- }
-
- return 0;
-}
-
-static void __destruct_pkt(struct AVPacket *pkt)
-{
- pkt->data = NULL; pkt->size = 0;
- return;
-}
-
-static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int n, d[8], size, i;
-
- memset(d, -1, sizeof(int)*8);
-
- if (avi->type == 1 && avi->stream_index) {
- /* duplicate DV packet */
- av_init_packet(pkt);
- pkt->data = avi->buf;
- pkt->size = avi->buf_size;
- pkt->destruct = __destruct_pkt;
- pkt->stream_index = avi->stream_index;
- avi->stream_index = !avi->stream_index;
- return 0;
- }
-
- for(i=url_ftell(pb); !url_feof(pb); i++) {
- int j;
-
- if (i >= avi->movi_end) { /* Let's see if it's an OpenDML AVI */
- uint32_t tag, size, tag2;
- url_fskip(pb, avi->riff_end - url_ftell(pb));
- if (get_riff(avi, pb) < 0)
- return -1;
-
- tag = get_le32(pb);
- size = get_le32(pb);
- tag2 = get_le32(pb);
- if (tag == MKTAG('L','I','S','T') && tag2 == MKTAG('m','o','v','i'))
- avi->movi_end = url_ftell(pb) + size - 4;
- else
- return -1;
- }
-
- for(j=0; j<7; j++)
- d[j]= d[j+1];
- d[7]= get_byte(pb);
-
- size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
-
- //parse ix##
- n= (d[2] - '0') * 10 + (d[3] - '0');
- if( d[2] >= '0' && d[2] <= '9'
- && d[3] >= '0' && d[3] <= '9'
- && d[0] == 'i' && d[1] == 'x'
- && n < s->nb_streams
- && i + size <= avi->movi_end){
-
- url_fskip(pb, size);
- }
-
- //parse ##dc/##wb
- n= (d[0] - '0') * 10 + (d[1] - '0');
- if( d[0] >= '0' && d[0] <= '9'
- && d[1] >= '0' && d[1] <= '9'
- && ((d[2] == 'd' && d[3] == 'c') ||
- (d[2] == 'w' && d[3] == 'b') ||
- (d[2] == 'd' && d[3] == 'b') ||
- (d[2] == '_' && d[3] == '_'))
- && n < s->nb_streams
- && i + size <= avi->movi_end) {
-
- if (avi->type == 1) {
- uint8_t *tbuf = av_realloc(avi->buf, size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!tbuf)
- return -1;
- avi->buf = tbuf;
- avi->buf_size = size;
- av_init_packet(pkt);
- pkt->data = avi->buf;
- pkt->size = avi->buf_size;
- pkt->destruct = __destruct_pkt;
- avi->stream_index = n;
- } else {
- av_new_packet(pkt, size);
- }
- get_buffer(pb, pkt->data, size);
- if (size & 1)
- get_byte(pb);
- pkt->stream_index = n;
- pkt->flags |= PKT_FLAG_KEY; // FIXME: We really should read index for that
- return 0;
- }
- }
- return -1;
-}
-
-static int avi_read_close(AVFormatContext *s)
-{
- int i;
- AVIContext *avi = s->priv_data;
- av_free(avi->buf);
-
- for(i=0;i<s->nb_streams;i++) {
- AVStream *st = s->streams[i];
-// av_free(st->priv_data);
- av_free(st->codec.extradata);
- }
-
- return 0;
-}
-
-static int avi_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size <= 32)
- return 0;
- if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
- p->buf[2] == 'F' && p->buf[3] == 'F' &&
- p->buf[8] == 'A' && p->buf[9] == 'V' &&
- p->buf[10] == 'I' && p->buf[11] == ' ')
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static AVInputFormat avi_iformat = {
- "avi",
- "avi format",
- sizeof(AVIContext),
- avi_probe,
- avi_read_header,
- avi_read_packet,
- avi_read_close,
-};
-
-int avidec_init(void)
-{
- av_register_input_format(&avi_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * AVI encoder.
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-/*
- * TODO:
- * - fill all fields if non streamed (nb_frames for example)
- */
-
-typedef struct AVIIentry {
- unsigned int flags, pos, len;
-} AVIIentry;
-
-#define AVI_INDEX_CLUSTER_SIZE 16384
-
-typedef struct AVIIndex {
- offset_t indx_start;
- int entry;
- int ents_allocated;
- AVIIentry** cluster;
-} AVIIndex;
-
-typedef struct {
- offset_t riff_start, movi_list, odml_list;
- offset_t frames_hdr_all, frames_hdr_strm[MAX_STREAMS];
- int audio_strm_length[MAX_STREAMS];
- int riff_id;
-
- AVIIndex indexes[MAX_STREAMS];
-} AVIContext;
-
-static inline AVIIentry* avi_get_ientry(AVIIndex* idx, int ent_id)
-{
- int cl = ent_id / AVI_INDEX_CLUSTER_SIZE;
- int id = ent_id % AVI_INDEX_CLUSTER_SIZE;
- return &idx->cluster[cl][id];
-}
-
-offset_t start_tag(ByteIOContext *pb, const char *tag)
-{
- put_tag(pb, tag);
- put_le32(pb, 0);
- return url_ftell(pb);
-}
-
-void end_tag(ByteIOContext *pb, offset_t start)
-{
- offset_t pos;
-
- pos = url_ftell(pb);
- url_fseek(pb, start - 4, SEEK_SET);
- put_le32(pb, (uint32_t)(pos - start));
- url_fseek(pb, pos, SEEK_SET);
-}
-
-/* Note: when encoding, the first matching tag is used, so order is
- important if multiple tags possible for a given codec. */
-const CodecTag codec_bmp_tags[] = {
- { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
- { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
- { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */
-
- /* added based on MPlayer */
- { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
- { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
-
- { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 },
- { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
- { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
- { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
-
- /* added based on MPlayer */
- { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
- { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
- { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
- { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
-
- { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */
- { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
-
- /* added based on MPlayer */
- { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
- { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
- { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
- { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
- { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
- { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
- { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
-
- { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
-
- /* added based on MPlayer */
- { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
-
- { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
-
- /* added based on MPlayer */
- { CODEC_ID_MSMPEG4V1, MKTAG('D', 'I', 'V', '4') },
-
- { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
-
- /* added based on MPlayer */
- { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
- { CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
- { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
- { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
- { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
- { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
- { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
- { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
- { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') },
- { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') },
- { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
- { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
- { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
- { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
- { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
- { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
- { CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
- { CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
- { 0, 0 },
-};
-
-unsigned int codec_get_tag(const CodecTag *tags, int id)
-{
- while (tags->id != 0) {
- if (tags->id == id)
- return tags->tag;
- tags++;
- }
- return 0;
-}
-
-static unsigned int codec_get_asf_tag(const CodecTag *tags, int id)
-{
- while (tags->id != 0) {
- if (!tags->invalid_asf && tags->id == id)
- return tags->tag;
- tags++;
- }
- return 0;
-}
-
-enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
-{
- while (tags->id != 0) {
- if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
- && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
- && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
- && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
- return tags->id;
- tags++;
- }
- return CODEC_ID_NONE;
-}
-
-unsigned int codec_get_bmp_tag(int id)
-{
- return codec_get_tag(codec_bmp_tags, id);
-}
-
-unsigned int codec_get_wav_tag(int id)
-{
- return codec_get_tag(codec_wav_tags, id);
-}
-
-enum CodecID codec_get_bmp_id(unsigned int tag)
-{
- return codec_get_id(codec_bmp_tags, tag);
-}
-
-enum CodecID codec_get_wav_id(unsigned int tag)
-{
- return codec_get_id(codec_wav_tags, tag);
-}
-
-/* BITMAPINFOHEADER header */
-void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf)
-{
- put_le32(pb, 40 + enc->extradata_size); /* size */
- put_le32(pb, enc->width);
- put_le32(pb, enc->height);
- put_le16(pb, 1); /* planes */
-
- put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
- /* compression type */
- put_le32(pb, for_asf ? codec_get_asf_tag(tags, enc->codec_id) : enc->codec_tag);
- put_le32(pb, enc->width * enc->height * 3);
- put_le32(pb, 0);
- put_le32(pb, 0);
- put_le32(pb, 0);
- put_le32(pb, 0);
-
- put_buffer(pb, enc->extradata, enc->extradata_size);
-
- if (enc->extradata_size & 1)
- put_byte(pb, 0);
-}
-
-static void parse_specific_params(AVCodecContext *stream, int *au_byterate, int *au_ssize, int *au_scale)
-{
- switch(stream->codec_id) {
- case CODEC_ID_PCM_S16LE:
- *au_scale = *au_ssize = 2*stream->channels;
- *au_byterate = *au_ssize * stream->sample_rate;
- break;
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_MULAW:
- *au_scale = *au_ssize = stream->channels;
- *au_byterate = *au_ssize * stream->sample_rate;
- break;
- case CODEC_ID_MP2:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- case CODEC_ID_MP3:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- default:
- *au_ssize = 1;
- *au_scale = 1;
- *au_byterate = stream->bit_rate / 8;
- break;
- }
-}
-
-static offset_t avi_start_new_riff(AVIContext *avi, ByteIOContext *pb,
- const char* riff_tag, const char* list_tag)
-{
- offset_t loff;
- int i;
-
- avi->riff_id++;
- for (i=0; i<MAX_STREAMS; i++)
- avi->indexes[i].entry = 0;
-
- avi->riff_start = start_tag(pb, "RIFF");
- put_tag(pb, riff_tag);
- loff = start_tag(pb, "LIST");
- put_tag(pb, list_tag);
- return loff;
-}
-
-static unsigned char* avi_stream2fourcc(unsigned char* tag, int index,
- enum CodecType type)
-{
- tag[0] = '0';
- tag[1] = '0' + index;
- if (type == CODEC_TYPE_VIDEO) {
- tag[2] = 'd';
- tag[3] = 'c';
- } else {
- tag[2] = 'w';
- tag[3] = 'b';
- }
- tag[4] = '\0';
- return tag;
-}
-
-static int avi_write_header(AVFormatContext *s)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
- AVCodecContext *stream, *video_enc;
- offset_t list1, list2, strh, strf;
-
- /* header list */
- avi->riff_id = 0;
- list1 = avi_start_new_riff(avi, pb, "AVI ", "hdrl");
-
- /* avi header */
- put_tag(pb, "avih");
- put_le32(pb, 14 * 4);
- bitrate = 0;
-
- video_enc = NULL;
- for(n=0;n<s->nb_streams;n++) {
- stream = &s->streams[n]->codec;
- bitrate += stream->bit_rate;
- if (stream->codec_type == CODEC_TYPE_VIDEO)
- video_enc = stream;
- }
-
- nb_frames = 0;
-
- if(video_enc){
- put_le32(pb, (uint32_t)(int64_t_C(1000000) * video_enc->frame_rate_base / video_enc->frame_rate));
- } else {
- put_le32(pb, 0);
- }
- put_le32(pb, bitrate / 8); /* XXX: not quite exact */
- put_le32(pb, 0); /* padding */
- put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */
- avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, nb_frames); /* nb frames, filled later */
- put_le32(pb, 0); /* initial frame */
- put_le32(pb, s->nb_streams); /* nb streams */
- put_le32(pb, 1024 * 1024); /* suggested buffer size */
- if(video_enc){
- put_le32(pb, video_enc->width);
- put_le32(pb, video_enc->height);
- } else {
- put_le32(pb, 0);
- put_le32(pb, 0);
- }
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
- put_le32(pb, 0); /* reserved */
-
- /* stream list */
- for(i=0;i<n;i++) {
- list2 = start_tag(pb, "LIST");
- put_tag(pb, "strl");
-
- stream = &s->streams[i]->codec;
-
- /* FourCC should really be set by the codec itself */
- if (! stream->codec_tag) {
- stream->codec_tag = codec_get_bmp_tag(stream->codec_id);
- }
-
- /* stream generic header */
- strh = start_tag(pb, "strh");
- switch(stream->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_tag(pb, "vids");
- put_le32(pb, stream->codec_tag);
- put_le32(pb, 0); /* flags */
- put_le16(pb, 0); /* priority */
- put_le16(pb, 0); /* language */
- put_le32(pb, 0); /* initial frame */
-
- put_le32(pb, stream->frame_rate_base); /* scale */
- put_le32(pb, stream->frame_rate); /* rate */
-
- put_le32(pb, 0); /* start */
- avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, nb_frames); /* length, XXX: fill later */
- put_le32(pb, 1024 * 1024); /* suggested buffer size */
- put_le32(pb, -1); /* quality */
- put_le32(pb, stream->width * stream->height * 3); /* sample size */
- put_le16(pb, 0);
- put_le16(pb, 0);
- put_le16(pb, stream->width);
- put_le16(pb, stream->height);
- break;
- case CODEC_TYPE_AUDIO:
- put_tag(pb, "auds");
- put_le32(pb, 1); /* tag */
- put_le32(pb, 0); /* flags */
- put_le16(pb, 0); /* priority */
- put_le16(pb, 0); /* language */
- put_le32(pb, 0); /* initial frame */
- parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
- put_le32(pb, au_scale); /* scale */
- put_le32(pb, au_byterate); /* rate */
- put_le32(pb, 0); /* start */
- avi->frames_hdr_strm[i] = url_ftell(pb); /* remember this offset to fill later */
- put_le32(pb, 0); /* length, XXX: filled later */
- put_le32(pb, 12 * 1024); /* suggested buffer size */
- put_le32(pb, -1); /* quality */
- put_le32(pb, au_ssize); /* sample size */
- put_le32(pb, 0);
- put_le32(pb, 0);
- break;
- default:
- av_abort();
- }
- end_tag(pb, strh);
-
- strf = start_tag(pb, "strf");
- switch(stream->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_bmp_header(pb, stream, codec_bmp_tags, 0);
- break;
- case CODEC_TYPE_AUDIO:
- if (put_wav_header(pb, stream) < 0) {
- av_free(avi);
- return -1;
- }
- break;
- default:
- av_abort();
- }
- end_tag(pb, strf);
-
- if (!url_is_streamed(pb)) {
- unsigned char tag[5];
- int j;
-
- /* Starting to lay out AVI OpenDML master index.
- * We want to make it JUNK entry for now, since we'd
- * like to get away without making AVI an OpenDML one
- * for compatibility reasons.
- */
- avi->indexes[i].entry = avi->indexes[i].ents_allocated = 0;
- avi->indexes[i].indx_start = start_tag(pb, "JUNK");
- put_le16(pb, 4); /* wLongsPerEntry */
- put_byte(pb, 0); /* bIndexSubType (0 == frame index) */
- put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
- put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */
- put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type));
- /* dwChunkId */
- put_le64(pb, 0); /* dwReserved[3]
- put_le32(pb, 0); Must be 0. */
- for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++)
- put_le64(pb, 0);
- end_tag(pb, avi->indexes[i].indx_start);
- }
-
- end_tag(pb, list2);
- }
-
- if (!url_is_streamed(pb)) {
- /* AVI could become an OpenDML one, if it grows beyond 2Gb range */
- avi->odml_list = start_tag(pb, "JUNK");
- put_tag(pb, "odml");
- put_tag(pb, "dmlh");
- put_le32(pb, 248);
- for (i = 0; i < 248; i+= 4)
- put_le32(pb, 0);
- end_tag(pb, avi->odml_list);
- }
-
- end_tag(pb, list1);
-
- avi->movi_list = start_tag(pb, "LIST");
- put_tag(pb, "movi");
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int avi_write_ix(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- AVIContext *avi = s->priv_data;
- unsigned char tag[5];
- unsigned char ix_tag[] = "ix00";
- int i, j;
-
- if (avi->riff_id > AVI_MASTER_INDEX_SIZE)
- return -1;
-
- for (i=0;i<s->nb_streams;i++) {
- offset_t ix, pos;
-
- avi_stream2fourcc(&tag[0], i, s->streams[i]->codec.codec_type);
- ix_tag[3] = '0' + i;
-
- /* Writing AVI OpenDML leaf index chunk */
- ix = url_ftell(pb);
- put_tag(pb, &ix_tag[0]); /* ix?? */
- put_le32(pb, avi->indexes[i].entry * 8 + 24);
- /* chunk size */
- put_le16(pb, 2); /* wLongsPerEntry */
- put_byte(pb, 0); /* bIndexSubType (0 == frame index) */
- put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */
- put_le32(pb, avi->indexes[i].entry);
- /* nEntriesInUse */
- put_tag(pb, &tag[0]); /* dwChunkId */
- put_le64(pb, avi->movi_list);/* qwBaseOffset */
- put_le32(pb, 0); /* dwReserved_3 (must be 0) */
-
- for (j=0; j<avi->indexes[i].entry; j++) {
- AVIIentry* ie = avi_get_ientry(&avi->indexes[i], j);
- put_le32(pb, ie->pos + 8);
- put_le32(pb, ((uint32_t)ie->len & ~0x80000000) |
- (ie->flags & 0x10 ? 0 : 0x80000000));
- }
- put_flush_packet(pb);
- pos = url_ftell(pb);
-
- /* Updating one entry in the AVI OpenDML master index */
- url_fseek(pb, avi->indexes[i].indx_start - 8, SEEK_SET);
- put_tag(pb, "indx"); /* enabling this entry */
- url_fskip(pb, 8);
- put_le32(pb, avi->riff_id); /* nEntriesInUse */
- url_fskip(pb, 16*avi->riff_id);
- put_le64(pb, ix); /* qwOffset */
- put_le32(pb, pos - ix); /* dwSize */
- put_le32(pb, avi->indexes[i].entry); /* dwDuration */
-
- url_fseek(pb, pos, SEEK_SET);
- }
- return 0;
-}
-
-static int avi_write_idx1(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- AVIContext *avi = s->priv_data;
- offset_t file_size, idx_chunk;
- int i, n, nb_frames, au_byterate, au_ssize, au_scale;
- AVCodecContext *stream;
- unsigned char tag[5];
-
- if (!url_is_streamed(pb)) {
- AVIIentry* ie = 0, *tie;
- int entry[MAX_STREAMS];
- int empty, stream_id = -1;
-
- idx_chunk = start_tag(pb, "idx1");
- memset(&entry[0], 0, sizeof(entry));
- do {
- empty = 1;
- for (i=0; i<s->nb_streams; i++) {
- if (avi->indexes[i].entry <= entry[i])
- continue;
-
- tie = avi_get_ientry(&avi->indexes[i], entry[i]);
- if (empty || tie->pos < ie->pos) {
- ie = tie;
- stream_id = i;
- }
- empty = 0;
- }
- if (!empty) {
- avi_stream2fourcc(&tag[0], stream_id,
- s->streams[stream_id]->codec.codec_type);
- put_tag(pb, &tag[0]);
- put_le32(pb, ie->flags);
- put_le32(pb, ie->pos);
- put_le32(pb, ie->len);
- entry[stream_id]++;
- }
- } while (!empty);
- end_tag(pb, idx_chunk);
-
- /* Fill in frame/sample counters */
- file_size = url_ftell(pb);
- nb_frames = 0;
- for(n=0;n<s->nb_streams;n++) {
- if (avi->frames_hdr_strm[n] != 0) {
- stream = &s->streams[n]->codec;
- url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET);
- if (stream->codec_type == CODEC_TYPE_VIDEO) {
- put_le32(pb, stream->frame_number);
- if (nb_frames < stream->frame_number)
- nb_frames = stream->frame_number;
- } else {
- if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
- put_le32(pb, stream->frame_number);
- nb_frames += stream->frame_number;
- } else {
- parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale);
- put_le32(pb, avi->audio_strm_length[n] / au_ssize);
- }
- }
- }
- }
- if (avi->frames_hdr_all != 0) {
- url_fseek(pb, avi->frames_hdr_all, SEEK_SET);
- put_le32(pb, nb_frames);
- }
- url_fseek(pb, file_size, SEEK_SET);
- }
- return 0;
-}
-
-static int avi_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- unsigned char tag[5];
- unsigned int flags;
- AVCodecContext *enc;
-
- if (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE) {
- avi_write_ix(s);
- end_tag(pb, avi->movi_list);
-
- if (avi->riff_id == 1)
- avi_write_idx1(s);
-
- end_tag(pb, avi->riff_start);
- avi->movi_list = avi_start_new_riff(avi, pb, "AVIX", "movi");
- }
-
- enc = &s->streams[stream_index]->codec;
- avi_stream2fourcc(&tag[0], stream_index, enc->codec_type);
- if (enc->codec_type == CODEC_TYPE_AUDIO) {
- avi->audio_strm_length[stream_index] += size;
- flags = 0x10;
- } else
- flags = enc->coded_frame->key_frame ? 0x10 : 0x00;
-
- if (!url_is_streamed(&s->pb)) {
- AVIIndex* idx = &avi->indexes[stream_index];
- int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE;
- int id = idx->entry % AVI_INDEX_CLUSTER_SIZE;
- if (idx->ents_allocated <= idx->entry) {
- idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*));
- if (!idx->cluster)
- return -1;
- idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry));
- if (!idx->cluster[cl])
- return -1;
- idx->ents_allocated += AVI_INDEX_CLUSTER_SIZE;
- }
-
- idx->cluster[cl][id].flags = flags;
- idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list;
- idx->cluster[cl][id].len = size;
- idx->entry++;
- }
-
- put_buffer(pb, tag, 4);
- put_le32(pb, size);
- put_buffer(pb, buf, size);
- if (size & 1)
- put_byte(pb, 0);
-
- put_flush_packet(pb);
- return 0;
-}
-
-static int avi_write_trailer(AVFormatContext *s)
-{
- AVIContext *avi = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int res = 0;
- int i, j, n, nb_frames;
- offset_t file_size;
-
- if (avi->riff_id == 1) {
- end_tag(pb, avi->movi_list);
- res = avi_write_idx1(s);
- end_tag(pb, avi->riff_start);
- } else {
- avi_write_ix(s);
- end_tag(pb, avi->movi_list);
- end_tag(pb, avi->riff_start);
-
- file_size = url_ftell(pb);
- url_fseek(pb, avi->odml_list - 8, SEEK_SET);
- put_tag(pb, "LIST"); /* Making this AVI OpenDML one */
- url_fskip(pb, 16);
-
- for (n=nb_frames=0;n<s->nb_streams;n++) {
- AVCodecContext *stream = &s->streams[n]->codec;
- if (stream->codec_type == CODEC_TYPE_VIDEO) {
- if (nb_frames < stream->frame_number)
- nb_frames = stream->frame_number;
- } else {
- if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
- nb_frames += stream->frame_number;
- }
- }
- }
- put_le32(pb, nb_frames);
- url_fseek(pb, file_size, SEEK_SET);
- }
- put_flush_packet(pb);
-
- for (i=0; i<MAX_STREAMS; i++) {
- for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
- av_free(avi->indexes[i].cluster[j]);
- av_free(avi->indexes[i].cluster);
- avi->indexes[i].cluster = NULL;
- avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0;
- }
-
- return res;
-}
-
-static AVOutputFormat avi_oformat = {
- "avi",
- "avi format",
- "video/x-msvideo",
- "avi",
- sizeof(AVIContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG4,
- avi_write_header,
- avi_write_packet,
- avi_write_trailer,
-};
-
-int avienc_init(void)
-{
- av_register_output_format(&avi_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Unbuffered io for ffmpeg system
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-static int default_interrupt_cb(void);
-
-URLProtocol *first_protocol = NULL;
-URLInterruptCB *url_interrupt_cb = default_interrupt_cb;
-
-int register_protocol(URLProtocol *protocol)
-{
- URLProtocol **p;
- p = &first_protocol;
- while (*p != NULL) p = &(*p)->next;
- *p = protocol;
- protocol->next = NULL;
- return 0;
-}
-
-int url_open(URLContext **puc, const char *filename, int flags)
-{
- URLContext *uc;
- URLProtocol *up;
- const char *p;
- char proto_str[128], *q;
- int err;
-
- p = filename;
- q = proto_str;
- while (*p != '\0' && *p != ':') {
- /* protocols can only contain alphabetic chars */
- if (!isalpha(*p))
- goto file_proto;
- if ((q - proto_str) < sizeof(proto_str) - 1)
- *q++ = *p;
- p++;
- }
- /* if the protocol has length 1, we consider it is a dos drive */
- if (*p == '\0' || (q - proto_str) <= 1) {
- file_proto:
- strcpy(proto_str, "file");
- } else {
- *q = '\0';
- }
-
- up = first_protocol;
- while (up != NULL) {
- if (!strcmp(proto_str, up->name))
- goto found;
- up = up->next;
- }
- err = -ENOENT;
- goto fail;
- found:
- uc = av_malloc(sizeof(URLContext) + strlen(filename));
- if (!uc) {
- err = -ENOMEM;
- goto fail;
- }
- strcpy(uc->filename, filename);
- uc->prot = up;
- uc->flags = flags;
- uc->is_streamed = 0; /* default = not streamed */
- uc->max_packet_size = 0; /* default: stream file */
- err = up->url_open(uc, filename, flags);
- if (err < 0) {
- av_free(uc);
- *puc = NULL;
- return err;
- }
- *puc = uc;
- return 0;
- fail:
- *puc = NULL;
- return err;
-}
-
-int url_read(URLContext *h, unsigned char *buf, int size)
-{
- int ret;
- if (h->flags & URL_WRONLY)
- return -EIO;
- ret = h->prot->url_read(h, buf, size);
- return ret;
-}
-
-int url_write(URLContext *h, unsigned char *buf, int size)
-{
- int ret;
- if (!(h->flags & (URL_WRONLY | URL_RDWR)))
- return -EIO;
- /* avoid sending too big packets */
- if (h->max_packet_size && size > h->max_packet_size)
- return -EIO;
- ret = h->prot->url_write(h, buf, size);
- return ret;
-}
-
-offset_t url_seek(URLContext *h, offset_t pos, int whence)
-{
- offset_t ret;
-
- if (!h->prot->url_seek)
- return -EPIPE;
- ret = h->prot->url_seek(h, pos, whence);
- return ret;
-}
-
-int url_close(URLContext *h)
-{
- int ret;
-
- ret = h->prot->url_close(h);
- av_free(h);
- return ret;
-}
-
-int url_exist(const char *filename)
-{
- URLContext *h;
- if (url_open(&h, filename, URL_RDONLY) < 0)
- return 0;
- url_close(h);
- return 1;
-}
-
-offset_t url_filesize(URLContext *h)
-{
- offset_t pos, size;
-
- pos = url_seek(h, 0, SEEK_CUR);
- size = url_seek(h, 0, SEEK_END);
- url_seek(h, pos, SEEK_SET);
- return size;
-}
-
-/*
- * Return the maximum packet size associated to packetized file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h file handle
- * @return maximum packet size in bytes
- */
-int url_get_max_packet_size(URLContext *h)
-{
- return h->max_packet_size;
-}
-
-void url_get_filename(URLContext *h, char *buf, int buf_size)
-{
- pstrcpy(buf, buf_size, h->filename);
-}
-
-
-static int default_interrupt_cb(void)
-{
- return 0;
-}
-
-/**
- * The callback is called in blocking functions to test regulary if
- * asynchronous interruption is needed. -EINTR is returned in this
- * case by the interrupted function. 'NULL' means no interrupt
- * callback is given.
- */
-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)
-{
- if (!interrupt_cb)
- interrupt_cb = default_interrupt_cb;
- url_interrupt_cb = interrupt_cb;
-}
+++ /dev/null
-#ifndef AVIO_H
-#define AVIO_H
-
-/* output byte stream handling */
-
-typedef int64_t offset_t;
-
-/* unbuffered I/O */
-
-struct URLContext {
- struct URLProtocol *prot;
- int flags;
- int is_streamed; /* true if streamed (no seek possible), default = false */
- int max_packet_size; /* if non zero, the stream is packetized with this max packet size */
- void *priv_data;
- char filename[1]; /* specified filename */
-};
-
-typedef struct URLContext URLContext;
-
-typedef struct URLPollEntry {
- URLContext *handle;
- int events;
- int revents;
-} URLPollEntry;
-
-#define URL_RDONLY 0
-#define URL_WRONLY 1
-#define URL_RDWR 2
-
-typedef int URLInterruptCB(void);
-
-int url_open(URLContext **h, const char *filename, int flags);
-int url_read(URLContext *h, unsigned char *buf, int size);
-int url_write(URLContext *h, unsigned char *buf, int size);
-offset_t url_seek(URLContext *h, offset_t pos, int whence);
-int url_close(URLContext *h);
-int url_exist(const char *filename);
-offset_t url_filesize(URLContext *h);
-int url_get_max_packet_size(URLContext *h);
-void url_get_filename(URLContext *h, char *buf, int buf_size);
-
-/* the callback is called in blocking functions to test regulary if
- asynchronous interruption is needed. -EINTR is returned in this
- case by the interrupted function. 'NULL' means no interrupt
- callback is given. */
-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
-
-/* not implemented */
-int url_poll(URLPollEntry *poll_table, int n, int timeout);
-
-typedef struct URLProtocol {
- const char *name;
- int (*url_open)(URLContext *h, const char *filename, int flags);
- int (*url_read)(URLContext *h, unsigned char *buf, int size);
- int (*url_write)(URLContext *h, unsigned char *buf, int size);
- offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
- int (*url_close)(URLContext *h);
- struct URLProtocol *next;
-} URLProtocol;
-
-extern URLProtocol *first_protocol;
-extern URLInterruptCB *url_interrupt_cb;
-
-int register_protocol(URLProtocol *protocol);
-
-typedef struct {
- unsigned char *buffer;
- int buffer_size;
- unsigned char *buf_ptr, *buf_end;
- void *opaque;
- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
- void (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
- int (*seek)(void *opaque, offset_t offset, int whence);
- offset_t pos; /* position in the file of the current buffer */
- int must_flush; /* true if the next seek should flush */
- int eof_reached; /* true if eof reached */
- int write_flag; /* true if open for writing */
- int is_streamed;
- int max_packet_size;
-} ByteIOContext;
-
-int init_put_byte(ByteIOContext *s,
- unsigned char *buffer,
- int buffer_size,
- int write_flag,
- void *opaque,
- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
- void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
- int (*seek)(void *opaque, offset_t offset, int whence));
-
-void put_byte(ByteIOContext *s, int b);
-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size);
-void put_le64(ByteIOContext *s, uint64_t val);
-void put_be64(ByteIOContext *s, uint64_t val);
-void put_le32(ByteIOContext *s, unsigned int val);
-void put_be32(ByteIOContext *s, unsigned int val);
-void put_le16(ByteIOContext *s, unsigned int val);
-void put_be16(ByteIOContext *s, unsigned int val);
-void put_tag(ByteIOContext *s, const char *tag);
-
-void put_be64_double(ByteIOContext *s, double val);
-void put_strz(ByteIOContext *s, const char *buf);
-
-offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
-void url_fskip(ByteIOContext *s, offset_t offset);
-offset_t url_ftell(ByteIOContext *s);
-int url_feof(ByteIOContext *s);
-
-#define URL_EOF (-1)
-int url_fgetc(ByteIOContext *s);
-#ifdef __GNUC__
-int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
-#else
-int url_fprintf(ByteIOContext *s, const char *fmt, ...);
-#endif
-char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
-
-void put_flush_packet(ByteIOContext *s);
-
-int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
-int get_byte(ByteIOContext *s);
-unsigned int get_le32(ByteIOContext *s);
-uint64_t get_le64(ByteIOContext *s);
-unsigned int get_le16(ByteIOContext *s);
-
-double get_be64_double(ByteIOContext *s);
-char *get_strz(ByteIOContext *s, char *buf, int maxlen);
-unsigned int get_be16(ByteIOContext *s);
-unsigned int get_be32(ByteIOContext *s);
-uint64_t get_be64(ByteIOContext *s);
-
-static inline int url_is_streamed(ByteIOContext *s)
-{
- return s->is_streamed;
-}
-
-int url_fdopen(ByteIOContext *s, URLContext *h);
-int url_setbufsize(ByteIOContext *s, int buf_size);
-int url_fopen(ByteIOContext *s, const char *filename, int flags);
-int url_fclose(ByteIOContext *s);
-URLContext *url_fileno(ByteIOContext *s);
-int url_fget_max_packet_size(ByteIOContext *s);
-
-int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags);
-int url_close_buf(ByteIOContext *s);
-
-int url_open_dyn_buf(ByteIOContext *s);
-int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size);
-int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer);
-
-/* file.c */
-extern URLProtocol file_protocol;
-extern URLProtocol pipe_protocol;
-
-/* udp.c */
-extern URLProtocol udp_protocol;
-int udp_set_remote_url(URLContext *h, const char *uri);
-int udp_get_local_port(URLContext *h);
-int udp_get_file_handle(URLContext *h);
-
-/* tcp.c */
-extern URLProtocol tcp_protocol;
-
-/* http.c */
-extern URLProtocol http_protocol;
-
-#endif
-
+++ /dev/null
-/*
- * Buffered I/O for ffmpeg system
- * Copyright (c) 2000,2001 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avio.h"
-#include <stdarg.h>
-
-#define IO_BUFFER_SIZE 32768
-
-int init_put_byte(ByteIOContext *s,
- unsigned char *buffer,
- int buffer_size,
- int write_flag,
- void *opaque,
- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
- void (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
- int (*seek)(void *opaque, offset_t offset, int whence))
-{
- s->buffer = buffer;
- s->buffer_size = buffer_size;
- s->buf_ptr = buffer;
- s->write_flag = write_flag;
- if (!s->write_flag)
- s->buf_end = buffer;
- else
- s->buf_end = buffer + buffer_size;
- s->opaque = opaque;
- s->write_packet = write_packet;
- s->read_packet = read_packet;
- s->seek = seek;
- s->pos = 0;
- s->must_flush = 0;
- s->eof_reached = 0;
- s->is_streamed = 0;
- s->max_packet_size = 0;
- return 0;
-}
-
-
-static void flush_buffer(ByteIOContext *s)
-{
- if (s->buf_ptr > s->buffer) {
- if (s->write_packet)
- s->write_packet(s->opaque, s->buffer, s->buf_ptr - s->buffer);
- s->pos += s->buf_ptr - s->buffer;
- }
- s->buf_ptr = s->buffer;
-}
-
-void put_byte(ByteIOContext *s, int b)
-{
- *(s->buf_ptr)++ = b;
- if (s->buf_ptr >= s->buf_end)
- flush_buffer(s);
-}
-
-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)
-{
- int len;
-
- while (size > 0) {
- len = (s->buf_end - s->buf_ptr);
- if (len > size)
- len = size;
- memcpy(s->buf_ptr, buf, len);
- s->buf_ptr += len;
-
- if (s->buf_ptr >= s->buf_end)
- flush_buffer(s);
-
- buf += len;
- size -= len;
- }
-}
-
-void put_flush_packet(ByteIOContext *s)
-{
- flush_buffer(s);
- s->must_flush = 0;
-}
-
-offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)
-{
- offset_t offset1;
-
- if (whence != SEEK_CUR && whence != SEEK_SET)
- return -EINVAL;
-
- if (s->write_flag) {
- if (whence == SEEK_CUR) {
- offset1 = s->pos + (s->buf_ptr - s->buffer);
- if (offset == 0)
- return offset1;
- offset += offset1;
- }
- offset1 = offset - s->pos;
- if (!s->must_flush &&
- offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
- /* can do the seek inside the buffer */
- s->buf_ptr = s->buffer + offset1;
- } else {
- if (!s->seek)
- return -EPIPE;
- flush_buffer(s);
- s->must_flush = 1;
- s->buf_ptr = s->buffer;
- s->seek(s->opaque, offset, SEEK_SET);
- s->pos = offset;
- }
- } else {
- if (whence == SEEK_CUR) {
- offset1 = s->pos - (s->buf_end - s->buffer) + (s->buf_ptr - s->buffer);
- if (offset == 0)
- return offset1;
- offset += offset1;
- }
- offset1 = offset - (s->pos - (s->buf_end - s->buffer));
- if (offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) {
- /* can do the seek inside the buffer */
- s->buf_ptr = s->buffer + offset1;
- } else {
- if (!s->seek)
- return -EPIPE;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer;
- s->seek(s->opaque, offset, SEEK_SET);
- s->pos = offset;
- }
- s->eof_reached = 0;
- }
- return offset;
-}
-
-void url_fskip(ByteIOContext *s, offset_t offset)
-{
- url_fseek(s, offset, SEEK_CUR);
-}
-
-offset_t url_ftell(ByteIOContext *s)
-{
- return url_fseek(s, 0, SEEK_CUR);
-}
-
-int url_feof(ByteIOContext *s)
-{
- return s->eof_reached;
-}
-
-void put_le32(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val);
- put_byte(s, val >> 8);
- put_byte(s, val >> 16);
- put_byte(s, val >> 24);
-}
-
-void put_be32(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val >> 24);
- put_byte(s, val >> 16);
- put_byte(s, val >> 8);
- put_byte(s, val);
-}
-
-/* IEEE format is assumed */
-void put_be64_double(ByteIOContext *s, double val)
-{
- union {
- double d;
- uint64_t ull;
- } u;
- u.d = val;
- put_be64(s, u.ull);
-}
-
-void put_strz(ByteIOContext *s, const char *str)
-{
- if (str)
- put_buffer(s, (const unsigned char *) str, strlen(str) + 1);
- else
- put_byte(s, 0);
-}
-
-void put_le64(ByteIOContext *s, uint64_t val)
-{
- put_le32(s, (uint32_t)(val & 0xffffffff));
- put_le32(s, (uint32_t)(val >> 32));
-}
-
-void put_be64(ByteIOContext *s, uint64_t val)
-{
- put_be32(s, (uint32_t)(val >> 32));
- put_be32(s, (uint32_t)(val & 0xffffffff));
-}
-
-void put_le16(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val);
- put_byte(s, val >> 8);
-}
-
-void put_be16(ByteIOContext *s, unsigned int val)
-{
- put_byte(s, val >> 8);
- put_byte(s, val);
-}
-
-void put_tag(ByteIOContext *s, const char *tag)
-{
- while (*tag) {
- put_byte(s, *tag++);
- }
-}
-
-/* Input stream */
-
-static void fill_buffer(ByteIOContext *s)
-{
- int len;
-
- /* no need to do anything if EOF already reached */
- if (s->eof_reached)
- return;
- len = s->read_packet(s->opaque, s->buffer, s->buffer_size);
- if (len <= 0) {
- /* do not modify buffer if EOF reached so that a seek back can
- be done without rereading data */
- s->eof_reached = 1;
- } else {
- s->pos += len;
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
- }
-}
-
-/* NOTE: return 0 if EOF, so you cannot use it if EOF handling is
- necessary */
-/* XXX: put an inline version */
-int get_byte(ByteIOContext *s)
-{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
- fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return 0;
- }
-}
-
-/* NOTE: return URL_EOF (-1) if EOF */
-int url_fgetc(ByteIOContext *s)
-{
- if (s->buf_ptr < s->buf_end) {
- return *s->buf_ptr++;
- } else {
- fill_buffer(s);
- if (s->buf_ptr < s->buf_end)
- return *s->buf_ptr++;
- else
- return URL_EOF;
- }
-}
-
-int get_buffer(ByteIOContext *s, unsigned char *buf, int size)
-{
- int len, size1;
-
- size1 = size;
- while (size > 0) {
- len = s->buf_end - s->buf_ptr;
- if (len > size)
- len = size;
- if (len == 0) {
- fill_buffer(s);
- len = s->buf_end - s->buf_ptr;
- if (len == 0)
- break;
- } else {
- memcpy(buf, s->buf_ptr, len);
- buf += len;
- s->buf_ptr += len;
- size -= len;
- }
- }
- return size1 - size;
-}
-
-unsigned int get_le16(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s);
- val |= get_byte(s) << 8;
- return val;
-}
-
-unsigned int get_le32(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s);
- val |= get_byte(s) << 8;
- val |= get_byte(s) << 16;
- val |= get_byte(s) << 24;
- return val;
-}
-
-uint64_t get_le64(ByteIOContext *s)
-{
- uint64_t val;
- val = (uint64_t)get_le32(s);
- val |= (uint64_t)get_le32(s) << 32;
- return val;
-}
-
-unsigned int get_be16(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-unsigned int get_be32(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 24;
- val |= get_byte(s) << 16;
- val |= get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-double get_be64_double(ByteIOContext *s)
-{
- union {
- double d;
- uint64_t ull;
- } u;
-
- u.ull = get_be64(s);
- return u.d;
-}
-
-char *get_strz(ByteIOContext *s, char *buf, int maxlen)
-{
- int i = 0;
- char c;
-
- while ((c = get_byte(s))) {
- if (i < maxlen-1)
- buf[i++] = c;
- }
-
- buf[i] = 0; /* Ensure null terminated, but may be truncated */
-
- return buf;
-}
-
-uint64_t get_be64(ByteIOContext *s)
-{
- uint64_t val;
- val = (uint64_t)get_be32(s) << 32;
- val |= (uint64_t)get_be32(s);
- return val;
-}
-
-/* link with avio functions */
-
-static void url_write_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- URLContext *h = opaque;
- url_write(h, buf, buf_size);
-}
-
-static int url_read_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- URLContext *h = opaque;
- return url_read(h, buf, buf_size);
-}
-
-static int url_seek_packet(void *opaque, int64_t offset, int whence)
-{
- URLContext *h = opaque;
- url_seek(h, offset, whence);
- return 0;
-}
-
-int url_fdopen(ByteIOContext *s, URLContext *h)
-{
- uint8_t *buffer;
- int buffer_size, max_packet_size;
-
-
- max_packet_size = url_get_max_packet_size(h);
- if (max_packet_size) {
- buffer_size = max_packet_size; /* no need to bufferize more than one packet */
- } else {
- buffer_size = IO_BUFFER_SIZE;
- }
- buffer = av_malloc(buffer_size);
- if (!buffer)
- return -ENOMEM;
-
- if (init_put_byte(s, buffer, buffer_size,
- (h->flags & URL_WRONLY) != 0, h,
- url_read_packet, url_write_packet, url_seek_packet) < 0) {
- av_free(buffer);
- return -EIO;
- }
- s->is_streamed = h->is_streamed;
- s->max_packet_size = max_packet_size;
- return 0;
-}
-
-/* XXX: must be called before any I/O */
-int url_setbufsize(ByteIOContext *s, int buf_size)
-{
- uint8_t *buffer;
- buffer = av_malloc(buf_size);
- if (!buffer)
- return -ENOMEM;
-
- av_free(s->buffer);
- s->buffer = buffer;
- s->buffer_size = buf_size;
- s->buf_ptr = buffer;
- if (!s->write_flag)
- s->buf_end = buffer;
- else
- s->buf_end = buffer + buf_size;
- return 0;
-}
-
-/* NOTE: when opened as read/write, the buffers are only used for
- reading */
-int url_fopen(ByteIOContext *s, const char *filename, int flags)
-{
- URLContext *h;
- int err;
-
- err = url_open(&h, filename, flags);
- if (err < 0)
- return err;
- err = url_fdopen(s, h);
- if (err < 0) {
- url_close(h);
- return err;
- }
- return 0;
-}
-
-int url_fclose(ByteIOContext *s)
-{
- URLContext *h = s->opaque;
-
- av_free(s->buffer);
- memset(s, 0, sizeof(ByteIOContext));
- return url_close(h);
-}
-
-URLContext *url_fileno(ByteIOContext *s)
-{
- return s->opaque;
-}
-
-/* XXX: currently size is limited */
-int url_fprintf(ByteIOContext *s, const char *fmt, ...)
-{
- va_list ap;
- char buf[4096];
- int ret;
-
- va_start(ap, fmt);
- ret = vsnprintf(buf, sizeof(buf), fmt, ap);
- va_end(ap);
- put_buffer(s, buf, strlen(buf));
- return ret;
-}
-
-/* note: unlike fgets, the EOL character is not returned and a whole
- line is parsed. return NULL if first char read was EOF */
-char *url_fgets(ByteIOContext *s, char *buf, int buf_size)
-{
- int c;
- char *q;
-
- c = url_fgetc(s);
- if (c == EOF)
- return NULL;
- q = buf;
- for(;;) {
- if (c == EOF || c == '\n')
- break;
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- c = url_fgetc(s);
- }
- if (buf_size > 0)
- *q = '\0';
- return buf;
-}
-
-/*
- * Return the maximum packet size associated to packetized buffered file
- * handle. If the file is not packetized (stream like http or file on
- * disk), then 0 is returned.
- *
- * @param h buffered file handle
- * @return maximum packet size in bytes
- */
-int url_fget_max_packet_size(ByteIOContext *s)
-{
- return s->max_packet_size;
-}
-
-/* buffer handling */
-int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags)
-{
- return init_put_byte(s, buf, buf_size,
- (flags & URL_WRONLY) != 0, NULL, NULL, NULL, NULL);
-}
-
-/* return the written or read size */
-int url_close_buf(ByteIOContext *s)
-{
- put_flush_packet(s);
- return s->buf_ptr - s->buffer;
-}
-
-/* output in a dynamic buffer */
-
-typedef struct DynBuffer {
- int pos, size, allocated_size;
- uint8_t *buffer;
- int io_buffer_size;
- uint8_t io_buffer[1];
-} DynBuffer;
-
-static void dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
-{
- DynBuffer *d = opaque;
- int new_size, new_allocated_size;
-
- /* reallocate buffer if needed */
- new_size = d->pos + buf_size;
- new_allocated_size = d->allocated_size;
- while (new_size > new_allocated_size) {
- if (!new_allocated_size)
- new_allocated_size = new_size;
- else
- new_allocated_size = (new_allocated_size * 3) / 2 + 1;
- }
-
- if (new_allocated_size > d->allocated_size) {
- d->buffer = av_realloc(d->buffer, new_allocated_size);
- if(d->buffer == NULL)
- return ;
- d->allocated_size = new_allocated_size;
- }
- memcpy(d->buffer + d->pos, buf, buf_size);
- d->pos = new_size;
- if (d->pos > d->size)
- d->size = d->pos;
-}
-
-static void dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
-{
- unsigned char buf1[4];
-
- /* packetized write: output the header */
- buf1[0] = (buf_size >> 24);
- buf1[1] = (buf_size >> 16);
- buf1[2] = (buf_size >> 8);
- buf1[3] = (buf_size);
- dyn_buf_write(opaque, buf1, 4);
-
- /* then the data */
- dyn_buf_write(opaque, buf, buf_size);
-}
-
-static int dyn_buf_seek(void *opaque, offset_t offset, int whence)
-{
- DynBuffer *d = opaque;
-
- if (whence == SEEK_CUR)
- offset += d->pos;
- else if (whence == SEEK_END)
- offset += d->size;
- if (offset < 0 || offset > 0x7fffffffLL)
- return -1;
- d->pos = offset;
- return 0;
-}
-
-static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size)
-{
- DynBuffer *d;
- int io_buffer_size, ret;
-
- if (max_packet_size)
- io_buffer_size = max_packet_size;
- else
- io_buffer_size = 1024;
-
- d = av_malloc(sizeof(DynBuffer) + io_buffer_size);
- if (!d)
- return -1;
- d->io_buffer_size = io_buffer_size;
- d->buffer = NULL;
- d->pos = 0;
- d->size = 0;
- d->allocated_size = 0;
- ret = init_put_byte(s, d->io_buffer, io_buffer_size,
- 1, d, NULL,
- max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
- max_packet_size ? NULL : dyn_buf_seek);
- if (ret == 0) {
- s->max_packet_size = max_packet_size;
- }
- return ret;
-}
-
-/*
- * Open a write only memory stream.
- *
- * @param s new IO context
- * @return zero if no error.
- */
-int url_open_dyn_buf(ByteIOContext *s)
-{
- return url_open_dyn_buf_internal(s, 0);
-}
-
-/*
- * Open a write only packetized memory stream with a maximum packet
- * size of 'max_packet_size'. The stream is stored in a memory buffer
- * with a big endian 4 byte header giving the packet size in bytes.
- *
- * @param s new IO context
- * @param max_packet_size maximum packet size (must be > 0)
- * @return zero if no error.
- */
-int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size)
-{
- if (max_packet_size <= 0)
- return -1;
- return url_open_dyn_buf_internal(s, max_packet_size);
-}
-
-/*
- * Return the written size and a pointer to the buffer. The buffer
- * must be freed with av_free().
- * @param s IO context
- * @param pointer to a byte buffer
- * @return the length of the byte buffer
- */
-int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
-{
- DynBuffer *d = s->opaque;
- int size;
-
- put_flush_packet(s);
-
- *pbuffer = d->buffer;
- size = d->size;
- av_free(d);
- return size;
-}
+++ /dev/null
-
-#include <stdlib.h>
-#include <strings.h>
-#include "barpainet.h"
-
-int inet_aton (const char * str, struct in_addr * add) {
- const char * pch = str;
- unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
-
- add1 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add2 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add3 = atoi(pch);
- pch = strpbrk(pch,".");
- if (pch == 0 || ++pch == 0) goto done;
- add4 = atoi(pch);
-
-done:
- add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
-
- return 1;
-}
+++ /dev/null
-#ifndef BARPA_INET_H
-#define BARPA_INET_H
-
-#include "../config.h"
-
-#ifdef CONFIG_BEOS_NETSERVER
-
-# include <socket.h>
-int inet_aton (const char * str, struct in_addr * add);
-# define PF_INET AF_INET
-# define SO_SNDBUF 0x40000001
-
-/* fake */
-struct ip_mreq {
- struct in_addr imr_multiaddr; /* IP multicast address of group */
- struct in_addr imr_interface; /* local IP address of interface */
-};
-
-#include <netdb.h>
-
-#else
-# include <arpa/inet.h>
-#endif
-
-#endif /* BARPA_INET_H */
+++ /dev/null
-/*
- * BeOS audio play interface
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include <Application.h>
-#include <SoundPlayer.h>
-
-extern "C" {
-#include "avformat.h"
-}
-
-#ifdef HAVE_BSOUNDRECORDER
-#include <SoundRecorder.h>
-using namespace BPrivate::Media::Experimental;
-#endif
-
-/* enable performance checks */
-//#define PERF_CHECK
-
-/* enable Media Kit latency checks */
-//#define LATENCY_CHECK
-
-#define AUDIO_BLOCK_SIZE 4096
-#define AUDIO_BLOCK_COUNT 8
-
-#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT)
-
-typedef struct {
- int fd; // UNUSED
- int sample_rate;
- int channels;
- int frame_size; /* in bytes ! */
- CodecID codec_id;
- uint8_t buffer[AUDIO_BUFFER_SIZE];
- int buffer_ptr;
- /* ring buffer */
- sem_id input_sem;
- int input_index;
- sem_id output_sem;
- int output_index;
- BSoundPlayer *player;
-#ifdef HAVE_BSOUNDRECORDER
- BSoundRecorder *recorder;
-#endif
- int has_quit; /* signal callbacks not to wait */
- volatile bigtime_t starve_time;
-} AudioData;
-
-static thread_id main_thid;
-static thread_id bapp_thid;
-static int own_BApp_created = 0;
-static int refcount = 0;
-
-/* create the BApplication and Run() it */
-static int32 bapp_thread(void *arg)
-{
- new BApplication("application/x-vnd.ffmpeg");
- own_BApp_created = 1;
- be_app->Run();
- /* kill the process group */
-// kill(0, SIGINT);
-// kill(main_thid, SIGHUP);
- return B_OK;
-}
-
-/* create the BApplication only if needed */
-static void create_bapp_if_needed(void)
-{
- if (refcount++ == 0) {
- /* needed by libmedia */
- if (be_app == NULL) {
- bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL);
- resume_thread(bapp_thid);
- while (!own_BApp_created)
- snooze(50000);
- }
- }
-}
-
-static void destroy_bapp_if_needed(void)
-{
- if (--refcount == 0 && own_BApp_created) {
- be_app->Lock();
- be_app->Quit();
- be_app = NULL;
- }
-}
-
-/* called back by BSoundPlayer */
-static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format)
-{
- AudioData *s;
- size_t len, amount;
- unsigned char *buf = (unsigned char *)buffer;
-
- s = (AudioData *)cookie;
- if (s->has_quit)
- return;
- while (bufferSize > 0) {
-#ifdef PERF_CHECK
- bigtime_t t;
- t = system_time();
-#endif
- len = MIN(AUDIO_BLOCK_SIZE, bufferSize);
- if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
- s->has_quit = 1;
- s->player->SetHasData(false);
- return;
- }
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
- memcpy(buf, &s->buffer[s->output_index], amount);
- s->output_index += amount;
- if (s->output_index >= AUDIO_BUFFER_SIZE) {
- s->output_index %= AUDIO_BUFFER_SIZE;
- memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
- s->output_index += len-amount;
- s->output_index %= AUDIO_BUFFER_SIZE;
- }
- release_sem_etc(s->input_sem, len, 0);
-#ifdef PERF_CHECK
- t = system_time() - t;
- s->starve_time = MAX(s->starve_time, t);
-#endif
- buf += len;
- bufferSize -= len;
- }
-}
-
-#ifdef HAVE_BSOUNDRECORDER
-/* called back by BSoundRecorder */
-static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format)
-{
- AudioData *s;
- size_t len, amount;
- unsigned char *buf = (unsigned char *)buffer;
-
- s = (AudioData *)cookie;
- if (s->has_quit)
- return;
-
- while (bufferSize > 0) {
- len = MIN(bufferSize, AUDIO_BLOCK_SIZE);
- //printf("acquire_sem(input, %d)\n", len);
- if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) {
- s->has_quit = 1;
- return;
- }
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
- memcpy(&s->buffer[s->input_index], buf, amount);
- s->input_index += amount;
- if (s->input_index >= AUDIO_BUFFER_SIZE) {
- s->input_index %= AUDIO_BUFFER_SIZE;
- memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
- s->input_index += len - amount;
- }
- release_sem_etc(s->output_sem, len, 0);
- //printf("release_sem(output, %d)\n", len);
- buf += len;
- bufferSize -= len;
- }
-}
-#endif
-
-static int audio_open(AudioData *s, int is_output, const char *audio_device)
-{
- int p[2];
- int ret;
- media_raw_audio_format format;
- media_multi_audio_format iformat;
-
-#ifndef HAVE_BSOUNDRECORDER
- if (!is_output)
- return -EIO; /* not for now */
-#endif
- s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input");
- if (s->input_sem < B_OK)
- return -EIO;
- s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output");
- if (s->output_sem < B_OK) {
- delete_sem(s->input_sem);
- return -EIO;
- }
- s->input_index = 0;
- s->output_index = 0;
- create_bapp_if_needed();
- s->frame_size = AUDIO_BLOCK_SIZE;
- /* bump up the priority (avoid realtime though) */
- set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1);
-#ifdef HAVE_BSOUNDRECORDER
- if (!is_output) {
- bool wait_for_input = false;
- if (audio_device && !strcmp(audio_device, "wait:"))
- wait_for_input = true;
- s->recorder = new BSoundRecorder(&iformat, wait_for_input, "ffmpeg input", audiorecord_callback);
- if (wait_for_input && (s->recorder->InitCheck() == B_OK)) {
- s->recorder->WaitForIncomingConnection(&iformat);
- }
- if (s->recorder->InitCheck() != B_OK || iformat.format != media_raw_audio_format::B_AUDIO_SHORT) {
- delete s->recorder;
- s->recorder = NULL;
- if (s->input_sem)
- delete_sem(s->input_sem);
- if (s->output_sem)
- delete_sem(s->output_sem);
- return -EIO;
- }
- s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE;
- s->channels = iformat.channel_count;
- s->sample_rate = (int)iformat.frame_rate;
- s->frame_size = iformat.buffer_size;
- s->recorder->SetCookie(s);
- s->recorder->SetVolume(1.0);
- s->recorder->Start();
- return 0;
- }
-#endif
- format = media_raw_audio_format::wildcard;
- format.format = media_raw_audio_format::B_AUDIO_SHORT;
- format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN;
- format.channel_count = s->channels;
- format.buffer_size = s->frame_size;
- format.frame_rate = s->sample_rate;
- s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback);
- if (s->player->InitCheck() != B_OK) {
- delete s->player;
- s->player = NULL;
- if (s->input_sem)
- delete_sem(s->input_sem);
- if (s->output_sem)
- delete_sem(s->output_sem);
- return -EIO;
- }
- s->player->SetCookie(s);
- s->player->SetVolume(1.0);
- s->player->Start();
- s->player->SetHasData(true);
- return 0;
-}
-
-static int audio_close(AudioData *s)
-{
- if (s->input_sem)
- delete_sem(s->input_sem);
- if (s->output_sem)
- delete_sem(s->output_sem);
- s->has_quit = 1;
- if (s->player) {
- s->player->Stop();
- }
- if (s->player)
- delete s->player;
-#ifdef HAVE_BSOUNDRECORDER
- if (s->recorder)
- delete s->recorder;
-#endif
- destroy_bapp_if_needed();
- return 0;
-}
-
-/* sound output support */
-static int audio_write_header(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- AVStream *st;
- int ret;
-
- st = s1->streams[0];
- s->sample_rate = st->codec.sample_rate;
- s->channels = st->codec.channels;
- ret = audio_open(s, 1, NULL);
- if (ret < 0)
- return -EIO;
- return 0;
-}
-
-static int audio_write_packet(AVFormatContext *s1, int stream_index,
- const uint8_t *buf, int size, int64_t force_pts)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- int len, ret;
-#ifdef LATENCY_CHECK
-bigtime_t lat1, lat2;
-lat1 = s->player->Latency();
-#endif
-#ifdef PERF_CHECK
- bigtime_t t = s->starve_time;
- s->starve_time = 0;
- printf("starve_time: %lld \n", t);
-#endif
- while (size > 0) {
- int amount;
- len = MIN(size, AUDIO_BLOCK_SIZE);
- if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK)
- return -EIO;
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index));
- memcpy(&s->buffer[s->input_index], buf, amount);
- s->input_index += amount;
- if (s->input_index >= AUDIO_BUFFER_SIZE) {
- s->input_index %= AUDIO_BUFFER_SIZE;
- memcpy(&s->buffer[s->input_index], buf + amount, len - amount);
- s->input_index += len - amount;
- }
- release_sem_etc(s->output_sem, len, 0);
- buf += len;
- size -= len;
- }
-#ifdef LATENCY_CHECK
-lat2 = s->player->Latency();
-printf("#### BSoundPlayer::Latency(): before= %lld, after= %lld\n", lat1, lat2);
-#endif
- return 0;
-}
-
-static int audio_write_trailer(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-/* grab support */
-
-static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- AVStream *st;
- int ret;
-
- if (!ap || ap->sample_rate <= 0 || ap->channels <= 0)
- return -1;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- return -ENOMEM;
- }
- s->sample_rate = ap->sample_rate;
- s->channels = ap->channels;
-
- ret = audio_open(s, 0, ap->device);
- if (ret < 0) {
- av_free(st);
- return -EIO;
- }
- /* take real parameters */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = s->codec_id;
- st->codec.sample_rate = s->sample_rate;
- st->codec.channels = s->channels;
- return 0;
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
-}
-
-static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- AudioData *s = (AudioData *)s1->priv_data;
- int size;
- size_t len, amount;
- unsigned char *buf;
- status_t err;
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
- buf = (unsigned char *)pkt->data;
- size = pkt->size;
- while (size > 0) {
- len = MIN(AUDIO_BLOCK_SIZE, size);
- //printf("acquire_sem(output, %d)\n", len);
- while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED);
- if (err < B_OK) {
- av_free_packet(pkt);
- return -EIO;
- }
- amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index));
- memcpy(buf, &s->buffer[s->output_index], amount);
- s->output_index += amount;
- if (s->output_index >= AUDIO_BUFFER_SIZE) {
- s->output_index %= AUDIO_BUFFER_SIZE;
- memcpy(buf + amount, &s->buffer[s->output_index], len - amount);
- s->output_index += len-amount;
- s->output_index %= AUDIO_BUFFER_SIZE;
- }
- release_sem_etc(s->input_sem, len, 0);
- //printf("release_sem(input, %d)\n", len);
- buf += len;
- size -= len;
- }
- //XXX: add pts info
- return 0;
-}
-
-static int audio_read_close(AVFormatContext *s1)
-{
- AudioData *s = (AudioData *)s1->priv_data;
-
- audio_close(s);
- return 0;
-}
-
-static AVInputFormat audio_in_format = {
- "audio_device",
- "audio grab and output",
- sizeof(AudioData),
- NULL,
- audio_read_header,
- audio_read_packet,
- audio_read_close,
- NULL,
- AVFMT_NOFILE,
-};
-
-AVOutputFormat audio_out_format = {
- "audio_device",
- "audio grab and output",
- "",
- "",
- sizeof(AudioData),
-#ifdef WORDS_BIGENDIAN
- CODEC_ID_PCM_S16BE,
-#else
- CODEC_ID_PCM_S16LE,
-#endif
- CODEC_ID_NONE,
- audio_write_header,
- audio_write_packet,
- audio_write_trailer,
- AVFMT_NOFILE,
-};
-
-extern "C" {
-
-int audio_init(void)
-{
- main_thid = find_thread(NULL);
- av_register_input_format(&audio_in_format);
- av_register_output_format(&audio_out_format);
- return 0;
-}
-
-} // "C"
-
+++ /dev/null
-/*
- * CRC decoder (for codec/format testing)
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* adler32.c -- compute the Adler-32 checksum of a data stream
- * Copyright (C) 1995 Mark Adler
- * For conditions of distribution and use, see copyright notice in zlib.h
- */
-
-#define BASE 65521L /* largest prime smaller than 65536 */
-#define NMAX 5552
-/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
-
-#define DO1(buf) {s1 += *buf++; s2 += s1;}
-#define DO2(buf) DO1(buf); DO1(buf);
-#define DO4(buf) DO2(buf); DO2(buf);
-#define DO8(buf) DO4(buf); DO4(buf);
-#define DO16(buf) DO8(buf); DO8(buf);
-
-static uint32_t adler32(uint32_t adler, const uint8_t *buf, unsigned int len)
-{
- unsigned long s1 = adler & 0xffff;
- unsigned long s2 = (adler >> 16) & 0xffff;
- int k;
-
- if (buf == NULL) return 1L;
-
- while (len > 0) {
- k = len < NMAX ? len : NMAX;
- len -= k;
- while (k >= 16) {
- DO16(buf);
- k -= 16;
- }
- if (k != 0) do {
- DO1(buf);
- } while (--k);
- s1 %= BASE;
- s2 %= BASE;
- }
- return (s2 << 16) | s1;
-}
-
-typedef struct CRCState {
- uint32_t crcval;
-} CRCState;
-
-static int crc_write_header(struct AVFormatContext *s)
-{
- CRCState *crc = s->priv_data;
-
- /* init CRC */
- crc->crcval = adler32(0, NULL, 0);
-
- return 0;
-}
-
-static int crc_write_packet(struct AVFormatContext *s,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- CRCState *crc = s->priv_data;
- crc->crcval = adler32(crc->crcval, buf, size);
- return 0;
-}
-
-static int crc_write_trailer(struct AVFormatContext *s)
-{
- CRCState *crc = s->priv_data;
- char buf[64];
-
- snprintf(buf, sizeof(buf), "CRC=%08x\n", crc->crcval);
- put_buffer(&s->pb, buf, strlen(buf));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static AVOutputFormat crc_format = {
- "crc",
- "crc testing format",
- NULL,
- "",
- sizeof(CRCState),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_RAWVIDEO,
- crc_write_header,
- crc_write_packet,
- crc_write_trailer,
-};
-
-int crc_init(void)
-{
- av_register_output_format(&crc_format);
- return 0;
-}
+++ /dev/null
-/*
- * Various simple utilities for ffmpeg system
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#if !defined(CONFIG_NOCUTILS)
-/**
- * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is
- * set to the next character in 'str' after the prefix.
- *
- * @param str input string
- * @param val prefix to test
- * @param ptr updated after the prefix in str in there is a match
- * @return TRUE if there is a match
- */
-int strstart(const char *str, const char *val, const char **ptr)
-{
- const char *p, *q;
- p = str;
- q = val;
- while (*q != '\0') {
- if (*p != *q)
- return 0;
- p++;
- q++;
- }
- if (ptr)
- *ptr = p;
- return 1;
-}
-
-/**
- * Return TRUE if val is a prefix of str (case independent). If it
- * returns TRUE, ptr is set to the next character in 'str' after the
- * prefix.
- *
- * @param str input string
- * @param val prefix to test
- * @param ptr updated after the prefix in str in there is a match
- * @return TRUE if there is a match */
-int stristart(const char *str, const char *val, const char **ptr)
-{
- const char *p, *q;
- p = str;
- q = val;
- while (*q != '\0') {
- if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q))
- return 0;
- p++;
- q++;
- }
- if (ptr)
- *ptr = p;
- return 1;
-}
-
-/**
- * Copy the string str to buf. If str length is bigger than buf_size -
- * 1 then it is clamped to buf_size - 1.
- * NOTE: this function does what strncpy should have done to be
- * useful. NEVER use strncpy.
- *
- * @param buf destination buffer
- * @param buf_size size of destination buffer
- * @param str source string
- */
-void pstrcpy(char *buf, int buf_size, const char *str)
-{
- int c;
- char *q = buf;
-
- if (buf_size <= 0)
- return;
-
- for(;;) {
- c = *str++;
- if (c == 0 || q >= buf + buf_size - 1)
- break;
- *q++ = c;
- }
- *q = '\0';
-}
-
-/* strcat and truncate. */
-char *pstrcat(char *buf, int buf_size, const char *s)
-{
- int len;
- len = strlen(buf);
- if (len < buf_size)
- pstrcpy(buf + len, buf_size - len, s);
- return buf;
-}
-
-#endif
-
-/* add one element to a dynamic array */
-void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem)
-{
- int nb, nb_alloc;
- unsigned long *tab;
-
- nb = *nb_ptr;
- tab = *tab_ptr;
- if ((nb & (nb - 1)) == 0) {
- if (nb == 0)
- nb_alloc = 1;
- else
- nb_alloc = nb * 2;
- tab = av_realloc(tab, nb_alloc * sizeof(unsigned long));
- *tab_ptr = tab;
- }
- tab[nb++] = elem;
- *nb_ptr = nb;
-}
-
-time_t mktimegm(struct tm *tm)
-{
- time_t t;
-
- int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
-
- if (m < 3) {
- m += 12;
- y--;
- }
-
- t = 86400 *
- (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
-
- t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
-
- return t;
-}
-
-/* get a positive number between n_min and n_max, for a maximum length
- of len_max. Return -1 if error. */
-static int date_get_num(const char **pp,
- int n_min, int n_max, int len_max)
-{
- int i, val, c;
- const char *p;
-
- p = *pp;
- val = 0;
- for(i = 0; i < len_max; i++) {
- c = *p;
- if (!isdigit(c))
- break;
- val = (val * 10) + c - '0';
- p++;
- }
- /* no number read ? */
- if (p == *pp)
- return -1;
- if (val < n_min || val > n_max)
- return -1;
- *pp = p;
- return val;
-}
-
-/* small strptime for ffmpeg */
-const char *small_strptime(const char *p, const char *fmt,
- struct tm *dt)
-{
- int c, val;
-
- for(;;) {
- c = *fmt++;
- if (c == '\0') {
- return p;
- } else if (c == '%') {
- c = *fmt++;
- switch(c) {
- case 'H':
- val = date_get_num(&p, 0, 23, 2);
- if (val == -1)
- return NULL;
- dt->tm_hour = val;
- break;
- case 'M':
- val = date_get_num(&p, 0, 59, 2);
- if (val == -1)
- return NULL;
- dt->tm_min = val;
- break;
- case 'S':
- val = date_get_num(&p, 0, 59, 2);
- if (val == -1)
- return NULL;
- dt->tm_sec = val;
- break;
- case 'Y':
- val = date_get_num(&p, 0, 9999, 4);
- if (val == -1)
- return NULL;
- dt->tm_year = val - 1900;
- break;
- case 'm':
- val = date_get_num(&p, 1, 12, 2);
- if (val == -1)
- return NULL;
- dt->tm_mon = val - 1;
- break;
- case 'd':
- val = date_get_num(&p, 1, 31, 2);
- if (val == -1)
- return NULL;
- dt->tm_mday = val;
- break;
- case '%':
- goto match;
- default:
- return NULL;
- }
- } else {
- match:
- if (c != *p)
- return NULL;
- p++;
- }
- }
- return p;
-}
-
+++ /dev/null
-/*
- * Raw DV format
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "dvcore.h"
-
-typedef struct DVDemuxContext {
- int is_audio;
- uint8_t buf[144000];
- int size;
-} DVDemuxContext;
-
-/* raw input */
-static int dv_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *vst, *ast;
- DVDemuxContext *c = s->priv_data;
-
- vst = av_new_stream(s, 0);
- if (!vst)
- return AVERROR_NOMEM;
- vst->codec.codec_type = CODEC_TYPE_VIDEO;
- vst->codec.codec_id = CODEC_ID_DVVIDEO;
- vst->codec.bit_rate = 25000000;
-
- ast = av_new_stream(s, 1);
- if (!ast)
- return AVERROR_NOMEM;
-
- ast->codec.codec_type = CODEC_TYPE_AUDIO;
- ast->codec.codec_id = CODEC_ID_DVAUDIO;
- c->is_audio = 0;
-
- return 0;
-}
-
-static void __destruct_pkt(struct AVPacket *pkt)
-{
- pkt->data = NULL; pkt->size = 0;
- return;
-}
-
-static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret;
- DVDemuxContext *c = s->priv_data;
-
- if (!c->is_audio) {
- ret = get_buffer(&s->pb, c->buf, 4);
- if (ret <= 0)
- return -EIO;
- c->size = dv_frame_profile(&c->buf[0])->frame_size;
-
- ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
- if (ret <= 0)
- return -EIO;
- }
-
- av_init_packet(pkt);
- pkt->destruct = __destruct_pkt;
- pkt->data = c->buf;
- pkt->size = c->size;
- pkt->stream_index = c->is_audio;
- pkt->flags |= PKT_FLAG_KEY;
-
- c->is_audio = !c->is_audio;
- return c->size;
-}
-
-static int dv_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-int dv_write_header(struct AVFormatContext *s)
-{
- DVMuxContext *c = s->priv_data;
-
- if (s->nb_streams != 2 || dv_core_init(c, s->streams) != 0) {
- fprintf(stderr, "Can't initialize DV format!\n"
- "Make sure that you supply exactly two streams:\n"
- " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
- return -1;
- }
- return 0;
-}
-
-int dv_write_packet(struct AVFormatContext *s,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- DVMuxContext *c = s->priv_data;
-
- if (stream_index == c->vst)
- dv_assemble_frame(c, buf, NULL, 0);
- else
- dv_assemble_frame(c, NULL, buf, size);
-
- if (c->has_audio && c->has_video) {
- put_buffer(&s->pb, &c->frame_buf[0], c->sys->frame_size);
- put_flush_packet(&s->pb);
- }
-
- return 0;
-}
-
-/*
- * We might end up with some extra A/V data without matching counterpart.
- * E.g. video data without enough audio to write the complete frame.
- * Currently we simply drop the last frame. I don't know whether this
- * is the best strategy of all
- */
-int dv_write_trailer(struct AVFormatContext *s)
-{
- dv_core_delete((DVMuxContext *)s->priv_data);
- return 0;
-}
-
-static AVInputFormat dv_iformat = {
- "dv",
- "DV video format",
- sizeof(DVDemuxContext),
- NULL,
- dv_read_header,
- dv_read_packet,
- dv_read_close,
- .extensions = "dv",
-};
-
-AVOutputFormat dv_oformat = {
- "dv",
- "DV video format",
- NULL,
- "dv",
- sizeof(DVMuxContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_DVVIDEO,
- dv_write_header,
- dv_write_packet,
- dv_write_trailer,
-};
-
-int dv_init(void)
-{
- av_register_input_format(&dv_iformat);
- av_register_output_format(&dv_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Linux DV1394 interface
- * Copyright (c) 2003 Max Krasnyansky <maxk@qualcomm.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/poll.h>
-#include <sys/time.h>
-#include <time.h>
-
-#include "avformat.h"
-
-#undef DV1394_DEBUG
-
-#include "dv1394.h"
-
-struct dv1394_data {
- int fd;
- int channel;
- int width, height;
- int frame_rate;
- int frame_size;
- int format;
-
- void *ring; /* Ring buffer */
- int index; /* Current frame index */
- int avail; /* Number of frames available for reading */
- int done; /* Number of completed frames */
-
- int stream; /* Current stream. 0 - video, 1 - audio */
- int64_t pts; /* Current timestamp */
- AVStream *vst, *ast;
-};
-
-/*
- * The trick here is to kludge around well known problem with kernel Ooopsing
- * when you try to capture PAL on a device node configure for NTSC. That's
- * why we have to configure the device node for PAL, and then read only NTSC
- * amount of data.
- */
-static int dv1394_reset(struct dv1394_data *dv)
-{
- struct dv1394_init init;
-
- init.channel = dv->channel;
- init.api_version = DV1394_API_VERSION;
- init.n_frames = DV1394_RING_FRAMES;
- init.format = DV1394_PAL;
-
- if (ioctl(dv->fd, DV1394_INIT, &init) < 0)
- return -1;
-
- dv->avail = dv->done = 0;
- dv->stream = 0;
- return 0;
-}
-
-static int dv1394_start(struct dv1394_data *dv)
-{
- /* Tell DV1394 driver to enable receiver */
- if (ioctl(dv->fd, DV1394_START_RECEIVE, 0) < 0) {
- perror("Failed to start receiver");
- return -1;
- }
- return 0;
-}
-
-static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap)
-{
- struct dv1394_data *dv = context->priv_data;
- const char *video_device;
-
- dv->vst = av_new_stream(context, 0);
- if (!dv->vst)
- return -ENOMEM;
- dv->ast = av_new_stream(context, 1);
- if (!dv->ast) {
- av_free(dv->vst);
- return -ENOMEM;
- }
-
- if (ap->standard && !strcasecmp(ap->standard, "pal"))
- dv->format = DV1394_PAL;
- else
- dv->format = DV1394_NTSC;
-
- if (ap->channel)
- dv->channel = ap->channel;
- else
- dv->channel = DV1394_DEFAULT_CHANNEL;
-
- dv->width = DV1394_WIDTH;
- if (dv->format == DV1394_NTSC) {
- dv->height = DV1394_NTSC_HEIGHT;
- dv->frame_size = DV1394_NTSC_FRAME_SIZE;
- dv->frame_rate = 30;
- } else {
- dv->height = DV1394_PAL_HEIGHT;
- dv->frame_size = DV1394_PAL_FRAME_SIZE;
- dv->frame_rate = 25;
- }
-
- /* Open and initialize DV1394 device */
- video_device = ap->device;
- if (!video_device)
- video_device = "/dev/dv1394/0";
- dv->fd = open(video_device, O_RDONLY);
- if (dv->fd < 0) {
- perror("Failed to open DV interface");
- goto failed;
- }
-
- if (dv1394_reset(dv) < 0) {
- perror("Failed to initialize DV interface");
- goto failed;
- }
-
- dv->ring = mmap(NULL, DV1394_PAL_FRAME_SIZE * DV1394_RING_FRAMES,
- PROT_READ, MAP_PRIVATE, dv->fd, 0);
- if (dv->ring == MAP_FAILED) {
- perror("Failed to mmap DV ring buffer");
- goto failed;
- }
-
- dv->stream = 0;
-
- dv->vst->codec.codec_type = CODEC_TYPE_VIDEO;
- dv->vst->codec.codec_id = CODEC_ID_DVVIDEO;
- dv->vst->codec.width = dv->width;
- dv->vst->codec.height = dv->height;
- dv->vst->codec.frame_rate = dv->frame_rate;
- dv->vst->codec.frame_rate_base = 1;
- dv->vst->codec.bit_rate = 25000000; /* Consumer DV is 25Mbps */
-
- dv->ast->codec.codec_type = CODEC_TYPE_AUDIO;
- dv->ast->codec.codec_id = CODEC_ID_DVAUDIO;
- dv->ast->codec.channels = 2;
- dv->ast->codec.sample_rate= 48000;
-
- av_set_pts_info(context, 48, 1, 1000000);
-
- if (dv1394_start(dv) < 0)
- goto failed;
-
- return 0;
-
-failed:
- close(dv->fd);
- av_free(dv->vst);
- av_free(dv->ast);
- return -EIO;
-}
-
-static void __destruct_pkt(struct AVPacket *pkt)
-{
- pkt->data = NULL; pkt->size = 0;
- return;
-}
-
-static inline int __get_frame(struct dv1394_data *dv, AVPacket *pkt)
-{
- char *ptr = dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE);
-
- if (dv->stream) {
- dv->index = (dv->index + 1) % DV1394_RING_FRAMES;
- dv->done++; dv->avail--;
- } else {
- dv->pts = av_gettime() & ((1LL << 48) - 1);
- }
-
- dv->format = ((ptr[3] & 0x80) == 0) ? DV1394_NTSC : DV1394_PAL;
- if (dv->format == DV1394_NTSC) {
- dv->frame_size = DV1394_NTSC_FRAME_SIZE;
- dv->vst->codec.height = dv->height = DV1394_NTSC_HEIGHT;
- dv->vst->codec.frame_rate = dv->frame_rate = 30;
- } else {
- dv->frame_size = DV1394_PAL_FRAME_SIZE;
- dv->vst->codec.height = dv->height = DV1394_PAL_HEIGHT;
- dv->vst->codec.frame_rate = dv->frame_rate = 25;
- }
-
- av_init_packet(pkt);
- pkt->destruct = __destruct_pkt;
- pkt->data = ptr;
- pkt->size = dv->frame_size;
- pkt->pts = dv->pts;
- pkt->stream_index = dv->stream;
- pkt->flags |= PKT_FLAG_KEY;
-
- dv->stream ^= 1;
-
- return dv->frame_size;
-}
-
-static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
-{
- struct dv1394_data *dv = context->priv_data;
-
- if (!dv->avail) {
- struct dv1394_status s;
- struct pollfd p;
-
- if (dv->done) {
- /* Request more frames */
- if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) {
- /* This usually means that ring buffer overflowed.
- * We have to reset :(.
- */
-
- fprintf(stderr, "DV1394: Ring buffer overflow. Reseting ..\n");
-
- dv1394_reset(dv);
- dv1394_start(dv);
- }
- dv->done = 0;
- }
-
- /* Wait until more frames are available */
-restart_poll:
- p.fd = dv->fd;
- p.events = POLLIN | POLLERR | POLLHUP;
- if (poll(&p, 1, -1) < 0) {
- if (errno == EAGAIN || errno == EINTR)
- goto restart_poll;
- perror("Poll failed");
- return -EIO;
- }
-
- if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {
- perror("Failed to get status");
- return -EIO;
- }
-#ifdef DV1394_DEBUG
- fprintf(stderr, "DV1394: status\n"
- "\tactive_frame\t%d\n"
- "\tfirst_clear_frame\t%d\n"
- "\tn_clear_frames\t%d\n"
- "\tdropped_frames\t%d\n",
- s.active_frame, s.first_clear_frame,
- s.n_clear_frames, s.dropped_frames);
-#endif
-
- dv->avail = s.n_clear_frames;
- dv->index = s.first_clear_frame;
- dv->done = 0;
-
- if (s.dropped_frames) {
- fprintf(stderr, "DV1394: Frame drop detected (%d). Reseting ..\n",
- s.dropped_frames);
-
- dv1394_reset(dv);
- dv1394_start(dv);
- }
- }
-
-#ifdef DV1394_DEBUG
- fprintf(stderr, "index %d, avail %d, done %d\n", dv->index, dv->avail,
- dv->done);
-#endif
-
- return __get_frame(dv, pkt);
-}
-
-static int dv1394_close(AVFormatContext * context)
-{
- struct dv1394_data *dv = context->priv_data;
-
- /* Shutdown DV1394 receiver */
- if (ioctl(dv->fd, DV1394_SHUTDOWN, 0) < 0)
- perror("Failed to shutdown DV1394");
-
- /* Unmap ring buffer */
- if (munmap(dv->ring, DV1394_NTSC_FRAME_SIZE * DV1394_RING_FRAMES) < 0)
- perror("Failed to munmap DV1394 ring buffer");
-
- close(dv->fd);
-
- return 0;
-}
-
-static AVInputFormat dv1394_format = {
- .name = "dv1394",
- .long_name = "dv1394 A/V grab",
- .priv_data_size = sizeof(struct dv1394_data),
- .read_header = dv1394_read_header,
- .read_packet = dv1394_read_packet,
- .read_close = dv1394_close,
- .flags = AVFMT_NOFILE
-};
-
-int dv1394_init(void)
-{
- av_register_input_format(&dv1394_format);
- return 0;
-}
+++ /dev/null
-/*
- * dv1394.h - DV input/output over IEEE 1394 on OHCI chips
- * Copyright (C)2001 Daniel Maas <dmaas@dcine.com>
- * receive, proc_fs by Dan Dennedy <dan@dennedy.org>
- *
- * based on:
- * video1394.h - driver for OHCI 1394 boards
- * Copyright (C)1999,2000 Sebastien Rougeaux <sebastien.rougeaux@anu.edu.au>
- * Peter Schlaile <udbz@rz.uni-karlsruhe.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef _DV_1394_H
-#define _DV_1394_H
-
-#define DV1394_DEFAULT_CHANNEL 63
-#define DV1394_DEFAULT_CARD 0
-#define DV1394_RING_FRAMES 20
-
-#define DV1394_WIDTH 720
-#define DV1394_NTSC_HEIGHT 480
-#define DV1394_PAL_HEIGHT 576
-
-/* This is the public user-space interface. Try not to break it. */
-
-#define DV1394_API_VERSION 0x20011127
-
-/* ********************
- ** **
- ** DV1394 API **
- ** **
- ********************
-
- There are two methods of operating the DV1394 DV output device.
-
- 1)
-
- The simplest is an interface based on write(): simply write
- full DV frames of data to the device, and they will be transmitted
- as quickly as possible. The FD may be set for non-blocking I/O,
- in which case you can use select() or poll() to wait for output
- buffer space.
-
- To set the DV output parameters (e.g. whether you want NTSC or PAL
- video), use the DV1394_INIT ioctl, passing in the parameters you
- want in a struct dv1394_init.
-
- Example 1:
- To play a raw .DV file: cat foo.DV > /dev/dv1394
- (cat will use write() internally)
-
- Example 2:
- static struct dv1394_init init = {
- 0x63, (broadcast channel)
- 4, (four-frame ringbuffer)
- DV1394_NTSC, (send NTSC video)
- 0, 0 (default empty packet rate)
- }
-
- ioctl(fd, DV1394_INIT, &init);
-
- while(1) {
- read( <a raw DV file>, buf, DV1394_NTSC_FRAME_SIZE );
- write( <the dv1394 FD>, buf, DV1394_NTSC_FRAME_SIZE );
- }
-
- 2)
-
- For more control over buffering, and to avoid unnecessary copies
- of the DV data, you can use the more sophisticated the mmap() interface.
- First, call the DV1394_INIT ioctl to specify your parameters,
- including the number of frames in the ringbuffer. Then, calling mmap()
- on the dv1394 device will give you direct access to the ringbuffer
- from which the DV card reads your frame data.
-
- The ringbuffer is simply one large, contiguous region of memory
- containing two or more frames of packed DV data. Each frame of DV data
- is 120000 bytes (NTSC) or 144000 bytes (PAL).
-
- Fill one or more frames in the ringbuffer, then use the DV1394_SUBMIT_FRAMES
- ioctl to begin I/O. You can use either the DV1394_WAIT_FRAMES ioctl
- or select()/poll() to wait until the frames are transmitted. Next, you'll
- need to call the DV1394_GET_STATUS ioctl to determine which ringbuffer
- frames are clear (ready to be filled with new DV data). Finally, use
- DV1394_SUBMIT_FRAMES again to send the new data to the DV output.
-
-
- Example: here is what a four-frame ringbuffer might look like
- during DV transmission:
-
-
- frame 0 frame 1 frame 2 frame 3
-
- *--------------------------------------*
- | CLEAR | DV data | DV data | CLEAR |
- *--------------------------------------*
- <ACTIVE>
-
- transmission goes in this direction --->>>
-
-
- The DV hardware is currently transmitting the data in frame 1.
- Once frame 1 is finished, it will automatically transmit frame 2.
- (if frame 2 finishes before frame 3 is submitted, the device
- will continue to transmit frame 2, and will increase the dropped_frames
- counter each time it repeats the transmission).
-
-
- If you called DV1394_GET_STATUS at this instant, you would
- receive the following values:
-
- n_frames = 4
- active_frame = 1
- first_clear_frame = 3
- n_clear_frames = 2
-
- At this point, you should write new DV data into frame 3 and optionally
- frame 0. Then call DV1394_SUBMIT_FRAMES to inform the device that
- it may transmit the new frames.
-
- ERROR HANDLING
-
- An error (buffer underflow/overflow or a break in the DV stream due
- to a 1394 bus reset) can be detected by checking the dropped_frames
- field of struct dv1394_status (obtained through the
- DV1394_GET_STATUS ioctl).
-
- The best way to recover from such an error is to re-initialize
- dv1394, either by using the DV1394_INIT ioctl call, or closing the
- file descriptor and opening it again. (note that you must unmap all
- ringbuffer mappings when closing the file descriptor, or else
- dv1394 will still be considered 'in use').
-
- MAIN LOOP
-
- For maximum efficiency and robustness against bus errors, you are
- advised to model the main loop of your application after the
- following pseudo-code example:
-
- (checks of system call return values omitted for brevity; always
- check return values in your code!)
-
- while( frames left ) {
-
- struct pollfd *pfd = ...;
-
- pfd->fd = dv1394_fd;
- pfd->revents = 0;
- pfd->events = POLLOUT | POLLIN; (OUT for transmit, IN for receive)
-
- (add other sources of I/O here)
-
- poll(pfd, 1, -1); (or select(); add a timeout if you want)
-
- if(pfd->revents) {
- struct dv1394_status status;
-
- ioctl(dv1394_fd, DV1394_GET_STATUS, &status);
-
- if(status.dropped_frames > 0) {
- reset_dv1394();
- } else {
- for(int i = 0; i < status.n_clear_frames; i++) {
- copy_DV_frame();
- }
- }
- }
- }
-
- where copy_DV_frame() reads or writes on the dv1394 file descriptor
- (read/write mode) or copies data to/from the mmap ringbuffer and
- then calls ioctl(DV1394_SUBMIT_FRAMES) to notify dv1394 that new
- frames are availble (mmap mode).
-
- reset_dv1394() is called in the event of a buffer
- underflow/overflow or a halt in the DV stream (e.g. due to a 1394
- bus reset). To guarantee recovery from the error, this function
- should close the dv1394 file descriptor (and munmap() all
- ringbuffer mappings, if you are using them), then re-open the
- dv1394 device (and re-map the ringbuffer).
-
-*/
-
-
-/* maximum number of frames in the ringbuffer */
-#define DV1394_MAX_FRAMES 32
-
-/* number of *full* isochronous packets per DV frame */
-#define DV1394_NTSC_PACKETS_PER_FRAME 250
-#define DV1394_PAL_PACKETS_PER_FRAME 300
-
-/* size of one frame's worth of DV data, in bytes */
-#define DV1394_NTSC_FRAME_SIZE (480 * DV1394_NTSC_PACKETS_PER_FRAME)
-#define DV1394_PAL_FRAME_SIZE (480 * DV1394_PAL_PACKETS_PER_FRAME)
-
-
-/* ioctl() commands */
-
-enum {
- /* I don't like using 0 as a valid ioctl() */
- DV1394_INVALID = 0,
-
-
- /* get the driver ready to transmit video.
- pass a struct dv1394_init* as the parameter (see below),
- or NULL to get default parameters */
- DV1394_INIT,
-
-
- /* stop transmitting video and free the ringbuffer */
- DV1394_SHUTDOWN,
-
-
- /* submit N new frames to be transmitted, where
- the index of the first new frame is first_clear_buffer,
- and the index of the last new frame is
- (first_clear_buffer + N) % n_frames */
- DV1394_SUBMIT_FRAMES,
-
-
- /* block until N buffers are clear (pass N as the parameter)
- Because we re-transmit the last frame on underrun, there
- will at most be n_frames - 1 clear frames at any time */
- DV1394_WAIT_FRAMES,
-
- /* capture new frames that have been received, where
- the index of the first new frame is first_clear_buffer,
- and the index of the last new frame is
- (first_clear_buffer + N) % n_frames */
- DV1394_RECEIVE_FRAMES,
-
-
- DV1394_START_RECEIVE,
-
-
- /* pass a struct dv1394_status* as the parameter (see below) */
- DV1394_GET_STATUS,
-};
-
-
-
-enum pal_or_ntsc {
- DV1394_NTSC = 0,
- DV1394_PAL
-};
-
-
-
-
-/* this is the argument to DV1394_INIT */
-struct dv1394_init {
- /* DV1394_API_VERSION */
- unsigned int api_version;
-
- /* isochronous transmission channel to use */
- unsigned int channel;
-
- /* number of frames in the ringbuffer. Must be at least 2
- and at most DV1394_MAX_FRAMES. */
- unsigned int n_frames;
-
- /* send/receive PAL or NTSC video format */
- enum pal_or_ntsc format;
-
- /* the following are used only for transmission */
-
- /* set these to zero unless you want a
- non-default empty packet rate (see below) */
- unsigned long cip_n;
- unsigned long cip_d;
-
- /* set this to zero unless you want a
- non-default SYT cycle offset (default = 3 cycles) */
- unsigned int syt_offset;
-};
-
-/* NOTE: you may only allocate the DV frame ringbuffer once each time
- you open the dv1394 device. DV1394_INIT will fail if you call it a
- second time with different 'n_frames' or 'format' arguments (which
- would imply a different size for the ringbuffer). If you need a
- different buffer size, simply close and re-open the device, then
- initialize it with your new settings. */
-
-/* Q: What are cip_n and cip_d? */
-
-/*
- A: DV video streams do not utilize 100% of the potential bandwidth offered
- by IEEE 1394 (FireWire). To achieve the correct rate of data transmission,
- DV devices must periodically insert empty packets into the 1394 data stream.
- Typically there is one empty packet per 14-16 data-carrying packets.
-
- Some DV devices will accept a wide range of empty packet rates, while others
- require a precise rate. If the dv1394 driver produces empty packets at
- a rate that your device does not accept, you may see ugly patterns on the
- DV output, or even no output at all.
-
- The default empty packet insertion rate seems to work for many people; if
- your DV output is stable, you can simply ignore this discussion. However,
- we have exposed the empty packet rate as a parameter to support devices that
- do not work with the default rate.
-
- The decision to insert an empty packet is made with a numerator/denominator
- algorithm. Empty packets are produced at an average rate of CIP_N / CIP_D.
- You can alter the empty packet rate by passing non-zero values for cip_n
- and cip_d to the INIT ioctl.
-
- */
-
-
-
-struct dv1394_status {
- /* this embedded init struct returns the current dv1394
- parameters in use */
- struct dv1394_init init;
-
- /* the ringbuffer frame that is currently being
- displayed. (-1 if the device is not transmitting anything) */
- int active_frame;
-
- /* index of the first buffer (ahead of active_frame) that
- is ready to be filled with data */
- unsigned int first_clear_frame;
-
- /* how many buffers, including first_clear_buffer, are
- ready to be filled with data */
- unsigned int n_clear_frames;
-
- /* how many times the DV stream has underflowed, overflowed,
- or otherwise encountered an error, since the previous call
- to DV1394_GET_STATUS */
- unsigned int dropped_frames;
-
- /* N.B. The dropped_frames counter is only a lower bound on the actual
- number of dropped frames, with the special case that if dropped_frames
- is zero, then it is guaranteed that NO frames have been dropped
- since the last call to DV1394_GET_STATUS.
- */
-};
-
-
-#endif /* _DV_1394_H */
+++ /dev/null
-/*
- * DV format muxer/demuxer
- * Copyright (c) 2003 Roman Shaposhnik
- *
- * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
- * of DV technical info.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "dvcore.h"
-
-/*
- * The reason why the following three big ugly looking tables are
- * here is my lack of DV spec IEC 61834. The tables were basically
- * constructed to make code that places packs in SSYB, VAUX and
- * AAUX blocks very simple and table-driven. They conform to the
- * SMPTE 314M and the output of my personal DV camcorder, neither
- * of which is sufficient for a reliable DV stream producing. Thus
- * while code is still in development I'll be gathering input from
- * people with different DV equipment and modifying the tables to
- * accommodate all the quirks. Later on, if possible, some of them
- * will be folded into smaller tables and/or switch-if logic. For
- * now, my only excuse is -- they don't eat up that much of a space.
- */
-
-static const int dv_ssyb_packs_dist[12][6] = {
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
- { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
-};
-
-static const int dv_vaux_packs_dist[12][15] = {
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
- { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
-};
-
-static const int dv_aaux_packs_dist[12][9] = {
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
-};
-
-enum dv_section_type {
- dv_sect_header = 0x1f,
- dv_sect_subcode = 0x3f,
- dv_sect_vaux = 0x56,
- dv_sect_audio = 0x76,
- dv_sect_video = 0x96,
-};
-
-enum dv_pack_type {
- dv_header525 = 0x3f, /* see dv_write_pack for important details on */
- dv_header625 = 0xbf, /* these two packs */
- dv_timecode = 0x13,
- dv_audio_source = 0x50,
- dv_audio_control = 0x51,
- dv_audio_recdate = 0x52,
- dv_audio_rectime = 0x53,
- dv_video_source = 0x60,
- dv_video_control = 0x61,
- dv_viedo_recdate = 0x62,
- dv_video_rectime = 0x63,
- dv_unknown_pack = 0xff,
-};
-
-static const uint16_t dv_audio_shuffle525[10][9] = {
- { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
- { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
- { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
- { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
- { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
-
- { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
- { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
- { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
- { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
- { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
-};
-
-static const uint16_t dv_audio_shuffle625[12][9] = {
- { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
- { 6, 42, 78, 32, 68, 104, 22, 58, 94},
- { 12, 48, 84, 2, 38, 74, 28, 64, 100},
- { 18, 54, 90, 8, 44, 80, 34, 70, 106},
- { 24, 60, 96, 14, 50, 86, 4, 40, 76},
- { 30, 66, 102, 20, 56, 92, 10, 46, 82},
-
- { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
- { 7, 43, 79, 33, 69, 105, 23, 59, 95},
- { 13, 49, 85, 3, 39, 75, 29, 65, 101},
- { 19, 55, 91, 9, 45, 81, 35, 71, 107},
- { 25, 61, 97, 15, 51, 87, 5, 41, 77},
- { 31, 67, 103, 21, 57, 93, 11, 47, 83},
-};
-
-static const int dv_audio_frequency[3] = {
- 48000, 44100, 32000,
-};
-
-const DVprofile dv_profiles[2] = {
- { .dsf = 0,
- .frame_size = 120000, /* 525/60 system (NTSC) */
- .difseg_size = 10,
- .frame_rate = 30000,
- .ltc_divisor = 30,
- .frame_rate_base = 1001,
- .height = 480,
-/* .video_place = dv_place_411, */
- .audio_stride = 90,
- .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32Khz */
- .audio_samples_dist = { 1602, 1601, 1602, 1601, 1602 },
- .audio_shuffle = dv_audio_shuffle525,
- },
- { .dsf = 1,
- .frame_size = 144000, /* 625/50 system (PAL) */
- .difseg_size = 12,
- .frame_rate = 25,
- .frame_rate_base = 1,
- .ltc_divisor = 25,
- .height = 576,
-/* .video_place = dv_place_420, */
- .audio_stride = 108,
- .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32Khz */
- .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
- .audio_shuffle = dv_audio_shuffle525,
- }
-};
-
-static inline uint16_t dv_audio_12to16(uint16_t sample)
-{
- uint16_t shift, result;
-
- sample = (sample < 0x800) ? sample : sample | 0xf000;
- shift = (sample & 0xf00) >> 8;
-
- if (shift < 0x2 || shift > 0xd) {
- result = sample;
- } else if (shift < 0x8) {
- shift--;
- result = (sample - (256 * shift)) << shift;
- } else {
- shift = 0xe - shift;
- result = ((sample + ((256 * shift) + 1)) << shift) - 1;
- }
-
- return result;
-}
-
-static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf)
-{
- struct tm tc;
- time_t ct;
- int ltc_frame;
-
- buf[0] = (uint8_t)pack_id;
- switch (pack_id) {
- case dv_header525: /* I can't imagine why these two weren't defined as real */
- case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
- buf[1] = 0xf8 | /* reserved -- always 1 */
- (0 & 0x07); /* APT: Track application ID */
- buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (0 & 0x07); /* AP1: Audio application ID */
- buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (0 & 0x07); /* AP2: Video application ID */
- buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
- (0x0f << 3) | /* reserved -- always 1 */
- (0 & 0x07); /* AP3: Subcode application ID */
- break;
- case dv_timecode:
- ct = (time_t)(c->frames / ((float)c->sys->frame_rate /
- (float)c->sys->frame_rate_base));
- localtime_r(&ct, &tc);
- /*
- * LTC drop-frame frame counter drops two frames (0 and 1) every
- * minute, unless it is exactly divisible by 10
- */
- ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor;
- buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */
- (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */
- ((ltc_frame / 10) << 4) | /* Tens of frames */
- (ltc_frame % 10); /* Units of frames */
- buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */
- ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
- (tc.tm_sec % 10); /* Units of seconds */
- buf[3] = (1 << 7) | /* Binary group flag BGF0 */
- ((tc.tm_min / 10) << 4) | /* Tens of minutes */
- (tc.tm_min % 10); /* Units of minutes */
- buf[4] = (1 << 7) | /* Binary group flag BGF2 */
- (1 << 6) | /* Binary group flag BGF1 */
- ((tc.tm_hour / 10) << 4) | /* Tens of hours */
- (tc.tm_hour % 10); /* Units of hours */
- break;
- case dv_audio_source: /* AAUX source pack */
- buf[1] = (0 << 7) | /* locked mode */
- (1 << 6) | /* reserved -- always 1 */
- (dv_audio_frame_size(c->sys, c->frames) -
- c->sys->audio_min_samples[0]);
- /* # of samples */
- buf[2] = (0 << 7) | /* multi-stereo */
- (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */
- (0 << 4) | /* pair bit: 0 -- one pair of channels */
- 0; /* audio mode */
- buf[3] = (1 << 7) | /* res */
- (1 << 6) | /* multi-language flag */
- (c->sys->dsf << 5) | /* system: 60fields/50fields */
- 0; /* definition: 0 -- SD (525/625) */
- buf[4] = (1 << 7) | /* emphasis: 1 -- off */
- (0 << 6) | /* emphasis time constant: 0 -- reserved */
- (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */
- 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */
- break;
- case dv_audio_control:
- buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
- (1 << 4) | /* input source: 1 -- digital input */
- (3 << 2) | /* compression: 3 -- no information */
- 0; /* misc. info/SMPTE emphasis off */
- buf[2] = (1 << 7) | /* recording start point: 1 -- no */
- (1 << 6) | /* recording end point: 1 -- no */
- (1 << 3) | /* recording mode: 1 -- original */
- 7;
- buf[3] = (1 << 7) | /* direction: 1 -- forward */
- 0x20; /* speed */
- buf[4] = (1 << 7) | /* reserved -- always 1 */
- 0x7f; /* genre category */
- break;
- case dv_audio_recdate:
- case dv_viedo_recdate: /* VAUX recording date */
- ct = c->start_time + (time_t)(c->frames /
- ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
- localtime_r(&ct, &tc);
- buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */
- /* 0xff is very likely to be "unknown" */
- buf[2] = (3 << 6) | /* reserved -- always 1 */
- ((tc.tm_mday / 10) << 4) | /* Tens of day */
- (tc.tm_mday % 10); /* Units of day */
- buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */
- (tc.tm_mon % 10); /* Units of month */
- buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */
- (tc.tm_year % 10); /* Units of year */
- break;
- case dv_audio_rectime: /* AAUX recording time */
- case dv_video_rectime: /* VAUX recording time */
- ct = c->start_time + (time_t)(c->frames /
- ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
- localtime_r(&ct, &tc);
- buf[1] = (3 << 6) | /* reserved -- always 1 */
- 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */
- buf[2] = (1 << 7) | /* reserved -- always 1 */
- ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
- (tc.tm_sec % 10); /* Units of seconds */
- buf[3] = (1 << 7) | /* reserved -- always 1 */
- ((tc.tm_min / 10) << 4) | /* Tens of minutes */
- (tc.tm_min % 10); /* Units of minutes */
- buf[4] = (3 << 6) | /* reserved -- always 1 */
- ((tc.tm_hour / 10) << 4) | /* Tens of hours */
- (tc.tm_hour % 10); /* Units of hours */
- break;
- case dv_video_source:
- buf[1] = 0xff; /* reserved -- always 1 */
- buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
- (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
- (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */
- 0xf; /* reserved -- always 1 */
- buf[3] = (3 << 6) | /* reserved -- always 1 */
- (c->sys->dsf << 5) | /* system: 60fields/50fields */
- 0; /* signal type video compression */
- buf[4] = 0xff; /* VISC: 0xff -- no information */
- break;
- case dv_video_control:
- buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
- 0x3f; /* reserved -- always 1 */
- buf[2] = 0xc8 | /* reserved -- always b11001xxx */
- c->aspect;
- buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */
- (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */
- (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */
- (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
- 0xc; /* reserved -- always b1100 */
- buf[4] = 0xff; /* reserved -- always 1 */
- break;
- default:
- buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
- }
- return 5;
-}
-
-static inline int dv_write_dif_id(enum dv_section_type t, uint8_t seq_num,
- uint8_t dif_num, uint8_t* buf)
-{
- buf[0] = (uint8_t)t; /* Section type */
- buf[1] = (seq_num<<4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
- (0 << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
- 7; /* reserved -- always 1 */
- buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */
- return 3;
-}
-
-static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf)
-{
- if (syb_num == 0 || syb_num == 6) {
- buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
- (0<<4) | /* AP3 (Subcode application ID) */
- 0x0f; /* reserved -- always 1 */
- }
- else if (syb_num == 11) {
- buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
- 0x7f; /* reserved -- always 1 */
- }
- else {
- buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
- (0<<4) | /* APT (Track application ID) */
- 0x0f; /* reserved -- always 1 */
- }
- buf[1] = 0xf0 | /* reserved -- always 1 */
- (syb_num & 0x0f); /* SSYB number 0 - 11 */
- buf[2] = 0xff; /* reserved -- always 1 */
- return 3;
-}
-
-void dv_format_frame(DVMuxContext *c, uint8_t* buf)
-{
- int i, j, k;
-
- for (i = 0; i < c->sys->difseg_size; i++) {
- memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */
-
- /* DV header: 1DIF */
- buf += dv_write_dif_id(dv_sect_header, i, 0, buf);
- buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf);
- buf += 72; /* unused bytes */
-
- /* DV subcode: 2DIFs */
- for (j = 0; j < 2; j++) {
- buf += dv_write_dif_id( dv_sect_subcode, i, j, buf);
- for (k = 0; k < 6; k++) {
- buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf);
- buf += dv_write_pack(dv_ssyb_packs_dist[i][k], c, buf);
- }
- buf += 29; /* unused bytes */
- }
-
- /* DV VAUX: 3DIFs */
- for (j = 0; j < 3; j++) {
- buf += dv_write_dif_id(dv_sect_vaux, i, j, buf);
- for (k = 0; k < 15 ; k++)
- buf += dv_write_pack(dv_vaux_packs_dist[i][k], c, buf);
- buf += 2; /* unused bytes */
- }
-
- /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
- for (j = 0; j < 135; j++) {
- if (j%15 == 0) {
- buf += dv_write_dif_id(dv_sect_audio, i, j/15, buf);
- buf += dv_write_pack(dv_aaux_packs_dist[i][j/15], c, buf);
- buf += 72; /* shuffled PCM audio */
- }
- buf += dv_write_dif_id(dv_sect_video, i, j, buf);
- buf += 77; /* 1 video macro block: 1 bytes control
- 4 * 14 bytes Y 8x8 data
- 10 bytes Cr 8x8 data
- 10 bytes Cb 8x8 data */
- }
- }
-}
-
-void dv_inject_audio(DVMuxContext *c, const uint8_t* pcm, uint8_t* frame_ptr)
-{
- int i, j, d, of;
- for (i = 0; i < c->sys->difseg_size; i++) {
- frame_ptr += 6 * 80; /* skip DIF segment header */
- for (j = 0; j < 9; j++) {
- for (d = 8; d < 80; d+=2) {
- of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride;
- frame_ptr[d] = pcm[of*2+1]; // FIXME: may be we have to admit
- frame_ptr[d+1] = pcm[of*2]; // that DV is a big endian PCM
- }
- frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
- }
- }
-}
-
-void dv_inject_video(DVMuxContext *c, const uint8_t* video_data, uint8_t* frame_ptr)
-{
- int i, j;
- int ptr = 0;
-
- for (i = 0; i < c->sys->difseg_size; i++) {
- ptr += 6 * 80; /* skip DIF segment header */
- for (j = 0; j < 135; j++) {
- if (j%15 == 0)
- ptr += 80; /* skip Audio DIF */
- ptr += 3;
- memcpy(frame_ptr + ptr, video_data + ptr, 77);
- ptr += 77;
- }
- }
-}
-
-int dv_audio_frame_size(const DVprofile* sys, int frame)
-{
- return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist)/
- sizeof(sys->audio_samples_dist[0]))];
-}
-
-const DVprofile* dv_frame_profile(uint8_t* frame)
-{
- return &dv_profiles[!!(frame[3] & 0x80)]; /* Header, DSF flag */
-}
-
-/*
- * This is the dumbest implementation of all -- it simply looks at
- * a fixed offset and if pack isn't there -- fails. We might want
- * to have a fallback mechanism for complete search of missing packs.
- */
-const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
-{
- int offs;
-
- switch (t) {
- case dv_audio_source:
- offs = (80*6 + 80*16*3 + 3);
- break;
- case dv_audio_control:
- offs = (80*6 + 80*16*4 + 3);
- break;
- case dv_video_control:
- offs = (80*5 + 48 + 5);
- break;
- default:
- return NULL;
- }
-
- return (frame[offs] == t ? &frame[offs] : NULL);
-}
-
-/*
- * There's a couple of assumptions being made here:
- * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples.
- * We can pass them upwards when ffmpeg will be ready to deal with them.
- * 2. We don't do software emphasis.
- * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
- * are converted into 16bit linear ones.
- */
-int dv_extract_audio(uint8_t* frame, uint8_t* pcm, AVCodecContext* avctx)
-{
- int size, i, j, d, of, smpls, freq, quant;
- uint16_t lc, rc;
- const DVprofile* sys;
- const uint8_t* as_pack;
-
- as_pack = dv_extract_pack(frame, dv_audio_source);
- if (!as_pack) /* No audio ? */
- return 0;
-
- sys = dv_frame_profile(frame);
- smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
- freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
- quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
-
- if (quant > 1)
- return -1; /* Unsupported quantization */
-
- avctx->sample_rate = dv_audio_frequency[freq];
- avctx->channels = 2;
- avctx->bit_rate = avctx->channels * avctx->sample_rate * 16;
- // What about:
- // avctx->frame_size =
-
- size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
-
- /* for each DIF segment */
- for (i = 0; i < sys->difseg_size; i++) {
- frame += 6 * 80; /* skip DIF segment header */
- for (j = 0; j < 9; j++) {
- for (d = 8; d < 80; d += 2) {
- if (quant == 0) { /* 16bit quantization */
- of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
- pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit
- pcm[of*2+1] = frame[d]; // that DV is a big endian PCM
- if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
- pcm[of*2+1] = 0;
- } else { /* 12bit quantization */
- if (i >= sys->difseg_size/2)
- goto out; /* We're not doing 4ch at this time */
-
- lc = ((uint16_t)frame[d] << 4) |
- ((uint16_t)frame[d+2] >> 4);
- rc = ((uint16_t)frame[d+1] << 4) |
- ((uint16_t)frame[d+2] & 0x0f);
- lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
- rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
-
- of = sys->audio_shuffle[i][j] + (d - 8)/3 * sys->audio_stride;
- pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit
- pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM
- of = sys->audio_shuffle[i+sys->difseg_size/2][j] +
- (d - 8)/3 * sys->audio_stride;
- pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit
- pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM
- ++d;
- }
- }
-
- frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
- }
- }
-
-out:
- return size;
-}
-
-/* FIXME: The following three functions could be underengineered ;-) */
-void dv_assemble_frame(DVMuxContext *c, const uint8_t* video, const uint8_t* audio, int asize)
-{
- uint8_t pcm[8192];
- uint8_t* frame = &c->frame_buf[0];
- int fsize, reqasize;
-
- if (c->has_audio && c->has_video) { /* must be a stale frame */
- dv_format_frame(c, frame);
- c->frames++;
- c->has_audio = c->has_video = 0;
- }
-
- if (video) {
- /* FIXME: we have to have more sensible approach than this one */
- if (c->has_video)
- fprintf(stderr, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
-
- dv_inject_video(c, video, frame);
- c->has_video = 1;
- }
- if (audio) {
- reqasize = 4 * dv_audio_frame_size(c->sys, c->frames);
- fsize = fifo_size(&c->audio_data, c->audio_data.rptr);
- if (fsize + asize >= reqasize) {
- if (fsize >= reqasize) {
- fifo_read(&c->audio_data, &pcm[0], reqasize, &c->audio_data.rptr);
- } else {
- fifo_read(&c->audio_data, &pcm[0], fsize, &c->audio_data.rptr);
- memcpy(&pcm[fsize], &audio[0], reqasize - fsize);
- audio += reqasize - fsize;
- asize -= reqasize - fsize;
- }
- dv_inject_audio(c, &pcm[0], frame);
- c->has_audio = 1;
- }
-
- /* FIXME: we have to have more sensible approach than this one */
- if (fifo_size(&c->audio_data, c->audio_data.rptr) + asize >= AVCODEC_MAX_AUDIO_FRAME_SIZE)
- fprintf(stderr, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
- fifo_write(&c->audio_data, (uint8_t *)audio, asize, &c->audio_data.wptr);
- }
-}
-
-int dv_core_init(DVMuxContext *c, AVStream *streams[])
-{
- /* We have to sort out where audio and where video stream is */
- if (streams[0]->codec.codec_type == CODEC_TYPE_VIDEO &&
- streams[1]->codec.codec_type == CODEC_TYPE_AUDIO) {
- c->vst = 0;
- c->ast = 1;
- }
- else if (streams[1]->codec.codec_type == CODEC_TYPE_VIDEO &&
- streams[0]->codec.codec_type == CODEC_TYPE_AUDIO) {
- c->vst = 1;
- c->ast = 0;
- } else
- goto bail_out;
-
- /* Some checks -- DV format is very picky about its incoming streams */
- if (streams[c->vst]->codec.codec_id != CODEC_ID_DVVIDEO ||
- streams[c->ast]->codec.codec_id != CODEC_ID_PCM_S16LE)
- goto bail_out;
- if (streams[c->ast]->codec.sample_rate != 48000 ||
- streams[c->ast]->codec.channels != 2)
- goto bail_out;
-
- if (streams[c->vst]->codec.frame_rate == 25 &&
- streams[c->vst]->codec.frame_rate_base == 1) {
- /* May be we have to pick sys for every frame */
- c->sys = &dv_profiles[1];
- }
- else if (streams[c->vst]->codec.frame_rate == 30000 &&
- streams[c->vst]->codec.frame_rate_base == 1001) {
- /* May be we have to pick sys for every frame */
- c->sys = &dv_profiles[0];
- } else
- goto bail_out;
-
- /* Ok, everything seems to be in working order */
- c->frames = 0;
- c->has_audio = c->has_video = 0;
- c->start_time = time(NULL);
- c->aspect = 0; /* 4:3 is the default */
- if (streams[c->vst]->codec.aspect_ratio == 16.0 / 9.0)
- c->aspect = 0x07;
-
- if (fifo_init(&c->audio_data, AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0)
- goto bail_out;
-
- dv_format_frame(c, &c->frame_buf[0]);
-
- return 0;
-
-bail_out:
- return -1;
-}
-
-void dv_core_delete(DVMuxContext *c)
-{
- fifo_free(&c->audio_data);
-}
+++ /dev/null
-/*
- * DV format muxer/demuxer
- * Copyright (c) 2003 Roman Shaposhnik
- *
- * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
- * of DV technical info.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <time.h>
-#include "avformat.h"
-
-/*
- * DVprofile is used to express the differences between various
- * DV flavors. For now it's primarily used for differentiating
- * 525/60 and 625/50, but the plans are to use it for various
- * DV specs as well (e.g. SMPTE314M vs. IEC 61834).
- */
-typedef struct DVprofile {
- int dsf; /* value of the dsf in the DV header */
- int frame_size; /* total size of one frame in bytes */
- int difseg_size; /* number of DIF segments */
- int frame_rate;
- int frame_rate_base;
- int ltc_divisor; /* FPS from the LTS standpoint */
- int height; /* picture height in pixels */
- uint16_t *video_place; /* positions of all DV macro blocks */
-
- int audio_stride; /* size of audio_shuffle table */
- int audio_min_samples[3]; /* min ammount of audio samples */
- /* for 48Khz, 44.1Khz and 32Khz */
- int audio_samples_dist[5];/* how many samples are supposed to be */
- /* in each frame in a 5 frames window */
- const uint16_t (*audio_shuffle)[9]; /* PCM shuffling table */
-} DVprofile;
-
-typedef struct DVMuxContext {
- const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */
- uint8_t frame_buf[144000]; /* frame under contruction */
- FifoBuffer audio_data; /* Fifo for storing excessive amounts of PCM */
- int frames; /* Number of a current frame */
- time_t start_time; /* Start time of recording */
- uint8_t aspect; /* Aspect ID 0 - 4:3, 7 - 16:9 */
- int ast, vst; /* Audio and Video stream indecies */
- int has_audio; /* frame under contruction has audio */
- int has_video; /* frame under contruction has video */
-} DVMuxContext;
-
-void dv_format_frame(DVMuxContext *, uint8_t*);
-void dv_inject_audio(DVMuxContext *, const uint8_t*, uint8_t*);
-void dv_inject_video(DVMuxContext *, const uint8_t*, uint8_t*);
-
-int dv_extract_audio(uint8_t*, uint8_t*, AVCodecContext*);
-
-int dv_audio_frame_size(const DVprofile*, int);
-
-void dv_assemble_frame(DVMuxContext *c, const uint8_t*, const uint8_t*, int);
-int dv_core_init(DVMuxContext *, AVStream*[]);
-void dv_core_delete(DVMuxContext *);
-
-const DVprofile* dv_frame_profile(uint8_t*);
+++ /dev/null
-/*
- * FFM (ffserver live feed) encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-
-/* The FFM file is made of blocks of fixed size */
-#define FFM_HEADER_SIZE 14
-#define PACKET_ID 0x666d
-
-/* each packet contains frames (which can span several packets */
-#define FRAME_HEADER_SIZE 8
-#define FLAG_KEY_FRAME 0x01
-
-typedef struct FFMStream {
- int64_t pts;
-} FFMStream;
-
-enum {
- READ_HEADER,
- READ_DATA,
-};
-
-typedef struct FFMContext {
- /* only reading mode */
- offset_t write_index, file_size;
- int read_state;
- uint8_t header[FRAME_HEADER_SIZE];
-
- /* read and write */
- int first_packet; /* true if first packet, needed to set the discontinuity tag */
- int packet_size;
- int frame_offset;
- int64_t pts;
- uint8_t *packet_ptr, *packet_end;
- uint8_t packet[FFM_PACKET_SIZE];
-} FFMContext;
-
-/* disable pts hack for testing */
-int ffm_nopts = 0;
-
-static void flush_packet(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- int fill_size, h;
- ByteIOContext *pb = &s->pb;
-
- fill_size = ffm->packet_end - ffm->packet_ptr;
- memset(ffm->packet_ptr, 0, fill_size);
-
- /* put header */
- put_be16(pb, PACKET_ID);
- put_be16(pb, fill_size);
- put_be64(pb, ffm->pts);
- h = ffm->frame_offset;
- if (ffm->first_packet)
- h |= 0x8000;
- put_be16(pb, h);
- put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet);
-
- /* prepare next packet */
- ffm->frame_offset = 0; /* no key frame */
- ffm->pts = 0; /* no pts */
- ffm->packet_ptr = ffm->packet;
- ffm->first_packet = 0;
-}
-
-/* 'first' is true if first data of a frame */
-static void ffm_write_data(AVFormatContext *s,
- const uint8_t *buf, int size,
- int64_t pts, int first)
-{
- FFMContext *ffm = s->priv_data;
- int len;
-
- if (first && ffm->frame_offset == 0)
- ffm->frame_offset = ffm->packet_ptr - ffm->packet + FFM_HEADER_SIZE;
- if (first && ffm->pts == 0)
- ffm->pts = pts;
-
- /* write as many packets as needed */
- while (size > 0) {
- len = ffm->packet_end - ffm->packet_ptr;
- if (len > size)
- len = size;
- memcpy(ffm->packet_ptr, buf, len);
-
- ffm->packet_ptr += len;
- buf += len;
- size -= len;
- if (ffm->packet_ptr >= ffm->packet_end) {
- /* special case : no pts in packet : we leave the current one */
- if (ffm->pts == 0)
- ffm->pts = pts;
-
- flush_packet(s);
- }
- }
-}
-
-static int ffm_write_header(AVFormatContext *s)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- FFMStream *fst;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *codec;
- int bit_rate, i;
-
- ffm->packet_size = FFM_PACKET_SIZE;
-
- /* header */
- put_tag(pb, "FFM1");
- put_be32(pb, ffm->packet_size);
- /* XXX: store write position in other file ? */
- put_be64(pb, ffm->packet_size); /* current write position */
-
- put_be32(pb, s->nb_streams);
- bit_rate = 0;
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- bit_rate += st->codec.bit_rate;
- }
- put_be32(pb, bit_rate);
-
- /* list of streams */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- fst = av_mallocz(sizeof(FFMStream));
- if (!fst)
- goto fail;
- st->priv_data = fst;
-
- codec = &st->codec;
- /* generic info */
- put_be32(pb, codec->codec_id);
- put_byte(pb, codec->codec_type);
- put_be32(pb, codec->bit_rate);
- put_be32(pb, st->quality);
- put_be32(pb, codec->flags);
- /* specific info */
- switch(codec->codec_type) {
- case CODEC_TYPE_VIDEO:
- put_be32(pb, codec->frame_rate_base);
- put_be32(pb, codec->frame_rate);
- put_be16(pb, codec->width);
- put_be16(pb, codec->height);
- put_be16(pb, codec->gop_size);
- put_byte(pb, codec->qmin);
- put_byte(pb, codec->qmax);
- put_byte(pb, codec->max_qdiff);
- put_be16(pb, (int) (codec->qcompress * 10000.0));
- put_be16(pb, (int) (codec->qblur * 10000.0));
- put_be32(pb, codec->bit_rate_tolerance);
- put_strz(pb, codec->rc_eq);
- put_be32(pb, codec->rc_max_rate);
- put_be32(pb, codec->rc_min_rate);
- put_be32(pb, codec->rc_buffer_size);
- put_be64_double(pb, codec->i_quant_factor);
- put_be64_double(pb, codec->b_quant_factor);
- put_be64_double(pb, codec->i_quant_offset);
- put_be64_double(pb, codec->b_quant_offset);
- put_be32(pb, codec->dct_algo);
- break;
- case CODEC_TYPE_AUDIO:
- put_be32(pb, codec->sample_rate);
- put_le16(pb, codec->channels);
- put_le16(pb, codec->frame_size);
- break;
- default:
- av_abort();
- }
- /* hack to have real time */
- if (ffm_nopts)
- fst->pts = 0;
- else
- fst->pts = av_gettime();
- }
-
- /* flush until end of block reached */
- while ((url_ftell(pb) % ffm->packet_size) != 0)
- put_byte(pb, 0);
-
- put_flush_packet(pb);
-
- /* init packet mux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE;
- ffm->frame_offset = 0;
- ffm->pts = 0;
- ffm->first_packet = 1;
-
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- av_freep(&st->priv_data);
- }
- return -1;
-}
-
-static int ffm_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t force_pts)
-{
- AVStream *st = s->streams[stream_index];
- FFMStream *fst = st->priv_data;
- int64_t pts;
- uint8_t header[FRAME_HEADER_SIZE];
- int duration;
-
- if (st->codec.codec_type == CODEC_TYPE_AUDIO) {
- duration = ((float)st->codec.frame_size / st->codec.sample_rate * 1000000.0);
- } else {
- duration = (1000000.0 * st->codec.frame_rate_base / (float)st->codec.frame_rate);
- }
-
- pts = fst->pts;
- /* packet size & key_frame */
- header[0] = stream_index;
- header[1] = 0;
- if (st->codec.coded_frame->key_frame) //if st->codec.coded_frame==NULL then there is a bug somewhere else
- header[1] |= FLAG_KEY_FRAME;
- header[2] = (size >> 16) & 0xff;
- header[3] = (size >> 8) & 0xff;
- header[4] = size & 0xff;
- header[5] = (duration >> 16) & 0xff;
- header[6] = (duration >> 8) & 0xff;
- header[7] = duration & 0xff;
- ffm_write_data(s, header, FRAME_HEADER_SIZE, pts, 1);
- ffm_write_data(s, buf, size, pts, 0);
-
- fst->pts += duration;
- return 0;
-}
-
-static int ffm_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- FFMContext *ffm = s->priv_data;
- int i;
-
- /* flush packets */
- if (ffm->packet_ptr > ffm->packet)
- flush_packet(s);
-
- put_flush_packet(pb);
-
- if (!url_is_streamed(pb)) {
- int64_t size;
- /* update the write offset */
- size = url_ftell(pb);
- url_fseek(pb, 8, SEEK_SET);
- put_be64(pb, size);
- put_flush_packet(pb);
- }
-
- for(i=0;i<s->nb_streams;i++)
- av_freep(&s->streams[i]->priv_data);
- return 0;
-}
-
-/* ffm demux */
-
-static int ffm_is_avail_data(AVFormatContext *s, int size)
-{
- FFMContext *ffm = s->priv_data;
- offset_t pos, avail_size;
- int len;
-
- len = ffm->packet_end - ffm->packet_ptr;
- if (!ffm_nopts) {
- /* XXX: I don't understand this test, so I disabled it for testing */
- if (size <= len)
- return 1;
- }
- pos = url_ftell(&s->pb);
- if (pos == ffm->write_index) {
- /* exactly at the end of stream */
- return 0;
- } else if (pos < ffm->write_index) {
- avail_size = ffm->write_index - pos;
- } else {
- avail_size = (ffm->file_size - pos) + (ffm->write_index - FFM_PACKET_SIZE);
- }
- avail_size = (avail_size / ffm->packet_size) * (ffm->packet_size - FFM_HEADER_SIZE) + len;
- if (size <= avail_size)
- return 1;
- else
- return 0;
-}
-
-/* first is true if we read the frame header */
-static int ffm_read_data(AVFormatContext *s,
- uint8_t *buf, int size, int first)
-{
- FFMContext *ffm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int len, fill_size, size1, frame_offset;
-
- size1 = size;
- while (size > 0) {
- redo:
- len = ffm->packet_end - ffm->packet_ptr;
- if (len > size)
- len = size;
- if (len == 0) {
- if (url_ftell(pb) == ffm->file_size)
- url_fseek(pb, ffm->packet_size, SEEK_SET);
- retry_read:
- get_be16(pb); /* PACKET_ID */
- fill_size = get_be16(pb);
- ffm->pts = get_be64(pb);
- frame_offset = get_be16(pb);
- get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE);
- ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size);
- /* if first packet or resynchronization packet, we must
- handle it specifically */
- if (ffm->first_packet || (frame_offset & 0x8000)) {
- if (!frame_offset) {
- /* This packet has no frame headers in it */
- if (url_ftell(pb) >= ffm->packet_size * 3) {
- url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR);
- goto retry_read;
- }
- /* This is bad, we cannot find a valid frame header */
- return 0;
- }
- ffm->first_packet = 0;
- if ((frame_offset & 0x7ffff) < FFM_HEADER_SIZE)
- av_abort();
- ffm->packet_ptr = ffm->packet + (frame_offset & 0x7fff) - FFM_HEADER_SIZE;
- if (!first)
- break;
- } else {
- ffm->packet_ptr = ffm->packet;
- }
- goto redo;
- }
- memcpy(buf, ffm->packet_ptr, len);
- buf += len;
- ffm->packet_ptr += len;
- size -= len;
- first = 0;
- }
- return size1 - size;
-}
-
-
-static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- FFMContext *ffm = s->priv_data;
- AVStream *st;
- FFMStream *fst;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *codec;
- int i, nb_streams;
- uint32_t tag;
-
- /* header */
- tag = get_le32(pb);
- if (tag != MKTAG('F', 'F', 'M', '1'))
- goto fail;
- ffm->packet_size = get_be32(pb);
- if (ffm->packet_size != FFM_PACKET_SIZE)
- goto fail;
- ffm->write_index = get_be64(pb);
- /* get also filesize */
- if (!url_is_streamed(pb)) {
- ffm->file_size = url_filesize(url_fileno(pb));
- } else {
- ffm->file_size = (uint64_t_C(1) << 63) - 1;
- }
-
- nb_streams = get_be32(pb);
- get_be32(pb); /* total bitrate */
- /* read each stream */
- for(i=0;i<nb_streams;i++) {
- char rc_eq_buf[128];
-
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
- fst = av_mallocz(sizeof(FFMStream));
- if (!fst)
- goto fail;
- st->priv_data = fst;
-
- codec = &st->codec;
- /* generic info */
- st->codec.codec_id = get_be32(pb);
- st->codec.codec_type = get_byte(pb); /* codec_type */
- codec->bit_rate = get_be32(pb);
- st->quality = get_be32(pb);
- codec->flags = get_be32(pb);
- /* specific info */
- switch(codec->codec_type) {
- case CODEC_TYPE_VIDEO:
- codec->frame_rate_base = get_be32(pb);
- codec->frame_rate = get_be32(pb);
- codec->width = get_be16(pb);
- codec->height = get_be16(pb);
- codec->gop_size = get_be16(pb);
- codec->qmin = get_byte(pb);
- codec->qmax = get_byte(pb);
- codec->max_qdiff = get_byte(pb);
- codec->qcompress = get_be16(pb) / 10000.0;
- codec->qblur = get_be16(pb) / 10000.0;
- codec->bit_rate_tolerance = get_be32(pb);
- codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf)));
- codec->rc_max_rate = get_be32(pb);
- codec->rc_min_rate = get_be32(pb);
- codec->rc_buffer_size = get_be32(pb);
- codec->i_quant_factor = get_be64_double(pb);
- codec->b_quant_factor = get_be64_double(pb);
- codec->i_quant_offset = get_be64_double(pb);
- codec->b_quant_offset = get_be64_double(pb);
- codec->dct_algo = get_be32(pb);
- break;
- case CODEC_TYPE_AUDIO:
- codec->sample_rate = get_be32(pb);
- codec->channels = get_le16(pb);
- codec->frame_size = get_le16(pb);
- break;
- default:
- goto fail;
- }
-
- }
-
- /* get until end of block reached */
- while ((url_ftell(pb) % ffm->packet_size) != 0)
- get_byte(pb);
-
- /* init packet demux */
- ffm->packet_ptr = ffm->packet;
- ffm->packet_end = ffm->packet;
- ffm->frame_offset = 0;
- ffm->pts = 0;
- ffm->read_state = READ_HEADER;
- ffm->first_packet = 1;
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (st) {
- av_freep(&st->priv_data);
- av_free(st);
- }
- }
- return -1;
-}
-
-/* return < 0 if eof */
-static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int size;
- FFMContext *ffm = s->priv_data;
- int duration;
-
- switch(ffm->read_state) {
- case READ_HEADER:
- if (!ffm_is_avail_data(s, FRAME_HEADER_SIZE)) {
- return -EAGAIN;
- }
-#if 0
- printf("pos=%08Lx spos=%Lx, write_index=%Lx size=%Lx\n",
- url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size);
-#endif
- if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) !=
- FRAME_HEADER_SIZE)
- return -EAGAIN;
-#if 0
- {
- int i;
- for(i=0;i<FRAME_HEADER_SIZE;i++)
- printf("%02x ", ffm->header[i]);
- printf("\n");
- }
-#endif
- ffm->read_state = READ_DATA;
- /* fall thru */
- case READ_DATA:
- size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4];
- if (!ffm_is_avail_data(s, size)) {
- return -EAGAIN;
- }
-
- duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7];
-
- av_new_packet(pkt, size);
- pkt->stream_index = ffm->header[0];
- if (ffm->header[1] & FLAG_KEY_FRAME)
- pkt->flags |= PKT_FLAG_KEY;
-
- ffm->read_state = READ_HEADER;
- if (ffm_read_data(s, pkt->data, size, 0) != size) {
- /* bad case: desynchronized packet. we cancel all the packet loading */
- av_free_packet(pkt);
- return -EAGAIN;
- }
- pkt->pts = ffm->pts;
- pkt->duration = duration;
- break;
- }
- return 0;
-}
-
-//#define DEBUG_SEEK
-
-/* pos is between 0 and file_size - FFM_PACKET_SIZE. It is translated
- by the write position inside this function */
-static void ffm_seek1(AVFormatContext *s, offset_t pos1)
-{
- FFMContext *ffm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- offset_t pos;
-
- pos = pos1 + ffm->write_index;
- if (pos >= ffm->file_size)
- pos -= (ffm->file_size - FFM_PACKET_SIZE);
-#ifdef DEBUG_SEEK
- printf("seek to %Lx -> %Lx\n", pos1, pos);
-#endif
- url_fseek(pb, pos, SEEK_SET);
-}
-
-static int64_t get_pts(AVFormatContext *s, offset_t pos)
-{
- ByteIOContext *pb = &s->pb;
- int64_t pts;
-
- ffm_seek1(s, pos);
- url_fskip(pb, 4);
- pts = get_be64(pb);
-#ifdef DEBUG_SEEK
- printf("pts=%0.6f\n", pts / 1000000.0);
-#endif
- return pts;
-}
-
-/* seek to a given time in the file. The file read pointer is
- positionned at or before pts. XXX: the following code is quite
- approximative */
-static int ffm_seek(AVFormatContext *s, int64_t wanted_pts)
-{
- FFMContext *ffm = s->priv_data;
- offset_t pos_min, pos_max, pos;
- int64_t pts_min, pts_max, pts;
- double pos1;
-
-#ifdef DEBUG_SEEK
- printf("wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
-#endif
- /* find the position using linear interpolation (better than
- dichotomy in typical cases) */
- pos_min = 0;
- pos_max = ffm->file_size - 2 * FFM_PACKET_SIZE;
- while (pos_min <= pos_max) {
- pts_min = get_pts(s, pos_min);
- pts_max = get_pts(s, pos_max);
- /* linear interpolation */
- pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
- (double)(pts_max - pts_min);
- pos = (((int64_t)pos1) / FFM_PACKET_SIZE) * FFM_PACKET_SIZE;
- if (pos <= pos_min)
- pos = pos_min;
- else if (pos >= pos_max)
- pos = pos_max;
- pts = get_pts(s, pos);
- /* check if we are lucky */
- if (pts == wanted_pts) {
- goto found;
- } else if (pts > wanted_pts) {
- pos_max = pos - FFM_PACKET_SIZE;
- } else {
- pos_min = pos + FFM_PACKET_SIZE;
- }
- }
- pos = pos_min;
- if (pos > 0)
- pos -= FFM_PACKET_SIZE;
- found:
- ffm_seek1(s, pos);
- return 0;
-}
-
-offset_t ffm_read_write_index(int fd)
-{
- uint8_t buf[8];
- offset_t pos;
- int i;
-
- lseek(fd, 8, SEEK_SET);
- read(fd, buf, 8);
- pos = 0;
- for(i=0;i<8;i++)
- pos |= (int64_t)buf[i] << (56 - i * 8);
- return pos;
-}
-
-void ffm_write_write_index(int fd, offset_t pos)
-{
- uint8_t buf[8];
- int i;
-
- for(i=0;i<8;i++)
- buf[i] = (pos >> (56 - i * 8)) & 0xff;
- lseek(fd, 8, SEEK_SET);
- write(fd, buf, 8);
-}
-
-void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size)
-{
- FFMContext *ffm = s->priv_data;
- ffm->write_index = pos;
- ffm->file_size = file_size;
-}
-
-static int ffm_read_close(AVFormatContext *s)
-{
- AVStream *st;
- int i;
-
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- av_freep(&st->priv_data);
- }
- return 0;
-}
-
-static int ffm_probe(AVProbeData *p)
-{
- if (p->buf_size >= 4 &&
- p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' &&
- p->buf[3] == '1')
- return AVPROBE_SCORE_MAX + 1;
- return 0;
-}
-
-static AVInputFormat ffm_iformat = {
- "ffm",
- "ffm format",
- sizeof(FFMContext),
- ffm_probe,
- ffm_read_header,
- ffm_read_packet,
- ffm_read_close,
- ffm_seek,
-};
-
-static AVOutputFormat ffm_oformat = {
- "ffm",
- "ffm format",
- "",
- "ffm",
- sizeof(FFMContext),
- /* not really used */
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- ffm_write_header,
- ffm_write_packet,
- ffm_write_trailer,
-};
-
-int ffm_init(void)
-{
- av_register_input_format(&ffm_iformat);
- av_register_output_format(&ffm_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Buffered file io for ffmpeg system
- * Copyright (c) 2001 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <fcntl.h>
-#ifndef CONFIG_WIN32
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#else
-#include <io.h>
-#define open(fname,oflag,pmode) _open(fname,oflag,pmode)
-#endif /* CONFIG_WIN32 */
-
-
-/* standard file protocol */
-
-static int file_open(URLContext *h, const char *filename, int flags)
-{
- int access;
- int fd;
-
- strstart(filename, "file:", &filename);
-
- if (flags & URL_WRONLY) {
- access = O_CREAT | O_TRUNC | O_WRONLY;
- } else {
- access = O_RDONLY;
- }
-#if defined(CONFIG_WIN32) || defined(CONFIG_OS2)
- access |= O_BINARY;
-#endif
- fd = open(filename, access, 0666);
- if (fd < 0)
- return -ENOENT;
- h->priv_data = (void *)fd;
- return 0;
-}
-
-static int file_read(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return read(fd, buf, size);
-}
-
-static int file_write(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return write(fd, buf, size);
-}
-
-/* XXX: use llseek */
-static offset_t file_seek(URLContext *h, offset_t pos, int whence)
-{
- int fd = (int)h->priv_data;
-#ifdef CONFIG_WIN32
- return _lseeki64(fd, pos, whence);
-#else
- return lseek(fd, pos, whence);
-#endif
-}
-
-static int file_close(URLContext *h)
-{
- int fd = (int)h->priv_data;
- return close(fd);
-}
-
-URLProtocol file_protocol = {
- "file",
- file_open,
- file_read,
- file_write,
- file_seek,
- file_close,
-};
-
-/* pipe protocol */
-
-static int pipe_open(URLContext *h, const char *filename, int flags)
-{
- int fd;
-
- if (flags & URL_WRONLY) {
- fd = 1;
- } else {
- fd = 0;
- }
- h->priv_data = (void *)fd;
- return 0;
-}
-
-static int pipe_read(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return read(fd, buf, size);
-}
-
-static int pipe_write(URLContext *h, unsigned char *buf, int size)
-{
- int fd = (int)h->priv_data;
- return write(fd, buf, size);
-}
-
-static int pipe_close(URLContext *h)
-{
- return 0;
-}
-
-URLProtocol pipe_protocol = {
- "pipe",
- pipe_open,
- pipe_read,
- pipe_write,
- NULL,
- pipe_close,
-};
+++ /dev/null
-/*
- * FLV encoder.
- * Copyright (c) 2003 The FFmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-unsigned int get_be24(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 16;
- val |= get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-static int flv_probe(AVProbeData *p)
-{
- const uint8_t *d;
-
- if (p->buf_size < 6)
- return 0;
- d = p->buf;
- if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V') {
- return 50;
- }
- return 0;
-}
-
-static int flv_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- int offset, flags;
- AVStream *st;
-
- av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-
- url_fskip(&s->pb, 4);
- flags = get_byte(&s->pb);
-
- if ((flags & 1)) {
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_FLV1;
- }
-
- if ((flags & 4)) {
- st = av_new_stream(s, 1);
- if (!st)
- return AVERROR_NOMEM;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_MP3;
- }
-
- offset = get_be32(&s->pb);
- url_fseek(&s->pb, offset, SEEK_SET);
-
- return 0;
-}
-
-static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret, i, type, size, pts, flags;
- AVStream *st;
-
- redo:
- url_fskip(&s->pb, 4); /* size of previous packet */
- type = get_byte(&s->pb);
- size = get_be24(&s->pb);
- pts = get_be24(&s->pb);
- if (url_feof(&s->pb))
- return -EIO;
- url_fskip(&s->pb, 4); /* reserved */
- flags = 0;
- if (type == 8) {
- flags = get_byte(&s->pb);
- size--;
- if ((flags >> 4) != 2) { /* 0: uncompressed 1: ADPCM 2: mp3 5: Nellymoser 8kHz mono 6: Nellymoser*/
- goto skip;
- }
- } else if (type == 9) {
- flags = get_byte(&s->pb);
- size--;
- if ((flags & 0xF) != 2) { /* 2: only format */
- goto skip;
- }
- } else {
- skip:
- /* skip packet */
- printf("skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
- url_fskip(&s->pb, size);
- goto redo;
- }
-
- /* now find stream */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (st->id == ((type == 9) ? 0 : 1))
- goto found;
- }
- goto skip;
- found:
-
- if (av_new_packet(pkt, size) < 0)
- return -EIO;
-
- ret = get_buffer(&s->pb, pkt->data, size);
- if (ret <= 0) {
- av_free_packet(pkt);
- return -EIO;
- }
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- pkt->pts = pts;
- pkt->stream_index = st->index;
- return ret;
-}
-
-static int flv_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-AVInputFormat flv_iformat = {
- "flv",
- "flv format",
- 0,
- flv_probe,
- flv_read_header,
- flv_read_packet,
- flv_read_close,
- .extensions = "flv",
- .value = CODEC_ID_FLV1,
-};
-
-int flvdec_init(void)
-{
- av_register_input_format(&flv_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * FLV encoder.
- * Copyright (c) 2003 The FFmpeg Project.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#define VIDEO_FIFO_SIZE 512
-
-typedef struct FLVFrame {
- int type;
- int timestamp;
- int flags;
- uint8_t *data;
- int size;
- struct FLVFrame *next;
-} FLVFrame;
-
-typedef struct FLVContext {
- int hasAudio;
- int hasVideo;
-#ifdef CONFIG_MP3LAME
- int audioTime;
- int audioInPos;
- int audioOutPos;
- int audioSize;
- int audioRate;
- int initDelay;
- int soundDelay;
- uint8_t *audioFifo;
- int64_t sampleCount;
-#endif // CONFIG_MP3LAME
- int64_t frameCount;
- FLVFrame *frames;
-} FLVContext;
-
-
-#ifdef CONFIG_MP3LAME
-
-#define AUDIO_FIFO_SIZE 65536
-
-static const int sSampleRates[3][4] = {
- {44100, 48000, 32000, 0},
- {22050, 24000, 16000, 0},
- {11025, 12000, 8000, 0},
-};
-
-static const int sBitRates[2][3][15] = {
- { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448},
- { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384},
- { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320}
- },
- { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256},
- { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160},
- { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}
- },
-};
-
-static const int sSamplesPerFrame[3][3] =
-{
- { 384, 1152, 1152 },
- { 384, 1152, 576 },
- { 384, 1152, 576 }
-};
-
-static const int sBitsPerSlot[3] = {
- 32,
- 8,
- 8
-};
-
-static int mp3info(void *data, int *byteSize, int *samplesPerFrame, int *sampleRate, int *isMono )
-{
- uint8_t *dataTmp = (uint8_t *)data;
- uint32_t header = ( (uint32_t)dataTmp[0] << 24 ) | ( (uint32_t)dataTmp[1] << 16 ) | ( (uint32_t)dataTmp[2] << 8 ) | (uint32_t)dataTmp[3];
- int layerID = 3 - ((header >> 17) & 0x03);
- int bitRateID = ((header >> 12) & 0x0f);
- int sampleRateID = ((header >> 10) & 0x03);
- int bitRate = 0;
- int bitsPerSlot = sBitsPerSlot[layerID];
- int isPadded = ((header >> 9) & 0x01);
-
- if ( (( header >> 21 ) & 0x7ff) != 0x7ff ) {
- return 0;
- }
-
- if ( !isPadded ) {
- printf("Fatal error: mp3 data is not padded!\n");
- exit(0);
- }
-
- *isMono = ((header >> 6) & 0x03) == 0x03;
-
- if ( (header >> 19 ) & 0x01 ) {
- *sampleRate = sSampleRates[0][sampleRateID];
- bitRate = sBitRates[0][layerID][bitRateID] * 1000;
- *samplesPerFrame = sSamplesPerFrame[0][layerID];
-
- } else {
- if ( (header >> 20) & 0x01 ) {
- *sampleRate = sSampleRates[1][sampleRateID];
- bitRate = sBitRates[1][layerID][bitRateID] * 1000;
- *samplesPerFrame = sSamplesPerFrame[1][layerID];
- } else {
- *sampleRate = sSampleRates[2][sampleRateID];
- bitRate = sBitRates[1][layerID][bitRateID] * 1000;
- *samplesPerFrame = sSamplesPerFrame[2][layerID];
- }
- }
-
- *byteSize = ( ( ( ( *samplesPerFrame * (bitRate / bitsPerSlot) ) / *sampleRate ) + isPadded ) * bitsPerSlot);
-
- return 1;
-}
-#endif // CONFIG_MP3LAME
-
-static int flv_write_header(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- FLVContext *flv = s->priv_data;
-
- av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-
- flv->hasAudio = 0;
- flv->hasVideo = 0;
-
-#ifdef CONFIG_MP3LAME
- flv->audioTime = -1;
- flv->audioFifo = av_malloc(AUDIO_FIFO_SIZE);
- flv->audioInPos = 0;
- flv->audioOutPos = 0;
- flv->audioSize = 0;
- flv->audioRate = 44100;
- flv->initDelay = -1;
- flv->soundDelay = 0;
-#endif // CONFIG_MP3LAME
-
- flv->frames = 0;
-
- put_tag(pb,"FLV");
- put_byte(pb,1);
- put_byte(pb,0); // delayed write
- put_be32(pb,9);
- put_be32(pb,0);
-
- return 0;
-}
-
-static void put_be24(ByteIOContext *pb, int value)
-{
- put_byte(pb, (value>>16) & 0xFF );
- put_byte(pb, (value>> 8) & 0xFF );
- put_byte(pb, (value>> 0) & 0xFF );
-}
-
-static void InsertSorted(FLVContext *flv, FLVFrame *frame)
-{
- if ( !flv->frames ) {
- flv->frames = frame;
- } else {
- FLVFrame *trav = flv->frames;
- FLVFrame *prev = 0;
- for (;trav;) {
- if ( trav->timestamp >= frame->timestamp ) {
- frame->next = trav;
- if ( prev ) {
- prev->next = frame;
- } else {
- flv->frames = frame;
- }
- break;
- }
- prev = trav;
- trav = trav->next;
- }
- if ( !trav ) {
- prev->next = frame;
- }
- }
-}
-
-static void DumpFrame(ByteIOContext *pb, FLVFrame *frame)
-{
- put_byte(pb,frame->type); // message type
- put_be24(pb,frame->size+1); // include flags
- put_be24(pb,frame->timestamp); // time stamp
- put_be32(pb,0); // reserved
- put_byte(pb,frame->flags);
- put_buffer(pb, frame->data, frame->size);
- put_be32(pb,frame->size+1+11); // reserved
- av_free(frame->data);
-}
-
-static void Dump(FLVContext *flv, ByteIOContext *pb, int count)
-{
- int c=0;
- FLVFrame *trav = flv->frames;
- FLVFrame *prev = 0;
- for (;trav;c++) {
- trav = trav->next;
- }
- trav = flv->frames;
- for ( ; c >= count; c-- ) {
- DumpFrame(pb,trav);
- prev = trav;
- trav = trav->next;
- av_free(prev);
- }
- flv->frames = trav;
-}
-
-static int flv_write_trailer(AVFormatContext *s)
-{
- int64_t file_size;
- int flags = 0;
-
- ByteIOContext *pb = &s->pb;
- FLVContext *flv = s->priv_data;
-
- Dump(flv,pb,1);
-
- file_size = url_ftell(pb);
- flags |= flv->hasAudio ? 4 : 0;
- flags |= flv->hasVideo ? 1 : 0;
- url_fseek(pb, 4, SEEK_SET);
- put_byte(pb,flags);
- url_fseek(pb, file_size, SEEK_SET);
- return 0;
-}
-
-static int flv_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t timestamp)
-{
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc = &s->streams[stream_index]->codec;
- FLVContext *flv = s->priv_data;
-
- if (enc->codec_type == CODEC_TYPE_VIDEO) {
- FLVFrame *frame = av_malloc(sizeof(FLVFrame));
- frame->next = 0;
- frame->type = 9;
- frame->flags = 2; // choose h263
- frame->flags |= enc->coded_frame->key_frame ? 0x10 : 0x20; // add keyframe indicator
- frame->timestamp = timestamp;
- //frame->timestamp = ( ( flv->frameCount * (int64_t)FRAME_RATE_BASE * (int64_t)1000 ) / (int64_t)enc->frame_rate );
- //printf("%08x %f %f\n",frame->timestamp,(double)enc->frame_rate/(double)FRAME_RATE_BASE,1000*(double)FRAME_RATE_BASE/(double)enc->frame_rate);
- frame->size = size;
- frame->data = av_malloc(size);
- memcpy(frame->data,buf,size);
- flv->hasVideo = 1;
-
- InsertSorted(flv,frame);
-
- flv->frameCount ++;
- }
- else if (enc->codec_type == CODEC_TYPE_AUDIO) {
-#ifdef CONFIG_MP3LAME
- if (enc->codec_id == CODEC_ID_MP3 ) {
- int c=0;
- for (;c<size;c++) {
- flv->audioFifo[(flv->audioOutPos+c)%AUDIO_FIFO_SIZE] = buf[c];
- }
- flv->audioSize += size;
- flv->audioOutPos += size;
- flv->audioOutPos %= AUDIO_FIFO_SIZE;
-
- if ( flv->initDelay == -1 ) {
- flv->initDelay = timestamp;
- }
-
- if ( flv->audioTime == -1 ) {
- flv->audioTime = timestamp;
-// flv->audioTime = ( ( ( flv->sampleCount - enc->delay ) * 8000 ) / flv->audioRate ) - flv->initDelay - 250;
-// if ( flv->audioTime < 0 ) {
-// flv->audioTime = 0;
-// }
- }
- }
- for ( ; flv->audioSize >= 4 ; ) {
-
- int mp3FrameSize = 0;
- int mp3SampleRate = 0;
- int mp3IsMono = 0;
- int mp3SamplesPerFrame = 0;
-
- if ( mp3info(&flv->audioFifo[flv->audioInPos],&mp3FrameSize,&mp3SamplesPerFrame,&mp3SampleRate,&mp3IsMono) ) {
- if ( flv->audioSize >= mp3FrameSize ) {
-
- int soundFormat = 0x22;
- int c=0;
- FLVFrame *frame = av_malloc(sizeof(FLVFrame));
-
- flv->audioRate = mp3SampleRate;
-
- switch (mp3SampleRate) {
- case 44100:
- soundFormat |= 0x0C;
- break;
- case 22050:
- soundFormat |= 0x08;
- break;
- case 11025:
- soundFormat |= 0x04;
- break;
- }
-
- if ( !mp3IsMono ) {
- soundFormat |= 0x01;
- }
-
- frame->next = 0;
- frame->type = 8;
- frame->flags = soundFormat;
- frame->timestamp = flv->audioTime;
- frame->size = mp3FrameSize;
- frame->data = av_malloc(mp3FrameSize);
-
- for (;c<mp3FrameSize;c++) {
- frame->data[c] = flv->audioFifo[(flv->audioInPos+c)%AUDIO_FIFO_SIZE];
- }
-
- flv->audioInPos += mp3FrameSize;
- flv->audioSize -= mp3FrameSize;
- flv->audioInPos %= AUDIO_FIFO_SIZE;
- flv->sampleCount += mp3SamplesPerFrame;
-
- // Reset audio for next round
- flv->audioTime = -1;
- // We got audio! Make sure we set this to the global flags on closure
- flv->hasAudio = 1;
-
- InsertSorted(flv,frame);
- }
- break;
- }
- flv->audioInPos ++;
- flv->audioSize --;
- flv->audioInPos %= AUDIO_FIFO_SIZE;
- // no audio in here!
- flv->audioTime = -1;
- }
-#endif
- }
- Dump(flv,pb,128);
- put_flush_packet(pb);
- return 0;
-}
-
-static AVOutputFormat flv_oformat = {
- "flv",
- "flv format",
- "video/x-flashvideo",
- "flv",
- sizeof(FLVContext),
-#ifdef CONFIG_MP3LAME
- CODEC_ID_MP3,
-#else // CONFIG_MP3LAME
- CODEC_ID_NONE,
-#endif // CONFIG_MP3LAME
- CODEC_ID_FLV1,
- flv_write_header,
- flv_write_packet,
- flv_write_trailer,
-};
-
-int flvenc_init(void)
-{
- av_register_output_format(&flv_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Video processing hooks
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <errno.h>
-#include "config.h"
-#include "framehook.h"
-#include "avformat.h"
-
-#ifdef CONFIG_HAVE_DLFCN
-#include <dlfcn.h>
-#endif
-
-
-typedef struct _FrameHookEntry {
- struct _FrameHookEntry *next;
- FrameHookConfigureFn Configure;
- FrameHookProcessFn Process;
- FrameHookReleaseFn Release;
- void *ctx;
-} FrameHookEntry;
-
-static FrameHookEntry *first_hook;
-
-/* Returns 0 on OK */
-int frame_hook_add(int argc, char *argv[])
-{
-#ifdef HAVE_VHOOK
- void *loaded;
- FrameHookEntry *fhe, **fhep;
-
- if (argc < 1) {
- return ENOENT;
- }
-
- loaded = dlopen(argv[0], RTLD_NOW);
- if (!loaded) {
- fprintf(stderr, "%s\n", dlerror());
- return -1;
- }
-
- fhe = av_mallocz(sizeof(*fhe));
- if (!fhe) {
- return errno;
- }
-
- fhe->Configure = dlsym(loaded, "Configure");
- fhe->Process = dlsym(loaded, "Process");
- fhe->Release = dlsym(loaded, "Release"); /* Optional */
-
- if (!fhe->Process) {
- fprintf(stderr, "Failed to find Process entrypoint in %s\n", argv[0]);
- return -1;
- }
-
- if (!fhe->Configure && argc > 1) {
- fprintf(stderr, "Failed to find Configure entrypoint in %s\n", argv[0]);
- return -1;
- }
-
- if (argc > 1 || fhe->Configure) {
- if (fhe->Configure(&fhe->ctx, argc, argv)) {
- fprintf(stderr, "Failed to Configure %s\n", argv[0]);
- return -1;
- }
- }
-
- for (fhep = &first_hook; *fhep; fhep = &((*fhep)->next)) {
- }
-
- *fhep = fhe;
-
- return 0;
-#else
- fprintf(stderr, "Video hooking not compiled into this version\n");
- return 1;
-#endif
-}
-
-void frame_hook_process(AVPicture *pict, enum PixelFormat pix_fmt, int width, int height)
-{
- if (first_hook) {
- FrameHookEntry *fhe;
- int64_t pts = av_gettime();
-
- for (fhe = first_hook; fhe; fhe = fhe->next) {
- fhe->Process(fhe->ctx, pict, pix_fmt, width, height, pts);
- }
- }
-}
-
-void frame_hook_release(void)
-{
- FrameHookEntry *fhe;
- FrameHookEntry *fhenext;
-
- for (fhe = first_hook; fhe; fhe = fhenext) {
- fhenext = fhe->next;
- if (fhe->Release)
- fhe->Release(fhe->ctx);
- av_free(fhe);
- }
-
- first_hook = NULL;
-}
+++ /dev/null
-#ifndef _FRAMEHOOK_H
-#define _FRAMEHOOK_H
-
-/*
- * Prototypes for interface to .so that implement a video processing hook
- */
-
-#include "avcodec.h"
-
-/* Function must be called 'Configure' */
-typedef int (FrameHookConfigure)(void **ctxp, int argc, char *argv[]);
-typedef FrameHookConfigure *FrameHookConfigureFn;
-extern FrameHookConfigure Configure;
-
-/* Function must be called 'Process' */
-typedef void (FrameHookProcess)(void *ctx, struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts);
-typedef FrameHookProcess *FrameHookProcessFn;
-extern FrameHookProcess Process;
-
-/* Function must be called 'Release' */
-typedef void (FrameHookRelease)(void *ctx);
-typedef FrameHookRelease *FrameHookReleaseFn;
-extern FrameHookRelease Release;
-
-extern int frame_hook_add(int argc, char *argv[]);
-extern void frame_hook_process(struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height);
-extern void frame_hook_release();
-
-#endif
+++ /dev/null
-/*
- * Animated GIF encoder
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Features and limitations:
- * - currently no compression is performed,
- * in fact the size of the data is 9/8 the size of the image in 8bpp
- * - uses only a global standard palette
- * - tested with IE 5.0, Opera for BeOS, NetPositive (BeOS), and Mozilla (BeOS).
- *
- * Reference documents:
- * http://www.goice.co.jp/member/mo/formats/gif.html
- * http://astronomy.swin.edu.au/pbourke/dataformats/gif/
- * http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/GIF89a.txt
- *
- * this url claims to have an LZW algorithm not covered by Unisys patent:
- * http://www.msg.net/utility/whirlgif/gifencod.html
- * could help reduce the size of the files _a lot_...
- * some sites mentions an RLE type compression also.
- */
-
-#include "avformat.h"
-
-/* bitstream minipacket size */
-#define GIF_CHUNKS 100
-
-/* slows down the decoding (and some browsers doesn't like it) */
-/* #define GIF_ADD_APP_HEADER */
-
-typedef struct {
- unsigned char r;
- unsigned char g;
- unsigned char b;
-} rgb_triplet;
-
-/* we use the standard 216 color palette */
-
-/* this script was used to create the palette:
- * for r in 00 33 66 99 cc ff; do for g in 00 33 66 99 cc ff; do echo -n " "; for b in 00 33 66 99 cc ff; do
- * echo -n "{ 0x$r, 0x$g, 0x$b }, "; done; echo ""; done; done
- */
-
-static const rgb_triplet gif_clut[216] = {
- { 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x33 }, { 0x00, 0x00, 0x66 }, { 0x00, 0x00, 0x99 }, { 0x00, 0x00, 0xcc }, { 0x00, 0x00, 0xff },
- { 0x00, 0x33, 0x00 }, { 0x00, 0x33, 0x33 }, { 0x00, 0x33, 0x66 }, { 0x00, 0x33, 0x99 }, { 0x00, 0x33, 0xcc }, { 0x00, 0x33, 0xff },
- { 0x00, 0x66, 0x00 }, { 0x00, 0x66, 0x33 }, { 0x00, 0x66, 0x66 }, { 0x00, 0x66, 0x99 }, { 0x00, 0x66, 0xcc }, { 0x00, 0x66, 0xff },
- { 0x00, 0x99, 0x00 }, { 0x00, 0x99, 0x33 }, { 0x00, 0x99, 0x66 }, { 0x00, 0x99, 0x99 }, { 0x00, 0x99, 0xcc }, { 0x00, 0x99, 0xff },
- { 0x00, 0xcc, 0x00 }, { 0x00, 0xcc, 0x33 }, { 0x00, 0xcc, 0x66 }, { 0x00, 0xcc, 0x99 }, { 0x00, 0xcc, 0xcc }, { 0x00, 0xcc, 0xff },
- { 0x00, 0xff, 0x00 }, { 0x00, 0xff, 0x33 }, { 0x00, 0xff, 0x66 }, { 0x00, 0xff, 0x99 }, { 0x00, 0xff, 0xcc }, { 0x00, 0xff, 0xff },
- { 0x33, 0x00, 0x00 }, { 0x33, 0x00, 0x33 }, { 0x33, 0x00, 0x66 }, { 0x33, 0x00, 0x99 }, { 0x33, 0x00, 0xcc }, { 0x33, 0x00, 0xff },
- { 0x33, 0x33, 0x00 }, { 0x33, 0x33, 0x33 }, { 0x33, 0x33, 0x66 }, { 0x33, 0x33, 0x99 }, { 0x33, 0x33, 0xcc }, { 0x33, 0x33, 0xff },
- { 0x33, 0x66, 0x00 }, { 0x33, 0x66, 0x33 }, { 0x33, 0x66, 0x66 }, { 0x33, 0x66, 0x99 }, { 0x33, 0x66, 0xcc }, { 0x33, 0x66, 0xff },
- { 0x33, 0x99, 0x00 }, { 0x33, 0x99, 0x33 }, { 0x33, 0x99, 0x66 }, { 0x33, 0x99, 0x99 }, { 0x33, 0x99, 0xcc }, { 0x33, 0x99, 0xff },
- { 0x33, 0xcc, 0x00 }, { 0x33, 0xcc, 0x33 }, { 0x33, 0xcc, 0x66 }, { 0x33, 0xcc, 0x99 }, { 0x33, 0xcc, 0xcc }, { 0x33, 0xcc, 0xff },
- { 0x33, 0xff, 0x00 }, { 0x33, 0xff, 0x33 }, { 0x33, 0xff, 0x66 }, { 0x33, 0xff, 0x99 }, { 0x33, 0xff, 0xcc }, { 0x33, 0xff, 0xff },
- { 0x66, 0x00, 0x00 }, { 0x66, 0x00, 0x33 }, { 0x66, 0x00, 0x66 }, { 0x66, 0x00, 0x99 }, { 0x66, 0x00, 0xcc }, { 0x66, 0x00, 0xff },
- { 0x66, 0x33, 0x00 }, { 0x66, 0x33, 0x33 }, { 0x66, 0x33, 0x66 }, { 0x66, 0x33, 0x99 }, { 0x66, 0x33, 0xcc }, { 0x66, 0x33, 0xff },
- { 0x66, 0x66, 0x00 }, { 0x66, 0x66, 0x33 }, { 0x66, 0x66, 0x66 }, { 0x66, 0x66, 0x99 }, { 0x66, 0x66, 0xcc }, { 0x66, 0x66, 0xff },
- { 0x66, 0x99, 0x00 }, { 0x66, 0x99, 0x33 }, { 0x66, 0x99, 0x66 }, { 0x66, 0x99, 0x99 }, { 0x66, 0x99, 0xcc }, { 0x66, 0x99, 0xff },
- { 0x66, 0xcc, 0x00 }, { 0x66, 0xcc, 0x33 }, { 0x66, 0xcc, 0x66 }, { 0x66, 0xcc, 0x99 }, { 0x66, 0xcc, 0xcc }, { 0x66, 0xcc, 0xff },
- { 0x66, 0xff, 0x00 }, { 0x66, 0xff, 0x33 }, { 0x66, 0xff, 0x66 }, { 0x66, 0xff, 0x99 }, { 0x66, 0xff, 0xcc }, { 0x66, 0xff, 0xff },
- { 0x99, 0x00, 0x00 }, { 0x99, 0x00, 0x33 }, { 0x99, 0x00, 0x66 }, { 0x99, 0x00, 0x99 }, { 0x99, 0x00, 0xcc }, { 0x99, 0x00, 0xff },
- { 0x99, 0x33, 0x00 }, { 0x99, 0x33, 0x33 }, { 0x99, 0x33, 0x66 }, { 0x99, 0x33, 0x99 }, { 0x99, 0x33, 0xcc }, { 0x99, 0x33, 0xff },
- { 0x99, 0x66, 0x00 }, { 0x99, 0x66, 0x33 }, { 0x99, 0x66, 0x66 }, { 0x99, 0x66, 0x99 }, { 0x99, 0x66, 0xcc }, { 0x99, 0x66, 0xff },
- { 0x99, 0x99, 0x00 }, { 0x99, 0x99, 0x33 }, { 0x99, 0x99, 0x66 }, { 0x99, 0x99, 0x99 }, { 0x99, 0x99, 0xcc }, { 0x99, 0x99, 0xff },
- { 0x99, 0xcc, 0x00 }, { 0x99, 0xcc, 0x33 }, { 0x99, 0xcc, 0x66 }, { 0x99, 0xcc, 0x99 }, { 0x99, 0xcc, 0xcc }, { 0x99, 0xcc, 0xff },
- { 0x99, 0xff, 0x00 }, { 0x99, 0xff, 0x33 }, { 0x99, 0xff, 0x66 }, { 0x99, 0xff, 0x99 }, { 0x99, 0xff, 0xcc }, { 0x99, 0xff, 0xff },
- { 0xcc, 0x00, 0x00 }, { 0xcc, 0x00, 0x33 }, { 0xcc, 0x00, 0x66 }, { 0xcc, 0x00, 0x99 }, { 0xcc, 0x00, 0xcc }, { 0xcc, 0x00, 0xff },
- { 0xcc, 0x33, 0x00 }, { 0xcc, 0x33, 0x33 }, { 0xcc, 0x33, 0x66 }, { 0xcc, 0x33, 0x99 }, { 0xcc, 0x33, 0xcc }, { 0xcc, 0x33, 0xff },
- { 0xcc, 0x66, 0x00 }, { 0xcc, 0x66, 0x33 }, { 0xcc, 0x66, 0x66 }, { 0xcc, 0x66, 0x99 }, { 0xcc, 0x66, 0xcc }, { 0xcc, 0x66, 0xff },
- { 0xcc, 0x99, 0x00 }, { 0xcc, 0x99, 0x33 }, { 0xcc, 0x99, 0x66 }, { 0xcc, 0x99, 0x99 }, { 0xcc, 0x99, 0xcc }, { 0xcc, 0x99, 0xff },
- { 0xcc, 0xcc, 0x00 }, { 0xcc, 0xcc, 0x33 }, { 0xcc, 0xcc, 0x66 }, { 0xcc, 0xcc, 0x99 }, { 0xcc, 0xcc, 0xcc }, { 0xcc, 0xcc, 0xff },
- { 0xcc, 0xff, 0x00 }, { 0xcc, 0xff, 0x33 }, { 0xcc, 0xff, 0x66 }, { 0xcc, 0xff, 0x99 }, { 0xcc, 0xff, 0xcc }, { 0xcc, 0xff, 0xff },
- { 0xff, 0x00, 0x00 }, { 0xff, 0x00, 0x33 }, { 0xff, 0x00, 0x66 }, { 0xff, 0x00, 0x99 }, { 0xff, 0x00, 0xcc }, { 0xff, 0x00, 0xff },
- { 0xff, 0x33, 0x00 }, { 0xff, 0x33, 0x33 }, { 0xff, 0x33, 0x66 }, { 0xff, 0x33, 0x99 }, { 0xff, 0x33, 0xcc }, { 0xff, 0x33, 0xff },
- { 0xff, 0x66, 0x00 }, { 0xff, 0x66, 0x33 }, { 0xff, 0x66, 0x66 }, { 0xff, 0x66, 0x99 }, { 0xff, 0x66, 0xcc }, { 0xff, 0x66, 0xff },
- { 0xff, 0x99, 0x00 }, { 0xff, 0x99, 0x33 }, { 0xff, 0x99, 0x66 }, { 0xff, 0x99, 0x99 }, { 0xff, 0x99, 0xcc }, { 0xff, 0x99, 0xff },
- { 0xff, 0xcc, 0x00 }, { 0xff, 0xcc, 0x33 }, { 0xff, 0xcc, 0x66 }, { 0xff, 0xcc, 0x99 }, { 0xff, 0xcc, 0xcc }, { 0xff, 0xcc, 0xff },
- { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
-};
-
-/* The GIF format uses reversed order for bitstreams... */
-/* at least they don't use PDP_ENDIAN :) */
-/* so we 'extend' PutBitContext. hmmm, OOP :) */
-/* seems this thing changed slightly since I wrote it... */
-
-#ifdef ALT_BITSTREAM_WRITER
-# error no ALT_BITSTREAM_WRITER support for now
-#endif
-
-static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value)
-{
- unsigned int bit_buf;
- int bit_cnt;
-
-#ifdef STATS
- st_out_bit_counts[st_current_index] += n;
-#endif
- // printf("put_bits=%d %x\n", n, value);
- assert(n == 32 || value < (1U << n));
-
- bit_buf = s->bit_buf;
- bit_cnt = 32 - s->bit_left; /* XXX:lazyness... was = s->bit_cnt; */
-
- // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
- /* XXX: optimize */
- if (n < (32-bit_cnt)) {
- bit_buf |= value << (bit_cnt);
- bit_cnt+=n;
- } else {
- bit_buf |= value << (bit_cnt);
-
- *s->buf_ptr = bit_buf & 0xff;
- s->buf_ptr[1] = (bit_buf >> 8) & 0xff;
- s->buf_ptr[2] = (bit_buf >> 16) & 0xff;
- s->buf_ptr[3] = (bit_buf >> 24) & 0xff;
-
- //printf("bitbuf = %08x\n", bit_buf);
- s->buf_ptr+=4;
- if (s->buf_ptr >= s->buf_end)
- puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ???
-// flush_buffer_rev(s);
- bit_cnt=bit_cnt + n - 32;
- if (bit_cnt == 0) {
- bit_buf = 0;
- } else {
- bit_buf = value >> (n - bit_cnt);
- }
- }
-
- s->bit_buf = bit_buf;
- s->bit_left = 32 - bit_cnt;
-}
-
-/* pad the end of the output stream with zeros */
-static void gif_flush_put_bits_rev(PutBitContext *s)
-{
- while (s->bit_left < 32) {
- /* XXX: should test end of buffer */
- *s->buf_ptr++=s->bit_buf & 0xff;
- s->bit_buf>>=8;
- s->bit_left+=8;
- }
-// flush_buffer_rev(s);
- s->bit_left=32;
- s->bit_buf=0;
-}
-
-/* !RevPutBitContext */
-
-/* GIF header */
-static int gif_image_write_header(ByteIOContext *pb,
- int width, int height, uint32_t *palette)
-{
- int i;
- unsigned int v;
-
- put_tag(pb, "GIF");
- put_tag(pb, "89a");
- put_le16(pb, width);
- put_le16(pb, height);
-
- put_byte(pb, 0xf7); /* flags: global clut, 256 entries */
- put_byte(pb, 0x1f); /* background color index */
- put_byte(pb, 0); /* aspect ratio */
-
- /* the global palette */
- if (!palette) {
- put_buffer(pb, (unsigned char *)gif_clut, 216*3);
- for(i=0;i<((256-216)*3);i++)
- put_byte(pb, 0);
- } else {
- for(i=0;i<256;i++) {
- v = palette[i];
- put_byte(pb, (v >> 16) & 0xff);
- put_byte(pb, (v >> 8) & 0xff);
- put_byte(pb, (v) & 0xff);
- }
- }
-
- /* application extension header */
- /* XXX: not really sure what to put in here... */
-#ifdef GIF_ADD_APP_HEADER
- put_byte(pb, 0x21);
- put_byte(pb, 0xff);
- put_byte(pb, 0x0b);
- put_tag(pb, "NETSCAPE2.0");
- put_byte(pb, 0x03);
- put_byte(pb, 0x01);
- put_byte(pb, 0x00);
- put_byte(pb, 0x00);
-#endif
- return 0;
-}
-
-/* this is maybe slow, but allows for extensions */
-static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
-{
- return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
-}
-
-
-static int gif_image_write_image(ByteIOContext *pb,
- int x1, int y1, int width, int height,
- const uint8_t *buf, int linesize, int pix_fmt)
-{
- PutBitContext p;
- uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */
- int i, left, w, v;
- const uint8_t *ptr;
- /* image block */
-
- put_byte(pb, 0x2c);
- put_le16(pb, x1);
- put_le16(pb, y1);
- put_le16(pb, width);
- put_le16(pb, height);
- put_byte(pb, 0x00); /* flags */
- /* no local clut */
-
- put_byte(pb, 0x08);
-
- left= width * height;
-
- init_put_bits(&p, buffer, 130, NULL, NULL);
-
-/*
- * the thing here is the bitstream is written as little packets, with a size byte before
- * but it's still the same bitstream between packets (no flush !)
- */
- ptr = buf;
- w = width;
- while(left>0) {
-
- gif_put_bits_rev(&p, 9, 0x0100); /* clear code */
-
- for(i=0;i<GIF_CHUNKS;i++) {
- if (pix_fmt == PIX_FMT_RGB24) {
- v = gif_clut_index(ptr[0], ptr[1], ptr[2]);
- ptr+=3;
- } else {
- v = *ptr++;
- }
- gif_put_bits_rev(&p, 9, v);
- if (--w == 0) {
- w = width;
- buf += linesize;
- ptr = buf;
- }
- }
-
- if(left<=GIF_CHUNKS) {
- gif_put_bits_rev(&p, 9, 0x101); /* end of stream */
- gif_flush_put_bits_rev(&p);
- }
- if(pbBufPtr(&p) - p.buf > 0) {
- put_byte(pb, pbBufPtr(&p) - p.buf); /* byte count of the packet */
- put_buffer(pb, p.buf, pbBufPtr(&p) - p.buf); /* the actual buffer */
- p.data_out_size += pbBufPtr(&p) - p.buf;
- p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */
- }
- if(left<=GIF_CHUNKS) {
- put_byte(pb, 0x00); /* end of image block */
- }
-
- left-=GIF_CHUNKS;
- }
- return 0;
-}
-
-typedef struct {
- int64_t time, file_time;
- uint8_t buffer[100]; /* data chunks */
-} GIFContext;
-
-static int gif_write_header(AVFormatContext *s)
-{
- GIFContext *gif = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc, *video_enc;
- int i, width, height/*, rate*/;
-
-/* XXX: do we reject audio streams or just ignore them ?
- if(s->nb_streams > 1)
- return -1;
-*/
- gif->time = 0;
- gif->file_time = 0;
-
- video_enc = NULL;
- for(i=0;i<s->nb_streams;i++) {
- enc = &s->streams[i]->codec;
- if (enc->codec_type != CODEC_TYPE_AUDIO)
- video_enc = enc;
- }
-
- if (!video_enc) {
- av_free(gif);
- return -1;
- } else {
- width = video_enc->width;
- height = video_enc->height;
-// rate = video_enc->frame_rate;
- }
-
- /* XXX: is it allowed ? seems to work so far... */
- video_enc->pix_fmt = PIX_FMT_RGB24;
-
- gif_image_write_header(pb, width, height, NULL);
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int gif_write_video(AVFormatContext *s,
- AVCodecContext *enc, const uint8_t *buf, int size)
-{
- ByteIOContext *pb = &s->pb;
- GIFContext *gif = s->priv_data;
- int jiffies;
- int64_t delay;
-
- /* graphic control extension block */
- put_byte(pb, 0x21);
- put_byte(pb, 0xf9);
- put_byte(pb, 0x04); /* block size */
- put_byte(pb, 0x04); /* flags */
-
- /* 1 jiffy is 1/70 s */
- /* the delay_time field indicates the number of jiffies - 1 */
- delay = gif->file_time - gif->time;
-
- /* XXX: should use delay, in order to be more accurate */
- /* instead of using the same rounded value each time */
- /* XXX: don't even remember if I really use it for now */
- jiffies = (70*enc->frame_rate_base/enc->frame_rate) - 1;
-
- put_le16(pb, jiffies);
-
- put_byte(pb, 0x1f); /* transparent color index */
- put_byte(pb, 0x00);
-
- gif_image_write_image(pb, 0, 0, enc->width, enc->height,
- buf, enc->width * 3, PIX_FMT_RGB24);
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int gif_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- AVCodecContext *codec = &s->streams[stream_index]->codec;
- if (codec->codec_type == CODEC_TYPE_AUDIO)
- return 0; /* just ignore audio */
- else
- return gif_write_video(s, codec, buf, size);
-}
-
-static int gif_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- put_byte(pb, 0x3b);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-/* better than nothing gif image writer */
-int gif_write(ByteIOContext *pb, AVImageInfo *info)
-{
- gif_image_write_header(pb, info->width, info->height,
- (uint32_t *)info->pict.data[1]);
- gif_image_write_image(pb, 0, 0, info->width, info->height,
- info->pict.data[0], info->pict.linesize[0],
- PIX_FMT_PAL8);
- put_byte(pb, 0x3b);
- put_flush_packet(pb);
- return 0;
-}
-
-static AVOutputFormat gif_oformat = {
- "gif",
- "GIF Animation",
- "image/gif",
- "gif",
- sizeof(GIFContext),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- gif_write_header,
- gif_write_packet,
- gif_write_trailer,
-};
-
-extern AVInputFormat gif_iformat;
-
-int gif_init(void)
-{
- av_register_output_format(&gif_oformat);
- av_register_input_format(&gif_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * GIF decoder
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-int gif_write(ByteIOContext *pb, AVImageInfo *info);
-
-//#define DEBUG
-
-#define MAXBITS 12
-#define SIZTABLE (1<<MAXBITS)
-
-#define GCE_DISPOSAL_NONE 0
-#define GCE_DISPOSAL_INPLACE 1
-#define GCE_DISPOSAL_BACKGROUND 2
-#define GCE_DISPOSAL_RESTORE 3
-
-typedef struct GifState {
- int screen_width;
- int screen_height;
- int bits_per_pixel;
- int background_color_index;
- int transparent_color_index;
- int color_resolution;
- uint8_t *image_buf;
- int image_linesize;
- uint32_t *image_palette;
- int pix_fmt;
-
- /* after the frame is displayed, the disposal method is used */
- int gce_disposal;
- /* delay during which the frame is shown */
- int gce_delay;
-
- /* LZW compatible decoder */
- ByteIOContext *f;
- int eob_reached;
- uint8_t *pbuf, *ebuf;
- int bbits;
- unsigned int bbuf;
-
- int cursize; /* The current code size */
- int curmask;
- int codesize;
- int clear_code;
- int end_code;
- int newcodes; /* First available code */
- int top_slot; /* Highest code for current size */
- int slot; /* Last read code */
- int fc, oc;
- uint8_t *sp;
- uint8_t stack[SIZTABLE];
- uint8_t suffix[SIZTABLE];
- uint16_t prefix[SIZTABLE];
-
- /* aux buffers */
- uint8_t global_palette[256 * 3];
- uint8_t local_palette[256 * 3];
- uint8_t buf[256];
-} GifState;
-
-
-static const uint8_t gif87a_sig[6] = "GIF87a";
-static const uint8_t gif89a_sig[6] = "GIF89a";
-
-static const uint16_t mask[17] =
-{
- 0x0000, 0x0001, 0x0003, 0x0007,
- 0x000F, 0x001F, 0x003F, 0x007F,
- 0x00FF, 0x01FF, 0x03FF, 0x07FF,
- 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
-};
-
-/* Probe gif video format or gif image format. The current heuristic
- supposes the gif87a is always a single image. For gif89a, we
- consider it as a video only if a GCE extension is present in the
- first kilobyte. */
-static int gif_video_probe(AVProbeData * pd)
-{
- const uint8_t *p, *p_end;
- int bits_per_pixel, has_global_palette, ext_code, ext_len;
- int gce_flags, gce_disposal;
-
- if (pd->buf_size < 24 ||
- memcmp(pd->buf, gif89a_sig, 6) != 0)
- return 0;
- p_end = pd->buf + pd->buf_size;
- p = pd->buf + 6;
- bits_per_pixel = (p[4] & 0x07) + 1;
- has_global_palette = (p[4] & 0x80);
- p += 7;
- if (has_global_palette)
- p += (1 << bits_per_pixel) * 3;
- for(;;) {
- if (p >= p_end)
- return 0;
- if (*p != '!')
- break;
- p++;
- if (p >= p_end)
- return 0;
- ext_code = *p++;
- if (p >= p_end)
- return 0;
- ext_len = *p++;
- if (ext_code == 0xf9) {
- if (p >= p_end)
- return 0;
- /* if GCE extension found with gce_disposal != 0: it is
- likely to be an animation */
- gce_flags = *p++;
- gce_disposal = (gce_flags >> 2) & 0x7;
- if (gce_disposal != 0)
- return AVPROBE_SCORE_MAX;
- else
- return 0;
- }
- for(;;) {
- if (ext_len == 0)
- break;
- p += ext_len;
- if (p >= p_end)
- return 0;
- ext_len = *p++;
- }
- }
- return 0;
-}
-
-static int gif_image_probe(AVProbeData * pd)
-{
- if (pd->buf_size >= 24 &&
- (memcmp(pd->buf, gif87a_sig, 6) == 0 ||
- memcmp(pd->buf, gif89a_sig, 6) == 0))
- return AVPROBE_SCORE_MAX - 1;
- else
- return 0;
-}
-
-
-static void GLZWDecodeInit(GifState * s, int csize)
-{
- /* read buffer */
- s->eob_reached = 0;
- s->pbuf = s->buf;
- s->ebuf = s->buf;
- s->bbuf = 0;
- s->bbits = 0;
-
- /* decoder */
- s->codesize = csize;
- s->cursize = s->codesize + 1;
- s->curmask = mask[s->cursize];
- s->top_slot = 1 << s->cursize;
- s->clear_code = 1 << s->codesize;
- s->end_code = s->clear_code + 1;
- s->slot = s->newcodes = s->clear_code + 2;
- s->oc = s->fc = 0;
- s->sp = s->stack;
-}
-
-/* XXX: optimize */
-static inline int GetCode(GifState * s)
-{
- int c, sizbuf;
- uint8_t *ptr;
-
- while (s->bbits < s->cursize) {
- ptr = s->pbuf;
- if (ptr >= s->ebuf) {
- if (!s->eob_reached) {
- sizbuf = get_byte(s->f);
- s->ebuf = s->buf + sizbuf;
- s->pbuf = s->buf;
- if (sizbuf > 0) {
- get_buffer(s->f, s->buf, sizbuf);
- } else {
- s->eob_reached = 1;
- }
- }
- ptr = s->pbuf;
- }
- s->bbuf |= ptr[0] << s->bbits;
- ptr++;
- s->pbuf = ptr;
- s->bbits += 8;
- }
- c = s->bbuf & s->curmask;
- s->bbuf >>= s->cursize;
- s->bbits -= s->cursize;
- return c;
-}
-
-/* NOTE: the algorithm here is inspired from the LZW GIF decoder
- written by Steven A. Bennett in 1987. */
-/* return the number of byte decoded */
-static int GLZWDecode(GifState * s, uint8_t * buf, int len)
-{
- int l, c, code, oc, fc;
- uint8_t *sp;
-
- if (s->end_code < 0)
- return 0;
-
- l = len;
- sp = s->sp;
- oc = s->oc;
- fc = s->fc;
-
- while (sp > s->stack) {
- *buf++ = *(--sp);
- if ((--l) == 0)
- goto the_end;
- }
-
- for (;;) {
- c = GetCode(s);
- if (c == s->end_code) {
- s->end_code = -1;
- break;
- } else if (c == s->clear_code) {
- s->cursize = s->codesize + 1;
- s->curmask = mask[s->cursize];
- s->slot = s->newcodes;
- s->top_slot = 1 << s->cursize;
- while ((c = GetCode(s)) == s->clear_code);
- if (c == s->end_code) {
- s->end_code = -1;
- break;
- }
- /* test error */
- if (c >= s->slot)
- c = 0;
- fc = oc = c;
- *buf++ = c;
- if ((--l) == 0)
- break;
- } else {
- code = c;
- if (code >= s->slot) {
- *sp++ = fc;
- code = oc;
- }
- while (code >= s->newcodes) {
- *sp++ = s->suffix[code];
- code = s->prefix[code];
- }
- *sp++ = code;
- if (s->slot < s->top_slot) {
- s->suffix[s->slot] = fc = code;
- s->prefix[s->slot++] = oc;
- oc = c;
- }
- if (s->slot >= s->top_slot) {
- if (s->cursize < MAXBITS) {
- s->top_slot <<= 1;
- s->curmask = mask[++s->cursize];
- }
- }
- while (sp > s->stack) {
- *buf++ = *(--sp);
- if ((--l) == 0)
- goto the_end;
- }
- }
- }
- the_end:
- s->sp = sp;
- s->oc = oc;
- s->fc = fc;
- return len - l;
-}
-
-static int gif_read_image(GifState *s)
-{
- ByteIOContext *f = s->f;
- int left, top, width, height, bits_per_pixel, code_size, flags;
- int is_interleaved, has_local_palette, y, x, pass, y1, linesize, n, i;
- uint8_t *ptr, *line, *d, *spal, *palette, *sptr, *ptr1;
-
- left = get_le16(f);
- top = get_le16(f);
- width = get_le16(f);
- height = get_le16(f);
- flags = get_byte(f);
- is_interleaved = flags & 0x40;
- has_local_palette = flags & 0x80;
- bits_per_pixel = (flags & 0x07) + 1;
-#ifdef DEBUG
- printf("gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height);
-#endif
-
- if (has_local_palette) {
- get_buffer(f, s->local_palette, 3 * (1 << bits_per_pixel));
- palette = s->local_palette;
- } else {
- palette = s->global_palette;
- bits_per_pixel = s->bits_per_pixel;
- }
-
- /* verify that all the image is inside the screen dimensions */
- if (left + width > s->screen_width ||
- top + height > s->screen_height)
- return -EINVAL;
-
- /* build the palette */
- if (s->pix_fmt == PIX_FMT_RGB24) {
- line = av_malloc(width);
- if (!line)
- return -ENOMEM;
- } else {
- n = (1 << bits_per_pixel);
- spal = palette;
- for(i = 0; i < n; i++) {
- s->image_palette[i] = (0xff << 24) |
- (spal[0] << 16) | (spal[1] << 8) | (spal[2]);
- spal += 3;
- }
- for(; i < 256; i++)
- s->image_palette[i] = (0xff << 24);
- /* handle transparency */
- if (s->transparent_color_index >= 0)
- s->image_palette[s->transparent_color_index] = 0;
- line = NULL;
- }
-
- /* now get the image data */
- s->f = f;
- code_size = get_byte(f);
- GLZWDecodeInit(s, code_size);
-
- /* read all the image */
- linesize = s->image_linesize;
- ptr1 = s->image_buf + top * linesize + (left * 3);
- ptr = ptr1;
- pass = 0;
- y1 = 0;
- for (y = 0; y < height; y++) {
- if (s->pix_fmt == PIX_FMT_RGB24) {
- /* transcode to RGB24 */
- GLZWDecode(s, line, width);
- d = ptr;
- sptr = line;
- for(x = 0; x < width; x++) {
- spal = palette + sptr[0] * 3;
- d[0] = spal[0];
- d[1] = spal[1];
- d[2] = spal[2];
- d += 3;
- sptr++;
- }
- } else {
- GLZWDecode(s, ptr, width);
- }
- if (is_interleaved) {
- switch(pass) {
- default:
- case 0:
- case 1:
- y1 += 8;
- ptr += linesize * 8;
- if (y1 >= height) {
- y1 = 4;
- if (pass == 0)
- ptr = ptr1 + linesize * 4;
- else
- ptr = ptr1 + linesize * 2;
- pass++;
- }
- break;
- case 2:
- y1 += 4;
- ptr += linesize * 4;
- if (y1 >= height) {
- y1 = 1;
- ptr = ptr1 + linesize;
- pass++;
- }
- break;
- case 3:
- y1 += 2;
- ptr += linesize * 2;
- break;
- }
- } else {
- ptr += linesize;
- }
- }
- av_free(line);
-
- /* read the garbage data until end marker is found */
- while (!s->eob_reached)
- GetCode(s);
- return 0;
-}
-
-static int gif_read_extension(GifState *s)
-{
- ByteIOContext *f = s->f;
- int ext_code, ext_len, i, gce_flags, gce_transparent_index;
-
- /* extension */
- ext_code = get_byte(f);
- ext_len = get_byte(f);
-#ifdef DEBUG
- printf("gif: ext_code=0x%x len=%d\n", ext_code, ext_len);
-#endif
- switch(ext_code) {
- case 0xf9:
- if (ext_len != 4)
- goto discard_ext;
- s->transparent_color_index = -1;
- gce_flags = get_byte(f);
- s->gce_delay = get_le16(f);
- gce_transparent_index = get_byte(f);
- if (gce_flags & 0x01)
- s->transparent_color_index = gce_transparent_index;
- else
- s->transparent_color_index = -1;
- s->gce_disposal = (gce_flags >> 2) & 0x7;
-#ifdef DEBUG
- printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n",
- gce_flags, s->gce_delay,
- s->transparent_color_index, s->gce_disposal);
-#endif
- ext_len = get_byte(f);
- break;
- }
-
- /* NOTE: many extension blocks can come after */
- discard_ext:
- while (ext_len != 0) {
- for (i = 0; i < ext_len; i++)
- get_byte(f);
- ext_len = get_byte(f);
-#ifdef DEBUG
- printf("gif: ext_len1=%d\n", ext_len);
-#endif
- }
- return 0;
-}
-
-static int gif_read_header1(GifState *s)
-{
- ByteIOContext *f = s->f;
- uint8_t sig[6];
- int ret, v, n;
- int has_global_palette;
-
- /* read gif signature */
- ret = get_buffer(f, sig, 6);
- if (ret != 6)
- return -1;
- if (memcmp(sig, gif87a_sig, 6) != 0 &&
- memcmp(sig, gif89a_sig, 6) != 0)
- return -1;
-
- /* read screen header */
- s->transparent_color_index = -1;
- s->screen_width = get_le16(f);
- s->screen_height = get_le16(f);
- v = get_byte(f);
- s->color_resolution = ((v & 0x70) >> 4) + 1;
- has_global_palette = (v & 0x80);
- s->bits_per_pixel = (v & 0x07) + 1;
- s->background_color_index = get_byte(f);
- get_byte(f); /* ignored */
-#ifdef DEBUG
- printf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n",
- s->screen_width, s->screen_height, s->bits_per_pixel,
- has_global_palette);
-#endif
- if (has_global_palette) {
- n = 1 << s->bits_per_pixel;
- get_buffer(f, s->global_palette, n * 3);
- }
- return 0;
-}
-
-static int gif_parse_next_image(GifState *s)
-{
- ByteIOContext *f = s->f;
- int ret, code;
-
- for (;;) {
- code = url_fgetc(f);
-#ifdef DEBUG
- printf("gif: code=%02x '%c'\n", code, code);
-#endif
- switch (code) {
- case ',':
- if (gif_read_image(s) < 0)
- return -EIO;
- ret = 0;
- goto the_end;
- case ';':
- /* end of image */
- ret = -EIO;
- goto the_end;
- case '!':
- if (gif_read_extension(s) < 0)
- return -EIO;
- break;
- case EOF:
- default:
- /* error or errneous EOF */
- ret = -EIO;
- goto the_end;
- }
- }
- the_end:
- return ret;
-}
-
-static int gif_read_header(AVFormatContext * s1,
- AVFormatParameters * ap)
-{
- GifState *s = s1->priv_data;
- ByteIOContext *f = &s1->pb;
- AVStream *st;
-
- s->f = f;
- if (gif_read_header1(s) < 0)
- return -1;
-
- /* allocate image buffer */
- s->image_linesize = s->screen_width * 3;
- s->image_buf = av_malloc(s->screen_height * s->image_linesize);
- if (!s->image_buf)
- return -ENOMEM;
- s->pix_fmt = PIX_FMT_RGB24;
- /* now we are ready: build format streams */
- st = av_new_stream(s1, 0);
- if (!st)
- return -1;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.frame_rate = 5;
- st->codec.frame_rate_base = 1;
- /* XXX: check if screen size is always valid */
- st->codec.width = s->screen_width;
- st->codec.height = s->screen_height;
- st->codec.pix_fmt = PIX_FMT_RGB24;
- return 0;
-}
-
-static int gif_read_packet(AVFormatContext * s1,
- AVPacket * pkt)
-{
- GifState *s = s1->priv_data;
- int ret;
-
- ret = gif_parse_next_image(s);
- if (ret < 0)
- return ret;
-
- /* XXX: avoid copying */
- if (av_new_packet(pkt, s->screen_width * s->screen_height * 3)) {
- return -EIO;
- }
- pkt->stream_index = 0;
- memcpy(pkt->data, s->image_buf, s->screen_width * s->screen_height * 3);
- return 0;
-}
-
-static int gif_read_close(AVFormatContext *s1)
-{
- GifState *s = s1->priv_data;
- av_free(s->image_buf);
- return 0;
-}
-
-/* read gif as image */
-static int gif_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- GifState s1, *s = &s1;
- AVImageInfo info1, *info = &info1;
- int ret;
-
- memset(s, 0, sizeof(GifState));
- s->f = f;
- if (gif_read_header1(s) < 0)
- return -1;
- info->width = s->screen_width;
- info->height = s->screen_height;
- info->pix_fmt = PIX_FMT_PAL8;
- ret = alloc_cb(opaque, info);
- if (ret)
- return ret;
- s->image_buf = info->pict.data[0];
- s->image_linesize = info->pict.linesize[0];
- s->image_palette = (uint32_t *)info->pict.data[1];
-
- if (gif_parse_next_image(s) < 0)
- return -1;
- return 0;
-}
-
-AVInputFormat gif_iformat =
-{
- "gif",
- "gif format",
- sizeof(GifState),
- gif_video_probe,
- gif_read_header,
- gif_read_packet,
- gif_read_close,
-};
-
-AVImageFormat gif_image_format = {
- "gif",
- "gif",
- gif_image_probe,
- gif_read,
- (1 << PIX_FMT_PAL8),
- gif_write,
-};
+++ /dev/null
-/*
- * Linux video grab interface
- * Copyright (c) 2000,2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/time.h>
-#define _LINUX_TIME_H 1
-#include <linux/videodev.h>
-#include <time.h>
-
-typedef struct {
- int fd;
- int frame_format; /* see VIDEO_PALETTE_xxx */
- int use_mmap;
- int width, height;
- int frame_rate;
- int frame_rate_base;
- int64_t time_frame;
- int frame_size;
- struct video_capability video_cap;
- struct video_audio audio_saved;
- uint8_t *video_buf;
- struct video_mbuf gb_buffers;
- struct video_mmap gb_buf;
- int gb_frame;
-
- /* ATI All In Wonder specific stuff */
- /* XXX: remove and merge in libavcodec/imgconvert.c */
- int aiw_enabled;
- int deint;
- int halfw;
- uint8_t *src_mem;
- uint8_t *lum_m4_mem;
-} VideoData;
-
-static int aiw_init(VideoData *s);
-static int aiw_read_picture(VideoData *s, uint8_t *data);
-static int aiw_close(VideoData *s);
-
-static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- VideoData *s = s1->priv_data;
- AVStream *st;
- int width, height;
- int video_fd, frame_size;
- int ret, frame_rate, frame_rate_base;
- int desired_palette;
- struct video_tuner tuner;
- struct video_audio audio;
- const char *video_device;
-
- if (!ap || ap->width <= 0 || ap->height <= 0 || ap->frame_rate <= 0)
- return -1;
-
- width = ap->width;
- height = ap->height;
- frame_rate = ap->frame_rate;
- frame_rate_base = ap->frame_rate_base;
-
- st = av_new_stream(s1, 0);
- if (!st)
- return -ENOMEM;
-
- s->width = width;
- s->height = height;
- s->frame_rate = frame_rate;
- s->frame_rate_base = frame_rate_base;
-
- video_device = ap->device;
- if (!video_device)
- video_device = "/dev/video";
- video_fd = open(video_device, O_RDWR);
- if (video_fd < 0) {
- perror(video_device);
- goto fail;
- }
-
- if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) {
- perror("VIDIOCGCAP");
- goto fail;
- }
-
- if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
- fprintf(stderr, "Fatal: grab device does not handle capture\n");
- goto fail;
- }
-
- desired_palette = -1;
- if (st->codec.pix_fmt == PIX_FMT_YUV420P) {
- desired_palette = VIDEO_PALETTE_YUV420P;
- } else if (st->codec.pix_fmt == PIX_FMT_YUV422) {
- desired_palette = VIDEO_PALETTE_YUV422;
- } else if (st->codec.pix_fmt == PIX_FMT_BGR24) {
- desired_palette = VIDEO_PALETTE_RGB24;
- }
-
- /* set tv standard */
- if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
- if (!strcasecmp(ap->standard, "pal"))
- tuner.mode = VIDEO_MODE_PAL;
- else if (!strcasecmp(ap->standard, "secam"))
- tuner.mode = VIDEO_MODE_SECAM;
- else
- tuner.mode = VIDEO_MODE_NTSC;
- ioctl(video_fd, VIDIOCSTUNER, &tuner);
- }
-
- /* unmute audio */
- audio.audio = 0;
- ioctl(video_fd, VIDIOCGAUDIO, &audio);
- memcpy(&s->audio_saved, &audio, sizeof(audio));
- audio.flags &= ~VIDEO_AUDIO_MUTE;
- ioctl(video_fd, VIDIOCSAUDIO, &audio);
-
- ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers);
- if (ret < 0) {
- /* try to use read based access */
- struct video_window win;
- struct video_picture pict;
- int val;
-
- win.x = 0;
- win.y = 0;
- win.width = width;
- win.height = height;
- win.chromakey = -1;
- win.flags = 0;
-
- ioctl(video_fd, VIDIOCSWIN, &win);
-
- ioctl(video_fd, VIDIOCGPICT, &pict);
-#if 0
- printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n",
- pict.colour,
- pict.hue,
- pict.brightness,
- pict.contrast,
- pict.whiteness);
-#endif
- /* try to choose a suitable video format */
- pict.palette = desired_palette;
- if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) {
- pict.palette=VIDEO_PALETTE_YUV420P;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_YUV422;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0) {
- pict.palette=VIDEO_PALETTE_RGB24;
- ret = ioctl(video_fd, VIDIOCSPICT, &pict);
- if (ret < 0)
- goto fail1;
- }
- }
- }
-
- s->frame_format = pict.palette;
-
- val = 1;
- ioctl(video_fd, VIDIOCCAPTURE, &val);
-
- s->time_frame = av_gettime();
- s->use_mmap = 0;
-
- /* ATI All In Wonder automatic activation */
- if (!strcmp(s->video_cap.name, "Km")) {
- if (aiw_init(s) < 0)
- goto fail;
- s->aiw_enabled = 1;
- /* force 420P format because convertion from YUV422 to YUV420P
- is done in this driver (ugly) */
- s->frame_format = VIDEO_PALETTE_YUV420P;
- }
- } else {
- s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0);
- if ((unsigned char*)-1 == s->video_buf) {
- perror("mmap");
- goto fail;
- }
- s->gb_frame = 0;
- s->time_frame = av_gettime();
-
- /* start to grab the first frame */
- s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames;
- s->gb_buf.height = height;
- s->gb_buf.width = width;
- s->gb_buf.format = desired_palette;
-
- if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf)) < 0) {
- s->gb_buf.format = VIDEO_PALETTE_YUV420P;
-
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- if (ret < 0 && errno != EAGAIN) {
- /* try YUV422 */
- s->gb_buf.format = VIDEO_PALETTE_YUV422;
-
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- if (ret < 0 && errno != EAGAIN) {
- /* try RGB24 */
- s->gb_buf.format = VIDEO_PALETTE_RGB24;
- ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf);
- }
- }
- }
- if (ret < 0) {
- if (errno != EAGAIN) {
- fail1:
- fprintf(stderr, "Fatal: grab device does not support suitable format\n");
- } else {
- fprintf(stderr,"Fatal: grab device does not receive any video signal\n");
- }
- goto fail;
- }
- s->frame_format = s->gb_buf.format;
- s->use_mmap = 1;
- }
-
- switch(s->frame_format) {
- case VIDEO_PALETTE_YUV420P:
- frame_size = (width * height * 3) / 2;
- st->codec.pix_fmt = PIX_FMT_YUV420P;
- break;
- case VIDEO_PALETTE_YUV422:
- frame_size = width * height * 2;
- st->codec.pix_fmt = PIX_FMT_YUV422;
- break;
- case VIDEO_PALETTE_RGB24:
- frame_size = width * height * 3;
- st->codec.pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */
- break;
- default:
- goto fail;
- }
- s->fd = video_fd;
- s->frame_size = frame_size;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.width = width;
- st->codec.height = height;
- st->codec.frame_rate = frame_rate;
- st->codec.frame_rate_base = frame_rate_base;
-
- av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
-
- return 0;
- fail:
- if (video_fd >= 0)
- close(video_fd);
- av_free(st);
- return -EIO;
-}
-
-static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
-{
- uint8_t *ptr;
-
- /* Setup to capture the next frame */
- s->gb_buf.frame = (s->gb_frame + 1) % s->gb_buffers.frames;
- if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
- if (errno == EAGAIN)
- fprintf(stderr,"Cannot Sync\n");
- else
- perror("VIDIOCMCAPTURE");
- return -EIO;
- }
-
- while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 &&
- (errno == EAGAIN || errno == EINTR));
-
- ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame];
- memcpy(buf, ptr, s->frame_size);
-
- /* This is now the grabbing frame */
- s->gb_frame = s->gb_buf.frame;
-
- return s->frame_size;
-}
-
-static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- VideoData *s = s1->priv_data;
- int64_t curtime, delay;
- struct timespec ts;
- int64_t per_frame = (int64_t_C(1000000) * s->frame_rate_base) / s->frame_rate;
-
- /* Calculate the time of the next frame */
- s->time_frame += per_frame;
-
- /* wait based on the frame rate */
- for(;;) {
- curtime = av_gettime();
- delay = s->time_frame - curtime;
- if (delay <= 0) {
- if (delay < -per_frame) {
- /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */
- s->time_frame += per_frame;
- }
- break;
- }
- ts.tv_sec = delay / 1000000;
- ts.tv_nsec = (delay % 1000000) * 1000;
- nanosleep(&ts, NULL);
- }
-
- if (av_new_packet(pkt, s->frame_size) < 0)
- return -EIO;
-
- pkt->pts = curtime & ((1LL << 48) - 1);
-
- /* read one frame */
- if (s->aiw_enabled) {
- return aiw_read_picture(s, pkt->data);
- } else if (s->use_mmap) {
- return v4l_mm_read_picture(s, pkt->data);
- } else {
- if (read(s->fd, pkt->data, pkt->size) != pkt->size)
- return -EIO;
- return s->frame_size;
- }
-}
-
-static int grab_read_close(AVFormatContext *s1)
-{
- VideoData *s = s1->priv_data;
-
- if (s->aiw_enabled)
- aiw_close(s);
-
- if (s->use_mmap)
- munmap(s->video_buf, s->gb_buffers.size);
-
- /* mute audio. we must force it because the BTTV driver does not
- return its state correctly */
- s->audio_saved.flags |= VIDEO_AUDIO_MUTE;
- ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved);
-
- close(s->fd);
- return 0;
-}
-
-static AVInputFormat video_grab_device_format = {
- "video4linux",
- "video grab",
- sizeof(VideoData),
- NULL,
- grab_read_header,
- grab_read_packet,
- grab_read_close,
- .flags = AVFMT_NOFILE,
-};
-
-/* All in Wonder specific stuff */
-/* XXX: remove and merge in libavcodec/imgconvert.c */
-
-static int aiw_init(VideoData *s)
-{
- int width, height;
-
- width = s->width;
- height = s->height;
-
- if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) ||
- (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) ||
- (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) {
-
- s->deint=0;
- s->halfw=0;
- if (height == s->video_cap.maxheight*2) s->deint=1;
- if (width == s->video_cap.maxwidth/2) s->halfw=1;
- } else {
- fprintf(stderr,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
- fprintf(stderr," %dx%d %dx%d %dx%d\n\n",
- s->video_cap.maxwidth,s->video_cap.maxheight,
- s->video_cap.maxwidth,s->video_cap.maxheight*2,
- s->video_cap.maxwidth/2,s->video_cap.maxheight);
- goto fail;
- }
-
- if (s->halfw == 0) {
- s->src_mem = av_malloc(s->width*2);
- } else {
- s->src_mem = av_malloc(s->width*4);
- }
- if (!s->src_mem) goto fail;
-
- s->lum_m4_mem = av_malloc(s->width);
- if (!s->lum_m4_mem)
- goto fail;
- return 0;
- fail:
- av_freep(&s->src_mem);
- av_freep(&s->lum_m4_mem);
- return -1;
-}
-
-#ifdef HAVE_MMX
-#include "../libavcodec/i386/mmx.h"
-
-#define LINE_WITH_UV \
- movq_m2r(ptr[0],mm0); \
- movq_m2r(ptr[8],mm1); \
- movq_r2r(mm0, mm4); \
- punpcklbw_r2r(mm1,mm0); \
- punpckhbw_r2r(mm1,mm4); \
- movq_r2r(mm0,mm5); \
- punpcklbw_r2r(mm4,mm0); \
- punpckhbw_r2r(mm4,mm5); \
- movq_r2r(mm0,mm1); \
- punpcklbw_r2r(mm5,mm1); \
- movq_r2m(mm1,lum[0]); \
- movq_m2r(ptr[16],mm2); \
- movq_m2r(ptr[24],mm1); \
- movq_r2r(mm2,mm4); \
- punpcklbw_r2r(mm1,mm2); \
- punpckhbw_r2r(mm1,mm4); \
- movq_r2r(mm2,mm3); \
- punpcklbw_r2r(mm4,mm2); \
- punpckhbw_r2r(mm4,mm3); \
- movq_r2r(mm2,mm1); \
- punpcklbw_r2r(mm3,mm1); \
- movq_r2m(mm1,lum[8]); \
- punpckhdq_r2r(mm2,mm0); \
- punpckhdq_r2r(mm3,mm5); \
- movq_r2m(mm0,cb[0]); \
- movq_r2m(mm5,cr[0]);
-
-#define LINE_NO_UV \
- movq_m2r(ptr[0],mm0);\
- movq_m2r(ptr[8],mm1);\
- movq_r2r(mm0, mm4);\
- punpcklbw_r2r(mm1,mm0); \
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm0,mm5);\
- punpcklbw_r2r(mm4,mm0);\
- punpckhbw_r2r(mm4,mm5);\
- movq_r2r(mm0,mm1);\
- punpcklbw_r2r(mm5,mm1);\
- movq_r2m(mm1,lum[0]);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm1);\
- movq_r2r(mm2,mm4);\
- punpcklbw_r2r(mm1,mm2);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm2,mm3);\
- punpcklbw_r2r(mm4,mm2);\
- punpckhbw_r2r(mm4,mm3);\
- movq_r2r(mm2,mm1);\
- punpcklbw_r2r(mm3,mm1);\
- movq_r2m(mm1,lum[8]);
-
-#define LINE_WITHUV_AVG \
- movq_m2r(ptr[0], mm0);\
- movq_m2r(ptr[8], mm1);\
- movq_r2r(mm0, mm4);\
- punpcklbw_r2r(mm1,mm0);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm0,mm5);\
- punpcklbw_r2r(mm4,mm0);\
- punpckhbw_r2r(mm4,mm5);\
- movq_r2r(mm0,mm1);\
- movq_r2r(mm5,mm2);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- paddw_r2r(mm6,mm1);\
- paddw_r2r(mm2,mm1);\
- psraw_i2r(1,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum[0]);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm1);\
- movq_r2r(mm2,mm4);\
- punpcklbw_r2r(mm1,mm2);\
- punpckhbw_r2r(mm1,mm4);\
- movq_r2r(mm2,mm3);\
- punpcklbw_r2r(mm4,mm2);\
- punpckhbw_r2r(mm4,mm3);\
- movq_r2r(mm2,mm1);\
- movq_r2r(mm3,mm4);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm4);\
- paddw_r2r(mm6,mm1);\
- paddw_r2r(mm4,mm1);\
- psraw_i2r(1,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum[4]);\
- punpckhbw_r2r(mm7,mm0);\
- punpckhbw_r2r(mm7,mm2);\
- paddw_r2r(mm6,mm0);\
- paddw_r2r(mm2,mm0);\
- psraw_i2r(1,mm0);\
- packuswb_r2r(mm7,mm0);\
- punpckhbw_r2r(mm7,mm5);\
- punpckhbw_r2r(mm7,mm3);\
- paddw_r2r(mm6,mm5);\
- paddw_r2r(mm3,mm5);\
- psraw_i2r(1,mm5);\
- packuswb_r2r(mm7,mm5);\
- movd_r2m(mm0,cb[0]);\
- movd_r2m(mm5,cr[0]);
-
-#define LINE_NOUV_AVG \
- movq_m2r(ptr[0],mm0);\
- movq_m2r(ptr[8],mm1);\
- pand_r2r(mm5,mm0);\
- pand_r2r(mm5,mm1);\
- pmaddwd_r2r(mm6,mm0);\
- pmaddwd_r2r(mm6,mm1);\
- packssdw_r2r(mm1,mm0);\
- paddw_r2r(mm6,mm0);\
- psraw_i2r(1,mm0);\
- movq_m2r(ptr[16],mm2);\
- movq_m2r(ptr[24],mm3);\
- pand_r2r(mm5,mm2);\
- pand_r2r(mm5,mm3);\
- pmaddwd_r2r(mm6,mm2);\
- pmaddwd_r2r(mm6,mm3);\
- packssdw_r2r(mm3,mm2);\
- paddw_r2r(mm6,mm2);\
- psraw_i2r(1,mm2);\
- packuswb_r2r(mm2,mm0);\
- movq_r2m(mm0,lum[0]);
-
-#define DEINT_LINE_LUM(ptroff) \
- movd_m2r(lum_m4[(ptroff)],mm0);\
- movd_m2r(lum_m3[(ptroff)],mm1);\
- movd_m2r(lum_m2[(ptroff)],mm2);\
- movd_m2r(lum_m1[(ptroff)],mm3);\
- movd_m2r(lum[(ptroff)],mm4);\
- punpcklbw_r2r(mm7,mm0);\
- movd_r2m(mm2,lum_m4[(ptroff)]);\
- punpcklbw_r2r(mm7,mm1);\
- punpcklbw_r2r(mm7,mm2);\
- punpcklbw_r2r(mm7,mm3);\
- punpcklbw_r2r(mm7,mm4);\
- psllw_i2r(2,mm1);\
- psllw_i2r(1,mm2);\
- paddw_r2r(mm6,mm1);\
- psllw_i2r(2,mm3);\
- paddw_r2r(mm2,mm1);\
- paddw_r2r(mm4,mm0);\
- paddw_r2r(mm3,mm1);\
- psubusw_r2r(mm0,mm1);\
- psrlw_i2r(3,mm1);\
- packuswb_r2r(mm7,mm1);\
- movd_r2m(mm1,lum_m2[(ptroff)]);
-
-#else
-#include "../libavcodec/dsputil.h"
-
-#define LINE_WITH_UV \
- lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
- cb[0]=ptr[1];cb[1]=ptr[5];\
- cr[0]=ptr[3];cr[1]=ptr[7];\
- lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
- cb[2]=ptr[9];cb[3]=ptr[13];\
- cr[2]=ptr[11];cr[3]=ptr[15];\
- lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
- cb[4]=ptr[17];cb[5]=ptr[21];\
- cr[4]=ptr[19];cr[5]=ptr[23];\
- lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\
- cb[6]=ptr[25];cb[7]=ptr[29];\
- cr[6]=ptr[27];cr[7]=ptr[31];
-
-#define LINE_NO_UV \
- lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\
- lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\
- lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\
- lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];
-
-#define LINE_WITHUV_AVG \
- sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
- sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
- sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \
- sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \
- sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
- sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
- sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \
- sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \
- sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
- sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
- sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \
- sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \
- sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
- sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \
- sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \
- sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum;
-
-#define LINE_NOUV_AVG \
- sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \
- sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \
- sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \
- sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \
- sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \
- sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \
- sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \
- sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum;
-
-#define DEINT_LINE_LUM(ptroff) \
- sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \
- lum_m4[(ptroff)]=lum_m2[(ptroff)];\
- lum_m2[(ptroff)]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \
- lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\
- lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \
- lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\
- lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\
- sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \
- lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\
- lum_m2[(ptroff)+3]=cm[(sum+4)>>3];
-
-#endif
-
-
-/* Read two fields separately. */
-static int aiw_read_picture(VideoData *s, uint8_t *data)
-{
- uint8_t *ptr, *lum, *cb, *cr;
- int h;
-#ifndef HAVE_MMX
- int sum;
-#endif
- uint8_t* src = s->src_mem;
- uint8_t *ptrend = &src[s->width*2];
- lum=data;
- cb=&lum[s->width*s->height];
- cr=&cb[(s->width*s->height)/4];
- if (s->deint == 0 && s->halfw == 0) {
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- read(s->fd,src,s->width*2);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- /* drop second field */
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height - 1; h++) {
- read(s->fd,src,s->width*2);
- }
- } else if (s->halfw == 1) {
-#ifdef HAVE_MMX
- mmx_t rounder;
- mmx_t masker;
- rounder.uw[0]=1;
- rounder.uw[1]=1;
- rounder.uw[2]=1;
- rounder.uw[3]=1;
- masker.ub[0]=0xff;
- masker.ub[1]=0;
- masker.ub[2]=0xff;
- masker.ub[3]=0;
- masker.ub[4]=0xff;
- masker.ub[5]=0;
- masker.ub[6]=0xff;
- masker.ub[7]=0;
- pxor_r2r(mm7,mm7);
- movq_m2r(rounder,mm6);
-#endif
- while (read(s->fd,src,s->width*4) < 0) {
- usleep(100);
- }
- ptrend = &src[s->width*4];
- for (h = 0; h < s->height-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
- LINE_WITHUV_AVG
- }
- read(s->fd,src,s->width*4);
-#ifdef HAVE_MMX
- movq_m2r(masker,mm5);
-#endif
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
- LINE_NOUV_AVG
- }
- read(s->fd,src,s->width*4);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) {
- LINE_WITHUV_AVG
- }
- read(s->fd,src,s->width*4);
-#ifdef HAVE_MMX
- movq_m2r(masker,mm5);
-#endif
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) {
- LINE_NOUV_AVG
- }
- /* drop second field */
- while (read(s->fd,src,s->width*4) < 0) {
- usleep(100);
- }
- for (h = 0; h < s->height - 1; h++) {
- read(s->fd,src,s->width*4);
- }
- } else {
- uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4;
-#ifdef HAVE_MMX
- mmx_t rounder;
- rounder.uw[0]=4;
- rounder.uw[1]=4;
- rounder.uw[2]=4;
- rounder.uw[3]=4;
- movq_m2r(rounder,mm6);
- pxor_r2r(mm7,mm7);
-#else
- uint8_t *cm = cropTbl + MAX_NEG_CROP;
-#endif
-
- /* read two fields and deinterlace them */
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(100);
- }
- for (h = 0; h < (s->height/2)-2; h+=2) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- read(s->fd,src,s->width*2);
- }
- /*
- * Do last two lines
- */
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /* skip a luminance line - will be filled in later */
- lum += s->width;
- read(s->fd,src,s->width*2);
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) {
- LINE_WITH_UV
- }
- /*
- *
- * SECOND FIELD
- *
- */
- lum=&data[s->width];
- while (read(s->fd,src,s->width*2) < 0) {
- usleep(10);
- }
- /* First (and last) two lines not interlaced */
- for (h = 0; h < 2; h++) {
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) {
- LINE_NO_UV
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line */
- lum += s->width;
- }
- lum_m1=&lum[-s->width];
- lum_m2=&lum_m1[-s->width];
- lum_m3=&lum_m2[-s->width];
- memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width);
- for (; h < (s->height/2)-1; h++) {
- lum_m4=s->lum_m4_mem;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) {
- LINE_NO_UV
-
- DEINT_LINE_LUM(0)
- DEINT_LINE_LUM(4)
- DEINT_LINE_LUM(8)
- DEINT_LINE_LUM(12)
- }
- read(s->fd,src,s->width*2);
- /* skip a luminance line */
- lum += s->width;
- lum_m1 += s->width;
- lum_m2 += s->width;
- lum_m3 += s->width;
- // lum_m4 += s->width;
- }
- /*
- * Do last line
- */
- lum_m4=s->lum_m4_mem;
- for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) {
- LINE_NO_UV
-
- DEINT_LINE_LUM(0)
- DEINT_LINE_LUM(4)
- DEINT_LINE_LUM(8)
- DEINT_LINE_LUM(12)
- }
- }
-#ifdef HAVE_MMX
- emms();
-#endif
- return s->frame_size;
-}
-
-static int aiw_close(VideoData *s)
-{
- av_freep(&s->lum_m4_mem);
- av_freep(&s->src_mem);
- return 0;
-}
-
-int video_grab_init(void)
-{
- av_register_input_format(&video_grab_device_format);
- return 0;
-}
+++ /dev/null
-/*
- * HTTP protocol for ffmpeg client
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-
-
-/* XXX: POST protocol is not completly implemented because ffmpeg use
- only a subset of it */
-
-//#define DEBUG
-
-/* used for protocol handling */
-#define BUFFER_SIZE 1024
-#define URL_SIZE 4096
-
-typedef struct {
- URLContext *hd;
- unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
- int line_count;
- int http_code;
- char location[URL_SIZE];
-} HTTPContext;
-
-static int http_connect(URLContext *h, const char *path, const char *hoststr);
-static int http_write(URLContext *h, uint8_t *buf, int size);
-
-
-/* return non zero if error */
-static int http_open(URLContext *h, const char *uri, int flags)
-{
- const char *path, *proxy_path;
- char hostname[1024], hoststr[1024];
- char path1[1024];
- char buf[1024];
- int port, use_proxy, err;
- HTTPContext *s;
- URLContext *hd = NULL;
-
- h->is_streamed = 1;
-
- s = av_malloc(sizeof(HTTPContext));
- if (!s) {
- return -ENOMEM;
- }
- h->priv_data = s;
-
- proxy_path = getenv("http_proxy");
- use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
- strstart(proxy_path, "http://", NULL);
-
- /* fill the dest addr */
- redo:
- /* needed in any case to build the host string */
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- path1, sizeof(path1), uri);
- if (port > 0) {
- snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
- } else {
- pstrcpy(hoststr, sizeof(hoststr), hostname);
- }
-
- if (use_proxy) {
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- NULL, 0, proxy_path);
- path = uri;
- } else {
- if (path1[0] == '\0')
- path = "/";
- else
- path = path1;
- }
- if (port < 0)
- port = 80;
-
- snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
- err = url_open(&hd, buf, URL_RDWR);
- if (err < 0)
- goto fail;
-
- s->hd = hd;
- if (http_connect(h, path, hoststr) < 0)
- goto fail;
- if (s->http_code == 303 && s->location[0] != '\0') {
- /* url moved, get next */
- uri = s->location;
- url_close(hd);
- goto redo;
- }
- return 0;
- fail:
- if (hd)
- url_close(hd);
- av_free(s);
- return -EIO;
-}
-
-static int http_getc(HTTPContext *s)
-{
- int len;
- if (s->buf_ptr >= s->buf_end) {
- len = url_read(s->hd, s->buffer, BUFFER_SIZE);
- if (len < 0) {
- return -EIO;
- } else if (len == 0) {
- return -1;
- } else {
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer + len;
- }
- }
- return *s->buf_ptr++;
-}
-
-static int process_line(HTTPContext *s, char *line, int line_count)
-{
- char *tag, *p;
-
- /* end of header */
- if (line[0] == '\0')
- return 0;
-
- p = line;
- if (line_count == 0) {
- while (!isspace(*p) && *p != '\0')
- p++;
- while (isspace(*p))
- p++;
- s->http_code = strtol(p, NULL, 10);
-#ifdef DEBUG
- printf("http_code=%d\n", s->http_code);
-#endif
- } else {
- while (*p != '\0' && *p != ':')
- p++;
- if (*p != ':')
- return 1;
-
- *p = '\0';
- tag = line;
- p++;
- while (isspace(*p))
- p++;
- if (!strcmp(tag, "Location")) {
- strcpy(s->location, p);
- }
- }
- return 1;
-}
-
-static int http_connect(URLContext *h, const char *path, const char *hoststr)
-{
- HTTPContext *s = h->priv_data;
- int post, err, ch;
- char line[1024], *q;
-
-
- /* send http header */
- post = h->flags & URL_WRONLY;
-
- snprintf(s->buffer, sizeof(s->buffer),
- "%s %s HTTP/1.0\n"
- "User-Agent: FFmpeg %s\n"
- "Accept: */*\n"
- "Host: %s\n"
- "\n",
- post ? "POST" : "GET",
- path,
- LIBAVFORMAT_VERSION,
- hoststr);
-
- if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
- return -EIO;
-
- /* init input buffer */
- s->buf_ptr = s->buffer;
- s->buf_end = s->buffer;
- s->line_count = 0;
- s->location[0] = '\0';
- if (post) {
- sleep(1);
- return 0;
- }
-
- /* wait for header */
- q = line;
- for(;;) {
- ch = http_getc(s);
- if (ch < 0)
- return -EIO;
- if (ch == '\n') {
- /* process line */
- if (q > line && q[-1] == '\r')
- q--;
- *q = '\0';
-#ifdef DEBUG
- printf("header='%s'\n", line);
-#endif
- err = process_line(s, line, s->line_count);
- if (err < 0)
- return err;
- if (err == 0)
- return 0;
- s->line_count++;
- q = line;
- } else {
- if ((q - line) < sizeof(line) - 1)
- *q++ = ch;
- }
- }
-}
-
-
-static int http_read(URLContext *h, uint8_t *buf, int size)
-{
- HTTPContext *s = h->priv_data;
- int size1, len;
-
- size1 = size;
- while (size > 0) {
- /* read bytes from input buffer first */
- len = s->buf_end - s->buf_ptr;
- if (len > 0) {
- if (len > size)
- len = size;
- memcpy(buf, s->buf_ptr, len);
- s->buf_ptr += len;
- } else {
- len = url_read (s->hd, buf, size);
- if (len < 0) {
- return len;
- } else if (len == 0) {
- break;
- }
- }
- size -= len;
- buf += len;
- }
- return size1 - size;
-}
-
-/* used only when posting data */
-static int http_write(URLContext *h, uint8_t *buf, int size)
-{
- HTTPContext *s = h->priv_data;
- return url_write(s->hd, buf, size);
-}
-
-static int http_close(URLContext *h)
-{
- HTTPContext *s = h->priv_data;
- url_close(s->hd);
- av_free(s);
- return 0;
-}
-
-URLProtocol http_protocol = {
- "http",
- http_open,
- http_read,
- http_write,
- NULL, /* seek */
- http_close,
-};
-
+++ /dev/null
-/*
- * Id RoQ (.roq) File Demuxer
- * Copyright (c) 2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file idroq.c
- * Id RoQ format file demuxer
- * by Mike Melanson (melanson@pcisys.net)
- * for more information on the .roq file format, visit:
- * http://www.csse.monash.edu.au/~timf/
- */
-
-#include "avformat.h"
-
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-#define RoQ_MAGIC_NUMBER 0x1084
-#define RoQ_CHUNK_PREAMBLE_SIZE 8
-#define RoQ_AUDIO_SAMPLE_RATE 22050
-#define RoQ_CHUNKS_TO_SCAN 30
-
-#define RoQ_INFO 0x1001
-#define RoQ_QUAD_CODEBOOK 0x1002
-#define RoQ_QUAD_VQ 0x1011
-#define RoQ_SOUND_MONO 0x1020
-#define RoQ_SOUND_STEREO 0x1021
-
-typedef struct RoqDemuxContext {
-
- int width;
- int height;
- int audio_channels;
- int framerate;
- int frame_pts_inc;
-
- int video_stream_index;
- int audio_stream_index;
-
- int64_t video_pts;
- unsigned int audio_frame_count;
-
-} RoqDemuxContext;
-
-static int roq_probe(AVProbeData *p)
-{
- if (p->buf_size < 6)
- return 0;
-
- if ((LE_16(&p->buf[0]) != RoQ_MAGIC_NUMBER) ||
- (LE_32(&p->buf[2]) != 0xFFFFFFFF))
- return 0;
-
- return AVPROBE_SCORE_MAX;
-}
-
-static int roq_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- RoqDemuxContext *roq = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVStream *st;
- unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
- int i;
- unsigned int chunk_size;
- unsigned int chunk_type;
-
- /* get the main header */
- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
- RoQ_CHUNK_PREAMBLE_SIZE)
- return AVERROR_IO;
- roq->framerate = LE_16(&preamble[6]);
- roq->frame_pts_inc = 90000 / roq->framerate;
-
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
- /* init private context parameters */
- roq->width = roq->height = roq->audio_channels = roq->video_pts =
- roq->audio_frame_count = 0;
-
- /* scan the first n chunks searching for A/V parameters */
- for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) {
- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
- RoQ_CHUNK_PREAMBLE_SIZE)
- return AVERROR_IO;
-
- chunk_type = LE_16(&preamble[0]);
- chunk_size = LE_32(&preamble[2]);
-
- switch (chunk_type) {
-
- case RoQ_INFO:
- /* fetch the width and height; reuse the preamble bytes */
- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
- RoQ_CHUNK_PREAMBLE_SIZE)
- return AVERROR_IO;
- roq->width = LE_16(&preamble[0]);
- roq->height = LE_16(&preamble[2]);
- break;
-
- case RoQ_QUAD_CODEBOOK:
- case RoQ_QUAD_VQ:
- /* ignore during this scan */
- url_fseek(pb, chunk_size, SEEK_CUR);
- break;
-
- case RoQ_SOUND_MONO:
- roq->audio_channels = 1;
- url_fseek(pb, chunk_size, SEEK_CUR);
- break;
-
- case RoQ_SOUND_STEREO:
- roq->audio_channels = 2;
- url_fseek(pb, chunk_size, SEEK_CUR);
- break;
-
- default:
- printf (" unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
- return AVERROR_INVALIDDATA;
- break;
- }
-
- /* if all necessary parameters have been gathered, exit early */
- if ((roq->width && roq->height) && roq->audio_channels)
- break;
- }
-
- /* seek back to the first chunk */
- url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_SET);
-
- /* initialize the decoders */
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- roq->video_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_ROQ;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = roq->width;
- st->codec.height = roq->height;
-
- if (roq->audio_channels) {
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- roq->audio_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_ROQ_DPCM;
- st->codec.codec_tag = 0; /* no tag */
- st->codec.channels = roq->audio_channels;
- st->codec.sample_rate = RoQ_AUDIO_SAMPLE_RATE;
- st->codec.bits_per_sample = 16;
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
- st->codec.bits_per_sample;
- st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
- }
-
- return 0;
-}
-
-static int roq_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- RoqDemuxContext *roq = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int ret = 0;
- unsigned int chunk_size;
- unsigned int chunk_type;
- unsigned int codebook_size;
- unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
- int packet_read = 0;
- offset_t codebook_offset;
-
- while (!packet_read) {
-
- if (url_feof(&s->pb))
- return -EIO;
-
- /* get the next chunk preamble */
- if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) !=
- RoQ_CHUNK_PREAMBLE_SIZE)
- return -EIO;
-
- chunk_type = LE_16(&preamble[0]);
- chunk_size = LE_32(&preamble[2]);
-
- switch (chunk_type) {
-
- case RoQ_INFO:
- /* don't care about this chunk anymore */
- url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR);
- break;
-
- case RoQ_QUAD_CODEBOOK:
- /* packet needs to contain both this codebook and next VQ chunk */
- codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE;
- codebook_size = chunk_size;
- url_fseek(pb, codebook_size, SEEK_CUR);
- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
- RoQ_CHUNK_PREAMBLE_SIZE)
- return -EIO;
- chunk_size = LE_32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +
- codebook_size;
-
- /* rewind */
- url_fseek(pb, codebook_offset, SEEK_SET);
-
- /* load up the packet */
- if (av_new_packet(pkt, chunk_size))
- return -EIO;
- pkt->stream_index = roq->video_stream_index;
- pkt->pts = roq->video_pts;
- ret = get_buffer(pb, pkt->data, chunk_size);
- if (ret != chunk_size)
- ret = -EIO;
-
- roq->video_pts += roq->frame_pts_inc;
- packet_read = 1;
- break;
-
- case RoQ_SOUND_MONO:
- case RoQ_SOUND_STEREO:
- case RoQ_QUAD_VQ:
- /* load up the packet */
- if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))
- return -EIO;
- /* copy over preamble */
- memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);
-
- if (chunk_type == RoQ_QUAD_VQ) {
- pkt->stream_index = roq->video_stream_index;
- pkt->pts = roq->video_pts;
- roq->video_pts += roq->frame_pts_inc;
- } else {
- pkt->stream_index = roq->audio_stream_index;
- pkt->pts = roq->audio_frame_count;
- pkt->pts *= 90000;
- pkt->pts /= RoQ_AUDIO_SAMPLE_RATE;
- roq->audio_frame_count += (chunk_size / roq->audio_channels);
- }
-
- ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE,
- chunk_size);
- if (ret != chunk_size)
- ret = -EIO;
-
- packet_read = 1;
- break;
-
- default:
- printf (" unknown RoQ chunk (%04X)\n", chunk_type);
- return AVERROR_INVALIDDATA;
- break;
- }
- }
-
- return ret;
-}
-
-static int roq_read_close(AVFormatContext *s)
-{
-// RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data;
-
- return 0;
-}
-
-static AVInputFormat roq_iformat = {
- "RoQ",
- "Id RoQ format",
- sizeof(RoqDemuxContext),
- roq_probe,
- roq_read_header,
- roq_read_packet,
- roq_read_close,
-};
-
-int roq_init(void)
-{
- av_register_input_format(&roq_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * Image format
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* XXX: this is a hack */
-int loop_input = 0;
-
-typedef struct {
- int width;
- int height;
- int img_first;
- int img_last;
- int img_number;
- int img_count;
- int img_size;
- AVImageFormat *img_fmt;
- int pix_fmt;
- int is_pipe;
- char path[1024];
- /* temporary usage */
- void *ptr;
-} VideoData;
-
-
-/* return -1 if no image found */
-static int find_image_range(int *pfirst_index, int *plast_index,
- const char *path)
-{
- char buf[1024];
- int range, last_index, range1, first_index;
-
- /* find the first image */
- for(first_index = 0; first_index < 5; first_index++) {
- if (get_frame_filename(buf, sizeof(buf), path, first_index) < 0)
- goto fail;
- if (url_exist(buf))
- break;
- }
- if (first_index == 5)
- goto fail;
-
- /* find the last image */
- last_index = first_index;
- for(;;) {
- range = 0;
- for(;;) {
- if (!range)
- range1 = 1;
- else
- range1 = 2 * range;
- if (get_frame_filename(buf, sizeof(buf), path,
- last_index + range1) < 0)
- goto fail;
- if (!url_exist(buf))
- break;
- range = range1;
- /* just in case... */
- if (range >= (1 << 30))
- goto fail;
- }
- /* we are sure than image last_index + range exists */
- if (!range)
- break;
- last_index += range;
- }
- *pfirst_index = first_index;
- *plast_index = last_index;
- return 0;
- fail:
- return -1;
-}
-
-
-static int image_probe(AVProbeData *p)
-{
- if (filename_number_test(p->filename) >= 0 && guess_image_format(p->filename))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static int read_header_alloc_cb(void *opaque, AVImageInfo *info)
-{
- VideoData *s = opaque;
-
- s->width = info->width;
- s->height = info->height;
- s->pix_fmt = info->pix_fmt;
- /* stop image reading but no error */
- return 1;
-}
-
-static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
-{
- VideoData *s = s1->priv_data;
- int ret, first_index, last_index;
- char buf[1024];
- ByteIOContext pb1, *f = &pb1;
- AVStream *st;
-
- st = av_new_stream(s1, 0);
- if (!st) {
- av_free(s);
- return -ENOMEM;
- }
-
- if (ap && ap->image_format)
- s->img_fmt = ap->image_format;
-
- strcpy(s->path, s1->filename);
- s->img_number = 0;
- s->img_count = 0;
-
- /* find format */
- if (s1->iformat->flags & AVFMT_NOFILE)
- s->is_pipe = 0;
- else
- s->is_pipe = 1;
-
- if (!ap || !ap->frame_rate) {
- st->codec.frame_rate = 25;
- st->codec.frame_rate_base = 1;
- } else {
- st->codec.frame_rate = ap->frame_rate;
- st->codec.frame_rate_base = ap->frame_rate_base;
- }
-
- if (!s->is_pipe) {
- if (find_image_range(&first_index, &last_index, s->path) < 0)
- goto fail;
- s->img_first = first_index;
- s->img_last = last_index;
- s->img_number = first_index;
- /* compute duration */
- st->start_time = 0;
- st->duration = ((int64_t)AV_TIME_BASE *
- (last_index - first_index + 1) *
- st->codec.frame_rate_base) / st->codec.frame_rate;
- if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
- goto fail;
- if (url_fopen(f, buf, URL_RDONLY) < 0)
- goto fail;
- } else {
- f = &s1->pb;
- }
-
- ret = av_read_image(f, s1->filename, s->img_fmt, read_header_alloc_cb, s);
- if (ret < 0)
- goto fail1;
-
- if (!s->is_pipe) {
- url_fclose(f);
- } else {
- url_fseek(f, 0, SEEK_SET);
- }
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
- st->codec.width = s->width;
- st->codec.height = s->height;
- st->codec.pix_fmt = s->pix_fmt;
- s->img_size = avpicture_get_size(s->pix_fmt, s->width, s->height);
-
- return 0;
- fail1:
- if (!s->is_pipe)
- url_fclose(f);
- fail:
- av_free(s);
- return -EIO;
-}
-
-static int read_packet_alloc_cb(void *opaque, AVImageInfo *info)
-{
- VideoData *s = opaque;
-
- if (info->width != s->width ||
- info->height != s->height)
- return -1;
- avpicture_fill(&info->pict, s->ptr, info->pix_fmt, info->width, info->height);
- return 0;
-}
-
-static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- VideoData *s = s1->priv_data;
- char filename[1024];
- int ret;
- ByteIOContext f1, *f;
-
- if (!s->is_pipe) {
- /* loop over input */
- if (loop_input && s->img_number > s->img_last) {
- s->img_number = s->img_first;
- }
- if (get_frame_filename(filename, sizeof(filename),
- s->path, s->img_number) < 0)
- return -EIO;
- f = &f1;
- if (url_fopen(f, filename, URL_RDONLY) < 0)
- return -EIO;
- } else {
- f = &s1->pb;
- if (url_feof(f))
- return -EIO;
- }
-
- av_new_packet(pkt, s->img_size);
- pkt->stream_index = 0;
-
- s->ptr = pkt->data;
- ret = av_read_image(f, filename, s->img_fmt, read_packet_alloc_cb, s);
- if (!s->is_pipe) {
- url_fclose(f);
- }
-
- if (ret < 0) {
- av_free_packet(pkt);
- return -EIO; /* signal EOF */
- } else {
- /* XXX: computing this pts is not necessary as it is done in
- the generic code too */
- pkt->pts = av_rescale((int64_t)s->img_count * s1->streams[0]->codec.frame_rate_base, s1->pts_den, s1->streams[0]->codec.frame_rate) / s1->pts_num;
- s->img_count++;
- s->img_number++;
- return 0;
- }
-}
-
-static int img_read_close(AVFormatContext *s1)
-{
- return 0;
-}
-
-/******************************************************/
-/* image output */
-
-static int img_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
-{
- VideoData *img = s->priv_data;
- AVStream *st;
- AVImageFormat *img_fmt;
- int i;
-
- /* find output image format */
- if (ap && ap->image_format) {
- img_fmt = ap->image_format;
- } else {
- img_fmt = guess_image_format(s->filename);
- }
- if (!img_fmt)
- return -1;
-
- if (s->nb_streams != 1)
- return -1;
-
- st = s->streams[0];
- /* we select the first matching format */
- for(i=0;i<PIX_FMT_NB;i++) {
- if (img_fmt->supported_pixel_formats & (1 << i))
- break;
- }
- if (i >= PIX_FMT_NB)
- return -1;
- img->img_fmt = img_fmt;
- img->pix_fmt = i;
- st->codec.pix_fmt = img->pix_fmt;
- return 0;
-}
-
-static int img_write_header(AVFormatContext *s)
-{
- VideoData *img = s->priv_data;
-
- img->img_number = 1;
- strcpy(img->path, s->filename);
-
- /* find format */
- if (s->oformat->flags & AVFMT_NOFILE)
- img->is_pipe = 0;
- else
- img->is_pipe = 1;
-
- return 0;
-}
-
-static int img_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- VideoData *img = s->priv_data;
- AVStream *st = s->streams[stream_index];
- ByteIOContext pb1, *pb;
- AVPicture *picture;
- int width, height, ret;
- char filename[1024];
- AVImageInfo info;
-
- width = st->codec.width;
- height = st->codec.height;
-
- picture = (AVPicture *)buf;
-
- if (!img->is_pipe) {
- if (get_frame_filename(filename, sizeof(filename),
- img->path, img->img_number) < 0)
- return -EIO;
- pb = &pb1;
- if (url_fopen(pb, filename, URL_WRONLY) < 0)
- return -EIO;
- } else {
- pb = &s->pb;
- }
- info.width = width;
- info.height = height;
- info.pix_fmt = st->codec.pix_fmt;
- info.pict = *picture;
- ret = av_write_image(pb, img->img_fmt, &info);
- if (!img->is_pipe) {
- url_fclose(pb);
- }
-
- img->img_number++;
- return 0;
-}
-
-static int img_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-/* input */
-
-static AVInputFormat image_iformat = {
- "image",
- "image sequence",
- sizeof(VideoData),
- image_probe,
- img_read_header,
- img_read_packet,
- img_read_close,
- NULL,
- AVFMT_NOFILE | AVFMT_NEEDNUMBER,
-};
-
-static AVInputFormat imagepipe_iformat = {
- "imagepipe",
- "piped image sequence",
- sizeof(VideoData),
- NULL, /* no probe */
- img_read_header,
- img_read_packet,
- img_read_close,
- NULL,
-};
-
-
-/* output */
-
-static AVOutputFormat image_oformat = {
- "image",
- "image sequence",
- "",
- "",
- sizeof(VideoData),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- img_write_header,
- img_write_packet,
- img_write_trailer,
- AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RAWPICTURE,
- img_set_parameters,
-};
-
-static AVOutputFormat imagepipe_oformat = {
- "imagepipe",
- "piped image sequence",
- "",
- "",
- sizeof(VideoData),
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- img_write_header,
- img_write_packet,
- img_write_trailer,
- AVFMT_RAWPICTURE,
- img_set_parameters,
-};
-
-int img_init(void)
-{
- av_register_input_format(&image_iformat);
- av_register_output_format(&image_oformat);
-
- av_register_input_format(&imagepipe_iformat);
- av_register_output_format(&imagepipe_oformat);
-
- return 0;
-}
+++ /dev/null
-/*
- * Interplay MVE File Demuxer
- * Copyright (c) 2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file ipmovie.c
- * Interplay MVE file demuxer
- * by Mike Melanson (melanson@pcisys.net)
- * For more information regarding the Interplay MVE file format, visit:
- * http://www.pcisys.net/~melanson/codecs/
- * The aforementioned site also contains a command line utility for parsing
- * IP MVE files so that you can get a good idea of the typical structure of
- * such files. This demuxer is not the best example to use if you are trying
- * to write your own as it uses a rather roundabout approach for splitting
- * up and sending out the chunks.
- */
-
-#include "avformat.h"
-
-/* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely
- * verbose information about the demux process */
-#define DEBUG_IPMOVIE 0
-
-#if DEBUG_IPMOVIE
-#define debug_ipmovie printf
-#else
-static inline void debug_ipmovie(const char *format, ...) { }
-#endif
-
-
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-#define IPMOVIE_SIGNATURE "Interplay MVE File\x1A\0"
-#define IPMOVIE_SIGNATURE_SIZE 20
-#define CHUNK_PREAMBLE_SIZE 4
-#define OPCODE_PREAMBLE_SIZE 4
-
-#define CHUNK_INIT_AUDIO 0x0000
-#define CHUNK_AUDIO_ONLY 0x0001
-#define CHUNK_INIT_VIDEO 0x0002
-#define CHUNK_VIDEO 0x0003
-#define CHUNK_SHUTDOWN 0x0004
-#define CHUNK_END 0x0005
-/* these last types are used internally */
-#define CHUNK_DONE 0xFFFC
-#define CHUNK_NOMEM 0xFFFD
-#define CHUNK_EOF 0xFFFE
-#define CHUNK_BAD 0xFFFF
-
-#define OPCODE_END_OF_STREAM 0x00
-#define OPCODE_END_OF_CHUNK 0x01
-#define OPCODE_CREATE_TIMER 0x02
-#define OPCODE_INIT_AUDIO_BUFFERS 0x03
-#define OPCODE_START_STOP_AUDIO 0x04
-#define OPCODE_INIT_VIDEO_BUFFERS 0x05
-#define OPCODE_UNKNOWN_06 0x06
-#define OPCODE_SEND_BUFFER 0x07
-#define OPCODE_AUDIO_FRAME 0x08
-#define OPCODE_SILENCE_FRAME 0x09
-#define OPCODE_INIT_VIDEO_MODE 0x0A
-#define OPCODE_CREATE_GRADIENT 0x0B
-#define OPCODE_SET_PALETTE 0x0C
-#define OPCODE_SET_PALETTE_COMPRESSED 0x0D
-#define OPCODE_UNKNOWN_0E 0x0E
-#define OPCODE_SET_DECODING_MAP 0x0F
-#define OPCODE_UNKNOWN_10 0x10
-#define OPCODE_VIDEO_DATA 0x11
-#define OPCODE_UNKNOWN_12 0x12
-#define OPCODE_UNKNOWN_13 0x13
-#define OPCODE_UNKNOWN_14 0x14
-#define OPCODE_UNKNOWN_15 0x15
-
-#define PALETTE_COUNT 256
-
-typedef struct IPMVEContext {
-
- unsigned char *buf;
- int buf_size;
-
- int fps;
- int frame_pts_inc;
-
- unsigned int video_width;
- unsigned int video_height;
- int64_t video_pts;
-
- unsigned int audio_bits;
- unsigned int audio_channels;
- unsigned int audio_sample_rate;
- unsigned int audio_type;
- unsigned int audio_frame_count;
-
- int video_stream_index;
- int audio_stream_index;
-
- offset_t audio_chunk_offset;
- int audio_chunk_size;
- offset_t video_chunk_offset;
- int video_chunk_size;
- offset_t decode_map_chunk_offset;
- int decode_map_chunk_size;
-
- offset_t next_chunk_offset;
-
- AVPaletteControl palette_control;
-
-} IPMVEContext;
-
-static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb,
- AVPacket *pkt) {
-
- int chunk_type;
- int64_t audio_pts = 0;
-
- if (s->audio_chunk_offset) {
-
- /* adjust for PCM audio by skipping chunk header */
- if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) {
- s->audio_chunk_offset += 6;
- s->audio_chunk_size -= 6;
- }
-
- url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
- s->audio_chunk_offset = 0;
-
- /* figure out the audio pts */
- audio_pts = 90000;
- audio_pts *= s->audio_frame_count;
- audio_pts /= s->audio_sample_rate;
-
- if (av_new_packet(pkt, s->audio_chunk_size))
- return CHUNK_NOMEM;
-
- pkt->stream_index = s->audio_stream_index;
- pkt->pts = audio_pts;
- if (get_buffer(pb, pkt->data, s->audio_chunk_size) !=
- s->audio_chunk_size) {
- av_free_packet(pkt);
- return CHUNK_EOF;
- }
-
- /* audio frame maintenance */
- if (s->audio_type != CODEC_ID_INTERPLAY_DPCM)
- s->audio_frame_count +=
- (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8));
- else
- s->audio_frame_count +=
- (s->audio_chunk_size - 6) / s->audio_channels;
-
- debug_ipmovie("sending audio frame with pts %lld (%d audio frames)\n",
- audio_pts, s->audio_frame_count);
-
- chunk_type = CHUNK_VIDEO;
-
- } else if (s->decode_map_chunk_offset) {
-
- /* send both the decode map and the video data together */
-
- if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size))
- return CHUNK_NOMEM;
-
- url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
- s->decode_map_chunk_offset = 0;
-
- if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) !=
- s->decode_map_chunk_size) {
- av_free_packet(pkt);
- return CHUNK_EOF;
- }
-
- url_fseek(pb, s->video_chunk_offset, SEEK_SET);
- s->video_chunk_offset = 0;
-
- if (get_buffer(pb, pkt->data + s->decode_map_chunk_size,
- s->video_chunk_size) != s->video_chunk_size) {
- av_free_packet(pkt);
- return CHUNK_EOF;
- }
-
- pkt->stream_index = s->video_stream_index;
- pkt->pts = s->video_pts;
-
- s->video_pts += s->frame_pts_inc;
-
- chunk_type = CHUNK_VIDEO;
-
- } else {
-
- url_fseek(pb, s->next_chunk_offset, SEEK_SET);
- chunk_type = CHUNK_DONE;
-
- }
-
- return chunk_type;
-}
-
-/* This function loads and processes a single chunk in an IP movie file.
- * It returns the type of chunk that was processed. */
-static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
- AVPacket *pkt)
-{
- unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
- int chunk_type;
- int chunk_size;
- unsigned char opcode_preamble[OPCODE_PREAMBLE_SIZE];
- unsigned char opcode_type;
- unsigned char opcode_version;
- int opcode_size;
- unsigned char scratch[1024];
- int i, j;
- int first_color, last_color;
- int audio_flags;
-
- /* see if there are any pending packets */
- chunk_type = load_ipmovie_packet(s, pb, pkt);
- if ((chunk_type == CHUNK_VIDEO) && (chunk_type != CHUNK_DONE))
- return chunk_type;
-
- /* read the next chunk, wherever the file happens to be pointing */
- if (url_feof(pb))
- return CHUNK_EOF;
- if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
- CHUNK_PREAMBLE_SIZE)
- return CHUNK_BAD;
- chunk_size = LE_16(&chunk_preamble[0]);
- chunk_type = LE_16(&chunk_preamble[2]);
-
- debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size);
-
- switch (chunk_type) {
-
- case CHUNK_INIT_AUDIO:
- debug_ipmovie("initialize audio\n");
- break;
-
- case CHUNK_AUDIO_ONLY:
- debug_ipmovie("audio only\n");
- break;
-
- case CHUNK_INIT_VIDEO:
- debug_ipmovie("initialize video\n");
- break;
-
- case CHUNK_VIDEO:
- debug_ipmovie("video (and audio)\n");
- break;
-
- case CHUNK_SHUTDOWN:
- debug_ipmovie("shutdown\n");
- break;
-
- case CHUNK_END:
- debug_ipmovie("end\n");
- break;
-
- default:
- debug_ipmovie("invalid chunk\n");
- chunk_type = CHUNK_BAD;
- break;
-
- }
-
- while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
-
- /* read the next chunk, wherever the file happens to be pointing */
- if (url_feof(pb)) {
- chunk_type = CHUNK_EOF;
- break;
- }
- if (get_buffer(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
- CHUNK_PREAMBLE_SIZE) {
- chunk_type = CHUNK_BAD;
- break;
- }
-
- opcode_size = LE_16(&opcode_preamble[0]);
- opcode_type = opcode_preamble[2];
- opcode_version = opcode_preamble[3];
-
- chunk_size -= OPCODE_PREAMBLE_SIZE;
- chunk_size -= opcode_size;
- if (chunk_size < 0) {
- debug_ipmovie("chunk_size countdown just went negative\n");
- chunk_type = CHUNK_BAD;
- break;
- }
-
- debug_ipmovie(" opcode type %02X, version %d, 0x%04X bytes: ",
- opcode_type, opcode_version, opcode_size);
- switch (opcode_type) {
-
- case OPCODE_END_OF_STREAM:
- debug_ipmovie("end of stream\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_END_OF_CHUNK:
- debug_ipmovie("end of chunk\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_CREATE_TIMER:
- debug_ipmovie("create timer\n");
- if ((opcode_version > 0) || (opcode_size > 6)) {
- debug_ipmovie("bad create_timer opcode\n");
- chunk_type = CHUNK_BAD;
- break;
- }
- if (get_buffer(pb, scratch, opcode_size) !=
- opcode_size) {
- chunk_type = CHUNK_BAD;
- break;
- }
- s->fps = 1000000 / (LE_32(&scratch[0]) * LE_16(&scratch[4]));
- s->fps++; /* above calculation usually yields 14.9; we need 15 */
- s->frame_pts_inc = 90000 / s->fps;
- debug_ipmovie("%d frames/second (timer div = %d, subdiv = %d)\n",
- s->fps, LE_32(&scratch[0]), LE_16(&scratch[4]));
- break;
-
- case OPCODE_INIT_AUDIO_BUFFERS:
- debug_ipmovie("initialize audio buffers\n");
- if ((opcode_version > 1) || (opcode_size > 10)) {
- debug_ipmovie("bad init_audio_buffers opcode\n");
- chunk_type = CHUNK_BAD;
- break;
- }
- if (get_buffer(pb, scratch, opcode_size) !=
- opcode_size) {
- chunk_type = CHUNK_BAD;
- break;
- }
- s->audio_sample_rate = LE_16(&scratch[4]);
- audio_flags = LE_16(&scratch[2]);
- /* bit 0 of the flags: 0 = mono, 1 = stereo */
- s->audio_channels = (audio_flags & 1) + 1;
- /* bit 1 of the flags: 0 = 8 bit, 1 = 16 bit */
- s->audio_bits = (((audio_flags >> 1) & 1) + 1) * 8;
- /* bit 2 indicates compressed audio in version 1 opcode */
- if ((opcode_version == 1) && (audio_flags & 0x4))
- s->audio_type = CODEC_ID_INTERPLAY_DPCM;
- else if (s->audio_bits == 16)
- s->audio_type = CODEC_ID_PCM_S16LE;
- else
- s->audio_type = CODEC_ID_PCM_U8;
- debug_ipmovie("audio: %d bits, %d Hz, %s, %s format\n",
- s->audio_bits,
- s->audio_sample_rate,
- (s->audio_channels == 2) ? "stereo" : "mono",
- (s->audio_type == CODEC_ID_INTERPLAY_DPCM) ?
- "Interplay audio" : "PCM");
- break;
-
- case OPCODE_START_STOP_AUDIO:
- debug_ipmovie("start/stop audio\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_INIT_VIDEO_BUFFERS:
- debug_ipmovie("initialize video buffers\n");
- if ((opcode_version > 2) || (opcode_size > 8)) {
- debug_ipmovie("bad init_video_buffers opcode\n");
- chunk_type = CHUNK_BAD;
- break;
- }
- if (get_buffer(pb, scratch, opcode_size) !=
- opcode_size) {
- chunk_type = CHUNK_BAD;
- break;
- }
- s->video_width = LE_16(&scratch[0]) * 8;
- s->video_height = LE_16(&scratch[2]) * 8;
- debug_ipmovie("video resolution: %d x %d\n",
- s->video_width, s->video_height);
- break;
-
- case OPCODE_UNKNOWN_06:
- case OPCODE_UNKNOWN_0E:
- case OPCODE_UNKNOWN_10:
- case OPCODE_UNKNOWN_12:
- case OPCODE_UNKNOWN_13:
- case OPCODE_UNKNOWN_14:
- case OPCODE_UNKNOWN_15:
- debug_ipmovie("unknown (but documented) opcode %02X\n", opcode_type);
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_SEND_BUFFER:
- debug_ipmovie("send buffer\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_AUDIO_FRAME:
- debug_ipmovie("audio frame\n");
-
- /* log position and move on for now */
- s->audio_chunk_offset = url_ftell(pb);
- s->audio_chunk_size = opcode_size;
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_SILENCE_FRAME:
- debug_ipmovie("silence frame\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_INIT_VIDEO_MODE:
- debug_ipmovie("initialize video mode\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_CREATE_GRADIENT:
- debug_ipmovie("create gradient\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_SET_PALETTE:
- debug_ipmovie("set palette\n");
- /* check for the logical maximum palette size
- * (3 * 256 + 4 bytes) */
- if (opcode_size > 0x304) {
- debug_ipmovie("demux_ipmovie: set_palette opcode too large\n");
- chunk_type = CHUNK_BAD;
- break;
- }
- if (get_buffer(pb, scratch, opcode_size) != opcode_size) {
- chunk_type = CHUNK_BAD;
- break;
- }
-
- /* load the palette into internal data structure */
- first_color = LE_16(&scratch[0]);
- last_color = first_color + LE_16(&scratch[2]);
- /* sanity check (since they are 16 bit values) */
- if ((first_color > 0xFF) || (last_color > 0xFF)) {
- debug_ipmovie("demux_ipmovie: set_palette indices out of range (%d -> %d)\n",
- first_color, last_color);
- chunk_type = CHUNK_BAD;
- break;
- }
- j = 4; /* offset of first palette data */
- for (i = first_color; i <= last_color; i++) {
- /* the palette is stored as a 6-bit VGA palette, thus each
- * component is shifted up to a 8-bit range */
- s->palette_control.palette[i * 3 + 0] = scratch[j++] * 4;
- s->palette_control.palette[i * 3 + 1] = scratch[j++] * 4;
- s->palette_control.palette[i * 3 + 2] = scratch[j++] * 4;
- }
- /* indicate a palette change */
- s->palette_control.palette_changed = 1;
- break;
-
- case OPCODE_SET_PALETTE_COMPRESSED:
- debug_ipmovie("set palette compressed\n");
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_SET_DECODING_MAP:
- debug_ipmovie("set decoding map\n");
-
- /* log position and move on for now */
- s->decode_map_chunk_offset = url_ftell(pb);
- s->decode_map_chunk_size = opcode_size;
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- case OPCODE_VIDEO_DATA:
- debug_ipmovie("set video data\n");
-
- /* log position and move on for now */
- s->video_chunk_offset = url_ftell(pb);
- s->video_chunk_size = opcode_size;
- url_fseek(pb, opcode_size, SEEK_CUR);
- break;
-
- default:
- debug_ipmovie("*** unknown opcode type\n");
- chunk_type = CHUNK_BAD;
- break;
-
- }
- }
-
- /* make a note of where the stream is sitting */
- s->next_chunk_offset = url_ftell(pb);
-
- /* dispatch the first of any pending packets */
- if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY))
- chunk_type = load_ipmovie_packet(s, pb, pkt);
-
- return chunk_type;
-}
-
-static int ipmovie_probe(AVProbeData *p)
-{
- if (p->buf_size < IPMOVIE_SIGNATURE_SIZE)
- return 0;
- if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0)
- return 0;
-
- return AVPROBE_SCORE_MAX;
-}
-
-static int ipmovie_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVPacket pkt;
- AVStream *st;
-
- /* initialize private context members */
- ipmovie->video_pts = ipmovie->audio_frame_count = 0;
- ipmovie->audio_chunk_offset = ipmovie->video_chunk_offset =
- ipmovie->decode_map_chunk_offset = 0;
-
- /* on the first read, this will position the stream at the first chunk */
- ipmovie->next_chunk_offset = IPMOVIE_SIGNATURE_SIZE + 6;
-
- /* process the first chunk which should be CHUNK_INIT_VIDEO */
- if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
- return AVERROR_INVALIDDATA;
-
- /* process the next chunk which should be CHUNK_INIT_AUDIO */
- if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
- return AVERROR_INVALIDDATA;
-
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
- /* initialize the stream decoders */
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- ipmovie->video_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_INTERPLAY_VIDEO;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = ipmovie->video_width;
- st->codec.height = ipmovie->video_height;
-
- /* palette considerations */
- st->codec.extradata_size = sizeof(AVPaletteControl);
- st->codec.extradata = &ipmovie->palette_control;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- ipmovie->audio_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = ipmovie->audio_type;
- st->codec.codec_tag = 0; /* no tag */
- st->codec.channels = ipmovie->audio_channels;
- st->codec.sample_rate = ipmovie->audio_sample_rate;
- st->codec.bits_per_sample = ipmovie->audio_bits;
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
- st->codec.bits_per_sample;
- if (st->codec.codec_id == CODEC_ID_INTERPLAY_DPCM)
- st->codec.bit_rate /= 2;
- st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
-
- return 0;
-}
-
-static int ipmovie_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
- ByteIOContext *pb = &s->pb;
- int ret;
-
- ret = process_ipmovie_chunk(ipmovie, pb, pkt);
- if (ret == CHUNK_BAD)
- ret = AVERROR_INVALIDDATA;
- else if (ret == CHUNK_EOF)
- ret = -EIO;
- else if (ret == CHUNK_NOMEM)
- ret = AVERROR_NOMEM;
- else
- ret = 0;
-
- return ret;
-}
-
-static int ipmovie_read_close(AVFormatContext *s)
-{
-// IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data;
-
- return 0;
-}
-
-static AVInputFormat ipmovie_iformat = {
- "ipmovie",
- "Interplay MVE format",
- sizeof(IPMVEContext),
- ipmovie_probe,
- ipmovie_read_header,
- ipmovie_read_packet,
- ipmovie_read_close,
-};
-
-int ipmovie_init(void)
-{
- av_register_input_format(&ipmovie_iformat);
- return 0;
-}
-
+++ /dev/null
-/*
- * JPEG image format
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-static int jpeg_probe(AVProbeData *pd)
-{
- if (pd->buf_size >= 64 &&
- pd->buf[0] == 0xff && pd->buf[1] == 0xd8 && pd->buf[2] == 0xff)
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-typedef struct JpegOpaque {
- int (*alloc_cb)(void *opaque, AVImageInfo *info);
- void *opaque;
- int ret_code;
-} JpegOpaque;
-
-/* called by the codec to allocate the image */
-static int jpeg_get_buffer(AVCodecContext *c, AVFrame *picture)
-{
- JpegOpaque *jctx = c->opaque;
- AVImageInfo info1, *info = &info1;
- int ret, i;
-
- info->width = c->width;
- info->height = c->height;
- switch(c->pix_fmt) {
- case PIX_FMT_YUV420P:
- info->pix_fmt = PIX_FMT_YUVJ420P;
- break;
- case PIX_FMT_YUV422P:
- info->pix_fmt = PIX_FMT_YUVJ422P;
- break;
- case PIX_FMT_YUV444P:
- info->pix_fmt = PIX_FMT_YUVJ444P;
- break;
- default:
- return -1;
- }
- ret = jctx->alloc_cb(jctx->opaque, info);
- if (ret) {
- jctx->ret_code = ret;
- return -1;
- } else {
- for(i=0;i<3;i++) {
- picture->data[i] = info->pict.data[i];
- picture->linesize[i] = info->pict.linesize[i];
- }
- return 0;
- }
-}
-
-static void img_copy(uint8_t *dst, int dst_wrap,
- uint8_t *src, int src_wrap,
- int width, int height)
-{
- for(;height > 0; height--) {
- memcpy(dst, src, width);
- dst += dst_wrap;
- src += src_wrap;
- }
-}
-
-/* XXX: libavcodec is broken for truncated jpegs! */
-#define IO_BUF_SIZE (1024*1024)
-
-static int jpeg_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- AVCodecContext *c;
- AVFrame *picture, picture1;
- int len, size, got_picture, i;
- uint8_t *inbuf_ptr, inbuf[IO_BUF_SIZE];
- JpegOpaque jctx;
-
- jctx.alloc_cb = alloc_cb;
- jctx.opaque = opaque;
- jctx.ret_code = -1; /* default return code is error */
-
- c = avcodec_alloc_context();
- if (!c)
- return -1;
- picture= avcodec_alloc_frame();
- if (!picture) {
- av_free(c);
- return -1;
- }
- c->opaque = &jctx;
- c->get_buffer = jpeg_get_buffer;
- c->flags |= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
- if (avcodec_open(c, &mjpeg_decoder) < 0)
- goto fail1;
- for(;;) {
- size = get_buffer(f, inbuf, sizeof(inbuf));
- if (size == 0)
- break;
- inbuf_ptr = inbuf;
- while (size > 0) {
- len = avcodec_decode_video(c, &picture1, &got_picture,
- inbuf_ptr, size);
- if (len < 0)
- goto fail;
- if (got_picture)
- goto the_end;
- size -= len;
- inbuf_ptr += len;
- }
- }
- the_end:
- /* XXX: currently, the mjpeg decoder does not use AVFrame, so we
- must do it by hand */
- if (jpeg_get_buffer(c, picture) < 0)
- goto fail;
- for(i=0;i<3;i++) {
- int w, h;
- w = c->width;
- h = c->height;
- if (i >= 1) {
- switch(c->pix_fmt) {
- default:
- case PIX_FMT_YUV420P:
- w = (w + 1) >> 1;
- h = (h + 1) >> 1;
- break;
- case PIX_FMT_YUV422P:
- w = (w + 1) >> 1;
- break;
- case PIX_FMT_YUV444P:
- break;
- }
- }
- img_copy(picture->data[i], picture->linesize[i],
- picture1.data[i], picture1.linesize[i],
- w, h);
- }
- jctx.ret_code = 0;
- fail:
- avcodec_close(c);
- fail1:
- av_free(picture);
- av_free(c);
- return jctx.ret_code;
-}
-
-#ifdef CONFIG_ENCODERS
-static int jpeg_write(ByteIOContext *pb, AVImageInfo *info)
-{
- AVCodecContext *c;
- uint8_t *outbuf = NULL;
- int outbuf_size, ret, size, i;
- AVFrame *picture;
-
- ret = -1;
- c = avcodec_alloc_context();
- if (!c)
- return -1;
- picture = avcodec_alloc_frame();
- if (!picture)
- goto fail2;
- c->width = info->width;
- c->height = info->height;
- /* XXX: currently move that to the codec ? */
- switch(info->pix_fmt) {
- case PIX_FMT_YUVJ420P:
- c->pix_fmt = PIX_FMT_YUV420P;
- break;
- case PIX_FMT_YUVJ422P:
- c->pix_fmt = PIX_FMT_YUV422P;
- break;
- case PIX_FMT_YUVJ444P:
- c->pix_fmt = PIX_FMT_YUV444P;
- break;
- default:
- goto fail1;
- }
- for(i=0;i<3;i++) {
- picture->data[i] = info->pict.data[i];
- picture->linesize[i] = info->pict.linesize[i];
- }
- /* set the quality */
- picture->quality = 3; /* XXX: a parameter should be used */
- c->flags |= CODEC_FLAG_QSCALE;
-
- if (avcodec_open(c, &mjpeg_encoder) < 0)
- goto fail1;
-
- /* XXX: needs to sort out that size problem */
- outbuf_size = 1000000;
- outbuf = av_malloc(outbuf_size);
-
- size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
- if (size < 0)
- goto fail;
- put_buffer(pb, outbuf, size);
- put_flush_packet(pb);
- ret = 0;
-
- fail:
- avcodec_close(c);
- av_free(outbuf);
- fail1:
- av_free(picture);
- fail2:
- av_free(c);
- return ret;
-}
-#endif //CONFIG_ENCODERS
-
-AVImageFormat jpeg_image_format = {
- "jpeg",
- "jpg,jpeg",
- jpeg_probe,
- jpeg_read,
- (1 << PIX_FMT_YUVJ420P) | (1 << PIX_FMT_YUVJ422P) | (1 << PIX_FMT_YUVJ444P),
-#ifdef CONFIG_ENCODERS
- jpeg_write,
-#else
- NULL,
-#endif //CONFIG_ENCODERS
-};
+++ /dev/null
-/*
- * MOV decoder.
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-#endif
-
-/*
- * First version by Francois Revol revol@free.fr
- *
- * Features and limitations:
- * - reads most of the QT files I have (at least the structure),
- * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement.
- * FIXED, Francois Revol, 07/17/2002
- * - ffmpeg has nearly none of the usual QuickTime codecs,
- * although I succesfully dumped raw and mp3 audio tracks off .mov files.
- * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
- * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes
- * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at
- * http://mpeg.telecomitalialab.com/faq.htm
- * - the code is quite ugly... maybe I won't do it recursive next time :-)
- *
- * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/
- * when coding this :) (it's a writer anyway)
- *
- * Reference documents:
- * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
- * Apple:
- * http://developer.apple.com/techpubs/quicktime/qtdevdocs/QTFF/qtff.html
- * http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
- * QuickTime is a trademark of Apple (AFAIK :))
- */
-
-//#define DEBUG
-#ifdef DEBUG
-#include <stdio.h>
-#include <fcntl.h>
-#endif
-
-/* allows chunk splitting - should work now... */
-/* in case you can't read a file, try commenting */
-#define MOV_SPLIT_CHUNKS
-
-/* Special handling for movies created with Minolta Dimaxe Xi*/
-/* this fix should not interfere with other .mov files, but just in case*/
-#define MOV_MINOLTA_FIX
-
-/* some streams in QT (and in MP4 mostly) aren't either video nor audio */
-/* so we first list them as this, then clean up the list of streams we give back, */
-/* getting rid of these */
-#define CODEC_TYPE_MOV_OTHER (enum CodecType) 2
-
-static const CodecTag mov_video_tags[] = {
-/* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
-/* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
-/* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
-/* { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'U', 'I') }, *//* YUV with alpha-channel (AVID Uncompressed) */
-/* Graphics */
-/* Animation */
-/* Apple video */
-/* Kodak Photo CD */
- { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
- { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
- { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */
- { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
- { CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') }, /* MJPEG with alpha-channel (AVID JFIF meridien compressed) */
-/* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */
-/* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */
-/* Sorenson video */
- { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
- { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
- { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/
- { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') }, /* Sorenson Video v3 */
- { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
- { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
-/* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
- { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
- { CODEC_ID_H263, MKTAG('s', '2', '6', '3') }, /* H263 ?? works */
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */
- { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */
-/* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */
- { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */
- { CODEC_ID_NONE, 0 },
-};
-
-static const CodecTag mov_audio_tags[] = {
-/* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
- { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
- /* { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') },*/ /* 8 bits */
- { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */
- { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
- { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
- { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
- { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
- { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */
- { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */
-
- { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
- { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */
- { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */
-/* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
-/* MP4 tags */
- { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG 4 AAC or audio ? */
- /* The standard for mpeg4 audio is still not normalised AFAIK anyway */
- { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */
- { CODEC_ID_NONE, 0 },
-};
-
-/* the QuickTime file format is quite convoluted...
- * it has lots of index tables, each indexing something in another one...
- * Here we just use what is needed to read the chunks
- */
-
-typedef struct MOV_sample_to_chunk_tbl {
- long first;
- long count;
- long id;
-} MOV_sample_to_chunk_tbl;
-
-typedef struct {
- uint32_t type;
- int64_t offset;
- int64_t size; /* total size (excluding the size and type fields) */
-} MOV_atom_t;
-
-typedef struct {
- int seed;
- int flags;
- int size;
- void* clrs;
-} MOV_ctab_t;
-
-typedef struct {
- uint8_t version;
- uint32_t flags; // 24bit
-
- /* 0x03 ESDescrTag */
- uint16_t es_id;
-#define MP4ODescrTag 0x01
-#define MP4IODescrTag 0x02
-#define MP4ESDescrTag 0x03
-#define MP4DecConfigDescrTag 0x04
-#define MP4DecSpecificDescrTag 0x05
-#define MP4SLConfigDescrTag 0x06
-#define MP4ContentIdDescrTag 0x07
-#define MP4SupplContentIdDescrTag 0x08
-#define MP4IPIPtrDescrTag 0x09
-#define MP4IPMPPtrDescrTag 0x0A
-#define MP4IPMPDescrTag 0x0B
-#define MP4RegistrationDescrTag 0x0D
-#define MP4ESIDIncDescrTag 0x0E
-#define MP4ESIDRefDescrTag 0x0F
-#define MP4FileIODescrTag 0x10
-#define MP4FileODescrTag 0x11
-#define MP4ExtProfileLevelDescrTag 0x13
-#define MP4ExtDescrTagsStart 0x80
-#define MP4ExtDescrTagsEnd 0xFE
- uint8_t stream_priority;
-
- /* 0x04 DecConfigDescrTag */
- uint8_t object_type_id;
- uint8_t stream_type;
- /* XXX: really streamType is
- * only 6bit, followed by:
- * 1bit upStream
- * 1bit reserved
- */
- uint32_t buffer_size_db; // 24
- uint32_t max_bitrate;
- uint32_t avg_bitrate;
-
- /* 0x05 DecSpecificDescrTag */
- uint8_t decoder_cfg_len;
- uint8_t *decoder_cfg;
-
- /* 0x06 SLConfigDescrTag */
- uint8_t sl_config_len;
- uint8_t *sl_config;
-} MOV_esds_t;
-
-struct MOVParseTableEntry;
-
-typedef struct MOVStreamContext {
- int ffindex; /* the ffmpeg stream id */
- int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
- long next_chunk;
- long chunk_count;
- int64_t *chunk_offsets;
- long sample_to_chunk_sz;
- MOV_sample_to_chunk_tbl *sample_to_chunk;
- long sample_to_chunk_index;
- long sample_size;
- long sample_count;
- long *sample_sizes;
- int time_scale;
- long current_sample;
- long left_in_chunk; /* how many samples before next chunk */
- /* specific MPEG4 header which is added at the beginning of the stream */
- int header_len;
- uint8_t *header_data;
- MOV_esds_t esds;
-} MOVStreamContext;
-
-typedef struct MOVContext {
- int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
- AVFormatContext *fc;
- int time_scale;
- int duration; /* duration of the longest track */
- int found_moov; /* when both 'moov' and 'mdat' sections has been found */
- int found_mdat; /* we suppose we have enough data to read the file */
- int64_t mdat_size;
- int64_t mdat_offset;
- int total_streams;
- /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio
- * but we need the info to be able to skip data from those streams in the 'mdat' section
- */
- MOVStreamContext *streams[MAX_STREAMS];
-
- int64_t next_chunk_offset;
- MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */
- int ctab_size;
- MOV_ctab_t **ctab; /* color tables */
- const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */
- /* NOTE: for recursion save to/ restore from local variable! */
-} MOVContext;
-
-
-/* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
-
-/* those functions parse an atom */
-/* return code:
- 1: found what I wanted, exit
- 0: continue to parse next atom
- -1: error occured, exit
- */
-typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom);
-
-/* links atom IDs to parse functions */
-typedef struct MOVParseTableEntry {
- uint32_t type;
- mov_parse_function func;
-} MOVParseTableEntry;
-
-#ifdef DEBUG
-/*
- * XXX: static sux, even more in a multithreaded environment...
- * Avoid them. This is here just to help debugging.
- */
-static int debug_indent = 0;
-void print_atom(const char *str, MOV_atom_t atom)
-{
- unsigned int tag, i;
- tag = (unsigned int) atom.type;
- i=debug_indent;
- if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L');
- while(i--)
- printf("|");
- printf("parse:");
- printf(" %s: tag=%c%c%c%c offset=0x%x size=0x%x\n",
- str, tag & 0xff,
- (tag >> 8) & 0xff,
- (tag >> 16) & 0xff,
- (tag >> 24) & 0xff,
- (unsigned int)atom.offset,
- (unsigned int)atom.size);
- assert((unsigned int)atom.size < 0x7fffffff);// catching errors
-}
-#else
-#define print_atom(a,b)
-#endif
-
-
-static int mov_read_leaf(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- print_atom("leaf", atom);
-
- if (atom.size>1)
- url_fskip(pb, atom.size);
-/* url_seek(pb, atom_offset+atom.size, SEEK_SET); */
- return 0;
-}
-
-static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- int64_t total_size = 0;
- MOV_atom_t a;
- int i;
- int err = 0;
-
-#ifdef DEBUG
- print_atom("default", atom);
- debug_indent++;
-#endif
-
- a.offset = atom.offset;
-
- if (atom.size < 0)
- atom.size = 0x7fffffffffffffffLL;
- while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) {
- a.size = atom.size;
- a.type=0L;
- if(atom.size >= 8) {
- a.size = get_be32(pb);
- a.type = get_le32(pb);
- }
- total_size += 8;
- a.offset += 8;
- //printf("type: %08x %.4s sz: %Lx %Lx %Lx\n", type, (char*)&type, size, atom.size, total_size);
- if (a.size == 1) { /* 64 bit extended size */
- a.size = get_be64(pb) - 8;
- a.offset += 8;
- total_size += 8;
- }
- if (a.size == 0) {
- a.size = atom.size - total_size;
- if (a.size <= 8)
- break;
- }
- for (i = 0; c->parse_table[i].type != 0L
- && c->parse_table[i].type != a.type; i++)
- /* empty */;
-
- a.size -= 8;
-// printf(" i=%ld\n", i);
- if (c->parse_table[i].type == 0) { /* skip leaf atoms data */
-// url_seek(pb, atom.offset+atom.size, SEEK_SET);
-#ifdef DEBUG
- print_atom("unknown", a);
-#endif
- url_fskip(pb, a.size);
- } else {
-#ifdef DEBUG
- //char b[5] = { type & 0xff, (type >> 8) & 0xff, (type >> 16) & 0xff, (type >> 24) & 0xff, 0 };
- //print_atom(b, type, offset, size);
-#endif
- err = (c->parse_table[i].func)(c, pb, a);
- }
-
- a.offset += a.size;
- total_size += a.size;
- }
-
- if (!err && total_size < atom.size && atom.size < 0x7ffff) {
- //printf("RESET %Ld %Ld err:%d\n", atom.size, total_size, err);
- url_fskip(pb, atom.size - total_size);
- }
-
-#ifdef DEBUG
- debug_indent--;
-#endif
- return err;
-}
-
-static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- unsigned int len;
- MOV_ctab_t *t;
- //url_fskip(pb, atom.size); // for now
- c->ctab = av_realloc(c->ctab, ++c->ctab_size);
- t = c->ctab[c->ctab_size];
- t->seed = get_be32(pb);
- t->flags = get_be16(pb);
- t->size = get_be16(pb) + 1;
- len = 2 * t->size * 4;
- if (len > 0) {
- t->clrs = av_malloc(len); // 16bit A R G B
- if (t->clrs)
- get_buffer(pb, t->clrs, len);
- }
-
- return 0;
-}
-
-static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- int len = 0;
- uint32_t type;
- uint32_t ctype;
-
- print_atom("hdlr", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- /* component type */
- ctype = get_le32(pb);
- type = get_le32(pb); /* component subtype */
-
-#ifdef DEBUG
- printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
- printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
-#endif
-#ifdef DEBUG
-/* XXX: yeah this is ugly... */
- if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
- if(type == MKTAG('v', 'i', 'd', 'e'))
- puts("hdlr: vide");
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- puts("hdlr: soun");
- } else if(ctype == 0) { /* MP4 */
- if(type == MKTAG('v', 'i', 'd', 'e'))
- puts("hdlr: vide");
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- puts("hdlr: soun");
- else if(type == MKTAG('o', 'd', 's', 'm'))
- puts("hdlr: odsm");
- else if(type == MKTAG('s', 'd', 's', 'm'))
- puts("hdlr: sdsm");
- } else puts("hdlr: meta");
-#endif
-
- if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
- /* helps parsing the string hereafter... */
- c->mp4 = 0;
- if(type == MKTAG('v', 'i', 'd', 'e'))
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- } else if(ctype == 0) { /* MP4 */
- /* helps parsing the string hereafter... */
- c->mp4 = 1;
- if(type == MKTAG('v', 'i', 'd', 'e'))
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- else if(type == MKTAG('s', 'o', 'u', 'n'))
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- }
- get_be32(pb); /* component manufacture */
- get_be32(pb); /* component flags */
- get_be32(pb); /* component flags mask */
-
- if(atom.size <= 24)
- return 0; /* nothing left to read */
- /* XXX: MP4 uses a C string, not a pascal one */
- /* component name */
-
- if(c->mp4) {
- /* .mp4: C string */
- while(get_byte(pb) && (++len < (atom.size - 24)));
- } else {
- /* .mov: PASCAL string */
-#ifdef DEBUG
- char* buf;
-#endif
- len = get_byte(pb);
-#ifdef DEBUG
- buf = (uint8_t*) av_malloc(len+1);
- if (buf) {
- get_buffer(pb, buf, len);
- buf[len] = '\0';
- printf("**buf='%s'\n", buf);
- av_free(buf);
- } else
-#endif
- url_fskip(pb, len);
- }
-
- return 0;
-}
-
-static int mov_mp4_read_descr_len(ByteIOContext *pb)
-{
- int len = 0;
- int count = 4;
- while (count--) {
- int c = get_byte(pb);
- len = (len << 7) | (c & 0x7f);
- if (!(c & 0x80))
- break;
- }
- return len;
-}
-
-static int mov_mp4_read_descr(ByteIOContext *pb, int *tag)
-{
- int len;
- *tag = get_byte(pb);
- len = mov_mp4_read_descr_len(pb);
-#ifdef DEBUG
- printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
-#endif
- return len;
-}
-
-static inline unsigned int get_be24(ByteIOContext *s)
-{
- unsigned int val;
- val = get_byte(s) << 16;
- val |= get_byte(s) << 8;
- val |= get_byte(s);
- return val;
-}
-
-static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int64_t start_pos = url_ftell(pb);
- int tag, len;
-
- print_atom("esds", atom);
-
- /* Well, broken but suffisant for some MP4 streams */
- get_be32(pb); /* version + flags */
- len = mov_mp4_read_descr(pb, &tag);
- if (tag == MP4ESDescrTag) {
- get_be16(pb); /* ID */
- get_byte(pb); /* priority */
- } else
- get_be16(pb); /* ID */
-
- len = mov_mp4_read_descr(pb, &tag);
- if (tag == MP4DecConfigDescrTag) {
- sc->esds.object_type_id = get_byte(pb);
- sc->esds.stream_type = get_byte(pb);
- sc->esds.buffer_size_db = get_be24(pb);
- sc->esds.max_bitrate = get_be32(pb);
- sc->esds.avg_bitrate = get_be32(pb);
-
- len = mov_mp4_read_descr(pb, &tag);
- //printf("LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate);
- if (tag == MP4DecSpecificDescrTag) {
-#ifdef DEBUG
- printf("Specific MPEG4 header len=%d\n", len);
-#endif
- st->codec.extradata = (uint8_t*) av_mallocz(len);
- if (st->codec.extradata) {
- get_buffer(pb, st->codec.extradata, len);
- st->codec.extradata_size = len;
- }
- }
- }
- /* in any case, skip garbage */
- url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos)));
- return 0;
-}
-
-/* this atom contains actual media data */
-static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- print_atom("mdat", atom);
-
- if(atom.size == 0) /* wrong one (MP4) */
- return 0;
- c->found_mdat=1;
- c->mdat_offset = atom.offset;
- c->mdat_size = atom.size;
- if(c->found_moov)
- return 1; /* found both, just go */
- url_fskip(pb, atom.size);
- return 0; /* now go for moov */
-}
-
-/* this atom should contain all header atoms */
-static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- int err;
-
- print_atom("moov", atom);
-
- err = mov_read_default(c, pb, atom);
- /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
- /* so we don't parse the whole file if over a network */
- c->found_moov=1;
- if(c->found_mdat)
- return 1; /* found both, just go */
- return 0; /* now go for mdat */
-}
-
-
-static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- print_atom("mdhd", atom);
-
- get_byte(pb); /* version */
-
- get_byte(pb); get_byte(pb);
- get_byte(pb); /* flags */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
-
- c->streams[c->total_streams]->time_scale = get_be32(pb);
-
-#ifdef DEBUG
- printf("track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
-#endif
- get_be32(pb); /* duration */
-
- get_be16(pb); /* language */
- get_be16(pb); /* quality */
-
- return 0;
-}
-
-static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- print_atom("mvhd", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
- c->time_scale = get_be32(pb); /* time scale */
-#ifdef DEBUG
- printf("time scale = %i\n", c->time_scale);
-#endif
- c->duration = get_be32(pb); /* duration */
- get_be32(pb); /* preferred scale */
-
- get_be16(pb); /* preferred volume */
-
- url_fskip(pb, 10); /* reserved */
-
- url_fskip(pb, 36); /* display matrix */
-
- get_be32(pb); /* preview time */
- get_be32(pb); /* preview duration */
- get_be32(pb); /* poster time */
- get_be32(pb); /* selection time */
- get_be32(pb); /* selection duration */
- get_be32(pb); /* current time */
- get_be32(pb); /* next track ID */
-
- return 0;
-}
-
-static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
-
- // currently SVQ3 decoder expect full STSD header - so let's fake it
- // this should be fixed and just SMI header should be passed
- av_free(st->codec.extradata);
- st->codec.extradata_size = 0x5a + atom.size;
- st->codec.extradata = (uint8_t*) av_mallocz(st->codec.extradata_size);
-
- if (st->codec.extradata) {
- strcpy(st->codec.extradata, "SVQ3"); // fake
- get_buffer(pb, st->codec.extradata + 0x5a, atom.size);
- //printf("Reading SMI %Ld %s\n", atom.size, (char*)st->codec.extradata + 0x5a);
- } else
- url_fskip(pb, atom.size);
-
- return 0;
-}
-
-static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int entries, i;
-
- print_atom("stco", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
- sc->chunk_count = entries;
- sc->chunk_offsets = (int64_t*) av_malloc(entries * sizeof(int64_t));
- if (!sc->chunk_offsets)
- return -1;
- if (atom.type == MKTAG('s', 't', 'c', 'o')) {
- for(i=0; i<entries; i++) {
- sc->chunk_offsets[i] = get_be32(pb);
- }
- } else if (atom.type == MKTAG('c', 'o', '6', '4')) {
- for(i=0; i<entries; i++) {
- sc->chunk_offsets[i] = get_be64(pb);
- }
- } else
- return -1;
-#ifdef DEBUG
-/*
- for(i=0; i<entries; i++) {
- printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]);
- }
-*/
-#endif
- return 0;
-}
-
-static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int entries, frames_per_sample;
- uint32_t format;
-
- print_atom("stsd", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
-
- while(entries--) { //Parsing Sample description table
- enum CodecID id;
- int size = get_be32(pb); /* size */
- format = get_le32(pb); /* data format */
-
- get_be32(pb); /* reserved */
- get_be16(pb); /* reserved */
- get_be16(pb); /* index */
-
- /* for MPEG4: set codec type by looking for it */
- id = codec_get_id(mov_video_tags, format);
- if (id >= 0) {
- AVCodec *codec;
- codec = avcodec_find_decoder(id);
- if (codec)
- st->codec.codec_type = codec->type;
- }
-#ifdef DEBUG
- printf("size=%d 4CC= %c%c%c%c codec_type=%d\n",
- size,
- (format >> 0) & 0xff,
- (format >> 8) & 0xff,
- (format >> 16) & 0xff,
- (format >> 24) & 0xff,
- st->codec.codec_type);
-#endif
- st->codec.codec_tag = format;
- if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
- MOV_atom_t a = { 0, 0, 0 };
- st->codec.codec_id = id;
- get_be16(pb); /* version */
- get_be16(pb); /* revision level */
- get_be32(pb); /* vendor */
- get_be32(pb); /* temporal quality */
- get_be32(pb); /* spacial quality */
- st->codec.width = get_be16(pb); /* width */
- st->codec.height = get_be16(pb); /* height */
-#if 1
- if (st->codec.codec_id == CODEC_ID_MPEG4) {
- /* in some MPEG4 the width/height are not correct, so
- we ignore this info */
- st->codec.width = 0;
- st->codec.height = 0;
- }
-#endif
- get_be32(pb); /* horiz resolution */
- get_be32(pb); /* vert resolution */
- get_be32(pb); /* data size, always 0 */
- frames_per_sample = get_be16(pb); /* frames per samples */
-#ifdef DEBUG
- printf("frames/samples = %d\n", frames_per_sample);
-#endif
- get_buffer(pb, (uint8_t *)st->codec.codec_name, 32); /* codec name */
-
- st->codec.bits_per_sample = get_be16(pb); /* depth */
- st->codec.color_table_id = get_be16(pb); /* colortable id */
-
-/* These are set in mov_read_stts and might already be set!
- st->codec.frame_rate = 25;
- st->codec.frame_rate_base = 1;
-*/
- size -= (16+8*4+2+32+2*2);
-#if 0
- while (size >= 8) {
- MOV_atom_t a;
- int64_t start_pos;
-
- a.size = get_be32(pb);
- a.type = get_le32(pb);
- size -= 8;
-#ifdef DEBUG
- printf("VIDEO: atom_type=%c%c%c%c atom.size=%Ld size_left=%d\n",
- (a.type >> 0) & 0xff,
- (a.type >> 8) & 0xff,
- (a.type >> 16) & 0xff,
- (a.type >> 24) & 0xff,
- a.size, size);
-#endif
- start_pos = url_ftell(pb);
-
- switch(a.type) {
- case MKTAG('e', 's', 'd', 's'):
- {
- int tag, len;
- /* Well, broken but suffisant for some MP4 streams */
- get_be32(pb); /* version + flags */
- len = mov_mp4_read_descr(pb, &tag);
- if (tag == 0x03) {
- /* MP4ESDescrTag */
- get_be16(pb); /* ID */
- get_byte(pb); /* priority */
- len = mov_mp4_read_descr(pb, &tag);
- if (tag != 0x04)
- goto fail;
- /* MP4DecConfigDescrTag */
- get_byte(pb); /* objectTypeId */
- get_be32(pb); /* streamType + buffer size */
- get_be32(pb); /* max bit rate */
- get_be32(pb); /* avg bit rate */
- len = mov_mp4_read_descr(pb, &tag);
- if (tag != 0x05)
- goto fail;
- /* MP4DecSpecificDescrTag */
-#ifdef DEBUG
- printf("Specific MPEG4 header len=%d\n", len);
-#endif
- sc->header_data = av_mallocz(len);
- if (sc->header_data) {
- get_buffer(pb, sc->header_data, len);
- sc->header_len = len;
- }
- }
- /* in any case, skip garbage */
- }
- break;
- default:
- break;
- }
- fail:
- printf("ATOMENEWSIZE %Ld %d\n", atom.size, url_ftell(pb) - start_pos);
- if (atom.size > 8) {
- url_fskip(pb, (atom.size - 8) -
- ((url_ftell(pb) - start_pos)));
- size -= atom.size - 8;
- }
- }
- if (size > 0) {
- /* unknown extension */
- url_fskip(pb, size);
- }
-#else
- a.size = size;
- mov_read_default(c, pb, a);
-#endif
- } else {
- st->codec.codec_id = codec_get_id(mov_audio_tags, format);
- if(st->codec.codec_id==CODEC_ID_AMR_NB) //from TS26.244
- {
-#ifdef DEBUG
- printf("AMR-NB audio identified!!\n");
-#endif
- get_be32(pb);get_be32(pb); //Reserved_8
- get_be16(pb);//Reserved_2
- get_be16(pb);//Reserved_2
- get_be32(pb);//Reserved_4
- get_be16(pb);//TimeScale
- get_be16(pb);//Reserved_2
-
- //AMRSpecificBox.(10 bytes)
-
-#ifdef DEBUG
- int damr_size=
-#endif
- get_be32(pb); //size
-#ifdef DEBUG
- int damr_type=
-#endif
- get_be32(pb); //type=='damr'
-#ifdef DEBUG
- int damr_vendor=
-#endif
- get_be32(pb); //vendor
- get_byte(pb); //decoder version
- get_be16(pb); //mode_set
- get_byte(pb); //mode_change_period
- get_byte(pb); //frames_per_sample
-
-#ifdef DEBUG
- printf("Audio: damr_type=%c%c%c%c damr_size=%d damr_vendor=%c%c%c%c\n",
- (damr_type >> 24) & 0xff,
- (damr_type >> 16) & 0xff,
- (damr_type >> 8) & 0xff,
- (damr_type >> 0) & 0xff,
- damr_size,
- (damr_vendor >> 24) & 0xff,
- (damr_vendor >> 16) & 0xff,
- (damr_vendor >> 8) & 0xff,
- (damr_vendor >> 0) & 0xff
- );
-#endif
-
- st->duration = AV_NOPTS_VALUE;//Not possible to get from this info, must count number of AMR frames
- st->codec.sample_rate=8000;
- st->codec.channels=1;
- st->codec.bits_per_sample=16;
- st->codec.bit_rate=0; /*It is not possible to tell this before we have
- an audio frame and even then every frame can be different*/
- }
- else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 's' ))
- {
- //This is some stuff for the hint track, lets ignore it!
- //Do some mp4 auto detect.
- c->mp4=1;
- size-=(16);
- url_fskip(pb, size); /* The mp4s atom also contians a esds atom that we can skip*/
- }
- else if(size>=(16+20))
- {//16 bytes read, reading atleast 20 more
-#ifdef DEBUG
- printf("audio size=0x%X\n",size);
-#endif
- uint16_t version = get_be16(pb); /* version */
- get_be16(pb); /* revision level */
- get_be32(pb); /* vendor */
-
- st->codec.channels = get_be16(pb); /* channel count */
- st->codec.bits_per_sample = get_be16(pb); /* sample size */
-
- /* handle specific s8 codec */
- get_be16(pb); /* compression id = 0*/
- get_be16(pb); /* packet size = 0 */
-
- st->codec.sample_rate = ((get_be32(pb) >> 16));
- //printf("CODECID %d %d %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format);
-
- switch (st->codec.codec_id) {
- case CODEC_ID_PCM_S16BE:
- if (st->codec.bits_per_sample == 8)
- st->codec.codec_id = CODEC_ID_PCM_S8;
- /* fall */
- case CODEC_ID_PCM_U8:
- st->codec.bit_rate = st->codec.sample_rate * 8;
- break;
- default:
- ;
- }
-
- //Read QT version 1 fields. In version 0 theese dont exist
-#ifdef DEBUG
- printf("version =%d mp4=%d\n",version,c->mp4);
- printf("size-(16+20+16)=%d\n",size-(16+20+16));
-#endif
- if((version==1) && size>=(16+20+16))
- {
- get_be32(pb); /* samples per packet */
- get_be32(pb); /* bytes per packet */
- get_be32(pb); /* bytes per frame */
- get_be32(pb); /* bytes per sample */
- if(size>(16+20+16))
- {
- //Optional, additional atom-based fields
-#ifdef DEBUG
- printf("offest=0x%X, sizeleft=%d=0x%x,format=%c%c%c%c\n",(int)url_ftell(pb),size - (16 + 20 + 16 ),size - (16 + 20 + 16 ),
- (format >> 0) & 0xff,
- (format >> 8) & 0xff,
- (format >> 16) & 0xff,
- (format >> 24) & 0xff);
-#endif
- MOV_atom_t a = { format, url_ftell(pb), size - (16 + 20 + 16 + 8) };
- mov_read_default(c, pb, a);
- }
- }
- else
- {
- //We should be down to 0 bytes here, but lets make sure.
- size-=(16+20);
-#ifdef DEBUG
- if(size>0)
- printf("skipping 0x%X bytes\n",size-(16+20));
-#endif
- url_fskip(pb, size);
- }
- }
- else
- {
- size-=16;
- //Unknown size, but lets do our best and skip the rest.
-#ifdef DEBUG
- printf("Strange size, skipping 0x%X bytes\n",size);
-#endif
- url_fskip(pb, size);
- }
- }
- }
-
- return 0;
-}
-
-static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int entries, i;
-
- print_atom("stsc", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- entries = get_be32(pb);
-#ifdef DEBUG
-printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
-#endif
- sc->sample_to_chunk_sz = entries;
- sc->sample_to_chunk = (MOV_sample_to_chunk_tbl*) av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
- if (!sc->sample_to_chunk)
- return -1;
- for(i=0; i<entries; i++) {
- sc->sample_to_chunk[i].first = get_be32(pb);
- sc->sample_to_chunk[i].count = get_be32(pb);
- sc->sample_to_chunk[i].id = get_be32(pb);
-#ifdef DEBUG
-/* printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); */
-#endif
- }
- return 0;
-}
-
-static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int entries, i;
-
- print_atom("stsz", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
-
- sc->sample_size = get_be32(pb);
- entries = get_be32(pb);
- sc->sample_count = entries;
-#ifdef DEBUG
- printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
-#endif
- if(sc->sample_size)
- return 0; /* there isn't any table following */
- sc->sample_sizes = (long*) av_malloc(entries * sizeof(long));
- if (!sc->sample_sizes)
- return -1;
- for(i=0; i<entries; i++) {
- sc->sample_sizes[i] = get_be32(pb);
-#ifdef DEBUG
-/* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */
-#endif
- }
- return 0;
-}
-
-static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st = c->fc->streams[c->fc->nb_streams-1];
- //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data;
- int entries, i;
- int duration=0;
- int total_sample_count=0;
-
- print_atom("stts", atom);
-
- get_byte(pb); /* version */
- get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
- entries = get_be32(pb);
-
-
-#ifdef DEBUG
-printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
-#endif
- for(i=0; i<entries; i++) {
- int sample_duration;
- int sample_count;
-
- sample_count=get_be32(pb);
- sample_duration = get_be32(pb);
-#ifdef DEBUG
- printf("sample_count=%d, sample_duration=%d\n",sample_count,sample_duration);
-#endif
- duration+=sample_duration*sample_count;
- total_sample_count+=sample_count;
-
-#if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone
-
- if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
- st->codec.frame_rate_base = sample_duration ? sample_duration : 1;
- st->codec.frame_rate = c->streams[c->total_streams]->time_scale;
-#ifdef DEBUG
- printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);
-#endif
- }
-#endif
- }
-
-#define MAX(a,b) a>b?a:b
-#define MIN(a,b) a>b?b:a
- /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/
- if(duration>0)
- {
- //Find greatest common divisor to avoid overflow using the Euclidean Algorithm...
- uint32_t max=MAX(duration,total_sample_count);
- uint32_t min=MIN(duration,total_sample_count);
- uint32_t spare=max%min;
-
- while(spare!=0)
- {
- max=min;
- min=spare;
- spare=max%min;
- }
-
- duration/=min;
- total_sample_count/=min;
-
- //Only support constant frame rate. But lets calculate the average. Needed by .mp4-files created with nec e606 3g phone.
- //To get better precision, we use the duration as frame_rate_base
-
- st->codec.frame_rate_base=duration;
- st->codec.frame_rate = c->streams[c->total_streams]->time_scale * total_sample_count;
-
-#ifdef DEBUG
- printf("FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,c->streams[c->total_streams]->time_scale);
-#endif
- }
- else
- {
- st->codec.frame_rate_base = 1;
- st->codec.frame_rate = c->streams[c->total_streams]->time_scale;
- }
-#undef MAX
-#undef MIN
- return 0;
-}
-
-static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st;
- MOVStreamContext *sc;
-
- print_atom("trak", atom);
-
- st = av_new_stream(c->fc, c->fc->nb_streams);
- if (!st) return -2;
- sc = (MOVStreamContext*) av_mallocz(sizeof(MOVStreamContext));
- if (!sc) {
- av_free(st);
- return -1;
- }
-
- sc->sample_to_chunk_index = -1;
- st->priv_data = sc;
- st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
- st->start_time = 0; /* XXX: check */
- st->duration = (c->duration * (int64_t)AV_TIME_BASE) / c->time_scale;
- c->streams[c->fc->nb_streams-1] = sc;
-
- return mov_read_default(c, pb, atom);
-}
-
-static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- AVStream *st;
-
- print_atom("tkhd", atom);
-
- st = c->fc->streams[c->fc->nb_streams-1];
-
- get_byte(pb); /* version */
-
- get_byte(pb); get_byte(pb);
- get_byte(pb); /* flags */
- /*
- MOV_TRACK_ENABLED 0x0001
- MOV_TRACK_IN_MOVIE 0x0002
- MOV_TRACK_IN_PREVIEW 0x0004
- MOV_TRACK_IN_POSTER 0x0008
- */
-
- get_be32(pb); /* creation time */
- get_be32(pb); /* modification time */
- st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
- get_be32(pb); /* reserved */
- st->start_time = 0; /* check */
- st->duration = (get_be32(pb) * (int64_t)AV_TIME_BASE) / c->time_scale; /* duration */
- get_be32(pb); /* reserved */
- get_be32(pb); /* reserved */
-
- get_be16(pb); /* layer */
- get_be16(pb); /* alternate group */
- get_be16(pb); /* volume */
- get_be16(pb); /* reserved */
-
- url_fskip(pb, 36); /* display matrix */
-
- /* those are fixed-point */
- st->codec.width = get_be32(pb) >> 16; /* track width */
- st->codec.height = get_be32(pb) >> 16; /* track height */
-
- return 0;
-}
-
-/* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
-/* like the files created with Adobe Premiere 5.0, for samples see */
-/* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
-static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- int err;
-
-#ifdef DEBUG
- print_atom("wide", atom);
- debug_indent++;
-#endif
- if (atom.size < 8)
- return 0; /* continue */
- if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
- url_fskip(pb, atom.size - 4);
- return 0;
- }
- atom.type = get_le32(pb);
- atom.offset += 8;
- atom.size -= 8;
- if (atom.type != MKTAG('m', 'd', 'a', 't')) {
- url_fskip(pb, atom.size);
- return 0;
- }
- err = mov_read_mdat(c, pb, atom);
-#ifdef DEBUG
- debug_indent--;
-#endif
- return err;
-}
-
-
-#ifdef CONFIG_ZLIB
-static int null_read_packet(void *opaque, uint8_t *buf, int buf_size)
-{
- return -1;
-}
-
-static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
-{
- ByteIOContext ctx;
- uint8_t *cmov_data;
- uint8_t *moov_data; /* uncompressed data */
- long cmov_len, moov_len;
- int ret;
-
- print_atom("cmov", atom);
-
- get_be32(pb); /* dcom atom */
- if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
- return -1;
- if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
- dprintf("unknown compression for cmov atom !");
- return -1;
- }
- get_be32(pb); /* cmvd atom */
- if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
- return -1;
- moov_len = get_be32(pb); /* uncompressed size */
- cmov_len = atom.size - 6 * 4;
-
- cmov_data = (uint8_t *) av_malloc(cmov_len);
- if (!cmov_data)
- return -1;
- moov_data = (uint8_t *) av_malloc(moov_len);
- if (!moov_data) {
- av_free(cmov_data);
- return -1;
- }
- get_buffer(pb, cmov_data, cmov_len);
- if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
- return -1;
- if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0)
- return -1;
- ctx.buf_end = ctx.buffer + moov_len;
- atom.type = MKTAG( 'm', 'o', 'o', 'v' );
- atom.offset = 0;
- atom.size = moov_len;
-#ifdef DEBUG
- { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); }
-#endif
- ret = mov_read_default(c, &ctx, atom);
- av_free(moov_data);
- av_free(cmov_data);
-
- return ret;
-}
-#endif
-
-static const MOVParseTableEntry mov_default_parse_table[] = {
-/* mp4 atoms */
-{ MKTAG( 'c', 'o', '6', '4' ), mov_read_stco },
-{ MKTAG( 'c', 'p', 'r', 't' ), mov_read_default },
-{ MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default },
-{ MKTAG( 'c', 't', 't', 's' ), mov_read_leaf }, /* composition time to sample */
-{ MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */
-{ MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf },
-{ MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf },
-{ MKTAG( 'e', 'd', 't', 's' ), mov_read_default },
-{ MKTAG( 'e', 'l', 's', 't' ), mov_read_leaf },
-{ MKTAG( 'f', 'r', 'e', 'e' ), mov_read_leaf },
-{ MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr },
-{ MKTAG( 'h', 'i', 'n', 't' ), mov_read_leaf },
-{ MKTAG( 'h', 'm', 'h', 'd' ), mov_read_leaf },
-{ MKTAG( 'i', 'o', 'd', 's' ), mov_read_leaf },
-{ MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat },
-{ MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd },
-{ MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default },
-{ MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default },
-{ MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov },
-{ MKTAG( 'm', 'p', '4', 'a' ), mov_read_default },
-{ MKTAG( 'm', 'p', '4', 's' ), mov_read_default },
-{ MKTAG( 'm', 'p', '4', 'v' ), mov_read_default },
-{ MKTAG( 'm', 'p', 'o', 'd' ), mov_read_leaf },
-{ MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd },
-{ MKTAG( 'n', 'm', 'h', 'd' ), mov_read_leaf },
-{ MKTAG( 'o', 'd', 'h', 'd' ), mov_read_default },
-{ MKTAG( 's', 'd', 'h', 'd' ), mov_read_default },
-{ MKTAG( 's', 'k', 'i', 'p' ), mov_read_default },
-{ MKTAG( 's', 'm', 'h', 'd' ), mov_read_leaf }, /* sound media info header */
-{ MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorrenson extension ??? */
-{ MKTAG( 's', 't', 'b', 'l' ), mov_read_default },
-{ MKTAG( 's', 't', 'c', 'o' ), mov_read_stco },
-{ MKTAG( 's', 't', 'd', 'p' ), mov_read_default },
-{ MKTAG( 's', 't', 's', 'c' ), mov_read_stsc },
-{ MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */
-{ MKTAG( 's', 't', 's', 'h' ), mov_read_default },
-{ MKTAG( 's', 't', 's', 's' ), mov_read_leaf }, /* sync sample */
-{ MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */
-{ MKTAG( 's', 't', 't', 's' ), mov_read_stts },
-{ MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */
-{ MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak },
-{ MKTAG( 't', 'r', 'e', 'f' ), mov_read_default }, /* not really */
-{ MKTAG( 'u', 'd', 't', 'a' ), mov_read_leaf },
-{ MKTAG( 'u', 'r', 'l', ' ' ), mov_read_leaf },
-{ MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf },
-{ MKTAG( 'u', 'u', 'i', 'd' ), mov_read_default },
-{ MKTAG( 'v', 'm', 'h', 'd' ), mov_read_leaf }, /* video media info header */
-{ MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default },
-/* extra mp4 */
-{ MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf },
-/* QT atoms */
-{ MKTAG( 'c', 'h', 'a', 'p' ), mov_read_leaf },
-{ MKTAG( 'c', 'l', 'i', 'p' ), mov_read_default },
-{ MKTAG( 'c', 'r', 'g', 'n' ), mov_read_leaf },
-{ MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab },
-{ MKTAG( 'e', 's', 'd', 's' ), mov_read_esds },
-{ MKTAG( 'k', 'm', 'a', 't' ), mov_read_leaf },
-{ MKTAG( 'm', 'a', 't', 't' ), mov_read_default },
-{ MKTAG( 'r', 'd', 'r', 'f' ), mov_read_leaf },
-{ MKTAG( 'r', 'm', 'd', 'a' ), mov_read_default },
-{ MKTAG( 'r', 'm', 'd', 'r' ), mov_read_leaf },
-{ MKTAG( 'r', 'm', 'r', 'a' ), mov_read_default },
-{ MKTAG( 's', 'c', 'p', 't' ), mov_read_leaf },
-{ MKTAG( 's', 's', 'r', 'c' ), mov_read_leaf },
-{ MKTAG( 's', 'y', 'n', 'c' ), mov_read_leaf },
-{ MKTAG( 't', 'c', 'm', 'd' ), mov_read_leaf },
-{ MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */
-//{ MKTAG( 'r', 'm', 'q', 'u' ), mov_read_leaf },
-#ifdef CONFIG_ZLIB
-{ MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov },
-#else
-{ MKTAG( 'c', 'm', 'o', 'v' ), mov_read_leaf },
-#endif
-{ 0L, mov_read_leaf }
-};
-
-static void mov_free_stream_context(MOVStreamContext *sc)
-{
- if(sc) {
- av_free(sc->chunk_offsets);
- av_free(sc->sample_to_chunk);
- av_free(sc->sample_sizes);
- av_free(sc->header_data);
- av_free(sc);
- }
-}
-
-static inline uint32_t mov_to_tag(uint8_t *buf)
-{
- return MKTAG(buf[0], buf[1], buf[2], buf[3]);
-}
-
-static inline uint32_t to_be32(uint8_t *buf)
-{
- return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
-}
-
-/* XXX: is it sufficient ? */
-static int mov_probe(AVProbeData *p)
-{
- unsigned int offset;
- uint32_t tag;
-
- /* check file header */
- if (p->buf_size <= 12)
- return 0;
- offset = 0;
- for(;;) {
- /* ignore invalid offset */
- if ((offset + 8) > (unsigned int)p->buf_size)
- return 0;
- tag = mov_to_tag(p->buf + offset + 4);
- switch(tag) {
- case MKTAG( 'm', 'o', 'o', 'v' ):
- case MKTAG( 'w', 'i', 'd', 'e' ):
- case MKTAG( 'f', 'r', 'e', 'e' ):
- case MKTAG( 'm', 'd', 'a', 't' ):
- case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */
- case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */
- return AVPROBE_SCORE_MAX;
- case MKTAG( 'f', 't', 'y', 'p' ):
- case MKTAG( 's', 'k', 'i', 'p' ):
- offset = to_be32(p->buf+offset) + offset;
- break;
- default:
- /* unrecognized tag */
- return 0;
- }
- }
- return 0;
-}
-
-static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- MOVContext *mov = (MOVContext *) s->priv_data;
- ByteIOContext *pb = &s->pb;
- int i, j, nb, err;
- MOV_atom_t atom = { 0, 0, 0 };
-
- mov->fc = s;
- mov->parse_table = mov_default_parse_table;
-#if 0
- /* XXX: I think we should auto detect */
- if(s->iformat->name[1] == 'p')
- mov->mp4 = 1;
-#endif
- if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
- atom.size = url_filesize(url_fileno(pb));
- else
- atom.size = 0x7FFFFFFFFFFFFFFFLL;
-
-#ifdef DEBUG
- printf("filesz=%Ld\n", atom.size);
-#endif
-
- /* check MOV header */
- err = mov_read_default(mov, pb, atom);
- if (err<0 || (!mov->found_moov && !mov->found_mdat)) {
- fprintf(stderr, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%lld\n",
- err, mov->found_moov, mov->found_mdat, url_ftell(pb));
- return -1;
- }
-#ifdef DEBUG
- printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb));
-#endif
- /* some cleanup : make sure we are on the mdat atom */
- if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
- url_fseek(pb, mov->mdat_offset, SEEK_SET);
-
- mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */
-
-#ifdef DEBUG
- printf("mdat_reset_offset=%d\n", (int) url_ftell(pb));
-#endif
-
-#ifdef DEBUG
- printf("streams= %d\n", s->nb_streams);
-#endif
- mov->total_streams = nb = s->nb_streams;
-
-#if 1
- for(i=0; i<s->nb_streams;) {
- if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
- av_free(s->streams[i]);
- for(j=i+1; j<s->nb_streams; j++)
- s->streams[j-1] = s->streams[j];
- s->nb_streams--;
- } else
- i++;
- }
- for(i=0; i<s->nb_streams;i++) {
- MOVStreamContext *sc;
- sc = (MOVStreamContext *)s->streams[i]->priv_data;
- sc->ffindex = i;
- sc->is_ff_stream = 1;
- }
-#endif
-#ifdef DEBUG
- printf("real streams= %d\n", s->nb_streams);
-#endif
- return 0;
-}
-
-/* Yes, this is ugly... I didn't write the specs of QT :p */
-/* XXX:remove useless commented code sometime */
-static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- MOVContext *mov = (MOVContext *) s->priv_data;
- MOVStreamContext *sc;
- int64_t offset = 0x0FFFFFFFFFFFFFFFLL;
- int i;
- int size;
- size = 0x0FFFFFFF;
-
-#ifdef MOV_SPLIT_CHUNKS
- if (mov->partial) {
-
- int idx;
-
- sc = mov->partial;
- idx = sc->sample_to_chunk_index;
-
- if (idx < 0) return 0;
- size = sc->sample_sizes[sc->current_sample];
-
- sc->current_sample++;
- sc->left_in_chunk--;
-
- if (sc->left_in_chunk <= 0)
- mov->partial = 0;
- offset = mov->next_chunk_offset;
- /* extract the sample */
-
- goto readchunk;
- }
-#endif
-
-again:
- sc = 0;
- for(i=0; i<mov->total_streams; i++) {
- MOVStreamContext *msc = mov->streams[i];
- //printf("MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb));
- if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0
- && (msc->chunk_offsets[msc->next_chunk] < offset)) {
- sc = msc;
- offset = msc->chunk_offsets[msc->next_chunk];
- //printf("SELETED %Ld i:%d\n", offset, i);
- }
- }
- if (!sc || offset==0x0FFFFFFFFFFFFFFFLL)
- return -1;
-
- sc->next_chunk++;
-
- if(mov->next_chunk_offset < offset) { /* some meta data */
- url_fskip(&s->pb, (offset - mov->next_chunk_offset));
- mov->next_chunk_offset = offset;
- }
-
-//printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
- if(!sc->is_ff_stream) {
- url_fskip(&s->pb, (offset - mov->next_chunk_offset));
- mov->next_chunk_offset = offset;
- offset = 0x0FFFFFFFFFFFFFFFLL;
- goto again;
- }
-
- /* now get the chunk size... */
-
- for(i=0; i<mov->total_streams; i++) {
- MOVStreamContext *msc = mov->streams[i];
- if ((msc->next_chunk < msc->chunk_count)
- && ((msc->chunk_offsets[msc->next_chunk] - offset) < size))
- size = msc->chunk_offsets[msc->next_chunk] - offset;
- }
-
-#ifdef MOV_MINOLTA_FIX
- //Make sure that size is according to sample_size (Needed by .mov files
- //created on a Minolta Dimage Xi where audio chunks contains waste data in the end)
- //Maybe we should really not only check sc->sample_size, but also sc->sample_sizes
- //but I have no such movies
- if (sc->sample_size > 0) {
- int foundsize=0;
- for(i=0; i<(sc->sample_to_chunk_sz); i++) {
- if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) && (sc->sample_size>0) )
- {
- foundsize=sc->sample_to_chunk[i].count*sc->sample_size;
- }
-#ifdef DEBUG
- /*printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id);*/
-#endif
- }
- if( (foundsize>0) && (foundsize<size) )
- {
-#ifdef DEBUG
- /*printf("this size should actually be %d\n",foundsize);*/
-#endif
- size=foundsize;
- }
- }
-#endif //MOV_MINOLTA_FIX
-
-#ifdef MOV_SPLIT_CHUNKS
- /* split chunks into samples */
- if (sc->sample_size == 0) {
- int idx = sc->sample_to_chunk_index;
- if ((idx + 1 < sc->sample_to_chunk_sz)
- && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first))
- idx++;
- sc->sample_to_chunk_index = idx;
- if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) {
- mov->partial = sc;
- /* we'll have to get those samples before next chunk */
- sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1;
- size = sc->sample_sizes[sc->current_sample];
- }
-
- sc->current_sample++;
- }
-#endif
-
-readchunk:
-//printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size);
- if(size == 0x0FFFFFFF)
- size = mov->mdat_size + mov->mdat_offset - offset;
- if(size < 0)
- return -1;
- if(size == 0)
- return -1;
- url_fseek(&s->pb, offset, SEEK_SET);
-
- //printf("READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb));
- if (sc->header_len > 0) {
- av_new_packet(pkt, size + sc->header_len);
- memcpy(pkt->data, sc->header_data, sc->header_len);
- get_buffer(&s->pb, pkt->data + sc->header_len, size);
- /* free header */
- av_freep(&sc->header_data);
- sc->header_len = 0;
- } else {
- av_new_packet(pkt, size);
- get_buffer(&s->pb, pkt->data, pkt->size);
- }
- pkt->stream_index = sc->ffindex;
-
-#ifdef DEBUG
-/*
- printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size);
- for(i=0; i<8; i++)
- printf("%02x ", pkt->data[i]);
- for(i=0; i<8; i++)
- printf("%c ", (pkt->data[i]) & 0x7F);
- puts("");
-*/
-#endif
-
- mov->next_chunk_offset = offset + size;
-
- return 0;
-}
-
-static int mov_read_close(AVFormatContext *s)
-{
- int i;
- MOVContext *mov = (MOVContext *) s->priv_data;
- for(i=0; i<mov->total_streams; i++)
- mov_free_stream_context(mov->streams[i]);
- for(i=0; i<s->nb_streams; i++)
- av_freep(&s->streams[i]);
- /* free color tabs */
- for(i=0; i<mov->ctab_size; i++)
- av_freep(&mov->ctab[i]);
- av_freep(&mov->ctab);
- return 0;
-}
-
-static AVInputFormat mov_iformat = {
- "mov",
- "QuickTime/MPEG4 format",
- sizeof(MOVContext),
- mov_probe,
- mov_read_header,
- mov_read_packet,
- mov_read_close,
-};
-
-int mov_init(void)
-{
- av_register_input_format(&mov_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * MOV, 3GP, MP4 encoder.
- * Copyright (c) 2003 Thomas Raivio.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avio.h"
-#include <time.h>
-
-#undef NDEBUG
-#include <assert.h>
-
-/*
- * Limitations
- * - Currently supports h.263, MPEG4 video codecs, and AMR audio codec.
- */
-
-#define MOV_INDEX_CLUSTER_SIZE 16384
-#define globalTimescale 1000
-
-typedef struct MOVIentry {
- unsigned int flags, pos, len;
- unsigned int entries;
-} MOVIentry;
-
-typedef struct MOVIndex {
- int entry;
- int samples;
- int mdat_size;
- offset_t mdat_pos;
- int ents_allocated;
- long timescale;
- long time;
- long frameDuration;
- long sampleDelta;
- int trackID;
- AVCodecContext *enc;
-
- int vosLen;
- uint8_t *vosData;
- MOVIentry** cluster;
-} MOVTrack;
-
-typedef struct {
- long time;
- int nb_streams;
- offset_t movi_list;
- long timescale;
- MOVTrack tracks[MAX_STREAMS];
-} MOVContext;
-
-//FIXME supprt 64bit varaint with wide placeholders
-static int updateSize (ByteIOContext *pb, int pos)
-{
- long curpos = url_ftell(pb);
- url_fseek(pb, pos, SEEK_SET);
- put_be32(pb, curpos - pos); /* rewrite size */
- url_fseek(pb, curpos, SEEK_SET);
-
- return curpos - pos;
-}
-
-static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int i;
- put_be32(pb, 16+track->entry*4); /* size */
- put_tag(pb, "stco");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, track->entry); /* entry count */
- for (i=0; i<track->entry; i++) {
- int cl = i / MOV_INDEX_CLUSTER_SIZE;
- int id = i % MOV_INDEX_CLUSTER_SIZE;
- put_be32(pb, track->cluster[cl][id].pos);
- }
- return 16+track->entry*4;
-}
-
-static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int i, size;
-
- if(track->cluster[0][0].entries != 0)
- size = 20;
- else
- size = 20+track->samples*4;
- put_be32(pb, size); /* size */
- put_tag(pb, "stsz");
- put_be32(pb, 0); /* version & flags */
-
- /* TODO: Ugly (and false) assumption: if we have a chunk of samples, assume
- * all sizes are same */
- if(track->cluster[0][0].entries != 0) {
- int sSize = track->cluster[0][0].len/track->cluster[0][0].entries;
- put_be32(pb, sSize); /* sample size */
- put_be32(pb, track->samples); /* sample count */
- }
- else
- {
- put_be32(pb, 0); /* sample size */
- put_be32(pb, track->samples); /* sample count */
- for (i=0; i<track->samples; i++) {
- int cl = i / MOV_INDEX_CLUSTER_SIZE;
- int id = i % MOV_INDEX_CLUSTER_SIZE;
- put_be32(pb, track->cluster[cl][id].len);
- }
- }
- return size;
-}
-
-static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int size;
- if(track->cluster[0][0].entries != 0)
- size = 16+track->entry*4*3;
- else
- size = 0x1c;
- put_be32(pb, size); // size
- put_tag(pb, "stsc");
- put_be32(pb, 0); // version & flags
- if(track->cluster[0][0].entries != 0) {
- int i;
- put_be32(pb, track->entry); // entry count
- for (i=0; i<track->entry; i++) {
- int cl = i / MOV_INDEX_CLUSTER_SIZE;
- int id = i % MOV_INDEX_CLUSTER_SIZE;
- put_be32(pb, i+1); // first chunk
- put_be32(pb, track->cluster[cl][id].entries);
- put_be32(pb, 0x1); // sample description index
- }
- }
- else {
- put_be32(pb, 1); // entry count
- put_be32(pb, 0x1); // first chunk
- put_be32(pb, 0x1); // samples per chunk
- put_be32(pb, 0x1); // sample description index
- }
-
- return size;
-}
-
-//FIXME keyframes?
-static int mov_write_stss_tag(ByteIOContext *pb) //TRA OK
-{
- put_be32(pb, 0x14); /* size */
- put_tag(pb, "stss");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, 1); /* entry count */
- put_be32(pb, 0x1); /* sample number */
- return 0x14;
-}
-
-static int mov_write_damr_tag(ByteIOContext *pb)
-{
- put_be32(pb, 0x11); /* size */
- put_tag(pb, "damr");
- put_tag(pb, "FFMP");
- put_byte(pb, 0);
- put_be16(pb, 0x81ff); /* Mode set (all modes for AMR_NB) */
- put_be16(pb, 1); /* Mode change period (no restriction) */
- return 0x11;
-}
-
-static int mov_write_samr_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- /* "samr" for AMR NB, "sawb" for AMR WB */
- put_tag(pb, "samr");
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, 0); /* Reserved */
- put_be16(pb, 1); /* Data-reference index, XXX == 1 */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
-
- put_be16(pb, 2); /* Reserved */
- put_be16(pb, 0x10); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, track->timescale); /* Time scale */
- put_be16(pb, 0); /* Reserved */
-
- mov_write_damr_tag(pb);
- return updateSize (pb, pos);
-}
-
-static int mov_write_d263_tag(ByteIOContext *pb)
-{
- put_be32(pb, 0xf); /* size */
- put_tag(pb, "d263");
- put_tag(pb, "FFMP");
- put_be16(pb, 0x0a);
- put_byte(pb, 0);
- return 0xf;
-}
-
-static int mov_write_s263_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "s263");
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, 0); /* Reserved */
- put_be16(pb, 1); /* Data-reference index */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, track->enc->width); /* Video width */
- put_be16(pb, track->enc->height); /* Video height */
- put_be32(pb, 0x00480000); /* Reserved */
- put_be32(pb, 0x00480000); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, 1); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be32(pb, 0); /* Reserved */
- put_be16(pb, 0x18); /* Reserved */
- put_be16(pb, 0xffff); /* Reserved */
- mov_write_d263_tag(pb);
- return updateSize (pb, pos);
-}
-
-static unsigned int esdsLength(unsigned int len)
-{
- unsigned int result = 0;
- unsigned char b = len & 0x7f;
- result += b;
- b = (len >> 8) & 0x7f;
- result += (b + 0x80) << 8;
- b = (len >> 16) & 0x7f;
- result += (b + 0x80) << 16;
- b = (len >> 24) & 0x7f;
- result += (b + 0x80) << 24;
- return result;
-}
-
-static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack* track) // Basic
-{
- put_be32(pb, track->vosLen+18+14+17);
- put_tag(pb, "esds");
- put_be32(pb, 0); // Version
-
- put_byte(pb, 0x03); // tag = ES_DescriptorTag
- put_be32(pb, esdsLength(track->vosLen+18+14)); // Length
- put_be16(pb, 0x0001); // ID (= 1)
- put_byte(pb, 0x00); // flags (= no flags)
-
-// Decoderconfigdescriptor = 4
- put_byte(pb, 0x04); // tag = DecoderConfigDescriptor
- put_be32(pb, esdsLength(track->vosLen+18)); // Length
- put_byte(pb, 0x20); // Object type indication (Visual 14496-2)
- put_byte(pb, 0x11); // flags (= Visualstream)
- put_byte(pb, 0x0); // Buffersize DB (24 bits)
- put_be16(pb, 0x0dd2); // Buffersize DB
-
- // TODO: find real values for these
- put_be32(pb, 0x0002e918); // maxbitrate
- put_be32(pb, 0x00017e6b); // avg bitrate
-
-// Decoderspecific info Tag = 5
- put_byte(pb, 0x05); // tag = Decoderspecific info
- put_be32(pb, esdsLength(track->vosLen)); // length
- put_buffer(pb, track->vosData, track->vosLen);
-
- put_byte(pb, 0x06);
- put_be32(pb, esdsLength(1)); // length
- put_byte(pb, 0x02);
- return track->vosLen+18+14+17;
-}
-
-static int mov_write_mp4v_tag(ByteIOContext *pb, MOVTrack* track) // Basic
-{
- int pos = url_ftell(pb);
-
- put_be32(pb, 0);
- put_tag(pb, "mp4v");
- put_be32(pb, 0); // Reserved
- put_be16(pb, 0); // Reserved
- put_be16(pb, 1); // Data-reference index
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be16(pb, track->enc->width); // Width
- put_be16(pb, track->enc->height); // Height
- put_be32(pb, 0x00480000); // Reserved
- put_be32(pb, 0x00480000); // Reserved
- put_be32(pb, 0); // Reserved
- put_be16(pb, 1); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be32(pb, 0); // Reserved
- put_be16(pb, 24); // Reserved
- put_be16(pb, 0xFFFF); // Reserved
- mov_write_esds_tag(pb, track);
- return updateSize(pb, pos);
-}
-
-static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "stsd");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, 1); /* entry count */
- if (track->enc->codec_type == CODEC_TYPE_VIDEO) {
- if (track->enc->codec_id == CODEC_ID_H263)
- mov_write_s263_tag(pb, track);
- else if (track->enc->codec_id == CODEC_ID_MPEG4)
- mov_write_mp4v_tag(pb, track);
- }
- else if (track->enc->codec_type == CODEC_TYPE_AUDIO) {
- if (track->enc->codec_id == CODEC_ID_AMR_NB)
- mov_write_samr_tag(pb, track);
- }
- return updateSize(pb, pos);
-}
-
-static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track)
-{
- put_be32(pb, 0x18); /* size */
- put_tag(pb, "stts");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, 1); /* entry count */
-
- put_be32(pb, track->samples); /* sample count */
- put_be32(pb, track->sampleDelta); /* sample delta */
- return 0x18;
-}
-
-static int mov_write_dref_tag(ByteIOContext *pb)
-{
- put_be32(pb, 28); /* size */
- put_tag(pb, "dref");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, 1); /* entry count */
-
- put_be32(pb, 0xc); /* size */
- put_tag(pb, "url ");
- put_be32(pb, 1); /* version & flags */
-
- return 28;
-}
-
-static int mov_write_stbl_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "stbl");
- mov_write_stsd_tag(pb, track);
- mov_write_stts_tag(pb, track);
- if (track->enc->codec_type == CODEC_TYPE_VIDEO)
- mov_write_stss_tag(pb);
- mov_write_stsc_tag(pb, track);
- mov_write_stsz_tag(pb, track);
- mov_write_stco_tag(pb, track);
- return updateSize(pb, pos);
-}
-
-static int mov_write_dinf_tag(ByteIOContext *pb)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "dinf");
- mov_write_dref_tag(pb);
- return updateSize(pb, pos);
-}
-
-static int mov_write_smhd_tag(ByteIOContext *pb)
-{
- put_be32(pb, 16); /* size */
- put_tag(pb, "smhd");
- put_be32(pb, 0); /* version & flags */
- put_be16(pb, 0); /* reserved (balance, normally = 0) */
- put_be16(pb, 0); /* reserved */
- return 16;
-}
-
-static int mov_write_vmhd_tag(ByteIOContext *pb)
-{
- put_be32(pb, 0x14); /* size (always 0x14) */
- put_tag(pb, "vmhd");
- put_be32(pb, 0x01); /* version & flags */
- put_be64(pb, 0); /* reserved (graphics mode = copy) */
- return 0x14;
-}
-
-static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "minf");
- if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- mov_write_vmhd_tag(pb);
- else
- mov_write_smhd_tag(pb);
- mov_write_dinf_tag(pb);
- mov_write_stbl_tag(pb, track);
- return updateSize(pb, pos);
-}
-
-static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int size = 0;
- size = 45;
- put_be32(pb, size); /* size */
- put_tag(pb, "hdlr");
- put_be32(pb, 0); /* Version & flags */
- put_be32(pb, 0); /* reserved */
- if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- put_tag(pb, "vide"); /* handler type */
- else
- put_tag(pb, "soun"); /* handler type */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- put_byte(pb, 0); /* reserved */
- if(track->enc->codec_type == CODEC_TYPE_VIDEO)
- put_buffer(pb, "VideoHandler", 13);
- else
- put_buffer(pb, "SoundHandler", 13);
- return size;
-}
-
-static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track)
-{
- put_be32(pb, 32); /* size */
- put_tag(pb, "mdhd");
- put_be32(pb, 0); /* Version & flags */
- put_be32(pb, track->time); /* creation time */
- put_be32(pb, track->time); /* modification time */
- put_be32(pb, track->timescale); /* time scale */
-
- put_be32(pb, track->timescale*track->entry*track->frameDuration/globalTimescale); /* duration */
- put_be16(pb, 0); /* language, 0 = english */
- put_be16(pb, 0); /* reserved (quality) */
- return 32;
-}
-
-static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "mdia");
- mov_write_mdhd_tag(pb, track);
- mov_write_hdlr_tag(pb, track);
- mov_write_minf_tag(pb, track);
- return updateSize(pb, pos);
-}
-
-static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track)
-{
- put_be32(pb, 0x5c); /* size (always 0x5c) */
- put_tag(pb, "tkhd");
- put_be32(pb, 1); /* version & flags (track enabled) */
- put_be32(pb, track->time); /* creation time */
- put_be32(pb, track->time); /* modification time */
- put_be32(pb, track->trackID); /* track-id */
- put_be32(pb, 0); /* reserved */
- put_be32(pb, track->entry*track->frameDuration); /* duration */
-
- put_be32(pb, 0); /* reserved */
- put_be32(pb, 0); /* reserved */
- put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */
- /* Volume, only for audio */
- if(track->enc->codec_type == CODEC_TYPE_AUDIO)
- put_be16(pb, 0x0100);
- else
- put_be16(pb, 0);
- put_be16(pb, 0); /* reserved */
-
- /* Matrix structure */
- put_be32(pb, 0x00010000); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x00010000); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x40000000); /* reserved */
-
- /* Track width and height, for visual only */
- if(track->enc->codec_type == CODEC_TYPE_VIDEO) {
- put_be32(pb, 0x01400000);
- put_be32(pb, 0x00f00000);
- }
- else {
- put_be32(pb, 0);
- put_be32(pb, 0);
- }
- return 0x5c;
-}
-
-static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack* track)
-{
- int pos = url_ftell(pb);
- put_be32(pb, 0); /* size */
- put_tag(pb, "trak");
- mov_write_tkhd_tag(pb, track);
- mov_write_mdia_tag(pb, track);
- return updateSize(pb, pos);
-}
-
-/* TODO: Not sorted out, but not necessary either */
-static int mov_write_iods_tag(ByteIOContext *pb, MOVContext *mov)
-{
- put_be32(pb, 0x15); /* size */
- put_tag(pb, "iods");
- put_be32(pb, 0); /* version & flags */
- put_be16(pb, 0x1007);
- put_byte(pb, 0);
- put_be16(pb, 0x4fff);
- put_be16(pb, 0xfffe);
- put_be16(pb, 0x01ff);
- return 0x15;
-}
-
-static int mov_write_mvhd_tag(ByteIOContext *pb, MOVContext *mov)
-{
- int maxTrackID = 1, maxTrackLen = 0, i;
-
- put_be32(pb, 0x6c); /* size (always 0x6c) */
- put_tag(pb, "mvhd");
- put_be32(pb, 0); /* version & flags */
- put_be32(pb, mov->time); /* creation time */
- put_be32(pb, mov->time); /* modification time */
- put_be32(pb, mov->timescale); /* timescale */
- for (i=0; i<MAX_STREAMS; i++) {
- if(mov->tracks[i].entry > 0) {
- if(maxTrackLen < mov->tracks[i].entry*mov->tracks[i].frameDuration)
- maxTrackLen = mov->tracks[i].entry*mov->tracks[i].frameDuration;
- if(maxTrackID < mov->tracks[i].trackID)
- maxTrackID = mov->tracks[i].trackID;
- }
- }
- put_be32(pb, maxTrackLen); /* duration of longest track */
-
- put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */
- put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */
- put_be16(pb, 0); /* reserved */
- put_be32(pb, 0); /* reserved */
- put_be32(pb, 0); /* reserved */
-
- /* Matrix structure */
- put_be32(pb, 0x00010000); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x00010000); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x0); /* reserved */
- put_be32(pb, 0x40000000); /* reserved */
-
- put_be32(pb, 0); /* reserved (preview time) */
- put_be32(pb, 0); /* reserved (preview duration) */
- put_be32(pb, 0); /* reserved (poster time) */
- put_be32(pb, 0); /* reserved (selection time) */
- put_be32(pb, 0); /* reserved (selection duration) */
- put_be32(pb, 0); /* reserved (current time) */
- put_be32(pb, maxTrackID+1); /* Next track id */
- return 0x6c;
-}
-
-static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov)
-{
- int pos, i;
- pos = url_ftell(pb);
- put_be32(pb, 0); /* size placeholder*/
- put_tag(pb, "moov");
- mov->timescale = globalTimescale;
-
- for (i=0; i<MAX_STREAMS; i++) {
- if(mov->tracks[i].entry > 0) {
- if(mov->tracks[i].enc->codec_type == CODEC_TYPE_VIDEO) {
- mov->tracks[i].timescale = globalTimescale;
- mov->tracks[i].sampleDelta = mov->tracks[i].frameDuration =
- globalTimescale*mov->tracks[i].enc->frame_rate_base/mov->tracks[i].enc->frame_rate;
- }
- else if(mov->tracks[i].enc->codec_type == CODEC_TYPE_AUDIO) {
- /* If AMR, track timescale = 8000, AMR_WB = 16000 */
- if(mov->tracks[i].enc->codec_id == CODEC_ID_AMR_NB) {
- mov->tracks[i].frameDuration = 20;
- mov->tracks[i].sampleDelta = 160;
- mov->tracks[i].timescale = 8000;
- }
- else {
- mov->tracks[i].timescale = globalTimescale;
- mov->tracks[i].frameDuration =
- globalTimescale*mov->tracks[i].enc->frame_rate_base/mov->tracks[i].enc->frame_rate;
- }
- }
- mov->tracks[i].time = mov->time;
- mov->tracks[i].trackID = i+1;
- }
- }
-
- mov_write_mvhd_tag(pb, mov);
- //mov_write_iods_tag(pb, mov);
- for (i=0; i<MAX_STREAMS; i++) {
- if(mov->tracks[i].entry > 0) {
- mov_write_trak_tag(pb, &(mov->tracks[i]));
- }
- }
-
- return updateSize(pb, pos);
-}
-
-int mov_write_mdat_tag(ByteIOContext *pb, MOVTrack* track)
-{
- track->mdat_pos = url_ftell(pb);
- put_be32(pb, 0); /* size placeholder*/
- put_tag(pb, "mdat");
- return 0;
-}
-
-/* TODO: This needs to be more general */
-int mov_write_ftyp_tag(ByteIOContext *pb)
-{
- put_be32(pb, 0x14 ); /* size */
- put_tag(pb, "ftyp");
- put_tag(pb, "3gp4");
- put_be32(pb, 0x200 );
- put_tag(pb, "3gp4");
- return 0x14;
-}
-
-static int mov_write_header(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
-
- /* write ftyp */
- mov_write_ftyp_tag(pb);
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int Timestamp() {
- time_t ltime;
- time ( <ime );
- return ltime+(24107*86400);
-}
-
-static int mov_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- MOVContext *mov = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc;
- int cl, id;
-
- enc = &s->streams[stream_index]->codec;
- if (!url_is_streamed(&s->pb)) {
- MOVTrack* trk = &mov->tracks[stream_index];
- int sampleCount = 0;
-
- /* We must find out how many AMR blocks there are in one packet */
- if(enc->codec_id == CODEC_ID_AMR_NB) {
- static uint16_t packed_size[16] = {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
- int len = 0;
-
- while(len < size && sampleCount < 100) {
- len += packed_size[(buf[len] >> 3) & 0x0F];
- sampleCount++;
- }
- }
-
- if(enc->codec_id == CODEC_ID_MPEG4 &&
- trk->vosLen == 0)
- {
- assert(enc->extradata_size);
-
- trk->vosLen = enc->extradata_size;
- trk->vosData = av_malloc(trk->vosLen);
- memcpy(trk->vosData, enc->extradata, trk->vosLen);
- }
-
- cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;
- id = trk->entry % MOV_INDEX_CLUSTER_SIZE;
-
- if (trk->ents_allocated <= trk->entry) {
- trk->cluster = av_realloc(trk->cluster, (cl+1)*sizeof(void*));
- if (!trk->cluster)
- return -1;
- trk->cluster[cl] = av_malloc(MOV_INDEX_CLUSTER_SIZE*sizeof(MOVIentry));
- if (!trk->cluster[cl])
- return -1;
- trk->ents_allocated += MOV_INDEX_CLUSTER_SIZE;
- }
- if(stream_index == 0 && trk->entry == 0) {
- mov_write_mdat_tag(pb, trk);
- mov->time = Timestamp();
- }
-
- trk->cluster[cl][id].pos = url_ftell(pb) - mov->movi_list;
- trk->cluster[cl][id].len = size;
- trk->cluster[cl][id].entries = sampleCount;
- trk->enc = enc;
- trk->entry++;
- if(sampleCount == 0)
- trk->samples++;
- else
- trk->samples += sampleCount;
- trk->mdat_size += size;
- }
- put_buffer(pb, buf, size);
-
- put_flush_packet(pb);
- return 0;
-}
-
-static int mov_write_trailer(AVFormatContext *s)
-{
- MOVContext *mov = s->priv_data;
- ByteIOContext *pb = &s->pb;
- int res = 0;
- int i, j;
- offset_t file_size;
-
- file_size = url_ftell(pb);
- j = 0;
-
- /* Write size of mdat tag */
- for (i=0; i<MAX_STREAMS; i++) {
- if(mov->tracks[i].ents_allocated > 0) {
- j += mov->tracks[i].mdat_size;
- }
- }
- url_fseek(pb, mov->tracks[0].mdat_pos, SEEK_SET);
- put_be32(pb, j+8);
- url_fseek(pb, file_size, SEEK_SET);
-
- mov_write_moov_tag(pb, mov);
-
- for (i=0; i<MAX_STREAMS; i++) {
- for (j=0; j<mov->tracks[i].ents_allocated/MOV_INDEX_CLUSTER_SIZE; j++) {
- av_free(mov->tracks[i].cluster[j]);
- }
- av_free(mov->tracks[i].cluster);
- mov->tracks[i].cluster = NULL;
- mov->tracks[i].ents_allocated = mov->tracks[i].entry = 0;
- }
- put_flush_packet(pb);
-
- return res;
-}
-
-static AVOutputFormat mov_oformat = {
- "mov",
- "mov format",
- NULL,
- "mov",
- sizeof(MOVContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG4,
- mov_write_header,
- mov_write_packet,
- mov_write_trailer,
-};
-
-static AVOutputFormat _3gp_oformat = {
- "3gp",
- "3gp format",
- NULL,
- "3gp",
- sizeof(MOVContext),
- CODEC_ID_AMR_NB,
- CODEC_ID_H263,
- mov_write_header,
- mov_write_packet,
- mov_write_trailer,
-};
-
-static AVOutputFormat mp4_oformat = {
- "mp4",
- "mp4 format",
- NULL,
- "mp4",
- sizeof(MOVContext),
- CODEC_ID_AAC,
- CODEC_ID_MPEG4,
- mov_write_header,
- mov_write_packet,
- mov_write_trailer,
-};
-
-int movenc_init(void)
-{
- av_register_output_format(&mov_oformat);
- av_register_output_format(&_3gp_oformat);
- av_register_output_format(&mp4_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * MP3 encoder and decoder
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#define ID3_HEADER_SIZE 10
-#define ID3_TAG_SIZE 128
-
-#define ID3_GENRE_MAX 125
-
-static const char *id3_genre_str[ID3_GENRE_MAX + 1] = {
- [0] = "Blues",
- [1] = "Classic Rock",
- [2] = "Country",
- [3] = "Dance",
- [4] = "Disco",
- [5] = "Funk",
- [6] = "Grunge",
- [7] = "Hip-Hop",
- [8] = "Jazz",
- [9] = "Metal",
- [10] = "New Age",
- [11] = "Oldies",
- [12] = "Other",
- [13] = "Pop",
- [14] = "R&B",
- [15] = "Rap",
- [16] = "Reggae",
- [17] = "Rock",
- [18] = "Techno",
- [19] = "Industrial",
- [20] = "Alternative",
- [21] = "Ska",
- [22] = "Death Metal",
- [23] = "Pranks",
- [24] = "Soundtrack",
- [25] = "Euro-Techno",
- [26] = "Ambient",
- [27] = "Trip-Hop",
- [28] = "Vocal",
- [29] = "Jazz+Funk",
- [30] = "Fusion",
- [31] = "Trance",
- [32] = "Classical",
- [33] = "Instrumental",
- [34] = "Acid",
- [35] = "House",
- [36] = "Game",
- [37] = "Sound Clip",
- [38] = "Gospel",
- [39] = "Noise",
- [40] = "AlternRock",
- [41] = "Bass",
- [42] = "Soul",
- [43] = "Punk",
- [44] = "Space",
- [45] = "Meditative",
- [46] = "Instrumental Pop",
- [47] = "Instrumental Rock",
- [48] = "Ethnic",
- [49] = "Gothic",
- [50] = "Darkwave",
- [51] = "Techno-Industrial",
- [52] = "Electronic",
- [53] = "Pop-Folk",
- [54] = "Eurodance",
- [55] = "Dream",
- [56] = "Southern Rock",
- [57] = "Comedy",
- [58] = "Cult",
- [59] = "Gangsta",
- [60] = "Top 40",
- [61] = "Christian Rap",
- [62] = "Pop/Funk",
- [63] = "Jungle",
- [64] = "Native American",
- [65] = "Cabaret",
- [66] = "New Wave",
- [67] = "Psychadelic",
- [68] = "Rave",
- [69] = "Showtunes",
- [70] = "Trailer",
- [71] = "Lo-Fi",
- [72] = "Tribal",
- [73] = "Acid Punk",
- [74] = "Acid Jazz",
- [75] = "Polka",
- [76] = "Retro",
- [77] = "Musical",
- [78] = "Rock & Roll",
- [79] = "Hard Rock",
- [80] = "Folk",
- [81] = "Folk-Rock",
- [82] = "National Folk",
- [83] = "Swing",
- [84] = "Fast Fusion",
- [85] = "Bebob",
- [86] = "Latin",
- [87] = "Revival",
- [88] = "Celtic",
- [89] = "Bluegrass",
- [90] = "Avantgarde",
- [91] = "Gothic Rock",
- [92] = "Progressive Rock",
- [93] = "Psychedelic Rock",
- [94] = "Symphonic Rock",
- [95] = "Slow Rock",
- [96] = "Big Band",
- [97] = "Chorus",
- [98] = "Easy Listening",
- [99] = "Acoustic",
- [100] = "Humour",
- [101] = "Speech",
- [102] = "Chanson",
- [103] = "Opera",
- [104] = "Chamber Music",
- [105] = "Sonata",
- [106] = "Symphony",
- [107] = "Booty Bass",
- [108] = "Primus",
- [109] = "Porn Groove",
- [110] = "Satire",
- [111] = "Slow Jam",
- [112] = "Club",
- [113] = "Tango",
- [114] = "Samba",
- [115] = "Folklore",
- [116] = "Ballad",
- [117] = "Power Ballad",
- [118] = "Rhythmic Soul",
- [119] = "Freestyle",
- [120] = "Duet",
- [121] = "Punk Rock",
- [122] = "Drum Solo",
- [123] = "A capella",
- [124] = "Euro-House",
- [125] = "Dance Hall",
-};
-
-/* buf must be ID3_HEADER_SIZE byte long */
-static int id3_match(const uint8_t *buf)
-{
- return (buf[0] == 'I' &&
- buf[1] == 'D' &&
- buf[2] == '3' &&
- buf[3] != 0xff &&
- buf[4] != 0xff &&
- (buf[6] & 0x80) == 0 &&
- (buf[7] & 0x80) == 0 &&
- (buf[8] & 0x80) == 0 &&
- (buf[9] & 0x80) == 0);
-}
-
-static void id3_get_string(char *str, int str_size,
- const uint8_t *buf, int buf_size)
-{
- int i, c;
- char *q;
-
- q = str;
- for(i = 0; i < buf_size; i++) {
- c = buf[i];
- if (c == '\0')
- break;
- if ((q - str) >= str_size - 1)
- break;
- *q++ = c;
- }
- *q = '\0';
-}
-
-/* 'buf' must be ID3_TAG_SIZE byte long */
-static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf)
-{
- char str[5];
- int genre;
-
- if (!(buf[0] == 'T' &&
- buf[1] == 'A' &&
- buf[2] == 'G'))
- return -1;
- id3_get_string(s->title, sizeof(s->title), buf + 3, 30);
- id3_get_string(s->author, sizeof(s->author), buf + 33, 30);
- id3_get_string(s->album, sizeof(s->album), buf + 63, 30);
- id3_get_string(str, sizeof(str), buf + 93, 4);
- s->year = atoi(str);
- id3_get_string(s->comment, sizeof(s->comment), buf + 97, 30);
- if (buf[125] == 0 && buf[126] != 0)
- s->track = buf[126];
- genre = buf[127];
- if (genre <= ID3_GENRE_MAX)
- pstrcpy(s->genre, sizeof(s->genre), id3_genre_str[genre]);
- return 0;
-}
-
-static void id3_create_tag(AVFormatContext *s, uint8_t *buf)
-{
- int v, i;
-
- memset(buf, 0, ID3_TAG_SIZE); /* fail safe */
- buf[0] = 'T';
- buf[1] = 'A';
- buf[2] = 'G';
- strncpy(buf + 3, s->title, 30);
- strncpy(buf + 33, s->author, 30);
- strncpy(buf + 63, s->album, 30);
- v = s->year;
- if (v > 0) {
- for(i = 0;i < 4; i++) {
- buf[96 - i] = '0' + (v % 10);
- v = v / 10;
- }
- }
- strncpy(buf + 97, s->comment, 30);
- if (s->track != 0) {
- buf[125] = 0;
- buf[126] = s->track;
- }
- for(i = 0; i <= ID3_GENRE_MAX; i++) {
- if (!strcasecmp(s->genre, id3_genre_str[i])) {
- buf[127] = i;
- break;
- }
- }
-}
-
-/* mp3 read */
-static int mp3_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *st;
- uint8_t buf[ID3_TAG_SIZE];
- int len, ret, filesize;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_MP3;
-
- /* try to get the TAG */
- if (!url_is_streamed(&s->pb)) {
- /* XXX: change that */
- filesize = url_filesize(url_fileno(&s->pb));
- if (filesize > 128) {
- url_fseek(&s->pb, filesize - 128, SEEK_SET);
- ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE);
- if (ret == ID3_TAG_SIZE) {
- id3_parse_tag(s, buf);
- }
- url_fseek(&s->pb, 0, SEEK_SET);
- }
- }
-
- /* if ID3 header found, skip it */
- ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE);
- if (ret != ID3_HEADER_SIZE)
- return -1;
- if (id3_match(buf)) {
- /* skip ID3 header */
- len = ((buf[6] & 0x7f) << 21) |
- ((buf[7] & 0x7f) << 14) |
- ((buf[8] & 0x7f) << 7) |
- (buf[9] & 0x7f);
- url_fskip(&s->pb, len);
- } else {
- url_fseek(&s->pb, 0, SEEK_SET);
- }
-
- /* the parameters will be extracted from the compressed bitstream */
- return 0;
-}
-
-#define MP3_PACKET_SIZE 1024
-
-static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret, size;
- // AVStream *st = s->streams[0];
-
- size= MP3_PACKET_SIZE;
-
- if (av_new_packet(pkt, size) < 0)
- return -EIO;
-
- pkt->stream_index = 0;
- ret = get_buffer(&s->pb, pkt->data, size);
- if (ret <= 0) {
- av_free_packet(pkt);
- return -EIO;
- }
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- return ret;
-}
-
-static int mp3_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-/* simple formats */
-static int mp3_write_header(struct AVFormatContext *s)
-{
- return 0;
-}
-
-static int mp3_write_packet(struct AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int mp3_write_trailer(struct AVFormatContext *s)
-{
- uint8_t buf[ID3_TAG_SIZE];
-
- /* write the id3 header */
- if (s->title[0] != '\0') {
- id3_create_tag(s, buf);
- put_buffer(&s->pb, buf, ID3_TAG_SIZE);
- put_flush_packet(&s->pb);
- }
- return 0;
-}
-
-AVInputFormat mp3_iformat = {
- "mp3",
- "MPEG audio",
- 0,
- NULL,
- mp3_read_header,
- mp3_read_packet,
- mp3_read_close,
- .extensions = "mp2,mp3", /* XXX: use probe */
-};
-
-AVOutputFormat mp2_oformat = {
- "mp2",
- "MPEG audio layer 2",
- "audio/x-mpeg",
-#ifdef CONFIG_MP3LAME
- "mp2",
-#else
- "mp2,mp3",
-#endif
- 0,
- CODEC_ID_MP2,
- 0,
- mp3_write_header,
- mp3_write_packet,
- mp3_write_trailer,
-};
-
-#ifdef CONFIG_MP3LAME
-AVOutputFormat mp3_oformat = {
- "mp3",
- "MPEG audio layer 3",
- "audio/x-mpeg",
- "mp3",
- 0,
- CODEC_ID_MP3,
- 0,
- mp3_write_header,
- mp3_write_packet,
- mp3_write_trailer,
-};
-#endif
-
-int mp3_init(void)
-{
- av_register_input_format(&mp3_iformat);
- av_register_output_format(&mp2_oformat);
-#ifdef CONFIG_MP3LAME
- av_register_output_format(&mp3_oformat);
-#endif
- return 0;
-}
+++ /dev/null
-/*
- * MPEG1/2 mux/demux
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#define MAX_PAYLOAD_SIZE 4096
-#define NB_STREAMS 2
-
-typedef struct {
- uint8_t buffer[MAX_PAYLOAD_SIZE];
- int buffer_ptr;
- uint8_t id;
- int max_buffer_size; /* in bytes */
- int packet_number;
- int64_t start_pts;
-} StreamInfo;
-
-typedef struct {
- int packet_size; /* required packet size */
- int packet_data_max_size; /* maximum data size inside a packet */
- int packet_number;
- int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */
- int system_header_freq;
- int mux_rate; /* bitrate in units of 50 bytes/s */
- /* stream info */
- int audio_bound;
- int video_bound;
- int is_mpeg2;
- int is_vcd;
-} MpegMuxContext;
-
-#define PACK_START_CODE ((unsigned int)0x000001ba)
-#define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb)
-#define SEQUENCE_END_CODE ((unsigned int)0x000001b7)
-#define PACKET_START_CODE_MASK ((unsigned int)0xffffff00)
-#define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100)
-#define ISO_11172_END_CODE ((unsigned int)0x000001b9)
-
-/* mpeg2 */
-#define PROGRAM_STREAM_MAP 0x1bc
-#define PRIVATE_STREAM_1 0x1bd
-#define PADDING_STREAM 0x1be
-#define PRIVATE_STREAM_2 0x1bf
-
-
-#define AUDIO_ID 0xc0
-#define VIDEO_ID 0xe0
-
-extern AVOutputFormat mpeg1system_mux;
-extern AVOutputFormat mpeg1vcd_mux;
-extern AVOutputFormat mpeg2vob_mux;
-
-static int put_pack_header(AVFormatContext *ctx,
- uint8_t *buf, int64_t timestamp)
-{
- MpegMuxContext *s = ctx->priv_data;
- PutBitContext pb;
-
- init_put_bits(&pb, buf, 128, NULL, NULL);
-
- put_bits(&pb, 32, PACK_START_CODE);
- if (s->is_mpeg2) {
- put_bits(&pb, 2, 0x1);
- } else {
- put_bits(&pb, 4, 0x2);
- }
- put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07));
- put_bits(&pb, 1, 1);
- put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff));
- put_bits(&pb, 1, 1);
- put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff));
- put_bits(&pb, 1, 1);
- if (s->is_mpeg2) {
- /* clock extension */
- put_bits(&pb, 9, 0);
- put_bits(&pb, 1, 1);
- }
- put_bits(&pb, 1, 1);
- put_bits(&pb, 22, s->mux_rate);
- put_bits(&pb, 1, 1);
- if (s->is_mpeg2) {
- put_bits(&pb, 5, 0x1f); /* reserved */
- put_bits(&pb, 3, 0); /* stuffing length */
- }
- flush_put_bits(&pb);
- return pbBufPtr(&pb) - pb.buf;
-}
-
-static int put_system_header(AVFormatContext *ctx, uint8_t *buf)
-{
- MpegMuxContext *s = ctx->priv_data;
- int size, rate_bound, i, private_stream_coded, id;
- PutBitContext pb;
-
- init_put_bits(&pb, buf, 128, NULL, NULL);
-
- put_bits(&pb, 32, SYSTEM_HEADER_START_CODE);
- put_bits(&pb, 16, 0);
- put_bits(&pb, 1, 1);
-
- rate_bound = s->mux_rate; /* maximum bit rate of the multiplexed stream */
- put_bits(&pb, 22, rate_bound);
- put_bits(&pb, 1, 1); /* marker */
- put_bits(&pb, 6, s->audio_bound);
-
- put_bits(&pb, 1, 1); /* variable bitrate */
- put_bits(&pb, 1, 1); /* non constrainted bit stream */
-
- put_bits(&pb, 1, 0); /* audio locked */
- put_bits(&pb, 1, 0); /* video locked */
- put_bits(&pb, 1, 1); /* marker */
-
- put_bits(&pb, 5, s->video_bound);
- put_bits(&pb, 8, 0xff); /* reserved byte */
-
- /* audio stream info */
- private_stream_coded = 0;
- for(i=0;i<ctx->nb_streams;i++) {
- StreamInfo *stream = ctx->streams[i]->priv_data;
- id = stream->id;
- if (id < 0xc0) {
- /* special case for private streams (AC3 use that) */
- if (private_stream_coded)
- continue;
- private_stream_coded = 1;
- id = 0xbd;
- }
- put_bits(&pb, 8, id); /* stream ID */
- put_bits(&pb, 2, 3);
- if (id < 0xe0) {
- /* audio */
- put_bits(&pb, 1, 0);
- put_bits(&pb, 13, stream->max_buffer_size / 128);
- } else {
- /* video */
- put_bits(&pb, 1, 1);
- put_bits(&pb, 13, stream->max_buffer_size / 1024);
- }
- }
- flush_put_bits(&pb);
- size = pbBufPtr(&pb) - pb.buf;
- /* patch packet size */
- buf[4] = (size - 6) >> 8;
- buf[5] = (size - 6) & 0xff;
-
- return size;
-}
-
-static int mpeg_mux_init(AVFormatContext *ctx)
-{
- MpegMuxContext *s = ctx->priv_data;
- int bitrate, i, mpa_id, mpv_id, ac3_id;
- AVStream *st;
- StreamInfo *stream;
-
- s->packet_number = 0;
- s->is_vcd = (ctx->oformat == &mpeg1vcd_mux);
- s->is_mpeg2 = (ctx->oformat == &mpeg2vob_mux);
-
- if (s->is_vcd)
- s->packet_size = 2324; /* VCD packet size */
- else
- s->packet_size = 2048;
-
- /* startcode(4) + length(2) + flags(1) */
- s->packet_data_max_size = s->packet_size - 7;
- s->audio_bound = 0;
- s->video_bound = 0;
- mpa_id = AUDIO_ID;
- ac3_id = 0x80;
- mpv_id = VIDEO_ID;
- for(i=0;i<ctx->nb_streams;i++) {
- st = ctx->streams[i];
- stream = av_mallocz(sizeof(StreamInfo));
- if (!stream)
- goto fail;
- st->priv_data = stream;
-
- switch(st->codec.codec_type) {
- case CODEC_TYPE_AUDIO:
- if (st->codec.codec_id == CODEC_ID_AC3)
- stream->id = ac3_id++;
- else
- stream->id = mpa_id++;
- stream->max_buffer_size = 4 * 1024;
- s->audio_bound++;
- break;
- case CODEC_TYPE_VIDEO:
- stream->id = mpv_id++;
- stream->max_buffer_size = 46 * 1024;
- s->video_bound++;
- break;
- default:
- av_abort();
- }
- }
-
- /* we increase slightly the bitrate to take into account the
- headers. XXX: compute it exactly */
- bitrate = 2000;
- for(i=0;i<ctx->nb_streams;i++) {
- st = ctx->streams[i];
- bitrate += st->codec.bit_rate;
- }
- s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50);
-
- if (s->is_vcd || s->is_mpeg2)
- /* every packet */
- s->pack_header_freq = 1;
- else
- /* every 2 seconds */
- s->pack_header_freq = 2 * bitrate / s->packet_size / 8;
-
- if (s->is_mpeg2)
- /* every 200 packets. Need to look at the spec. */
- s->system_header_freq = s->pack_header_freq * 40;
- else if (s->is_vcd)
- /* every 40 packets, this is my invention */
- s->system_header_freq = s->pack_header_freq * 40;
- else
- s->system_header_freq = s->pack_header_freq * 5;
-
- for(i=0;i<ctx->nb_streams;i++) {
- stream = ctx->streams[i]->priv_data;
- stream->buffer_ptr = 0;
- stream->packet_number = 0;
- stream->start_pts = -1;
- }
- return 0;
- fail:
- for(i=0;i<ctx->nb_streams;i++) {
- av_free(ctx->streams[i]->priv_data);
- }
- return -ENOMEM;
-}
-
-/* flush the packet on stream stream_index */
-static void flush_packet(AVFormatContext *ctx, int stream_index)
-{
- MpegMuxContext *s = ctx->priv_data;
- StreamInfo *stream = ctx->streams[stream_index]->priv_data;
- uint8_t *buf_ptr;
- int size, payload_size, startcode, id, len, stuffing_size, i, header_len;
- int64_t timestamp;
- uint8_t buffer[128];
-
- id = stream->id;
- timestamp = stream->start_pts;
-
-#if 0
- printf("packet ID=%2x PTS=%0.3f\n",
- id, timestamp / 90000.0);
-#endif
-
- buf_ptr = buffer;
- if (((s->packet_number % s->pack_header_freq) == 0)) {
- /* output pack and systems header if needed */
- size = put_pack_header(ctx, buf_ptr, timestamp);
- buf_ptr += size;
- if ((s->packet_number % s->system_header_freq) == 0) {
- size = put_system_header(ctx, buf_ptr);
- buf_ptr += size;
- }
- }
- size = buf_ptr - buffer;
- put_buffer(&ctx->pb, buffer, size);
-
- /* packet header */
- if (s->is_mpeg2) {
- header_len = 8;
- } else {
- header_len = 5;
- }
- payload_size = s->packet_size - (size + 6 + header_len);
- if (id < 0xc0) {
- startcode = PRIVATE_STREAM_1;
- payload_size -= 4;
- } else {
- startcode = 0x100 + id;
- }
- stuffing_size = payload_size - stream->buffer_ptr;
- if (stuffing_size < 0)
- stuffing_size = 0;
-
- put_be32(&ctx->pb, startcode);
-
- put_be16(&ctx->pb, payload_size + header_len);
- /* stuffing */
- for(i=0;i<stuffing_size;i++)
- put_byte(&ctx->pb, 0xff);
-
- if (s->is_mpeg2) {
- put_byte(&ctx->pb, 0x80); /* mpeg2 id */
- put_byte(&ctx->pb, 0x80); /* flags */
- put_byte(&ctx->pb, 0x05); /* header len (only pts is included) */
- }
- put_byte(&ctx->pb,
- (0x02 << 4) |
- (((timestamp >> 30) & 0x07) << 1) |
- 1);
- put_be16(&ctx->pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
- put_be16(&ctx->pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
-
- if (startcode == PRIVATE_STREAM_1) {
- put_byte(&ctx->pb, id);
- if (id >= 0x80 && id <= 0xbf) {
- /* XXX: need to check AC3 spec */
- put_byte(&ctx->pb, 1);
- put_byte(&ctx->pb, 0);
- put_byte(&ctx->pb, 2);
- }
- }
-
- /* output data */
- put_buffer(&ctx->pb, stream->buffer, payload_size - stuffing_size);
- put_flush_packet(&ctx->pb);
-
- /* preserve remaining data */
- len = stream->buffer_ptr - payload_size;
- if (len < 0)
- len = 0;
- memmove(stream->buffer, stream->buffer + stream->buffer_ptr - len, len);
- stream->buffer_ptr = len;
-
- s->packet_number++;
- stream->packet_number++;
- stream->start_pts = -1;
-}
-
-static int mpeg_mux_write_packet(AVFormatContext *ctx, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- MpegMuxContext *s = ctx->priv_data;
- AVStream *st = ctx->streams[stream_index];
- StreamInfo *stream = st->priv_data;
- int len;
-
- while (size > 0) {
- /* set pts */
- if (stream->start_pts == -1) {
- stream->start_pts = pts;
- }
- len = s->packet_data_max_size - stream->buffer_ptr;
- if (len > size)
- len = size;
- memcpy(stream->buffer + stream->buffer_ptr, buf, len);
- stream->buffer_ptr += len;
- buf += len;
- size -= len;
- while (stream->buffer_ptr >= s->packet_data_max_size) {
- /* output the packet */
- if (stream->start_pts == -1)
- stream->start_pts = pts;
- flush_packet(ctx, stream_index);
- }
- }
- return 0;
-}
-
-static int mpeg_mux_end(AVFormatContext *ctx)
-{
- StreamInfo *stream;
- int i;
-
- /* flush each packet */
- for(i=0;i<ctx->nb_streams;i++) {
- stream = ctx->streams[i]->priv_data;
- if (stream->buffer_ptr > 0) {
- flush_packet(ctx, i);
- }
- }
-
- /* End header according to MPEG1 systems standard. We do not write
- it as it is usually not needed by decoders and because it
- complicates MPEG stream concatenation. */
- //put_be32(&ctx->pb, ISO_11172_END_CODE);
- //put_flush_packet(&ctx->pb);
-
- for(i=0;i<ctx->nb_streams;i++)
- av_freep(&ctx->streams[i]->priv_data);
-
- return 0;
-}
-
-/*********************************************/
-/* demux code */
-
-#define MAX_SYNC_SIZE 100000
-
-static int mpegps_probe(AVProbeData *p)
-{
- int code, c, i;
-
- code = 0xff;
- /* we search the first start code. If it is a packet start code,
- then we decide it is mpeg ps. We do not send highest value to
- give a chance to mpegts */
- /* NOTE: the search range was restricted to avoid too many false
- detections */
-
- if (p->buf_size < 6)
- return 0;
-
- for (i = 0; i < 20; i++) {
- c = p->buf[i];
- code = (code << 8) | c;
- if ((code & 0xffffff00) == 0x100) {
- if (code == PACK_START_CODE ||
- code == SYSTEM_HEADER_START_CODE ||
- (code >= 0x1e0 && code <= 0x1ef) ||
- (code >= 0x1c0 && code <= 0x1df) ||
- code == PRIVATE_STREAM_2 ||
- code == PROGRAM_STREAM_MAP ||
- code == PRIVATE_STREAM_1 ||
- code == PADDING_STREAM)
- return AVPROBE_SCORE_MAX - 2;
- else
- return 0;
- }
- }
- return 0;
-}
-
-
-typedef struct MpegDemuxContext {
- int header_state;
-} MpegDemuxContext;
-
-static int find_start_code(ByteIOContext *pb, int *size_ptr,
- uint32_t *header_state)
-{
- unsigned int state, v;
- int val, n;
-
- state = *header_state;
- n = *size_ptr;
- while (n > 0) {
- if (url_feof(pb))
- break;
- v = get_byte(pb);
- n--;
- if (state == 0x000001) {
- state = ((state << 8) | v) & 0xffffff;
- val = state;
- goto found;
- }
- state = ((state << 8) | v) & 0xffffff;
- }
- val = -1;
- found:
- *header_state = state;
- *size_ptr = n;
- return val;
-}
-
-static int mpegps_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- MpegDemuxContext *m = s->priv_data;
- m->header_state = 0xff;
- /* no need to do more */
- return 0;
-}
-
-static int64_t get_pts(ByteIOContext *pb, int c)
-{
- int64_t pts;
- int val;
-
- if (c < 0)
- c = get_byte(pb);
- pts = (int64_t)((c >> 1) & 0x07) << 30;
- val = get_be16(pb);
- pts |= (int64_t)(val >> 1) << 15;
- val = get_be16(pb);
- pts |= (int64_t)(val >> 1);
- return pts;
-}
-
-static int mpegps_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- MpegDemuxContext *m = s->priv_data;
- AVStream *st;
- int len, size, startcode, i, c, flags, header_len, type, codec_id;
- int64_t pts, dts;
-
- /* next start code (should be immediately after) */
- redo:
- m->header_state = 0xff;
- size = MAX_SYNC_SIZE;
- startcode = find_start_code(&s->pb, &size, &m->header_state);
- //printf("startcode=%x pos=0x%Lx\n", startcode, url_ftell(&s->pb));
- if (startcode < 0)
- return -EIO;
- if (startcode == PACK_START_CODE)
- goto redo;
- if (startcode == SYSTEM_HEADER_START_CODE)
- goto redo;
- if (startcode == PADDING_STREAM ||
- startcode == PRIVATE_STREAM_2) {
- /* skip them */
- len = get_be16(&s->pb);
- url_fskip(&s->pb, len);
- goto redo;
- }
- /* find matching stream */
- if (!((startcode >= 0x1c0 && startcode <= 0x1df) ||
- (startcode >= 0x1e0 && startcode <= 0x1ef) ||
- (startcode == 0x1bd)))
- goto redo;
-
- len = get_be16(&s->pb);
- pts = AV_NOPTS_VALUE;
- dts = AV_NOPTS_VALUE;
- /* stuffing */
- for(;;) {
- c = get_byte(&s->pb);
- len--;
- /* XXX: for mpeg1, should test only bit 7 */
- if (c != 0xff)
- break;
- }
- if ((c & 0xc0) == 0x40) {
- /* buffer scale & size */
- get_byte(&s->pb);
- c = get_byte(&s->pb);
- len -= 2;
- }
- if ((c & 0xf0) == 0x20) {
- pts = get_pts(&s->pb, c);
- len -= 4;
- } else if ((c & 0xf0) == 0x30) {
- pts = get_pts(&s->pb, c);
- dts = get_pts(&s->pb, -1);
- len -= 9;
- } else if ((c & 0xc0) == 0x80) {
- /* mpeg 2 PES */
- if ((c & 0x30) != 0) {
- fprintf(stderr, "Encrypted multiplex not handled\n");
- return -EIO;
- }
- flags = get_byte(&s->pb);
- header_len = get_byte(&s->pb);
- len -= 2;
- if (header_len > len)
- goto redo;
- if ((flags & 0xc0) == 0x80) {
- pts = get_pts(&s->pb, -1);
- header_len -= 5;
- len -= 5;
- } if ((flags & 0xc0) == 0xc0) {
- pts = get_pts(&s->pb, -1);
- dts = get_pts(&s->pb, -1);
- header_len -= 10;
- len -= 10;
- }
- len -= header_len;
- while (header_len > 0) {
- get_byte(&s->pb);
- header_len--;
- }
- }
- if (startcode == 0x1bd) {
- startcode = get_byte(&s->pb);
- len--;
- if (startcode >= 0x80 && startcode <= 0xbf) {
- /* audio: skip header */
- get_byte(&s->pb);
- get_byte(&s->pb);
- get_byte(&s->pb);
- len -= 3;
- }
- }
-
- /* now find stream */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (st->id == startcode)
- goto found;
- }
- if (startcode >= 0x1e0 && startcode <= 0x1ef) {
- type = CODEC_TYPE_VIDEO;
- codec_id = CODEC_ID_MPEG1VIDEO;
- } else if (startcode >= 0x1c0 && startcode <= 0x1df) {
- type = CODEC_TYPE_AUDIO;
- codec_id = CODEC_ID_MP2;
- } else if (startcode >= 0x80 && startcode <= 0x9f) {
- type = CODEC_TYPE_AUDIO;
- codec_id = CODEC_ID_AC3;
- } else if (startcode >= 0xa0 && startcode <= 0xbf) {
- type = CODEC_TYPE_AUDIO;
- codec_id = CODEC_ID_PCM_S16BE;
- } else {
- skip:
- /* skip packet */
- url_fskip(&s->pb, len);
- goto redo;
- }
- /* no stream found: add a new stream */
- st = av_new_stream(s, startcode);
- if (!st)
- goto skip;
- st->codec.codec_type = type;
- st->codec.codec_id = codec_id;
- found:
- if (startcode >= 0xa0 && startcode <= 0xbf) {
- int b1, freq;
- static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 };
-
- /* for LPCM, we just skip the header and consider it is raw
- audio data */
- if (len <= 3)
- goto skip;
- get_byte(&s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */
- b1 = get_byte(&s->pb); /* quant (2), freq(2), reserved(1), channels(3) */
- get_byte(&s->pb); /* dynamic range control (0x80 = off) */
- len -= 3;
- freq = (b1 >> 4) & 3;
- st->codec.sample_rate = lpcm_freq_tab[freq];
- st->codec.channels = 1 + (b1 & 7);
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate * 2;
- }
- av_new_packet(pkt, len);
- //printf("\nRead Packet ID: %x PTS: %f Size: %d", startcode,
- // (float)pts/90000, len);
- get_buffer(&s->pb, pkt->data, pkt->size);
- pkt->pts = pts;
- pkt->stream_index = st->index;
- return 0;
-}
-
-static int mpegps_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVOutputFormat mpeg1system_mux = {
- "mpeg",
- "MPEG1 System format",
- "video/mpeg",
- "mpg,mpeg",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
-};
-
-static AVOutputFormat mpeg1vcd_mux = {
- "vcd",
- "MPEG1 System format (VCD)",
- "video/mpeg",
- NULL,
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
-};
-
-static AVOutputFormat mpeg2vob_mux = {
- "vob",
- "MPEG2 PS format (VOB)",
- "video/mpeg",
- "vob",
- sizeof(MpegMuxContext),
- CODEC_ID_MP2,
- CODEC_ID_MPEG1VIDEO,
- mpeg_mux_init,
- mpeg_mux_write_packet,
- mpeg_mux_end,
-};
-
-AVInputFormat mpegps_demux = {
- "mpeg",
- "MPEG PS format",
- sizeof(MpegDemuxContext),
- mpegps_probe,
- mpegps_read_header,
- mpegps_read_packet,
- mpegps_read_close,
- .flags = AVFMT_NOHEADER,
-};
-
-int mpegps_init(void)
-{
- av_register_output_format(&mpeg1system_mux);
- av_register_output_format(&mpeg1vcd_mux);
- av_register_output_format(&mpeg2vob_mux);
- av_register_input_format(&mpegps_demux);
- return 0;
-}
+++ /dev/null
-/*
- * MPEG2 transport stream (aka DVB) demux
- * Copyright (c) 2002-2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include "mpegts.h"
-
-//#define DEBUG_SI
-
-/* 1.0 second at 24Mbit/s */
-#define MAX_SCAN_PACKETS 32000
-
-/* maximum size in which we look for synchronisation if
- synchronisation is lost */
-#define MAX_RESYNC_SIZE 4096
-
-static int add_pes_stream(AVFormatContext *s, int pid);
-
-enum MpegTSFilterType {
- MPEGTS_PES,
- MPEGTS_SECTION,
-};
-
-typedef void PESCallback(void *opaque, const uint8_t *buf, int len, int is_start);
-
-typedef struct MpegTSPESFilter {
- PESCallback *pes_cb;
- void *opaque;
-} MpegTSPESFilter;
-
-typedef void SectionCallback(void *opaque, const uint8_t *buf, int len);
-
-typedef void SetServiceCallback(void *opaque, int ret);
-
-typedef struct MpegTSSectionFilter {
- int section_index;
- int section_h_size;
- uint8_t *section_buf;
- int check_crc:1;
- int end_of_section_reached:1;
- SectionCallback *section_cb;
- void *opaque;
-} MpegTSSectionFilter;
-
-typedef struct MpegTSFilter {
- int pid;
- int last_cc; /* last cc code (-1 if first packet) */
- enum MpegTSFilterType type;
- union {
- MpegTSPESFilter pes_filter;
- MpegTSSectionFilter section_filter;
- } u;
-} MpegTSFilter;
-
-typedef struct MpegTSService {
- int running:1;
- int sid;
- char *provider_name;
- char *name;
-} MpegTSService;
-
-typedef struct MpegTSContext {
- /* user data */
- AVFormatContext *stream;
- int raw_packet_size; /* raw packet size, including FEC if present */
- int auto_guess; /* if true, all pids are analized to find streams */
- int set_service_ret;
-
- /* data needed to handle file based ts */
- int stop_parse; /* stop parsing loop */
- AVPacket *pkt; /* packet containing av data */
-
- /******************************************/
- /* private mpegts data */
- /* scan context */
- MpegTSFilter *sdt_filter;
- int nb_services;
- MpegTSService **services;
-
- /* set service context (XXX: allocated it ?) */
- SetServiceCallback *set_service_cb;
- void *set_service_opaque;
- MpegTSFilter *pat_filter;
- MpegTSFilter *pmt_filter;
- int req_sid;
-
- MpegTSFilter *pids[NB_PID_MAX];
-} MpegTSContext;
-
-static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
- const uint8_t *buf, int buf_size, int is_start)
-{
- MpegTSSectionFilter *tss = &tss1->u.section_filter;
- int len;
- unsigned int crc;
-
- if (is_start) {
- memcpy(tss->section_buf, buf, buf_size);
- tss->section_index = buf_size;
- tss->section_h_size = -1;
- tss->end_of_section_reached = 0;
- } else {
- if (tss->end_of_section_reached)
- return;
- len = 4096 - tss->section_index;
- if (buf_size < len)
- len = buf_size;
- memcpy(tss->section_buf + tss->section_index, buf, len);
- tss->section_index += len;
- }
-
- /* compute section length if possible */
- if (tss->section_h_size == -1 && tss->section_index >= 3) {
- len = (((tss->section_buf[1] & 0xf) << 8) | tss->section_buf[2]) + 3;
- if (len > 4096)
- return;
- tss->section_h_size = len;
- }
-
- if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) {
- if (tss->check_crc) {
- crc = mpegts_crc32(tss->section_buf, tss->section_h_size);
- if (crc != 0)
- goto invalid_crc;
- }
- tss->section_cb(tss->opaque, tss->section_buf, tss->section_h_size);
- invalid_crc:
- tss->end_of_section_reached = 1;
- }
-}
-
-MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
- SectionCallback *section_cb, void *opaque,
- int check_crc)
-
-{
- MpegTSFilter *filter;
- MpegTSSectionFilter *sec;
-
- if (pid >= NB_PID_MAX || ts->pids[pid])
- return NULL;
- filter = av_mallocz(sizeof(MpegTSFilter));
- if (!filter)
- return NULL;
- ts->pids[pid] = filter;
- filter->type = MPEGTS_SECTION;
- filter->pid = pid;
- filter->last_cc = -1;
- sec = &filter->u.section_filter;
- sec->section_cb = section_cb;
- sec->opaque = opaque;
- sec->section_buf = av_malloc(MAX_SECTION_SIZE);
- sec->check_crc = check_crc;
- if (!sec->section_buf) {
- av_free(filter);
- return NULL;
- }
- return filter;
-}
-
-MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
- PESCallback *pes_cb,
- void *opaque)
-{
- MpegTSFilter *filter;
- MpegTSPESFilter *pes;
-
- if (pid >= NB_PID_MAX || ts->pids[pid])
- return NULL;
- filter = av_mallocz(sizeof(MpegTSFilter));
- if (!filter)
- return NULL;
- ts->pids[pid] = filter;
- filter->type = MPEGTS_PES;
- filter->pid = pid;
- filter->last_cc = -1;
- pes = &filter->u.pes_filter;
- pes->pes_cb = pes_cb;
- pes->opaque = opaque;
- return filter;
-}
-
-void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
-{
- int pid;
-
- pid = filter->pid;
- if (filter->type == MPEGTS_SECTION)
- av_freep(&filter->u.section_filter.section_buf);
- av_free(filter);
- ts->pids[pid] = NULL;
-}
-
-/* autodetect fec presence. Must have at least 1024 bytes */
-static int get_packet_size(const uint8_t *buf, int size)
-{
- int i;
-
- if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
- return -1;
- for(i=0;i<5;i++) {
- if (buf[i * TS_PACKET_SIZE] != 0x47)
- goto try_fec;
- }
- return TS_PACKET_SIZE;
- try_fec:
- for(i=0;i<5;i++) {
- if (buf[i * TS_FEC_PACKET_SIZE] != 0x47)
- return -1;
- }
- return TS_FEC_PACKET_SIZE;
-}
-
-typedef struct SectionHeader {
- uint8_t tid;
- uint16_t id;
- uint8_t version;
- uint8_t sec_num;
- uint8_t last_sec_num;
-} SectionHeader;
-
-static inline int get8(const uint8_t **pp, const uint8_t *p_end)
-{
- const uint8_t *p;
- int c;
-
- p = *pp;
- if (p >= p_end)
- return -1;
- c = *p++;
- *pp = p;
- return c;
-}
-
-static inline int get16(const uint8_t **pp, const uint8_t *p_end)
-{
- const uint8_t *p;
- int c;
-
- p = *pp;
- if ((p + 1) >= p_end)
- return -1;
- c = (p[0] << 8) | p[1];
- p += 2;
- *pp = p;
- return c;
-}
-
-/* read and allocate a DVB string preceeded by its length */
-static char *getstr8(const uint8_t **pp, const uint8_t *p_end)
-{
- int len;
- const uint8_t *p;
- char *str;
-
- p = *pp;
- len = get8(&p, p_end);
- if (len < 0)
- return NULL;
- if ((p + len) > p_end)
- return NULL;
- str = av_malloc(len + 1);
- if (!str)
- return NULL;
- memcpy(str, p, len);
- str[len] = '\0';
- p += len;
- *pp = p;
- return str;
-}
-
-static int parse_section_header(SectionHeader *h,
- const uint8_t **pp, const uint8_t *p_end)
-{
- int val;
-
- val = get8(pp, p_end);
- if (val < 0)
- return -1;
- h->tid = val;
- *pp += 2;
- val = get16(pp, p_end);
- if (val < 0)
- return -1;
- h->id = val;
- val = get8(pp, p_end);
- if (val < 0)
- return -1;
- h->version = (val >> 1) & 0x1f;
- val = get8(pp, p_end);
- if (val < 0)
- return -1;
- h->sec_num = val;
- val = get8(pp, p_end);
- if (val < 0)
- return -1;
- h->last_sec_num = val;
- return 0;
-}
-
-static MpegTSService *new_service(MpegTSContext *ts, int sid,
- char *provider_name, char *name)
-{
- MpegTSService *service;
-
-#ifdef DEBUG_SI
- printf("new_service: sid=0x%04x provider='%s' name='%s'\n",
- sid, provider_name, name);
-#endif
-
- service = av_mallocz(sizeof(MpegTSService));
- if (!service)
- return NULL;
- service->sid = sid;
- service->provider_name = provider_name;
- service->name = name;
- dynarray_add(&ts->services, &ts->nb_services, service);
- return service;
-}
-
-static void pmt_cb(void *opaque, const uint8_t *section, int section_len)
-{
- MpegTSContext *ts = opaque;
- SectionHeader h1, *h = &h1;
- const uint8_t *p, *p_end;
- int program_info_length, pcr_pid, pid, stream_type, desc_length;
-
-#ifdef DEBUG_SI
- printf("PMT:\n");
- av_hex_dump((uint8_t *)section, section_len);
-#endif
- p_end = section + section_len - 4;
- p = section;
- if (parse_section_header(h, &p, p_end) < 0)
- return;
-#ifdef DEBUG_SI
- printf("sid=0x%x sec_num=%d/%d\n", h->id, h->sec_num, h->last_sec_num);
-#endif
- if (h->tid != PMT_TID || (ts->req_sid >= 0 && h->id != ts->req_sid) )
- return;
-
- pcr_pid = get16(&p, p_end) & 0x1fff;
- if (pcr_pid < 0)
- return;
-#ifdef DEBUG_SI
- printf("pcr_pid=0x%x\n", pcr_pid);
-#endif
- program_info_length = get16(&p, p_end) & 0xfff;
- if (program_info_length < 0)
- return;
- p += program_info_length;
- if (p >= p_end)
- return;
- for(;;) {
- stream_type = get8(&p, p_end);
- if (stream_type < 0)
- break;
- pid = get16(&p, p_end) & 0x1fff;
- if (pid < 0)
- break;
- desc_length = get16(&p, p_end) & 0xfff;
- if (desc_length < 0)
- break;
- p += desc_length;
- if (p > p_end)
- return;
-
-#ifdef DEBUG_SI
- printf("stream_type=%d pid=0x%x\n", stream_type, pid);
-#endif
-
- /* now create ffmpeg stream */
- switch(stream_type) {
- case STREAM_TYPE_AUDIO_MPEG1:
- case STREAM_TYPE_AUDIO_MPEG2:
- case STREAM_TYPE_VIDEO_MPEG1:
- case STREAM_TYPE_VIDEO_MPEG2:
- case STREAM_TYPE_AUDIO_AC3:
- add_pes_stream(ts->stream, pid);
- break;
- default:
- /* we ignore the other streams */
- break;
- }
- }
- /* all parameters are there */
- ts->set_service_cb(ts->set_service_opaque, 0);
- mpegts_close_filter(ts, ts->pmt_filter);
- ts->pmt_filter = NULL;
-}
-
-static void pat_cb(void *opaque, const uint8_t *section, int section_len)
-{
- MpegTSContext *ts = opaque;
- SectionHeader h1, *h = &h1;
- const uint8_t *p, *p_end;
- int sid, pmt_pid;
-
-#ifdef DEBUG_SI
- printf("PAT:\n");
- av_hex_dump((uint8_t *)section, section_len);
-#endif
- p_end = section + section_len - 4;
- p = section;
- if (parse_section_header(h, &p, p_end) < 0)
- return;
- if (h->tid != PAT_TID)
- return;
-
- for(;;) {
- sid = get16(&p, p_end);
- if (sid < 0)
- break;
- pmt_pid = get16(&p, p_end) & 0x1fff;
- if (pmt_pid < 0)
- break;
-#ifdef DEBUG_SI
- printf("sid=0x%x pid=0x%x\n", sid, pmt_pid);
-#endif
- if (sid == 0x0000) {
- /* NIT info */
- } else {
- if (ts->req_sid == sid) {
- ts->pmt_filter = mpegts_open_section_filter(ts, pmt_pid,
- pmt_cb, ts, 1);
- goto found;
- }
- }
- }
- /* not found */
- ts->set_service_cb(ts->set_service_opaque, -1);
-
- found:
- mpegts_close_filter(ts, ts->pat_filter);
- ts->pat_filter = NULL;
-}
-
-/* add all services found in the PAT */
-static void pat_scan_cb(void *opaque, const uint8_t *section, int section_len)
-{
- MpegTSContext *ts = opaque;
- SectionHeader h1, *h = &h1;
- const uint8_t *p, *p_end;
- int sid, pmt_pid;
- char *provider_name, *name;
- char buf[256];
-
-#ifdef DEBUG_SI
- printf("PAT:\n");
- av_hex_dump((uint8_t *)section, section_len);
-#endif
- p_end = section + section_len - 4;
- p = section;
- if (parse_section_header(h, &p, p_end) < 0)
- return;
- if (h->tid != PAT_TID)
- return;
-
- for(;;) {
- sid = get16(&p, p_end);
- if (sid < 0)
- break;
- pmt_pid = get16(&p, p_end) & 0x1fff;
- if (pmt_pid < 0)
- break;
-#ifdef DEBUG_SI
- printf("sid=0x%x pid=0x%x\n", sid, pmt_pid);
-#endif
- if (sid == 0x0000) {
- /* NIT info */
- } else {
- /* add the service with a dummy name */
- snprintf(buf, sizeof(buf), "Service %x\n", sid);
- name = av_strdup(buf);
- provider_name = av_strdup("");
- if (name && provider_name) {
- new_service(ts, sid, provider_name, name);
- } else {
- av_freep(&name);
- av_freep(&provider_name);
- }
- }
- }
- ts->stop_parse = 1;
-
- /* remove filter */
- mpegts_close_filter(ts, ts->pat_filter);
- ts->pat_filter = NULL;
-}
-
-void mpegts_set_service(MpegTSContext *ts, int sid,
- SetServiceCallback *set_service_cb, void *opaque)
-{
- ts->set_service_cb = set_service_cb;
- ts->set_service_opaque = opaque;
- ts->req_sid = sid;
- ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
- pat_cb, ts, 1);
-}
-
-static void sdt_cb(void *opaque, const uint8_t *section, int section_len)
-{
- MpegTSContext *ts = opaque;
- SectionHeader h1, *h = &h1;
- const uint8_t *p, *p_end, *desc_list_end, *desc_end;
- int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type;
- char *name, *provider_name;
-
-#ifdef DEBUG_SI
- printf("SDT:\n");
- av_hex_dump((uint8_t *)section, section_len);
-#endif
-
- p_end = section + section_len - 4;
- p = section;
- if (parse_section_header(h, &p, p_end) < 0)
- return;
- if (h->tid != SDT_TID)
- return;
- onid = get16(&p, p_end);
- if (onid < 0)
- return;
- val = get8(&p, p_end);
- if (val < 0)
- return;
- for(;;) {
- sid = get16(&p, p_end);
- if (sid < 0)
- break;
- val = get8(&p, p_end);
- if (val < 0)
- break;
- desc_list_len = get16(&p, p_end) & 0xfff;
- if (desc_list_len < 0)
- break;
- desc_list_end = p + desc_list_len;
- if (desc_list_end > p_end)
- break;
- for(;;) {
- desc_tag = get8(&p, desc_list_end);
- if (desc_tag < 0)
- break;
- desc_len = get8(&p, desc_list_end);
- desc_end = p + desc_len;
- if (desc_end > desc_list_end)
- break;
-#ifdef DEBUG_SI
- printf("tag: 0x%02x len=%d\n", desc_tag, desc_len);
-#endif
- switch(desc_tag) {
- case 0x48:
- service_type = get8(&p, p_end);
- if (service_type < 0)
- break;
- provider_name = getstr8(&p, p_end);
- if (!provider_name)
- break;
- name = getstr8(&p, p_end);
- if (!name)
- break;
- new_service(ts, sid, provider_name, name);
- break;
- default:
- break;
- }
- p = desc_end;
- }
- p = desc_list_end;
- }
- ts->stop_parse = 1;
-
- /* remove filter */
- mpegts_close_filter(ts, ts->sdt_filter);
- ts->sdt_filter = NULL;
-}
-
-/* scan services in a transport stream by looking at the SDT */
-void mpegts_scan_sdt(MpegTSContext *ts)
-{
- ts->sdt_filter = mpegts_open_section_filter(ts, SDT_PID,
- sdt_cb, ts, 1);
-}
-
-/* scan services in a transport stream by looking at the PAT (better
- than nothing !) */
-void mpegts_scan_pat(MpegTSContext *ts)
-{
- ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID,
- pat_scan_cb, ts, 1);
-}
-
-/* TS stream handling */
-
-enum MpegTSState {
- MPEGTS_HEADER = 0,
- MPEGTS_PESHEADER_FILL,
- MPEGTS_PAYLOAD,
- MPEGTS_SKIP,
-};
-
-/* enough for PES header + length */
-#define PES_START_SIZE 9
-#define MAX_PES_HEADER_SIZE (9 + 255)
-
-typedef struct PESContext {
- int pid;
- AVFormatContext *stream;
- AVStream *st;
- enum MpegTSState state;
- /* used to get the format */
- int data_index;
- int total_size;
- int pes_header_size;
- int64_t pts, dts;
- uint8_t header[MAX_PES_HEADER_SIZE];
-} PESContext;
-
-static int64_t get_pts(const uint8_t *p)
-{
- int64_t pts;
- int val;
-
- pts = (int64_t)((p[0] >> 1) & 0x07) << 30;
- val = (p[1] << 8) | p[2];
- pts |= (int64_t)(val >> 1) << 15;
- val = (p[3] << 8) | p[4];
- pts |= (int64_t)(val >> 1);
- return pts;
-}
-
-/* return non zero if a packet could be constructed */
-static void mpegts_push_data(void *opaque,
- const uint8_t *buf, int buf_size, int is_start)
-{
- PESContext *pes = opaque;
- MpegTSContext *ts = pes->stream->priv_data;
- AVStream *st;
- const uint8_t *p;
- int len, code, codec_type, codec_id;
-
- if (is_start) {
- pes->state = MPEGTS_HEADER;
- pes->data_index = 0;
- }
- p = buf;
- while (buf_size > 0) {
- switch(pes->state) {
- case MPEGTS_HEADER:
- len = PES_START_SIZE - pes->data_index;
- if (len > buf_size)
- len = buf_size;
- memcpy(pes->header + pes->data_index, p, len);
- pes->data_index += len;
- p += len;
- buf_size -= len;
- if (pes->data_index == PES_START_SIZE) {
- /* we got all the PES or section header. We can now
- decide */
-#if 0
- av_hex_dump(pes->header, pes->data_index);
-#endif
- if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
- pes->header[2] == 0x01) {
- /* it must be an mpeg2 PES stream */
- code = pes->header[3] | 0x100;
- if (!((code >= 0x1c0 && code <= 0x1df) ||
- (code >= 0x1e0 && code <= 0x1ef) ||
- (code == 0x1bd)))
- goto skip;
- if (!pes->st) {
- /* allocate stream */
- if (code >= 0x1c0 && code <= 0x1df) {
- codec_type = CODEC_TYPE_AUDIO;
- codec_id = CODEC_ID_MP2;
- } else if (code == 0x1bd) {
- codec_type = CODEC_TYPE_AUDIO;
- codec_id = CODEC_ID_AC3;
- } else {
- codec_type = CODEC_TYPE_VIDEO;
- codec_id = CODEC_ID_MPEG1VIDEO;
- }
- st = av_new_stream(pes->stream, pes->pid);
- if (st) {
- st->priv_data = pes;
- st->codec.codec_type = codec_type;
- st->codec.codec_id = codec_id;
- pes->st = st;
- }
- }
- pes->state = MPEGTS_PESHEADER_FILL;
- pes->total_size = (pes->header[4] << 8) | pes->header[5];
- /* NOTE: a zero total size means the PES size is
- unbounded */
- if (pes->total_size)
- pes->total_size += 6;
- pes->pes_header_size = pes->header[8] + 9;
- } else {
- /* otherwise, it should be a table */
- /* skip packet */
- skip:
- pes->state = MPEGTS_SKIP;
- continue;
- }
- }
- break;
- /**********************************************/
- /* PES packing parsing */
- case MPEGTS_PESHEADER_FILL:
- len = pes->pes_header_size - pes->data_index;
- if (len > buf_size)
- len = buf_size;
- memcpy(pes->header + pes->data_index, p, len);
- pes->data_index += len;
- p += len;
- buf_size -= len;
- if (pes->data_index == pes->pes_header_size) {
- const uint8_t *r;
- unsigned int flags;
-
- flags = pes->header[7];
- r = pes->header + 9;
- pes->pts = AV_NOPTS_VALUE;
- pes->dts = AV_NOPTS_VALUE;
- if ((flags & 0xc0) == 0x80) {
- pes->pts = get_pts(r);
- r += 5;
- } else if ((flags & 0xc0) == 0xc0) {
- pes->pts = get_pts(r);
- r += 5;
- pes->dts = get_pts(r);
- r += 5;
- }
- /* we got the full header. We parse it and get the payload */
- pes->state = MPEGTS_PAYLOAD;
- }
- break;
- case MPEGTS_PAYLOAD:
- if (pes->total_size) {
- len = pes->total_size - pes->data_index;
- if (len > buf_size)
- len = buf_size;
- } else {
- len = buf_size;
- }
- if (len > 0) {
- AVPacket *pkt = ts->pkt;
- if (pes->st && av_new_packet(pkt, len) == 0) {
- memcpy(pkt->data, p, len);
- pkt->stream_index = pes->st->index;
- pkt->pts = pes->pts;
- /* reset pts values */
- pes->pts = AV_NOPTS_VALUE;
- pes->dts = AV_NOPTS_VALUE;
- ts->stop_parse = 1;
- return;
- }
- }
- buf_size = 0;
- break;
- case MPEGTS_SKIP:
- buf_size = 0;
- break;
- }
- }
-}
-
-static int add_pes_stream(AVFormatContext *s, int pid)
-{
- MpegTSContext *ts = s->priv_data;
- MpegTSFilter *tss;
- PESContext *pes;
-
- /* if no pid found, then add a pid context */
- pes = av_mallocz(sizeof(PESContext));
- if (!pes)
- return -1;
- pes->stream = s;
- pes->pid = pid;
- tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes);
- if (!tss) {
- av_free(pes);
- return -1;
- }
- return 0;
-}
-
-/* handle one TS packet */
-static void handle_packet(AVFormatContext *s, uint8_t *packet)
-{
- MpegTSContext *ts = s->priv_data;
- MpegTSFilter *tss;
- int len, pid, cc, cc_ok, afc, is_start;
- const uint8_t *p, *p_end;
-
- pid = ((packet[1] & 0x1f) << 8) | packet[2];
- is_start = packet[1] & 0x40;
- tss = ts->pids[pid];
- if (ts->auto_guess && tss == NULL && is_start) {
- add_pes_stream(s, pid);
- tss = ts->pids[pid];
- }
- if (!tss)
- return;
-
- /* continuity check (currently not used) */
- cc = (packet[3] & 0xf);
- cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc));
- tss->last_cc = cc;
-
- /* skip adaptation field */
- afc = (packet[3] >> 4) & 3;
- p = packet + 4;
- if (afc == 0) /* reserved value */
- return;
- if (afc == 2) /* adaptation field only */
- return;
- if (afc == 3) {
- /* skip adapation field */
- p += p[0] + 1;
- }
- /* if past the end of packet, ignore */
- p_end = packet + TS_PACKET_SIZE;
- if (p >= p_end)
- return;
-
- if (tss->type == MPEGTS_SECTION) {
- if (is_start) {
- /* pointer field present */
- len = *p++;
- if (p + len > p_end)
- return;
- if (len && cc_ok) {
- /* write remaning section bytes */
- write_section_data(s, tss,
- p, len, 0);
- }
- p += len;
- if (p < p_end) {
- write_section_data(s, tss,
- p, p_end - p, 1);
- }
- } else {
- if (cc_ok) {
- write_section_data(s, tss,
- p, p_end - p, 0);
- }
- }
- } else {
- tss->u.pes_filter.pes_cb(tss->u.pes_filter.opaque,
- p, p_end - p, is_start);
- }
-}
-
-/* XXX: try to find a better synchro over several packets (use
- get_packet_size() ?) */
-static int mpegts_resync(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- int c, i;
-
- for(i = 0;i < MAX_RESYNC_SIZE; i++) {
- c = url_fgetc(pb);
- if (c < 0)
- return -1;
- if (c == 0x47) {
- url_fseek(pb, -1, SEEK_CUR);
- return 0;
- }
- }
- /* no sync found */
- return -1;
-}
-
-static int handle_packets(AVFormatContext *s, int nb_packets)
-{
- MpegTSContext *ts = s->priv_data;
- ByteIOContext *pb = &s->pb;
- uint8_t packet[TS_FEC_PACKET_SIZE];
- int packet_num, len;
- int64_t pos;
-
- ts->stop_parse = 0;
- packet_num = 0;
- for(;;) {
- if (ts->stop_parse)
- break;
- packet_num++;
- if (nb_packets != 0 && packet_num >= nb_packets)
- break;
- pos = url_ftell(pb);
- len = get_buffer(pb, packet, ts->raw_packet_size);
- if (len != ts->raw_packet_size)
- return AVERROR_IO;
- /* check paquet sync byte */
- if (packet[0] != 0x47) {
- /* find a new packet start */
- url_fseek(pb, -ts->raw_packet_size, SEEK_CUR);
- if (mpegts_resync(s) < 0)
- return AVERROR_INVALIDDATA;
- else
- continue;
- }
- handle_packet(s, packet);
- }
- return 0;
-}
-
-static int mpegts_probe(AVProbeData *p)
-{
-#if 1
- int size;
- size = get_packet_size(p->buf, p->buf_size);
- if (size < 0)
- return 0;
- return AVPROBE_SCORE_MAX - 1;
-#else
- /* only use the extension for safer guess */
- if (match_ext(p->filename, "ts"))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-#endif
-}
-
-void set_service_cb(void *opaque, int ret)
-{
- MpegTSContext *ts = opaque;
- ts->set_service_ret = ret;
- ts->stop_parse = 1;
-}
-
-static int mpegts_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- MpegTSContext *ts = s->priv_data;
- ByteIOContext *pb = &s->pb;
- uint8_t buf[1024];
- int len, sid;
- int64_t pos;
- MpegTSService *service;
-
- /* read the first 1024 bytes to get packet size */
- pos = url_ftell(pb);
- len = get_buffer(pb, buf, sizeof(buf));
- if (len != sizeof(buf))
- goto fail;
- ts->raw_packet_size = get_packet_size(buf, sizeof(buf));
- if (ts->raw_packet_size <= 0)
- goto fail;
- ts->auto_guess = 0;
-
- if (!ts->auto_guess) {
- ts->set_service_ret = -1;
-
- /* first do a scaning to get all the services */
- url_fseek(pb, pos, SEEK_SET);
- mpegts_scan_sdt(ts);
-
- handle_packets(s, MAX_SCAN_PACKETS);
-
- if (ts->nb_services <= 0) {
- /* no SDT found, we try to look at the PAT */
-
- url_fseek(pb, pos, SEEK_SET);
- mpegts_scan_pat(ts);
-
- handle_packets(s, MAX_SCAN_PACKETS);
- }
-
- if (ts->nb_services <= 0)
- return -1;
-
- /* tune to first service found */
- service = ts->services[0];
- sid = service->sid;
-#ifdef DEBUG_SI
- printf("tuning to '%s'\n", service->name);
-#endif
-
- /* now find the info for the first service if we found any,
- otherwise try to filter all PATs */
-
- url_fseek(pb, pos, SEEK_SET);
- ts->stream = s;
- mpegts_set_service(ts, sid, set_service_cb, ts);
-
- handle_packets(s, MAX_SCAN_PACKETS);
-
- /* if could not find service, exit */
- if (ts->set_service_ret != 0)
- return -1;
-
-#ifdef DEBUG_SI
- printf("tuning done\n");
-#endif
- }
-
- url_fseek(pb, pos, SEEK_SET);
- return 0;
- fail:
- return -1;
-}
-
-static int mpegts_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- MpegTSContext *ts = s->priv_data;
- ts->pkt = pkt;
- return handle_packets(s, 0);
-}
-
-static int mpegts_read_close(AVFormatContext *s)
-{
- MpegTSContext *ts = s->priv_data;
- int i;
- for(i=0;i<NB_PID_MAX;i++)
- av_free(ts->pids[i]);
- return 0;
-}
-
-AVInputFormat mpegts_demux = {
- "mpegts",
- "MPEG2 transport stream format",
- sizeof(MpegTSContext),
- mpegts_probe,
- mpegts_read_header,
- mpegts_read_packet,
- mpegts_read_close,
- .flags = AVFMT_NOHEADER | AVFMT_SHOW_IDS,
-};
-
-int mpegts_init(void)
-{
- av_register_input_format(&mpegts_demux);
- av_register_output_format(&mpegts_mux);
- return 0;
-}
+++ /dev/null
-/*
- * MPEG2 transport stream defines
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#define TS_FEC_PACKET_SIZE 204
-#define TS_PACKET_SIZE 188
-#define NB_PID_MAX 8192
-#define MAX_SECTION_SIZE 4096
-
-/* pids */
-#define PAT_PID 0x0000
-#define SDT_PID 0x0011
-
-/* table ids */
-#define PAT_TID 0x00
-#define PMT_TID 0x02
-#define SDT_TID 0x42
-
-#define STREAM_TYPE_VIDEO_MPEG1 0x01
-#define STREAM_TYPE_VIDEO_MPEG2 0x02
-#define STREAM_TYPE_AUDIO_MPEG1 0x03
-#define STREAM_TYPE_AUDIO_MPEG2 0x04
-#define STREAM_TYPE_PRIVATE_SECTION 0x05
-#define STREAM_TYPE_PRIVATE_DATA 0x06
-
-#define STREAM_TYPE_AUDIO_AC3 0x81
-
-unsigned int mpegts_crc32(const uint8_t *data, int len);
-extern AVOutputFormat mpegts_mux;
+++ /dev/null
-/*
- * MPEG2 transport stream (aka DVB) mux
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include "mpegts.h"
-
-/* write DVB SI sections */
-
-static const uint32_t crc_table[256] = {
- 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
- 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
- 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
- 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
- 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
- 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
- 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
- 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
- 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
- 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
- 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
- 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
- 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
- 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
- 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
- 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
- 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
- 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
- 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
- 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
- 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
- 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
- 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
- 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
- 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
- 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
- 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
- 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
- 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
- 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
- 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
- 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
- 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
- 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
- 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
- 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
- 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
- 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
- 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
- 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
- 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
- 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
- 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
-};
-
-unsigned int mpegts_crc32(const uint8_t *data, int len)
-{
- register int i;
- unsigned int crc = 0xffffffff;
-
- for (i=0; i<len; i++)
- crc = (crc << 8) ^ crc_table[((crc >> 24) ^ *data++) & 0xff];
-
- return crc;
-}
-
-/*********************************************/
-/* mpegts section writer */
-
-typedef struct MpegTSSection {
- int pid;
- int cc;
- void (*write_packet)(struct MpegTSSection *s, const uint8_t *packet);
- void *opaque;
-} MpegTSSection;
-
-/* NOTE: 4 bytes must be left at the end for the crc32 */
-void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len)
-{
- unsigned int crc;
- unsigned char packet[TS_PACKET_SIZE];
- const unsigned char *buf_ptr;
- unsigned char *q;
- int first, b, len1, left;
-
- crc = mpegts_crc32(buf, len - 4);
- buf[len - 4] = (crc >> 24) & 0xff;
- buf[len - 3] = (crc >> 16) & 0xff;
- buf[len - 2] = (crc >> 8) & 0xff;
- buf[len - 1] = (crc) & 0xff;
-
- /* send each packet */
- buf_ptr = buf;
- while (len > 0) {
- first = (buf == buf_ptr);
- q = packet;
- *q++ = 0x47;
- b = (s->pid >> 8);
- if (first)
- b |= 0x40;
- *q++ = b;
- *q++ = s->pid;
- s->cc = (s->cc + 1) & 0xf;
- *q++ = 0x10 | s->cc;
- if (first)
- *q++ = 0; /* 0 offset */
- len1 = TS_PACKET_SIZE - (q - packet);
- if (len1 > len)
- len1 = len;
- memcpy(q, buf_ptr, len1);
- q += len1;
- /* add known padding data */
- left = TS_PACKET_SIZE - (q - packet);
- if (left > 0)
- memset(q, 0xff, left);
-
- s->write_packet(s, packet);
-
- buf_ptr += len1;
- len -= len1;
- }
-}
-
-static inline void put16(uint8_t **q_ptr, int val)
-{
- uint8_t *q;
- q = *q_ptr;
- *q++ = val >> 8;
- *q++ = val;
- *q_ptr = q;
-}
-
-int mpegts_write_section1(MpegTSSection *s, int tid, int id,
- int version, int sec_num, int last_sec_num,
- uint8_t *buf, int len)
-{
- uint8_t section[1024], *q;
- unsigned int tot_len;
-
- tot_len = 3 + 5 + len + 4;
- /* check if not too big */
- if (tot_len > 1024)
- return -1;
-
- q = section;
- *q++ = tid;
- put16(&q, 0xb000 | (len + 5 + 4)); /* 5 byte header + 4 byte CRC */
- put16(&q, id);
- *q++ = 0xc1 | (version << 1); /* current_next_indicator = 1 */
- *q++ = sec_num;
- *q++ = last_sec_num;
- memcpy(q, buf, len);
-
- mpegts_write_section(s, section, tot_len);
- return 0;
-}
-
-/*********************************************/
-/* mpegts writer */
-
-#define DEFAULT_PMT_START_PID 0x1000
-#define DEFAULT_START_PID 0x0100
-#define DEFAULT_PROVIDER_NAME "FFmpeg"
-#define DEFAULT_SERVICE_NAME "Service01"
-
-/* default network id, transport stream and service identifiers */
-#define DEFAULT_ONID 0x0001
-#define DEFAULT_TSID 0x0001
-#define DEFAULT_SID 0x0001
-
-/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */
-#define DEFAULT_PES_HEADER_FREQ 16
-#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
-
-/* we retransmit the SI info at this rate */
-#define SDT_RETRANS_TIME 500
-#define PAT_RETRANS_TIME 100
-
-typedef struct MpegTSWriteStream {
- int pid; /* stream associated pid */
- int cc;
- int payload_index;
- int64_t payload_pts;
- uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE];
-} MpegTSWriteStream;
-
-typedef struct MpegTSService {
- MpegTSSection pmt; /* MPEG2 pmt table context */
- int pcr_pid;
- int sid; /* service ID */
- char *name;
- char *provider_name;
-} MpegTSService;
-
-typedef struct MpegTSWrite {
- MpegTSSection pat; /* MPEG2 pat table */
- MpegTSSection sdt; /* MPEG2 sdt table context */
- MpegTSService **services;
- int sdt_packet_count;
- int sdt_packet_freq;
- int pat_packet_count;
- int pat_packet_freq;
- int nb_services;
- int onid;
- int tsid;
-} MpegTSWrite;
-
-static void mpegts_write_pat(AVFormatContext *s)
-{
- MpegTSWrite *ts = s->priv_data;
- MpegTSService *service;
- uint8_t data[1012], *q;
- int i;
-
- q = data;
- for(i = 0; i < ts->nb_services; i++) {
- service = ts->services[i];
- put16(&q, service->sid);
- put16(&q, 0xe000 | service->pmt.pid);
- }
- mpegts_write_section1(&ts->pat, PAT_TID, ts->tsid, 0, 0, 0,
- data, q - data);
-}
-
-static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
-{
- // MpegTSWrite *ts = s->priv_data;
- uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
- int val, stream_type, i;
-
- q = data;
- put16(&q, 0xe000 | service->pcr_pid);
-
- program_info_length_ptr = q;
- q += 2; /* patched after */
-
- /* put program info here */
-
- val = 0xf000 | (q - program_info_length_ptr - 2);
- program_info_length_ptr[0] = val >> 8;
- program_info_length_ptr[1] = val;
-
- for(i = 0; i < s->nb_streams; i++) {
- AVStream *st = s->streams[i];
- MpegTSWriteStream *ts_st = st->priv_data;
- switch(st->codec.codec_type) {
- case CODEC_TYPE_VIDEO:
- stream_type = STREAM_TYPE_VIDEO_MPEG2; //XXX/FIXME is this (and the define) correct?
- break;
- case CODEC_TYPE_AUDIO:
- stream_type = STREAM_TYPE_AUDIO_MPEG1;
- break;
- default:
- stream_type = STREAM_TYPE_PRIVATE_DATA;
- break;
- }
- *q++ = stream_type;
- put16(&q, 0xe000 | ts_st->pid);
- desc_length_ptr = q;
- q += 2; /* patched after */
-
- /* write optional descriptors here */
-
- val = 0xf000 | (q - desc_length_ptr - 2);
- desc_length_ptr[0] = val >> 8;
- desc_length_ptr[1] = val;
- }
- mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0,
- data, q - data);
-}
-
-/* NOTE: str == NULL is accepted for an empty string */
-static void putstr8(uint8_t **q_ptr, const char *str)
-{
- uint8_t *q;
- int len;
-
- q = *q_ptr;
- if (!str)
- len = 0;
- else
- len = strlen(str);
- *q++ = len;
- memcpy(q, str, len);
- q += len;
- *q_ptr = q;
-}
-
-static void mpegts_write_sdt(AVFormatContext *s)
-{
- MpegTSWrite *ts = s->priv_data;
- MpegTSService *service;
- uint8_t data[1012], *q, *desc_list_len_ptr, *desc_len_ptr;
- int i, running_status, free_ca_mode, val;
-
- q = data;
- put16(&q, ts->onid);
- *q++ = 0xff;
- for(i = 0; i < ts->nb_services; i++) {
- service = ts->services[i];
- put16(&q, service->sid);
- *q++ = 0xfc | 0x00; /* currently no EIT info */
- desc_list_len_ptr = q;
- q += 2;
- running_status = 4; /* running */
- free_ca_mode = 0;
-
- /* write only one descriptor for the service name and provider */
- *q++ = 0x48;
- desc_len_ptr = q;
- q++;
- *q++ = 0x01; /* digital television service */
- putstr8(&q, service->provider_name);
- putstr8(&q, service->name);
- desc_len_ptr[0] = q - desc_len_ptr - 1;
-
- /* fill descriptor length */
- val = (running_status << 13) | (free_ca_mode << 12) |
- (q - desc_list_len_ptr - 2);
- desc_list_len_ptr[0] = val >> 8;
- desc_list_len_ptr[1] = val;
- }
- mpegts_write_section1(&ts->sdt, SDT_TID, ts->tsid, 0, 0, 0,
- data, q - data);
-}
-
-static MpegTSService *mpegts_add_service(MpegTSWrite *ts,
- int sid,
- const char *provider_name,
- const char *name)
-{
- MpegTSService *service;
-
- service = av_mallocz(sizeof(MpegTSService));
- if (!service)
- return NULL;
- service->pmt.pid = DEFAULT_PMT_START_PID + ts->nb_services - 1;
- service->sid = sid;
- service->provider_name = av_strdup(provider_name);
- service->name = av_strdup(name);
- service->pcr_pid = 0x1fff;
- dynarray_add(&ts->services, &ts->nb_services, service);
- return service;
-}
-
-static void section_write_packet(MpegTSSection *s, const uint8_t *packet)
-{
- AVFormatContext *ctx = s->opaque;
- put_buffer(&ctx->pb, packet, TS_PACKET_SIZE);
-}
-
-static int mpegts_write_header(AVFormatContext *s)
-{
- MpegTSWrite *ts = s->priv_data;
- MpegTSWriteStream *ts_st;
- MpegTSService *service;
- AVStream *st;
- int i, total_bit_rate;
-
- ts->tsid = DEFAULT_TSID;
- ts->onid = DEFAULT_ONID;
- /* allocate a single DVB service */
- service = mpegts_add_service(ts, DEFAULT_SID,
- DEFAULT_PROVIDER_NAME, DEFAULT_SERVICE_NAME);
- service->pmt.write_packet = section_write_packet;
- service->pmt.opaque = s;
-
- ts->pat.pid = PAT_PID;
- ts->pat.cc = 0;
- ts->pat.write_packet = section_write_packet;
- ts->pat.opaque = s;
-
- ts->sdt.pid = SDT_PID;
- ts->sdt.cc = 0;
- ts->sdt.write_packet = section_write_packet;
- ts->sdt.opaque = s;
-
- /* assign pids to each stream */
- total_bit_rate = 0;
- for(i = 0;i < s->nb_streams; i++) {
- st = s->streams[i];
- ts_st = av_mallocz(sizeof(MpegTSWriteStream));
- if (!ts_st)
- goto fail;
- st->priv_data = ts_st;
- ts_st->pid = DEFAULT_START_PID + i;
- ts_st->payload_pts = AV_NOPTS_VALUE;
- /* update PCR pid if needed */
- if (st->codec.codec_type == CODEC_TYPE_VIDEO &&
- service->pcr_pid == 0x1fff)
- service->pcr_pid = ts_st->pid;
- total_bit_rate += st->codec.bit_rate;
- }
- if (total_bit_rate <= 8 * 1024)
- total_bit_rate = 8 * 1024;
- ts->sdt_packet_freq = (total_bit_rate * SDT_RETRANS_TIME) /
- (TS_PACKET_SIZE * 8 * 1000);
- ts->pat_packet_freq = (total_bit_rate * PAT_RETRANS_TIME) /
- (TS_PACKET_SIZE * 8 * 1000);
-#if 0
- printf("%d %d %d\n",
- total_bit_rate, ts->sdt_packet_freq, ts->pat_packet_freq);
-#endif
-
- /* write info at the start of the file, so that it will be fast to
- find them */
- mpegts_write_sdt(s);
- mpegts_write_pat(s);
- for(i = 0; i < ts->nb_services; i++) {
- mpegts_write_pmt(s, ts->services[i]);
- }
- put_flush_packet(&s->pb);
-
- return 0;
-
- fail:
- for(i = 0;i < s->nb_streams; i++) {
- st = s->streams[i];
- av_free(st->priv_data);
- }
- return -1;
-}
-
-/* send SDT, PAT and PMT tables regulary */
-static void retransmit_si_info(AVFormatContext *s)
-{
- MpegTSWrite *ts = s->priv_data;
- int i;
-
- if (++ts->sdt_packet_count == ts->sdt_packet_freq) {
- ts->sdt_packet_count = 0;
- mpegts_write_sdt(s);
- }
- if (++ts->pat_packet_count == ts->pat_packet_freq) {
- ts->pat_packet_count = 0;
- mpegts_write_pat(s);
- for(i = 0; i < ts->nb_services; i++) {
- mpegts_write_pmt(s, ts->services[i]);
- }
- }
-}
-
-/* NOTE: pes_data contains all the PES packet */
-static void mpegts_write_pes(AVFormatContext *s, AVStream *st,
- const uint8_t *payload, int payload_size,
- int64_t pts)
-{
- MpegTSWriteStream *ts_st = st->priv_data;
- uint8_t buf[TS_PACKET_SIZE];
- uint8_t *q;
- int val, is_start, len, ts_len, header_len;
-
- is_start = 1;
- while (payload_size > 0) {
- retransmit_si_info(s);
-
- /* prepare packet header */
- q = buf;
- *q++ = 0x47;
- val = (ts_st->pid >> 8);
- if (is_start)
- val |= 0x40;
- *q++ = val;
- *q++ = ts_st->pid;
- *q++ = 0x10 | ts_st->cc;
- ts_st->cc = (ts_st->cc + 1) & 0xf;
- if (is_start) {
- /* write PES header */
- *q++ = 0x00;
- *q++ = 0x00;
- *q++ = 0x01;
- if (st->codec.codec_type == CODEC_TYPE_VIDEO)
- *q++ = 0xe0;
- else
- *q++ = 0xc0;
- if (pts != AV_NOPTS_VALUE)
- header_len = 8;
- else
- header_len = 3;
- len = payload_size + header_len;
- *q++ = len >> 8;
- *q++ = len;
- *q++ = 0x80;
- if (pts != AV_NOPTS_VALUE) {
- *q++ = 0x80; /* PTS only */
- *q++ = 0x05; /* header len */
- val = (0x02 << 4) |
- (((pts >> 30) & 0x07) << 1) | 1;
- *q++ = val;
- val = (((pts >> 15) & 0x7fff) << 1) | 1;
- *q++ = val >> 8;
- *q++ = val;
- val = (((pts) & 0x7fff) << 1) | 1;
- *q++ = val >> 8;
- *q++ = val;
- } else {
- *q++ = 0x00;
- *q++ = 0x00;
- }
- is_start = 0;
- }
- /* write header */
- ts_len = q - buf;
- put_buffer(&s->pb, buf, ts_len);
- /* write data */
- len = TS_PACKET_SIZE - ts_len;
- if (len > payload_size)
- len = payload_size;
- put_buffer(&s->pb, payload, len);
- payload += len;
- payload_size -= len;
- ts_len += len;
- /* stuffing */
- len = TS_PACKET_SIZE - ts_len;
- if (len > 0) {
- memset(buf, 0xff, len);
- put_buffer(&s->pb, buf, len);
- }
- }
- put_flush_packet(&s->pb);
-}
-
-static int mpegts_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts1)
-{
- AVStream *st = s->streams[stream_index];
- MpegTSWriteStream *ts_st = st->priv_data;
- int len;
-
- while (size > 0) {
- len = DEFAULT_PES_PAYLOAD_SIZE - ts_st->payload_index;
- if (len > size)
- len = size;
- memcpy(ts_st->payload + ts_st->payload_index, buf, len);
- buf += len;
- size -= len;
- ts_st->payload_index += len;
- if (ts_st->payload_pts == AV_NOPTS_VALUE)
- ts_st->payload_pts = pts1;
- if (ts_st->payload_index >= DEFAULT_PES_PAYLOAD_SIZE) {
- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
- ts_st->payload_pts);
- ts_st->payload_pts = AV_NOPTS_VALUE;
- ts_st->payload_index = 0;
- }
- }
- return 0;
-}
-
-static int mpegts_write_end(AVFormatContext *s)
-{
- MpegTSWrite *ts = s->priv_data;
- MpegTSWriteStream *ts_st;
- MpegTSService *service;
- AVStream *st;
- int i;
-
- /* flush current packets */
- for(i = 0; i < s->nb_streams; i++) {
- st = s->streams[i];
- ts_st = st->priv_data;
- if (ts_st->payload_index > 0) {
- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index,
- ts_st->payload_pts);
- }
- }
- put_flush_packet(&s->pb);
-
- for(i = 0; i < ts->nb_services; i++) {
- service = ts->services[i];
- av_freep(&service->provider_name);
- av_freep(&service->name);
- av_free(service);
- }
- av_free(ts->services);
-
- for(i = 0; i < s->nb_streams; i++) {
- st = s->streams[i];
- av_free(st->priv_data);
- }
- return 0;
-}
-
-AVOutputFormat mpegts_mux = {
- "mpegts",
- "MPEG2 transport stream format",
- "video/x-mpegts",
- "ts",
- sizeof(MpegTSWrite),
- CODEC_ID_MP2,
- CODEC_ID_MPEG2VIDEO,
- mpegts_write_header,
- mpegts_write_packet,
- mpegts_write_end,
-};
+++ /dev/null
-/*
- * Multipart JPEG format
- * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* Multipart JPEG */
-
-#define BOUNDARY_TAG "ffserver"
-
-static int mpjpeg_write_header(AVFormatContext *s)
-{
- uint8_t buf1[256];
-
- snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int mpjpeg_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- uint8_t buf1[256];
-
- snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_buffer(&s->pb, buf, size);
-
- snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
- put_buffer(&s->pb, buf1, strlen(buf1));
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int mpjpeg_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVOutputFormat mpjpeg_format = {
- "mpjpeg",
- "Mime multipart JPEG format",
- "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
- "mjpg",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MJPEG,
- mpjpeg_write_header,
- mpjpeg_write_packet,
- mpjpeg_write_trailer,
-};
-
-
-/*************************************/
-/* single frame JPEG */
-
-static int single_jpeg_write_header(AVFormatContext *s)
-{
- return 0;
-}
-
-static int single_jpeg_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 1; /* no more data can be sent */
-}
-
-static int single_jpeg_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVOutputFormat single_jpeg_format = {
- "singlejpeg",
- "single JPEG image",
- "image/jpeg",
- NULL, /* note: no extension to favorize jpeg multiple images match */
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MJPEG,
- single_jpeg_write_header,
- single_jpeg_write_packet,
- single_jpeg_write_trailer,
-};
-
-int jpeg_init(void)
-{
- av_register_output_format(&mpjpeg_format);
- av_register_output_format(&single_jpeg_format);
- return 0;
-}
+++ /dev/null
-/*
- * NUT (de)muxer based on initial draft
- * Copyright (c) 2003 Alex Beregszaszi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * NUT DRAFT can be found in MPlayer CVS at DOCS/tech/mpcf.txt
- *
- * Compatible with draft version 20030906
- *
- */
-
-/*
- * TODO:
- * - checksumming
- * - correct rate denom/nom and sample_mul
- * - correct timestamp handling
- * - index writing
- * - info and index packet reading support
- * - startcode searching for broken streams
- * - subpacket support
- * - handling of codec specific headers
-*/
-
-//#define DEBUG 1
-
-#include "avformat.h"
-#include "mpegaudio.h"
-#include "avi.h"
-
-//from /dev/random
-
-#define MAIN_STARTCODE (0xF9526A6200000000ULL + ('N'<<24) + ('U'<<16) + ('T'<<8) + 'M')
-#define STREAM_STARTCODE (0xD667773F00000000ULL + ('N'<<24) + ('U'<<16) + ('T'<<8) + 'S')
-#define KEYFRAME_STARTCODE (0xCB86308700000000ULL + ('N'<<24) + ('U'<<16) + ('T'<<8) + 'K')
-#define INDEX_STARTCODE (0xEBFCDE0E00000000ULL + ('N'<<24) + ('U'<<16) + ('T'<<8) + 'X')
-#define INFO_STARTCODE (0xA37B643500000000ULL + ('N'<<24) + ('U'<<16) + ('T'<<8) + 'I')
-
-typedef struct {
- int curr_frame_start;
- int last_frame_size;
- int curr_frame_size;
-} NUTContext;
-
-static int bytes_left(ByteIOContext *bc)
-{
- return bc->buf_end - bc->buf_ptr;
-}
-
-static uint64_t get_v(ByteIOContext *bc)
-{
- uint64_t val = 0;
-
-// for (; bytes_left(s)*8 > 0; )
- for(; bytes_left(bc) > 0; )
- {
- int tmp = get_byte(bc);
-
- if (tmp&0x80)
- val= (val<<7) + tmp - 0x80;
- else
- return (val<<7) + tmp;
- }
- return -1;
-}
-
-static int64_t get_s(ByteIOContext *bc)
-{
- int64_t v = get_v(bc) + 1;
-
- if (v&1)
- return -(v>>1);
- else
- return (v>>1);
-}
-
-static int get_b(ByteIOContext *bc, char *data, int maxlen)
-{
- int i, len;
-
- len = get_v(bc);
- for (i = 0; i < len && i < maxlen; i++)
- data[i] = get_byte(bc);
- if (i < len)
- {
- len = i;
- for (i = 0; i < len; i++)
- get_byte(bc);
- }
-
- return 0;
-}
-
-static int get_bi(ByteIOContext *bc)
-{
- int i, len, val;
-
- len = get_v(bc);
- if(len > 4) return -1;
-
- val = 0;
- for (i = 0; i < len; i++) {
- val |= get_byte(bc) << (i * 8);
- }
-
- return val;
-}
-
-static int get_packetheader(NUTContext *nut, ByteIOContext *bc)
-{
- nut->curr_frame_start = url_ftell(bc);
- nut->curr_frame_size = get_v(bc);
- nut->last_frame_size = get_v(bc);
- dprintf("Packet: fwd: %d bwd: %d\n",
- nut->curr_frame_size, nut->last_frame_size);
-
- return 0;
-}
-
-/**
- *
- */
-static int get_length(uint64_t val){
- int i;
-
- for (i=7; ; i+=7)
- if ((val>>i) == 0)
- return i;
-
- return 7; //not reached
-}
-
-static int put_v(ByteIOContext *bc, uint64_t val)
-{
- int i;
-
-// if (bytes_left(s)*8 < 9)
-// return -1;
-
- if (bytes_left(bc) < 1)
- return -1;
-
- val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently
- i= get_length(val);
-
- for (i-=7; i>0; i-=7){
- put_byte(bc, 0x80 | (val>>i));
- }
-
- put_byte(bc, val&0x7f);
-
- return 0;
-}
-
-static int put_s(ByteIOContext *bc, uint64_t val)
-{
- if (val<=0)
- return put_v(bc, -2*val);
- else
- return put_v(bc, 2*val-1);
-}
-
-static int put_b(ByteIOContext *bc, char *data, int len)
-{
- int i;
-
- put_v(bc, len);
- for (i = 0; i < len; i++)
- put_byte(bc, data[i]);
-
- return 0;
-}
-
-static int put_bi(ByteIOContext *bc, int val)
-{
- put_v(bc, 4);
- put_le32(bc, val);
- return 0;
-}
-
-static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size)
-{
- put_flush_packet(bc);
- nut->curr_frame_start = url_ftell(bc);
- nut->curr_frame_size = max_size;
-
- /* packet header */
- put_v(bc, nut->curr_frame_size); /* forward ptr */
- put_v(bc, nut->last_frame_size); /* backward ptr */
- dprintf("Packet: fwd: %d, bwd: %d\n",
- nut->curr_frame_size, nut->last_frame_size);
-
- nut->last_frame_size = nut->curr_frame_size;
-
- return 0;
-}
-
-static int update_packetheader(NUTContext *nut, ByteIOContext *bc, int additional_size){
- offset_t start= nut->curr_frame_start;
- offset_t cur= url_ftell(bc);
- int size= cur - start + additional_size;
-
- assert( size <= nut->curr_frame_size );
-
- url_fseek(bc, start, SEEK_SET);
- put_v(bc, size);
- if(get_length(size) < get_length(nut->curr_frame_size))
- put_byte(bc, 0x80);
- nut->curr_frame_size= size;
- dprintf("Packet update: size: %d\n", size);
-
- url_fseek(bc, cur, SEEK_SET);
-
- return 0;
-}
-
-static int nut_write_header(AVFormatContext *s)
-{
- NUTContext *nut = s->priv_data;
- ByteIOContext *bc = &s->pb;
- AVCodecContext *codec;
- int i;
- int stream_length = 0;
-
- for (i = 0; i < s->nb_streams; i++)
- {
- if (stream_length < (s->streams[i]->duration * (AV_TIME_BASE / 1000)))
- stream_length = s->streams[i]->duration * (AV_TIME_BASE / 1000);
- }
-
- /* main header */
- put_be64(bc, MAIN_STARTCODE);
- put_packetheader(nut, bc, 120);
- put_v(bc, 0); /* version */
- put_v(bc, s->nb_streams);
- put_v(bc, 0); /* file size */
- put_v(bc, stream_length); /* len in msec */
- put_be32(bc, 0); /* FIXME: checksum */
-
- update_packetheader(nut, bc, 0);
-
- /* stream headers */
- for (i = 0; i < s->nb_streams; i++)
- {
- codec = &s->streams[i]->codec;
-
- put_be64(bc, STREAM_STARTCODE);
- put_packetheader(nut, bc, 120);
- put_v(bc, i /*s->streams[i]->index*/);
- put_v(bc, (codec->codec_type == CODEC_TYPE_AUDIO) ? 32 : 0);
- if (codec->codec_tag)
- put_bi(bc, codec->codec_tag);
- else if (codec->codec_type == CODEC_TYPE_VIDEO)
- {
- int tmp = codec_get_bmp_tag(codec->codec_id);
- put_bi(bc, tmp);
- }
- else if (codec->codec_type == CODEC_TYPE_AUDIO)
- {
- int tmp = codec_get_wav_tag(codec->codec_id);
- put_bi(bc, tmp);
- }
- put_v(bc, codec->bit_rate);
- put_v(bc, 0); /* no language code */
- put_v(bc, codec->frame_rate_base);
- put_v(bc, codec->frame_rate);
- put_v(bc, 0); /* timestamp_shift */
- put_v(bc, 0); /* shuffle type */
- put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
-
- put_v(bc, 0); /* no codec specific headers */
-
- switch(codec->codec_type)
- {
- case CODEC_TYPE_AUDIO:
- put_v(bc, codec->sample_rate / (double)(codec->frame_rate_base / codec->frame_rate));
- put_v(bc, codec->channels);
- put_be32(bc, 0); /* FIXME: checksum */
- break;
- case CODEC_TYPE_VIDEO:
- put_v(bc, codec->width);
- put_v(bc, codec->height);
- put_v(bc, 0); /* aspected w */
- put_v(bc, 0); /* aspected h */
- put_v(bc, 0); /* csp type -- unknown */
- put_be32(bc, 0); /* FIXME: checksum */
- break;
- default:
- break;
- }
- update_packetheader(nut, bc, 0);
- }
-
-#if 0
- /* info header */
- put_be64(bc, INFO_STARTCODE);
- put_packetheader(nut, bc, 16+strlen(s->author)+strlen(s->title)+
- strlen(s->comment)+strlen(s->copyright));
- if (s->author[0])
- {
- put_v(bc, 5); /* type */
- put_b(bc, s->author, strlen(s->author));
- }
- if (s->title[0])
- {
- put_v(bc, 6); /* type */
- put_b(bc, s->title, strlen(s->title));
- }
- if (s->comment[0])
- {
- put_v(bc, 7); /* type */
- put_b(bc, s->comment, strlen(s->comment));
- }
- if (s->copyright[0])
- {
- put_v(bc, 8); /* type */
- put_b(bc, s->copyright, strlen(s->copyright));
- }
- /* encoder */
- put_v(bc, 9); /* type */
- put_b(bc, LIBAVFORMAT_IDENT "\0", strlen(LIBAVFORMAT_IDENT));
-
- put_v(bc, 0); /* eof info */
-
- put_be32(bc, 0); /* FIXME: checksum */
- update_packetheader(nut, bc, 0);
-#endif
-
- put_flush_packet(bc);
-
- return 0;
-}
-
-static int nut_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- NUTContext *nut = s->priv_data;
- ByteIOContext *bc = &s->pb;
- int key_frame = 0;
- int flags;
- AVCodecContext *enc;
-
- if (stream_index > s->nb_streams)
- return 1;
-
- enc = &s->streams[stream_index]->codec;
- key_frame = enc->coded_frame->key_frame;
-
- if (key_frame)
- put_be64(bc, KEYFRAME_STARTCODE);
-
- flags=0;
- flags<<=2; flags|=1; //priority
- flags<<=1; flags|=0; //checksum
- flags<<=1; flags|=0; //msb_timestamp_flag
- flags<<=2; flags|=1; //subpacket_type
- flags<<=1; flags|=0; //reserved
-
- put_byte(bc, flags);
-
- put_packetheader(nut, bc, size+20);
- put_v(bc, stream_index);
- put_s(bc, pts); /* lsb_timestamp */
- update_packetheader(nut, bc, size);
-
- put_buffer(bc, buf, size);
-
- put_flush_packet(bc);
-
- return 0;
-}
-
-static int nut_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *bc = &s->pb;
-#if 0
- int i;
-
- /* WRITE INDEX */
-
- for (i = 0; s->nb_streams; i++)
- {
- put_be64(bc, INDEX_STARTCODE);
- put_packetheader(nut, bc, 64);
- put_v(bc, s->streams[i]->id);
- put_v(bc, ...);
- put_be32(bc, 0); /* FIXME: checksum */
- update_packetheader(nut, bc, 0);
- }
-#endif
-
- put_flush_packet(bc);
-
- return 0;
-}
-
-static int nut_probe(AVProbeData *p)
-{
- int i;
- uint64_t code;
-
- code = 0xff;
- for (i = 0; i < p->buf_size; i++) {
- int c = p->buf[i];
- code = (code << 8) | c;
- if (code == MAIN_STARTCODE)
- return AVPROBE_SCORE_MAX;
- }
- return 0;
-}
-
-static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- NUTContext *nut = s->priv_data;
- ByteIOContext *bc = &s->pb;
- uint64_t tmp;
- int cur_stream, nb_streams;
-
- /* main header */
- tmp = get_be64(bc);
- if (tmp != MAIN_STARTCODE)
- fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
- get_packetheader(nut, bc);
-
- tmp = get_v(bc);
- if (tmp != 0)
- fprintf(stderr, "bad version (%Ld)\n", tmp);
-
- nb_streams = get_v(bc);
-
- s->file_size = get_v(bc);
- s->duration = get_v(bc) / (AV_TIME_BASE / 1000);
-
- get_be32(bc); /* checkusm */
-
- s->bit_rate = 0;
-
- /* stream header */
- for (cur_stream = 0; cur_stream < nb_streams; cur_stream++)
- {
- int class;
- AVStream *st;
-
- tmp = get_be64(bc);
- if (tmp != STREAM_STARTCODE)
- fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
- get_packetheader(nut, bc);
- st = av_new_stream(s, get_v(bc));
- if (!st)
- return AVERROR_NOMEM;
- class = get_v(bc);
- tmp = get_bi(bc);
- switch(class)
- {
- case 0:
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = codec_get_bmp_id(tmp);
- if (st->codec.codec_id == CODEC_ID_NONE)
- fprintf(stderr, "Unknown codec?!\n");
- break;
- case 32:
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = codec_get_wav_id(tmp);
- if (st->codec.codec_id == CODEC_ID_NONE)
- fprintf(stderr, "Unknown codec?!\n");
- break;
- default:
- fprintf(stderr, "Unknown stream class (%d)\n", class);
- return -1;
- }
- s->bit_rate += get_v(bc);
- get_b(bc, NULL, 0); /* language code */
- st->codec.frame_rate_base = get_v(bc);
- st->codec.frame_rate = get_v(bc);
- get_v(bc); /* FIXME: msb timestamp base */
- get_v(bc); /* shuffle type */
- get_byte(bc); /* flags */
-
- get_v(bc); /* FIXME: codec specific data headers */
-
- if (class == 0) /* VIDEO */
- {
- st->codec.width = get_v(bc);
- st->codec.height = get_v(bc);
- get_v(bc); /* aspected w */
- get_v(bc); /* aspected h */
- get_v(bc); /* csp type */
- get_be32(bc); /* checksum */
- }
- if (class == 32) /* AUDIO */
- {
- st->codec.sample_rate = get_v(bc) * (double)(st->codec.frame_rate_base / st->codec.frame_rate);
- st->codec.channels = get_v(bc);
- get_be32(bc); /* checksum */
- }
- }
-
- return 0;
-}
-
-static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- NUTContext *nut = s->priv_data;
- ByteIOContext *bc = &s->pb;
- int id, timestamp, size;
- int key_frame = 0;
- uint64_t tmp;
-
-
- if (url_feof(bc))
- return -1;
-
- tmp = get_byte(bc);
- if (tmp & 0x80) /* zero bit set? */
- {
- tmp<<=8 ; tmp |= get_byte(bc);
- tmp<<=16; tmp |= get_be16(bc);
- tmp<<=32; tmp |= get_be32(bc);
- if (tmp == KEYFRAME_STARTCODE)
- {
- key_frame = 1;
- tmp = get_byte(bc); /* flags */
- }
- else
- fprintf(stderr, "error in zero bit / startcode %LX\n", tmp);
- }
- get_packetheader(nut, bc);
-#if 0
- if (((tmp & 0x60)>>5) > 3) /* priority <= 3 */
- fprintf(stderr, "sanity check failed!\n");
-#endif
- id = get_v(bc);
- timestamp = get_s(bc);
-
- size = (nut->curr_frame_size - (url_ftell(bc)-nut->curr_frame_start));
- dprintf("flags: 0x%Lx, timestamp: %d, packet size: %d\n", tmp, timestamp, size);
-
- if (size < 0)
- return -1;
-
- av_new_packet(pkt, size);
- get_buffer(bc, pkt->data, size);
- pkt->stream_index = id;
- if (key_frame)
- pkt->flags |= PKT_FLAG_KEY;
- pkt->pts = timestamp;
-
- return 0;
-}
-
-static AVInputFormat nut_iformat = {
- "nut",
- "nut format",
- sizeof(NUTContext),
- nut_probe,
- nut_read_header,
- nut_read_packet,
-// nut_read_close,
-// nut_read_seek,
- .extensions = "nut",
-};
-
-static AVOutputFormat nut_oformat = {
- "nut",
- "nut format",
- "video/x-nut",
- "nut",
- sizeof(NUTContext),
-#ifdef CONFIG_VORBIS
- CODEC_ID_VORBIS,
-#elif defined(CONFIG_MP3LAME)
- CODEC_ID_MP3,
-#else
- CODEC_ID_MP2, /* AC3 needs liba52 decoder */
-#endif
- CODEC_ID_MPEG4,
- nut_write_header,
- nut_write_packet,
- nut_write_trailer,
-};
-
-int nut_init(void)
-{
- av_register_input_format(&nut_iformat);
- av_register_output_format(&nut_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Ogg bitstream support
- * Mark Hills <mark@pogo.org.uk>
- *
- * Uses libogg, but requires libvorbisenc to construct correct headers
- * when containing Vorbis stream -- currently the only format supported
- */
-
-#include <stdio.h>
-#include <time.h>
-
-#include <ogg/ogg.h>
-#include <vorbis/vorbisenc.h>
-
-#include "avformat.h"
-#include "oggvorbis.h"
-
-#define DECODER_BUFFER_SIZE 4096
-
-
-typedef struct OggContext {
- /* output */
- ogg_stream_state os ;
- int header_handled ;
- ogg_int64_t base_packet_no ;
- ogg_int64_t base_granule_pos ;
-
- /* input */
- ogg_sync_state oy ;
-} OggContext ;
-
-
-static int ogg_write_header(AVFormatContext *avfcontext)
-{
- OggContext *context = avfcontext->priv_data;
- AVCodecContext *avccontext ;
- vorbis_info vi ;
- vorbis_dsp_state vd ;
- vorbis_comment vc ;
- vorbis_block vb ;
- ogg_packet header, header_comm, header_code ;
- int n ;
-
- srand(time(NULL));
- ogg_stream_init(&context->os, rand());
-
- for(n = 0 ; n < avfcontext->nb_streams ; n++) {
- avccontext = &avfcontext->streams[n]->codec ;
-
- /* begin vorbis specific code */
-
- vorbis_info_init(&vi) ;
-
- /* code copied from libavcodec/oggvorbis.c */
-
- if(oggvorbis_init_encoder(&vi, avccontext) < 0) {
- fprintf(stderr, "ogg_write_header: init_encoder failed") ;
- return -1 ;
- }
-
- vorbis_analysis_init(&vd, &vi) ;
- vorbis_block_init(&vd, &vb) ;
-
- vorbis_comment_init(&vc) ;
- vorbis_comment_add_tag(&vc, "encoder", "ffmpeg") ;
- if(*avfcontext->title)
- vorbis_comment_add_tag(&vc, "title", avfcontext->title) ;
-
- vorbis_analysis_headerout(&vd, &vc, &header,
- &header_comm, &header_code) ;
- ogg_stream_packetin(&context->os, &header) ;
- ogg_stream_packetin(&context->os, &header_comm) ;
- ogg_stream_packetin(&context->os, &header_code) ;
-
- vorbis_block_clear(&vb) ;
- vorbis_dsp_clear(&vd) ;
- vorbis_info_clear(&vi) ;
- vorbis_comment_clear(&vc) ;
-
- /* end of vorbis specific code */
-
- context->header_handled = 0 ;
- context->base_packet_no = 0 ;
- }
-
- return 0 ;
-}
-
-
-static int ogg_write_packet(AVFormatContext *avfcontext,
- int stream_index,
- unsigned char *buf, int size, int force_pts)
-{
- OggContext *context = avfcontext->priv_data ;
- ogg_packet *op ;
- ogg_page og ;
- int l = 0 ;
-
- /* flush header packets so audio starts on a new page */
-
- if(!context->header_handled) {
- while(ogg_stream_flush(&context->os, &og)) {
- put_buffer(&avfcontext->pb, og.header, og.header_len) ;
- put_buffer(&avfcontext->pb, og.body, og.body_len) ;
- put_flush_packet(&avfcontext->pb);
- }
- context->header_handled = 1 ;
- }
-
- while(l < size) {
- op = (ogg_packet*)(buf + l) ;
- op->packet = buf + l + sizeof(ogg_packet) ; /* fix data pointer */
-
- if(!context->base_packet_no) { /* this is the first packet */
- context->base_packet_no = op->packetno ;
- context->base_granule_pos = op->granulepos ;
- }
-
- /* correct the fields in the packet -- essential for streaming */
-
- op->packetno -= context->base_packet_no ;
- op->granulepos -= context->base_granule_pos ;
-
- ogg_stream_packetin(&context->os, op) ;
- l += sizeof(ogg_packet) + op->bytes ;
-
- while(ogg_stream_pageout(&context->os, &og)) {
- put_buffer(&avfcontext->pb, og.header, og.header_len) ;
- put_buffer(&avfcontext->pb, og.body, og.body_len) ;
- put_flush_packet(&avfcontext->pb);
- }
- }
-
- return 0;
-}
-
-
-static int ogg_write_trailer(AVFormatContext *avfcontext) {
- OggContext *context = avfcontext->priv_data ;
- ogg_page og ;
-
- while(ogg_stream_flush(&context->os, &og)) {
- put_buffer(&avfcontext->pb, og.header, og.header_len) ;
- put_buffer(&avfcontext->pb, og.body, og.body_len) ;
- put_flush_packet(&avfcontext->pb);
- }
-
- ogg_stream_clear(&context->os) ;
- return 0 ;
-}
-
-
-static AVOutputFormat ogg_oformat = {
- "ogg",
- "Ogg Vorbis",
- "audio/x-vorbis",
- "ogg",
- sizeof(OggContext),
- CODEC_ID_VORBIS,
- 0,
- ogg_write_header,
- ogg_write_packet,
- ogg_write_trailer,
-} ;
-
-
-static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) {
- OggContext *context = avfcontext->priv_data ;
- ogg_page og ;
- char *buf ;
-
- while(ogg_stream_packetout(&context->os, op) != 1) {
-
- /* while no pages are available, read in more data to the sync */
- while(ogg_sync_pageout(&context->oy, &og) != 1) {
- buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
- if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
- return 1 ;
- ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
- }
-
- /* got a page. Feed it into the stream and get the packet */
- if(ogg_stream_pagein(&context->os, &og) != 0)
- return 1 ;
- }
-
- return 0 ;
-}
-
-
-static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap)
-{
- OggContext *context = avfcontext->priv_data;
- char *buf ;
- ogg_page og ;
- AVStream *ast ;
-
- ogg_sync_init(&context->oy) ;
- buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
-
- if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0)
- return -EIO ;
-
- ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ;
- ogg_sync_pageout(&context->oy, &og) ;
- ogg_stream_init(&context->os, ogg_page_serialno(&og)) ;
- ogg_stream_pagein(&context->os, &og) ;
-
- /* currently only one vorbis stream supported */
-
- ast = av_new_stream(avfcontext, 0) ;
- if(!ast)
- return AVERROR_NOMEM ;
-
- ast->codec.codec_type = CODEC_TYPE_AUDIO ;
- ast->codec.codec_id = CODEC_ID_VORBIS ;
-
- return 0 ;
-}
-
-
-static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) {
- ogg_packet op ;
-
- if(next_packet(avfcontext, &op))
- return -EIO ;
- if(av_new_packet(pkt, sizeof(ogg_packet) + op.bytes) < 0)
- return -EIO ;
- pkt->stream_index = 0 ;
- memcpy(pkt->data, &op, sizeof(ogg_packet)) ;
- memcpy(pkt->data + sizeof(ogg_packet), op.packet, op.bytes) ;
-
- return sizeof(ogg_packet) + op.bytes ;
-}
-
-
-static int ogg_read_close(AVFormatContext *avfcontext) {
- OggContext *context = avfcontext->priv_data ;
-
- ogg_stream_clear(&context->os) ;
- ogg_sync_clear(&context->oy) ;
-
- return 0 ;
-}
-
-
-static AVInputFormat ogg_iformat = {
- "ogg",
- "Ogg Vorbis",
- sizeof(OggContext),
- NULL,
- ogg_read_header,
- ogg_read_packet,
- ogg_read_close,
- .extensions = "ogg",
-} ;
-
-
-int ogg_init(void) {
- av_register_output_format(&ogg_oformat) ;
- av_register_input_format(&ogg_iformat);
- return 0 ;
-}
+++ /dev/null
-/*
- * Various utilities for ffmpeg system
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#ifdef CONFIG_WIN32
-#include <sys/types.h>
-#include <sys/timeb.h>
-#elif defined(CONFIG_OS2)
-#include <string.h>
-#include <sys/time.h>
-#else
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#endif
-#include <time.h>
-
-int64_t av_gettime(void)
-{
-#ifdef CONFIG_WIN32
- struct _timeb tb;
- _ftime(&tb);
- return ((int64_t)tb.time * int64_t_C(1000) + (int64_t)tb.millitm) * int64_t_C(1000);
-#else
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
-#endif
-}
-
-#if !defined(HAVE_LOCALTIME_R)
-struct tm *localtime_r(const time_t *t, struct tm *tp)
-{
- struct tm *l;
-
- l = localtime(t);
- if (!l)
- return 0;
- *tp = *l;
- return tp;
-}
-#endif /* !defined(HAVE_LOCALTIME_R) */
+++ /dev/null
-#ifndef _OS_SUPPORT_H
-#define _OS_SUPPORT_H
-
-/**
- * @file os_support.h
- * miscellaneous OS support macros and functions.
- *
- * - usleep() (Win32, BeOS, OS/2)
- * - floatf() (OS/2)
- * - strcasecmp() (OS/2)
- */
-
-#ifdef __MINGW32__
-# undef DATADIR /* clashes with /usr/include/w32api/objidl.h */
-__declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds);
-// # include <windows.h>
-# define usleep(t) Sleep((t) / 1000)
-#endif
-
-#ifdef __BEOS__
-# ifndef usleep
-# include <OS.h>
-# define usleep(t) snooze((bigtime_t)(t))
-# endif
-#endif
-
-#if defined(CONFIG_OS2)
-#include <stdlib.h>
-static inline int usleep(unsigned int t) { return _sleep2(t / 1000); }
-static inline int strcasecmp(const char* s1, const char* s2) { return stricmp(s1,s2); }
-#endif
-
-#endif /* _OS_SUPPORT_H */
+++ /dev/null
-/*
- * PNG image format
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* TODO:
- * - add 2, 4 and 16 bit depth support
- * - use filters when generating a png (better compression)
- */
-
-#ifdef CONFIG_ZLIB
-#include <zlib.h>
-
-//#define DEBUG
-
-#define PNG_COLOR_MASK_PALETTE 1
-#define PNG_COLOR_MASK_COLOR 2
-#define PNG_COLOR_MASK_ALPHA 4
-
-#define PNG_COLOR_TYPE_GRAY 0
-#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
-#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
-#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
-#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
-
-#define PNG_FILTER_VALUE_NONE 0
-#define PNG_FILTER_VALUE_SUB 1
-#define PNG_FILTER_VALUE_UP 2
-#define PNG_FILTER_VALUE_AVG 3
-#define PNG_FILTER_VALUE_PAETH 4
-
-#define PNG_IHDR 0x0001
-#define PNG_IDAT 0x0002
-#define PNG_ALLIMAGE 0x0004
-#define PNG_PLTE 0x0008
-
-#define NB_PASSES 7
-
-#define IOBUF_SIZE 4096
-
-typedef struct PNGDecodeState {
- int state;
- int width, height;
- int bit_depth;
- int color_type;
- int compression_type;
- int interlace_type;
- int filter_type;
- int channels;
- int bits_per_pixel;
- int bpp;
-
- uint8_t *image_buf;
- int image_linesize;
- uint32_t palette[256];
- uint8_t *crow_buf;
- uint8_t *last_row;
- uint8_t *tmp_row;
- int pass;
- int crow_size; /* compressed row size (include filter type) */
- int row_size; /* decompressed row size */
- int pass_row_size; /* decompress row size of the current pass */
- int y;
- z_stream zstream;
-} PNGDecodeState;
-
-static const uint8_t pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
-
-/* Mask to determine which y pixels are valid in a pass */
-static const uint8_t png_pass_ymask[NB_PASSES] = {
- 0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55,
-};
-
-/* Mask to determine which y pixels can be written in a pass */
-static const uint8_t png_pass_dsp_ymask[NB_PASSES] = {
- 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55,
-};
-
-/* minimum x value */
-static const uint8_t png_pass_xmin[NB_PASSES] = {
- 0, 4, 0, 2, 0, 1, 0
-};
-
-/* x shift to get row width */
-static const uint8_t png_pass_xshift[NB_PASSES] = {
- 3, 3, 2, 2, 1, 1, 0
-};
-
-/* Mask to determine which pixels are valid in a pass */
-static const uint8_t png_pass_mask[NB_PASSES] = {
- 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff
-};
-
-/* Mask to determine which pixels to overwrite while displaying */
-static const uint8_t png_pass_dsp_mask[NB_PASSES] = {
- 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff
-};
-
-static int png_probe(AVProbeData *pd)
-{
- if (pd->buf_size >= 8 &&
- memcmp(pd->buf, pngsig, 8) == 0)
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static void *png_zalloc(void *opaque, unsigned int items, unsigned int size)
-{
- return av_malloc(items * size);
-}
-
-static void png_zfree(void *opaque, void *ptr)
-{
- av_free(ptr);
-}
-
-static int png_get_nb_channels(int color_type)
-{
- int channels;
- channels = 1;
- if ((color_type & (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)) ==
- PNG_COLOR_MASK_COLOR)
- channels = 3;
- if (color_type & PNG_COLOR_MASK_ALPHA)
- channels++;
- return channels;
-}
-
-/* compute the row size of an interleaved pass */
-static int png_pass_row_size(int pass, int bits_per_pixel, int width)
-{
- int shift, xmin, pass_width;
-
- xmin = png_pass_xmin[pass];
- if (width <= xmin)
- return 0;
- shift = png_pass_xshift[pass];
- pass_width = (width - xmin + (1 << shift) - 1) >> shift;
- return (pass_width * bits_per_pixel + 7) >> 3;
-}
-
-/* NOTE: we try to construct a good looking image at each pass. width
- is the original image width. We also do pixel format convertion at
- this stage */
-static void png_put_interlaced_row(uint8_t *dst, int width,
- int bits_per_pixel, int pass,
- int color_type, const uint8_t *src)
-{
- int x, mask, dsp_mask, j, src_x, b, bpp;
- uint8_t *d;
- const uint8_t *s;
-
- mask = png_pass_mask[pass];
- dsp_mask = png_pass_dsp_mask[pass];
- switch(bits_per_pixel) {
- case 1:
- /* we must intialize the line to zero before writing to it */
- if (pass == 0)
- memset(dst, 0, (width + 7) >> 3);
- src_x = 0;
- for(x = 0; x < width; x++) {
- j = (x & 7);
- if ((dsp_mask << j) & 0x80) {
- b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1;
- dst[x >> 3] |= b << (7 - j);
- }
- if ((mask << j) & 0x80)
- src_x++;
- }
- break;
- default:
- bpp = bits_per_pixel >> 3;
- d = dst;
- s = src;
- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- for(x = 0; x < width; x++) {
- j = x & 7;
- if ((dsp_mask << j) & 0x80) {
- *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2];
- }
- d += bpp;
- if ((mask << j) & 0x80)
- s += bpp;
- }
- } else {
- for(x = 0; x < width; x++) {
- j = x & 7;
- if ((dsp_mask << j) & 0x80) {
- memcpy(d, s, bpp);
- }
- d += bpp;
- if ((mask << j) & 0x80)
- s += bpp;
- }
- }
- break;
- }
-}
-
-static void png_get_interlaced_row(uint8_t *dst, int row_size,
- int bits_per_pixel, int pass,
- const uint8_t *src, int width)
-{
- int x, mask, dst_x, j, b, bpp;
- uint8_t *d;
- const uint8_t *s;
-
- mask = png_pass_mask[pass];
- switch(bits_per_pixel) {
- case 1:
- memset(dst, 0, row_size);
- dst_x = 0;
- for(x = 0; x < width; x++) {
- j = (x & 7);
- if ((mask << j) & 0x80) {
- b = (src[x >> 3] >> (7 - j)) & 1;
- dst[dst_x >> 3] |= b << (7 - (dst_x & 7));
- dst_x++;
- }
- }
- break;
- default:
- bpp = bits_per_pixel >> 3;
- d = dst;
- s = src;
- for(x = 0; x < width; x++) {
- j = x & 7;
- if ((mask << j) & 0x80) {
- memcpy(d, s, bpp);
- d += bpp;
- }
- s += bpp;
- }
- break;
- }
-}
-
-/* XXX: optimize */
-/* NOTE: 'dst' can be equal to 'last' */
-static void png_filter_row(uint8_t *dst, int filter_type,
- uint8_t *src, uint8_t *last, int size, int bpp)
-{
- int i, p;
-
- switch(filter_type) {
- case PNG_FILTER_VALUE_NONE:
- memcpy(dst, src, size);
- break;
- case PNG_FILTER_VALUE_SUB:
- for(i = 0; i < bpp; i++) {
- dst[i] = src[i];
- }
- for(i = bpp; i < size; i++) {
- p = dst[i - bpp];
- dst[i] = p + src[i];
- }
- break;
- case PNG_FILTER_VALUE_UP:
- for(i = 0; i < size; i++) {
- p = last[i];
- dst[i] = p + src[i];
- }
- break;
- case PNG_FILTER_VALUE_AVG:
- for(i = 0; i < bpp; i++) {
- p = (last[i] >> 1);
- dst[i] = p + src[i];
- }
- for(i = bpp; i < size; i++) {
- p = ((dst[i - bpp] + last[i]) >> 1);
- dst[i] = p + src[i];
- }
- break;
- case PNG_FILTER_VALUE_PAETH:
- for(i = 0; i < bpp; i++) {
- p = last[i];
- dst[i] = p + src[i];
- }
- for(i = bpp; i < size; i++) {
- int a, b, c, pa, pb, pc;
-
- a = dst[i - bpp];
- b = last[i];
- c = last[i - bpp];
-
- p = b - c;
- pc = a - c;
-
- pa = abs(p);
- pb = abs(pc);
- pc = abs(p + pc);
-
- if (pa <= pb && pa <= pc)
- p = a;
- else if (pb <= pc)
- p = b;
- else
- p = c;
- dst[i] = p + src[i];
- }
- break;
- }
-}
-
-static void convert_from_rgba32(uint8_t *dst, const uint8_t *src, int width)
-{
- uint8_t *d;
- int j;
- unsigned int v;
-
- d = dst;
- for(j = 0; j < width; j++) {
- v = ((uint32_t *)src)[j];
- d[0] = v >> 16;
- d[1] = v >> 8;
- d[2] = v;
- d[3] = v >> 24;
- d += 4;
- }
-}
-
-static void convert_to_rgba32(uint8_t *dst, const uint8_t *src, int width)
-{
- int j;
- unsigned int r, g, b, a;
-
- for(j = 0;j < width; j++) {
- r = src[0];
- g = src[1];
- b = src[2];
- a = src[3];
- *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b;
- dst += 4;
- src += 4;
- }
-}
-
-/* process exactly one decompressed row */
-static void png_handle_row(PNGDecodeState *s)
-{
- uint8_t *ptr, *last_row;
- int got_line;
-
- if (!s->interlace_type) {
- ptr = s->image_buf + s->image_linesize * s->y;
- /* need to swap bytes correctly for RGB_ALPHA */
- if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
- s->last_row, s->row_size, s->bpp);
- memcpy(s->last_row, s->tmp_row, s->row_size);
- convert_to_rgba32(ptr, s->tmp_row, s->width);
- } else {
- /* in normal case, we avoid one copy */
- if (s->y == 0)
- last_row = s->last_row;
- else
- last_row = ptr - s->image_linesize;
-
- png_filter_row(ptr, s->crow_buf[0], s->crow_buf + 1,
- last_row, s->row_size, s->bpp);
- }
- s->y++;
- if (s->y == s->height) {
- s->state |= PNG_ALLIMAGE;
- }
- } else {
- got_line = 0;
- for(;;) {
- ptr = s->image_buf + s->image_linesize * s->y;
- if ((png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) {
- /* if we already read one row, it is time to stop to
- wait for the next one */
- if (got_line)
- break;
- png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1,
- s->last_row, s->pass_row_size, s->bpp);
- memcpy(s->last_row, s->tmp_row, s->pass_row_size);
- got_line = 1;
- }
- if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) {
- /* NOTE: rgba32 is handled directly in png_put_interlaced_row */
- png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass,
- s->color_type, s->last_row);
- }
- s->y++;
- if (s->y == s->height) {
- for(;;) {
- if (s->pass == NB_PASSES - 1) {
- s->state |= PNG_ALLIMAGE;
- goto the_end;
- } else {
- s->pass++;
- s->y = 0;
- s->pass_row_size = png_pass_row_size(s->pass,
- s->bits_per_pixel,
- s->width);
- s->crow_size = s->pass_row_size + 1;
- if (s->pass_row_size != 0)
- break;
- /* skip pass if empty row */
- }
- }
- }
- }
- the_end: ;
- }
-}
-
-static int png_decode_idat(PNGDecodeState *s, ByteIOContext *f, int length)
-{
- uint8_t buf[IOBUF_SIZE];
- int buf_size;
- int ret;
- while (length > 0) {
- /* read the buffer */
- buf_size = IOBUF_SIZE;
- if (buf_size > length)
- buf_size = length;
- ret = get_buffer(f, buf, buf_size);
- if (ret != buf_size)
- return -1;
- s->zstream.avail_in = buf_size;
- s->zstream.next_in = buf;
- /* decode one line if possible */
- while (s->zstream.avail_in > 0) {
- ret = inflate(&s->zstream, Z_PARTIAL_FLUSH);
- if (ret != Z_OK && ret != Z_STREAM_END) {
- return -1;
- }
- if (s->zstream.avail_out == 0) {
- if (!(s->state & PNG_ALLIMAGE)) {
- png_handle_row(s);
- }
- s->zstream.avail_out = s->crow_size;
- s->zstream.next_out = s->crow_buf;
- }
- }
- length -= buf_size;
- }
- return 0;
-}
-
-static int png_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- AVImageInfo info1, *info = &info1;
- PNGDecodeState s1, *s = &s1;
- uint32_t tag, length;
- int ret, crc;
- uint8_t buf[8];
-
- /* check signature */
- ret = get_buffer(f, buf, 8);
- if (ret != 8)
- return -1;
- if (memcmp(buf, pngsig, 8) != 0)
- return -1;
- memset(s, 0, sizeof(PNGDecodeState));
- /* init the zlib */
- s->zstream.zalloc = png_zalloc;
- s->zstream.zfree = png_zfree;
- s->zstream.opaque = NULL;
- ret = inflateInit(&s->zstream);
- if (ret != Z_OK)
- return -1;
- for(;;) {
- if (url_feof(f))
- goto fail;
- length = get_be32(f);
- if (length > 0x7fffffff)
- goto fail;
- tag = get_le32(f);
-#ifdef DEBUG
- printf("png: tag=%c%c%c%c length=%u\n",
- (tag & 0xff),
- ((tag >> 8) & 0xff),
- ((tag >> 16) & 0xff),
- ((tag >> 24) & 0xff), length);
-#endif
- switch(tag) {
- case MKTAG('I', 'H', 'D', 'R'):
- if (length != 13)
- goto fail;
- s->width = get_be32(f);
- s->height = get_be32(f);
- s->bit_depth = get_byte(f);
- s->color_type = get_byte(f);
- s->compression_type = get_byte(f);
- s->filter_type = get_byte(f);
- s->interlace_type = get_byte(f);
- crc = get_be32(f);
- s->state |= PNG_IHDR;
-#ifdef DEBUG
- printf("width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n",
- s->width, s->height, s->bit_depth, s->color_type,
- s->compression_type, s->filter_type, s->interlace_type);
-#endif
- break;
- case MKTAG('I', 'D', 'A', 'T'):
- if (!(s->state & PNG_IHDR))
- goto fail;
- if (!(s->state & PNG_IDAT)) {
- /* init image info */
- info->width = s->width;
- info->height = s->height;
- info->interleaved = (s->interlace_type != 0);
-
- s->channels = png_get_nb_channels(s->color_type);
- s->bits_per_pixel = s->bit_depth * s->channels;
- s->bpp = (s->bits_per_pixel + 7) >> 3;
- s->row_size = (info->width * s->bits_per_pixel + 7) >> 3;
-
- if (s->bit_depth == 8 &&
- s->color_type == PNG_COLOR_TYPE_RGB) {
- info->pix_fmt = PIX_FMT_RGB24;
- } else if (s->bit_depth == 8 &&
- s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- info->pix_fmt = PIX_FMT_RGBA32;
- } else if (s->bit_depth == 8 &&
- s->color_type == PNG_COLOR_TYPE_GRAY) {
- info->pix_fmt = PIX_FMT_GRAY8;
- } else if (s->bit_depth == 1 &&
- s->color_type == PNG_COLOR_TYPE_GRAY) {
- info->pix_fmt = PIX_FMT_MONOBLACK;
- } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) {
- info->pix_fmt = PIX_FMT_PAL8;
- } else {
- goto fail;
- }
- ret = alloc_cb(opaque, info);
- if (ret)
- goto the_end;
-
- /* compute the compressed row size */
- if (!s->interlace_type) {
- s->crow_size = s->row_size + 1;
- } else {
- s->pass = 0;
- s->pass_row_size = png_pass_row_size(s->pass,
- s->bits_per_pixel,
- s->width);
- s->crow_size = s->pass_row_size + 1;
- }
-#ifdef DEBUG
- printf("row_size=%d crow_size =%d\n",
- s->row_size, s->crow_size);
-#endif
- s->image_buf = info->pict.data[0];
- s->image_linesize = info->pict.linesize[0];
- /* copy the palette if needed */
- if (s->color_type == PNG_COLOR_TYPE_PALETTE)
- memcpy(info->pict.data[1], s->palette, 256 * sizeof(uint32_t));
- /* empty row is used if differencing to the first row */
- s->last_row = av_mallocz(s->row_size);
- if (!s->last_row)
- goto fail;
- if (s->interlace_type ||
- s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- s->tmp_row = av_malloc(s->row_size);
- if (!s->tmp_row)
- goto fail;
- }
- /* compressed row */
- s->crow_buf = av_malloc(s->row_size + 1);
- if (!s->crow_buf)
- goto fail;
- s->zstream.avail_out = s->crow_size;
- s->zstream.next_out = s->crow_buf;
- }
- s->state |= PNG_IDAT;
- if (png_decode_idat(s, f, length) < 0)
- goto fail;
- /* skip crc */
- crc = get_be32(f);
- break;
- case MKTAG('P', 'L', 'T', 'E'):
- {
- int n, i, r, g, b;
-
- if ((length % 3) != 0 || length > 256 * 3)
- goto skip_tag;
- /* read the palette */
- n = length / 3;
- for(i=0;i<n;i++) {
- r = get_byte(f);
- g = get_byte(f);
- b = get_byte(f);
- s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b;
- }
- for(;i<256;i++) {
- s->palette[i] = (0xff << 24);
- }
- s->state |= PNG_PLTE;
- crc = get_be32(f);
- }
- break;
- case MKTAG('t', 'R', 'N', 'S'):
- {
- int v, i;
-
- /* read the transparency. XXX: Only palette mode supported */
- if (s->color_type != PNG_COLOR_TYPE_PALETTE ||
- length > 256 ||
- !(s->state & PNG_PLTE))
- goto skip_tag;
- for(i=0;i<length;i++) {
- v = get_byte(f);
- s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24);
- }
- crc = get_be32(f);
- }
- break;
- case MKTAG('I', 'E', 'N', 'D'):
- if (!(s->state & PNG_ALLIMAGE))
- goto fail;
- crc = get_be32(f);
- goto exit_loop;
- default:
- /* skip tag */
- skip_tag:
- url_fskip(f, length + 4);
- break;
- }
- }
- exit_loop:
- ret = 0;
- the_end:
- inflateEnd(&s->zstream);
- av_free(s->crow_buf);
- av_free(s->last_row);
- av_free(s->tmp_row);
- return ret;
- fail:
- ret = -1;
- goto the_end;
-}
-
-static void png_write_chunk(ByteIOContext *f, uint32_t tag,
- const uint8_t *buf, int length)
-{
- uint32_t crc;
- uint8_t tagbuf[4];
-
- put_be32(f, length);
- crc = crc32(0, Z_NULL, 0);
- tagbuf[0] = tag;
- tagbuf[1] = tag >> 8;
- tagbuf[2] = tag >> 16;
- tagbuf[3] = tag >> 24;
- crc = crc32(crc, tagbuf, 4);
- put_le32(f, tag);
- if (length > 0) {
- crc = crc32(crc, buf, length);
- put_buffer(f, buf, length);
- }
- put_be32(f, crc);
-}
-
-/* XXX: use avcodec generic function ? */
-static void to_be32(uint8_t *p, uint32_t v)
-{
- p[0] = v >> 24;
- p[1] = v >> 16;
- p[2] = v >> 8;
- p[3] = v;
-}
-
-typedef struct PNGEncodeState {
- ByteIOContext *f;
- z_stream zstream;
- uint8_t buf[IOBUF_SIZE];
-} PNGEncodeState;
-
-
-/* XXX: do filtering */
-static int png_write_row(PNGEncodeState *s, const uint8_t *data, int size)
-{
- int ret;
-
- s->zstream.avail_in = size;
- s->zstream.next_in = (uint8_t *)data;
- while (s->zstream.avail_in > 0) {
- ret = deflate(&s->zstream, Z_NO_FLUSH);
- if (ret != Z_OK)
- return -1;
- if (s->zstream.avail_out == 0) {
- png_write_chunk(s->f, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE);
- s->zstream.avail_out = IOBUF_SIZE;
- s->zstream.next_out = s->buf;
- }
- }
- return 0;
-}
-
-static int png_write(ByteIOContext *f, AVImageInfo *info)
-{
- PNGEncodeState s1, *s = &s1;
- int bit_depth, color_type, y, len, row_size, ret, is_progressive;
- int bits_per_pixel, pass_row_size;
- uint8_t *ptr;
- uint8_t *crow_buf = NULL;
- uint8_t *tmp_buf = NULL;
-
- s->f = f;
- is_progressive = info->interleaved;
- switch(info->pix_fmt) {
- case PIX_FMT_RGBA32:
- bit_depth = 8;
- color_type = PNG_COLOR_TYPE_RGB_ALPHA;
- break;
- case PIX_FMT_RGB24:
- bit_depth = 8;
- color_type = PNG_COLOR_TYPE_RGB;
- break;
- case PIX_FMT_GRAY8:
- bit_depth = 8;
- color_type = PNG_COLOR_TYPE_GRAY;
- break;
- case PIX_FMT_MONOBLACK:
- bit_depth = 1;
- color_type = PNG_COLOR_TYPE_GRAY;
- break;
- case PIX_FMT_PAL8:
- bit_depth = 8;
- color_type = PNG_COLOR_TYPE_PALETTE;
- break;
- default:
- return -1;
- }
- bits_per_pixel = png_get_nb_channels(color_type) * bit_depth;
- row_size = (info->width * bits_per_pixel + 7) >> 3;
-
- s->zstream.zalloc = png_zalloc;
- s->zstream.zfree = png_zfree;
- s->zstream.opaque = NULL;
- ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
- Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
- if (ret != Z_OK)
- return -1;
- crow_buf = av_malloc(row_size + 1);
- if (!crow_buf)
- goto fail;
- if (is_progressive) {
- tmp_buf = av_malloc(row_size + 1);
- if (!tmp_buf)
- goto fail;
- }
-
- /* write png header */
- put_buffer(f, pngsig, 8);
-
- to_be32(s->buf, info->width);
- to_be32(s->buf + 4, info->height);
- s->buf[8] = bit_depth;
- s->buf[9] = color_type;
- s->buf[10] = 0; /* compression type */
- s->buf[11] = 0; /* filter type */
- s->buf[12] = is_progressive; /* interlace type */
-
- png_write_chunk(f, MKTAG('I', 'H', 'D', 'R'), s->buf, 13);
-
- /* put the palette if needed */
- if (color_type == PNG_COLOR_TYPE_PALETTE) {
- int has_alpha, alpha, i;
- unsigned int v;
- uint32_t *palette;
- uint8_t *alpha_ptr;
-
- palette = (uint32_t *)info->pict.data[1];
- ptr = s->buf;
- alpha_ptr = s->buf + 256 * 3;
- has_alpha = 0;
- for(i = 0; i < 256; i++) {
- v = palette[i];
- alpha = v >> 24;
- if (alpha != 0xff)
- has_alpha = 1;
- *alpha_ptr++ = alpha;
- ptr[0] = v >> 16;
- ptr[1] = v >> 8;
- ptr[2] = v;
- ptr += 3;
- }
- png_write_chunk(f, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3);
- if (has_alpha) {
- png_write_chunk(f, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256);
- }
- }
-
- /* now put each row */
- s->zstream.avail_out = IOBUF_SIZE;
- s->zstream.next_out = s->buf;
- if (is_progressive) {
- uint8_t *ptr1;
- int pass;
-
- for(pass = 0; pass < NB_PASSES; pass++) {
- /* NOTE: a pass is completely omited if no pixels would be
- output */
- pass_row_size = png_pass_row_size(pass, bits_per_pixel, info->width);
- if (pass_row_size > 0) {
- for(y = 0; y < info->height; y++) {
- if ((png_pass_ymask[pass] << (y & 7)) & 0x80) {
- ptr = info->pict.data[0] + y * info->pict.linesize[0];
- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
- convert_from_rgba32(tmp_buf, ptr, info->width);
- ptr1 = tmp_buf;
- } else {
- ptr1 = ptr;
- }
- png_get_interlaced_row(crow_buf + 1, pass_row_size,
- bits_per_pixel, pass,
- ptr1, info->width);
- crow_buf[0] = PNG_FILTER_VALUE_NONE;
- png_write_row(s, crow_buf, pass_row_size + 1);
- }
- }
- }
- }
- } else {
- for(y = 0; y < info->height; y++) {
- ptr = info->pict.data[0] + y * info->pict.linesize[0];
- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
- convert_from_rgba32(crow_buf + 1, ptr, info->width);
- else
- memcpy(crow_buf + 1, ptr, row_size);
- crow_buf[0] = PNG_FILTER_VALUE_NONE;
- png_write_row(s, crow_buf, row_size + 1);
- }
- }
- /* compress last bytes */
- for(;;) {
- ret = deflate(&s->zstream, Z_FINISH);
- if (ret == Z_OK || ret == Z_STREAM_END) {
- len = IOBUF_SIZE - s->zstream.avail_out;
- if (len > 0) {
- png_write_chunk(f, MKTAG('I', 'D', 'A', 'T'), s->buf, len);
- }
- s->zstream.avail_out = IOBUF_SIZE;
- s->zstream.next_out = s->buf;
- if (ret == Z_STREAM_END)
- break;
- } else {
- goto fail;
- }
- }
- png_write_chunk(f, MKTAG('I', 'E', 'N', 'D'), NULL, 0);
-
- put_flush_packet(f);
- ret = 0;
- the_end:
- av_free(crow_buf);
- av_free(tmp_buf);
- deflateEnd(&s->zstream);
- return ret;
- fail:
- ret = -1;
- goto the_end;
-}
-
-AVImageFormat png_image_format = {
- "png",
- "png",
- png_probe,
- png_read,
- (1 << PIX_FMT_RGBA32) | (1 << PIX_FMT_RGB24) | (1 << PIX_FMT_GRAY8) |
- (1 << PIX_FMT_MONOBLACK) | (1 << PIX_FMT_PAL8),
- png_write,
- AVIMAGE_INTERLEAVED,
-};
-#endif
+++ /dev/null
-/*
- * PNM image format
- * Copyright (c) 2002, 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-static inline int pnm_space(int c)
-{
- return (c == ' ' || c == '\n' || c == '\r' || c == '\t');
-}
-
-static void pnm_get(ByteIOContext *f, char *str, int buf_size)
-{
- char *s;
- int c;
-
- /* skip spaces and comments */
- for(;;) {
- c = url_fgetc(f);
- if (c == '#') {
- do {
- c = url_fgetc(f);
- } while (c != '\n' && c != URL_EOF);
- } else if (!pnm_space(c)) {
- break;
- }
- }
-
- s = str;
- while (c != URL_EOF && !pnm_space(c)) {
- if ((s - str) < buf_size - 1)
- *s++ = c;
- c = url_fgetc(f);
- }
- *s = '\0';
-}
-
-static int pnm_read1(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque,
- int allow_yuv)
-{
- int i, n, linesize, h;
- char buf1[32];
- unsigned char *ptr;
- AVImageInfo info1, *info = &info1;
- int ret;
-
- pnm_get(f, buf1, sizeof(buf1));
- if (!strcmp(buf1, "P4")) {
- info->pix_fmt = PIX_FMT_MONOWHITE;
- } else if (!strcmp(buf1, "P5")) {
- if (allow_yuv)
- info->pix_fmt = PIX_FMT_YUV420P;
- else
- info->pix_fmt = PIX_FMT_GRAY8;
- } else if (!strcmp(buf1, "P6")) {
- info->pix_fmt = PIX_FMT_RGB24;
- } else {
- return AVERROR_INVALIDDATA;
- }
- pnm_get(f, buf1, sizeof(buf1));
- info->width = atoi(buf1);
- if (info->width <= 0)
- return AVERROR_INVALIDDATA;
- pnm_get(f, buf1, sizeof(buf1));
- info->height = atoi(buf1);
- if (info->height <= 0)
- return AVERROR_INVALIDDATA;
- if (info->pix_fmt != PIX_FMT_MONOWHITE) {
- pnm_get(f, buf1, sizeof(buf1));
- }
-
- /* more check if YUV420 */
- if (info->pix_fmt == PIX_FMT_YUV420P) {
- if ((info->width & 1) != 0)
- return AVERROR_INVALIDDATA;
- h = (info->height * 2);
- if ((h % 3) != 0)
- return AVERROR_INVALIDDATA;
- h /= 3;
- info->height = h;
- }
-
- ret = alloc_cb(opaque, info);
- if (ret)
- return ret;
-
- switch(info->pix_fmt) {
- default:
- return AVERROR_INVALIDDATA;
- case PIX_FMT_RGB24:
- n = info->width * 3;
- goto do_read;
- case PIX_FMT_GRAY8:
- n = info->width;
- goto do_read;
- case PIX_FMT_MONOWHITE:
- n = (info->width + 7) >> 3;
- do_read:
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
- for(i = 0; i < info->height; i++) {
- get_buffer(f, ptr, n);
- ptr += linesize;
- }
- break;
- case PIX_FMT_YUV420P:
- {
- unsigned char *ptr1, *ptr2;
-
- n = info->width;
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
- for(i = 0; i < info->height; i++) {
- get_buffer(f, ptr, n);
- ptr += linesize;
- }
- ptr1 = info->pict.data[1];
- ptr2 = info->pict.data[2];
- n >>= 1;
- h = info->height >> 1;
- for(i = 0; i < h; i++) {
- get_buffer(f, ptr1, n);
- get_buffer(f, ptr2, n);
- ptr1 += info->pict.linesize[1];
- ptr2 += info->pict.linesize[2];
- }
- }
- break;
- }
- return 0;
-}
-
-static int pnm_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- return pnm_read1(f, alloc_cb, opaque, 0);
-}
-
-static int pgmyuv_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- return pnm_read1(f, alloc_cb, opaque, 1);
-}
-
-static int pnm_write(ByteIOContext *pb, AVImageInfo *info)
-{
- int i, h, h1, c, n, linesize;
- char buf[100];
- uint8_t *ptr, *ptr1, *ptr2;
-
- h = info->height;
- h1 = h;
- switch(info->pix_fmt) {
- case PIX_FMT_MONOWHITE:
- c = '4';
- n = (info->width + 7) >> 3;
- break;
- case PIX_FMT_GRAY8:
- c = '5';
- n = info->width;
- break;
- case PIX_FMT_RGB24:
- c = '6';
- n = info->width * 3;
- break;
- case PIX_FMT_YUV420P:
- c = '5';
- n = info->width;
- h1 = (h * 3) / 2;
- break;
- default:
- return AVERROR_INVALIDDATA;
- }
- snprintf(buf, sizeof(buf),
- "P%c\n%d %d\n",
- c, info->width, h1);
- put_buffer(pb, buf, strlen(buf));
- if (info->pix_fmt != PIX_FMT_MONOWHITE) {
- snprintf(buf, sizeof(buf),
- "%d\n", 255);
- put_buffer(pb, buf, strlen(buf));
- }
-
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
- for(i=0;i<h;i++) {
- put_buffer(pb, ptr, n);
- ptr += linesize;
- }
-
- if (info->pix_fmt == PIX_FMT_YUV420P) {
- h >>= 1;
- n >>= 1;
- ptr1 = info->pict.data[1];
- ptr2 = info->pict.data[2];
- for(i=0;i<h;i++) {
- put_buffer(pb, ptr1, n);
- put_buffer(pb, ptr2, n);
- ptr1 += info->pict.linesize[1];
- ptr2 += info->pict.linesize[2];
- }
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static int pam_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- int i, n, linesize, h, w, depth, maxval;
- char buf1[32], tuple_type[32];
- unsigned char *ptr;
- AVImageInfo info1, *info = &info1;
- int ret;
-
- pnm_get(f, buf1, sizeof(buf1));
- if (strcmp(buf1, "P7") != 0)
- return AVERROR_INVALIDDATA;
- w = -1;
- h = -1;
- maxval = -1;
- depth = -1;
- tuple_type[0] = '\0';
- for(;;) {
- pnm_get(f, buf1, sizeof(buf1));
- if (!strcmp(buf1, "WIDTH")) {
- pnm_get(f, buf1, sizeof(buf1));
- w = strtol(buf1, NULL, 10);
- } else if (!strcmp(buf1, "HEIGHT")) {
- pnm_get(f, buf1, sizeof(buf1));
- h = strtol(buf1, NULL, 10);
- } else if (!strcmp(buf1, "DEPTH")) {
- pnm_get(f, buf1, sizeof(buf1));
- depth = strtol(buf1, NULL, 10);
- } else if (!strcmp(buf1, "MAXVAL")) {
- pnm_get(f, buf1, sizeof(buf1));
- maxval = strtol(buf1, NULL, 10);
- } else if (!strcmp(buf1, "TUPLETYPE")) {
- pnm_get(f, buf1, sizeof(buf1));
- pstrcpy(tuple_type, sizeof(tuple_type), buf1);
- } else if (!strcmp(buf1, "ENDHDR")) {
- break;
- } else {
- return AVERROR_INVALIDDATA;
- }
- }
- /* check that all tags are present */
- if (w <= 0 || h <= 0 || maxval <= 0 || depth <= 0 || tuple_type[0] == '\0')
- return AVERROR_INVALIDDATA;
- info->width = w;
- info->height = h;
- if (depth == 1) {
- if (maxval == 1)
- info->pix_fmt = PIX_FMT_MONOWHITE;
- else
- info->pix_fmt = PIX_FMT_GRAY8;
- } else if (depth == 3) {
- info->pix_fmt = PIX_FMT_RGB24;
- } else if (depth == 4) {
- info->pix_fmt = PIX_FMT_RGBA32;
- } else {
- return AVERROR_INVALIDDATA;
- }
- ret = alloc_cb(opaque, info);
- if (ret)
- return ret;
-
- switch(info->pix_fmt) {
- default:
- return AVERROR_INVALIDDATA;
- case PIX_FMT_RGB24:
- n = info->width * 3;
- goto do_read;
- case PIX_FMT_GRAY8:
- n = info->width;
- goto do_read;
- case PIX_FMT_MONOWHITE:
- n = (info->width + 7) >> 3;
- do_read:
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
- for(i = 0; i < info->height; i++) {
- get_buffer(f, ptr, n);
- ptr += linesize;
- }
- break;
- case PIX_FMT_RGBA32:
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
- for(i = 0; i < info->height; i++) {
- int j, r, g, b, a;
-
- for(j = 0;j < w; j++) {
- r = get_byte(f);
- g = get_byte(f);
- b = get_byte(f);
- a = get_byte(f);
- ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b;
- }
- ptr += linesize;
- }
- break;
- }
- return 0;
-}
-
-static int pam_write(ByteIOContext *pb, AVImageInfo *info)
-{
- int i, h, w, n, linesize, depth, maxval;
- const char *tuple_type;
- char buf[100];
- uint8_t *ptr;
-
- h = info->height;
- w = info->width;
- switch(info->pix_fmt) {
- case PIX_FMT_MONOWHITE:
- n = (info->width + 7) >> 3;
- depth = 1;
- maxval = 1;
- tuple_type = "BLACKANDWHITE";
- break;
- case PIX_FMT_GRAY8:
- n = info->width;
- depth = 1;
- maxval = 255;
- tuple_type = "GRAYSCALE";
- break;
- case PIX_FMT_RGB24:
- n = info->width * 3;
- depth = 3;
- maxval = 255;
- tuple_type = "RGB";
- break;
- case PIX_FMT_RGBA32:
- n = info->width * 4;
- depth = 4;
- maxval = 255;
- tuple_type = "RGB_ALPHA";
- break;
- default:
- return AVERROR_INVALIDDATA;
- }
- snprintf(buf, sizeof(buf),
- "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n",
- w, h, depth, maxval, tuple_type);
- put_buffer(pb, buf, strlen(buf));
-
- ptr = info->pict.data[0];
- linesize = info->pict.linesize[0];
-
- if (info->pix_fmt == PIX_FMT_RGBA32) {
- int j;
- unsigned int v;
-
- for(i=0;i<h;i++) {
- for(j=0;j<w;j++) {
- v = ((uint32_t *)ptr)[j];
- put_byte(pb, (v >> 16) & 0xff);
- put_byte(pb, (v >> 8) & 0xff);
- put_byte(pb, (v) & 0xff);
- put_byte(pb, (v >> 24) & 0xff);
- }
- ptr += linesize;
- }
- } else {
- for(i=0;i<h;i++) {
- put_buffer(pb, ptr, n);
- ptr += linesize;
- }
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static int pnm_probe(AVProbeData *pd)
-{
- const char *p = pd->buf;
- if (pd->buf_size >= 8 &&
- p[0] == 'P' &&
- p[1] >= '4' && p[1] <= '6' &&
- p[2] == '\n')
- return AVPROBE_SCORE_MAX - 1; /* to permit pgmyuv probe */
- else
- return 0;
-}
-
-static int pgmyuv_probe(AVProbeData *pd)
-{
- if (match_ext(pd->filename, "pgmyuv"))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static int pam_probe(AVProbeData *pd)
-{
- const char *p = pd->buf;
- if (pd->buf_size >= 8 &&
- p[0] == 'P' &&
- p[1] == '7' &&
- p[2] == '\n')
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-AVImageFormat pnm_image_format = {
- "pnm",
- NULL,
- pnm_probe,
- pnm_read,
- 0,
- NULL,
-};
-
-AVImageFormat pbm_image_format = {
- "pbm",
- "pbm",
- NULL,
- NULL,
- (1 << PIX_FMT_MONOWHITE),
- pnm_write,
-};
-
-AVImageFormat pgm_image_format = {
- "pgm",
- "pgm",
- NULL,
- NULL,
- (1 << PIX_FMT_GRAY8),
- pnm_write,
-};
-
-AVImageFormat ppm_image_format = {
- "ppm",
- "ppm",
- NULL,
- NULL,
- (1 << PIX_FMT_RGB24),
- pnm_write,
-};
-
-AVImageFormat pam_image_format = {
- "pam",
- "pam",
- pam_probe,
- pam_read,
- (1 << PIX_FMT_MONOWHITE) | (1 << PIX_FMT_GRAY8) | (1 << PIX_FMT_RGB24) |
- (1 << PIX_FMT_RGBA32),
- pam_write,
-};
-
-AVImageFormat pgmyuv_image_format = {
- "pgmyuv",
- "pgmyuv",
- pgmyuv_probe,
- pgmyuv_read,
- (1 << PIX_FMT_YUV420P),
- pnm_write,
-};
+++ /dev/null
-/*
- * Sony Playstation (PSX) STR File Demuxer
- * Copyright (c) 2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file psxstr.c
- * PSX STR file demuxer
- * by Mike Melanson (melanson@pcisys.net)
- * This module handles streams that have been ripped from Sony Playstation
- * CD games. This demuxer can handle either raw STR files (which are just
- * concatenations of raw compact disc sectors) or STR files with 0x2C-byte
- * RIFF headers, followed by CD sectors.
- */
-
-#include "avformat.h"
-
-//#define PRINTSTUFF
-
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-
-#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
- ( (long)(unsigned char)(ch0) | \
- ( (long)(unsigned char)(ch1) << 8 ) | \
- ( (long)(unsigned char)(ch2) << 16 ) | \
- ( (long)(unsigned char)(ch3) << 24 ) )
-
-#define RIFF_TAG FOURCC_TAG('R', 'I', 'F', 'F')
-#define CDXA_TAG FOURCC_TAG('C', 'D', 'X', 'A')
-
-#define RAW_CD_SECTOR_SIZE 2352
-#define RAW_CD_SECTOR_DATA_SIZE 2304
-#define VIDEO_DATA_CHUNK_SIZE 0x7E0
-#define VIDEO_DATA_HEADER_SIZE 0x38
-#define RIFF_HEADER_SIZE 0x2C
-
-#define CDXA_TYPE_MASK 0x0E
-#define CDXA_TYPE_DATA 0x08
-#define CDXA_TYPE_AUDIO 0x04
-#define CDXA_TYPE_VIDEO 0x02
-
-#define STR_MAGIC (0x80010160)
-
-typedef struct StrChannel {
-
- int type;
-#define STR_AUDIO 0
-#define STR_VIDEO 1
-
- /* video parameters */
- int width;
- int height;
- int video_stream_index;
-
- /* audio parameters */
- int sample_rate;
- int channels;
- int bits;
- int audio_stream_index;
-} StrChannel;
-
-typedef struct StrDemuxContext {
-
- /* a STR file can contain up to 32 channels of data */
- StrChannel channels[32];
-
- /* only decode the first audio and video channels encountered */
- int video_channel;
- int audio_channel;
-
- int64_t pts;
-
- unsigned char *video_chunk;
-} StrDemuxContext;
-
-static int str_probe(AVProbeData *p)
-{
- int start;
-
- /* need at least 0x38 bytes to validate */
- if (p->buf_size < 0x38)
- return 0;
-
- if ((LE_32(&p->buf[0]) == RIFF_TAG) &&
- (LE_32(&p->buf[8]) == CDXA_TAG)) {
-
- /* RIFF header seen; skip 0x2C bytes */
- start = RIFF_HEADER_SIZE;
- } else
- start = 0;
-
- /* look for CD sync header (00, 0xFF x 10, 00) */
- if ((p->buf[start + 0] != 0x00) || (p->buf[start + 1] != 0xFF) ||
- (p->buf[start + 2] != 0xFF) || (p->buf[start + 3] != 0xFF) ||
- (p->buf[start + 4] != 0xFF) || (p->buf[start + 5] != 0xFF) ||
- (p->buf[start + 6] != 0xFF) || (p->buf[start + 7] != 0xFF) ||
- (p->buf[start + 8] != 0xFF) || (p->buf[start + 9] != 0xFF) ||
- (p->buf[start + 10] != 0xFF) || (p->buf[start + 11] != 0x00))
- return 0;
-
- /* MPEG files (like those ripped from VCDs) can also look like this;
- * only return half certainty */
- return 50;
-}
-
-static int str_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- ByteIOContext *pb = &s->pb;
- StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
- AVStream *st;
- unsigned char sector[RAW_CD_SECTOR_SIZE];
- int start;
- int i;
- int channel;
-
- /* initialize context members */
- str->pts = 0;
- str->audio_channel = -1; /* assume to audio or video */
- str->video_channel = -1;
- str->video_chunk = NULL;
-
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
- /* skip over any RIFF header */
- if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE)
- return AVERROR_IO;
- if (LE_32(§or[0]) == RIFF_TAG)
- start = RIFF_HEADER_SIZE;
- else
- start = 0;
-
- url_fseek(pb, start, SEEK_SET);
-
- /* check through the first 32 sectors for individual channels */
- for (i = 0; i < 32; i++) {
- if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
- return AVERROR_IO;
-
- channel = sector[0x11];
- if (channel >= 32)
- return AVERROR_INVALIDDATA;
-
- switch (sector[0x12] & CDXA_TYPE_MASK) {
-
- case CDXA_TYPE_DATA:
- case CDXA_TYPE_VIDEO:
- /* check if this channel gets to be the dominant video channel */
- if (str->video_channel == -1) {
- /* qualify the magic number */
- if (LE_32(§or[0x18]) != STR_MAGIC)
- break;
- str->video_channel = channel;
- str->channels[channel].type = STR_VIDEO;
- str->channels[channel].width = LE_16(§or[0x28]);
- str->channels[channel].height = LE_16(§or[0x2A]);
-
- /* allocate a new AVStream */
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- str->channels[channel].video_stream_index = st->index;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_MDEC;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = str->channels[channel].width;
- st->codec.height = str->channels[channel].height;
- }
- break;
-
- case CDXA_TYPE_AUDIO:
- /* check if this channel gets to be the dominant audio channel */
- if (str->audio_channel == -1) {
- str->audio_channel = channel;
- str->channels[channel].type = STR_AUDIO;
- str->channels[channel].channels =
- (sector[0x13] & 0x01) ? 2 : 1;
- str->channels[channel].sample_rate =
- (sector[0x13] & 0x04) ? 18900 : 37800;
- str->channels[channel].bits =
- (sector[0x13] & 0x10) ? 8 : 4;
- }
- break;
-
- default:
- /* ignore */
- break;
- }
- }
-
-if (str->video_channel != -1)
- printf (" video channel = %d, %d x %d\n", str->video_channel,
- str->channels[str->video_channel].width,
- str->channels[str->video_channel].height);
-if (str->audio_channel != -1)
- printf (" audio channel = %d, %d Hz, %d channels, %d bits/sample\n",
- str->video_channel,
- str->channels[str->video_channel].sample_rate,
- str->channels[str->video_channel].channels,
- str->channels[str->video_channel].bits);
-
- /* back to the start */
- url_fseek(pb, start, SEEK_SET);
-
- return 0;
-}
-
-static int str_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- ByteIOContext *pb = &s->pb;
- StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
- unsigned char sector[RAW_CD_SECTOR_SIZE];
- int channel;
- int packet_read = 0;
- int video_sector_count = 0;
- int current_video_sector = 0;
- int video_frame_size = 0;
- int video_frame_index = 0;
- int bytes_to_copy;
- int ret = 0;
-
- while (!packet_read) {
-
- if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE)
- return -EIO;
-
- channel = sector[0x11];
- if (channel >= 32)
- return AVERROR_INVALIDDATA;
-
- switch (sector[0x12] & CDXA_TYPE_MASK) {
-
- case CDXA_TYPE_DATA:
- case CDXA_TYPE_VIDEO:
- /* check if this the video channel we care about */
- if (channel == str->video_channel) {
-
- /* if this is the first sector of the frame, allocate a pkt */
- if (current_video_sector == 0) {
- video_frame_size = LE_32(§or[0x24]);
- video_sector_count = LE_16(§or[0x1E]);
- if (av_new_packet(pkt, video_frame_size))
- return -EIO;
-
- pkt->stream_index =
- str->channels[channel].video_stream_index;
- pkt->pts = str->pts;
-
- /* if there is no audio, adjust the pts after every video
- * frame; assume 15 fps */
- if (str->audio_channel != -1)
- str->pts += (90000 / 15);
- }
-
- /* load all the constituent chunks in the video packet */
- if (video_frame_size - video_frame_index < VIDEO_DATA_CHUNK_SIZE)
- bytes_to_copy = video_frame_size - video_frame_index;
- else
- bytes_to_copy = VIDEO_DATA_CHUNK_SIZE;
- if (video_frame_index < video_frame_size)
- memcpy(&pkt->data[video_frame_index],
- §or[VIDEO_DATA_HEADER_SIZE], bytes_to_copy);
-
-#ifdef PRINTSTUFF
-printf (" chunk %d/%d (bytes %d/%d), first 6 bytes = %02X %02X %02X %02X %02X %02X\n",
- current_video_sector, video_sector_count,
- video_frame_index, video_frame_size,
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 0],
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 1],
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 2],
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 3],
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 4],
- pkt->data[current_video_sector * VIDEO_DATA_CHUNK_SIZE + 5]);
-#endif
-
- video_frame_index += bytes_to_copy;
- /* must keep reading sectors until all current video sectors
- * are consumed */
- current_video_sector++;
- if (current_video_sector >= video_sector_count)
- packet_read = 1;
-
- }
- break;
-
- case CDXA_TYPE_AUDIO:
-#ifdef PRINTSTUFF
-printf (" dropping audio sector\n");
-#endif
- break;
- default:
- /* drop the sector and move on */
-#ifdef PRINTSTUFF
-printf (" dropping other sector\n");
-#endif
- break;
- }
-
- if (url_feof(pb))
- return -EIO;
- }
-
- return ret;
-}
-
-static int str_read_close(AVFormatContext *s)
-{
- StrDemuxContext *str = (StrDemuxContext *)s->priv_data;
-
- av_free(str->video_chunk);
-
- return 0;
-}
-
-static AVInputFormat str_iformat = {
- "psxstr",
- "Sony Playstation STR format",
- sizeof(StrDemuxContext),
- str_probe,
- str_read_header,
- str_read_packet,
- str_read_close,
-};
-
-int str_init(void)
-{
- av_register_input_format(&str_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * RAW encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* simple formats */
-static int raw_write_header(struct AVFormatContext *s)
-{
- return 0;
-}
-
-static int raw_write_packet(struct AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- put_buffer(&s->pb, buf, size);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int raw_write_trailer(struct AVFormatContext *s)
-{
- return 0;
-}
-
-/* raw input */
-static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- AVStream *st;
- int id;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- if (ap) {
- id = s->iformat->value;
- if (id == CODEC_ID_RAWVIDEO) {
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- } else {
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- }
- st->codec.codec_id = id;
-
- switch(st->codec.codec_type) {
- case CODEC_TYPE_AUDIO:
- st->codec.sample_rate = ap->sample_rate;
- st->codec.channels = ap->channels;
- break;
- case CODEC_TYPE_VIDEO:
- st->codec.frame_rate = ap->frame_rate;
- st->codec.frame_rate_base = ap->frame_rate_base;
- st->codec.width = ap->width;
- st->codec.height = ap->height;
- st->codec.pix_fmt = ap->pix_fmt;
- break;
- default:
- return -1;
- }
- } else {
- return -1;
- }
- return 0;
-}
-
-#define RAW_PACKET_SIZE 1024
-
-static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int ret, size;
- // AVStream *st = s->streams[0];
-
- size= RAW_PACKET_SIZE;
-
- if (av_new_packet(pkt, size) < 0)
- return -EIO;
-
- pkt->stream_index = 0;
- ret = get_buffer(&s->pb, pkt->data, size);
- if (ret <= 0) {
- av_free_packet(pkt);
- return -EIO;
- }
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- return ret;
-}
-
-static int raw_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-/* ac3 read */
-static int ac3_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *st;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_AC3;
- /* the parameters will be extracted from the compressed bitstream */
- return 0;
-}
-
-/* mpeg1/h263 input */
-static int video_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *st;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = s->iformat->value;
- /* for mjpeg, specify frame rate */
- /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/
- if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) {
- if (ap) {
- st->codec.frame_rate = ap->frame_rate;
- st->codec.frame_rate_base = ap->frame_rate_base;
- } else {
- st->codec.frame_rate = 25;
- st->codec.frame_rate_base = 1;
- }
- }
- return 0;
-}
-
-#define SEQ_START_CODE 0x000001b3
-#define GOP_START_CODE 0x000001b8
-#define PICTURE_START_CODE 0x00000100
-
-/* XXX: improve that by looking at several start codes */
-static int mpegvideo_probe(AVProbeData *p)
-{
- int code;
- const uint8_t *d;
-
- /* we search the first start code. If it is a sequence, gop or
- picture start code then we decide it is an mpeg video
- stream. We do not send highest value to give a chance to mpegts */
- /* NOTE: the search range was restricted to avoid too many false
- detections */
-
- if (p->buf_size < 6)
- return 0;
- d = p->buf;
- code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]);
- if ((code & 0xffffff00) == 0x100) {
- if (code == SEQ_START_CODE ||
- code == GOP_START_CODE ||
- code == PICTURE_START_CODE)
- return 50 - 1;
- else
- return 0;
- }
- return 0;
-}
-
-static int h263_probe(AVProbeData *p)
-{
- int code;
- const uint8_t *d;
-
- if (p->buf_size < 6)
- return 0;
- d = p->buf;
- code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
- if (code == 0x20) {
- return 50;
- }
- return 0;
-}
-
-AVInputFormat ac3_iformat = {
- "ac3",
- "raw ac3",
- 0,
- NULL,
- ac3_read_header,
- raw_read_packet,
- raw_read_close,
- .extensions = "ac3",
-};
-
-AVOutputFormat ac3_oformat = {
- "ac3",
- "raw ac3",
- "audio/x-ac3",
- "ac3",
- 0,
- CODEC_ID_AC3,
- 0,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-AVInputFormat h263_iformat = {
- "h263",
- "raw h263",
- 0,
- h263_probe,
- video_read_header,
- raw_read_packet,
- raw_read_close,
-// .extensions = "h263", //FIXME remove after writing mpeg4_probe
- .value = CODEC_ID_H263,
-};
-
-AVOutputFormat h263_oformat = {
- "h263",
- "raw h263",
- "video/x-h263",
- "h263",
- 0,
- 0,
- CODEC_ID_H263,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-AVInputFormat m4v_iformat = {
- "m4v",
- "raw MPEG4 video format",
- 0,
- NULL /*mpegvideo_probe*/,
- video_read_header,
- raw_read_packet,
- raw_read_close,
- .extensions = "m4v", //FIXME remove after writing mpeg4_probe
- .value = CODEC_ID_MPEG4,
-};
-
-AVOutputFormat m4v_oformat = {
- "m4v",
- "raw MPEG4 video format",
- NULL,
- "m4v",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_MPEG4,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-AVInputFormat h264_iformat = {
- "h264",
- "raw H264 video format",
- 0,
- NULL /*mpegvideo_probe*/,
- video_read_header,
- raw_read_packet,
- raw_read_close,
- .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe
- .value = CODEC_ID_H264,
-};
-
-AVOutputFormat h264_oformat = {
- "h264",
- "raw H264 video format",
- NULL,
- "h264",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_H264,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-AVInputFormat mpegvideo_iformat = {
- "mpegvideo",
- "MPEG video",
- 0,
- mpegvideo_probe,
- video_read_header,
- raw_read_packet,
- raw_read_close,
- .value = CODEC_ID_MPEG1VIDEO,
-};
-
-AVOutputFormat mpeg1video_oformat = {
- "mpeg1video",
- "MPEG video",
- "video/x-mpeg",
- "mpg,mpeg",
- 0,
- 0,
- CODEC_ID_MPEG1VIDEO,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-AVInputFormat mjpeg_iformat = {
- "mjpeg",
- "MJPEG video",
- 0,
- NULL,
- video_read_header,
- raw_read_packet,
- raw_read_close,
- .extensions = "mjpg,mjpeg",
- .value = CODEC_ID_MJPEG,
-};
-
-AVOutputFormat mjpeg_oformat = {
- "mjpeg",
- "MJPEG video",
- "video/x-mjpeg",
- "mjpg,mjpeg",
- 0,
- 0,
- CODEC_ID_MJPEG,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-/* pcm formats */
-
-#define PCMDEF(name, long_name, ext, codec) \
-AVInputFormat pcm_ ## name ## _iformat = {\
- #name,\
- long_name,\
- 0,\
- NULL,\
- raw_read_header,\
- raw_read_packet,\
- raw_read_close,\
- .extensions = ext,\
- .value = codec,\
-};\
-\
-AVOutputFormat pcm_ ## name ## _oformat = {\
- #name,\
- long_name,\
- NULL,\
- ext,\
- 0,\
- codec,\
- 0,\
- raw_write_header,\
- raw_write_packet,\
- raw_write_trailer,\
-};
-
-#ifdef WORDS_BIGENDIAN
-#define BE_DEF(s) s
-#define LE_DEF(s) NULL
-#else
-#define BE_DEF(s) NULL
-#define LE_DEF(s) s
-#endif
-
-
-PCMDEF(s16le, "pcm signed 16 bit little endian format",
- LE_DEF("sw"), CODEC_ID_PCM_S16LE)
-
-PCMDEF(s16be, "pcm signed 16 bit big endian format",
- BE_DEF("sw"), CODEC_ID_PCM_S16BE)
-
-PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
- LE_DEF("uw"), CODEC_ID_PCM_U16LE)
-
-PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
- BE_DEF("uw"), CODEC_ID_PCM_U16BE)
-
-PCMDEF(s8, "pcm signed 8 bit format",
- "sb", CODEC_ID_PCM_S8)
-
-PCMDEF(u8, "pcm unsigned 8 bit format",
- "ub", CODEC_ID_PCM_U8)
-
-PCMDEF(mulaw, "pcm mu law format",
- "ul", CODEC_ID_PCM_MULAW)
-
-PCMDEF(alaw, "pcm A law format",
- "al", CODEC_ID_PCM_ALAW)
-
-static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int packet_size, ret, width, height;
- AVStream *st = s->streams[0];
-
- width = st->codec.width;
- height = st->codec.height;
-
- packet_size = avpicture_get_size(st->codec.pix_fmt, width, height);
- if (packet_size < 0)
- av_abort();
-
- if (av_new_packet(pkt, packet_size) < 0)
- return -EIO;
-
- pkt->stream_index = 0;
-#if 0
- /* bypass buffered I/O */
- ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size);
-#else
- ret = get_buffer(&s->pb, pkt->data, pkt->size);
-#endif
- if (ret != pkt->size) {
- av_free_packet(pkt);
- return -EIO;
- } else {
- return 0;
- }
-}
-
-AVInputFormat rawvideo_iformat = {
- "rawvideo",
- "raw video format",
- 0,
- NULL,
- raw_read_header,
- rawvideo_read_packet,
- raw_read_close,
- .extensions = "yuv",
- .value = CODEC_ID_RAWVIDEO,
-};
-
-AVOutputFormat rawvideo_oformat = {
- "rawvideo",
- "raw video format",
- NULL,
- "yuv",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- raw_write_header,
- raw_write_packet,
- raw_write_trailer,
-};
-
-static int null_write_packet(struct AVFormatContext *s,
- int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- return 0;
-}
-
-AVOutputFormat null_oformat = {
- "null",
- "null video format",
- NULL,
- NULL,
- 0,
-#ifdef WORDS_BIGENDIAN
- CODEC_ID_PCM_S16BE,
-#else
- CODEC_ID_PCM_S16LE,
-#endif
- CODEC_ID_RAWVIDEO,
- raw_write_header,
- null_write_packet,
- raw_write_trailer,
- .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE,
-};
-
-int raw_init(void)
-{
- av_register_input_format(&ac3_iformat);
- av_register_output_format(&ac3_oformat);
-
- av_register_input_format(&h263_iformat);
- av_register_output_format(&h263_oformat);
-
- av_register_input_format(&m4v_iformat);
- av_register_output_format(&m4v_oformat);
-
- av_register_input_format(&h264_iformat);
- av_register_output_format(&h264_oformat);
-
- av_register_input_format(&mpegvideo_iformat);
- av_register_output_format(&mpeg1video_oformat);
-
- av_register_input_format(&mjpeg_iformat);
- av_register_output_format(&mjpeg_oformat);
-
- av_register_input_format(&pcm_s16le_iformat);
- av_register_output_format(&pcm_s16le_oformat);
- av_register_input_format(&pcm_s16be_iformat);
- av_register_output_format(&pcm_s16be_oformat);
- av_register_input_format(&pcm_u16le_iformat);
- av_register_output_format(&pcm_u16le_oformat);
- av_register_input_format(&pcm_u16be_iformat);
- av_register_output_format(&pcm_u16be_oformat);
- av_register_input_format(&pcm_s8_iformat);
- av_register_output_format(&pcm_s8_oformat);
- av_register_input_format(&pcm_u8_iformat);
- av_register_output_format(&pcm_u8_oformat);
- av_register_input_format(&pcm_mulaw_iformat);
- av_register_output_format(&pcm_mulaw_oformat);
- av_register_input_format(&pcm_alaw_iformat);
- av_register_output_format(&pcm_alaw_oformat);
-
- av_register_input_format(&rawvideo_iformat);
- av_register_output_format(&rawvideo_oformat);
-
- av_register_output_format(&null_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * "Real" compatible mux and demux.
- * Copyright (c) 2000, 2001 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* in ms */
-#define BUFFER_DURATION 0
-
-typedef struct {
- int nb_packets;
- int packet_total_size;
- int packet_max_size;
- /* codec related output */
- int bit_rate;
- float frame_rate;
- int nb_frames; /* current frame number */
- int total_frames; /* total number of frames */
- int num;
- AVCodecContext *enc;
-} StreamInfo;
-
-typedef struct {
- StreamInfo streams[2];
- StreamInfo *audio_stream, *video_stream;
- int data_pos; /* position of the data after the header */
- int nb_packets;
- int old_format;
-} RMContext;
-
-static void put_str(ByteIOContext *s, const char *tag)
-{
- put_be16(s,strlen(tag));
- while (*tag) {
- put_byte(s, *tag++);
- }
-}
-
-static void put_str8(ByteIOContext *s, const char *tag)
-{
- put_byte(s, strlen(tag));
- while (*tag) {
- put_byte(s, *tag++);
- }
-}
-
-static void rv10_write_header(AVFormatContext *ctx,
- int data_size, int index_pos)
-{
- RMContext *rm = ctx->priv_data;
- ByteIOContext *s = &ctx->pb;
- StreamInfo *stream;
- unsigned char *data_offset_ptr, *start_ptr;
- const char *desc, *mimetype;
- int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i;
- int bit_rate, v, duration, flags, data_pos;
-
- start_ptr = s->buf_ptr;
-
- put_tag(s, ".RMF");
- put_be32(s,18); /* header size */
- put_be16(s,0);
- put_be32(s,0);
- put_be32(s,4 + ctx->nb_streams); /* num headers */
-
- put_tag(s,"PROP");
- put_be32(s, 50);
- put_be16(s, 0);
- packet_max_size = 0;
- packet_total_size = 0;
- nb_packets = 0;
- bit_rate = 0;
- duration = 0;
- for(i=0;i<ctx->nb_streams;i++) {
- StreamInfo *stream = &rm->streams[i];
- bit_rate += stream->bit_rate;
- if (stream->packet_max_size > packet_max_size)
- packet_max_size = stream->packet_max_size;
- nb_packets += stream->nb_packets;
- packet_total_size += stream->packet_total_size;
- /* select maximum duration */
- v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate);
- if (v > duration)
- duration = v;
- }
- put_be32(s, bit_rate); /* max bit rate */
- put_be32(s, bit_rate); /* avg bit rate */
- put_be32(s, packet_max_size); /* max packet size */
- if (nb_packets > 0)
- packet_avg_size = packet_total_size / nb_packets;
- else
- packet_avg_size = 0;
- put_be32(s, packet_avg_size); /* avg packet size */
- put_be32(s, nb_packets); /* num packets */
- put_be32(s, duration); /* duration */
- put_be32(s, BUFFER_DURATION); /* preroll */
- put_be32(s, index_pos); /* index offset */
- /* computation of data the data offset */
- data_offset_ptr = s->buf_ptr;
- put_be32(s, 0); /* data offset : will be patched after */
- put_be16(s, ctx->nb_streams); /* num streams */
- flags = 1 | 2; /* save allowed & perfect play */
- if (url_is_streamed(s))
- flags |= 4; /* live broadcast */
- put_be16(s, flags);
-
- /* comments */
-
- put_tag(s,"CONT");
- size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) +
- strlen(ctx->comment) + 4 * 2 + 10;
- put_be32(s,size);
- put_be16(s,0);
- put_str(s, ctx->title);
- put_str(s, ctx->author);
- put_str(s, ctx->copyright);
- put_str(s, ctx->comment);
-
- for(i=0;i<ctx->nb_streams;i++) {
- int codec_data_size;
-
- stream = &rm->streams[i];
-
- if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
- desc = "The Audio Stream";
- mimetype = "audio/x-pn-realaudio";
- codec_data_size = 73;
- } else {
- desc = "The Video Stream";
- mimetype = "video/x-pn-realvideo";
- codec_data_size = 34;
- }
-
- put_tag(s,"MDPR");
- size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size;
- put_be32(s, size);
- put_be16(s, 0);
-
- put_be16(s, i); /* stream number */
- put_be32(s, stream->bit_rate); /* max bit rate */
- put_be32(s, stream->bit_rate); /* avg bit rate */
- put_be32(s, stream->packet_max_size); /* max packet size */
- if (stream->nb_packets > 0)
- packet_avg_size = stream->packet_total_size /
- stream->nb_packets;
- else
- packet_avg_size = 0;
- put_be32(s, packet_avg_size); /* avg packet size */
- put_be32(s, 0); /* start time */
- put_be32(s, BUFFER_DURATION); /* preroll */
- /* duration */
- if (url_is_streamed(s) || !stream->total_frames)
- put_be32(s, (int)(3600 * 1000));
- else
- put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate));
- put_str8(s, desc);
- put_str8(s, mimetype);
- put_be32(s, codec_data_size);
-
- if (stream->enc->codec_type == CODEC_TYPE_AUDIO) {
- int coded_frame_size, fscode, sample_rate;
- sample_rate = stream->enc->sample_rate;
- coded_frame_size = (stream->enc->bit_rate *
- stream->enc->frame_size) / (8 * sample_rate);
- /* audio codec info */
- put_tag(s, ".ra");
- put_byte(s, 0xfd);
- put_be32(s, 0x00040000); /* version */
- put_tag(s, ".ra4");
- put_be32(s, 0x01b53530); /* stream length */
- put_be16(s, 4); /* unknown */
- put_be32(s, 0x39); /* header size */
-
- switch(sample_rate) {
- case 48000:
- case 24000:
- case 12000:
- fscode = 1;
- break;
- default:
- case 44100:
- case 22050:
- case 11025:
- fscode = 2;
- break;
- case 32000:
- case 16000:
- case 8000:
- fscode = 3;
- }
- put_be16(s, fscode); /* codec additional info, for AC3, seems
- to be a frequency code */
- /* special hack to compensate rounding errors... */
- if (coded_frame_size == 557)
- coded_frame_size--;
- put_be32(s, coded_frame_size); /* frame length */
- put_be32(s, 0x51540); /* unknown */
- put_be32(s, 0x249f0); /* unknown */
- put_be32(s, 0x249f0); /* unknown */
- put_be16(s, 0x01);
- /* frame length : seems to be very important */
- put_be16(s, coded_frame_size);
- put_be32(s, 0); /* unknown */
- put_be16(s, stream->enc->sample_rate); /* sample rate */
- put_be32(s, 0x10); /* unknown */
- put_be16(s, stream->enc->channels);
- put_str8(s, "Int0"); /* codec name */
- put_str8(s, "dnet"); /* codec name */
- put_be16(s, 0); /* title length */
- put_be16(s, 0); /* author length */
- put_be16(s, 0); /* copyright length */
- put_byte(s, 0); /* end of header */
- } else {
- /* video codec info */
- put_be32(s,34); /* size */
- put_tag(s,"VIDORV10");
- put_be16(s, stream->enc->width);
- put_be16(s, stream->enc->height);
- put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */
- put_be32(s,0); /* unknown meaning */
- put_be16(s, (int) stream->frame_rate); /* unknown meaning */
- put_be32(s,0); /* unknown meaning */
- put_be16(s, 8); /* unknown meaning */
- /* Seems to be the codec version: only use basic H263. The next
- versions seems to add a diffential DC coding as in
- MPEG... nothing new under the sun */
- put_be32(s,0x10000000);
- //put_be32(s,0x10003000);
- }
- }
-
- /* patch data offset field */
- data_pos = s->buf_ptr - start_ptr;
- rm->data_pos = data_pos;
- data_offset_ptr[0] = data_pos >> 24;
- data_offset_ptr[1] = data_pos >> 16;
- data_offset_ptr[2] = data_pos >> 8;
- data_offset_ptr[3] = data_pos;
-
- /* data stream */
- put_tag(s,"DATA");
- put_be32(s,data_size + 10 + 8);
- put_be16(s,0);
-
- put_be32(s, nb_packets); /* number of packets */
- put_be32(s,0); /* next data header */
-}
-
-static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream,
- int length, int key_frame)
-{
- int timestamp;
- ByteIOContext *s = &ctx->pb;
-
- stream->nb_packets++;
- stream->packet_total_size += length;
- if (length > stream->packet_max_size)
- stream->packet_max_size = length;
-
- put_be16(s,0); /* version */
- put_be16(s,length + 12);
- put_be16(s, stream->num); /* stream number */
- timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate;
- put_be32(s, timestamp); /* timestamp */
- put_byte(s, 0); /* reserved */
- put_byte(s, key_frame ? 2 : 0); /* flags */
-}
-
-static int rm_write_header(AVFormatContext *s)
-{
- RMContext *rm = s->priv_data;
- StreamInfo *stream;
- int n;
- AVCodecContext *codec;
-
- for(n=0;n<s->nb_streams;n++) {
- s->streams[n]->id = n;
- codec = &s->streams[n]->codec;
- stream = &rm->streams[n];
- memset(stream, 0, sizeof(StreamInfo));
- stream->num = n;
- stream->bit_rate = codec->bit_rate;
- stream->enc = codec;
-
- switch(codec->codec_type) {
- case CODEC_TYPE_AUDIO:
- rm->audio_stream = stream;
- stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size;
- /* XXX: dummy values */
- stream->packet_max_size = 1024;
- stream->nb_packets = 0;
- stream->total_frames = stream->nb_packets;
- break;
- case CODEC_TYPE_VIDEO:
- rm->video_stream = stream;
- stream->frame_rate = (float)codec->frame_rate / (float)codec->frame_rate_base;
- /* XXX: dummy values */
- stream->packet_max_size = 4096;
- stream->nb_packets = 0;
- stream->total_frames = stream->nb_packets;
- break;
- default:
- av_abort();
- }
- }
-
- rv10_write_header(s, 0, 0);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size)
-{
- uint8_t *buf1;
- RMContext *rm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- StreamInfo *stream = rm->audio_stream;
- int i;
-
- /* XXX: suppress this malloc */
- buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) );
-
- write_packet_header(s, stream, size, stream->enc->coded_frame->key_frame);
-
- /* for AC3, the words seems to be reversed */
- for(i=0;i<size;i+=2) {
- buf1[i] = buf[i+1];
- buf1[i+1] = buf[i];
- }
- put_buffer(pb, buf1, size);
- put_flush_packet(pb);
- stream->nb_frames++;
- av_free(buf1);
- return 0;
-}
-
-static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size)
-{
- RMContext *rm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- StreamInfo *stream = rm->video_stream;
- int key_frame = stream->enc->coded_frame->key_frame;
-
- /* XXX: this is incorrect: should be a parameter */
-
- /* Well, I spent some time finding the meaning of these bits. I am
- not sure I understood everything, but it works !! */
-#if 1
- write_packet_header(s, stream, size + 7, key_frame);
- /* bit 7: '1' if final packet of a frame converted in several packets */
- put_byte(pb, 0x81);
- /* bit 7: '1' if I frame. bits 6..0 : sequence number in current
- frame starting from 1 */
- if (key_frame) {
- put_byte(pb, 0x81);
- } else {
- put_byte(pb, 0x01);
- }
- put_be16(pb, 0x4000 | (size)); /* total frame size */
- put_be16(pb, 0x4000 | (size)); /* offset from the start or the end */
-#else
- /* full frame */
- write_packet_header(s, size + 6);
- put_byte(pb, 0xc0);
- put_be16(pb, 0x4000 | size); /* total frame size */
- put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */
-#endif
- put_byte(pb, stream->nb_frames & 0xff);
-
- put_buffer(pb, buf, size);
- put_flush_packet(pb);
-
- stream->nb_frames++;
- return 0;
-}
-
-static int rm_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- if (s->streams[stream_index]->codec.codec_type ==
- CODEC_TYPE_AUDIO)
- return rm_write_audio(s, buf, size);
- else
- return rm_write_video(s, buf, size);
-}
-
-static int rm_write_trailer(AVFormatContext *s)
-{
- RMContext *rm = s->priv_data;
- int data_size, index_pos, i;
- ByteIOContext *pb = &s->pb;
-
- if (!url_is_streamed(&s->pb)) {
- /* end of file: finish to write header */
- index_pos = url_fseek(pb, 0, SEEK_CUR);
- data_size = index_pos - rm->data_pos;
-
- /* index */
- put_tag(pb, "INDX");
- put_be32(pb, 10 + 10 * s->nb_streams);
- put_be16(pb, 0);
-
- for(i=0;i<s->nb_streams;i++) {
- put_be32(pb, 0); /* zero indices */
- put_be16(pb, i); /* stream number */
- put_be32(pb, 0); /* next index */
- }
- /* undocumented end header */
- put_be32(pb, 0);
- put_be32(pb, 0);
-
- url_fseek(pb, 0, SEEK_SET);
- for(i=0;i<s->nb_streams;i++)
- rm->streams[i].total_frames = rm->streams[i].nb_frames;
- rv10_write_header(s, data_size, index_pos);
- } else {
- /* undocumented end header */
- put_be32(pb, 0);
- put_be32(pb, 0);
- }
- put_flush_packet(pb);
- return 0;
-}
-
-/***************************************************/
-
-static void get_str(ByteIOContext *pb, char *buf, int buf_size)
-{
- int len, i;
- char *q;
-
- len = get_be16(pb);
- q = buf;
- for(i=0;i<len;i++) {
- if (i < buf_size - 1)
- *q++ = get_byte(pb);
- }
- *q = '\0';
-}
-
-static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
-{
- int len, i;
- char *q;
-
- len = get_byte(pb);
- q = buf;
- for(i=0;i<len;i++) {
- if (i < buf_size - 1)
- *q++ = get_byte(pb);
- }
- *q = '\0';
-}
-
-static void rm_read_audio_stream_info(AVFormatContext *s, AVStream *st,
- int read_all)
-{
- ByteIOContext *pb = &s->pb;
- char buf[128];
- uint32_t version;
- int i;
-
- /* ra type header */
- version = get_be32(pb); /* version */
- if (((version >> 16) & 0xff) == 3) {
- /* very old version */
- for(i = 0; i < 14; i++)
- get_byte(pb);
- get_str8(pb, s->title, sizeof(s->title));
- get_str8(pb, s->author, sizeof(s->author));
- get_str8(pb, s->copyright, sizeof(s->copyright));
- get_str8(pb, s->comment, sizeof(s->comment));
- get_byte(pb);
- get_str8(pb, buf, sizeof(buf));
- st->codec.sample_rate = 8000;
- st->codec.channels = 1;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_RA_144;
- } else {
- /* old version (4) */
- get_be32(pb); /* .ra4 */
- get_be32(pb);
- get_be16(pb);
- get_be32(pb); /* header size */
- get_be16(pb); /* add codec info */
- get_be32(pb); /* coded frame size */
- get_be32(pb); /* ??? */
- get_be32(pb); /* ??? */
- get_be32(pb); /* ??? */
- get_be16(pb); /* 1 */
- get_be16(pb); /* coded frame size */
- get_be32(pb);
- st->codec.sample_rate = get_be16(pb);
- get_be32(pb);
- st->codec.channels = get_be16(pb);
- get_str8(pb, buf, sizeof(buf)); /* desc */
- get_str8(pb, buf, sizeof(buf)); /* desc */
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- if (!strcmp(buf, "dnet")) {
- st->codec.codec_id = CODEC_ID_AC3;
- } else {
- st->codec.codec_id = CODEC_ID_NONE;
- pstrcpy(st->codec.codec_name, sizeof(st->codec.codec_name),
- buf);
- }
- if (read_all) {
- get_byte(pb);
- get_byte(pb);
- get_byte(pb);
-
- get_str8(pb, s->title, sizeof(s->title));
- get_str8(pb, s->author, sizeof(s->author));
- get_str8(pb, s->copyright, sizeof(s->copyright));
- get_str8(pb, s->comment, sizeof(s->comment));
- }
- }
-}
-
-static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap)
-{
- RMContext *rm = s->priv_data;
- AVStream *st;
-
- rm->old_format = 1;
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
- rm_read_audio_stream_info(s, st, 1);
- return 0;
- fail:
- return -1;
-}
-
-static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- RMContext *rm = s->priv_data;
- AVStream *st;
- ByteIOContext *pb = &s->pb;
- unsigned int tag, v;
- int tag_size, size, codec_data_size, i;
- int64_t codec_pos;
- unsigned int h263_hack_version, start_time, duration;
- char buf[128];
- int flags = 0;
-
- tag = get_le32(pb);
- if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
- /* very old .ra format */
- return rm_read_header_old(s, ap);
- } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
- return -EIO;
- }
-
- get_be32(pb); /* header size */
- get_be16(pb);
- get_be32(pb);
- get_be32(pb); /* number of headers */
-
- for(;;) {
- if (url_feof(pb))
- goto fail;
- tag = get_le32(pb);
- tag_size = get_be32(pb);
- get_be16(pb);
-#if 0
- printf("tag=%c%c%c%c (%08x) size=%d\n",
- (tag) & 0xff,
- (tag >> 8) & 0xff,
- (tag >> 16) & 0xff,
- (tag >> 24) & 0xff,
- tag,
- tag_size);
-#endif
- if (tag_size < 10)
- goto fail;
- switch(tag) {
- case MKTAG('P', 'R', 'O', 'P'):
- /* file header */
- get_be32(pb); /* max bit rate */
- get_be32(pb); /* avg bit rate */
- get_be32(pb); /* max packet size */
- get_be32(pb); /* avg packet size */
- get_be32(pb); /* nb packets */
- get_be32(pb); /* duration */
- get_be32(pb); /* preroll */
- get_be32(pb); /* index offset */
- get_be32(pb); /* data offset */
- get_be16(pb); /* nb streams */
- flags = get_be16(pb); /* flags */
- break;
- case MKTAG('C', 'O', 'N', 'T'):
- get_str(pb, s->title, sizeof(s->title));
- get_str(pb, s->author, sizeof(s->author));
- get_str(pb, s->copyright, sizeof(s->copyright));
- get_str(pb, s->comment, sizeof(s->comment));
- break;
- case MKTAG('M', 'D', 'P', 'R'):
- st = av_new_stream(s, 0);
- if (!st)
- goto fail;
- st->id = get_be16(pb);
- get_be32(pb); /* max bit rate */
- st->codec.bit_rate = get_be32(pb); /* bit rate */
- get_be32(pb); /* max packet size */
- get_be32(pb); /* avg packet size */
- start_time = get_be32(pb); /* start time */
- get_be32(pb); /* preroll */
- duration = get_be32(pb); /* duration */
- st->start_time = start_time * (AV_TIME_BASE / 1000);
- st->duration = duration * (AV_TIME_BASE / 1000);
- get_str8(pb, buf, sizeof(buf)); /* desc */
- get_str8(pb, buf, sizeof(buf)); /* mimetype */
- codec_data_size = get_be32(pb);
- codec_pos = url_ftell(pb);
-
- v = get_be32(pb);
- if (v == MKTAG(0xfd, 'a', 'r', '.')) {
- /* ra type header */
- rm_read_audio_stream_info(s, st, 0);
- } else {
- if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
- fail1:
- fprintf(stderr, "Unsupported video codec\n");
- goto fail;
- }
- st->codec.codec_tag = get_le32(pb);
- if (st->codec.codec_tag != MKTAG('R', 'V', '1', '0'))
- goto fail1;
- st->codec.width = get_be16(pb);
- st->codec.height = get_be16(pb);
- st->codec.frame_rate_base= 1;
- st->codec.frame_rate = get_be16(pb) * st->codec.frame_rate_base;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- get_be32(pb);
- get_be16(pb);
- get_be32(pb);
- get_be16(pb);
- /* modification of h263 codec version (!) */
- h263_hack_version = get_be32(pb);
- switch(h263_hack_version) {
- case 0x10000000:
- case 0x10003000:
- case 0x10003001:
- st->codec.sub_id = h263_hack_version;
- st->codec.codec_id = CODEC_ID_RV10;
- break;
- default:
- /* not handled */
- st->codec.codec_id = CODEC_ID_NONE;
- break;
- }
- }
- /* skip codec info */
- size = url_ftell(pb) - codec_pos;
- url_fskip(pb, codec_data_size - size);
- break;
- case MKTAG('D', 'A', 'T', 'A'):
- goto header_end;
- default:
- /* unknown tag: skip it */
- url_fskip(pb, tag_size - 10);
- break;
- }
- }
- header_end:
- rm->nb_packets = get_be32(pb); /* number of packets */
- if (!rm->nb_packets && (flags & 4))
- rm->nb_packets = 3600 * 25;
- get_be32(pb); /* next data header */
- return 0;
-
- fail:
- for(i=0;i<s->nb_streams;i++) {
- av_free(s->streams[i]);
- }
- return -EIO;
-}
-
-static int get_num(ByteIOContext *pb, int *len)
-{
- int n, n1;
-
- n = get_be16(pb);
- (*len)-=2;
- if (n >= 0x4000) {
- return n - 0x4000;
- } else {
- n1 = get_be16(pb);
- (*len)-=2;
- return (n << 16) | n1;
- }
-}
-
-/* multiple of 20 bytes for ra144 (ugly) */
-#define RAW_PACKET_SIZE 1000
-
-static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- RMContext *rm = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVStream *st;
- int len, num, timestamp, i, tmp, j;
- uint8_t *ptr;
- int flags;
-
- if (rm->old_format) {
- /* just read raw bytes */
- len = RAW_PACKET_SIZE;
- av_new_packet(pkt, len);
- pkt->stream_index = 0;
- len = get_buffer(pb, pkt->data, len);
- if (len <= 0) {
- av_free_packet(pkt);
- return -EIO;
- }
- pkt->size = len;
- st = s->streams[0];
- } else {
- redo:
- if (rm->nb_packets == 0)
- return -EIO;
- get_be16(pb);
- len = get_be16(pb);
- if (len < 12)
- return -EIO;
- num = get_be16(pb);
- timestamp = get_be32(pb);
- get_byte(pb); /* reserved */
- flags = get_byte(pb); /* flags */
- rm->nb_packets--;
- len -= 12;
-
- st = NULL;
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- if (num == st->id)
- break;
- }
- if (i == s->nb_streams) {
- /* skip packet if unknown number */
- url_fskip(pb, len);
- goto redo;
- }
-
- if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
- int full_frame, h, pic_num;
-
- h= get_byte(pb);
- if ((h & 0xc0) == 0xc0) {
- int len2, pos;
- full_frame = 1;
- len2= get_num(pb, &len);
- pos = get_num(pb, &len);
- //printf("pos:%d\n",len);
- len -= 2;
- } else {
- int seq, frame_size, pos;
- full_frame = 0;
- seq = get_byte(pb);
- frame_size = get_num(pb, &len);
- pos = get_num(pb, &len);
- //printf("seq:%d, size:%d, pos:%d\n",seq,frame_size,pos);
- len -= 3;
- }
- /* picture number */
- pic_num= get_byte(pb);
-
- //XXX/FIXME/HACK, demuxer should be fixed to send complete frames ...
- if(st->codec.slice_offset==NULL)
- st->codec.slice_offset= (int*)av_malloc(sizeof(int));
- st->codec.slice_count= full_frame;
- st->codec.slice_offset[0]= 0;
- }
-
- av_new_packet(pkt, len);
- pkt->stream_index = i;
- get_buffer(pb, pkt->data, len);
- }
-
- /* for AC3, needs to swap bytes */
- if (st->codec.codec_id == CODEC_ID_AC3) {
- ptr = pkt->data;
- for(j=0;j<len;j+=2) {
- tmp = ptr[0];
- ptr[0] = ptr[1];
- ptr[1] = tmp;
- ptr += 2;
- }
- }
- return 0;
-}
-
-static int rm_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static int rm_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size <= 32)
- return 0;
- if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
- p->buf[2] == 'M' && p->buf[3] == 'F' &&
- p->buf[4] == 0 && p->buf[5] == 0) ||
- (p->buf[0] == '.' && p->buf[1] == 'r' &&
- p->buf[2] == 'a' && p->buf[3] == 0xfd))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static AVInputFormat rm_iformat = {
- "rm",
- "rm format",
- sizeof(RMContext),
- rm_probe,
- rm_read_header,
- rm_read_packet,
- rm_read_close,
-};
-
-static AVOutputFormat rm_oformat = {
- "rm",
- "rm format",
- "application/vnd.rn-realmedia",
- "rm,ra",
- sizeof(RMContext),
- CODEC_ID_AC3,
- CODEC_ID_RV10,
- rm_write_header,
- rm_write_packet,
- rm_write_trailer,
-};
-
-int rm_init(void)
-{
- av_register_input_format(&rm_iformat);
- av_register_output_format(&rm_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * RTP input/output format
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-
-//#define DEBUG
-
-
-/* TODO: - add RTCP statistics reporting (should be optional).
-
- - add support for h263/mpeg4 packetized output : IDEA: send a
- buffer to 'rtp_write_packet' contains all the packets for ONE
- frame. Each packet should have a four byte header containing
- the length in big endian format (same trick as
- 'url_open_dyn_packet_buf')
-*/
-
-#define RTP_VERSION 2
-
-#define RTP_MAX_SDES 256 /* maximum text length for SDES */
-
-/* RTCP paquets use 0.5 % of the bandwidth */
-#define RTCP_TX_RATIO_NUM 5
-#define RTCP_TX_RATIO_DEN 1000
-
-typedef enum {
- RTCP_SR = 200,
- RTCP_RR = 201,
- RTCP_SDES = 202,
- RTCP_BYE = 203,
- RTCP_APP = 204
-} rtcp_type_t;
-
-typedef enum {
- RTCP_SDES_END = 0,
- RTCP_SDES_CNAME = 1,
- RTCP_SDES_NAME = 2,
- RTCP_SDES_EMAIL = 3,
- RTCP_SDES_PHONE = 4,
- RTCP_SDES_LOC = 5,
- RTCP_SDES_TOOL = 6,
- RTCP_SDES_NOTE = 7,
- RTCP_SDES_PRIV = 8,
- RTCP_SDES_IMG = 9,
- RTCP_SDES_DOOR = 10,
- RTCP_SDES_SOURCE = 11
-} rtcp_sdes_type_t;
-
-enum RTPPayloadType {
- RTP_PT_ULAW = 0,
- RTP_PT_GSM = 3,
- RTP_PT_G723 = 4,
- RTP_PT_ALAW = 8,
- RTP_PT_S16BE_STEREO = 10,
- RTP_PT_S16BE_MONO = 11,
- RTP_PT_MPEGAUDIO = 14,
- RTP_PT_JPEG = 26,
- RTP_PT_H261 = 31,
- RTP_PT_MPEGVIDEO = 32,
- RTP_PT_MPEG2TS = 33,
- RTP_PT_H263 = 34, /* old H263 encapsulation */
- RTP_PT_PRIVATE = 96,
-};
-
-typedef struct RTPContext {
- int payload_type;
- uint32_t ssrc;
- uint16_t seq;
- uint32_t timestamp;
- uint32_t base_timestamp;
- uint32_t cur_timestamp;
- int max_payload_size;
- /* rtcp sender statistics receive */
- int64_t last_rtcp_ntp_time;
- int64_t first_rtcp_ntp_time;
- uint32_t last_rtcp_timestamp;
- /* rtcp sender statistics */
- unsigned int packet_count;
- unsigned int octet_count;
- unsigned int last_octet_count;
- int first_packet;
- /* buffer for output */
- uint8_t buf[RTP_MAX_PACKET_LENGTH];
- uint8_t *buf_ptr;
-} RTPContext;
-
-int rtp_get_codec_info(AVCodecContext *codec, int payload_type)
-{
- switch(payload_type) {
- case RTP_PT_ULAW:
- codec->codec_id = CODEC_ID_PCM_MULAW;
- codec->channels = 1;
- codec->sample_rate = 8000;
- break;
- case RTP_PT_ALAW:
- codec->codec_id = CODEC_ID_PCM_ALAW;
- codec->channels = 1;
- codec->sample_rate = 8000;
- break;
- case RTP_PT_S16BE_STEREO:
- codec->codec_id = CODEC_ID_PCM_S16BE;
- codec->channels = 2;
- codec->sample_rate = 44100;
- break;
- case RTP_PT_S16BE_MONO:
- codec->codec_id = CODEC_ID_PCM_S16BE;
- codec->channels = 1;
- codec->sample_rate = 44100;
- break;
- case RTP_PT_MPEGAUDIO:
- codec->codec_id = CODEC_ID_MP2;
- break;
- case RTP_PT_JPEG:
- codec->codec_id = CODEC_ID_MJPEG;
- break;
- case RTP_PT_MPEGVIDEO:
- codec->codec_id = CODEC_ID_MPEG1VIDEO;
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-/* return < 0 if unknown payload type */
-int rtp_get_payload_type(AVCodecContext *codec)
-{
- int payload_type;
-
- /* compute the payload type */
- payload_type = -1;
- switch(codec->codec_id) {
- case CODEC_ID_PCM_MULAW:
- payload_type = RTP_PT_ULAW;
- break;
- case CODEC_ID_PCM_ALAW:
- payload_type = RTP_PT_ALAW;
- break;
- case CODEC_ID_PCM_S16BE:
- if (codec->channels == 1) {
- payload_type = RTP_PT_S16BE_MONO;
- } else if (codec->channels == 2) {
- payload_type = RTP_PT_S16BE_STEREO;
- }
- break;
- case CODEC_ID_MP2:
- case CODEC_ID_MP3:
- payload_type = RTP_PT_MPEGAUDIO;
- break;
- case CODEC_ID_MJPEG:
- payload_type = RTP_PT_JPEG;
- break;
- case CODEC_ID_MPEG1VIDEO:
- payload_type = RTP_PT_MPEGVIDEO;
- break;
- default:
- break;
- }
- return payload_type;
-}
-
-static inline uint32_t decode_be32(const uint8_t *p)
-{
- return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
-}
-
-static inline uint64_t decode_be64(const uint8_t *p)
-{
- return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4);
-}
-
-static int rtcp_parse_packet(AVFormatContext *s1, const unsigned char *buf, int len)
-{
- RTPContext *s = s1->priv_data;
-
- if (buf[1] != 200)
- return -1;
- s->last_rtcp_ntp_time = decode_be64(buf + 8);
- if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE)
- s->first_rtcp_ntp_time = s->last_rtcp_ntp_time;
- s->last_rtcp_timestamp = decode_be32(buf + 16);
- return 0;
-}
-
-/**
- * Parse an RTP packet directly sent as raw data. Can only be used if
- * 'raw' is given as input file
- * @param s1 media file context
- * @param pkt returned packet
- * @param buf input buffer
- * @param len buffer len
- * @return zero if no error.
- */
-int rtp_parse_packet(AVFormatContext *s1, AVPacket *pkt,
- const unsigned char *buf, int len)
-{
- RTPContext *s = s1->priv_data;
- unsigned int ssrc, h;
- int payload_type, seq, delta_timestamp;
- AVStream *st;
- uint32_t timestamp;
-
- if (len < 12)
- return -1;
-
- if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
- return -1;
- if (buf[1] >= 200 && buf[1] <= 204) {
- rtcp_parse_packet(s1, buf, len);
- return -1;
- }
- payload_type = buf[1] & 0x7f;
- seq = (buf[2] << 8) | buf[3];
- timestamp = decode_be32(buf + 4);
- ssrc = decode_be32(buf + 8);
-
- if (s->payload_type < 0) {
- s->payload_type = payload_type;
-
- if (payload_type == RTP_PT_MPEG2TS) {
- /* XXX: special case : not a single codec but a whole stream */
- return -1;
- } else {
- st = av_new_stream(s1, 0);
- if (!st)
- return -1;
- rtp_get_codec_info(&st->codec, payload_type);
- }
- }
-
- /* NOTE: we can handle only one payload type */
- if (s->payload_type != payload_type)
- return -1;
-#if defined(DEBUG) || 1
- if (seq != ((s->seq + 1) & 0xffff)) {
- printf("RTP: PT=%02x: bad cseq %04x expected=%04x\n",
- payload_type, seq, ((s->seq + 1) & 0xffff));
- }
- s->seq = seq;
-#endif
- len -= 12;
- buf += 12;
- st = s1->streams[0];
- switch(st->codec.codec_id) {
- case CODEC_ID_MP2:
- /* better than nothing: skip mpeg audio RTP header */
- if (len <= 4)
- return -1;
- h = decode_be32(buf);
- len -= 4;
- buf += 4;
- av_new_packet(pkt, len);
- memcpy(pkt->data, buf, len);
- break;
- case CODEC_ID_MPEG1VIDEO:
- /* better than nothing: skip mpeg audio RTP header */
- if (len <= 4)
- return -1;
- h = decode_be32(buf);
- buf += 4;
- len -= 4;
- if (h & (1 << 26)) {
- /* mpeg2 */
- if (len <= 4)
- return -1;
- buf += 4;
- len -= 4;
- }
- av_new_packet(pkt, len);
- memcpy(pkt->data, buf, len);
- break;
- default:
- av_new_packet(pkt, len);
- memcpy(pkt->data, buf, len);
- break;
- }
-
- switch(st->codec.codec_id) {
- case CODEC_ID_MP2:
- case CODEC_ID_MPEG1VIDEO:
- if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
- int64_t addend;
- /* XXX: is it really necessary to unify the timestamp base ? */
- /* compute pts from timestamp with received ntp_time */
- delta_timestamp = timestamp - s->last_rtcp_timestamp;
- /* convert to 90 kHz without overflow */
- addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14;
- addend = (addend * 5625) >> 14;
- pkt->pts = addend + delta_timestamp;
- }
- break;
- default:
- /* no timestamp info yet */
- break;
- }
- return 0;
-}
-
-static int rtp_read_header(AVFormatContext *s1,
- AVFormatParameters *ap)
-{
- RTPContext *s = s1->priv_data;
- s->payload_type = -1;
- s->last_rtcp_ntp_time = AV_NOPTS_VALUE;
- s->first_rtcp_ntp_time = AV_NOPTS_VALUE;
- return 0;
-}
-
-static int rtp_read_packet(AVFormatContext *s1, AVPacket *pkt)
-{
- char buf[RTP_MAX_PACKET_LENGTH];
- int ret;
-
- /* XXX: needs a better API for packet handling ? */
- for(;;) {
- ret = url_read(url_fileno(&s1->pb), buf, sizeof(buf));
- if (ret < 0)
- return AVERROR_IO;
- if (rtp_parse_packet(s1, pkt, buf, ret) == 0)
- break;
- }
- return 0;
-}
-
-static int rtp_read_close(AVFormatContext *s1)
-{
- // RTPContext *s = s1->priv_data;
- return 0;
-}
-
-static int rtp_probe(AVProbeData *p)
-{
- if (strstart(p->filename, "rtp://", NULL))
- return AVPROBE_SCORE_MAX;
- return 0;
-}
-
-/* rtp output */
-
-static int rtp_write_header(AVFormatContext *s1)
-{
- RTPContext *s = s1->priv_data;
- int payload_type, max_packet_size;
- AVStream *st;
-
- if (s1->nb_streams != 1)
- return -1;
- st = s1->streams[0];
-
- payload_type = rtp_get_payload_type(&st->codec);
- if (payload_type < 0)
- payload_type = RTP_PT_PRIVATE; /* private payload type */
- s->payload_type = payload_type;
-
- s->base_timestamp = random();
- s->timestamp = s->base_timestamp;
- s->ssrc = random();
- s->first_packet = 1;
-
- max_packet_size = url_fget_max_packet_size(&s1->pb);
- if (max_packet_size <= 12)
- return AVERROR_IO;
- s->max_payload_size = max_packet_size - 12;
-
- switch(st->codec.codec_id) {
- case CODEC_ID_MP2:
- case CODEC_ID_MP3:
- s->buf_ptr = s->buf + 4;
- s->cur_timestamp = 0;
- break;
- case CODEC_ID_MPEG1VIDEO:
- s->cur_timestamp = 0;
- break;
- default:
- s->buf_ptr = s->buf;
- break;
- }
-
- return 0;
-}
-
-/* send an rtcp sender report packet */
-static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
-{
- RTPContext *s = s1->priv_data;
-#if defined(DEBUG)
- printf("RTCP: %02x %Lx %x\n", s->payload_type, ntp_time, s->timestamp);
-#endif
- put_byte(&s1->pb, (RTP_VERSION << 6));
- put_byte(&s1->pb, 200);
- put_be16(&s1->pb, 6); /* length in words - 1 */
- put_be32(&s1->pb, s->ssrc);
- put_be64(&s1->pb, ntp_time);
- put_be32(&s1->pb, s->timestamp);
- put_be32(&s1->pb, s->packet_count);
- put_be32(&s1->pb, s->octet_count);
- put_flush_packet(&s1->pb);
-}
-
-/* send an rtp packet. sequence number is incremented, but the caller
- must update the timestamp itself */
-static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len)
-{
- RTPContext *s = s1->priv_data;
-
-#ifdef DEBUG
- printf("rtp_send_data size=%d\n", len);
-#endif
-
- /* build the RTP header */
- put_byte(&s1->pb, (RTP_VERSION << 6));
- put_byte(&s1->pb, s->payload_type & 0x7f);
- put_be16(&s1->pb, s->seq);
- put_be32(&s1->pb, s->timestamp);
- put_be32(&s1->pb, s->ssrc);
-
- put_buffer(&s1->pb, buf1, len);
- put_flush_packet(&s1->pb);
-
- s->seq++;
- s->octet_count += len;
- s->packet_count++;
-}
-
-/* send an integer number of samples and compute time stamp and fill
- the rtp send buffer before sending. */
-static void rtp_send_samples(AVFormatContext *s1,
- const uint8_t *buf1, int size, int sample_size)
-{
- RTPContext *s = s1->priv_data;
- int len, max_packet_size, n;
-
- max_packet_size = (s->max_payload_size / sample_size) * sample_size;
- /* not needed, but who nows */
- if ((size % sample_size) != 0)
- av_abort();
- while (size > 0) {
- len = (max_packet_size - (s->buf_ptr - s->buf));
- if (len > size)
- len = size;
-
- /* copy data */
- memcpy(s->buf_ptr, buf1, len);
- s->buf_ptr += len;
- buf1 += len;
- size -= len;
- n = (s->buf_ptr - s->buf);
- /* if buffer full, then send it */
- if (n >= max_packet_size) {
- rtp_send_data(s1, s->buf, n);
- s->buf_ptr = s->buf;
- /* update timestamp */
- s->timestamp += n / sample_size;
- }
- }
-}
-
-/* NOTE: we suppose that exactly one frame is given as argument here */
-/* XXX: test it */
-static void rtp_send_mpegaudio(AVFormatContext *s1,
- const uint8_t *buf1, int size)
-{
- RTPContext *s = s1->priv_data;
- AVStream *st = s1->streams[0];
- int len, count, max_packet_size;
-
- max_packet_size = s->max_payload_size;
-
- /* test if we must flush because not enough space */
- len = (s->buf_ptr - s->buf);
- if ((len + size) > max_packet_size) {
- if (len > 4) {
- rtp_send_data(s1, s->buf, s->buf_ptr - s->buf);
- s->buf_ptr = s->buf + 4;
- /* 90 KHz time stamp */
- s->timestamp = s->base_timestamp +
- (s->cur_timestamp * 90000LL) / st->codec.sample_rate;
- }
- }
-
- /* add the packet */
- if (size > max_packet_size) {
- /* big packet: fragment */
- count = 0;
- while (size > 0) {
- len = max_packet_size - 4;
- if (len > size)
- len = size;
- /* build fragmented packet */
- s->buf[0] = 0;
- s->buf[1] = 0;
- s->buf[2] = count >> 8;
- s->buf[3] = count;
- memcpy(s->buf + 4, buf1, len);
- rtp_send_data(s1, s->buf, len + 4);
- size -= len;
- buf1 += len;
- count += len;
- }
- } else {
- if (s->buf_ptr == s->buf + 4) {
- /* no fragmentation possible */
- s->buf[0] = 0;
- s->buf[1] = 0;
- s->buf[2] = 0;
- s->buf[3] = 0;
- }
- memcpy(s->buf_ptr, buf1, size);
- s->buf_ptr += size;
- }
- s->cur_timestamp += st->codec.frame_size;
-}
-
-/* NOTE: a single frame must be passed with sequence header if
- needed. XXX: use slices. */
-static void rtp_send_mpegvideo(AVFormatContext *s1,
- const uint8_t *buf1, int size)
-{
- RTPContext *s = s1->priv_data;
- AVStream *st = s1->streams[0];
- int len, h, max_packet_size;
- uint8_t *q;
-
- max_packet_size = s->max_payload_size;
-
- while (size > 0) {
- /* XXX: more correct headers */
- h = 0;
- if (st->codec.sub_id == 2)
- h |= 1 << 26; /* mpeg 2 indicator */
- q = s->buf;
- *q++ = h >> 24;
- *q++ = h >> 16;
- *q++ = h >> 8;
- *q++ = h;
-
- if (st->codec.sub_id == 2) {
- h = 0;
- *q++ = h >> 24;
- *q++ = h >> 16;
- *q++ = h >> 8;
- *q++ = h;
- }
-
- len = max_packet_size - (q - s->buf);
- if (len > size)
- len = size;
-
- memcpy(q, buf1, len);
- q += len;
-
- /* 90 KHz time stamp */
- s->timestamp = s->base_timestamp +
- av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
- rtp_send_data(s1, s->buf, q - s->buf);
-
- buf1 += len;
- size -= len;
- }
- s->cur_timestamp++;
-}
-
-static void rtp_send_raw(AVFormatContext *s1,
- const uint8_t *buf1, int size)
-{
- RTPContext *s = s1->priv_data;
- AVStream *st = s1->streams[0];
- int len, max_packet_size;
-
- max_packet_size = s->max_payload_size;
-
- while (size > 0) {
- len = max_packet_size;
- if (len > size)
- len = size;
-
- /* 90 KHz time stamp */
- s->timestamp = s->base_timestamp +
- av_rescale((int64_t)s->cur_timestamp * st->codec.frame_rate_base, 90000, st->codec.frame_rate);
- rtp_send_data(s1, buf1, len);
-
- buf1 += len;
- size -= len;
- }
- s->cur_timestamp++;
-}
-
-/* write an RTP packet. 'buf1' must contain a single specific frame. */
-static int rtp_write_packet(AVFormatContext *s1, int stream_index,
- const uint8_t *buf1, int size, int64_t pts)
-{
- RTPContext *s = s1->priv_data;
- AVStream *st = s1->streams[0];
- int rtcp_bytes;
- int64_t ntp_time;
-
-#ifdef DEBUG
- printf("%d: write len=%d\n", stream_index, size);
-#endif
-
- /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */
- rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
- RTCP_TX_RATIO_DEN;
- if (s->first_packet || rtcp_bytes >= 28) {
- /* compute NTP time */
- /* XXX: 90 kHz timestamp hardcoded */
- ntp_time = (pts << 28) / 5625;
- rtcp_send_sr(s1, ntp_time);
- s->last_octet_count = s->octet_count;
- s->first_packet = 0;
- }
-
- switch(st->codec.codec_id) {
- case CODEC_ID_PCM_MULAW:
- case CODEC_ID_PCM_ALAW:
- case CODEC_ID_PCM_U8:
- case CODEC_ID_PCM_S8:
- rtp_send_samples(s1, buf1, size, 1 * st->codec.channels);
- break;
- case CODEC_ID_PCM_U16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_S16LE:
- rtp_send_samples(s1, buf1, size, 2 * st->codec.channels);
- break;
- case CODEC_ID_MP2:
- case CODEC_ID_MP3:
- rtp_send_mpegaudio(s1, buf1, size);
- break;
- case CODEC_ID_MPEG1VIDEO:
- rtp_send_mpegvideo(s1, buf1, size);
- break;
- default:
- /* better than nothing : send the codec raw data */
- rtp_send_raw(s1, buf1, size);
- break;
- }
- return 0;
-}
-
-static int rtp_write_trailer(AVFormatContext *s1)
-{
- // RTPContext *s = s1->priv_data;
- return 0;
-}
-
-AVInputFormat rtp_demux = {
- "rtp",
- "RTP input format",
- sizeof(RTPContext),
- rtp_probe,
- rtp_read_header,
- rtp_read_packet,
- rtp_read_close,
- .flags = AVFMT_NOHEADER,
-};
-
-AVOutputFormat rtp_mux = {
- "rtp",
- "RTP output format",
- NULL,
- NULL,
- sizeof(RTPContext),
- CODEC_ID_PCM_MULAW,
- CODEC_ID_NONE,
- rtp_write_header,
- rtp_write_packet,
- rtp_write_trailer,
-};
-
-int rtp_init(void)
-{
- av_register_output_format(&rtp_mux);
- av_register_input_format(&rtp_demux);
- return 0;
-}
+++ /dev/null
-/*
- * RTP definitions
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef RTP_H
-#define RTP_H
-
-#define RTP_MIN_PACKET_LENGTH 12
-#define RTP_MAX_PACKET_LENGTH 1500 /* XXX: suppress this define */
-
-int rtp_init(void);
-int rtp_get_codec_info(AVCodecContext *codec, int payload_type);
-int rtp_get_payload_type(AVCodecContext *codec);
-int rtp_parse_packet(AVFormatContext *s1, AVPacket *pkt,
- const unsigned char *buf, int len);
-
-extern AVOutputFormat rtp_mux;
-extern AVInputFormat rtp_demux;
-
-int rtp_get_local_port(URLContext *h);
-int rtp_set_remote_url(URLContext *h, const char *uri);
-void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd);
-
-extern URLProtocol rtp_protocol;
-
-#endif /* RTP_H */
+++ /dev/null
-/*
- * RTP network protocol
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include <unistd.h>
-#include <stdarg.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-#include <fcntl.h>
-
-#define RTP_TX_BUF_SIZE (64 * 1024)
-#define RTP_RX_BUF_SIZE (128 * 1024)
-
-typedef struct RTPContext {
- URLContext *rtp_hd, *rtcp_hd;
- int rtp_fd, rtcp_fd;
-} RTPContext;
-
-/**
- * If no filename is given to av_open_input_file because you want to
- * get the local port first, then you must call this function to set
- * the remote server address.
- *
- * @param s1 media file context
- * @param uri of the remote server
- * @return zero if no error.
- */
-int rtp_set_remote_url(URLContext *h, const char *uri)
-{
- RTPContext *s = h->priv_data;
- char hostname[256];
- int port;
-
- char buf[1024];
- char path[1024];
-
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- path, sizeof(path), uri);
-
- snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path);
- udp_set_remote_url(s->rtp_hd, buf);
-
- snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path);
- udp_set_remote_url(s->rtcp_hd, buf);
- return 0;
-}
-
-
-/* add option to url of the form:
- "http://host:port/path?option1=val1&option2=val2... */
-static void url_add_option(char *buf, int buf_size, const char *fmt, ...)
-{
- char buf1[1024];
- va_list ap;
-
- va_start(ap, fmt);
- if (strchr(buf, '?'))
- pstrcat(buf, buf_size, "&");
- else
- pstrcat(buf, buf_size, "?");
- vsnprintf(buf1, sizeof(buf1), fmt, ap);
- pstrcat(buf, buf_size, buf1);
- va_end(ap);
-}
-
-static void build_udp_url(char *buf, int buf_size,
- const char *hostname, int port,
- int local_port, int multicast, int ttl)
-{
- snprintf(buf, buf_size, "udp://%s:%d", hostname, port);
- if (local_port >= 0)
- url_add_option(buf, buf_size, "localport=%d", local_port);
- if (multicast)
- url_add_option(buf, buf_size, "multicast=1", multicast);
- if (ttl >= 0)
- url_add_option(buf, buf_size, "ttl=%d", ttl);
-}
-
-/*
- * url syntax: rtp://host:port[?option=val...]
- * option: 'multicast=1' : enable multicast
- * 'ttl=n' : set the ttl value (for multicast only)
- * 'localport=n' : set the local port to n
- *
- */
-static int rtp_open(URLContext *h, const char *uri, int flags)
-{
- RTPContext *s;
- int port, is_output, is_multicast, ttl, local_port;
- char hostname[256];
- char buf[1024];
- char path[1024];
- const char *p;
-
- is_output = (flags & URL_WRONLY);
-
- s = av_mallocz(sizeof(RTPContext));
- if (!s)
- return -ENOMEM;
- h->priv_data = s;
-
- url_split(NULL, 0, hostname, sizeof(hostname), &port,
- path, sizeof(path), uri);
- /* extract parameters */
- is_multicast = 0;
- ttl = -1;
- local_port = -1;
- p = strchr(uri, '?');
- if (p) {
- is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
- if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
- ttl = strtol(buf, NULL, 10);
- }
- if (find_info_tag(buf, sizeof(buf), "localport", p)) {
- local_port = strtol(buf, NULL, 10);
- }
- }
-
- build_udp_url(buf, sizeof(buf),
- hostname, port, local_port, is_multicast, ttl);
- if (url_open(&s->rtp_hd, buf, flags) < 0)
- goto fail;
- local_port = udp_get_local_port(s->rtp_hd);
- /* XXX: need to open another connexion if the port is not even */
-
- /* well, should suppress localport in path */
-
- build_udp_url(buf, sizeof(buf),
- hostname, port + 1, local_port + 1, is_multicast, ttl);
- if (url_open(&s->rtcp_hd, buf, flags) < 0)
- goto fail;
-
- /* just to ease handle access. XXX: need to suppress direct handle
- access */
- s->rtp_fd = udp_get_file_handle(s->rtp_hd);
- s->rtcp_fd = udp_get_file_handle(s->rtcp_hd);
-
- h->max_packet_size = url_get_max_packet_size(s->rtp_hd);
- h->is_streamed = 1;
- return 0;
-
- fail:
- if (s->rtp_hd)
- url_close(s->rtp_hd);
- if (s->rtcp_hd)
- url_close(s->rtcp_hd);
- av_free(s);
- return -EIO;
-}
-
-static int rtp_read(URLContext *h, uint8_t *buf, int size)
-{
- RTPContext *s = h->priv_data;
- struct sockaddr_in from;
- int from_len, len, fd_max, n;
- fd_set rfds;
-#if 0
- for(;;) {
- from_len = sizeof(from);
- len = recvfrom (s->rtp_fd, buf, size, 0,
- (struct sockaddr *)&from, &from_len);
- if (len < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- return -EIO;
- }
- break;
- }
-#else
- for(;;) {
- /* build fdset to listen to RTP and RTCP packets */
- FD_ZERO(&rfds);
- fd_max = s->rtp_fd;
- FD_SET(s->rtp_fd, &rfds);
- if (s->rtcp_fd > fd_max)
- fd_max = s->rtcp_fd;
- FD_SET(s->rtcp_fd, &rfds);
- n = select(fd_max + 1, &rfds, NULL, NULL, NULL);
- if (n > 0) {
- /* first try RTCP */
- if (FD_ISSET(s->rtcp_fd, &rfds)) {
- from_len = sizeof(from);
- len = recvfrom (s->rtcp_fd, buf, size, 0,
- (struct sockaddr *)&from, &from_len);
- if (len < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- return -EIO;
- }
- break;
- }
- /* then RTP */
- if (FD_ISSET(s->rtp_fd, &rfds)) {
- from_len = sizeof(from);
- len = recvfrom (s->rtp_fd, buf, size, 0,
- (struct sockaddr *)&from, &from_len);
- if (len < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- return -EIO;
- }
- break;
- }
- }
- }
-#endif
- return len;
-}
-
-static int rtp_write(URLContext *h, uint8_t *buf, int size)
-{
- RTPContext *s = h->priv_data;
- int ret;
- URLContext *hd;
-
- if (buf[1] >= 200 && buf[1] <= 204) {
- /* RTCP payload type */
- hd = s->rtcp_hd;
- } else {
- /* RTP payload type */
- hd = s->rtp_hd;
- }
-
- ret = url_write(hd, buf, size);
-#if 0
- {
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 10 * 1000000;
- nanosleep(&ts, NULL);
- }
-#endif
- return ret;
-}
-
-static int rtp_close(URLContext *h)
-{
- RTPContext *s = h->priv_data;
-
- url_close(s->rtp_hd);
- url_close(s->rtcp_hd);
- av_free(s);
- return 0;
-}
-
-/**
- * Return the local port used by the RTP connexion
- * @param s1 media file context
- * @return the local port number
- */
-int rtp_get_local_port(URLContext *h)
-{
- RTPContext *s = h->priv_data;
- return udp_get_local_port(s->rtp_hd);
-}
-
-/**
- * Return the rtp and rtcp file handles for select() usage to wait for several RTP
- * streams at the same time.
- * @param h media file context
- */
-void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd)
-{
- RTPContext *s = h->priv_data;
-
- *prtp_fd = s->rtp_fd;
- *prtcp_fd = s->rtcp_fd;
-}
-
-URLProtocol rtp_protocol = {
- "rtp",
- rtp_open,
- rtp_read,
- rtp_write,
- NULL, /* seek */
- rtp_close,
-};
+++ /dev/null
-/*
- * RTSP/SDP client
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#include <unistd.h> /* for select() prototype */
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-
-//#define DEBUG
-//#define DEBUG_RTP_TCP
-
-typedef struct RTSPState {
- URLContext *rtsp_hd; /* RTSP TCP connexion handle */
- /* XXX: currently we use unbuffered input */
- // ByteIOContext rtsp_gb;
- int seq; /* RTSP command sequence number */
- char session_id[512];
- enum RTSPProtocol protocol;
- char last_reply[2048]; /* XXX: allocate ? */
-} RTSPState;
-
-typedef struct RTSPStream {
- AVFormatContext *ic;
- int interleaved_min, interleaved_max; /* interleave ids, if TCP transport */
- char control_url[1024]; /* url for this stream (from SDP) */
-
- int sdp_port; /* port (from SDP content - not used in RTSP) */
- struct in_addr sdp_ip; /* IP address (from SDP content - not used in RTSP) */
- int sdp_ttl; /* IP TTL (from SDP content - not used in RTSP) */
- int sdp_payload_type; /* payload type - only used in SDP */
-} RTSPStream;
-
-/* XXX: currently, the only way to change the protocols consists in
- changing this variable */
-#if 1
-int rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP) | (1 << RTSP_PROTOCOL_RTP_UDP) | (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST);
-#else
-/* try it if a proxy is used */
-int rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP);
-#endif
-
-/* if non zero, then set a range for RTP ports */
-int rtsp_rtp_port_min = 0;
-int rtsp_rtp_port_max = 0;
-
-FFRTSPCallback *ff_rtsp_callback = NULL;
-
-static int rtsp_probe(AVProbeData *p)
-{
- if (strstart(p->filename, "rtsp:", NULL))
- return AVPROBE_SCORE_MAX;
- return 0;
-}
-
-static int redir_isspace(int c)
-{
- return (c == ' ' || c == '\t' || c == '\n' || c == '\r');
-}
-
-static void skip_spaces(const char **pp)
-{
- const char *p;
- p = *pp;
- while (redir_isspace(*p))
- p++;
- *pp = p;
-}
-
-static void get_word_sep(char *buf, int buf_size, const char *sep,
- const char **pp)
-{
- const char *p;
- char *q;
-
- p = *pp;
- skip_spaces(&p);
- q = buf;
- while (!strchr(sep, *p) && *p != '\0') {
- if ((q - buf) < buf_size - 1)
- *q++ = *p;
- p++;
- }
- if (buf_size > 0)
- *q = '\0';
- *pp = p;
-}
-
-static void get_word(char *buf, int buf_size, const char **pp)
-{
- const char *p;
- char *q;
-
- p = *pp;
- skip_spaces(&p);
- q = buf;
- while (!redir_isspace(*p) && *p != '\0') {
- if ((q - buf) < buf_size - 1)
- *q++ = *p;
- p++;
- }
- if (buf_size > 0)
- *q = '\0';
- *pp = p;
-}
-
-/* parse the rtpmap description: <codec_name>/<clock_rate>[/<other
- params>] */
-static int sdp_parse_rtpmap(AVCodecContext *codec, const char *p)
-{
- char buf[256];
-
- /* codec name */
- get_word_sep(buf, sizeof(buf), "/", &p);
- if (!strcmp(buf, "MP4V-ES")) {
- codec->codec_id = CODEC_ID_MPEG4;
- return 0;
- } else {
- return -1;
- }
-}
-
-/* return the length and optionnaly the data */
-static int hex_to_data(uint8_t *data, const char *p)
-{
- int c, len, v;
-
- len = 0;
- v = 1;
- for(;;) {
- skip_spaces(&p);
- if (p == '\0')
- break;
- c = toupper((unsigned char)*p++);
- if (c >= '0' && c <= '9')
- c = c - '0';
- else if (c >= 'A' && c <= 'F')
- c = c - 'A' + 10;
- else
- break;
- v = (v << 4) | c;
- if (v & 0x100) {
- if (data)
- data[len] = v;
- len++;
- v = 1;
- }
- }
- return len;
-}
-
-static void sdp_parse_fmtp(AVCodecContext *codec, const char *p)
-{
- char attr[256];
- char value[4096];
- int len;
-
- /* loop on each attribute */
- for(;;) {
- skip_spaces(&p);
- if (*p == '\0')
- break;
- get_word_sep(attr, sizeof(attr), "=", &p);
- if (*p == '=')
- p++;
- get_word_sep(value, sizeof(value), ";", &p);
- if (*p == ';')
- p++;
- /* handle MPEG4 video */
- switch(codec->codec_id) {
- case CODEC_ID_MPEG4:
- if (!strcmp(attr, "config")) {
- /* decode the hexa encoded parameter */
- len = hex_to_data(NULL, value);
- codec->extradata = av_mallocz(len);
- if (!codec->extradata)
- goto fail;
- codec->extradata_size = len;
- hex_to_data(codec->extradata, value);
- }
- break;
- default:
- /* ignore data for other codecs */
- break;
- }
- fail: ;
- // printf("'%s' = '%s'\n", attr, value);
- }
-}
-
-typedef struct SDPParseState {
- /* SDP only */
- struct in_addr default_ip;
- int default_ttl;
-} SDPParseState;
-
-static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
- int letter, const char *buf)
-{
- char buf1[64], st_type[64];
- const char *p;
- int codec_type, payload_type, i;
- AVStream *st;
- RTSPStream *rtsp_st;
- struct in_addr sdp_ip;
- int ttl;
-
-#ifdef DEBUG
- printf("sdp: %c='%s'\n", letter, buf);
-#endif
-
- p = buf;
- switch(letter) {
- case 'c':
- get_word(buf1, sizeof(buf1), &p);
- if (strcmp(buf1, "IN") != 0)
- return;
- get_word(buf1, sizeof(buf1), &p);
- if (strcmp(buf1, "IP4") != 0)
- return;
- get_word_sep(buf1, sizeof(buf1), "/", &p);
- if (inet_aton(buf1, &sdp_ip) == 0)
- return;
- ttl = 16;
- if (*p == '/') {
- p++;
- get_word_sep(buf1, sizeof(buf1), "/", &p);
- ttl = atoi(buf1);
- }
- if (s->nb_streams == 0) {
- s1->default_ip = sdp_ip;
- s1->default_ttl = ttl;
- } else {
- st = s->streams[s->nb_streams - 1];
- rtsp_st = st->priv_data;
- rtsp_st->sdp_ip = sdp_ip;
- rtsp_st->sdp_ttl = ttl;
- }
- break;
- case 's':
- pstrcpy(s->title, sizeof(s->title), p);
- break;
- case 'i':
- if (s->nb_streams == 0) {
- pstrcpy(s->comment, sizeof(s->comment), p);
- break;
- }
- break;
- case 'm':
- /* new stream */
- get_word(st_type, sizeof(st_type), &p);
- if (!strcmp(st_type, "audio")) {
- codec_type = CODEC_TYPE_AUDIO;
- } else if (!strcmp(st_type, "video")) {
- codec_type = CODEC_TYPE_VIDEO;
- } else {
- return;
- }
- rtsp_st = av_mallocz(sizeof(RTSPStream));
- if (!rtsp_st)
- return;
- st = av_new_stream(s, s->nb_streams);
- if (!st)
- return;
- st->priv_data = rtsp_st;
-
- rtsp_st->sdp_ip = s1->default_ip;
- rtsp_st->sdp_ttl = s1->default_ttl;
-
- st->codec.codec_type = codec_type;
-
- get_word(buf1, sizeof(buf1), &p); /* port */
- rtsp_st->sdp_port = atoi(buf1);
-
- get_word(buf1, sizeof(buf1), &p); /* protocol (ignored) */
-
- /* XXX: handle list of formats */
- get_word(buf1, sizeof(buf1), &p); /* format list */
- rtsp_st->sdp_payload_type = atoi(buf1);
- if (rtsp_st->sdp_payload_type < 96) {
- /* if standard payload type, we can find the codec right now */
- rtp_get_codec_info(&st->codec, rtsp_st->sdp_payload_type);
- }
-
- /* put a default control url */
- pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), s->filename);
- break;
- case 'a':
- if (strstart(p, "control:", &p) && s->nb_streams > 0) {
- char proto[32];
- /* get the control url */
- st = s->streams[s->nb_streams - 1];
- rtsp_st = st->priv_data;
-
- /* XXX: may need to add full url resolution */
- url_split(proto, sizeof(proto), NULL, 0, NULL, NULL, 0, p);
- if (proto[0] == '\0') {
- /* relative control URL */
- pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/");
- pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);
- } else {
- pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), p);
- }
- } else if (strstart(p, "rtpmap:", &p)) {
- /* NOTE: rtpmap is only supported AFTER the 'm=' tag */
- get_word(buf1, sizeof(buf1), &p);
- payload_type = atoi(buf1);
- for(i = 0; i < s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st->sdp_payload_type == payload_type) {
- sdp_parse_rtpmap(&st->codec, p);
- }
- }
- } else if (strstart(p, "fmtp:", &p)) {
- /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */
- get_word(buf1, sizeof(buf1), &p);
- payload_type = atoi(buf1);
- for(i = 0; i < s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st->sdp_payload_type == payload_type) {
- sdp_parse_fmtp(&st->codec, p);
- }
- }
- }
- break;
- }
-}
-
-static int sdp_parse(AVFormatContext *s, const char *content)
-{
- const char *p;
- int letter;
- char buf[1024], *q;
- SDPParseState sdp_parse_state, *s1 = &sdp_parse_state;
-
- memset(s1, 0, sizeof(SDPParseState));
- p = content;
- for(;;) {
- skip_spaces(&p);
- letter = *p;
- if (letter == '\0')
- break;
- p++;
- if (*p != '=')
- goto next_line;
- p++;
- /* get the content */
- q = buf;
- while (*p != '\n' && *p != '\r' && *p != '\0') {
- if ((q - buf) < sizeof(buf) - 1)
- *q++ = *p;
- p++;
- }
- *q = '\0';
- sdp_parse_line(s, s1, letter, buf);
- next_line:
- while (*p != '\n' && *p != '\0')
- p++;
- if (*p == '\n')
- p++;
- }
- return 0;
-}
-
-static void rtsp_parse_range(int *min_ptr, int *max_ptr, const char **pp)
-{
- const char *p;
- int v;
-
- p = *pp;
- skip_spaces(&p);
- v = strtol(p, (char **)&p, 10);
- if (*p == '-') {
- p++;
- *min_ptr = v;
- v = strtol(p, (char **)&p, 10);
- *max_ptr = v;
- } else {
- *min_ptr = v;
- *max_ptr = v;
- }
- *pp = p;
-}
-
-/* XXX: only one transport specification is parsed */
-static void rtsp_parse_transport(RTSPHeader *reply, const char *p)
-{
- char transport_protocol[16];
- char profile[16];
- char lower_transport[16];
- char parameter[16];
- RTSPTransportField *th;
- char buf[256];
-
- reply->nb_transports = 0;
-
- for(;;) {
- skip_spaces(&p);
- if (*p == '\0')
- break;
-
- th = &reply->transports[reply->nb_transports];
-
- get_word_sep(transport_protocol, sizeof(transport_protocol),
- "/", &p);
- if (*p == '/')
- p++;
- get_word_sep(profile, sizeof(profile), "/;,", &p);
- lower_transport[0] = '\0';
- if (*p == '/') {
- p++;
- get_word_sep(lower_transport, sizeof(lower_transport),
- ";,", &p);
- }
- if (!strcasecmp(lower_transport, "TCP"))
- th->protocol = RTSP_PROTOCOL_RTP_TCP;
- else
- th->protocol = RTSP_PROTOCOL_RTP_UDP;
-
- if (*p == ';')
- p++;
- /* get each parameter */
- while (*p != '\0' && *p != ',') {
- get_word_sep(parameter, sizeof(parameter), "=;,", &p);
- if (!strcmp(parameter, "port")) {
- if (*p == '=') {
- p++;
- rtsp_parse_range(&th->port_min, &th->port_max, &p);
- }
- } else if (!strcmp(parameter, "client_port")) {
- if (*p == '=') {
- p++;
- rtsp_parse_range(&th->client_port_min,
- &th->client_port_max, &p);
- }
- } else if (!strcmp(parameter, "server_port")) {
- if (*p == '=') {
- p++;
- rtsp_parse_range(&th->server_port_min,
- &th->server_port_max, &p);
- }
- } else if (!strcmp(parameter, "interleaved")) {
- if (*p == '=') {
- p++;
- rtsp_parse_range(&th->interleaved_min,
- &th->interleaved_max, &p);
- }
- } else if (!strcmp(parameter, "multicast")) {
- if (th->protocol == RTSP_PROTOCOL_RTP_UDP)
- th->protocol = RTSP_PROTOCOL_RTP_UDP_MULTICAST;
- } else if (!strcmp(parameter, "ttl")) {
- if (*p == '=') {
- p++;
- th->ttl = strtol(p, (char **)&p, 10);
- }
- } else if (!strcmp(parameter, "destination")) {
- struct in_addr ipaddr;
-
- if (*p == '=') {
- p++;
- get_word_sep(buf, sizeof(buf), ";,", &p);
- if (inet_aton(buf, &ipaddr))
- th->destination = ntohl(ipaddr.s_addr);
- }
- }
- while (*p != ';' && *p != '\0' && *p != ',')
- p++;
- if (*p == ';')
- p++;
- }
- if (*p == ',')
- p++;
-
- reply->nb_transports++;
- }
-}
-
-void rtsp_parse_line(RTSPHeader *reply, const char *buf)
-{
- const char *p;
-
- /* NOTE: we do case independent match for broken servers */
- p = buf;
- if (stristart(p, "Session:", &p)) {
- get_word_sep(reply->session_id, sizeof(reply->session_id), ";", &p);
- } else if (stristart(p, "Content-Length:", &p)) {
- reply->content_length = strtol(p, NULL, 10);
- } else if (stristart(p, "Transport:", &p)) {
- rtsp_parse_transport(reply, p);
- } else if (stristart(p, "CSeq:", &p)) {
- reply->seq = strtol(p, NULL, 10);
- }
-}
-
-/* skip a RTP/TCP interleaved packet */
-static void rtsp_skip_packet(AVFormatContext *s)
-{
- RTSPState *rt = s->priv_data;
- int ret, len, len1;
- uint8_t buf[1024];
-
- ret = url_read(rt->rtsp_hd, buf, 3);
- if (ret != 3)
- return;
- len = (buf[1] << 8) | buf[2];
-#ifdef DEBUG
- printf("skipping RTP packet len=%d\n", len);
-#endif
- /* skip payload */
- while (len > 0) {
- len1 = len;
- if (len1 > sizeof(buf))
- len1 = sizeof(buf);
- ret = url_read(rt->rtsp_hd, buf, len1);
- if (ret != len1)
- return;
- len -= len1;
- }
-}
-
-static void rtsp_send_cmd(AVFormatContext *s,
- const char *cmd, RTSPHeader *reply,
- unsigned char **content_ptr)
-{
- RTSPState *rt = s->priv_data;
- char buf[4096], buf1[1024], *q;
- unsigned char ch;
- const char *p;
- int content_length, line_count;
- unsigned char *content = NULL;
-
- memset(reply, 0, sizeof(RTSPHeader));
-
- rt->seq++;
- pstrcpy(buf, sizeof(buf), cmd);
- snprintf(buf1, sizeof(buf1), "CSeq: %d\r\n", rt->seq);
- pstrcat(buf, sizeof(buf), buf1);
- if (rt->session_id[0] != '\0' && !strstr(cmd, "\nIf-Match:")) {
- snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id);
- pstrcat(buf, sizeof(buf), buf1);
- }
- pstrcat(buf, sizeof(buf), "\r\n");
-#ifdef DEBUG
- printf("Sending:\n%s--\n", buf);
-#endif
- url_write(rt->rtsp_hd, buf, strlen(buf));
-
- /* parse reply (XXX: use buffers) */
- line_count = 0;
- rt->last_reply[0] = '\0';
- for(;;) {
- q = buf;
- for(;;) {
- if (url_read(rt->rtsp_hd, &ch, 1) != 1)
- break;
- if (ch == '\n')
- break;
- if (ch == '$') {
- /* XXX: only parse it if first char on line ? */
- rtsp_skip_packet(s);
- } else if (ch != '\r') {
- if ((q - buf) < sizeof(buf) - 1)
- *q++ = ch;
- }
- }
- *q = '\0';
-#ifdef DEBUG
- printf("line='%s'\n", buf);
-#endif
- /* test if last line */
- if (buf[0] == '\0')
- break;
- p = buf;
- if (line_count == 0) {
- /* get reply code */
- get_word(buf1, sizeof(buf1), &p);
- get_word(buf1, sizeof(buf1), &p);
- reply->status_code = atoi(buf1);
- } else {
- rtsp_parse_line(reply, p);
- pstrcat(rt->last_reply, sizeof(rt->last_reply), p);
- pstrcat(rt->last_reply, sizeof(rt->last_reply), "\n");
- }
- line_count++;
- }
-
- if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0')
- pstrcpy(rt->session_id, sizeof(rt->session_id), reply->session_id);
-
- content_length = reply->content_length;
- if (content_length > 0) {
- /* leave some room for a trailing '\0' (useful for simple parsing) */
- content = av_malloc(content_length + 1);
- url_read(rt->rtsp_hd, content, content_length);
- content[content_length] = '\0';
- }
- if (content_ptr)
- *content_ptr = content;
-}
-
-/* useful for modules: set RTSP callback function */
-
-void rtsp_set_callback(FFRTSPCallback *rtsp_cb)
-{
- ff_rtsp_callback = rtsp_cb;
-}
-
-
-static int rtsp_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- RTSPState *rt = s->priv_data;
- char host[1024], path[1024], tcpname[1024], cmd[2048];
- URLContext *rtsp_hd;
- int port, i, ret, err;
- RTSPHeader reply1, *reply = &reply1;
- unsigned char *content = NULL;
- AVStream *st;
- RTSPStream *rtsp_st;
- int protocol_mask;
-
- /* extract hostname and port */
- url_split(NULL, 0,
- host, sizeof(host), &port, path, sizeof(path), s->filename);
- if (port < 0)
- port = RTSP_DEFAULT_PORT;
-
- /* open the tcp connexion */
- snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port);
- if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0)
- return AVERROR_IO;
- rt->rtsp_hd = rtsp_hd;
- rt->seq = 0;
-
- /* describe the stream */
- snprintf(cmd, sizeof(cmd),
- "DESCRIBE %s RTSP/1.0\r\n"
- "Accept: application/sdp\r\n",
- s->filename);
- rtsp_send_cmd(s, cmd, reply, &content);
- if (!content) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- if (reply->status_code != RTSP_STATUS_OK) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-
- /* now we got the SDP description, we parse it */
- ret = sdp_parse(s, (const char *)content);
- av_freep(&content);
- if (ret < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-
- protocol_mask = rtsp_default_protocols;
-
- /* for each stream, make the setup request */
- /* XXX: we assume the same server is used for the control of each
- RTSP stream */
- for(i=0;i<s->nb_streams;i++) {
- char transport[2048];
- AVInputFormat *fmt;
-
- st = s->streams[i];
- rtsp_st = st->priv_data;
-
- /* compute available transports */
- transport[0] = '\0';
-
- /* RTP/UDP */
- if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP)) {
- char buf[256];
- int j;
-
- /* first try in specified port range */
- if (rtsp_rtp_port_min != 0) {
- for(j=rtsp_rtp_port_min;j<=rtsp_rtp_port_max;j++) {
- snprintf(buf, sizeof(buf), "rtp://?localport=%d", j);
- if (!av_open_input_file(&rtsp_st->ic, buf,
- &rtp_demux, 0, NULL))
- goto rtp_opened;
- }
- }
-
- /* then try on any port */
- if (av_open_input_file(&rtsp_st->ic, "rtp://",
- &rtp_demux, 0, NULL) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-
- rtp_opened:
- port = rtp_get_local_port(url_fileno(&rtsp_st->ic->pb));
- if (transport[0] != '\0')
- pstrcat(transport, sizeof(transport), ",");
- snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
- "RTP/AVP/UDP;unicast;client_port=%d-%d",
- port, port + 1);
- }
-
- /* RTP/TCP */
- if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_TCP)) {
- if (transport[0] != '\0')
- pstrcat(transport, sizeof(transport), ",");
- snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1,
- "RTP/AVP/TCP");
- }
-
- if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST)) {
- if (transport[0] != '\0')
- pstrcat(transport, sizeof(transport), ",");
- snprintf(transport + strlen(transport),
- sizeof(transport) - strlen(transport) - 1,
- "RTP/AVP/UDP;multicast");
- }
- snprintf(cmd, sizeof(cmd),
- "SETUP %s RTSP/1.0\r\n"
- "Transport: %s\r\n",
- rtsp_st->control_url, transport);
- rtsp_send_cmd(s, cmd, reply, NULL);
- if (reply->status_code != RTSP_STATUS_OK ||
- reply->nb_transports != 1) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-
- /* XXX: same protocol for all streams is required */
- if (i > 0) {
- if (reply->transports[0].protocol != rt->protocol) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- } else {
- rt->protocol = reply->transports[0].protocol;
- }
-
- /* close RTP connection if not choosen */
- if (reply->transports[0].protocol != RTSP_PROTOCOL_RTP_UDP &&
- (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP))) {
- av_close_input_file(rtsp_st->ic);
- rtsp_st->ic = NULL;
- }
-
- switch(reply->transports[0].protocol) {
- case RTSP_PROTOCOL_RTP_TCP:
- fmt = &rtp_demux;
- if (av_open_input_file(&rtsp_st->ic, "null", fmt, 0, NULL) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- rtsp_st->interleaved_min = reply->transports[0].interleaved_min;
- rtsp_st->interleaved_max = reply->transports[0].interleaved_max;
- break;
-
- case RTSP_PROTOCOL_RTP_UDP:
- {
- char url[1024];
-
- /* XXX: also use address if specified */
- snprintf(url, sizeof(url), "rtp://%s:%d",
- host, reply->transports[0].server_port_min);
- if (rtp_set_remote_url(url_fileno(&rtsp_st->ic->pb), url) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- }
- break;
- case RTSP_PROTOCOL_RTP_UDP_MULTICAST:
- {
- char url[1024];
- int ttl;
-
- fmt = &rtp_demux;
- ttl = reply->transports[0].ttl;
- if (!ttl)
- ttl = 16;
- snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d",
- host,
- reply->transports[0].server_port_min,
- ttl);
- if (av_open_input_file(&rtsp_st->ic, url, fmt, 0, NULL) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- }
- break;
- }
- }
-
- /* use callback if available to extend setup */
- if (ff_rtsp_callback) {
- if (ff_rtsp_callback(RTSP_ACTION_CLIENT_SETUP, rt->session_id,
- NULL, 0, rt->last_reply) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- }
-
- /* start playing */
- snprintf(cmd, sizeof(cmd),
- "PLAY %s RTSP/1.0\r\n"
- "Range: npt=0-\r\n",
- s->filename);
- rtsp_send_cmd(s, cmd, reply, NULL);
- if (reply->status_code != RTSP_STATUS_OK) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
-
-#if 0
- /* open TCP with bufferized input */
- if (rt->protocol == RTSP_PROTOCOL_RTP_TCP) {
- if (url_fdopen(&rt->rtsp_gb, rt->rtsp_hd) < 0) {
- err = AVERROR_NOMEM;
- goto fail;
- }
- }
-#endif
-
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st) {
- if (rtsp_st->ic)
- av_close_input_file(rtsp_st->ic);
- }
- av_free(rtsp_st);
- }
- av_freep(&content);
- url_close(rt->rtsp_hd);
- return err;
-}
-
-static int tcp_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- RTSPState *rt = s->priv_data;
- int id, len, i, ret;
- AVStream *st;
- RTSPStream *rtsp_st;
- uint8_t buf[RTP_MAX_PACKET_LENGTH];
-
-#ifdef DEBUG_RTP_TCP
- printf("tcp_read_packet:\n");
-#endif
- redo:
- for(;;) {
- ret = url_read(rt->rtsp_hd, buf, 1);
-#ifdef DEBUG_RTP_TCP
- printf("ret=%d c=%02x [%c]\n", ret, buf[0], buf[0]);
-#endif
- if (ret != 1)
- return AVERROR_IO;
- if (buf[0] == '$')
- break;
- }
- ret = url_read(rt->rtsp_hd, buf, 3);
- if (ret != 3)
- return AVERROR_IO;
- id = buf[0];
- len = (buf[1] << 8) | buf[2];
-#ifdef DEBUG_RTP_TCP
- printf("id=%d len=%d\n", id, len);
-#endif
- if (len > RTP_MAX_PACKET_LENGTH || len < 12)
- goto redo;
- /* get the data */
- ret = url_read(rt->rtsp_hd, buf, len);
- if (ret != len)
- return AVERROR_IO;
-
- /* find the matching stream */
- for(i = 0; i < s->nb_streams; i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (id >= rtsp_st->interleaved_min &&
- id <= rtsp_st->interleaved_max)
- goto found;
- }
- goto redo;
- found:
- ret = rtp_parse_packet(rtsp_st->ic, pkt, buf, len);
- if (ret < 0)
- goto redo;
- pkt->stream_index = i;
- return ret;
-}
-
-/* NOTE: output one packet at a time. May need to add a small fifo */
-static int udp_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- AVFormatContext *ic;
- AVStream *st;
- RTSPStream *rtsp_st;
- fd_set rfds;
- int fd1, fd2, fd_max, n, i, ret;
- char buf[RTP_MAX_PACKET_LENGTH];
- struct timeval tv;
-
- for(;;) {
- if (url_interrupt_cb())
- return -EIO;
- FD_ZERO(&rfds);
- fd_max = -1;
- for(i = 0; i < s->nb_streams; i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- ic = rtsp_st->ic;
- /* currently, we cannot probe RTCP handle because of blocking restrictions */
- rtp_get_file_handles(url_fileno(&ic->pb), &fd1, &fd2);
- if (fd1 > fd_max)
- fd_max = fd1;
- FD_SET(fd1, &rfds);
- }
- /* XXX: also add proper API to abort */
- tv.tv_sec = 0;
- tv.tv_usec = 100 * 1000;
- n = select(fd_max + 1, &rfds, NULL, NULL, &tv);
- if (n > 0) {
- for(i = 0; i < s->nb_streams; i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- ic = rtsp_st->ic;
- rtp_get_file_handles(url_fileno(&ic->pb), &fd1, &fd2);
- if (FD_ISSET(fd1, &rfds)) {
- ret = url_read(url_fileno(&ic->pb), buf, sizeof(buf));
- if (ret >= 0 &&
- rtp_parse_packet(ic, pkt, buf, ret) == 0) {
- pkt->stream_index = i;
- return ret;
- }
- }
- }
- }
- }
-}
-
-static int rtsp_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- RTSPState *rt = s->priv_data;
- int ret;
-
- switch(rt->protocol) {
- default:
- case RTSP_PROTOCOL_RTP_TCP:
- ret = tcp_read_packet(s, pkt);
- break;
- case RTSP_PROTOCOL_RTP_UDP:
- ret = udp_read_packet(s, pkt);
- break;
- }
- return ret;
-}
-
-/* pause the stream */
-int rtsp_pause(AVFormatContext *s)
-{
- RTSPState *rt;
- RTSPHeader reply1, *reply = &reply1;
- char cmd[1024];
-
- if (s->iformat != &rtsp_demux)
- return -1;
-
- rt = s->priv_data;
-
- snprintf(cmd, sizeof(cmd),
- "PAUSE %s RTSP/1.0\r\n",
- s->filename);
- rtsp_send_cmd(s, cmd, reply, NULL);
- if (reply->status_code != RTSP_STATUS_OK) {
- return -1;
- } else {
- return 0;
- }
-}
-
-/* resume the stream */
-int rtsp_resume(AVFormatContext *s)
-{
- RTSPState *rt;
- RTSPHeader reply1, *reply = &reply1;
- char cmd[1024];
-
- if (s->iformat != &rtsp_demux)
- return -1;
-
- rt = s->priv_data;
-
- snprintf(cmd, sizeof(cmd),
- "PLAY %s RTSP/1.0\r\n",
- s->filename);
- rtsp_send_cmd(s, cmd, reply, NULL);
- if (reply->status_code != RTSP_STATUS_OK) {
- return -1;
- } else {
- return 0;
- }
-}
-
-static int rtsp_read_close(AVFormatContext *s)
-{
- RTSPState *rt = s->priv_data;
- AVStream *st;
- RTSPStream *rtsp_st;
- RTSPHeader reply1, *reply = &reply1;
- int i;
- char cmd[1024];
-
-#if 0
- /* NOTE: it is valid to flush the buffer here */
- if (rt->protocol == RTSP_PROTOCOL_RTP_TCP) {
- url_fclose(&rt->rtsp_gb);
- }
-#endif
- snprintf(cmd, sizeof(cmd),
- "TEARDOWN %s RTSP/1.0\r\n",
- s->filename);
- rtsp_send_cmd(s, cmd, reply, NULL);
-
- if (ff_rtsp_callback) {
- ff_rtsp_callback(RTSP_ACTION_CLIENT_TEARDOWN, rt->session_id,
- NULL, 0, NULL);
- }
-
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st) {
- if (rtsp_st->ic)
- av_close_input_file(rtsp_st->ic);
- }
- av_free(rtsp_st);
- }
- url_close(rt->rtsp_hd);
- return 0;
-}
-
-AVInputFormat rtsp_demux = {
- "rtsp",
- "RTSP input format",
- sizeof(RTSPState),
- rtsp_probe,
- rtsp_read_header,
- rtsp_read_packet,
- rtsp_read_close,
- .flags = AVFMT_NOFILE,
-};
-
-static int sdp_probe(AVProbeData *p1)
-{
- const char *p;
-
- /* we look for a line beginning "c=IN IP4" */
- p = p1->buf;
- while (*p != '\0') {
- if (strstart(p, "c=IN IP4", NULL))
- return AVPROBE_SCORE_MAX / 2;
- p = strchr(p, '\n');
- if (!p)
- break;
- p++;
- if (*p == '\r')
- p++;
- }
- return 0;
-}
-
-#define SDP_MAX_SIZE 8192
-
-static int sdp_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- AVStream *st;
- RTSPStream *rtsp_st;
- int size, i, err;
- char *content;
- char url[1024];
-
- /* read the whole sdp file */
- /* XXX: better loading */
- content = av_malloc(SDP_MAX_SIZE);
- size = get_buffer(&s->pb, content, SDP_MAX_SIZE - 1);
- if (size <= 0) {
- av_free(content);
- return AVERROR_INVALIDDATA;
- }
- content[size] ='\0';
-
- sdp_parse(s, content);
- av_free(content);
-
- /* open each RTP stream */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
-
- snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d",
- inet_ntoa(rtsp_st->sdp_ip),
- rtsp_st->sdp_port,
- rtsp_st->sdp_ttl);
- if (av_open_input_file(&rtsp_st->ic, url, &rtp_demux, 0, NULL) < 0) {
- err = AVERROR_INVALIDDATA;
- goto fail;
- }
- }
- return 0;
- fail:
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st) {
- if (rtsp_st->ic)
- av_close_input_file(rtsp_st->ic);
- }
- av_free(rtsp_st);
- }
- return err;
-}
-
-static int sdp_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- return udp_read_packet(s, pkt);
-}
-
-static int sdp_read_close(AVFormatContext *s)
-{
- AVStream *st;
- RTSPStream *rtsp_st;
- int i;
-
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
- rtsp_st = st->priv_data;
- if (rtsp_st) {
- if (rtsp_st->ic)
- av_close_input_file(rtsp_st->ic);
- }
- av_free(rtsp_st);
- }
- return 0;
-}
-
-
-static AVInputFormat sdp_demux = {
- "sdp",
- "SDP",
- sizeof(RTSPState),
- sdp_probe,
- sdp_read_header,
- sdp_read_packet,
- sdp_read_close,
-};
-
-
-/* dummy redirector format (used directly in av_open_input_file now) */
-static int redir_probe(AVProbeData *pd)
-{
- const char *p;
- p = pd->buf;
- while (redir_isspace(*p))
- p++;
- if (strstart(p, "http://", NULL) ||
- strstart(p, "rtsp://", NULL))
- return AVPROBE_SCORE_MAX;
- return 0;
-}
-
-/* called from utils.c */
-int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f)
-{
- char buf[4096], *q;
- int c;
- AVFormatContext *ic = NULL;
-
- /* parse each URL and try to open it */
- c = url_fgetc(f);
- while (c != URL_EOF) {
- /* skip spaces */
- for(;;) {
- if (!redir_isspace(c))
- break;
- c = url_fgetc(f);
- }
- if (c == URL_EOF)
- break;
- /* record url */
- q = buf;
- for(;;) {
- if (c == URL_EOF || redir_isspace(c))
- break;
- if ((q - buf) < sizeof(buf) - 1)
- *q++ = c;
- c = url_fgetc(f);
- }
- *q = '\0';
- //printf("URL='%s'\n", buf);
- /* try to open the media file */
- if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0)
- break;
- }
- *ic_ptr = ic;
- if (!ic)
- return AVERROR_IO;
- else
- return 0;
-}
-
-AVInputFormat redir_demux = {
- "redir",
- "Redirector format",
- 0,
- redir_probe,
- NULL,
- NULL,
- NULL,
-};
-
-int rtsp_init(void)
-{
- av_register_input_format(&rtsp_demux);
- av_register_input_format(&redir_demux);
- av_register_input_format(&sdp_demux);
- return 0;
-}
+++ /dev/null
-/*
- * RTSP definitions
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef RTSP_H
-#define RTSP_H
-
-/* RTSP handling */
-enum RTSPStatusCode {
-#define DEF(n, c, s) c = n,
-#include "rtspcodes.h"
-#undef DEF
- USELESSCRAZYTHINGTOFIXCOMPILEERRORTHATNOONEWILLEVERUSE
-};
-
-enum RTSPProtocol {
- RTSP_PROTOCOL_RTP_UDP = 0,
- RTSP_PROTOCOL_RTP_TCP = 1,
- RTSP_PROTOCOL_RTP_UDP_MULTICAST = 2
-};
-
-#define RTSP_DEFAULT_PORT 554
-#define RTSP_MAX_TRANSPORTS 8
-#define RTSP_TCP_MAX_PACKET_SIZE 1472
-
-typedef struct RTSPTransportField {
- int interleaved_min, interleaved_max; /* interleave ids, if TCP transport */
- int port_min, port_max; /* RTP ports */
- int client_port_min, client_port_max; /* RTP ports */
- int server_port_min, server_port_max; /* RTP ports */
- int ttl; /* ttl value */
- uint32_t destination; /* destination IP address */
- enum RTSPProtocol protocol;
-} RTSPTransportField;
-
-typedef struct RTSPHeader {
- int content_length;
- enum RTSPStatusCode status_code; /* response code from server */
- int nb_transports;
- RTSPTransportField transports[RTSP_MAX_TRANSPORTS];
- int seq; /* sequence number */
- char session_id[512];
-} RTSPHeader;
-
-/* the callback can be used to extend the connection setup/teardown step */
-enum RTSPCallbackAction {
- RTSP_ACTION_SERVER_SETUP,
- RTSP_ACTION_SERVER_TEARDOWN,
- RTSP_ACTION_CLIENT_SETUP,
- RTSP_ACTION_CLIENT_TEARDOWN
-};
-
-typedef struct RTSPActionServerSetup {
- uint32_t ipaddr;
- char transport_option[512];
-} RTSPActionServerSetup;
-
-typedef int FFRTSPCallback(enum RTSPCallbackAction action,
- const char *session_id,
- char *buf, int buf_size,
- void *arg);
-
-void rtsp_set_callback(FFRTSPCallback *rtsp_cb);
-
-int rtsp_init(void);
-void rtsp_parse_line(RTSPHeader *reply, const char *buf);
-
-extern int rtsp_default_protocols;
-extern int rtsp_rtp_port_min;
-extern int rtsp_rtp_port_max;
-extern FFRTSPCallback *ff_rtsp_callback;
-extern AVInputFormat rtsp_demux;
-
-int rtsp_pause(AVFormatContext *s);
-int rtsp_resume(AVFormatContext *s);
-
-#endif /* RTSP_H */
+++ /dev/null
-DEF(200, RTSP_STATUS_OK, "OK")
-DEF(405, RTSP_STATUS_METHOD, "Method Not Allowed")
-DEF(453, RTSP_STATUS_BANDWIDTH, "Not Enough Bandwidth")
-DEF(454, RTSP_STATUS_SESSION, "Session Not Found")
-DEF(455, RTSP_STATUS_STATE, "Method Not Valid in This State")
-DEF(459, RTSP_STATUS_AGGREGATE, "Aggregate operation not allowed")
-DEF(460, RTSP_STATUS_ONLY_AGGREGATE, "Only aggregate operation allowed")
-DEF(461, RTSP_STATUS_TRANSPORT, "Unsupported transport")
-DEF(500, RTSP_STATUS_INTERNAL, "Internal Server Error")
-DEF(503, RTSP_STATUS_SERVICE, "Service Unavailable")
-DEF(505, RTSP_STATUS_VERSION, "RTSP Version not supported")
+++ /dev/null
-/*
- * Flash Compatible Streaming Format
- * Copyright (c) 2000 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-/* should have a generic way to indicate probable size */
-#define DUMMY_FILE_SIZE (100 * 1024 * 1024)
-#define DUMMY_DURATION 600 /* in seconds */
-
-#define TAG_END 0
-#define TAG_SHOWFRAME 1
-#define TAG_DEFINESHAPE 2
-#define TAG_FREECHARACTER 3
-#define TAG_PLACEOBJECT 4
-#define TAG_REMOVEOBJECT 5
-#define TAG_STREAMHEAD 18
-#define TAG_STREAMBLOCK 19
-#define TAG_JPEG2 21
-
-#define TAG_LONG 0x100
-
-/* flags for shape definition */
-#define FLAG_MOVETO 0x01
-#define FLAG_SETFILL0 0x02
-#define FLAG_SETFILL1 0x04
-
-/* character id used */
-#define BITMAP_ID 0
-#define SHAPE_ID 1
-
-typedef struct {
- offset_t duration_pos;
- offset_t tag_pos;
- int tag;
-} SWFContext;
-
-static void put_swf_tag(AVFormatContext *s, int tag)
-{
- SWFContext *swf = s->priv_data;
- ByteIOContext *pb = &s->pb;
-
- swf->tag_pos = url_ftell(pb);
- swf->tag = tag;
- /* reserve some room for the tag */
- if (tag & TAG_LONG) {
- put_le16(pb, 0);
- put_le32(pb, 0);
- } else {
- put_le16(pb, 0);
- }
-}
-
-static void put_swf_end_tag(AVFormatContext *s)
-{
- SWFContext *swf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- offset_t pos;
- int tag_len, tag;
-
- pos = url_ftell(pb);
- tag_len = pos - swf->tag_pos - 2;
- tag = swf->tag;
- url_fseek(pb, swf->tag_pos, SEEK_SET);
- if (tag & TAG_LONG) {
- tag &= ~TAG_LONG;
- put_le16(pb, (tag << 6) | 0x3f);
- put_le32(pb, tag_len - 4);
- } else {
- assert(tag_len < 0x3f);
- put_le16(pb, (tag << 6) | tag_len);
- }
- url_fseek(pb, pos, SEEK_SET);
-}
-
-static inline void max_nbits(int *nbits_ptr, int val)
-{
- int n;
-
- if (val == 0)
- return;
- val = abs(val);
- n = 1;
- while (val != 0) {
- n++;
- val >>= 1;
- }
- if (n > *nbits_ptr)
- *nbits_ptr = n;
-}
-
-static void put_swf_rect(ByteIOContext *pb,
- int xmin, int xmax, int ymin, int ymax)
-{
- PutBitContext p;
- uint8_t buf[256];
- int nbits, mask;
-
- init_put_bits(&p, buf, sizeof(buf), NULL, NULL);
-
- nbits = 0;
- max_nbits(&nbits, xmin);
- max_nbits(&nbits, xmax);
- max_nbits(&nbits, ymin);
- max_nbits(&nbits, ymax);
- mask = (1 << nbits) - 1;
-
- /* rectangle info */
- put_bits(&p, 5, nbits);
- put_bits(&p, nbits, xmin & mask);
- put_bits(&p, nbits, xmax & mask);
- put_bits(&p, nbits, ymin & mask);
- put_bits(&p, nbits, ymax & mask);
-
- flush_put_bits(&p);
- put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
-}
-
-static void put_swf_line_edge(PutBitContext *pb, int dx, int dy)
-{
- int nbits, mask;
-
- put_bits(pb, 1, 1); /* edge */
- put_bits(pb, 1, 1); /* line select */
- nbits = 2;
- max_nbits(&nbits, dx);
- max_nbits(&nbits, dy);
-
- mask = (1 << nbits) - 1;
- put_bits(pb, 4, nbits - 2); /* 16 bits precision */
- if (dx == 0) {
- put_bits(pb, 1, 0);
- put_bits(pb, 1, 1);
- put_bits(pb, nbits, dy & mask);
- } else if (dy == 0) {
- put_bits(pb, 1, 0);
- put_bits(pb, 1, 0);
- put_bits(pb, nbits, dx & mask);
- } else {
- put_bits(pb, 1, 1);
- put_bits(pb, nbits, dx & mask);
- put_bits(pb, nbits, dy & mask);
- }
-}
-
-#define FRAC_BITS 16
-
-/* put matrix (not size optimized */
-static void put_swf_matrix(ByteIOContext *pb,
- int a, int b, int c, int d, int tx, int ty)
-{
- PutBitContext p;
- uint8_t buf[256];
-
- init_put_bits(&p, buf, sizeof(buf), NULL, NULL);
-
- put_bits(&p, 1, 1); /* a, d present */
- put_bits(&p, 5, 20); /* nb bits */
- put_bits(&p, 20, a);
- put_bits(&p, 20, d);
-
- put_bits(&p, 1, 1); /* b, c present */
- put_bits(&p, 5, 20); /* nb bits */
- put_bits(&p, 20, c);
- put_bits(&p, 20, b);
-
- put_bits(&p, 5, 20); /* nb bits */
- put_bits(&p, 20, tx);
- put_bits(&p, 20, ty);
-
- flush_put_bits(&p);
- put_buffer(pb, buf, pbBufPtr(&p) - p.buf);
-}
-
-/* XXX: handle audio only */
-static int swf_write_header(AVFormatContext *s)
-{
- SWFContext *swf;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc, *audio_enc, *video_enc;
- PutBitContext p;
- uint8_t buf1[256];
- int i, width, height, rate, rate_base;
-
- swf = av_malloc(sizeof(SWFContext));
- if (!swf)
- return -1;
- s->priv_data = swf;
-
- video_enc = NULL;
- audio_enc = NULL;
- for(i=0;i<s->nb_streams;i++) {
- enc = &s->streams[i]->codec;
- if (enc->codec_type == CODEC_TYPE_AUDIO)
- audio_enc = enc;
- else
- video_enc = enc;
- }
-
- if (!video_enc) {
- /* currenty, cannot work correctly if audio only */
- width = 320;
- height = 200;
- rate = 10;
- rate_base= 1;
- } else {
- width = video_enc->width;
- height = video_enc->height;
- rate = video_enc->frame_rate;
- rate_base = video_enc->frame_rate_base;
- }
-
- put_tag(pb, "FWS");
- put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */
- put_le32(pb, DUMMY_FILE_SIZE); /* dummy size
- (will be patched if not streamed) */
-
- put_swf_rect(pb, 0, width, 0, height);
- put_le16(pb, (rate * 256) / rate_base); /* frame rate */
- swf->duration_pos = url_ftell(pb);
- put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */
-
- /* define a shape with the jpeg inside */
-
- put_swf_tag(s, TAG_DEFINESHAPE);
-
- put_le16(pb, SHAPE_ID); /* ID of shape */
- /* bounding rectangle */
- put_swf_rect(pb, 0, width, 0, height);
- /* style info */
- put_byte(pb, 1); /* one fill style */
- put_byte(pb, 0x41); /* clipped bitmap fill */
- put_le16(pb, BITMAP_ID); /* bitmap ID */
- /* position of the bitmap */
- put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0,
- 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0);
- put_byte(pb, 0); /* no line style */
-
- /* shape drawing */
- init_put_bits(&p, buf1, sizeof(buf1), NULL, NULL);
- put_bits(&p, 4, 1); /* one fill bit */
- put_bits(&p, 4, 0); /* zero line bit */
-
- put_bits(&p, 1, 0); /* not an edge */
- put_bits(&p, 5, FLAG_MOVETO | FLAG_SETFILL0);
- put_bits(&p, 5, 1); /* nbits */
- put_bits(&p, 1, 0); /* X */
- put_bits(&p, 1, 0); /* Y */
- put_bits(&p, 1, 1); /* set fill style 1 */
-
- /* draw the rectangle ! */
- put_swf_line_edge(&p, width, 0);
- put_swf_line_edge(&p, 0, height);
- put_swf_line_edge(&p, -width, 0);
- put_swf_line_edge(&p, 0, -height);
-
- /* end of shape */
- put_bits(&p, 1, 0); /* not an edge */
- put_bits(&p, 5, 0);
-
- flush_put_bits(&p);
- put_buffer(pb, buf1, pbBufPtr(&p) - p.buf);
-
- put_swf_end_tag(s);
-
-
- if (audio_enc) {
- int v;
-
- /* start sound */
-
- v = 0;
- switch(audio_enc->sample_rate) {
- case 11025:
- v |= 1 << 2;
- break;
- case 22050:
- v |= 2 << 2;
- break;
- case 44100:
- v |= 3 << 2;
- break;
- default:
- /* not supported */
- av_free(swf);
- return -1;
- }
- if (audio_enc->channels == 2)
- v |= 1;
- v |= 0x20; /* mp3 compressed */
- v |= 0x02; /* 16 bits */
-
- put_swf_tag(s, TAG_STREAMHEAD);
- put_byte(&s->pb, 0);
- put_byte(&s->pb, v);
- put_le16(&s->pb, (audio_enc->sample_rate * rate_base) / rate); /* avg samples per frame */
-
-
- put_swf_end_tag(s);
- }
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int swf_write_video(AVFormatContext *s,
- AVCodecContext *enc, const uint8_t *buf, int size)
-{
- ByteIOContext *pb = &s->pb;
- static int tag_id = 0;
-
- if (enc->frame_number > 1) {
- /* remove the shape */
- put_swf_tag(s, TAG_REMOVEOBJECT);
- put_le16(pb, SHAPE_ID); /* shape ID */
- put_le16(pb, 1); /* depth */
- put_swf_end_tag(s);
-
- /* free the bitmap */
- put_swf_tag(s, TAG_FREECHARACTER);
- put_le16(pb, BITMAP_ID);
- put_swf_end_tag(s);
- }
-
- put_swf_tag(s, TAG_JPEG2 | TAG_LONG);
-
- put_le16(pb, tag_id); /* ID of the image */
-
- /* a dummy jpeg header seems to be required */
- put_byte(pb, 0xff);
- put_byte(pb, 0xd8);
- put_byte(pb, 0xff);
- put_byte(pb, 0xd9);
- /* write the jpeg image */
- put_buffer(pb, buf, size);
-
- put_swf_end_tag(s);
-
- /* draw the shape */
-
- put_swf_tag(s, TAG_PLACEOBJECT);
- put_le16(pb, SHAPE_ID); /* shape ID */
- put_le16(pb, 1); /* depth */
- put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0);
- put_swf_end_tag(s);
-
- /* output the frame */
- put_swf_tag(s, TAG_SHOWFRAME);
- put_swf_end_tag(s);
-
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int swf_write_audio(AVFormatContext *s, const uint8_t *buf, int size)
-{
- ByteIOContext *pb = &s->pb;
-
- put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG);
-
- put_buffer(pb, buf, size);
-
- put_swf_end_tag(s);
- put_flush_packet(&s->pb);
- return 0;
-}
-
-static int swf_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- AVCodecContext *codec = &s->streams[stream_index]->codec;
- if (codec->codec_type == CODEC_TYPE_AUDIO)
- return swf_write_audio(s, buf, size);
- else
- return swf_write_video(s, codec, buf, size);
-}
-
-static int swf_write_trailer(AVFormatContext *s)
-{
- SWFContext *swf = s->priv_data;
- ByteIOContext *pb = &s->pb;
- AVCodecContext *enc, *video_enc;
- int file_size, i;
-
- video_enc = NULL;
- for(i=0;i<s->nb_streams;i++) {
- enc = &s->streams[i]->codec;
- if (enc->codec_type == CODEC_TYPE_VIDEO)
- video_enc = enc;
- }
-
- put_swf_tag(s, TAG_END);
- put_swf_end_tag(s);
-
- put_flush_packet(&s->pb);
-
- /* patch file size and number of frames if not streamed */
- if (!url_is_streamed(&s->pb) && video_enc) {
- file_size = url_ftell(pb);
- url_fseek(pb, 4, SEEK_SET);
- put_le32(pb, file_size);
- url_fseek(pb, swf->duration_pos, SEEK_SET);
- put_le16(pb, video_enc->frame_number);
- }
- return 0;
-}
-
-/***********************************/
-/* just to extract MP3 from swf */
-
-static int get_swf_tag(ByteIOContext *pb, int *len_ptr)
-{
- int tag, len;
-
- if (url_feof(pb))
- return -1;
-
- tag = get_le16(pb);
- len = tag & 0x3f;
- tag = tag >> 6;
- if (len == 0x3f) {
- len = get_le32(pb);
- }
- *len_ptr = len;
- return tag;
-}
-
-
-static int swf_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size <= 16)
- return 0;
- if (p->buf[0] == 'F' && p->buf[1] == 'W' &&
- p->buf[2] == 'S')
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- ByteIOContext *pb = &s->pb;
- int nbits, len, frame_rate, tag, v;
- AVStream *st;
-
- if ((get_be32(pb) & 0xffffff00) != MKBETAG('F', 'W', 'S', 0))
- return -EIO;
- get_le32(pb);
- /* skip rectangle size */
- nbits = get_byte(pb) >> 3;
- len = (4 * nbits - 3 + 7) / 8;
- url_fskip(pb, len);
- frame_rate = get_le16(pb);
- get_le16(pb); /* frame count */
-
- for(;;) {
- tag = get_swf_tag(pb, &len);
- if (tag < 0) {
- fprintf(stderr, "No streaming found in SWF\n");
- return -EIO;
- }
- if (tag == TAG_STREAMHEAD) {
- /* streaming found */
- get_byte(pb);
- v = get_byte(pb);
- get_le16(pb);
- /* if mp3 streaming found, OK */
- if ((v & 0x20) != 0) {
- st = av_new_stream(s, 0);
- if (!st)
- return -ENOMEM;
-
- if (v & 0x01)
- st->codec.channels = 2;
- else
- st->codec.channels = 1;
-
- switch((v>> 2) & 0x03) {
- case 1:
- st->codec.sample_rate = 11025;
- break;
- case 2:
- st->codec.sample_rate = 22050;
- break;
- case 3:
- st->codec.sample_rate = 44100;
- break;
- default:
- av_free(st);
- return -EIO;
- }
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_MP2;
- break;
- }
- } else {
- url_fskip(pb, len);
- }
- }
-
- return 0;
-}
-
-static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- ByteIOContext *pb = &s->pb;
- int tag, len;
-
- for(;;) {
- tag = get_swf_tag(pb, &len);
- if (tag < 0)
- return -EIO;
- if (tag == TAG_STREAMBLOCK) {
- av_new_packet(pkt, len);
- get_buffer(pb, pkt->data, pkt->size);
- break;
- } else {
- url_fskip(pb, len);
- }
- }
- return 0;
-}
-
-static int swf_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVInputFormat swf_iformat = {
- "swf",
- "Flash format",
- 0,
- swf_probe,
- swf_read_header,
- swf_read_packet,
- swf_read_close,
-};
-
-static AVOutputFormat swf_oformat = {
- "swf",
- "Flash format",
- "application/x-shockwave-flash",
- "swf",
- sizeof(SWFContext),
- CODEC_ID_MP2,
- CODEC_ID_MJPEG,
- swf_write_header,
- swf_write_packet,
- swf_write_trailer,
-};
-
-int swf_init(void)
-{
- av_register_input_format(&swf_iformat);
- av_register_output_format(&swf_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * TCP protocol
- * Copyright (c) 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#if defined(__APPLE__) || defined(__BEOS__)
-typedef int socklen_t;
-#endif
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-#include <sys/time.h>
-#include <fcntl.h>
-
-typedef struct TCPContext {
- int fd;
-} TCPContext;
-
-/* resolve host with also IP address parsing */
-int resolve_host(struct in_addr *sin_addr, const char *hostname)
-{
- struct hostent *hp;
-
- if ((inet_aton(hostname, sin_addr)) == 0) {
- hp = gethostbyname(hostname);
- if (!hp)
- return -1;
- memcpy (sin_addr, hp->h_addr, sizeof(struct in_addr));
- }
- return 0;
-}
-
-/* return non zero if error */
-static int tcp_open(URLContext *h, const char *uri, int flags)
-{
- struct sockaddr_in dest_addr;
- char hostname[1024], *q;
- int port, fd = -1;
- TCPContext *s;
- const char *p;
- fd_set wfds;
- int fd_max, ret;
- struct timeval tv;
- socklen_t optlen;
-
- s = av_malloc(sizeof(TCPContext));
- if (!s)
- return -ENOMEM;
- h->priv_data = s;
- p = uri;
- if (!strstart(p, "tcp://", &p))
- goto fail;
- q = hostname;
- while (*p != ':' && *p != '/' && *p != '\0') {
- if ((q - hostname) < sizeof(hostname) - 1)
- *q++ = *p;
- p++;
- }
- *q = '\0';
- if (*p != ':')
- goto fail;
- p++;
- port = strtoul(p, (char **)&p, 10);
- if (port <= 0 || port >= 65536)
- goto fail;
-
- dest_addr.sin_family = AF_INET;
- dest_addr.sin_port = htons(port);
- if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
- goto fail;
-
- fd = socket(PF_INET, SOCK_STREAM, 0);
- if (fd < 0)
- goto fail;
- fcntl(fd, F_SETFL, O_NONBLOCK);
-
- redo:
- ret = connect(fd, (struct sockaddr *)&dest_addr,
- sizeof(dest_addr));
- if (ret < 0) {
- if (errno == EINTR)
- goto redo;
- if (errno != EINPROGRESS)
- goto fail;
-
- /* wait until we are connected or until abort */
- for(;;) {
- if (url_interrupt_cb()) {
- ret = -EINTR;
- goto fail1;
- }
- fd_max = fd;
- FD_ZERO(&wfds);
- FD_SET(fd, &wfds);
- tv.tv_sec = 0;
- tv.tv_usec = 100 * 1000;
- ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
- if (ret > 0 && FD_ISSET(fd, &wfds))
- break;
- }
-
- /* test error */
- optlen = sizeof(ret);
- getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
- if (ret != 0)
- goto fail;
- }
- s->fd = fd;
- return 0;
-
- fail:
- ret = -EIO;
- fail1:
- if (fd >= 0)
- close(fd);
- av_free(s);
- return ret;
-}
-
-static int tcp_read(URLContext *h, uint8_t *buf, int size)
-{
- TCPContext *s = h->priv_data;
- int size1, len, fd_max;
- fd_set rfds;
- struct timeval tv;
-
- size1 = size;
- while (size > 0) {
- if (url_interrupt_cb())
- return -EINTR;
- fd_max = s->fd;
- FD_ZERO(&rfds);
- FD_SET(s->fd, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 100 * 1000;
- select(fd_max + 1, &rfds, NULL, NULL, &tv);
-#ifdef __BEOS__
- len = recv(s->fd, buf, size, 0);
-#else
- len = read(s->fd, buf, size);
-#endif
- if (len < 0) {
- if (errno != EINTR && errno != EAGAIN)
-#ifdef __BEOS__
- return errno;
-#else
- return -errno;
-#endif
- else
- continue;
- } else if (len == 0) {
- break;
- }
- size -= len;
- buf += len;
- }
- return size1 - size;
-}
-
-static int tcp_write(URLContext *h, uint8_t *buf, int size)
-{
- TCPContext *s = h->priv_data;
- int ret, size1, fd_max;
- fd_set wfds;
- struct timeval tv;
-
- size1 = size;
- while (size > 0) {
- if (url_interrupt_cb())
- return -EINTR;
- fd_max = s->fd;
- FD_ZERO(&wfds);
- FD_SET(s->fd, &wfds);
- tv.tv_sec = 0;
- tv.tv_usec = 100 * 1000;
- select(fd_max + 1, NULL, &wfds, NULL, &tv);
-#ifdef __BEOS__
- ret = send(s->fd, buf, size, 0);
-#else
- ret = write(s->fd, buf, size);
-#endif
- if (ret < 0 && errno != EINTR && errno != EAGAIN)
-#ifdef __BEOS__
- return errno;
-#else
- return -errno;
-#endif
- size -= ret;
- buf += ret;
- }
- return size1 - size;
-}
-
-static int tcp_close(URLContext *h)
-{
- TCPContext *s = h->priv_data;
-#ifdef CONFIG_BEOS_NETSERVER
- closesocket(s->fd);
-#else
- close(s->fd);
-#endif
- av_free(s);
- return 0;
-}
-
-URLProtocol tcp_protocol = {
- "tcp",
- tcp_open,
- tcp_read,
- tcp_write,
- NULL, /* seek */
- tcp_close,
-};
+++ /dev/null
-/*
- * UDP prototype streaming system
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
-#include <netdb.h>
-
-typedef struct {
- int udp_fd;
- int ttl;
- int is_multicast;
- int local_port;
- struct ip_mreq mreq;
- struct sockaddr_in dest_addr;
-} UDPContext;
-
-#define UDP_TX_BUF_SIZE 32768
-
-/**
- * If no filename is given to av_open_input_file because you want to
- * get the local port first, then you must call this function to set
- * the remote server address.
- *
- * url syntax: udp://host:port[?option=val...]
- * option: 'multicast=1' : enable multicast
- * 'ttl=n' : set the ttl value (for multicast only)
- * 'localport=n' : set the local port
- * 'pkt_size=n' : set max packet size
- *
- * @param s1 media file context
- * @param uri of the remote server
- * @return zero if no error.
- */
-int udp_set_remote_url(URLContext *h, const char *uri)
-{
- UDPContext *s = h->priv_data;
- char hostname[256];
- int port;
-
- url_split(NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
-
- /* set the destination address */
- if (resolve_host(&s->dest_addr.sin_addr, hostname) < 0)
- return -EIO;
- s->dest_addr.sin_family = AF_INET;
- s->dest_addr.sin_port = htons(port);
- return 0;
-}
-
-/**
- * Return the local port used by the UDP connexion
- * @param s1 media file context
- * @return the local port number
- */
-int udp_get_local_port(URLContext *h)
-{
- UDPContext *s = h->priv_data;
- return s->local_port;
-}
-
-/**
- * Return the udp file handle for select() usage to wait for several RTP
- * streams at the same time.
- * @param h media file context
- */
-int udp_get_file_handle(URLContext *h)
-{
- UDPContext *s = h->priv_data;
- return s->udp_fd;
-}
-
-/* put it in UDP context */
-/* return non zero if error */
-static int udp_open(URLContext *h, const char *uri, int flags)
-{
- struct sockaddr_in my_addr, my_addr1;
- char hostname[1024];
- int port, udp_fd = -1, tmp;
- UDPContext *s = NULL;
- int is_output, len;
- const char *p;
- char buf[256];
-
- h->is_streamed = 1;
- h->max_packet_size = 1472;
-
- is_output = (flags & URL_WRONLY);
-
- s = av_malloc(sizeof(UDPContext));
- if (!s)
- return -ENOMEM;
-
- h->priv_data = s;
- s->ttl = 16;
- s->is_multicast = 0;
- s->local_port = 0;
- p = strchr(uri, '?');
- if (p) {
- s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p);
- if (find_info_tag(buf, sizeof(buf), "ttl", p)) {
- s->ttl = strtol(buf, NULL, 10);
- }
- if (find_info_tag(buf, sizeof(buf), "localport", p)) {
- s->local_port = strtol(buf, NULL, 10);
- }
- if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
- h->max_packet_size = strtol(buf, NULL, 10);
- }
- }
-
- /* fill the dest addr */
- url_split(NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
-
- /* XXX: fix url_split */
- if (hostname[0] == '\0' || hostname[0] == '?') {
- /* only accepts null hostname if input */
- if (s->is_multicast || (flags & URL_WRONLY))
- goto fail;
- } else {
- udp_set_remote_url(h, uri);
- }
-
- udp_fd = socket(PF_INET, SOCK_DGRAM, 0);
- if (udp_fd < 0)
- goto fail;
-
- my_addr.sin_family = AF_INET;
- my_addr.sin_addr.s_addr = htonl (INADDR_ANY);
- if (s->is_multicast && !(h->flags & URL_WRONLY)) {
- /* special case: the bind must be done on the multicast address port */
- my_addr.sin_port = s->dest_addr.sin_port;
- } else {
- my_addr.sin_port = htons(s->local_port);
- }
-
- /* the bind is needed to give a port to the socket now */
- if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
- goto fail;
-
- len = sizeof(my_addr1);
- getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
- s->local_port = ntohs(my_addr1.sin_port);
-
-#ifndef CONFIG_BEOS_NETSERVER
- if (s->is_multicast) {
- if (h->flags & URL_WRONLY) {
- /* output */
- if (setsockopt(udp_fd, IPPROTO_IP, IP_MULTICAST_TTL,
- &s->ttl, sizeof(s->ttl)) < 0) {
- perror("IP_MULTICAST_TTL");
- goto fail;
- }
- } else {
- /* input */
- memset(&s->mreq, 0, sizeof(s->mreq));
- s->mreq.imr_multiaddr = s->dest_addr.sin_addr;
- s->mreq.imr_interface.s_addr = htonl (INADDR_ANY);
- if (setsockopt(udp_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
- &s->mreq, sizeof(s->mreq)) < 0) {
- perror("rtp: IP_ADD_MEMBERSHIP");
- goto fail;
- }
- }
- }
-#endif
-
- if (is_output) {
- /* limit the tx buf size to limit latency */
- tmp = UDP_TX_BUF_SIZE;
- if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) {
- perror("setsockopt sndbuf");
- goto fail;
- }
- }
-
- s->udp_fd = udp_fd;
- return 0;
- fail:
- if (udp_fd >= 0)
-#ifdef CONFIG_BEOS_NETSERVER
- closesocket(udp_fd);
-#else
- close(udp_fd);
-#endif
- av_free(s);
- return -EIO;
-}
-
-static int udp_read(URLContext *h, uint8_t *buf, int size)
-{
- UDPContext *s = h->priv_data;
- struct sockaddr_in from;
- int from_len, len;
-
- for(;;) {
- from_len = sizeof(from);
- len = recvfrom (s->udp_fd, buf, size, 0,
- (struct sockaddr *)&from, &from_len);
- if (len < 0) {
- if (errno != EAGAIN && errno != EINTR)
- return -EIO;
- } else {
- break;
- }
- }
- return len;
-}
-
-static int udp_write(URLContext *h, uint8_t *buf, int size)
-{
- UDPContext *s = h->priv_data;
- int ret;
-
- for(;;) {
- ret = sendto (s->udp_fd, buf, size, 0,
- (struct sockaddr *) &s->dest_addr,
- sizeof (s->dest_addr));
- if (ret < 0) {
- if (errno != EINTR && errno != EAGAIN)
- return -EIO;
- } else {
- break;
- }
- }
- return size;
-}
-
-static int udp_close(URLContext *h)
-{
- UDPContext *s = h->priv_data;
-
-#ifndef CONFIG_BEOS_NETSERVER
- if (s->is_multicast && !(h->flags & URL_WRONLY)) {
- if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,
- &s->mreq, sizeof(s->mreq)) < 0) {
- perror("IP_DROP_MEMBERSHIP");
- }
- }
- close(s->udp_fd);
-#else
- closesocket(s->udp_fd);
-#endif
- av_free(s);
- return 0;
-}
-
-URLProtocol udp_protocol = {
- "udp",
- udp_open,
- udp_read,
- udp_write,
- NULL, /* seek */
- udp_close,
-};
+++ /dev/null
-/*
- * Various utilities for ffmpeg system
- * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-AVInputFormat *first_iformat;
-AVOutputFormat *first_oformat;
-AVImageFormat *first_image_format;
-
-void av_register_input_format(AVInputFormat *format)
-{
- AVInputFormat **p;
- p = &first_iformat;
- while (*p != NULL) p = &(*p)->next;
- *p = format;
- format->next = NULL;
-}
-
-void av_register_output_format(AVOutputFormat *format)
-{
- AVOutputFormat **p;
- p = &first_oformat;
- while (*p != NULL) p = &(*p)->next;
- *p = format;
- format->next = NULL;
-}
-
-int match_ext(const char *filename, const char *extensions)
-{
- const char *ext, *p;
- char ext1[32], *q;
-
- ext = strrchr(filename, '.');
- if (ext) {
- ext++;
- p = extensions;
- for(;;) {
- q = ext1;
- while (*p != '\0' && *p != ',')
- *q++ = *p++;
- *q = '\0';
- if (!strcasecmp(ext1, ext))
- return 1;
- if (*p == '\0')
- break;
- p++;
- }
- }
- return 0;
-}
-
-AVOutputFormat *guess_format(const char *short_name, const char *filename,
- const char *mime_type)
-{
- AVOutputFormat *fmt, *fmt_found;
- int score_max, score;
-
- /* specific test for image sequences */
- if (!short_name && filename &&
- filename_number_test(filename) >= 0 &&
- guess_image_format(filename)) {
- return guess_format("image", NULL, NULL);
- }
-
- /* find the proper file type */
- fmt_found = NULL;
- score_max = 0;
- fmt = first_oformat;
- while (fmt != NULL) {
- score = 0;
- if (fmt->name && short_name && !strcmp(fmt->name, short_name))
- score += 100;
- if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))
- score += 10;
- if (filename && fmt->extensions &&
- match_ext(filename, fmt->extensions)) {
- score += 5;
- }
- if (score > score_max) {
- score_max = score;
- fmt_found = fmt;
- }
- fmt = fmt->next;
- }
- return fmt_found;
-}
-
-AVOutputFormat *guess_stream_format(const char *short_name, const char *filename,
- const char *mime_type)
-{
- AVOutputFormat *fmt = guess_format(short_name, filename, mime_type);
-
- if (fmt) {
- AVOutputFormat *stream_fmt;
- char stream_format_name[64];
-
- snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream", fmt->name);
- stream_fmt = guess_format(stream_format_name, NULL, NULL);
-
- if (stream_fmt)
- fmt = stream_fmt;
- }
-
- return fmt;
-}
-
-AVInputFormat *av_find_input_format(const char *short_name)
-{
- AVInputFormat *fmt;
- for(fmt = first_iformat; fmt != NULL; fmt = fmt->next) {
- if (!strcmp(fmt->name, short_name))
- return fmt;
- }
- return NULL;
-}
-
-/* memory handling */
-
-/**
- * Default packet destructor
- */
-static void av_destruct_packet(AVPacket *pkt)
-{
- av_free(pkt->data);
- pkt->data = NULL; pkt->size = 0;
-}
-
-/**
- * Allocate the payload of a packet and intialized its fields to default values.
- *
- * @param pkt packet
- * @param size wanted payload size
- * @return 0 if OK. AVERROR_xxx otherwise.
- */
-int av_new_packet(AVPacket *pkt, int size)
-{
- void *data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
- if (!data)
- return AVERROR_NOMEM;
- memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
-
- av_init_packet(pkt);
- pkt->data = data;
- pkt->size = size;
- pkt->destruct = av_destruct_packet;
- return 0;
-}
-
-/* fifo handling */
-
-int fifo_init(FifoBuffer *f, int size)
-{
- f->buffer = av_malloc(size);
- if (!f->buffer)
- return -1;
- f->end = f->buffer + size;
- f->wptr = f->rptr = f->buffer;
- return 0;
-}
-
-void fifo_free(FifoBuffer *f)
-{
- av_free(f->buffer);
-}
-
-int fifo_size(FifoBuffer *f, uint8_t *rptr)
-{
- int size;
-
- if (f->wptr >= rptr) {
- size = f->wptr - rptr;
- } else {
- size = (f->end - rptr) + (f->wptr - f->buffer);
- }
- return size;
-}
-
-/* get data from the fifo (return -1 if not enough data) */
-int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr)
-{
- uint8_t *rptr = *rptr_ptr;
- int size, len;
-
- if (f->wptr >= rptr) {
- size = f->wptr - rptr;
- } else {
- size = (f->end - rptr) + (f->wptr - f->buffer);
- }
-
- if (size < buf_size)
- return -1;
- while (buf_size > 0) {
- len = f->end - rptr;
- if (len > buf_size)
- len = buf_size;
- memcpy(buf, rptr, len);
- buf += len;
- rptr += len;
- if (rptr >= f->end)
- rptr = f->buffer;
- buf_size -= len;
- }
- *rptr_ptr = rptr;
- return 0;
-}
-
-void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr)
-{
- int len;
- uint8_t *wptr;
- wptr = *wptr_ptr;
- while (size > 0) {
- len = f->end - wptr;
- if (len > size)
- len = size;
- memcpy(wptr, buf, len);
- wptr += len;
- if (wptr >= f->end)
- wptr = f->buffer;
- buf += len;
- size -= len;
- }
- *wptr_ptr = wptr;
-}
-
-int filename_number_test(const char *filename)
-{
- char buf[1024];
- return get_frame_filename(buf, sizeof(buf), filename, 1);
-}
-
-/* guess file format */
-AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)
-{
- AVInputFormat *fmt1, *fmt;
- int score, score_max;
-
- fmt = NULL;
- score_max = 0;
- for(fmt1 = first_iformat; fmt1 != NULL; fmt1 = fmt1->next) {
- if (!is_opened && !(fmt1->flags & AVFMT_NOFILE))
- continue;
- score = 0;
- if (fmt1->read_probe) {
- score = fmt1->read_probe(pd);
- } else if (fmt1->extensions) {
- if (match_ext(pd->filename, fmt1->extensions)) {
- score = 50;
- }
- }
- if (score > score_max) {
- score_max = score;
- fmt = fmt1;
- }
- }
- return fmt;
-}
-
-/************************************************************/
-/* input media file */
-
-#define PROBE_BUF_SIZE 2048
-
-/**
- * Open a media file as input. The codec are not opened. Only the file
- * header (if present) is read.
- *
- * @param ic_ptr the opened media file handle is put here
- * @param filename filename to open.
- * @param fmt if non NULL, force the file format to use
- * @param buf_size optional buffer size (zero if default is OK)
- * @param ap additionnal parameters needed when opening the file (NULL if default)
- * @return 0 if OK. AVERROR_xxx otherwise.
- */
-int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
- AVInputFormat *fmt,
- int buf_size,
- AVFormatParameters *ap)
-{
- AVFormatContext *ic = NULL;
- int err, must_open_file;
- char buf[PROBE_BUF_SIZE];
- AVProbeData probe_data, *pd = &probe_data;
-
- ic = av_mallocz(sizeof(AVFormatContext));
- if (!ic) {
- err = AVERROR_NOMEM;
- goto fail;
- }
- ic->duration = AV_NOPTS_VALUE;
- ic->start_time = AV_NOPTS_VALUE;
- pstrcpy(ic->filename, sizeof(ic->filename), filename);
- pd->filename = ic->filename;
- pd->buf = buf;
- pd->buf_size = 0;
-
- if (!fmt) {
- /* guess format if no file can be opened */
- fmt = av_probe_input_format(pd, 0);
- }
-
- /* do not open file if the format does not need it. XXX: specific
- hack needed to handle RTSP/TCP */
- must_open_file = 1;
- if ((fmt && (fmt->flags & AVFMT_NOFILE))
-#ifdef CONFIG_NETWORK
- || (fmt == &rtp_demux && !strcmp(filename, "null"))
-#endif
- ) {
- must_open_file = 0;
- }
-
- if (!fmt || must_open_file) {
- /* if no file needed do not try to open one */
- if (url_fopen(&ic->pb, filename, URL_RDONLY) < 0) {
- err = AVERROR_IO;
- goto fail;
- }
- if (buf_size > 0) {
- url_setbufsize(&ic->pb, buf_size);
- }
- if (!fmt) {
- /* read probe data */
- pd->buf_size = get_buffer(&ic->pb, buf, PROBE_BUF_SIZE);
- url_fseek(&ic->pb, 0, SEEK_SET);
- }
- }
-
- /* guess file format */
- if (!fmt) {
- fmt = av_probe_input_format(pd, 1);
- }
-
- /* if still no format found, error */
- if (!fmt) {
- err = AVERROR_NOFMT;
- goto fail1;
- }
-
- /* XXX: suppress this hack for redirectors */
-#ifdef CONFIG_NETWORK
- if (fmt == &redir_demux) {
- err = redir_open(ic_ptr, &ic->pb);
- url_fclose(&ic->pb);
- av_free(ic);
- return err;
- }
-#endif
-
- ic->iformat = fmt;
-
- /* check filename in case of an image number is expected */
- if (ic->iformat->flags & AVFMT_NEEDNUMBER) {
- if (filename_number_test(ic->filename) < 0) {
- err = AVERROR_NUMEXPECTED;
- goto fail1;
- }
- }
-
- /* allocate private data */
- if (fmt->priv_data_size > 0) {
- ic->priv_data = av_mallocz(fmt->priv_data_size);
- if (!ic->priv_data) {
- err = AVERROR_NOMEM;
- goto fail1;
- }
- } else
- ic->priv_data = NULL;
-
- /* default pts settings is MPEG like */
- av_set_pts_info(ic, 33, 1, 90000);
-
- err = ic->iformat->read_header(ic, ap);
- if (err < 0)
- goto fail1;
- *ic_ptr = ic;
- return 0;
- fail1:
- if (!fmt || must_open_file) {
- url_fclose(&ic->pb);
- }
- fail:
- if (ic) {
- av_freep(&ic->priv_data);
- }
- av_free(ic);
- *ic_ptr = NULL;
- return err;
-}
-
-/**
- * Read a packet from a media file
- * @param s media file handle
- * @param pkt is filled
- * @return 0 if OK. AVERROR_xxx if error.
- */
-int av_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- AVPacketList *pktl;
-
- pktl = s->packet_buffer;
- if (pktl) {
- /* read packet from packet buffer, if there is data */
- *pkt = pktl->pkt;
- s->packet_buffer = pktl->next;
- av_free(pktl);
- return 0;
- } else {
- return s->iformat->read_packet(s, pkt);
- }
-}
-
-
-/* return TRUE if the stream has accurate timings for at least one component */
-static int av_has_timings(AVFormatContext *ic)
-{
- int i;
- AVStream *st;
-
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time != AV_NOPTS_VALUE &&
- st->duration != AV_NOPTS_VALUE)
- return 1;
- }
- return 0;
-}
-
-/* estimate the stream timings from the one of each components. Also
- compute the global bitrate if possible */
-static void av_update_stream_timings(AVFormatContext *ic)
-{
- int64_t start_time, end_time, end_time1;
- int i;
- AVStream *st;
-
- start_time = MAXINT64;
- end_time = MININT64;
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time != AV_NOPTS_VALUE) {
- if (st->start_time < start_time)
- start_time = st->start_time;
- if (st->duration != AV_NOPTS_VALUE) {
- end_time1 = st->start_time + st->duration;
- if (end_time1 > end_time)
- end_time = end_time1;
- }
- }
- }
- if (start_time != MAXINT64) {
- ic->start_time = start_time;
- if (end_time != MAXINT64) {
- ic->duration = end_time - start_time;
- if (ic->file_size > 0) {
- /* compute the bit rate */
- ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE /
- (double)ic->duration;
- }
- }
- }
-
-}
-
-static void fill_all_stream_timings(AVFormatContext *ic)
-{
- int i;
- AVStream *st;
-
- av_update_stream_timings(ic);
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time == AV_NOPTS_VALUE) {
- st->start_time = ic->start_time;
- st->duration = ic->duration;
- }
- }
-}
-
-static void av_estimate_timings_from_bit_rate(AVFormatContext *ic)
-{
- int64_t filesize, duration;
- int bit_rate, i;
- AVStream *st;
-
- /* if bit_rate is already set, we believe it */
- if (ic->bit_rate == 0) {
- bit_rate = 0;
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- bit_rate += st->codec.bit_rate;
- }
- ic->bit_rate = bit_rate;
- }
-
- /* if duration is already set, we believe it */
- if (ic->duration == AV_NOPTS_VALUE &&
- ic->bit_rate != 0 &&
- ic->file_size != 0) {
- filesize = ic->file_size;
- if (filesize > 0) {
- duration = (int64_t)((8 * AV_TIME_BASE * (double)filesize) / (double)ic->bit_rate);
- for(i = 0; i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time == AV_NOPTS_VALUE ||
- st->duration == AV_NOPTS_VALUE) {
- st->start_time = 0;
- st->duration = duration;
- }
- }
- }
- }
-}
-
-static void flush_packet_queue(AVFormatContext *s)
-{
- AVPacketList *pktl;
-
- for(;;) {
- pktl = s->packet_buffer;
- if (!pktl)
- break;
- s->packet_buffer = pktl->next;
- av_free_packet(&pktl->pkt);
- av_free(pktl);
- }
-}
-
-#define DURATION_MAX_READ_SIZE 250000
-
-/* only usable for MPEG-PS streams */
-static void av_estimate_timings_from_pts(AVFormatContext *ic)
-{
- AVPacket pkt1, *pkt = &pkt1;
- AVStream *st;
- int read_size, i, ret;
- int64_t start_time, end_time, end_time1;
- int64_t filesize, offset, duration;
-
- /* we read the first packets to get the first PTS (not fully
- accurate, but it is enough now) */
- url_fseek(&ic->pb, 0, SEEK_SET);
- read_size = 0;
- for(;;) {
- if (read_size >= DURATION_MAX_READ_SIZE)
- break;
- /* if all info is available, we can stop */
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time == AV_NOPTS_VALUE)
- break;
- }
- if (i == ic->nb_streams)
- break;
-
- ret = av_read_packet(ic, pkt);
- if (ret != 0)
- break;
- read_size += pkt->size;
- st = ic->streams[pkt->stream_index];
- if (pkt->pts != AV_NOPTS_VALUE) {
- if (st->start_time == AV_NOPTS_VALUE)
- st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
- }
- av_free_packet(pkt);
- }
-
- /* we compute the minimum start_time and use it as default */
- start_time = MAXINT64;
- for(i = 0; i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time != AV_NOPTS_VALUE &&
- st->start_time < start_time)
- start_time = st->start_time;
- }
- if (start_time != MAXINT64)
- ic->start_time = start_time;
-
- /* estimate the end time (duration) */
- /* XXX: may need to support wrapping */
- filesize = ic->file_size;
- offset = filesize - DURATION_MAX_READ_SIZE;
- if (offset < 0)
- offset = 0;
-
- /* flush packet queue */
- flush_packet_queue(ic);
-
- url_fseek(&ic->pb, offset, SEEK_SET);
- read_size = 0;
- for(;;) {
- if (read_size >= DURATION_MAX_READ_SIZE)
- break;
- /* if all info is available, we can stop */
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->duration == AV_NOPTS_VALUE)
- break;
- }
- if (i == ic->nb_streams)
- break;
-
- ret = av_read_packet(ic, pkt);
- if (ret != 0)
- break;
- read_size += pkt->size;
- st = ic->streams[pkt->stream_index];
- if (pkt->pts != AV_NOPTS_VALUE) {
- end_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
- duration = end_time - st->start_time;
- if (duration > 0) {
- if (st->duration == AV_NOPTS_VALUE ||
- st->duration < duration)
- st->duration = duration;
- }
- }
- av_free_packet(pkt);
- }
-
- /* estimate total duration */
- end_time = MININT64;
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->duration != AV_NOPTS_VALUE) {
- end_time1 = st->start_time + st->duration;
- if (end_time1 > end_time)
- end_time = end_time1;
- }
- }
-
- /* update start_time (new stream may have been created, so we do
- it at the end */
- if (ic->start_time != AV_NOPTS_VALUE) {
- for(i = 0; i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->start_time == AV_NOPTS_VALUE)
- st->start_time = ic->start_time;
- }
- }
-
- if (end_time != MININT64) {
- /* put dummy values for duration if needed */
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- if (st->duration == AV_NOPTS_VALUE &&
- st->start_time != AV_NOPTS_VALUE)
- st->duration = end_time - st->start_time;
- }
- ic->duration = end_time - ic->start_time;
- }
-
- url_fseek(&ic->pb, 0, SEEK_SET);
-}
-
-static void av_estimate_timings(AVFormatContext *ic)
-{
- URLContext *h;
- int64_t file_size;
-
- /* get the file size, if possible */
- if (ic->iformat->flags & AVFMT_NOFILE) {
- file_size = 0;
- } else {
- h = url_fileno(&ic->pb);
- file_size = url_filesize(h);
- if (file_size < 0)
- file_size = 0;
- }
- ic->file_size = file_size;
-
- if (ic->iformat == &mpegps_demux) {
- /* get accurate estimate from the PTSes */
- av_estimate_timings_from_pts(ic);
- } else if (av_has_timings(ic)) {
- /* at least one components has timings - we use them for all
- the components */
- fill_all_stream_timings(ic);
- } else {
- /* less precise: use bit rate info */
- av_estimate_timings_from_bit_rate(ic);
- }
- av_update_stream_timings(ic);
-
-#if 0
- {
- int i;
- AVStream *st;
- for(i = 0;i < ic->nb_streams; i++) {
- st = ic->streams[i];
- printf("%d: start_time: %0.3f duration: %0.3f\n",
- i, (double)st->start_time / AV_TIME_BASE,
- (double)st->duration / AV_TIME_BASE);
- }
- printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n",
- (double)ic->start_time / AV_TIME_BASE,
- (double)ic->duration / AV_TIME_BASE,
- ic->bit_rate / 1000);
- }
-#endif
-}
-
-/* state for codec information */
-#define CSTATE_NOTFOUND 0
-#define CSTATE_DECODING 1
-#define CSTATE_FOUND 2
-
-static int has_codec_parameters(AVCodecContext *enc)
-{
- int val;
- switch(enc->codec_type) {
- case CODEC_TYPE_AUDIO:
- val = enc->sample_rate;
- break;
- case CODEC_TYPE_VIDEO:
- val = enc->width;
- break;
- default:
- val = 1;
- break;
- }
- return (val != 0);
-}
-
-/**
- * Read the beginning of a media file to get stream information. This
- * is useful for file formats with no headers such as MPEG. This
- * function also compute the real frame rate in case of mpeg2 repeat
- * frame mode.
- *
- * @param ic media file handle
- * @return >=0 if OK. AVERROR_xxx if error.
- */
-int av_find_stream_info(AVFormatContext *ic)
-{
- int i, count, ret, got_picture, size, read_size;
- AVCodec *codec;
- AVStream *st;
- AVPacket *pkt;
- AVFrame picture;
- AVPacketList *pktl=NULL, **ppktl;
- short samples[AVCODEC_MAX_AUDIO_FRAME_SIZE / 2];
- uint8_t *ptr;
- int min_read_size, max_read_size;
-
- /* typical mpeg ts rate is 40 Mbits. DVD rate is about 10
- Mbits. We read at most 0.2 second of file to find all streams */
-
- /* XXX: base it on stream bitrate when possible */
- if (ic->iformat == &mpegts_demux) {
- /* maximum number of bytes we accept to read to find all the streams
- in a file */
- min_read_size = 6000000;
- } else {
- min_read_size = 250000;
- }
- /* max read size is 2 seconds of video max */
- max_read_size = min_read_size * 10;
-
- /* set initial codec state */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (has_codec_parameters(&st->codec))
- st->codec_info_state = CSTATE_FOUND;
- else
- st->codec_info_state = CSTATE_NOTFOUND;
- st->codec_info_nb_repeat_frames = 0;
- st->codec_info_nb_real_frames = 0;
- }
-
- count = 0;
- read_size = 0;
- ppktl = &ic->packet_buffer;
- for(;;) {
- /* check if one codec still needs to be handled */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (st->codec_info_state != CSTATE_FOUND)
- break;
- }
- if (i == ic->nb_streams) {
- /* NOTE: if the format has no header, then we need to read
- some packets to get most of the streams, so we cannot
- stop here */
- if (!(ic->iformat->flags & AVFMT_NOHEADER) ||
- read_size >= min_read_size) {
- /* if we found the info for all the codecs, we can stop */
- ret = count;
- break;
- }
- } else {
- /* we did not get all the codec info, but we read too much data */
- if (read_size >= max_read_size) {
- ret = count;
- break;
- }
- }
-
- pktl = av_mallocz(sizeof(AVPacketList));
- if (!pktl) {
- ret = AVERROR_NOMEM;
- break;
- }
-
- /* add the packet in the buffered packet list */
- *ppktl = pktl;
- ppktl = &pktl->next;
-
- /* NOTE: a new stream can be added there if no header in file
- (AVFMT_NOHEADER) */
- pkt = &pktl->pkt;
- if (ic->iformat->read_packet(ic, pkt) < 0) {
- /* EOF or error */
- ret = -1; /* we could not have all the codec parameters before EOF */
- if ((ic->iformat->flags & AVFMT_NOHEADER) &&
- i == ic->nb_streams)
- ret = 0;
- break;
- }
- read_size += pkt->size;
-
- /* open new codecs */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (st->codec_info_state == CSTATE_NOTFOUND) {
- /* set to found in case of error */
- st->codec_info_state = CSTATE_FOUND;
- codec = avcodec_find_decoder(st->codec.codec_id);
- if (codec) {
- if(codec->capabilities & CODEC_CAP_TRUNCATED)
- st->codec.flags |= CODEC_FLAG_TRUNCATED;
-
- ret = avcodec_open(&st->codec, codec);
- if (ret >= 0)
- st->codec_info_state = CSTATE_DECODING;
- }
- }
- }
-
- st = ic->streams[pkt->stream_index];
- if (st->codec_info_state == CSTATE_DECODING) {
- /* decode the data and update codec parameters */
- ptr = pkt->data;
- size = pkt->size;
- while (size > 0) {
- switch(st->codec.codec_type) {
- case CODEC_TYPE_VIDEO:
- ret = avcodec_decode_video(&st->codec, &picture,
- &got_picture, ptr, size);
- break;
- case CODEC_TYPE_AUDIO:
- ret = avcodec_decode_audio(&st->codec, samples,
- &got_picture, ptr, size);
- break;
- default:
- ret = -1;
- break;
- }
- if (ret < 0) {
- /* if error, simply ignore because another packet
- may be OK */
- break;
- }
- if (got_picture) {
- /* we got the parameters - now we can stop
- examining this stream */
- /* XXX: add a codec info so that we can decide if
- the codec can repeat frames */
- if (st->codec.codec_id == CODEC_ID_MPEG1VIDEO &&
- ic->iformat != &mpegts_demux &&
- st->codec.sub_id == 2) {
- /* for mpeg2 video, we want to know the real
- frame rate, so we decode 40 frames. In mpeg
- TS case we do not do it because it would be
- too long */
- st->codec_info_nb_real_frames++;
- st->codec_info_nb_repeat_frames += st->codec.coded_frame->repeat_pict;
-#if 0
- /* XXX: testing */
- if ((st->codec_info_nb_real_frames % 24) == 23) {
- st->codec_info_nb_repeat_frames += 2;
- }
-#endif
- /* stop after 40 frames */
- if (st->codec_info_nb_real_frames >= 40) {
- av_reduce(
- &st->r_frame_rate,
- &st->r_frame_rate_base,
- (int64_t)st->codec.frame_rate * st->codec_info_nb_real_frames,
- (st->codec_info_nb_real_frames + (st->codec_info_nb_repeat_frames >> 1)) * st->codec.frame_rate_base,
- 1<<30);
- goto close_codec;
- }
- } else {
- close_codec:
- st->codec_info_state = CSTATE_FOUND;
- avcodec_close(&st->codec);
- break;
- }
- }
- ptr += ret;
- size -= ret;
- }
- }
- count++;
- }
-
- /* close each codec if there are opened */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (st->codec_info_state == CSTATE_DECODING)
- avcodec_close(&st->codec);
- }
-
- /* set real frame rate info */
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
- if (!st->r_frame_rate){
- st->r_frame_rate = st->codec.frame_rate;
- st->r_frame_rate_base = st->codec.frame_rate_base;
- }
- }
- }
-
-
- av_estimate_timings(ic);
- return ret;
-}
-
-/**
- * Close a media file (but not its codecs)
- *
- * @param s media file handle
- */
-void av_close_input_file(AVFormatContext *s)
-{
- int i, must_open_file;
-
- if (s->iformat->read_close)
- s->iformat->read_close(s);
- for(i=0;i<s->nb_streams;i++) {
- av_free(s->streams[i]);
- }
- if (s->packet_buffer) {
- AVPacketList *p, *p1;
- p = s->packet_buffer;
- while (p != NULL) {
- p1 = p->next;
- av_free_packet(&p->pkt);
- av_free(p);
- p = p1;
- }
- s->packet_buffer = NULL;
- }
- must_open_file = 1;
- if ((s->iformat->flags & AVFMT_NOFILE)
-#ifdef CONFIG_NETWORK
- || (s->iformat == &rtp_demux && !strcmp(s->filename, "null"))
-#endif
- ) {
- must_open_file = 0;
- }
- if (must_open_file) {
- url_fclose(&s->pb);
- }
- av_freep(&s->priv_data);
- av_free(s);
-}
-
-/**
- * Add a new stream to a media file. Can only be called in the
- * read_header function. If the flag AVFMT_NOHEADER is in the format
- * description, then new streams can be added in read_packet too.
- *
- *
- * @param s media file handle
- * @param id file format dependent stream id
- */
-AVStream *av_new_stream(AVFormatContext *s, int id)
-{
- AVStream *st;
-
- if (s->nb_streams >= MAX_STREAMS)
- return NULL;
-
- st = av_mallocz(sizeof(AVStream));
- if (!st)
- return NULL;
- avcodec_get_context_defaults(&st->codec);
- if (s->iformat) {
- /* no default bitrate if decoding */
- st->codec.bit_rate = 0;
- }
- st->index = s->nb_streams;
- st->id = id;
- st->start_time = AV_NOPTS_VALUE;
- st->duration = AV_NOPTS_VALUE;
- s->streams[s->nb_streams++] = st;
- return st;
-}
-
-/************************************************************/
-/* output media file */
-
-int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)
-{
- int ret;
-
- if (s->oformat->priv_data_size > 0) {
- s->priv_data = av_mallocz(s->oformat->priv_data_size);
- if (!s->priv_data)
- return AVERROR_NOMEM;
- } else
- s->priv_data = NULL;
-
- if (s->oformat->set_parameters) {
- ret = s->oformat->set_parameters(s, ap);
- if (ret < 0)
- return ret;
- }
- return 0;
-}
-
-/**
- * allocate the stream private data and write the stream header to an
- * output media file
- *
- * @param s media file handle
- * @return 0 if OK. AVERROR_xxx if error.
- */
-int av_write_header(AVFormatContext *s)
-{
- int ret, i;
- AVStream *st;
-
- /* default pts settings is MPEG like */
- av_set_pts_info(s, 33, 1, 90000);
- ret = s->oformat->write_header(s);
- if (ret < 0)
- return ret;
-
- /* init PTS generation */
- for(i=0;i<s->nb_streams;i++) {
- st = s->streams[i];
-
- switch (st->codec.codec_type) {
- case CODEC_TYPE_AUDIO:
- av_frac_init(&st->pts, 0, 0,
- (int64_t)s->pts_num * st->codec.sample_rate);
- break;
- case CODEC_TYPE_VIDEO:
- av_frac_init(&st->pts, 0, 0,
- (int64_t)s->pts_num * st->codec.frame_rate);
- break;
- default:
- break;
- }
- }
- return 0;
-}
-
-/**
- * Write a packet to an output media file. The packet shall contain
- * one audio or video frame.
- *
- * @param s media file handle
- * @param stream_index stream index
- * @param buf buffer containing the frame data
- * @param size size of buffer
- * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
- */
-int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
- int size)
-{
- AVStream *st;
- int64_t pts_mask;
- int ret, frame_size;
-
- st = s->streams[stream_index];
- pts_mask = (1LL << s->pts_wrap_bits) - 1;
- ret = s->oformat->write_packet(s, stream_index, (uint8_t *)buf, size,
- st->pts.val & pts_mask);
- if (ret < 0)
- return ret;
-
- /* update pts */
- switch (st->codec.codec_type) {
- case CODEC_TYPE_AUDIO:
- if (st->codec.frame_size <= 1) {
- frame_size = size / st->codec.channels;
- /* specific hack for pcm codecs because no frame size is provided */
- switch(st->codec.codec_id) {
- case CODEC_ID_PCM_S16LE:
- case CODEC_ID_PCM_S16BE:
- case CODEC_ID_PCM_U16LE:
- case CODEC_ID_PCM_U16BE:
- frame_size >>= 1;
- break;
- default:
- break;
- }
- } else {
- frame_size = st->codec.frame_size;
- }
- av_frac_add(&st->pts,
- (int64_t)s->pts_den * frame_size);
- break;
- case CODEC_TYPE_VIDEO:
- av_frac_add(&st->pts,
- (int64_t)s->pts_den * st->codec.frame_rate_base);
- break;
- default:
- break;
- }
- return ret;
-}
-
-/**
- * write the stream trailer to an output media file and and free the
- * file private data.
- *
- * @param s media file handle
- * @return 0 if OK. AVERROR_xxx if error. */
-int av_write_trailer(AVFormatContext *s)
-{
- int ret;
- ret = s->oformat->write_trailer(s);
- av_freep(&s->priv_data);
- return ret;
-}
-
-/* "user interface" functions */
-
-void dump_format(AVFormatContext *ic,
- int index,
- const char *url,
- int is_output)
-{
- int i, flags;
- char buf[256];
-
- fprintf(stderr, "%s #%d, %s, %s '%s':\n",
- is_output ? "Output" : "Input",
- index,
- is_output ? ic->oformat->name : ic->iformat->name,
- is_output ? "to" : "from", url);
- if (!is_output) {
- fprintf(stderr, " Duration: ");
- if (ic->duration != AV_NOPTS_VALUE) {
- int hours, mins, secs, us;
- secs = ic->duration / AV_TIME_BASE;
- us = ic->duration % AV_TIME_BASE;
- mins = secs / 60;
- secs %= 60;
- hours = mins / 60;
- mins %= 60;
- fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs,
- (10 * us) / AV_TIME_BASE);
- } else {
- fprintf(stderr, "N/A");
- }
- fprintf(stderr, ", bitrate: ");
- if (ic->bit_rate) {
- fprintf(stderr,"%d kb/s", ic->bit_rate / 1000);
- } else {
- fprintf(stderr, "N/A");
- }
- fprintf(stderr, "\n");
- }
- for(i=0;i<ic->nb_streams;i++) {
- AVStream *st = ic->streams[i];
- avcodec_string(buf, sizeof(buf), &st->codec, is_output);
- fprintf(stderr, " Stream #%d.%d", index, i);
- /* the pid is an important information, so we display it */
- /* XXX: add a generic system */
- if (is_output)
- flags = ic->oformat->flags;
- else
- flags = ic->iformat->flags;
- if (flags & AVFMT_SHOW_IDS) {
- fprintf(stderr, "[0x%x]", st->id);
- }
- fprintf(stderr, ": %s\n", buf);
- }
-}
-
-typedef struct {
- const char *abv;
- int width, height;
- int frame_rate, frame_rate_base;
-} AbvEntry;
-
-static AbvEntry frame_abvs[] = {
- { "ntsc", 720, 480, 30000, 1001 },
- { "pal", 720, 576, 25, 1 },
- { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */
- { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */
- { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */
- { "spal", 768, 576, 25, 1 }, /* square pixel pal */
- { "film", 352, 240, 24, 1 },
- { "ntsc-film", 352, 240, 24000, 1001 },
- { "sqcif", 128, 96, 0, 0 },
- { "qcif", 176, 144, 0, 0 },
- { "cif", 352, 288, 0, 0 },
- { "4cif", 704, 576, 0, 0 },
-};
-
-int parse_image_size(int *width_ptr, int *height_ptr, const char *str)
-{
- int i;
- int n = sizeof(frame_abvs) / sizeof(AbvEntry);
- const char *p;
- int frame_width = 0, frame_height = 0;
-
- for(i=0;i<n;i++) {
- if (!strcmp(frame_abvs[i].abv, str)) {
- frame_width = frame_abvs[i].width;
- frame_height = frame_abvs[i].height;
- break;
- }
- }
- if (i == n) {
- p = str;
- frame_width = strtol(p, (char **)&p, 10);
- if (*p)
- p++;
- frame_height = strtol(p, (char **)&p, 10);
- }
- if (frame_width <= 0 || frame_height <= 0)
- return -1;
- *width_ptr = frame_width;
- *height_ptr = frame_height;
- return 0;
-}
-
-int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg)
-{
- int i;
- char* cp;
-
- /* First, we check our abbreviation table */
- for (i = 0; i < sizeof(frame_abvs)/sizeof(*frame_abvs); ++i)
- if (!strcmp(frame_abvs[i].abv, arg)) {
- *frame_rate = frame_abvs[i].frame_rate;
- *frame_rate_base = frame_abvs[i].frame_rate_base;
- return 0;
- }
-
- /* Then, we try to parse it as fraction */
- cp = strchr(arg, '/');
- if (cp) {
- char* cpp;
- *frame_rate = strtol(arg, &cpp, 10);
- if (cpp != arg || cpp == cp)
- *frame_rate_base = strtol(cp+1, &cpp, 10);
- else
- *frame_rate = 0;
- }
- else {
- /* Finally we give up and parse it as double */
- *frame_rate_base = DEFAULT_FRAME_RATE_BASE;
- *frame_rate = (int)(strtod(arg, 0) * (*frame_rate_base) + 0.5);
- }
- if (!*frame_rate || !*frame_rate_base)
- return -1;
- else
- return 0;
-}
-
-/* Syntax:
- * - If not a duration:
- * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
- * Time is localtime unless Z is suffixed to the end. In this case GMT
- * Return the date in micro seconds since 1970
- * - If duration:
- * HH[:MM[:SS[.m...]]]
- * S+[.m...]
- */
-int64_t parse_date(const char *datestr, int duration)
-{
- const char *p;
- int64_t t;
- struct tm dt;
- int i;
- static const char *date_fmt[] = {
- "%Y-%m-%d",
- "%Y%m%d",
- };
- static const char *time_fmt[] = {
- "%H:%M:%S",
- "%H%M%S",
- };
- const char *q;
- int is_utc, len;
- char lastch;
- time_t now = time(0);
-
- len = strlen(datestr);
- if (len > 0)
- lastch = datestr[len - 1];
- else
- lastch = '\0';
- is_utc = (lastch == 'z' || lastch == 'Z');
-
- memset(&dt, 0, sizeof(dt));
-
- p = datestr;
- q = NULL;
- if (!duration) {
- for (i = 0; i < sizeof(date_fmt) / sizeof(date_fmt[0]); i++) {
- q = small_strptime(p, date_fmt[i], &dt);
- if (q) {
- break;
- }
- }
-
- if (!q) {
- if (is_utc) {
- dt = *gmtime(&now);
- } else {
- dt = *localtime(&now);
- }
- dt.tm_hour = dt.tm_min = dt.tm_sec = 0;
- } else {
- p = q;
- }
-
- if (*p == 'T' || *p == 't' || *p == ' ')
- p++;
-
- for (i = 0; i < sizeof(time_fmt) / sizeof(time_fmt[0]); i++) {
- q = small_strptime(p, time_fmt[i], &dt);
- if (q) {
- break;
- }
- }
- } else {
- q = small_strptime(p, time_fmt[0], &dt);
- if (!q) {
- dt.tm_sec = strtol(p, (char **)&q, 10);
- dt.tm_min = 0;
- dt.tm_hour = 0;
- }
- }
-
- /* Now we have all the fields that we can get */
- if (!q) {
- if (duration)
- return 0;
- else
- return now * int64_t_C(1000000);
- }
-
- if (duration) {
- t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
- } else {
- dt.tm_isdst = -1; /* unknown */
- if (is_utc) {
- t = mktimegm(&dt);
- } else {
- t = mktime(&dt);
- }
- }
-
- t *= 1000000;
-
- if (*q == '.') {
- int val, n;
- q++;
- for (val = 0, n = 100000; n >= 1; n /= 10, q++) {
- if (!isdigit(*q))
- break;
- val += n * (*q - '0');
- }
- t += val;
- }
- return t;
-}
-
-/* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
- 1 if found */
-int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
-{
- const char *p;
- char tag[128], *q;
-
- p = info;
- if (*p == '?')
- p++;
- for(;;) {
- q = tag;
- while (*p != '\0' && *p != '=' && *p != '&') {
- if ((q - tag) < sizeof(tag) - 1)
- *q++ = *p;
- p++;
- }
- *q = '\0';
- q = arg;
- if (*p == '=') {
- p++;
- while (*p != '&' && *p != '\0') {
- if ((q - arg) < arg_size - 1) {
- if (*p == '+')
- *q++ = ' ';
- else
- *q++ = *p;
- }
- p++;
- }
- *q = '\0';
- }
- if (!strcmp(tag, tag1))
- return 1;
- if (*p != '&')
- break;
- p++;
- }
- return 0;
-}
-
-/* Return in 'buf' the path with '%d' replaced by number. Also handles
- the '%0nd' format where 'n' is the total number of digits and
- '%%'. Return 0 if OK, and -1 if format error */
-int get_frame_filename(char *buf, int buf_size,
- const char *path, int number)
-{
- const char *p;
- char *q, buf1[20];
- int nd, len, c, percentd_found;
-
- q = buf;
- p = path;
- percentd_found = 0;
- for(;;) {
- c = *p++;
- if (c == '\0')
- break;
- if (c == '%') {
- do {
- nd = 0;
- while (isdigit(*p)) {
- nd = nd * 10 + *p++ - '0';
- }
- c = *p++;
- } while (isdigit(c));
-
- switch(c) {
- case '%':
- goto addchar;
- case 'd':
- if (percentd_found)
- goto fail;
- percentd_found = 1;
- snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
- len = strlen(buf1);
- if ((q - buf + len) > buf_size - 1)
- goto fail;
- memcpy(q, buf1, len);
- q += len;
- break;
- default:
- goto fail;
- }
- } else {
- addchar:
- if ((q - buf) < buf_size - 1)
- *q++ = c;
- }
- }
- if (!percentd_found)
- goto fail;
- *q = '\0';
- return 0;
- fail:
- *q = '\0';
- return -1;
-}
-
-/**
- *
- * Print on stdout a nice hexa dump of a buffer
- * @param buf buffer
- * @param size buffer size
- */
-void av_hex_dump(uint8_t *buf, int size)
-{
- int len, i, j, c;
-
- for(i=0;i<size;i+=16) {
- len = size - i;
- if (len > 16)
- len = 16;
- printf("%08x ", i);
- for(j=0;j<16;j++) {
- if (j < len)
- printf(" %02x", buf[i+j]);
- else
- printf(" ");
- }
- printf(" ");
- for(j=0;j<len;j++) {
- c = buf[i+j];
- if (c < ' ' || c > '~')
- c = '.';
- printf("%c", c);
- }
- printf("\n");
- }
-}
-
-void url_split(char *proto, int proto_size,
- char *hostname, int hostname_size,
- int *port_ptr,
- char *path, int path_size,
- const char *url)
-{
- const char *p;
- char *q;
- int port;
-
- port = -1;
-
- p = url;
- q = proto;
- while (*p != ':' && *p != '\0') {
- if ((q - proto) < proto_size - 1)
- *q++ = *p;
- p++;
- }
- if (proto_size > 0)
- *q = '\0';
- if (*p == '\0') {
- if (proto_size > 0)
- proto[0] = '\0';
- if (hostname_size > 0)
- hostname[0] = '\0';
- p = url;
- } else {
- p++;
- if (*p == '/')
- p++;
- if (*p == '/')
- p++;
- q = hostname;
- while (*p != ':' && *p != '/' && *p != '?' && *p != '\0') {
- if ((q - hostname) < hostname_size - 1)
- *q++ = *p;
- p++;
- }
- if (hostname_size > 0)
- *q = '\0';
- if (*p == ':') {
- p++;
- port = strtoul(p, (char **)&p, 10);
- }
- }
- if (port_ptr)
- *port_ptr = port;
- pstrcpy(path, path_size, p);
-}
-
-/**
- * Set the pts for a given stream
- * @param s stream
- * @param pts_wrap_bits number of bits effectively used by the pts
- * (used for wrap control, 33 is the value for MPEG)
- * @param pts_num numerator to convert to seconds (MPEG: 1)
- * @param pts_den denominator to convert to seconds (MPEG: 90000)
- */
-void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
- int pts_num, int pts_den)
-{
- s->pts_wrap_bits = pts_wrap_bits;
- s->pts_num = pts_num;
- s->pts_den = pts_den;
-}
-
-/* fraction handling */
-
-/**
- * f = val + (num / den) + 0.5. 'num' is normalized so that it is such
- * as 0 <= num < den.
- *
- * @param f fractional number
- * @param val integer value
- * @param num must be >= 0
- * @param den must be >= 1
- */
-void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
-{
- num += (den >> 1);
- if (num >= den) {
- val += num / den;
- num = num % den;
- }
- f->val = val;
- f->num = num;
- f->den = den;
-}
-
-/* set f to (val + 0.5) */
-void av_frac_set(AVFrac *f, int64_t val)
-{
- f->val = val;
- f->num = f->den >> 1;
-}
-
-/**
- * Fractionnal addition to f: f = f + (incr / f->den)
- *
- * @param f fractional number
- * @param incr increment, can be positive or negative
- */
-void av_frac_add(AVFrac *f, int64_t incr)
-{
- int64_t num, den;
-
- num = f->num + incr;
- den = f->den;
- if (num < 0) {
- f->val += num / den;
- num = num % den;
- if (num < 0) {
- num += den;
- f->val--;
- }
- } else if (num >= den) {
- f->val += num / den;
- num = num % den;
- }
- f->num = num;
-}
-
-/**
- * register a new image format
- * @param img_fmt Image format descriptor
- */
-void av_register_image_format(AVImageFormat *img_fmt)
-{
- AVImageFormat **p;
-
- p = &first_image_format;
- while (*p != NULL) p = &(*p)->next;
- *p = img_fmt;
- img_fmt->next = NULL;
-}
-
-/* guess image format */
-AVImageFormat *av_probe_image_format(AVProbeData *pd)
-{
- AVImageFormat *fmt1, *fmt;
- int score, score_max;
-
- fmt = NULL;
- score_max = 0;
- for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
- if (fmt1->img_probe) {
- score = fmt1->img_probe(pd);
- if (score > score_max) {
- score_max = score;
- fmt = fmt1;
- }
- }
- }
- return fmt;
-}
-
-AVImageFormat *guess_image_format(const char *filename)
-{
- AVImageFormat *fmt1;
-
- for(fmt1 = first_image_format; fmt1 != NULL; fmt1 = fmt1->next) {
- if (fmt1->extensions && match_ext(filename, fmt1->extensions))
- return fmt1;
- }
- return NULL;
-}
-
-/**
- * Read an image from a stream.
- * @param gb byte stream containing the image
- * @param fmt image format, NULL if probing is required
- */
-int av_read_image(ByteIOContext *pb, const char *filename,
- AVImageFormat *fmt,
- int (*alloc_cb)(void *, AVImageInfo *info), void *opaque)
-{
- char buf[PROBE_BUF_SIZE];
- AVProbeData probe_data, *pd = &probe_data;
- offset_t pos;
- int ret;
-
- if (!fmt) {
- pd->filename = filename;
- pd->buf = buf;
- pos = url_ftell(pb);
- pd->buf_size = get_buffer(pb, buf, PROBE_BUF_SIZE);
- url_fseek(pb, pos, SEEK_SET);
- fmt = av_probe_image_format(pd);
- }
- if (!fmt)
- return AVERROR_NOFMT;
- ret = fmt->img_read(pb, alloc_cb, opaque);
- return ret;
-}
-
-/**
- * Write an image to a stream.
- * @param pb byte stream for the image output
- * @param fmt image format
- * @param img image data and informations
- */
-int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img)
-{
- return fmt->img_write(pb, img);
-}
-
+++ /dev/null
-/*
- * WAV encoder and decoder
- * Copyright (c) 2001, 2002 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-#include "avi.h"
-
-const CodecTag codec_wav_tags[] = {
- { CODEC_ID_MP2, 0x50 },
- { CODEC_ID_MP3, 0x55 },
- { CODEC_ID_AC3, 0x2000 },
- { CODEC_ID_PCM_S16LE, 0x01 },
- { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */
- { CODEC_ID_PCM_ALAW, 0x06 },
- { CODEC_ID_PCM_MULAW, 0x07 },
- { CODEC_ID_ADPCM_MS, 0x02 },
- { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
- { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */
- { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */
- { CODEC_ID_WMAV1, 0x160 },
- { CODEC_ID_WMAV2, 0x161 },
- { 0, 0 },
-};
-
-/* WAVEFORMATEX header */
-/* returns the size or -1 on error */
-int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
-{
- int bps, blkalign, bytespersec;
- int hdrsize = 18;
-
- if(!enc->codec_tag)
- enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
- if(!enc->codec_tag)
- return -1;
-
- put_le16(pb, enc->codec_tag);
- put_le16(pb, enc->channels);
- put_le32(pb, enc->sample_rate);
- if (enc->codec_id == CODEC_ID_PCM_U8 ||
- enc->codec_id == CODEC_ID_PCM_ALAW ||
- enc->codec_id == CODEC_ID_PCM_MULAW) {
- bps = 8;
- } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
- bps = 0;
- } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS) {
- bps = 4;
- } else {
- bps = 16;
- }
-
- if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
- blkalign = 1;
- //blkalign = 144 * enc->bit_rate/enc->sample_rate;
- } else if (enc->block_align != 0) { /* specified by the codec */
- blkalign = enc->block_align;
- } else
- blkalign = enc->channels*bps >> 3;
- if (enc->codec_id == CODEC_ID_PCM_U8 ||
- enc->codec_id == CODEC_ID_PCM_S16LE) {
- bytespersec = enc->sample_rate * blkalign;
- } else {
- bytespersec = enc->bit_rate / 8;
- }
- put_le32(pb, bytespersec); /* bytes per second */
- put_le16(pb, blkalign); /* block align */
- put_le16(pb, bps); /* bits per sample */
- if (enc->codec_id == CODEC_ID_MP3) {
- put_le16(pb, 12); /* wav_extra_size */
- hdrsize += 12;
- put_le16(pb, 1); /* wID */
- put_le32(pb, 2); /* fdwFlags */
- put_le16(pb, 1152); /* nBlockSize */
- put_le16(pb, 1); /* nFramesPerBlock */
- put_le16(pb, 1393); /* nCodecDelay */
- } else if (enc->codec_id == CODEC_ID_MP2) {
- put_le16(pb, 22); /* wav_extra_size */
- hdrsize += 22;
- put_le16(pb, 2); /* fwHeadLayer */
- put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
- put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */
- put_le16(pb, 0); /* fwHeadModeExt */
- put_le16(pb, 1); /* wHeadEmphasis */
- put_le16(pb, 16); /* fwHeadFlags */
- put_le32(pb, 0); /* dwPTSLow */
- put_le32(pb, 0); /* dwPTSHigh */
- } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
- put_le16(pb, 2); /* wav_extra_size */
- put_le16(pb, ((enc->block_align - 4 * enc->channels) / (4 * enc->channels)) * 8 + 1); /* wSamplesPerBlock */
- } else
- put_le16(pb, 0); /* wav_extra_size */
-
- return hdrsize;
-}
-
-/* We could be given one of the three possible structures here:
- * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
- * is an expansion of the previous one with the fields added
- * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
- * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
- * an openended structure.
- */
-void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
-{
- int id;
-
- id = get_le16(pb);
- codec->codec_type = CODEC_TYPE_AUDIO;
- codec->codec_tag = id;
- codec->channels = get_le16(pb);
- codec->sample_rate = get_le32(pb);
- codec->bit_rate = get_le32(pb) * 8;
- codec->block_align = get_le16(pb);
- if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
- codec->bits_per_sample = 8;
- }else
- codec->bits_per_sample = get_le16(pb);
- codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample);
-
- if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */
- codec->extradata_size = get_le16(pb);
- if (codec->extradata_size > 0) {
- if (codec->extradata_size > size - 18)
- codec->extradata_size = size - 18;
- codec->extradata = av_mallocz(codec->extradata_size);
- get_buffer(pb, codec->extradata, codec->extradata_size);
- } else
- codec->extradata_size = 0;
-
- /* It is possible for the chunk to contain garbage at the end */
- if (size - codec->extradata_size - 18 > 0)
- url_fskip(pb, size - codec->extradata_size - 18);
- }
-}
-
-
-int wav_codec_get_id(unsigned int tag, int bps)
-{
- int id;
- id = codec_get_id(codec_wav_tags, tag);
- if (id <= 0)
- return id;
- /* handle specific u8 codec */
- if (id == CODEC_ID_PCM_S16LE && bps == 8)
- id = CODEC_ID_PCM_U8;
- return id;
-}
-
-typedef struct {
- offset_t data;
-} WAVContext;
-
-static int wav_write_header(AVFormatContext *s)
-{
- WAVContext *wav = s->priv_data;
- ByteIOContext *pb = &s->pb;
- offset_t fmt;
-
- put_tag(pb, "RIFF");
- put_le32(pb, 0); /* file length */
- put_tag(pb, "WAVE");
-
- /* format header */
- fmt = start_tag(pb, "fmt ");
- if (put_wav_header(pb, &s->streams[0]->codec) < 0) {
- av_free(wav);
- return -1;
- }
- end_tag(pb, fmt);
-
- /* data header */
- wav->data = start_tag(pb, "data");
-
- put_flush_packet(pb);
-
- return 0;
-}
-
-static int wav_write_packet(AVFormatContext *s, int stream_index_ptr,
- const uint8_t *buf, int size, int64_t pts)
-{
- ByteIOContext *pb = &s->pb;
- put_buffer(pb, buf, size);
- return 0;
-}
-
-static int wav_write_trailer(AVFormatContext *s)
-{
- ByteIOContext *pb = &s->pb;
- WAVContext *wav = s->priv_data;
- offset_t file_size;
-
- if (!url_is_streamed(&s->pb)) {
- end_tag(pb, wav->data);
-
- /* update file size */
- file_size = url_ftell(pb);
- url_fseek(pb, 4, SEEK_SET);
- put_le32(pb, (uint32_t)(file_size - 8));
- url_fseek(pb, file_size, SEEK_SET);
-
- put_flush_packet(pb);
- }
- return 0;
-}
-
-/* return the size of the found tag */
-/* XXX: > 2GB ? */
-static int find_tag(ByteIOContext *pb, uint32_t tag1)
-{
- unsigned int tag;
- int size;
-
- for(;;) {
- if (url_feof(pb))
- return -1;
- tag = get_le32(pb);
- size = get_le32(pb);
- if (tag == tag1)
- break;
- url_fseek(pb, size, SEEK_CUR);
- }
- if (size < 0)
- size = 0x7fffffff;
- return size;
-}
-
-static int wav_probe(AVProbeData *p)
-{
- /* check file header */
- if (p->buf_size <= 32)
- return 0;
- if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
- p->buf[2] == 'F' && p->buf[3] == 'F' &&
- p->buf[8] == 'W' && p->buf[9] == 'A' &&
- p->buf[10] == 'V' && p->buf[11] == 'E')
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-/* wav input */
-static int wav_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- int size;
- unsigned int tag;
- ByteIOContext *pb = &s->pb;
- AVStream *st;
-
- /* check RIFF header */
- tag = get_le32(pb);
-
- if (tag != MKTAG('R', 'I', 'F', 'F'))
- return -1;
- get_le32(pb); /* file size */
- tag = get_le32(pb);
- if (tag != MKTAG('W', 'A', 'V', 'E'))
- return -1;
-
- /* parse fmt header */
- size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
- if (size < 0)
- return -1;
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
-
- get_wav_header(pb, &st->codec, size);
-
- size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
- if (size < 0)
- return -1;
- return 0;
-}
-
-#define MAX_SIZE 4096
-
-static int wav_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- int ret;
-
- if (url_feof(&s->pb))
- return -EIO;
- if (av_new_packet(pkt, MAX_SIZE))
- return -EIO;
- pkt->stream_index = 0;
-
- ret = get_buffer(&s->pb, pkt->data, pkt->size);
- if (ret < 0)
- av_free_packet(pkt);
- /* note: we need to modify the packet size here to handle the last
- packet */
- pkt->size = ret;
- return ret;
-}
-
-static int wav_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-static AVInputFormat wav_iformat = {
- "wav",
- "wav format",
- 0,
- wav_probe,
- wav_read_header,
- wav_read_packet,
- wav_read_close,
-};
-
-static AVOutputFormat wav_oformat = {
- "wav",
- "wav format",
- "audio/x-wav",
- "wav",
- sizeof(WAVContext),
- CODEC_ID_PCM_S16LE,
- CODEC_ID_NONE,
- wav_write_header,
- wav_write_packet,
- wav_write_trailer,
-};
-
-int wav_init(void)
-{
- av_register_input_format(&wav_iformat);
- av_register_output_format(&wav_oformat);
- return 0;
-}
+++ /dev/null
-/*
- * Wing Commander III Movie (.mve) File Demuxer
- * Copyright (c) 2003 The ffmpeg Project
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/**
- * @file wc3movie.c
- * Wing Commander III Movie file demuxer
- * by Mike Melanson (melanson@pcisys.net)
- * for more information on the WC3 .mve file format, visit:
- * http://www.pcisys.net/~melanson/codecs/
- */
-
-#include "avformat.h"
-
-#define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
-#define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
- (((uint8_t*)(x))[2] << 16) | \
- (((uint8_t*)(x))[1] << 8) | \
- ((uint8_t*)(x))[0])
-#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
-#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
- (((uint8_t*)(x))[1] << 16) | \
- (((uint8_t*)(x))[2] << 8) | \
- ((uint8_t*)(x))[3])
-
-#define WC3_PREAMBLE_SIZE 8
-
-#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
- ( (long)(unsigned char)(ch0) | \
- ( (long)(unsigned char)(ch1) << 8 ) | \
- ( (long)(unsigned char)(ch2) << 16 ) | \
- ( (long)(unsigned char)(ch3) << 24 ) )
-
-#define FORM_TAG FOURCC_TAG('F', 'O', 'R', 'M')
-#define MOVE_TAG FOURCC_TAG('M', 'O', 'V', 'E')
-#define _PC__TAG FOURCC_TAG('_', 'P', 'C', '_')
-#define SOND_TAG FOURCC_TAG('S', 'O', 'N', 'D')
-#define BNAM_TAG FOURCC_TAG('B', 'N', 'A', 'M')
-#define SIZE_TAG FOURCC_TAG('S', 'I', 'Z', 'E')
-#define PALT_TAG FOURCC_TAG('P', 'A', 'L', 'T')
-#define INDX_TAG FOURCC_TAG('I', 'N', 'D', 'X')
-#define BRCH_TAG FOURCC_TAG('B', 'R', 'C', 'H')
-#define SHOT_TAG FOURCC_TAG('S', 'H', 'O', 'T')
-#define VGA__TAG FOURCC_TAG('V', 'G', 'A', ' ')
-#define TEXT_TAG FOURCC_TAG('T', 'E', 'X', 'T')
-#define AUDI_TAG FOURCC_TAG('A', 'U', 'D', 'I')
-
-/* video resolution unless otherwise specified */
-#define WC3_DEFAULT_WIDTH 320
-#define WC3_DEFAULT_HEIGHT 165
-
-/* always use the same PCM audio parameters */
-#define WC3_SAMPLE_RATE 22050
-#define WC3_AUDIO_CHANNELS 1
-#define WC3_AUDIO_BITS 16
-
-/* nice, constant framerate */
-#define WC3_FRAME_PTS_INC (90000 / 15)
-
-#define PALETTE_SIZE (256 * 3)
-#define PALETTE_COUNT 256
-
-typedef struct Wc3DemuxContext {
- int width;
- int height;
- unsigned char *palettes;
- int palette_count;
- int64_t pts;
- int video_stream_index;
- int audio_stream_index;
-
- AVPaletteControl palette_control;
-
-} Wc3DemuxContext;
-
-/* bizarre palette lookup table */
-static const unsigned char wc3_pal_lookup[] = {
- 0x00, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0E,
- 0x10, 0x12, 0x13, 0x15, 0x16, 0x18, 0x19, 0x1A,
- 0x1C, 0x1D, 0x1F, 0x20, 0x21, 0x23, 0x24, 0x25,
- 0x27, 0x28, 0x29, 0x2A, 0x2C, 0x2D, 0x2E, 0x2F,
- 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x38, 0x39,
- 0x3A, 0x3B, 0x3C, 0x3D, 0x3F, 0x40, 0x41, 0x42,
- 0x43, 0x44, 0x45, 0x46, 0x48, 0x49, 0x4A, 0x4B,
- 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53,
- 0x54, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C,
- 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64,
- 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C,
- 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74,
- 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C,
- 0x7D, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83,
- 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B,
- 0x8C, 0x8D, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92,
- 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x99,
- 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1,
- 0xA2, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
- 0xA9, 0xAA, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
- 0xB0, 0xB1, 0xB2, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6,
- 0xB7, 0xB8, 0xB9, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD,
- 0xBE, 0xBF, 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4,
- 0xC5, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB,
- 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD0, 0xD1,
- 0xD2, 0xD3, 0xD4, 0xD5, 0xD5, 0xD6, 0xD7, 0xD8,
- 0xD9, 0xDA, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
- 0xDF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE4, 0xE5,
- 0xE6, 0xE7, 0xE8, 0xE9, 0xE9, 0xEA, 0xEB, 0xEC,
- 0xED, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF1, 0xF2,
- 0xF3, 0xF4, 0xF5, 0xF6, 0xF6, 0xF7, 0xF8, 0xF9,
- 0xFA, 0xFA, 0xFB, 0xFC, 0xFD, 0xFD, 0xFD, 0xFD
-};
-
-
-static int wc3_probe(AVProbeData *p)
-{
- if (p->buf_size < 12)
- return 0;
-
- if ((LE_32(&p->buf[0]) != FORM_TAG) ||
- (LE_32(&p->buf[8]) != MOVE_TAG))
- return 0;
-
- return AVPROBE_SCORE_MAX;
-}
-
-static int wc3_read_header(AVFormatContext *s,
- AVFormatParameters *ap)
-{
- Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
- ByteIOContext *pb = &s->pb;
- unsigned int fourcc_tag;
- unsigned int size;
- AVStream *st;
- unsigned char preamble[WC3_PREAMBLE_SIZE];
- int ret = 0;
- int current_palette = 0;
- int bytes_to_read;
- int i;
- unsigned char rotate;
-
- /* default context members */
- wc3->width = WC3_DEFAULT_WIDTH;
- wc3->height = WC3_DEFAULT_HEIGHT;
- wc3->palettes = NULL;
- wc3->palette_count = 0;
- wc3->pts = 0;
- wc3->video_stream_index = wc3->audio_stream_index = 0;
-
- /* skip the first 3 32-bit numbers */
- url_fseek(pb, 12, SEEK_CUR);
-
- /* traverse through the chunks and load the header information before
- * the first BRCH tag */
- if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
- WC3_PREAMBLE_SIZE)
- return -EIO;
- fourcc_tag = LE_32(&preamble[0]);
- size = (BE_32(&preamble[4]) + 1) & (~1);
-
- do {
- switch (fourcc_tag) {
-
- case SOND_TAG:
- case INDX_TAG:
- /* SOND unknown, INDX unnecessary; ignore both */
- url_fseek(pb, size, SEEK_CUR);
- break;
-
- case _PC__TAG:
- /* need the number of palettes */
- url_fseek(pb, 8, SEEK_CUR);
- if ((ret = get_buffer(pb, preamble, 4)) != 4)
- return -EIO;
- wc3->palette_count = LE_32(&preamble[0]);
- wc3->palettes = av_malloc(wc3->palette_count * PALETTE_SIZE);
- break;
-
- case BNAM_TAG:
- /* load up the name */
- if (size < 512)
- bytes_to_read = size;
- else
- bytes_to_read = 512;
- if ((ret = get_buffer(pb, s->title, bytes_to_read)) != bytes_to_read)
- return -EIO;
- break;
-
- case SIZE_TAG:
- /* video resolution override */
- if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
- WC3_PREAMBLE_SIZE)
- return -EIO;
- wc3->width = LE_32(&preamble[0]);
- wc3->height = LE_32(&preamble[4]);
- break;
-
- case PALT_TAG:
- /* one of several palettes */
- if (current_palette >= wc3->palette_count)
- return AVERROR_INVALIDDATA;
- if ((ret = get_buffer(pb,
- &wc3->palettes[current_palette * PALETTE_SIZE],
- PALETTE_SIZE)) != PALETTE_SIZE)
- return -EIO;
-
- /* transform the current palette in place */
- for (i = current_palette * PALETTE_SIZE;
- i < (current_palette + 1) * PALETTE_SIZE; i++) {
- /* rotate each palette component left by 2 and use the result
- * as an index into the color component table */
- rotate = ((wc3->palettes[i] << 2) & 0xFF) |
- ((wc3->palettes[i] >> 6) & 0xFF);
- wc3->palettes[i] = wc3_pal_lookup[rotate];
- }
- current_palette++;
- break;
-
- default:
- printf (" unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
- preamble[0], preamble[1], preamble[2], preamble[3],
- preamble[0], preamble[1], preamble[2], preamble[3]);
- return AVERROR_INVALIDDATA;
- break;
- }
-
- if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
- WC3_PREAMBLE_SIZE)
- return -EIO;
- fourcc_tag = LE_32(&preamble[0]);
- /* chunk sizes are 16-bit aligned */
- size = (BE_32(&preamble[4]) + 1) & (~1);
-
- } while (fourcc_tag != BRCH_TAG);
-
- /* initialize the decoder streams */
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- wc3->video_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_XAN_WC3;
- st->codec.codec_tag = 0; /* no fourcc */
- st->codec.width = wc3->width;
- st->codec.height = wc3->height;
-
- /* palette considerations */
- st->codec.extradata_size = sizeof(AVPaletteControl);
- st->codec.extradata = &wc3->palette_control;
-
- st = av_new_stream(s, 0);
- if (!st)
- return AVERROR_NOMEM;
- wc3->audio_stream_index = st->index;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_id = CODEC_ID_PCM_S16LE;
- st->codec.codec_tag = 1;
- st->codec.channels = WC3_AUDIO_CHANNELS;
- st->codec.bits_per_sample = WC3_AUDIO_BITS;
- st->codec.sample_rate = WC3_SAMPLE_RATE;
- st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
- st->codec.bits_per_sample;
- st->codec.block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS;
-
- /* set the pts reference (1 pts = 1/90000) */
- s->pts_num = 1;
- s->pts_den = 90000;
-
- return 0;
-}
-
-static int wc3_read_packet(AVFormatContext *s,
- AVPacket *pkt)
-{
- Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
- ByteIOContext *pb = &s->pb;
- unsigned int fourcc_tag;
- unsigned int size;
- int packet_read = 0;
- int ret = 0;
- unsigned char preamble[WC3_PREAMBLE_SIZE];
- unsigned char text[1024];
- unsigned int palette_number;
-
- while (!packet_read) {
-
- /* get the next chunk preamble */
- if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) !=
- WC3_PREAMBLE_SIZE)
- ret = -EIO;
-
- fourcc_tag = LE_32(&preamble[0]);
- /* chunk sizes are 16-bit aligned */
- size = (BE_32(&preamble[4]) + 1) & (~1);
-
- switch (fourcc_tag) {
-
- case BRCH_TAG:
- /* no-op */
- break;
-
- case SHOT_TAG:
- /* load up new palette */
- if ((ret = get_buffer(pb, preamble, 4)) != 4)
- return -EIO;
- palette_number = LE_32(&preamble[0]);
- if (palette_number >= wc3->palette_count)
- return AVERROR_INVALIDDATA;
- memcpy(wc3->palette_control.palette,
- &wc3->palettes[palette_number * PALETTE_COUNT * 3],
- PALETTE_COUNT * 3);
- wc3->palette_control.palette_changed = 1;
- break;
-
- case VGA__TAG:
- /* send out video chunk */
- if (av_new_packet(pkt, size))
- ret = -EIO;
- pkt->stream_index = wc3->video_stream_index;
- pkt->pts = wc3->pts;
- ret = get_buffer(pb, pkt->data, size);
- if (ret != size)
- ret = -EIO;
- packet_read = 1;
- break;
-
- case TEXT_TAG:
- /* subtitle chunk */
-#if 0
- url_fseek(pb, size, SEEK_CUR);
-#else
- if ((ret = get_buffer(pb, text, size)) != size)
- ret = -EIO;
- else {
- int i = 0;
- printf ("Subtitle time!\n");
- printf (" inglish: %s\n", &text[i + 1]);
- i += text[i] + 1;
- printf (" doytsch: %s\n", &text[i + 1]);
- i += text[i] + 1;
- printf (" fronsay: %s\n", &text[i + 1]);
- }
-#endif
- break;
-
- case AUDI_TAG:
- /* send out audio chunk */
- if (av_new_packet(pkt, size))
- ret = -EIO;
- pkt->stream_index = wc3->audio_stream_index;
- pkt->pts = wc3->pts;
- ret = get_buffer(pb, pkt->data, size);
- if (ret != size)
- ret = -EIO;
-
- /* time to advance pts */
- wc3->pts += WC3_FRAME_PTS_INC;
-
- packet_read = 1;
- break;
-
- default:
- printf (" unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
- preamble[0], preamble[1], preamble[2], preamble[3],
- preamble[0], preamble[1], preamble[2], preamble[3]);
- ret = AVERROR_INVALIDDATA;
- packet_read = 1;
- break;
- }
- }
-
- return ret;
-}
-
-static int wc3_read_close(AVFormatContext *s)
-{
- Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data;
-
- av_free(wc3->palettes);
-
- return 0;
-}
-
-static AVInputFormat wc3_iformat = {
- "wc3movie",
- "Wing Commander III movie format",
- sizeof(Wc3DemuxContext),
- wc3_probe,
- wc3_read_header,
- wc3_read_packet,
- wc3_read_close,
-};
-
-int wc3_init(void)
-{
- av_register_input_format(&wc3_iformat);
- return 0;
-}
+++ /dev/null
-/*
- * .Y.U.V image format
- * Copyright (c) 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-static int sizes[][2] = {
- { 640, 480 },
- { 720, 480 },
- { 720, 576 },
- { 352, 288 },
- { 352, 240 },
- { 160, 128 },
- { 512, 384 },
- { 640, 352 },
- { 640, 240 },
-};
-
-static int infer_size(int *width_ptr, int *height_ptr, int size)
-{
- int i;
-
- for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
- if ((sizes[i][0] * sizes[i][1]) == size) {
- *width_ptr = sizes[i][0];
- *height_ptr = sizes[i][1];
- return 0;
- }
- }
- return -1;
-}
-
-static int yuv_read(ByteIOContext *f,
- int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque)
-{
- ByteIOContext pb1, *pb = &pb1;
- int img_size, ret;
- char fname[1024], *p;
- int size;
- URLContext *h;
- AVImageInfo info1, *info = &info1;
-
- /* XXX: hack hack */
- h = url_fileno(f);
- img_size = url_seek(h, 0, SEEK_END);
- url_get_filename(h, fname, sizeof(fname));
-
- if (infer_size(&info->width, &info->height, img_size) < 0) {
- return -EIO;
- }
- info->pix_fmt = PIX_FMT_YUV420P;
-
- ret = alloc_cb(opaque, info);
- if (ret)
- return ret;
-
- size = info->width * info->height;
-
- p = strrchr(fname, '.');
- if (!p || p[1] != 'Y')
- return -EIO;
-
- get_buffer(f, info->pict.data[0], size);
-
- p[1] = 'U';
- if (url_fopen(pb, fname, URL_RDONLY) < 0)
- return -EIO;
-
- get_buffer(pb, info->pict.data[1], size / 4);
- url_fclose(pb);
-
- p[1] = 'V';
- if (url_fopen(pb, fname, URL_RDONLY) < 0)
- return -EIO;
-
- get_buffer(pb, info->pict.data[2], size / 4);
- url_fclose(pb);
- return 0;
-}
-
-static int yuv_write(ByteIOContext *pb2, AVImageInfo *info)
-{
- ByteIOContext pb1, *pb;
- char fname[1024], *p;
- int i, j, width, height;
- uint8_t *ptr;
- URLContext *h;
- static const char *ext = "YUV";
-
- /* XXX: hack hack */
- h = url_fileno(pb2);
- url_get_filename(h, fname, sizeof(fname));
-
- p = strrchr(fname, '.');
- if (!p || p[1] != 'Y')
- return -EIO;
-
- width = info->width;
- height = info->height;
-
- for(i=0;i<3;i++) {
- if (i == 1) {
- width >>= 1;
- height >>= 1;
- }
-
- if (i >= 1) {
- pb = &pb1;
- p[1] = ext[i];
- if (url_fopen(pb, fname, URL_WRONLY) < 0)
- return -EIO;
- } else {
- pb = pb2;
- }
-
- ptr = info->pict.data[i];
- for(j=0;j<height;j++) {
- put_buffer(pb, ptr, width);
- ptr += info->pict.linesize[i];
- }
- put_flush_packet(pb);
- if (i >= 1) {
- url_fclose(pb);
- }
- }
- return 0;
-}
-
-static int yuv_probe(AVProbeData *pd)
-{
- if (match_ext(pd->filename, "Y"))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
-}
-
-AVImageFormat yuv_image_format = {
- "yuv",
- "Y",
- yuv_probe,
- yuv_read,
- (1 << PIX_FMT_YUV420P),
- yuv_write,
-};
+++ /dev/null
-/*
- * YUV4MPEG format
- * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include "avformat.h"
-
-#define Y4M_MAGIC "YUV4MPEG2"
-#define Y4M_FRAME_MAGIC "FRAME"
-#define Y4M_LINE_MAX 256
-
-static int yuv4_write_header(AVFormatContext *s)
-{
- AVStream *st;
- int width, height;
- int raten, rated, aspectn, aspectd, n;
- char buf[Y4M_LINE_MAX+1];
-
- if (s->nb_streams != 1)
- return -EIO;
-
- st = s->streams[0];
- width = st->codec.width;
- height = st->codec.height;
-
-#if 1
- //this is identical to the code below for exact fps
- av_reduce(&raten, &rated, st->codec.frame_rate, st->codec.frame_rate_base, (1UL<<31)-1);
-#else
- {
- int gcd, fps, fps1;
-
- fps = st->codec.frame_rate;
- fps1 = (((float)fps / st->codec.frame_rate_base) * 1000);
-
- /* Sorry about this messy code, but mpeg2enc is very picky about
- * the framerates it accepts. */
- switch(fps1) {
- case 23976:
- raten = 24000; /* turn the framerate into a ratio */
- rated = 1001;
- break;
- case 29970:
- raten = 30000;
- rated = 1001;
- break;
- case 25000:
- raten = 25;
- rated = 1;
- break;
- case 30000:
- raten = 30;
- rated = 1;
- break;
- case 24000:
- raten = 24;
- rated = 1;
- break;
- case 50000:
- raten = 50;
- rated = 1;
- break;
- case 59940:
- raten = 60000;
- rated = 1001;
- break;
- case 60000:
- raten = 60;
- rated = 1;
- break;
- default:
- raten = st->codec.frame_rate; /* this setting should work, but often doesn't */
- rated = st->codec.frame_rate_base;
- gcd= av_gcd(raten, rated);
- raten /= gcd;
- rated /= gcd;
- break;
- }
- }
-#endif
-
- aspectn = 1;
- aspectd = 1; /* ffmpeg always uses a 1:1 aspect ratio */ //FIXME not true anymore
-
- /* construct stream header, if this is the first frame */
- n = snprintf(buf, sizeof(buf), "%s W%d H%d F%d:%d I%s A%d:%d\n",
- Y4M_MAGIC,
- width,
- height,
- raten, rated,
- "p", /* ffmpeg seems to only output progressive video */
- aspectn, aspectd);
- if (n < 0) {
- fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
- return -EIO;
- } else {
- put_buffer(&s->pb, buf, strlen(buf));
- }
- return 0;
-}
-
-static int yuv4_write_packet(AVFormatContext *s, int stream_index,
- const uint8_t *buf, int size, int64_t pts)
-{
- AVStream *st = s->streams[stream_index];
- ByteIOContext *pb = &s->pb;
- AVPicture *picture;
- int width, height;
- int i, m;
- char buf1[20];
- uint8_t *ptr, *ptr1, *ptr2;
-
- picture = (AVPicture *)buf;
-
- /* construct frame header */
- m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
- put_buffer(pb, buf1, strlen(buf1));
-
- width = st->codec.width;
- height = st->codec.height;
-
- ptr = picture->data[0];
- for(i=0;i<height;i++) {
- put_buffer(pb, ptr, width);
- ptr += picture->linesize[0];
- }
-
- height >>= 1;
- width >>= 1;
- ptr1 = picture->data[1];
- ptr2 = picture->data[2];
- for(i=0;i<height;i++) { /* Cb */
- put_buffer(pb, ptr1, width);
- ptr1 += picture->linesize[1];
- }
- for(i=0;i<height;i++) { /* Cr */
- put_buffer(pb, ptr2, width);
- ptr2 += picture->linesize[2];
- }
- put_flush_packet(pb);
- return 0;
-}
-
-static int yuv4_write_trailer(AVFormatContext *s)
-{
- return 0;
-}
-
-AVOutputFormat yuv4mpegpipe_oformat = {
- "yuv4mpegpipe",
- "YUV4MPEG pipe format",
- "",
- "yuv4mpeg",
- 0,
- CODEC_ID_NONE,
- CODEC_ID_RAWVIDEO,
- yuv4_write_header,
- yuv4_write_packet,
- yuv4_write_trailer,
- .flags = AVFMT_RAWPICTURE,
-};
-
-/* Header size increased to allow room for optional flags */
-#define MAX_YUV4_HEADER 80
-#define MAX_FRAME_HEADER 10
-
-static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
-{
- char header[MAX_YUV4_HEADER+1];
- int i;
- ByteIOContext *pb = &s->pb;
- int width, height, raten, rated, aspectn, aspectd;
- char lacing;
- AVStream *st;
-
- for (i=0; i<MAX_YUV4_HEADER; i++) {
- header[i] = get_byte(pb);
- if (header[i] == '\n') {
- header[i+1] = 0;
- break;
- }
- }
- if (i == MAX_YUV4_HEADER) return -1;
- if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1;
- sscanf(header+strlen(Y4M_MAGIC), " W%d H%d F%d:%d I%c A%d:%d",
- &width, &height, &raten, &rated, &lacing, &aspectn, &aspectd);
-
- st = av_new_stream(s, 0);
- st = s->streams[0];
- st->codec.width = width;
- st->codec.height = height;
- av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1);
- st->codec.frame_rate = raten;
- st->codec.frame_rate_base = rated;
- st->codec.pix_fmt = PIX_FMT_YUV420P;
- st->codec.codec_type = CODEC_TYPE_VIDEO;
- st->codec.codec_id = CODEC_ID_RAWVIDEO;
-
- return 0;
-}
-
-static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
-{
- int i;
- char header[MAX_FRAME_HEADER+1];
- int packet_size, ret, width, height;
- AVStream *st = s->streams[0];
-
- for (i=0; i<MAX_FRAME_HEADER; i++) {
- header[i] = get_byte(&s->pb);
- if (header[i] == '\n') {
- header[i+1] = 0;
- break;
- }
- }
- if (i == MAX_FRAME_HEADER) return -1;
- if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1;
-
- width = st->codec.width;
- height = st->codec.height;
-
- packet_size = avpicture_get_size(st->codec.pix_fmt, width, height);
- if (packet_size < 0)
- av_abort();
-
- if (av_new_packet(pkt, packet_size) < 0)
- return -EIO;
-
- pkt->stream_index = 0;
- ret = get_buffer(&s->pb, pkt->data, pkt->size);
- if (ret != pkt->size) {
- av_free_packet(pkt);
- return -EIO;
- } else {
- return 0;
- }
-}
-
-static int yuv4_read_close(AVFormatContext *s)
-{
- return 0;
-}
-
-AVInputFormat yuv4mpegpipe_iformat = {
- "yuv4mpegpipe",
- "YUV4MPEG pipe format",
- 0,
- NULL,
- yuv4_read_header,
- yuv4_read_packet,
- yuv4_read_close,
- .extensions = "yuv4mpeg"
-};
-
-int yuv4mpeg_init(void)
-{
- av_register_input_format(&yuv4mpegpipe_iformat);
- av_register_output_format(&yuv4mpegpipe_oformat);
- return 0;
-}
-
extern "C"
{
-#include "libavformat/avformat.h"
+#include <avformat.h>
}
#include <synfig/general.h>
AVCodecContext *context;
//get from inside stream
- context = &stream->codec;
+ context = stream->codec;
//search for desired codec (contained in the stream)
codec = avcodec_find_encoder(context->codec_id);
int size,
ret = 0;
- AVCodecContext *context = &stream->codec;
+ AVCodecContext *context = stream->codec;
/*
If pict is invalid (NULL), then we are done compressing frames and we are trying to get
pict = encodable;
}
+ AVPacket pkt;
+ av_init_packet(&pkt);
+ pkt.stream_index = stream->index;
+ pkt.data = (uint8_t *)pict;
+ pkt.size = sizeof(AVPicture);
+ if( context->coded_frame )
+ pkt.pts = context->coded_frame->pts;
+ if( context->coded_frame && context->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+
//cludge for raw picture format (they said they'd fix)
if (formatc->oformat->flags & AVFMT_RAWPICTURE)
{
- ret = av_write_frame(formatc, stream->index, (uint8_t *)pict, sizeof(AVPicture));
+ ret = av_write_frame(formatc, &pkt);
}
else
{
//if not zero we've got stuff to write
if (size != 0)
{
- ret = av_write_frame(formatc, stream->index, &videobuffer[0], size);
+ av_init_packet(&pkt);
+ pkt.stream_index = stream->index;
+ pkt.data = &videobuffer[0];
+ pkt.size = size;
+ if( context->coded_frame )
+ pkt.pts = context->coded_frame->pts;
+ if( context->coded_frame && context->coded_frame->key_frame)
+ pkt.flags |= PKT_FLAG_KEY;
+
+ ret = av_write_frame(formatc, &pkt);
//error detect - possibly throw later...
if(ret != 0)
void close(AVFormatContext *formatc, AVStream *stream)
{
if(stream)
- avcodec_close(&stream->codec);
+ avcodec_close(stream->codec);
if (encodable)
{
AVFormatParameters fmtparam,*ap = &fmtparam;
memset(ap, 0, sizeof(*ap));
- ap->frame_rate = vInfo.fps;
- ap->frame_rate_base = 1;
+ // FIXME: Port next two lines to recent libavcodec versions
+ //ap->frame_rate = vInfo.fps;
+ //ap->frame_rate_base = 1;
ap->width = vInfo.w;
ap->height = vInfo.h;
//ap->pix_fmt = frame_pix_fmt;
return 0;
}
- context = &st->codec;
+ context = st->codec;
context->codec_id = (CodecID)codec_id;
context->codec_type = CODEC_TYPE_VIDEO;
context->bit_rate = info.bitrate; //TODO: Make dependant on the quality
/* frames per second */
- context->frame_rate = info.fps;
- context->frame_rate_base = 1;
+ // FIXME: Port next two lines to recent libavcodec versions
+ //context->frame_rate = info.fps;
+ //context->frame_rate_base = 1;
/* "High Quality" */
context->mb_decision=FF_MB_DECISION_BITS;
return 0;
}
- context = &stream->codec;
+ context = stream->codec;
context->codec_id = (CodecID)codec_id;
context->codec_type = CODEC_TYPE_AUDIO;