code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
/*
* IFF PBM/ILBM bitmap decoder
* Copyright (c) 2010 Peter Ross <pross@xvid.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_IFF_H
#define AVCODEC_IFF_H
#include <stdint.h>
#include "avcodec.h"
int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal);
#endif /* AVCODEC_IFF_H */
| 123linslouis-android-video-cutter | jni/libavcodec/iff.h | C | asf20 | 1,027 |
/*
* WMA compatible codec
* Copyright (c) 2002-2007 The FFmpeg Project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_WMA_H
#define AVCODEC_WMA_H
#include "get_bits.h"
#include "put_bits.h"
#include "dsputil.h"
#include "fft.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 16384
#define MAX_CHANNELS 2
#define NOISE_TAB_SIZE 8192
#define LSP_POW_BITS 7
//FIXME should be in wmadec
#define VLCBITS 9
#define VLCMAX ((22+VLCBITS-1)/VLCBITS)
typedef float WMACoef; ///< type for decoded coefficients, int16_t would be enough for wma 1/2
typedef struct CoefVLCTable {
int n; ///< total number of codes
int max_level;
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;
typedef struct WMACodecContext {
AVCodecContext* avctx;
GetBitContext gb;
PutBitContext pb;
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 */
//FIXME the following 3 tables should be shared between decoders
VLC coef_vlc[2];
uint16_t *run_table[2];
float *level_table[2];
uint16_t *int_table[2];
const CoefVLCTable *coef_vlcs[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
int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length
DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE];
float max_exponent[MAX_CHANNELS];
WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE];
DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE];
DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2];
FFTContext mdct_ctx[BLOCK_NB_SIZES];
float *windows[BLOCK_NB_SIZES];
/* output buffer for one frame and the last for IMDCT windowing */
DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2];
/* 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)];
DSPContext dsp;
#ifdef TRACE
int frame_count;
#endif
} WMACodecContext;
extern const uint16_t ff_wma_critical_freqs[25];
extern const uint16_t ff_wma_hgain_huffcodes[37];
extern const uint8_t ff_wma_hgain_huffbits[37];
extern const float ff_wma_lsp_codebook[NB_LSP_COEFS][16];
extern const uint32_t ff_aac_scalefactor_code[121];
extern const uint8_t ff_aac_scalefactor_bits[121];
int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version,
unsigned int decode_flags);
int ff_wma_init(AVCodecContext * avctx, int flags2);
int ff_wma_total_gain_to_bits(int total_gain);
int ff_wma_end(AVCodecContext *avctx);
unsigned int ff_wma_get_large_val(GetBitContext* gb);
int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
VLC *vlc,
const float *level_table, const uint16_t *run_table,
int version, WMACoef *ptr, int offset,
int num_coefs, int block_len, int frame_len_bits,
int coef_nb_bits);
#endif /* AVCODEC_WMA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/wma.h | C | asf20 | 6,431 |
/*
* DXVA2 HW acceleration.
*
* copyright (c) 2010 Laurent Aimar
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "dxva2_internal.h"
void *ff_dxva2_get_surface(const Picture *picture)
{
return picture->data[3];
}
unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx,
const Picture *picture)
{
void *surface = ff_dxva2_get_surface(picture);
unsigned i;
for (i = 0; i < ctx->surface_count; i++)
if (ctx->surface[i] == surface)
return i;
assert(0);
return 0;
}
int ff_dxva2_commit_buffer(AVCodecContext *avctx,
struct dxva_context *ctx,
DXVA2_DecodeBufferDesc *dsc,
unsigned type, const void *data, unsigned size,
unsigned mb_count)
{
void *dxva_data;
unsigned dxva_size;
int result;
if (FAILED(IDirectXVideoDecoder_GetBuffer(ctx->decoder, type,
&dxva_data, &dxva_size))) {
av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %d\n", type);
return -1;
}
if (size <= dxva_size) {
memcpy(dxva_data, data, size);
memset(dsc, 0, sizeof(*dsc));
dsc->CompressedBufferType = type;
dsc->DataSize = size;
dsc->NumMBsInBuffer = mb_count;
result = 0;
} else {
av_log(avctx, AV_LOG_ERROR, "Buffer for type %d was too small\n", type);
result = -1;
}
if (FAILED(IDirectXVideoDecoder_ReleaseBuffer(ctx->decoder, type))) {
av_log(avctx, AV_LOG_ERROR, "Failed to release buffer type %d\n", type);
result = -1;
}
return result;
}
int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s,
const void *pp, unsigned pp_size,
const void *qm, unsigned qm_size,
int (*commit_bs_si)(AVCodecContext *,
DXVA2_DecodeBufferDesc *bs,
DXVA2_DecodeBufferDesc *slice))
{
struct dxva_context *ctx = avctx->hwaccel_context;
unsigned buffer_count = 0;
DXVA2_DecodeBufferDesc buffer[4];
DXVA2_DecodeExecuteParams exec;
int result;
if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder,
ff_dxva2_get_surface(s->current_picture_ptr),
NULL))) {
av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n");
return -1;
}
result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count],
DXVA2_PictureParametersBufferType,
pp, pp_size, 0);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add picture parameter buffer\n");
goto end;
}
buffer_count++;
if (qm_size > 0) {
result = ff_dxva2_commit_buffer(avctx, ctx, &buffer[buffer_count],
DXVA2_InverseQuantizationMatrixBufferType,
qm, qm_size, 0);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add inverse quantization matrix buffer\n");
goto end;
}
buffer_count++;
}
result = commit_bs_si(avctx,
&buffer[buffer_count + 0],
&buffer[buffer_count + 1]);
if (result) {
av_log(avctx, AV_LOG_ERROR,
"Failed to add bitstream or slice control buffer\n");
goto end;
}
buffer_count += 2;
/* TODO Film Grain when possible */
assert(buffer_count == 1 + (qm_size > 0) + 2);
memset(&exec, 0, sizeof(exec));
exec.NumCompBuffers = buffer_count;
exec.pCompressedBuffers = buffer;
exec.pExtensionData = NULL;
if (FAILED(IDirectXVideoDecoder_Execute(ctx->decoder, &exec))) {
av_log(avctx, AV_LOG_ERROR, "Failed to execute\n");
result = -1;
}
end:
if (FAILED(IDirectXVideoDecoder_EndFrame(ctx->decoder, NULL))) {
av_log(avctx, AV_LOG_ERROR, "Failed to end frame\n");
result = -1;
}
if (!result)
ff_draw_horiz_band(s, 0, s->avctx->height);
return result;
}
| 123linslouis-android-video-cutter | jni/libavcodec/dxva2.c | C | asf20 | 5,154 |
/*
* Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/attributes.h"
#include "dsputil.h"
#include "dwt.h"
void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer)
{
int i;
buf->base_buffer = base_buffer;
buf->line_count = line_count;
buf->line_width = line_width;
buf->data_count = max_allocated_lines;
buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count);
buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines);
for(i = 0; i < max_allocated_lines; i++){
buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width);
}
buf->data_stack_top = max_allocated_lines - 1;
}
IDWTELEM * ff_slice_buffer_load_line(slice_buffer * buf, int line)
{
IDWTELEM * buffer;
assert(buf->data_stack_top >= 0);
// assert(!buf->line[line]);
if (buf->line[line])
return buf->line[line];
buffer = buf->data_stack[buf->data_stack_top];
buf->data_stack_top--;
buf->line[line] = buffer;
return buffer;
}
void ff_slice_buffer_release(slice_buffer * buf, int line)
{
IDWTELEM * buffer;
assert(line >= 0 && line < buf->line_count);
assert(buf->line[line]);
buffer = buf->line[line];
buf->data_stack_top++;
buf->data_stack[buf->data_stack_top] = buffer;
buf->line[line] = NULL;
}
void ff_slice_buffer_flush(slice_buffer * buf)
{
int i;
for(i = 0; i < buf->line_count; i++){
if (buf->line[i])
ff_slice_buffer_release(buf, i);
}
}
void ff_slice_buffer_destroy(slice_buffer * buf)
{
int i;
ff_slice_buffer_flush(buf);
for(i = buf->data_count - 1; i >= 0; i--){
av_freep(&buf->data_stack[i]);
}
av_freep(&buf->data_stack);
av_freep(&buf->line);
}
static inline int mirror(int v, int m){
while((unsigned)v > (unsigned)m){
v=-v;
if(v<0) v+= 2*m;
}
return v;
}
static av_always_inline void
lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
int dst_step, int src_step, int ref_step,
int width, int mul, int add, int shift,
int highpass, int inverse){
const int mirror_left= !highpass;
const int mirror_right= (width&1) ^ highpass;
const int w= (width>>1) - 1 + (highpass & width);
int i;
#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
if(mirror_left){
dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse);
dst += dst_step;
src += src_step;
}
for(i=0; i<w; i++){
dst[i*dst_step] =
LIFT(src[i*src_step],
((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift),
inverse);
}
if(mirror_right){
dst[w*dst_step] =
LIFT(src[w*src_step],
((mul*2*ref[w*ref_step]+add)>>shift),
inverse);
}
}
static av_always_inline void
inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref,
int dst_step, int src_step, int ref_step,
int width, int mul, int add, int shift,
int highpass, int inverse){
const int mirror_left= !highpass;
const int mirror_right= (width&1) ^ highpass;
const int w= (width>>1) - 1 + (highpass & width);
int i;
#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref)))
if(mirror_left){
dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse);
dst += dst_step;
src += src_step;
}
for(i=0; i<w; i++){
dst[i*dst_step] =
LIFT(src[i*src_step],
((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift),
inverse);
}
if(mirror_right){
dst[w*dst_step] =
LIFT(src[w*src_step],
((mul*2*ref[w*ref_step]+add)>>shift),
inverse);
}
}
#ifndef liftS
static av_always_inline void
liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref,
int dst_step, int src_step, int ref_step,
int width, int mul, int add, int shift,
int highpass, int inverse){
const int mirror_left= !highpass;
const int mirror_right= (width&1) ^ highpass;
const int w= (width>>1) - 1 + (highpass & width);
int i;
assert(shift == 4);
#define LIFTS(src, ref, inv) \
((inv) ? \
(src) + (((ref) + 4*(src))>>shift): \
-((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23)))
if(mirror_left){
dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse);
dst += dst_step;
src += src_step;
}
for(i=0; i<w; i++){
dst[i*dst_step] =
LIFTS(src[i*src_step],
mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add,
inverse);
}
if(mirror_right){
dst[w*dst_step] =
LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
}
}
static av_always_inline void
inv_liftS(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref,
int dst_step, int src_step, int ref_step,
int width, int mul, int add, int shift,
int highpass, int inverse){
const int mirror_left= !highpass;
const int mirror_right= (width&1) ^ highpass;
const int w= (width>>1) - 1 + (highpass & width);
int i;
assert(shift == 4);
#define LIFTS(src, ref, inv) \
((inv) ? \
(src) + (((ref) + 4*(src))>>shift): \
-((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23)))
if(mirror_left){
dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse);
dst += dst_step;
src += src_step;
}
for(i=0; i<w; i++){
dst[i*dst_step] =
LIFTS(src[i*src_step],
mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add,
inverse);
}
if(mirror_right){
dst[w*dst_step] =
LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);
}
}
#endif /* ! liftS */
static void horizontal_decompose53i(DWTELEM *b, int width){
DWTELEM temp[width];
const int width2= width>>1;
int x;
const int w2= (width+1)>>1;
for(x=0; x<width2; x++){
temp[x ]= b[2*x ];
temp[x+w2]= b[2*x + 1];
}
if(width&1)
temp[x ]= b[2*x ];
#if 0
{
int A1,A2,A3,A4;
A2= temp[1 ];
A4= temp[0 ];
A1= temp[0+width2];
A1 -= (A2 + A4)>>1;
A4 += (A1 + 1)>>1;
b[0+width2] = A1;
b[0 ] = A4;
for(x=1; x+1<width2; x+=2){
A3= temp[x+width2];
A4= temp[x+1 ];
A3 -= (A2 + A4)>>1;
A2 += (A1 + A3 + 2)>>2;
b[x+width2] = A3;
b[x ] = A2;
A1= temp[x+1+width2];
A2= temp[x+2 ];
A1 -= (A2 + A4)>>1;
A4 += (A1 + A3 + 2)>>2;
b[x+1+width2] = A1;
b[x+1 ] = A4;
}
A3= temp[width-1];
A3 -= A2;
A2 += (A1 + A3 + 2)>>2;
b[width -1] = A3;
b[width2-1] = A2;
}
#else
lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);
lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0);
#endif /* 0 */
}
static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] -= (b0[i] + b2[i])>>1;
}
}
static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (b0[i] + b2[i] + 2)>>2;
}
}
static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){
int y;
DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride;
DWTELEM *b1= buffer + mirror(-2 , height-1)*stride;
for(y=-2; y<height; y+=2){
DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
b0=b2;
b1=b3;
}
}
static void horizontal_decompose97i(DWTELEM *b, int width){
DWTELEM temp[width];
const int w2= (width+1)>>1;
lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1);
liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0);
lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0);
lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0);
}
static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
}
}
static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
}
}
static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
#ifdef liftS
b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
#else
b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23);
#endif
}
}
static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
}
}
static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){
int y;
DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride;
DWTELEM *b1= buffer + mirror(-4 , height-1)*stride;
DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride;
DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride;
for(y=-4; y<height; y+=2){
DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
b0=b2;
b1=b3;
b2=b4;
b3=b5;
}
}
void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
int level;
for(level=0; level<decomposition_count; level++){
switch(type){
case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break;
case DWT_53: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break;
}
}
}
static void horizontal_compose53i(IDWTELEM *b, int width){
IDWTELEM temp[width];
const int width2= width>>1;
const int w2= (width+1)>>1;
int x;
for(x=0; x<width2; x++){
temp[2*x ]= b[x ];
temp[2*x + 1]= b[x+w2];
}
if(width&1)
temp[2*x ]= b[x ];
b[0] = temp[0] - ((temp[1]+1)>>1);
for(x=2; x<width-1; x+=2){
b[x ] = temp[x ] - ((temp[x-1] + temp[x+1]+2)>>2);
b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
}
if(width&1){
b[x ] = temp[x ] - ((temp[x-1]+1)>>1);
b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
}else
b[x-1] = temp[x-1] + b[x-2];
}
static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (b0[i] + b2[i])>>1;
}
}
static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] -= (b0[i] + b2[i] + 2)>>2;
}
}
static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){
cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line);
cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line);
cs->y = -1;
}
static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){
cs->b0 = buffer + mirror(-1-1, height-1)*stride;
cs->b1 = buffer + mirror(-1 , height-1)*stride;
cs->y = -1;
}
static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){
int y= cs->y;
IDWTELEM *b0= cs->b0;
IDWTELEM *b1= cs->b1;
IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line);
IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line);
if(y+1<(unsigned)height && y<(unsigned)height){
int x;
for(x=0; x<width; x++){
b2[x] -= (b1[x] + b3[x] + 2)>>2;
b1[x] += (b0[x] + b2[x])>>1;
}
}else{
if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
}
if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
cs->b0 = b2;
cs->b1 = b3;
cs->y += 2;
}
static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){
int y= cs->y;
IDWTELEM *b0= cs->b0;
IDWTELEM *b1= cs->b1;
IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride;
if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width);
if(y-1<(unsigned)height) horizontal_compose53i(b0, width);
if(y+0<(unsigned)height) horizontal_compose53i(b1, width);
cs->b0 = b2;
cs->b1 = b3;
cs->y += 2;
}
static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){
DWTCompose cs;
spatial_compose53i_init(&cs, buffer, height, stride);
while(cs.y <= height)
spatial_compose53i_dy(&cs, buffer, width, height, stride);
}
void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){
IDWTELEM temp[width];
const int w2= (width+1)>>1;
#if 0 //maybe more understadable but slower
inv_lift (temp , b , b +w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
inv_lift (temp+1 , b +w2, temp , 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1);
inv_liftS(b , temp , temp+1 , 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1);
inv_lift (b+1 , temp+1 , b , 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0);
#else
int x;
temp[0] = b[0] - ((3*b[w2]+2)>>2);
for(x=1; x<(width>>1); x++){
temp[2*x ] = b[x ] - ((3*(b [x+w2-1] + b[x+w2])+4)>>3);
temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x];
}
if(width&1){
temp[2*x ] = b[x ] - ((3*b [x+w2-1]+2)>>2);
temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x];
}else
temp[2*x-1] = b[x+w2-1] - 2*temp[2*x-2];
b[0] = temp[0] + ((2*temp[0] + temp[1]+4)>>3);
for(x=2; x<width-1; x+=2){
b[x ] = temp[x ] + ((4*temp[x ] + temp[x-1] + temp[x+1]+8)>>4);
b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1);
}
if(width&1){
b[x ] = temp[x ] + ((2*temp[x ] + temp[x-1]+4)>>3);
b[x-1] = temp[x-1] + ((3*(b [x-2] + b [x ] ))>>1);
}else
b[x-1] = temp[x-1] + 3*b [x-2];
#endif
}
static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
}
}
static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
}
}
static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
#ifdef liftS
b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;
#else
b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS;
#endif
}
}
static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
}
}
void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){
int i;
for(i=0; i<width; i++){
b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
#ifdef liftS
b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS;
#else
b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
#endif
b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
}
}
static void spatial_compose97i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){
cs->b0 = slice_buffer_get_line(sb, mirror(-3-1, height-1) * stride_line);
cs->b1 = slice_buffer_get_line(sb, mirror(-3 , height-1) * stride_line);
cs->b2 = slice_buffer_get_line(sb, mirror(-3+1, height-1) * stride_line);
cs->b3 = slice_buffer_get_line(sb, mirror(-3+2, height-1) * stride_line);
cs->y = -3;
}
static void spatial_compose97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){
cs->b0 = buffer + mirror(-3-1, height-1)*stride;
cs->b1 = buffer + mirror(-3 , height-1)*stride;
cs->b2 = buffer + mirror(-3+1, height-1)*stride;
cs->b3 = buffer + mirror(-3+2, height-1)*stride;
cs->y = -3;
}
static void spatial_compose97i_dy_buffered(DWTContext *dsp, DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){
int y = cs->y;
IDWTELEM *b0= cs->b0;
IDWTELEM *b1= cs->b1;
IDWTELEM *b2= cs->b2;
IDWTELEM *b3= cs->b3;
IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line);
IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line);
if(y>0 && y+4<height){
dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width);
}else{
if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
}
if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width);
if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width);
cs->b0=b2;
cs->b1=b3;
cs->b2=b4;
cs->b3=b5;
cs->y += 2;
}
static void spatial_compose97i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){
int y = cs->y;
IDWTELEM *b0= cs->b0;
IDWTELEM *b1= cs->b1;
IDWTELEM *b2= cs->b2;
IDWTELEM *b3= cs->b3;
IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width);
if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width);
if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width);
if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width);
if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width);
cs->b0=b2;
cs->b1=b3;
cs->b2=b4;
cs->b3=b5;
cs->y += 2;
}
static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){
DWTCompose cs;
spatial_compose97i_init(&cs, buffer, height, stride);
while(cs.y <= height)
spatial_compose97i_dy(&cs, buffer, width, height, stride);
}
void ff_spatial_idwt_buffered_init(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count){
int level;
for(level=decomposition_count-1; level>=0; level--){
switch(type){
case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
case DWT_53: spatial_compose53i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break;
}
}
}
void ff_spatial_idwt_buffered_slice(DWTContext *dsp, DWTCompose *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y){
const int support = type==1 ? 3 : 5;
int level;
if(type==2) return;
for(level=decomposition_count-1; level>=0; level--){
while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){
switch(type){
case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
break;
case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level);
break;
}
}
}
}
void ff_spatial_idwt_init(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
int level;
for(level=decomposition_count-1; level>=0; level--){
switch(type){
case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<<level); break;
case DWT_53: spatial_compose53i_init(cs+level, buffer, height>>level, stride<<level); break;
}
}
}
void ff_spatial_idwt_slice(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y){
const int support = type==1 ? 3 : 5;
int level;
if(type==2) return;
for(level=decomposition_count-1; level>=0; level--){
while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){
switch(type){
case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
break;
case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level);
break;
}
}
}
}
void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
DWTCompose cs[MAX_DECOMPOSITIONS];
int y;
ff_spatial_idwt_init(cs, buffer, width, height, stride, type, decomposition_count);
for(y=0; y<height; y+=4)
ff_spatial_idwt_slice(cs, buffer, width, height, stride, type, decomposition_count, y);
}
static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){
int s, i, j;
const int dec_count= w==8 ? 3 : 4;
int tmp[32*32];
int level, ori;
static const int scale[2][2][4][4]={
{
{
// 9/7 8x8 dec=3
{268, 239, 239, 213},
{ 0, 224, 224, 152},
{ 0, 135, 135, 110},
},{
// 9/7 16x16 or 32x32 dec=4
{344, 310, 310, 280},
{ 0, 320, 320, 228},
{ 0, 175, 175, 136},
{ 0, 129, 129, 102},
}
},{
{
// 5/3 8x8 dec=3
{275, 245, 245, 218},
{ 0, 230, 230, 156},
{ 0, 138, 138, 113},
},{
// 5/3 16x16 or 32x32 dec=4
{352, 317, 317, 286},
{ 0, 328, 328, 233},
{ 0, 180, 180, 140},
{ 0, 132, 132, 105},
}
}
};
for (i = 0; i < h; i++) {
for (j = 0; j < w; j+=4) {
tmp[32*i+j+0] = (pix1[j+0] - pix2[j+0])<<4;
tmp[32*i+j+1] = (pix1[j+1] - pix2[j+1])<<4;
tmp[32*i+j+2] = (pix1[j+2] - pix2[j+2])<<4;
tmp[32*i+j+3] = (pix1[j+3] - pix2[j+3])<<4;
}
pix1 += line_size;
pix2 += line_size;
}
ff_spatial_dwt(tmp, w, h, 32, type, dec_count);
s=0;
assert(w==h);
for(level=0; level<dec_count; level++){
for(ori= level ? 1 : 0; ori<4; ori++){
int size= w>>(dec_count-level);
int sx= (ori&1) ? size : 0;
int stride= 32<<(dec_count-level);
int sy= (ori&2) ? stride>>1 : 0;
for(i=0; i<size; i++){
for(j=0; j<size; j++){
int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori];
s += FFABS(v);
}
}
}
}
assert(s>=0);
return s>>9;
}
static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 8, h, 1);
}
static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 8, h, 0);
}
static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 16, h, 1);
}
static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 16, h, 0);
}
int ff_w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 32, h, 1);
}
int ff_w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){
return w_c(v, pix1, pix2, line_size, 32, h, 0);
}
void ff_dsputil_init_dwt(DSPContext *c)
{
c->w53[0]= w53_16_c;
c->w53[1]= w53_8_c;
c->w97[0]= w97_16_c;
c->w97[1]= w97_8_c;
}
void ff_dwt_init(DWTContext *c)
{
c->vertical_compose97i = ff_snow_vertical_compose97i;
c->horizontal_compose97i = ff_snow_horizontal_compose97i;
c->inner_add_yblock = ff_snow_inner_add_yblock;
if (HAVE_MMX) ff_dwt_init_x86(c);
}
| 123linslouis-android-video-cutter | jni/libavcodec/dwt.c | C | asf20 | 26,467 |
/*
* Copyright (c) 2002 The FFmpeg Project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "msmpeg4.h"
#include "msmpeg4data.h"
#include "h263.h"
#include "wmv2.h"
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);
put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //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, s->loop_filter);
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;
}
static av_cold int wmv2_encode_init(AVCodecContext *avctx){
Wmv2Context * const w= avctx->priv_data;
if(MPV_encode_init(avctx) < 0)
return -1;
ff_wmv2_common_init(w);
avctx->extradata_size= 4;
avctx->extradata= av_mallocz(avctx->extradata_size + 10);
encode_ext_header(w);
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 == FF_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->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 == FF_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){
ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
ff_msmpeg4_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);
ff_msmpeg4_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){
ff_msmpeg4_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){
ff_msmpeg4_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= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
}
s->esc3_level_length= 0;
s->esc3_run_length= 0;
return 0;
}
/* Nearly identical to wmv1 but that is just because we do not use the
* useless M$ crap features. It is duplicated here in case someone wants
* to add support for these crap 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;
ff_msmpeg4_handle_slices(s);
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);
}
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, 0, &pred_x, &pred_y);
ff_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 = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
*coded_block = val;
val = val ^ pred;
}
coded_cbp |= val << (5 - i);
}
if (s->pict_type == FF_I_TYPE) {
put_bits(&s->pb,
ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[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]);
}
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++) {
ff_msmpeg4_encode_block(s, block[i], i);
}
}
AVCodec wmv2_encoder = {
"wmv2",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_WMV2,
sizeof(Wmv2Context),
wmv2_encode_init,
MPV_encode_picture,
MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/wmv2enc.c | C | asf20 | 6,689 |
/**
* @file
* VP5 and VP6 compatible video decoder (common features)
*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
#include "vp56.h"
#include "vp56data.h"
void vp56_init_dequant(VP56Context *s, int quantizer)
{
s->quantizer = quantizer;
s->dequant_dc = vp56_dc_dequant[quantizer] << 2;
s->dequant_ac = vp56_ac_dequant[quantizer] << 2;
memset(s->qscale_table, quantizer, s->mb_width);
}
static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
VP56Frame ref_frame)
{
int nb_pred = 0;
VP56mv vect[2] = {{0,0}, {0,0}};
int pos, offset;
VP56mv mvp;
for (pos=0; pos<12; pos++) {
mvp.x = col + vp56_candidate_predictor_pos[pos][0];
mvp.y = row + vp56_candidate_predictor_pos[pos][1];
if (mvp.x < 0 || mvp.x >= s->mb_width ||
mvp.y < 0 || mvp.y >= s->mb_height)
continue;
offset = mvp.x + s->mb_width*mvp.y;
if (vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
continue;
if ((s->macroblocks[offset].mv.x == vect[0].x &&
s->macroblocks[offset].mv.y == vect[0].y) ||
(s->macroblocks[offset].mv.x == 0 &&
s->macroblocks[offset].mv.y == 0))
continue;
vect[nb_pred++] = s->macroblocks[offset].mv;
if (nb_pred > 1) {
nb_pred = -1;
break;
}
s->vector_candidate_pos = pos;
}
s->vector_candidate[0] = vect[0];
s->vector_candidate[1] = vect[1];
return nb_pred+1;
}
static void vp56_parse_mb_type_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int i, ctx, type;
for (ctx=0; ctx<3; ctx++) {
if (vp56_rac_get_prob(c, 174)) {
int idx = vp56_rac_gets(c, 4);
memcpy(model->mb_types_stats[ctx],
vp56_pre_def_mb_type_stats[idx][ctx],
sizeof(model->mb_types_stats[ctx]));
}
if (vp56_rac_get_prob(c, 254)) {
for (type=0; type<10; type++) {
for(i=0; i<2; i++) {
if (vp56_rac_get_prob(c, 205)) {
int delta, sign = vp56_rac_get(c);
delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
vp56_mb_type_model_model);
if (!delta)
delta = 4 * vp56_rac_gets(c, 7);
model->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
}
}
}
}
}
/* compute MB type probability tables based on previous MB type */
for (ctx=0; ctx<3; ctx++) {
int p[10];
for (type=0; type<10; type++)
p[type] = 100 * model->mb_types_stats[ctx][type][1];
for (type=0; type<10; type++) {
int p02, p34, p0234, p17, p56, p89, p5689, p156789;
/* conservative MB type probability */
model->mb_type[ctx][type][0] = 255 - (255 * model->mb_types_stats[ctx][type][0]) / (1 + model->mb_types_stats[ctx][type][0] + model->mb_types_stats[ctx][type][1]);
p[type] = 0; /* same MB type => weight is null */
/* binary tree parsing probabilities */
p02 = p[0] + p[2];
p34 = p[3] + p[4];
p0234 = p02 + p34;
p17 = p[1] + p[7];
p56 = p[5] + p[6];
p89 = p[8] + p[9];
p5689 = p56 + p89;
p156789 = p17 + p5689;
model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
/* restore initial value */
p[type] = 100 * model->mb_types_stats[ctx][type][1];
}
}
}
static VP56mb vp56_parse_mb_type(VP56Context *s,
VP56mb prev_type, int ctx)
{
uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
VP56RangeCoder *c = &s->c;
if (vp56_rac_get_prob(c, mb_type_model[0]))
return prev_type;
else
return vp56_rac_get_tree(c, vp56_pmbt_tree, mb_type_model);
}
static void vp56_decode_4mv(VP56Context *s, int row, int col)
{
VP56mv mv = {0,0};
int type[4];
int b;
/* parse each block type */
for (b=0; b<4; b++) {
type[b] = vp56_rac_gets(&s->c, 2);
if (type[b])
type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
}
/* get vectors */
for (b=0; b<4; b++) {
switch (type[b]) {
case VP56_MB_INTER_NOVEC_PF:
s->mv[b] = (VP56mv) {0,0};
break;
case VP56_MB_INTER_DELTA_PF:
s->parse_vector_adjustment(s, &s->mv[b]);
break;
case VP56_MB_INTER_V1_PF:
s->mv[b] = s->vector_candidate[0];
break;
case VP56_MB_INTER_V2_PF:
s->mv[b] = s->vector_candidate[1];
break;
}
mv.x += s->mv[b].x;
mv.y += s->mv[b].y;
}
/* this is the one selected for the whole MB for prediction */
s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
/* chroma vectors are average luma vectors */
if (s->avctx->codec->id == CODEC_ID_VP5) {
s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
} else {
s->mv[4] = s->mv[5] = (VP56mv) {mv.x/4, mv.y/4};
}
}
static VP56mb vp56_decode_mv(VP56Context *s, int row, int col)
{
VP56mv *mv, vect = {0,0};
int ctx, b;
ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
s->macroblocks[row * s->mb_width + col].type = s->mb_type;
switch (s->mb_type) {
case VP56_MB_INTER_V1_PF:
mv = &s->vector_candidate[0];
break;
case VP56_MB_INTER_V2_PF:
mv = &s->vector_candidate[1];
break;
case VP56_MB_INTER_V1_GF:
vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
mv = &s->vector_candidate[0];
break;
case VP56_MB_INTER_V2_GF:
vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
mv = &s->vector_candidate[1];
break;
case VP56_MB_INTER_DELTA_PF:
s->parse_vector_adjustment(s, &vect);
mv = &vect;
break;
case VP56_MB_INTER_DELTA_GF:
vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
s->parse_vector_adjustment(s, &vect);
mv = &vect;
break;
case VP56_MB_INTER_4V:
vp56_decode_4mv(s, row, col);
return s->mb_type;
default:
mv = &vect;
break;
}
s->macroblocks[row*s->mb_width + col].mv = *mv;
/* same vector for all blocks */
for (b=0; b<6; b++)
s->mv[b] = *mv;
return s->mb_type;
}
static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
{
int idx = s->scantable.permutated[0];
int b;
for (b=0; b<6; b++) {
VP56RefDc *ab = &s->above_blocks[s->above_block_idx[b]];
VP56RefDc *lb = &s->left_block[vp56_b6to4[b]];
int count = 0;
int dc = 0;
int i;
if (ref_frame == lb->ref_frame) {
dc += lb->dc_coeff;
count++;
}
if (ref_frame == ab->ref_frame) {
dc += ab->dc_coeff;
count++;
}
if (s->avctx->codec->id == CODEC_ID_VP5)
for (i=0; i<2; i++)
if (count < 2 && ref_frame == ab[-1+2*i].ref_frame) {
dc += ab[-1+2*i].dc_coeff;
count++;
}
if (count == 0)
dc = s->prev_dc[vp56_b2p[b]][ref_frame];
else if (count == 2)
dc /= 2;
s->block_coeff[b][idx] += dc;
s->prev_dc[vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx];
ab->dc_coeff = s->block_coeff[b][idx];
ab->ref_frame = ref_frame;
lb->dc_coeff = s->block_coeff[b][idx];
lb->ref_frame = ref_frame;
s->block_coeff[b][idx] *= s->dequant_dc;
}
}
static void vp56_deblock_filter(VP56Context *s, uint8_t *yuv,
int stride, int dx, int dy)
{
int t = vp56_filter_threshold[s->quantizer];
if (dx) s->vp56dsp.edge_filter_hor(yuv + 10-dx , stride, t);
if (dy) s->vp56dsp.edge_filter_ver(yuv + stride*(10-dy), stride, t);
}
static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
int stride, int x, int y)
{
uint8_t *dst=s->framep[VP56_FRAME_CURRENT]->data[plane]+s->block_offset[b];
uint8_t *src_block;
int src_offset;
int overlap_offset = 0;
int mask = s->vp56_coord_div[b] - 1;
int deblock_filtering = s->deblock_filtering;
int dx;
int dy;
if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
&& !s->framep[VP56_FRAME_CURRENT]->key_frame))
deblock_filtering = 0;
dx = s->mv[b].x / s->vp56_coord_div[b];
dy = s->mv[b].y / s->vp56_coord_div[b];
if (b >= 4) {
x /= 2;
y /= 2;
}
x += dx - 2;
y += dy - 2;
if (x<0 || x+12>=s->plane_width[plane] ||
y<0 || y+12>=s->plane_height[plane]) {
ff_emulated_edge_mc(s->edge_emu_buffer,
src + s->block_offset[b] + (dy-2)*stride + (dx-2),
stride, 12, 12, x, y,
s->plane_width[plane],
s->plane_height[plane]);
src_block = s->edge_emu_buffer;
src_offset = 2 + 2*stride;
} else if (deblock_filtering) {
/* only need a 12x12 block, but there is no such dsp function, */
/* so copy a 16x12 block */
s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
src + s->block_offset[b] + (dy-2)*stride + (dx-2),
stride, 12);
src_block = s->edge_emu_buffer;
src_offset = 2 + 2*stride;
} else {
src_block = src;
src_offset = s->block_offset[b] + dy*stride + dx;
}
if (deblock_filtering)
vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
if (s->mv[b].x & mask)
overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
if (s->mv[b].y & mask)
overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
if (overlap_offset) {
if (s->filter)
s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
stride, s->mv[b], mask, s->filter_selection, b<4);
else
s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
src_block+src_offset+overlap_offset,
stride, 8);
} else {
s->dsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
}
}
static void vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
{
AVFrame *frame_current, *frame_ref;
VP56mb mb_type;
VP56Frame ref_frame;
int b, ab, b_max, plane, off;
if (s->framep[VP56_FRAME_CURRENT]->key_frame)
mb_type = VP56_MB_INTRA;
else
mb_type = vp56_decode_mv(s, row, col);
ref_frame = vp56_reference_frame[mb_type];
s->dsp.clear_blocks(*s->block_coeff);
s->parse_coeff(s);
vp56_add_predictors_dc(s, ref_frame);
frame_current = s->framep[VP56_FRAME_CURRENT];
frame_ref = s->framep[ref_frame];
ab = 6*is_alpha;
b_max = 6 - 2*is_alpha;
switch (mb_type) {
case VP56_MB_INTRA:
for (b=0; b<b_max; b++) {
plane = vp56_b2p[b+ab];
s->dsp.idct_put(frame_current->data[plane] + s->block_offset[b],
s->stride[plane], s->block_coeff[b]);
}
break;
case VP56_MB_INTER_NOVEC_PF:
case VP56_MB_INTER_NOVEC_GF:
for (b=0; b<b_max; b++) {
plane = vp56_b2p[b+ab];
off = s->block_offset[b];
s->dsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
frame_ref->data[plane] + off,
s->stride[plane], 8);
s->dsp.idct_add(frame_current->data[plane] + off,
s->stride[plane], s->block_coeff[b]);
}
break;
case VP56_MB_INTER_DELTA_PF:
case VP56_MB_INTER_V1_PF:
case VP56_MB_INTER_V2_PF:
case VP56_MB_INTER_DELTA_GF:
case VP56_MB_INTER_4V:
case VP56_MB_INTER_V1_GF:
case VP56_MB_INTER_V2_GF:
for (b=0; b<b_max; b++) {
int x_off = b==1 || b==3 ? 8 : 0;
int y_off = b==2 || b==3 ? 8 : 0;
plane = vp56_b2p[b+ab];
vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane],
16*col+x_off, 16*row+y_off);
s->dsp.idct_add(frame_current->data[plane] + s->block_offset[b],
s->stride[plane], s->block_coeff[b]);
}
break;
}
}
static int vp56_size_changed(AVCodecContext *avctx)
{
VP56Context *s = avctx->priv_data;
int stride = s->framep[VP56_FRAME_CURRENT]->linesize[0];
int i;
s->plane_width[0] = s->plane_width[3] = avctx->coded_width;
s->plane_width[1] = s->plane_width[2] = avctx->coded_width/2;
s->plane_height[0] = s->plane_height[3] = avctx->coded_height;
s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2;
for (i=0; i<4; i++)
s->stride[i] = s->flip * s->framep[VP56_FRAME_CURRENT]->linesize[i];
s->mb_width = (avctx->coded_width +15) / 16;
s->mb_height = (avctx->coded_height+15) / 16;
if (s->mb_width > 1000 || s->mb_height > 1000) {
av_log(avctx, AV_LOG_ERROR, "picture too big\n");
return -1;
}
s->qscale_table = av_realloc(s->qscale_table, s->mb_width);
s->above_blocks = av_realloc(s->above_blocks,
(4*s->mb_width+6) * sizeof(*s->above_blocks));
s->macroblocks = av_realloc(s->macroblocks,
s->mb_width*s->mb_height*sizeof(*s->macroblocks));
av_free(s->edge_emu_buffer_alloc);
s->edge_emu_buffer_alloc = av_malloc(16*stride);
s->edge_emu_buffer = s->edge_emu_buffer_alloc;
if (s->flip < 0)
s->edge_emu_buffer += 15 * stride;
return 0;
}
int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
VP56Context *s = avctx->priv_data;
AVFrame *const p = s->framep[VP56_FRAME_CURRENT];
int remaining_buf_size = avpkt->size;
int is_alpha, av_uninit(alpha_offset);
if (s->has_alpha) {
if (remaining_buf_size < 3)
return -1;
alpha_offset = bytestream_get_be24(&buf);
remaining_buf_size -= 3;
if (remaining_buf_size < alpha_offset)
return -1;
}
for (is_alpha=0; is_alpha < 1+s->has_alpha; is_alpha++) {
int mb_row, mb_col, mb_row_flip, mb_offset = 0;
int block, y, uv, stride_y, stride_uv;
int golden_frame = 0;
int res;
s->modelp = &s->models[is_alpha];
res = s->parse_header(s, buf, remaining_buf_size, &golden_frame);
if (!res)
return -1;
if (!is_alpha) {
p->reference = 1;
if (avctx->get_buffer(avctx, p) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
if (res == 2)
if (vp56_size_changed(avctx)) {
avctx->release_buffer(avctx, p);
return -1;
}
}
if (p->key_frame) {
p->pict_type = FF_I_TYPE;
s->default_models_init(s);
for (block=0; block<s->mb_height*s->mb_width; block++)
s->macroblocks[block].type = VP56_MB_INTRA;
} else {
p->pict_type = FF_P_TYPE;
vp56_parse_mb_type_models(s);
s->parse_vector_models(s);
s->mb_type = VP56_MB_INTER_NOVEC_PF;
}
s->parse_coeff_models(s);
memset(s->prev_dc, 0, sizeof(s->prev_dc));
s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
for (block=0; block < 4*s->mb_width+6; block++) {
s->above_blocks[block].ref_frame = VP56_FRAME_NONE;
s->above_blocks[block].dc_coeff = 0;
s->above_blocks[block].not_null_dc = 0;
}
s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT;
s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT;
stride_y = p->linesize[0];
stride_uv = p->linesize[1];
if (s->flip < 0)
mb_offset = 7;
/* main macroblocks loop */
for (mb_row=0; mb_row<s->mb_height; mb_row++) {
if (s->flip < 0)
mb_row_flip = s->mb_height - mb_row - 1;
else
mb_row_flip = mb_row;
for (block=0; block<4; block++) {
s->left_block[block].ref_frame = VP56_FRAME_NONE;
s->left_block[block].dc_coeff = 0;
s->left_block[block].not_null_dc = 0;
}
memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx));
memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
s->above_block_idx[0] = 1;
s->above_block_idx[1] = 2;
s->above_block_idx[2] = 1;
s->above_block_idx[3] = 2;
s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
s->block_offset[1] = s->block_offset[0] + 8;
s->block_offset[3] = s->block_offset[2] + 8;
s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
s->block_offset[5] = s->block_offset[4];
for (mb_col=0; mb_col<s->mb_width; mb_col++) {
vp56_decode_mb(s, mb_row, mb_col, is_alpha);
for (y=0; y<4; y++) {
s->above_block_idx[y] += 2;
s->block_offset[y] += 16;
}
for (uv=4; uv<6; uv++) {
s->above_block_idx[uv] += 1;
s->block_offset[uv] += 8;
}
}
}
if (p->key_frame || golden_frame) {
if (s->framep[VP56_FRAME_GOLDEN]->data[0] &&
s->framep[VP56_FRAME_GOLDEN] != s->framep[VP56_FRAME_GOLDEN2])
avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
s->framep[VP56_FRAME_GOLDEN] = p;
}
if (s->has_alpha) {
FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN],
s->framep[VP56_FRAME_GOLDEN2]);
buf += alpha_offset;
remaining_buf_size -= alpha_offset;
}
}
if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN] ||
s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN2]) {
if (s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN] &&
s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN2])
FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
s->framep[VP56_FRAME_UNUSED]);
else
FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS],
s->framep[VP56_FRAME_UNUSED2]);
} else if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT],
s->framep[VP56_FRAME_PREVIOUS]);
p->qstride = 0;
p->qscale_table = s->qscale_table;
p->qscale_type = FF_QSCALE_TYPE_VP56;
*(AVFrame*)data = *p;
*data_size = sizeof(AVFrame);
return avpkt->size;
}
av_cold void vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
{
VP56Context *s = avctx->priv_data;
int i;
s->avctx = avctx;
avctx->pix_fmt = has_alpha ? PIX_FMT_YUVA420P : PIX_FMT_YUV420P;
if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_VP3;
dsputil_init(&s->dsp, avctx);
ff_vp56dsp_init(&s->vp56dsp, avctx->codec->id);
ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
for (i=0; i<4; i++)
s->framep[i] = &s->frames[i];
s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN];
s->framep[VP56_FRAME_UNUSED2] = s->framep[VP56_FRAME_GOLDEN2];
s->edge_emu_buffer_alloc = NULL;
s->above_blocks = NULL;
s->macroblocks = NULL;
s->quantizer = -1;
s->deblock_filtering = 1;
s->filter = NULL;
s->has_alpha = has_alpha;
if (flip) {
s->flip = -1;
s->frbi = 2;
s->srbi = 0;
} else {
s->flip = 1;
s->frbi = 0;
s->srbi = 2;
}
}
av_cold int vp56_free(AVCodecContext *avctx)
{
VP56Context *s = avctx->priv_data;
av_freep(&s->qscale_table);
av_freep(&s->above_blocks);
av_freep(&s->macroblocks);
av_freep(&s->edge_emu_buffer_alloc);
if (s->framep[VP56_FRAME_GOLDEN]->data[0])
avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]);
if (s->framep[VP56_FRAME_GOLDEN2]->data[0])
avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN2]);
if (s->framep[VP56_FRAME_PREVIOUS]->data[0])
avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]);
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/vp56.c | C | asf20 | 23,404 |
/*
* VC-1 and WMV3 decoder
* copyright (c) 2006 Konstantin Shishkov
* (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VC-1 tables.
*/
#ifndef AVCODEC_VC1DATA_H
#define AVCODEC_VC1DATA_H
#include <stdint.h>
#include "libavutil/rational.h"
#include "get_bits.h"
/** Table for conversion between TTBLK and TTMB */
extern const int ff_vc1_ttblk_to_tt[3][8];
extern const int ff_vc1_ttfrm_to_tt[4];
/** MV P mode - the 5th element is only used for mode 1 */
extern const uint8_t ff_vc1_mv_pmode_table[2][5];
extern const uint8_t ff_vc1_mv_pmode_table2[2][4];
extern const int ff_vc1_fps_nr[5], ff_vc1_fps_dr[2];
extern const uint8_t ff_vc1_pquant_table[3][32];
/** @name VC-1 VLC tables and defines
* @todo TODO move this into the context
*/
//@{
#define VC1_BFRACTION_VLC_BITS 7
extern VLC ff_vc1_bfraction_vlc;
#define VC1_IMODE_VLC_BITS 4
extern VLC ff_vc1_imode_vlc;
#define VC1_NORM2_VLC_BITS 3
extern VLC ff_vc1_norm2_vlc;
#define VC1_NORM6_VLC_BITS 9
extern VLC ff_vc1_norm6_vlc;
/* Could be optimized, one table only needs 8 bits */
#define VC1_TTMB_VLC_BITS 9 //12
extern VLC ff_vc1_ttmb_vlc[3];
#define VC1_MV_DIFF_VLC_BITS 9 //15
extern VLC ff_vc1_mv_diff_vlc[4];
#define VC1_CBPCY_P_VLC_BITS 9 //14
extern VLC ff_vc1_cbpcy_p_vlc[4];
#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6
extern VLC ff_vc1_4mv_block_pattern_vlc[4];
#define VC1_TTBLK_VLC_BITS 5
extern VLC ff_vc1_ttblk_vlc[3];
#define VC1_SUBBLKPAT_VLC_BITS 6
extern VLC ff_vc1_subblkpat_vlc[3];
extern VLC ff_vc1_ac_coeff_table[8];
//@}
#if 0 //original bfraction from vc9data.h, not conforming to standard
/* Denominator used for ff_vc1_bfraction_lut */
#define B_FRACTION_DEN 840
/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */
extern const int16_t ff_vc1_bfraction_lut[23];
#else
/* Denominator used for ff_vc1_bfraction_lut */
#define B_FRACTION_DEN 256
/* pre-computed scales for all bfractions and base=256 */
extern const int16_t ff_vc1_bfraction_lut[23];
#endif
extern const uint8_t ff_vc1_bfraction_bits[23];
extern const uint8_t ff_vc1_bfraction_codes[23];
//Same as H.264
extern const AVRational ff_vc1_pixel_aspect[16];
/* BitPlane IMODE - such a small table... */
extern const uint8_t ff_vc1_imode_codes[7];
extern const uint8_t ff_vc1_imode_bits[7];
/* Normal-2 imode */
extern const uint8_t ff_vc1_norm2_codes[4];
extern const uint8_t ff_vc1_norm2_bits[4];
extern const uint16_t ff_vc1_norm6_codes[64];
extern const uint8_t ff_vc1_norm6_bits[64];
/* Normal-6 imode */
extern const uint8_t ff_vc1_norm6_spec[64][5];
/* 4MV Block pattern VLC tables */
extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16];
extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16];
extern const uint8_t wmv3_dc_scale_table[32];
/* P-Picture CBPCY VLC tables */
extern const uint16_t ff_vc1_cbpcy_p_codes[4][64];
extern const uint8_t ff_vc1_cbpcy_p_bits[4][64];
/* MacroBlock Transform Type: 7.1.3.11, p89
* 8x8:B
* 8x4:B:btm 8x4:B:top 8x4:B:both,
* 4x8:B:right 4x8:B:left 4x8:B:both
* 4x4:B 8x8:MB
* 8x4:MB:btm 8x4:MB:top 8x4,MB,both
* 4x8,MB,right 4x8,MB,left
* 4x4,MB */
extern const uint16_t ff_vc1_ttmb_codes[3][16];
extern const uint8_t ff_vc1_ttmb_bits[3][16];
/* TTBLK (Transform Type per Block) tables */
extern const uint8_t ff_vc1_ttblk_codes[3][8];
extern const uint8_t ff_vc1_ttblk_bits[3][8];
/* SUBBLKPAT tables, p93-94, reordered */
extern const uint8_t ff_vc1_subblkpat_codes[3][15];
extern const uint8_t ff_vc1_subblkpat_bits[3][15];
/* MV differential tables, p265 */
extern const uint16_t ff_vc1_mv_diff_codes[4][73];
extern const uint8_t ff_vc1_mv_diff_bits[4][73];
/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */
/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */
extern const int8_t ff_vc1_simple_progressive_4x4_zz [16];
extern const int8_t ff_vc1_adv_progressive_8x4_zz [32];
extern const int8_t ff_vc1_adv_progressive_4x8_zz [32];
extern const int8_t ff_vc1_adv_interlaced_8x8_zz [64];
extern const int8_t ff_vc1_adv_interlaced_8x4_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x8_zz [32];
extern const int8_t ff_vc1_adv_interlaced_4x4_zz [16];
/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */
extern const int32_t ff_vc1_dqscale[63];
#endif /* AVCODEC_VC1DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/vc1data.h | C | asf20 | 5,106 |
/*
* PC Paintbrush PCX (.pcx) image encoder
* Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* PCX image encoder
* @file
* @author Daniel Verkamp
* @sa http://www.qzx.com/pc-gpe/pcx.txt
*/
#include "avcodec.h"
#include "bytestream.h"
typedef struct PCXContext {
AVFrame picture;
} PCXContext;
static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
static av_cold int pcx_encode_init(AVCodecContext *avctx)
{
PCXContext *s = avctx->priv_data;
avcodec_get_frame_defaults(&s->picture);
avctx->coded_frame = &s->picture;
return 0;
}
/**
* PCX run-length encoder
* @param dst output buffer
* @param dst_size size of output buffer
* @param src input buffer
* @param src_plane_size size of one plane of input buffer in bytes
* @param nplanes number of planes in input buffer
* @return number of bytes written to dst or -1 on error
* @bug will not work for nplanes != 1 && bpp != 8
*/
static int pcx_rle_encode( uint8_t *dst, int dst_size,
const uint8_t *src, int src_plane_size, int nplanes)
{
int p;
const uint8_t *dst_start = dst;
// check worst-case upper bound on dst_size
if (dst_size < 2LL * src_plane_size * nplanes || src_plane_size <= 0)
return -1;
for (p = 0; p < nplanes; p++) {
int count = 1;
const uint8_t *src_plane = src + p;
const uint8_t *src_plane_end = src_plane + src_plane_size * nplanes;
uint8_t prev = *src_plane;
src_plane += nplanes;
for (; ; src_plane += nplanes) {
if (src_plane < src_plane_end && *src_plane == prev && count < 0x3F) {
// current byte is same as prev
++count;
} else {
// output prev * count
if (count != 1 || prev >= 0xC0)
*dst++ = 0xC0 | count;
*dst++ = prev;
if (src_plane == src_plane_end)
break;
// start new run
count = 1;
prev = *src_plane;
}
}
}
return dst - dst_start;
}
static int pcx_encode_frame(AVCodecContext *avctx,
unsigned char *buf, int buf_size, void *data)
{
PCXContext *s = avctx->priv_data;
AVFrame *const pict = &s->picture;
const uint8_t *buf_start = buf;
const uint8_t *buf_end = buf + buf_size;
int bpp, nplanes, i, y, line_bytes, written;
const uint32_t *pal = NULL;
const uint8_t *src;
*pict = *(AVFrame *)data;
pict->pict_type = FF_I_TYPE;
pict->key_frame = 1;
if (avctx->width > 65535 || avctx->height > 65535) {
av_log(avctx, AV_LOG_ERROR, "image dimensions do not fit in 16 bits\n");
return -1;
}
switch (avctx->pix_fmt) {
case PIX_FMT_RGB24:
bpp = 8;
nplanes = 3;
break;
case PIX_FMT_RGB8:
case PIX_FMT_BGR8:
case PIX_FMT_RGB4_BYTE:
case PIX_FMT_BGR4_BYTE:
case PIX_FMT_GRAY8:
case PIX_FMT_PAL8:
bpp = 8;
nplanes = 1;
pal = (uint32_t *)pict->data[1];
break;
case PIX_FMT_MONOBLACK:
bpp = 1;
nplanes = 1;
pal = monoblack_pal;
break;
default:
av_log(avctx, AV_LOG_ERROR, "unsupported pixfmt\n");
return -1;
}
line_bytes = (avctx->width * bpp + 7) >> 3;
line_bytes = (line_bytes + 1) & ~1;
bytestream_put_byte(&buf, 10); // manufacturer
bytestream_put_byte(&buf, 5); // version
bytestream_put_byte(&buf, 1); // encoding
bytestream_put_byte(&buf, bpp); // bits per pixel per plane
bytestream_put_le16(&buf, 0); // x min
bytestream_put_le16(&buf, 0); // y min
bytestream_put_le16(&buf, avctx->width - 1); // x max
bytestream_put_le16(&buf, avctx->height - 1); // y max
bytestream_put_le16(&buf, 0); // horizontal DPI
bytestream_put_le16(&buf, 0); // vertical DPI
for (i = 0; i < 16; i++)
bytestream_put_be24(&buf, pal ? pal[i] : 0);// palette (<= 16 color only)
bytestream_put_byte(&buf, 0); // reserved
bytestream_put_byte(&buf, nplanes); // number of planes
bytestream_put_le16(&buf, line_bytes); // scanline plane size in bytes
while (buf - buf_start < 128)
*buf++= 0;
src = pict->data[0];
for (y = 0; y < avctx->height; y++) {
if ((written = pcx_rle_encode(buf, buf_end - buf,
src, line_bytes, nplanes)) < 0) {
av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
return -1;
}
buf += written;
src += pict->linesize[0];
}
if (nplanes == 1 && bpp == 8) {
if (buf_end - buf < 257) {
av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
return -1;
}
bytestream_put_byte(&buf, 12);
for (i = 0; i < 256; i++) {
bytestream_put_be24(&buf, pal[i]);
}
}
return buf - buf_start;
}
AVCodec pcx_encoder = {
"pcx",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_PCX,
sizeof(PCXContext),
pcx_encode_init,
pcx_encode_frame,
NULL,
.pix_fmts = (const enum PixelFormat[]){
PIX_FMT_RGB24,
PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
PIX_FMT_MONOBLACK,
PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/pcxenc.c | C | asf20 | 6,371 |
/*
* MPEG4 decoder / encoder common code.
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mpegvideo.h"
#include "mpeg4video.h"
#include "mpeg4data.h"
uint8_t ff_mpeg4_static_rl_table_store[3][2][2*MAX_RUN + MAX_LEVEL + 3];
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){
switch(s->pict_type){
case FF_I_TYPE:
return 16;
case FF_P_TYPE:
case FF_S_TYPE:
return s->f_code+15;
case FF_B_TYPE:
return FFMAX3(s->f_code, s->b_code, 2) + 15;
default:
return -1;
}
}
void ff_mpeg4_clean_buffers(MpegEncContext *s)
{
int c_wrap, c_xy, l_wrap, l_xy;
l_wrap= s->b8_stride;
l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1;
c_wrap= s->mb_stride;
c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1;
#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 can't 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;
}
#define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
#define tab_bias (tab_size/2)
//used by mpeg4 and rv10 decoder
void ff_mpeg4_init_direct_mv(MpegEncContext *s){
int i;
for(i=0; i<tab_size; i++){
s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time;
s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time;
}
}
static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){
int xy= s->block_index[i];
uint16_t time_pp= s->pp_time;
uint16_t time_pb= s->pb_time;
int p_mx, p_my;
p_mx= s->next_picture.motion_val[0][xy][0];
if((unsigned)(p_mx + tab_bias) < tab_size){
s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx;
s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
: s->direct_scale_mv[1][p_mx + tab_bias];
}else{
s->mv[0][i][0] = p_mx*time_pb/time_pp + mx;
s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx
: p_mx*(time_pb - time_pp)/time_pp;
}
p_my= s->next_picture.motion_val[0][xy][1];
if((unsigned)(p_my + tab_bias) < tab_size){
s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my;
s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
: s->direct_scale_mv[1][p_my + tab_bias];
}else{
s->mv[0][i][1] = p_my*time_pb/time_pp + my;
s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my
: p_my*(time_pb - time_pp)/time_pp;
}
}
#undef tab_size
#undef tab_bias
/**
*
* @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];
uint16_t time_pp;
uint16_t time_pb;
int i;
//FIXME avoid divides
// try special case with shifts for 1 and 3 B-frames?
if(IS_8X8(colocated_mb_type)){
s->mv_type = MV_TYPE_8X8;
for(i=0; i<4; i++){
ff_mpeg4_set_one_direct_mv(s, mx, my, i);
}
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++){
int field_select= s->next_picture.ref_index[0][4*mb_index + 2*i];
s->field_select[0][i]= field_select;
s->field_select[1][i]= i;
if(s->top_field_first){
time_pp= s->pp_field_time - field_select + i;
time_pb= s->pb_field_time - field_select + i;
}else{
time_pp= s->pp_field_time + field_select - i;
time_pb= s->pb_field_time + field_select - i;
}
s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx;
s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my;
s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0]
: s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp;
s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1]
: s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp;
}
return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
}else{
ff_mpeg4_set_one_direct_mv(s, mx, my, 0);
s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0];
s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1];
s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0];
s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1];
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
}
}
| 123linslouis-android-video-cutter | jni/libavcodec/mpeg4video.c | C | asf20 | 6,449 |
/*
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Native Vorbis encoder.
* @author Oded Shimon <ods15@ods15.dyndns.org>
*/
#include <float.h>
#include "avcodec.h"
#include "dsputil.h"
#include "fft.h"
#include "vorbis.h"
#include "vorbis_enc_data.h"
#define BITSTREAM_WRITER_LE
#include "put_bits.h"
#undef NDEBUG
#include <assert.h>
typedef struct {
int nentries;
uint8_t *lens;
uint32_t *codewords;
int ndimentions;
float min;
float delta;
int seq_p;
int lookup;
int *quantlist;
float *dimentions;
float *pow2;
} vorbis_enc_codebook;
typedef struct {
int dim;
int subclass;
int masterbook;
int *books;
} vorbis_enc_floor_class;
typedef struct {
int partitions;
int *partition_to_class;
int nclasses;
vorbis_enc_floor_class *classes;
int multiplier;
int rangebits;
int values;
vorbis_floor1_entry *list;
} vorbis_enc_floor;
typedef struct {
int type;
int begin;
int end;
int partition_size;
int classifications;
int classbook;
int8_t (*books)[8];
float (*maxes)[2];
} vorbis_enc_residue;
typedef struct {
int submaps;
int *mux;
int *floor;
int *residue;
int coupling_steps;
int *magnitude;
int *angle;
} vorbis_enc_mapping;
typedef struct {
int blockflag;
int mapping;
} vorbis_enc_mode;
typedef struct {
int channels;
int sample_rate;
int log2_blocksize[2];
FFTContext mdct[2];
const float *win[2];
int have_saved;
float *saved;
float *samples;
float *floor; // also used for tmp values for mdct
float *coeffs; // also used for residue after floor
float quality;
int ncodebooks;
vorbis_enc_codebook *codebooks;
int nfloors;
vorbis_enc_floor *floors;
int nresidues;
vorbis_enc_residue *residues;
int nmappings;
vorbis_enc_mapping *mappings;
int nmodes;
vorbis_enc_mode *modes;
int64_t sample_count;
} vorbis_enc_context;
static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb,
int entry)
{
assert(entry >= 0);
assert(entry < cb->nentries);
assert(cb->lens[entry]);
put_bits(pb, cb->lens[entry], cb->codewords[entry]);
}
static int cb_lookup_vals(int lookup, int dimentions, int entries)
{
if (lookup == 1)
return ff_vorbis_nth_root(entries, dimentions);
else if (lookup == 2)
return dimentions *entries;
return 0;
}
static void ready_codebook(vorbis_enc_codebook *cb)
{
int i;
ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);
if (!cb->lookup) {
cb->pow2 = cb->dimentions = NULL;
} else {
int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);
cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);
for (i = 0; i < cb->nentries; i++) {
float last = 0;
int j;
int div = 1;
for (j = 0; j < cb->ndimentions; j++) {
int off;
if (cb->lookup == 1)
off = (i / div) % vals; // lookup type 1
else
off = i * cb->ndimentions + j; // lookup type 2
cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta;
if (cb->seq_p)
last = cb->dimentions[i * cb->ndimentions + j];
cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j];
div *= vals;
}
cb->pow2[i] /= 2.;
}
}
}
static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc)
{
int i;
assert(rc->type == 2);
rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications);
for (i = 0; i < rc->classifications; i++) {
int j;
vorbis_enc_codebook * cb;
for (j = 0; j < 8; j++)
if (rc->books[i][j] != -1)
break;
if (j == 8) // zero
continue;
cb = &venc->codebooks[rc->books[i][j]];
assert(cb->ndimentions >= 2);
assert(cb->lookup);
for (j = 0; j < cb->nentries; j++) {
float a;
if (!cb->lens[j])
continue;
a = fabs(cb->dimentions[j * cb->ndimentions]);
if (a > rc->maxes[i][0])
rc->maxes[i][0] = a;
a = fabs(cb->dimentions[j * cb->ndimentions + 1]);
if (a > rc->maxes[i][1])
rc->maxes[i][1] = a;
}
}
// small bias
for (i = 0; i < rc->classifications; i++) {
rc->maxes[i][0] += 0.8;
rc->maxes[i][1] += 0.8;
}
}
static void create_vorbis_context(vorbis_enc_context *venc,
AVCodecContext *avccontext)
{
vorbis_enc_floor *fc;
vorbis_enc_residue *rc;
vorbis_enc_mapping *mc;
int i, book;
venc->channels = avccontext->channels;
venc->sample_rate = avccontext->sample_rate;
venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;
venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);
venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);
// codebook 0..14 - floor1 book, values 0..255
// codebook 15 residue masterbook
// codebook 16..29 residue
for (book = 0; book < venc->ncodebooks; book++) {
vorbis_enc_codebook *cb = &venc->codebooks[book];
int vals;
cb->ndimentions = cvectors[book].dim;
cb->nentries = cvectors[book].real_len;
cb->min = cvectors[book].min;
cb->delta = cvectors[book].delta;
cb->lookup = cvectors[book].lookup;
cb->seq_p = 0;
cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries);
cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);
memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);
memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);
if (cb->lookup) {
vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
cb->quantlist = av_malloc(sizeof(int) * vals);
for (i = 0; i < vals; i++)
cb->quantlist[i] = cvectors[book].quant[i];
} else {
cb->quantlist = NULL;
}
ready_codebook(cb);
}
venc->nfloors = 1;
venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);
// just 1 floor
fc = &venc->floors[0];
fc->partitions = 8;
fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);
fc->nclasses = 0;
for (i = 0; i < fc->partitions; i++) {
static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4};
fc->partition_to_class[i] = a[i];
fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]);
}
fc->nclasses++;
fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses);
for (i = 0; i < fc->nclasses; i++) {
vorbis_enc_floor_class * c = &fc->classes[i];
int j, books;
c->dim = floor_classes[i].dim;
c->subclass = floor_classes[i].subclass;
c->masterbook = floor_classes[i].masterbook;
books = (1 << c->subclass);
c->books = av_malloc(sizeof(int) * books);
for (j = 0; j < books; j++)
c->books[j] = floor_classes[i].nbooks[j];
}
fc->multiplier = 2;
fc->rangebits = venc->log2_blocksize[0] - 1;
fc->values = 2;
for (i = 0; i < fc->partitions; i++)
fc->values += fc->classes[fc->partition_to_class[i]].dim;
fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values);
fc->list[0].x = 0;
fc->list[1].x = 1 << fc->rangebits;
for (i = 2; i < fc->values; i++) {
static const int a[] = {
93, 23,372, 6, 46,186,750, 14, 33, 65,
130,260,556, 3, 10, 18, 28, 39, 55, 79,
111,158,220,312,464,650,850
};
fc->list[i].x = a[i - 2];
}
ff_vorbis_ready_floor1_list(fc->list, fc->values);
venc->nresidues = 1;
venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);
// single residue
rc = &venc->residues[0];
rc->type = 2;
rc->begin = 0;
rc->end = 1600;
rc->partition_size = 32;
rc->classifications = 10;
rc->classbook = 15;
rc->books = av_malloc(sizeof(*rc->books) * rc->classifications);
{
static const int8_t a[10][8] = {
{ -1, -1, -1, -1, -1, -1, -1, -1, },
{ -1, -1, 16, -1, -1, -1, -1, -1, },
{ -1, -1, 17, -1, -1, -1, -1, -1, },
{ -1, -1, 18, -1, -1, -1, -1, -1, },
{ -1, -1, 19, -1, -1, -1, -1, -1, },
{ -1, -1, 20, -1, -1, -1, -1, -1, },
{ -1, -1, 21, -1, -1, -1, -1, -1, },
{ 22, 23, -1, -1, -1, -1, -1, -1, },
{ 24, 25, -1, -1, -1, -1, -1, -1, },
{ 26, 27, 28, -1, -1, -1, -1, -1, },
};
memcpy(rc->books, a, sizeof a);
}
ready_residue(rc, venc);
venc->nmappings = 1;
venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);
// single mapping
mc = &venc->mappings[0];
mc->submaps = 1;
mc->mux = av_malloc(sizeof(int) * venc->channels);
for (i = 0; i < venc->channels; i++)
mc->mux[i] = 0;
mc->floor = av_malloc(sizeof(int) * mc->submaps);
mc->residue = av_malloc(sizeof(int) * mc->submaps);
for (i = 0; i < mc->submaps; i++) {
mc->floor[i] = 0;
mc->residue[i] = 0;
}
mc->coupling_steps = venc->channels == 2 ? 1 : 0;
mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps);
mc->angle = av_malloc(sizeof(int) * mc->coupling_steps);
if (mc->coupling_steps) {
mc->magnitude[0] = 0;
mc->angle[0] = 1;
}
venc->nmodes = 1;
venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);
// single mode
venc->modes[0].blockflag = 0;
venc->modes[0].mapping = 0;
venc->have_saved = 0;
venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));
venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);
venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];
venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];
ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0);
ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0);
}
static void put_float(PutBitContext *pb, float f)
{
int exp, mant;
uint32_t res = 0;
mant = (int)ldexp(frexp(f, &exp), 20);
exp += 788 - 20;
if (mant < 0) {
res |= (1 << 31);
mant = -mant;
}
res |= mant | (exp << 21);
put_bits32(pb, res);
}
static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb)
{
int i;
int ordered = 0;
put_bits(pb, 24, 0x564342); //magic
put_bits(pb, 16, cb->ndimentions);
put_bits(pb, 24, cb->nentries);
for (i = 1; i < cb->nentries; i++)
if (cb->lens[i] < cb->lens[i-1])
break;
if (i == cb->nentries)
ordered = 1;
put_bits(pb, 1, ordered);
if (ordered) {
int len = cb->lens[0];
put_bits(pb, 5, len - 1);
i = 0;
while (i < cb->nentries) {
int j;
for (j = 0; j+i < cb->nentries; j++)
if (cb->lens[j+i] != len)
break;
put_bits(pb, ilog(cb->nentries - i), j);
i += j;
len++;
}
} else {
int sparse = 0;
for (i = 0; i < cb->nentries; i++)
if (!cb->lens[i])
break;
if (i != cb->nentries)
sparse = 1;
put_bits(pb, 1, sparse);
for (i = 0; i < cb->nentries; i++) {
if (sparse)
put_bits(pb, 1, !!cb->lens[i]);
if (cb->lens[i])
put_bits(pb, 5, cb->lens[i] - 1);
}
}
put_bits(pb, 4, cb->lookup);
if (cb->lookup) {
int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);
int bits = ilog(cb->quantlist[0]);
for (i = 1; i < tmp; i++)
bits = FFMAX(bits, ilog(cb->quantlist[i]));
put_float(pb, cb->min);
put_float(pb, cb->delta);
put_bits(pb, 4, bits - 1);
put_bits(pb, 1, cb->seq_p);
for (i = 0; i < tmp; i++)
put_bits(pb, bits, cb->quantlist[i]);
}
}
static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc)
{
int i;
put_bits(pb, 16, 1); // type, only floor1 is supported
put_bits(pb, 5, fc->partitions);
for (i = 0; i < fc->partitions; i++)
put_bits(pb, 4, fc->partition_to_class[i]);
for (i = 0; i < fc->nclasses; i++) {
int j, books;
put_bits(pb, 3, fc->classes[i].dim - 1);
put_bits(pb, 2, fc->classes[i].subclass);
if (fc->classes[i].subclass)
put_bits(pb, 8, fc->classes[i].masterbook);
books = (1 << fc->classes[i].subclass);
for (j = 0; j < books; j++)
put_bits(pb, 8, fc->classes[i].books[j] + 1);
}
put_bits(pb, 2, fc->multiplier - 1);
put_bits(pb, 4, fc->rangebits);
for (i = 2; i < fc->values; i++)
put_bits(pb, fc->rangebits, fc->list[i].x);
}
static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc)
{
int i;
put_bits(pb, 16, rc->type);
put_bits(pb, 24, rc->begin);
put_bits(pb, 24, rc->end);
put_bits(pb, 24, rc->partition_size - 1);
put_bits(pb, 6, rc->classifications - 1);
put_bits(pb, 8, rc->classbook);
for (i = 0; i < rc->classifications; i++) {
int j, tmp = 0;
for (j = 0; j < 8; j++)
tmp |= (rc->books[i][j] != -1) << j;
put_bits(pb, 3, tmp & 7);
put_bits(pb, 1, tmp > 7);
if (tmp > 7)
put_bits(pb, 5, tmp >> 3);
}
for (i = 0; i < rc->classifications; i++) {
int j;
for (j = 0; j < 8; j++)
if (rc->books[i][j] != -1)
put_bits(pb, 8, rc->books[i][j]);
}
}
static int put_main_header(vorbis_enc_context *venc, uint8_t **out)
{
int i;
PutBitContext pb;
uint8_t buffer[50000] = {0}, *p = buffer;
int buffer_len = sizeof buffer;
int len, hlens[3];
// identification header
init_put_bits(&pb, p, buffer_len);
put_bits(&pb, 8, 1); //magic
for (i = 0; "vorbis"[i]; i++)
put_bits(&pb, 8, "vorbis"[i]);
put_bits32(&pb, 0); // version
put_bits(&pb, 8, venc->channels);
put_bits32(&pb, venc->sample_rate);
put_bits32(&pb, 0); // bitrate
put_bits32(&pb, 0); // bitrate
put_bits32(&pb, 0); // bitrate
put_bits(&pb, 4, venc->log2_blocksize[0]);
put_bits(&pb, 4, venc->log2_blocksize[1]);
put_bits(&pb, 1, 1); // framing
flush_put_bits(&pb);
hlens[0] = put_bits_count(&pb) >> 3;
buffer_len -= hlens[0];
p += hlens[0];
// comment header
init_put_bits(&pb, p, buffer_len);
put_bits(&pb, 8, 3); //magic
for (i = 0; "vorbis"[i]; i++)
put_bits(&pb, 8, "vorbis"[i]);
put_bits32(&pb, 0); // vendor length TODO
put_bits32(&pb, 0); // amount of comments
put_bits(&pb, 1, 1); // framing
flush_put_bits(&pb);
hlens[1] = put_bits_count(&pb) >> 3;
buffer_len -= hlens[1];
p += hlens[1];
// setup header
init_put_bits(&pb, p, buffer_len);
put_bits(&pb, 8, 5); //magic
for (i = 0; "vorbis"[i]; i++)
put_bits(&pb, 8, "vorbis"[i]);
// codebooks
put_bits(&pb, 8, venc->ncodebooks - 1);
for (i = 0; i < venc->ncodebooks; i++)
put_codebook_header(&pb, &venc->codebooks[i]);
// time domain, reserved, zero
put_bits(&pb, 6, 0);
put_bits(&pb, 16, 0);
// floors
put_bits(&pb, 6, venc->nfloors - 1);
for (i = 0; i < venc->nfloors; i++)
put_floor_header(&pb, &venc->floors[i]);
// residues
put_bits(&pb, 6, venc->nresidues - 1);
for (i = 0; i < venc->nresidues; i++)
put_residue_header(&pb, &venc->residues[i]);
// mappings
put_bits(&pb, 6, venc->nmappings - 1);
for (i = 0; i < venc->nmappings; i++) {
vorbis_enc_mapping *mc = &venc->mappings[i];
int j;
put_bits(&pb, 16, 0); // mapping type
put_bits(&pb, 1, mc->submaps > 1);
if (mc->submaps > 1)
put_bits(&pb, 4, mc->submaps - 1);
put_bits(&pb, 1, !!mc->coupling_steps);
if (mc->coupling_steps) {
put_bits(&pb, 8, mc->coupling_steps - 1);
for (j = 0; j < mc->coupling_steps; j++) {
put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]);
put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]);
}
}
put_bits(&pb, 2, 0); // reserved
if (mc->submaps > 1)
for (j = 0; j < venc->channels; j++)
put_bits(&pb, 4, mc->mux[j]);
for (j = 0; j < mc->submaps; j++) {
put_bits(&pb, 8, 0); // reserved time configuration
put_bits(&pb, 8, mc->floor[j]);
put_bits(&pb, 8, mc->residue[j]);
}
}
// modes
put_bits(&pb, 6, venc->nmodes - 1);
for (i = 0; i < venc->nmodes; i++) {
put_bits(&pb, 1, venc->modes[i].blockflag);
put_bits(&pb, 16, 0); // reserved window type
put_bits(&pb, 16, 0); // reserved transform type
put_bits(&pb, 8, venc->modes[i].mapping);
}
put_bits(&pb, 1, 1); // framing
flush_put_bits(&pb);
hlens[2] = put_bits_count(&pb) >> 3;
len = hlens[0] + hlens[1] + hlens[2];
p = *out = av_mallocz(64 + len + len/255);
*p++ = 2;
p += av_xiphlacing(p, hlens[0]);
p += av_xiphlacing(p, hlens[1]);
buffer_len = 0;
for (i = 0; i < 3; i++) {
memcpy(p, buffer + buffer_len, hlens[i]);
p += hlens[i];
buffer_len += hlens[i];
}
return p - *out;
}
static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i)
{
int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x;
int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x;
int j;
float average = 0;
for (j = begin; j < end; j++)
average += fabs(coeffs[j]);
return average / (end - begin);
}
static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc,
float *coeffs, uint_fast16_t *posts, int samples)
{
int range = 255 / fc->multiplier + 1;
int i;
float tot_average = 0.;
float averages[fc->values];
for (i = 0; i < fc->values; i++) {
averages[i] = get_floor_average(fc, coeffs, i);
tot_average += averages[i];
}
tot_average /= fc->values;
tot_average /= venc->quality;
for (i = 0; i < fc->values; i++) {
int position = fc->list[fc->list[i].sort].x;
float average = averages[i];
int j;
average *= pow(tot_average / average, 0.5) * pow(1.25, position/200.); // MAGIC!
for (j = 0; j < range - 1; j++)
if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average)
break;
posts[fc->list[i].sort] = j;
}
}
static int render_point(int x0, int y0, int x1, int y1, int x)
{
return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
}
static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc,
PutBitContext *pb, uint_fast16_t *posts,
float *floor, int samples)
{
int range = 255 / fc->multiplier + 1;
int coded[fc->values]; // first 2 values are unused
int i, counter;
put_bits(pb, 1, 1); // non zero
put_bits(pb, ilog(range - 1), posts[0]);
put_bits(pb, ilog(range - 1), posts[1]);
coded[0] = coded[1] = 1;
for (i = 2; i < fc->values; i++) {
int predicted = render_point(fc->list[fc->list[i].low].x,
posts[fc->list[i].low],
fc->list[fc->list[i].high].x,
posts[fc->list[i].high],
fc->list[i].x);
int highroom = range - predicted;
int lowroom = predicted;
int room = FFMIN(highroom, lowroom);
if (predicted == posts[i]) {
coded[i] = 0; // must be used later as flag!
continue;
} else {
if (!coded[fc->list[i].low ])
coded[fc->list[i].low ] = -1;
if (!coded[fc->list[i].high])
coded[fc->list[i].high] = -1;
}
if (posts[i] > predicted) {
if (posts[i] - predicted > room)
coded[i] = posts[i] - predicted + lowroom;
else
coded[i] = (posts[i] - predicted) << 1;
} else {
if (predicted - posts[i] > room)
coded[i] = predicted - posts[i] + highroom - 1;
else
coded[i] = ((predicted - posts[i]) << 1) - 1;
}
}
counter = 2;
for (i = 0; i < fc->partitions; i++) {
vorbis_enc_floor_class * c = &fc->classes[fc->partition_to_class[i]];
int k, cval = 0, csub = 1<<c->subclass;
if (c->subclass) {
vorbis_enc_codebook * book = &venc->codebooks[c->masterbook];
int cshift = 0;
for (k = 0; k < c->dim; k++) {
int l;
for (l = 0; l < csub; l++) {
int maxval = 1;
if (c->books[l] != -1)
maxval = venc->codebooks[c->books[l]].nentries;
// coded could be -1, but this still works, cause that is 0
if (coded[counter + k] < maxval)
break;
}
assert(l != csub);
cval |= l << cshift;
cshift += c->subclass;
}
put_codeword(pb, book, cval);
}
for (k = 0; k < c->dim; k++) {
int book = c->books[cval & (csub-1)];
int entry = coded[counter++];
cval >>= c->subclass;
if (book == -1)
continue;
if (entry == -1)
entry = 0;
put_codeword(pb, &venc->codebooks[book], entry);
}
}
ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded,
fc->multiplier, floor, samples);
}
static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb,
float *num)
{
int i, entry = -1;
float distance = FLT_MAX;
assert(book->dimentions);
for (i = 0; i < book->nentries; i++) {
float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i];
int j;
if (!book->lens[i])
continue;
for (j = 0; j < book->ndimentions; j++)
d -= vec[j] * num[j];
if (distance > d) {
entry = i;
distance = d;
}
}
put_codeword(pb, book, entry);
return &book->dimentions[entry * book->ndimentions];
}
static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc,
PutBitContext *pb, float *coeffs, int samples,
int real_ch)
{
int pass, i, j, p, k;
int psize = rc->partition_size;
int partitions = (rc->end - rc->begin) / psize;
int channels = (rc->type == 2) ? 1 : real_ch;
int classes[channels][partitions];
int classwords = venc->codebooks[rc->classbook].ndimentions;
assert(rc->type == 2);
assert(real_ch == 2);
for (p = 0; p < partitions; p++) {
float max1 = 0., max2 = 0.;
int s = rc->begin + p * psize;
for (k = s; k < s + psize; k += 2) {
max1 = FFMAX(max1, fabs(coeffs[ k / real_ch]));
max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch]));
}
for (i = 0; i < rc->classifications - 1; i++)
if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1])
break;
classes[0][p] = i;
}
for (pass = 0; pass < 8; pass++) {
p = 0;
while (p < partitions) {
if (pass == 0)
for (j = 0; j < channels; j++) {
vorbis_enc_codebook * book = &venc->codebooks[rc->classbook];
int entry = 0;
for (i = 0; i < classwords; i++) {
entry *= rc->classifications;
entry += classes[j][p + i];
}
put_codeword(pb, book, entry);
}
for (i = 0; i < classwords && p < partitions; i++, p++) {
for (j = 0; j < channels; j++) {
int nbook = rc->books[classes[j][p]][pass];
vorbis_enc_codebook * book = &venc->codebooks[nbook];
float *buf = coeffs + samples*j + rc->begin + p*psize;
if (nbook == -1)
continue;
assert(rc->type == 0 || rc->type == 2);
assert(!(psize % book->ndimentions));
if (rc->type == 0) {
for (k = 0; k < psize; k += book->ndimentions) {
float *a = put_vector(book, pb, &buf[k]);
int l;
for (l = 0; l < book->ndimentions; l++)
buf[k + l] -= a[l];
}
} else {
int s = rc->begin + p * psize, a1, b1;
a1 = (s % real_ch) * samples;
b1 = s / real_ch;
s = real_ch * samples;
for (k = 0; k < psize; k += book->ndimentions) {
int dim, a2 = a1, b2 = b1;
float vec[book->ndimentions], *pv = vec;
for (dim = book->ndimentions; dim--; ) {
*pv++ = coeffs[a2 + b2];
if ((a2 += samples) == s) {
a2 = 0;
b2++;
}
}
pv = put_vector(book, pb, vec);
for (dim = book->ndimentions; dim--; ) {
coeffs[a1 + b1] -= *pv++;
if ((a1 += samples) == s) {
a1 = 0;
b1++;
}
}
}
}
}
}
}
}
}
static int apply_window_and_mdct(vorbis_enc_context *venc, signed short *audio,
int samples)
{
int i, j, channel;
const float * win = venc->win[0];
int window_len = 1 << (venc->log2_blocksize[0] - 1);
float n = (float)(1 << venc->log2_blocksize[0]) / 4.;
// FIXME use dsp
if (!venc->have_saved && !samples)
return 0;
if (venc->have_saved) {
for (channel = 0; channel < venc->channels; channel++)
memcpy(venc->samples + channel * window_len * 2,
venc->saved + channel * window_len, sizeof(float) * window_len);
} else {
for (channel = 0; channel < venc->channels; channel++)
memset(venc->samples + channel * window_len * 2, 0,
sizeof(float) * window_len);
}
if (samples) {
for (channel = 0; channel < venc->channels; channel++) {
float * offset = venc->samples + channel*window_len*2 + window_len;
j = channel;
for (i = 0; i < samples; i++, j += venc->channels)
offset[i] = -audio[j] / 32768. / n * win[window_len - i - 1]; //FIXME find out why the sign has to be fliped
}
} else {
for (channel = 0; channel < venc->channels; channel++)
memset(venc->samples + channel * window_len * 2 + window_len,
0, sizeof(float) * window_len);
}
for (channel = 0; channel < venc->channels; channel++)
ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len,
venc->samples + channel * window_len * 2);
if (samples) {
for (channel = 0; channel < venc->channels; channel++) {
float *offset = venc->saved + channel * window_len;
j = channel;
for (i = 0; i < samples; i++, j += venc->channels)
offset[i] = -audio[j] / 32768. / n * win[i]; //FIXME find out why the sign has to be fliped
}
venc->have_saved = 1;
} else {
venc->have_saved = 0;
}
return 1;
}
static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
{
vorbis_enc_context *venc = avccontext->priv_data;
if (avccontext->channels != 2) {
av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
return -1;
}
create_vorbis_context(venc, avccontext);
if (avccontext->flags & CODEC_FLAG_QSCALE)
venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;
else
venc->quality = 1.;
venc->quality *= venc->quality;
avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
avccontext->coded_frame = avcodec_alloc_frame();
avccontext->coded_frame->key_frame = 1;
return 0;
}
static int vorbis_encode_frame(AVCodecContext *avccontext,
unsigned char *packets,
int buf_size, void *data)
{
vorbis_enc_context *venc = avccontext->priv_data;
signed short *audio = data;
int samples = data ? avccontext->frame_size : 0;
vorbis_enc_mode *mode;
vorbis_enc_mapping *mapping;
PutBitContext pb;
int i;
if (!apply_window_and_mdct(venc, audio, samples))
return 0;
samples = 1 << (venc->log2_blocksize[0] - 1);
init_put_bits(&pb, packets, buf_size);
put_bits(&pb, 1, 0); // magic bit
put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode
mode = &venc->modes[0];
mapping = &venc->mappings[mode->mapping];
if (mode->blockflag) {
put_bits(&pb, 1, 0);
put_bits(&pb, 1, 0);
}
for (i = 0; i < venc->channels; i++) {
vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]];
uint_fast16_t posts[fc->values];
floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples);
floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples);
}
for (i = 0; i < venc->channels * samples; i++)
venc->coeffs[i] /= venc->floor[i];
for (i = 0; i < mapping->coupling_steps; i++) {
float *mag = venc->coeffs + mapping->magnitude[i] * samples;
float *ang = venc->coeffs + mapping->angle[i] * samples;
int j;
for (j = 0; j < samples; j++) {
float a = ang[j];
ang[j] -= mag[j];
if (mag[j] > 0)
ang[j] = -ang[j];
if (ang[j] < 0)
mag[j] = a;
}
}
residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]],
&pb, venc->coeffs, samples, venc->channels);
avccontext->coded_frame->pts = venc->sample_count;
venc->sample_count += avccontext->frame_size;
flush_put_bits(&pb);
return put_bits_count(&pb) >> 3;
}
static av_cold int vorbis_encode_close(AVCodecContext *avccontext)
{
vorbis_enc_context *venc = avccontext->priv_data;
int i;
if (venc->codebooks)
for (i = 0; i < venc->ncodebooks; i++) {
av_freep(&venc->codebooks[i].lens);
av_freep(&venc->codebooks[i].codewords);
av_freep(&venc->codebooks[i].quantlist);
av_freep(&venc->codebooks[i].dimentions);
av_freep(&venc->codebooks[i].pow2);
}
av_freep(&venc->codebooks);
if (venc->floors)
for (i = 0; i < venc->nfloors; i++) {
int j;
if (venc->floors[i].classes)
for (j = 0; j < venc->floors[i].nclasses; j++)
av_freep(&venc->floors[i].classes[j].books);
av_freep(&venc->floors[i].classes);
av_freep(&venc->floors[i].partition_to_class);
av_freep(&venc->floors[i].list);
}
av_freep(&venc->floors);
if (venc->residues)
for (i = 0; i < venc->nresidues; i++) {
av_freep(&venc->residues[i].books);
av_freep(&venc->residues[i].maxes);
}
av_freep(&venc->residues);
if (venc->mappings)
for (i = 0; i < venc->nmappings; i++) {
av_freep(&venc->mappings[i].mux);
av_freep(&venc->mappings[i].floor);
av_freep(&venc->mappings[i].residue);
av_freep(&venc->mappings[i].magnitude);
av_freep(&venc->mappings[i].angle);
}
av_freep(&venc->mappings);
av_freep(&venc->modes);
av_freep(&venc->saved);
av_freep(&venc->samples);
av_freep(&venc->floor);
av_freep(&venc->coeffs);
ff_mdct_end(&venc->mdct[0]);
ff_mdct_end(&venc->mdct[1]);
av_freep(&avccontext->coded_frame);
av_freep(&avccontext->extradata);
return 0 ;
}
AVCodec vorbis_encoder = {
"vorbis",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_VORBIS,
sizeof(vorbis_enc_context),
vorbis_encode_init,
vorbis_encode_frame,
vorbis_encode_close,
.capabilities= CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL,
.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/vorbis_enc.c | C | asf20 | 35,148 |
/*
* RV30 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* RV30 decoder
*/
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "golomb.h"
#include "rv34.h"
#include "rv30data.h"
static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
{
int mb_bits;
int w = r->s.width, h = r->s.height;
int mb_size;
int rpr;
memset(si, 0, sizeof(SliceInfo));
if(get_bits(gb, 3))
return -1;
si->type = get_bits(gb, 2);
if(si->type == 1) si->type = 0;
if(get_bits1(gb))
return -1;
si->quant = get_bits(gb, 5);
skip_bits1(gb);
si->pts = get_bits(gb, 13);
rpr = get_bits(gb, r->rpr);
if(rpr){
w = r->s.avctx->extradata[6 + rpr*2] << 2;
h = r->s.avctx->extradata[7 + rpr*2] << 2;
}
si->width = w;
si->height = h;
mb_size = ((w + 15) >> 4) * ((h + 15) >> 4);
mb_bits = ff_rv34_get_start_offset(gb, mb_size);
si->start = get_bits(gb, mb_bits);
skip_bits1(gb);
return 0;
}
/**
* Decode 4x4 intra types array.
*/
static int rv30_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst)
{
int i, j, k;
for(i = 0; i < 4; i++, dst += r->intra_types_stride - 4){
for(j = 0; j < 4; j+= 2){
int code = svq3_get_ue_golomb(gb) << 1;
if(code >= 81*2){
av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction code\n");
return -1;
}
for(k = 0; k < 2; k++){
int A = dst[-r->intra_types_stride] + 1;
int B = dst[-1] + 1;
*dst++ = rv30_itype_from_context[A * 90 + B * 9 + rv30_itype_code[code + k]];
if(dst[-1] == 9){
av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction mode\n");
return -1;
}
}
}
}
return 0;
}
/**
* Decode macroblock information.
*/
static int rv30_decode_mb_info(RV34DecContext *r)
{
static const int rv30_p_types[6] = { RV34_MB_SKIP, RV34_MB_P_16x16, RV34_MB_P_8x8, -1, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
static const int rv30_b_types[6] = { RV34_MB_SKIP, RV34_MB_B_DIRECT, RV34_MB_B_FORWARD, RV34_MB_B_BACKWARD, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
MpegEncContext *s = &r->s;
GetBitContext *gb = &s->gb;
int code = svq3_get_ue_golomb(gb);
if(code > 11){
av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n");
return -1;
}
if(code > 5){
av_log(s->avctx, AV_LOG_ERROR, "dquant needed\n");
code -= 6;
}
if(s->pict_type != FF_B_TYPE)
return rv30_p_types[code];
else
return rv30_b_types[code];
}
static inline void rv30_weak_loop_filter(uint8_t *src, const int step,
const int stride, const int lim)
{
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int i, diff;
for(i = 0; i < 4; i++){
diff = ((src[-2*step] - src[1*step]) - (src[-1*step] - src[0*step])*4) >> 3;
diff = av_clip(diff, -lim, lim);
src[-1*step] = cm[src[-1*step] + diff];
src[ 0*step] = cm[src[ 0*step] - diff];
src += stride;
}
}
static void rv30_loop_filter(RV34DecContext *r, int row)
{
MpegEncContext *s = &r->s;
int mb_pos, mb_x;
int i, j, k;
uint8_t *Y, *C;
int loc_lim, cur_lim, left_lim = 0, top_lim = 0;
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int mbtype = s->current_picture_ptr->mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
r->cbp_chroma[mb_pos] = 0xFF;
}
/* all vertical edges are filtered first
* and horizontal edges are filtered on the next iteration
*/
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]];
if(mb_x)
left_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - 1]];
for(j = 0; j < 16; j += 4){
Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize + 4 * !mb_x;
for(i = !mb_x; i < 4; i++, Y += 4){
int ij = i + j;
loc_lim = 0;
if(r->deblock_coefs[mb_pos] & (1 << ij))
loc_lim = cur_lim;
else if(!i && r->deblock_coefs[mb_pos - 1] & (1 << (ij + 3)))
loc_lim = left_lim;
else if( i && r->deblock_coefs[mb_pos] & (1 << (ij - 1)))
loc_lim = cur_lim;
if(loc_lim)
rv30_weak_loop_filter(Y, 1, s->linesize, loc_lim);
}
}
for(k = 0; k < 2; k++){
int cur_cbp, left_cbp = 0;
cur_cbp = (r->cbp_chroma[mb_pos] >> (k*4)) & 0xF;
if(mb_x)
left_cbp = (r->cbp_chroma[mb_pos - 1] >> (k*4)) & 0xF;
for(j = 0; j < 8; j += 4){
C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize + 4 * !mb_x;
for(i = !mb_x; i < 2; i++, C += 4){
int ij = i + (j >> 1);
loc_lim = 0;
if(cur_cbp && (1 << ij))
loc_lim = cur_lim;
else if(!i && left_cbp & (1 << (ij + 1)))
loc_lim = left_lim;
else if( i && cur_cbp & (1 << (ij - 1)))
loc_lim = cur_lim;
if(loc_lim)
rv30_weak_loop_filter(C, 1, s->uvlinesize, loc_lim);
}
}
}
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]];
if(row)
top_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - s->mb_stride]];
for(j = 4*!row; j < 16; j += 4){
Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
loc_lim = 0;
if(r->deblock_coefs[mb_pos] & (1 << ij))
loc_lim = cur_lim;
else if(!j && r->deblock_coefs[mb_pos - s->mb_stride] & (1 << (ij + 12)))
loc_lim = top_lim;
else if( j && r->deblock_coefs[mb_pos] & (1 << (ij - 4)))
loc_lim = cur_lim;
if(loc_lim)
rv30_weak_loop_filter(Y, s->linesize, 1, loc_lim);
}
}
for(k = 0; k < 2; k++){
int cur_cbp, top_cbp = 0;
cur_cbp = (r->cbp_chroma[mb_pos] >> (k*4)) & 0xF;
if(row)
top_cbp = (r->cbp_chroma[mb_pos - s->mb_stride] >> (k*4)) & 0xF;
for(j = 4*!row; j < 8; j += 4){
C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + (j >> 1);
loc_lim = 0;
if(r->cbp_chroma[mb_pos] && (1 << ij))
loc_lim = cur_lim;
else if(!j && top_cbp & (1 << (ij + 2)))
loc_lim = top_lim;
else if( j && cur_cbp & (1 << (ij - 2)))
loc_lim = cur_lim;
if(loc_lim)
rv30_weak_loop_filter(C, s->uvlinesize, 1, loc_lim);
}
}
}
}
}
/**
* Initialize decoder.
*/
static av_cold int rv30_decode_init(AVCodecContext *avctx)
{
RV34DecContext *r = avctx->priv_data;
r->rv30 = 1;
ff_rv34_decode_init(avctx);
if(avctx->extradata_size < 2){
av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n");
return -1;
}
r->rpr = (avctx->extradata[1] & 7) >> 1;
r->rpr = FFMIN(r->rpr + 1, 3);
if(avctx->extradata_size - 8 < (r->rpr - 1) * 2){
av_log(avctx, AV_LOG_ERROR, "Insufficient extradata - need at least %d bytes, got %d\n",
6 + r->rpr * 2, avctx->extradata_size);
}
r->parse_slice_header = rv30_parse_slice_header;
r->decode_intra_types = rv30_decode_intra_types;
r->decode_mb_info = rv30_decode_mb_info;
r->loop_filter = rv30_loop_filter;
r->luma_dc_quant_i = rv30_luma_dc_quant;
r->luma_dc_quant_p = rv30_luma_dc_quant;
return 0;
}
AVCodec rv30_decoder = {
"rv30",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_RV30,
sizeof(RV34DecContext),
rv30_decode_init,
NULL,
ff_rv34_decode_end,
ff_rv34_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_DELAY,
.flush = ff_mpeg_flush,
.long_name = NULL_IF_CONFIG_SMALL("RealVideo 3.0"),
.pix_fmts= ff_pixfmt_list_420,
};
| 123linslouis-android-video-cutter | jni/libavcodec/rv30.c | C | asf20 | 9,841 |
/*
* Musepack SV7 decoder
* Copyright (c) 2006 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
* divided into 32 subbands.
*/
#include "libavutil/lfg.h"
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#include "mpegaudio.h"
#include "mpc.h"
#include "mpc7data.h"
#define BANDS 32
#define SAMPLES_PER_BAND 36
#define MPC_FRAME_SIZE (BANDS * SAMPLES_PER_BAND)
static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2];
static const uint16_t quant_offsets[MPC7_QUANT_VLC_TABLES*2 + 1] =
{
0, 512, 1024, 1536, 2052, 2564, 3076, 3588, 4100, 4612, 5124,
5636, 6164, 6676, 7224
};
static av_cold int mpc7_decode_init(AVCodecContext * avctx)
{
int i, j;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
uint8_t buf[16];
static int vlc_initialized = 0;
static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2];
static VLC_TYPE dscf_table[1 << MPC7_DSCF_BITS][2];
static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2];
static VLC_TYPE quant_tables[7224][2];
if(avctx->extradata_size < 16){
av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
return -1;
}
memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
av_lfg_init(&c->rnd, 0xDEADBEEF);
dsputil_init(&c->dsp, avctx);
c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);
ff_mpc_init();
init_get_bits(&gb, buf, 128);
c->IS = get_bits1(&gb);
c->MSS = get_bits1(&gb);
c->maxbands = get_bits(&gb, 6);
if(c->maxbands >= BANDS){
av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands);
return -1;
}
skip_bits_long(&gb, 88);
c->gapless = get_bits1(&gb);
c->lastframelen = get_bits(&gb, 11);
av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);
c->frames_to_skip = 0;
avctx->sample_fmt = SAMPLE_FMT_S16;
avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
if(vlc_initialized) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
scfi_vlc.table = scfi_table;
scfi_vlc.table_allocated = 1 << MPC7_SCFI_BITS;
if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
&mpc7_scfi[1], 2, 1,
&mpc7_scfi[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n");
return -1;
}
dscf_vlc.table = dscf_table;
dscf_vlc.table_allocated = 1 << MPC7_DSCF_BITS;
if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
&mpc7_dscf[1], 2, 1,
&mpc7_dscf[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n");
return -1;
}
hdr_vlc.table = hdr_table;
hdr_vlc.table_allocated = 1 << MPC7_HDR_BITS;
if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
&mpc7_hdr[1], 2, 1,
&mpc7_hdr[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n");
return -1;
}
for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){
for(j = 0; j < 2; j++){
quant_vlc[i][j].table = &quant_tables[quant_offsets[i*2 + j]];
quant_vlc[i][j].table_allocated = quant_offsets[i*2 + j + 1] - quant_offsets[i*2 + j];
if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],
&mpc7_quant_vlc[i][j][1], 4, 2,
&mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j);
return -1;
}
}
}
vlc_initialized = 1;
return 0;
}
/**
* Fill samples for given subband
*/
static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *dst)
{
int i, i1, t;
switch(idx){
case -1:
for(i = 0; i < SAMPLES_PER_BAND; i++){
*dst++ = (av_lfg_get(&c->rnd) & 0x3FC) - 510;
}
break;
case 1:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND/3; i++){
t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2);
*dst++ = mpc7_idx30[t];
*dst++ = mpc7_idx31[t];
*dst++ = mpc7_idx32[t];
}
break;
case 2:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND/2; i++){
t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2);
*dst++ = mpc7_idx50[t];
*dst++ = mpc7_idx51[t];
}
break;
case 3: case 4: case 5: case 6: case 7:
i1 = get_bits1(gb);
for(i = 0; i < SAMPLES_PER_BAND; i++)
*dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx-1];
break;
case 8: case 9: case 10: case 11: case 12:
case 13: case 14: case 15: case 16: case 17:
t = (1 << (idx - 2)) - 1;
for(i = 0; i < SAMPLES_PER_BAND; i++)
*dst++ = get_bits(gb, idx - 1) - t;
break;
default: // case 0 and -2..-17
return;
}
}
static int get_scale_idx(GetBitContext *gb, int ref)
{
int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7;
if (t == 8)
return get_bits(gb, 6);
return ref + t;
}
static int mpc7_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
uint8_t *bits;
int i, ch;
int mb = -1;
Band *bands = c->bands;
int off;
int bits_used, bits_avail;
memset(bands, 0, sizeof(bands));
if(buf_size <= 4){
av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size);
}
bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE);
c->dsp.bswap_buf((uint32_t*)bits, (const uint32_t*)(buf + 4), (buf_size - 4) >> 2);
init_get_bits(&gb, bits, (buf_size - 4)* 8);
skip_bits(&gb, buf[0]);
/* read subband indexes */
for(i = 0; i <= c->maxbands; i++){
for(ch = 0; ch < 2; ch++){
int t = 4;
if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5;
if(t == 4) bands[i].res[ch] = get_bits(&gb, 4);
else bands[i].res[ch] = bands[i-1].res[ch] + t;
}
if(bands[i].res[0] || bands[i].res[1]){
mb = i;
if(c->MSS) bands[i].msf = get_bits1(&gb);
}
}
/* get scale indexes coding method */
for(i = 0; i <= mb; i++)
for(ch = 0; ch < 2; ch++)
if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1);
/* get scale indexes */
for(i = 0; i <= mb; i++){
for(ch = 0; ch < 2; ch++){
if(bands[i].res[ch]){
bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i];
bands[i].scf_idx[ch][0] = get_scale_idx(&gb, bands[i].scf_idx[ch][2]);
switch(bands[i].scfi[ch]){
case 0:
bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]);
bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]);
break;
case 1:
bands[i].scf_idx[ch][1] = get_scale_idx(&gb, bands[i].scf_idx[ch][0]);
bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1];
break;
case 2:
bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];
bands[i].scf_idx[ch][2] = get_scale_idx(&gb, bands[i].scf_idx[ch][1]);
break;
case 3:
bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];
break;
}
c->oldDSCF[ch][i] = bands[i].scf_idx[ch][2];
}
}
}
/* get quantizers */
memset(c->Q, 0, sizeof(c->Q));
off = 0;
for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND)
for(ch = 0; ch < 2; ch++)
idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off);
ff_mpc_dequantize_and_synth(c, mb, data);
av_free(bits);
bits_used = get_bits_count(&gb);
bits_avail = (buf_size - 4) * 8;
if(!buf[1] && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))){
av_log(NULL,0, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail);
return -1;
}
if(c->frames_to_skip){
c->frames_to_skip--;
*data_size = 0;
return buf_size;
}
*data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4;
return buf_size;
}
static void mpc7_decode_flush(AVCodecContext *avctx)
{
MPCContext *c = avctx->priv_data;
memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
c->frames_to_skip = 32;
}
AVCodec mpc7_decoder = {
"mpc7",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MUSEPACK7,
sizeof(MPCContext),
mpc7_decode_init,
NULL,
NULL,
mpc7_decode_frame,
.flush = mpc7_decode_flush,
.long_name = NULL_IF_CONFIG_SMALL("Musepack SV7"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/mpc7.c | C | asf20 | 10,108 |
/*
* Motion Pixels Video Decoder
* Copyright (c) 2008 Gregory Montoir (cyx@users.sourceforge.net)
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#define MAX_HUFF_CODES 16
#include "motionpixels_tablegen.h"
typedef struct HuffCode {
int code;
uint8_t size;
uint8_t delta;
} HuffCode;
typedef struct MotionPixelsContext {
AVCodecContext *avctx;
AVFrame frame;
DSPContext dsp;
uint8_t *changes_map;
int offset_bits_len;
int codes_count, current_codes_count;
int max_codes_bits;
HuffCode codes[MAX_HUFF_CODES];
VLC vlc;
YuvPixel *vpt, *hpt;
uint8_t gradient_scale[3];
uint8_t *bswapbuf;
int bswapbuf_size;
} MotionPixelsContext;
static av_cold int mp_decode_init(AVCodecContext *avctx)
{
MotionPixelsContext *mp = avctx->priv_data;
motionpixels_tableinit();
mp->avctx = avctx;
dsputil_init(&mp->dsp, avctx);
mp->changes_map = av_mallocz(avctx->width * avctx->height);
mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1;
mp->vpt = av_mallocz(avctx->height * sizeof(YuvPixel));
mp->hpt = av_mallocz(avctx->height * avctx->width / 16 * sizeof(YuvPixel));
avctx->pix_fmt = PIX_FMT_RGB555;
return 0;
}
static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int count, int bits_len, int read_color)
{
uint16_t *pixels;
int offset, w, h, color = 0, x, y, i;
while (count--) {
offset = get_bits_long(gb, mp->offset_bits_len);
w = get_bits(gb, bits_len) + 1;
h = get_bits(gb, bits_len) + 1;
if (read_color)
color = get_bits(gb, 15);
x = offset % mp->avctx->width;
y = offset / mp->avctx->width;
if (y >= mp->avctx->height)
continue;
w = FFMIN(w, mp->avctx->width - x);
h = FFMIN(h, mp->avctx->height - y);
pixels = (uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2];
while (h--) {
mp->changes_map[offset] = w;
if (read_color)
for (i = 0; i < w; ++i)
pixels[i] = color;
offset += mp->avctx->width;
pixels += mp->frame.linesize[0] / 2;
}
}
}
static void mp_get_code(MotionPixelsContext *mp, GetBitContext *gb, int size, int code)
{
while (get_bits1(gb)) {
++size;
if (size > mp->max_codes_bits) {
av_log(mp->avctx, AV_LOG_ERROR, "invalid code size %d/%d\n", size, mp->max_codes_bits);
return;
}
code <<= 1;
mp_get_code(mp, gb, size, code + 1);
}
if (mp->current_codes_count >= MAX_HUFF_CODES) {
av_log(mp->avctx, AV_LOG_ERROR, "too many codes\n");
return;
}
mp->codes[mp->current_codes_count ].code = code;
mp->codes[mp->current_codes_count++].size = size;
}
static void mp_read_codes_table(MotionPixelsContext *mp, GetBitContext *gb)
{
if (mp->codes_count == 1) {
mp->codes[0].delta = get_bits(gb, 4);
} else {
int i;
mp->max_codes_bits = get_bits(gb, 4);
for (i = 0; i < mp->codes_count; ++i)
mp->codes[i].delta = get_bits(gb, 4);
mp->current_codes_count = 0;
mp_get_code(mp, gb, 0, 0);
}
}
static int mp_gradient(MotionPixelsContext *mp, int component, int v)
{
int delta;
delta = (v - 7) * mp->gradient_scale[component];
mp->gradient_scale[component] = (v == 0 || v == 14) ? 2 : 1;
return delta;
}
static YuvPixel mp_get_yuv_from_rgb(MotionPixelsContext *mp, int x, int y)
{
int color;
color = *(uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2];
return mp_rgb_yuv_table[color];
}
static void mp_set_rgb_from_yuv(MotionPixelsContext *mp, int x, int y, const YuvPixel *p)
{
int color;
color = mp_yuv_to_rgb(p->y, p->v, p->u, 1);
*(uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2] = color;
}
static int mp_get_vlc(MotionPixelsContext *mp, GetBitContext *gb)
{
int i;
i = (mp->codes_count == 1) ? 0 : get_vlc2(gb, mp->vlc.table, mp->max_codes_bits, 1);
return mp->codes[i].delta;
}
static void mp_decode_line(MotionPixelsContext *mp, GetBitContext *gb, int y)
{
YuvPixel p;
const int y0 = y * mp->avctx->width;
int w, i, x = 0;
p = mp->vpt[y];
if (mp->changes_map[y0 + x] == 0) {
memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
++x;
}
while (x < mp->avctx->width) {
w = mp->changes_map[y0 + x];
if (w != 0) {
if ((y & 3) == 0) {
if (mp->changes_map[y0 + x + mp->avctx->width] < w ||
mp->changes_map[y0 + x + mp->avctx->width * 2] < w ||
mp->changes_map[y0 + x + mp->avctx->width * 3] < w) {
for (i = (x + 3) & ~3; i < x + w; i += 4) {
mp->hpt[((y / 4) * mp->avctx->width + i) / 4] = mp_get_yuv_from_rgb(mp, i, y);
}
}
}
x += w;
memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
p = mp_get_yuv_from_rgb(mp, x - 1, y);
} else {
p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));
if ((x & 3) == 0) {
if ((y & 3) == 0) {
p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb));
p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb));
mp->hpt[((y / 4) * mp->avctx->width + x) / 4] = p;
} else {
p.v = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].v;
p.u = mp->hpt[((y / 4) * mp->avctx->width + x) / 4].u;
}
}
mp_set_rgb_from_yuv(mp, x, y, &p);
++x;
}
}
}
static void mp_decode_frame_helper(MotionPixelsContext *mp, GetBitContext *gb)
{
YuvPixel p;
int y, y0;
for (y = 0; y < mp->avctx->height; ++y) {
if (mp->changes_map[y * mp->avctx->width] != 0) {
memset(mp->gradient_scale, 1, sizeof(mp->gradient_scale));
p = mp_get_yuv_from_rgb(mp, 0, y);
} else {
p.y += mp_gradient(mp, 0, mp_get_vlc(mp, gb));
if ((y & 3) == 0) {
p.v += mp_gradient(mp, 1, mp_get_vlc(mp, gb));
p.u += mp_gradient(mp, 2, mp_get_vlc(mp, gb));
}
mp->vpt[y] = p;
mp_set_rgb_from_yuv(mp, 0, y, &p);
}
}
for (y0 = 0; y0 < 2; ++y0)
for (y = y0; y < mp->avctx->height; y += 2)
mp_decode_line(mp, gb, y);
}
static int mp_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MotionPixelsContext *mp = avctx->priv_data;
GetBitContext gb;
int i, count1, count2, sz;
mp->frame.reference = 1;
mp->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, &mp->frame)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
/* le32 bitstream msb first */
av_fast_malloc(&mp->bswapbuf, &mp->bswapbuf_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
if (!mp->bswapbuf)
return AVERROR(ENOMEM);
mp->dsp.bswap_buf((uint32_t *)mp->bswapbuf, (const uint32_t *)buf, buf_size / 4);
if (buf_size & 3)
memcpy(mp->bswapbuf + (buf_size & ~3), buf + (buf_size & ~3), buf_size & 3);
init_get_bits(&gb, mp->bswapbuf, buf_size * 8);
memset(mp->changes_map, 0, avctx->width * avctx->height);
for (i = !(avctx->extradata[1] & 2); i < 2; ++i) {
count1 = get_bits(&gb, 12);
count2 = get_bits(&gb, 12);
mp_read_changes_map(mp, &gb, count1, 8, i);
mp_read_changes_map(mp, &gb, count2, 4, i);
}
mp->codes_count = get_bits(&gb, 4);
if (mp->codes_count == 0)
goto end;
if (mp->changes_map[0] == 0) {
*(uint16_t *)mp->frame.data[0] = get_bits(&gb, 15);
mp->changes_map[0] = 1;
}
mp_read_codes_table(mp, &gb);
sz = get_bits(&gb, 18);
if (avctx->extradata[0] != 5)
sz += get_bits(&gb, 18);
if (sz == 0)
goto end;
init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0);
mp_decode_frame_helper(mp, &gb);
free_vlc(&mp->vlc);
end:
*data_size = sizeof(AVFrame);
*(AVFrame *)data = mp->frame;
return buf_size;
}
static av_cold int mp_decode_end(AVCodecContext *avctx)
{
MotionPixelsContext *mp = avctx->priv_data;
av_freep(&mp->changes_map);
av_freep(&mp->vpt);
av_freep(&mp->hpt);
av_freep(&mp->bswapbuf);
if (mp->frame.data[0])
avctx->release_buffer(avctx, &mp->frame);
return 0;
}
AVCodec motionpixels_decoder = {
"motionpixels",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_MOTIONPIXELS,
sizeof(MotionPixelsContext),
mp_decode_init,
NULL,
mp_decode_end,
mp_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Motion Pixels video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/motionpixels.c | C | asf20 | 10,001 |
/*
* MJPEG encoder and decoder
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
* Support for external huffman table, various fixes (AVID workaround),
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MJPEG encoder and decoder.
*/
#ifndef AVCODEC_MJPEG_H
#define AVCODEC_MJPEG_H
#include "avcodec.h"
#include "put_bits.h"
/* 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,
SOF48 = 0xf7, ///< JPEG-LS
LSE = 0xf8, ///< JPEG-LS extension parameters
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;
static inline void put_marker(PutBitContext *p, int code)
{
put_bits(p, 8, 0xff);
put_bits(p, 8, code);
}
#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;\
}
extern const uint8_t ff_mjpeg_bits_dc_luminance[];
extern const uint8_t ff_mjpeg_val_dc[];
extern const uint8_t ff_mjpeg_bits_dc_chrominance[];
extern const uint8_t ff_mjpeg_bits_ac_luminance[];
extern const uint8_t ff_mjpeg_val_ac_luminance[];
extern const uint8_t ff_mjpeg_bits_ac_chrominance[];
extern const uint8_t ff_mjpeg_val_ac_chrominance[];
void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code,
const uint8_t *bits_table,
const uint8_t *val_table);
#endif /* AVCODEC_MJPEG_H */
| 123linslouis-android-video-cutter | jni/libavcodec/mjpeg.h | C | asf20 | 4,755 |
/*
* Video Acceleration API (video decoding)
* HW decode acceleration for MPEG-2, MPEG-4, H.264 and VC-1
*
* Copyright (C) 2008-2009 Splitted-Desktop Systems
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_VAAPI_INTERNAL_H
#define AVCODEC_VAAPI_INTERNAL_H
#include <va/va.h>
#include "vaapi.h"
#include "avcodec.h"
#include "mpegvideo.h"
/**
* \addtogroup VAAPI_Decoding
*
* @{
*/
/** Extract VASurfaceID from a Picture */
static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic)
{
return (uintptr_t)pic->data[3];
}
/** Common AVHWAccel.end_frame() implementation */
int ff_vaapi_common_end_frame(MpegEncContext *s);
/** Allocate a new picture parameter buffer */
void *ff_vaapi_alloc_pic_param(struct vaapi_context *vactx, unsigned int size);
/** Allocate a new IQ matrix buffer */
void *ff_vaapi_alloc_iq_matrix(struct vaapi_context *vactx, unsigned int size);
/** Allocate a new bit-plane buffer */
uint8_t *ff_vaapi_alloc_bitplane(struct vaapi_context *vactx, uint32_t size);
/**
* Allocate a new slice descriptor for the input slice.
*
* @param vactx the VA API context
* @param buffer the slice data buffer base
* @param size the size of the slice in bytes
* @return the newly allocated slice parameter
*/
VASliceParameterBufferBase *ff_vaapi_alloc_slice(struct vaapi_context *vactx, const uint8_t *buffer, uint32_t size);
/* @} */
#endif /* AVCODEC_VAAPI_INTERNAL_H */
| 123linslouis-android-video-cutter | jni/libavcodec/vaapi_internal.h | C | asf20 | 2,144 |
/*
* SVQ1 Encoder
* Copyright (C) 2004 Mike Melanson <melanson@pcisys.net>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* svq1 code books.
*/
#ifndef AVCODEC_SVQ1ENC_CB_H
#define AVCODEC_SVQ1ENC_CB_H
#include <stdint.h>
static const int8_t svq1_inter_codebook_sum[4][16*6] = {
{
-1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1,
0, -1, -1, -1, -1, 0, -1, 0, 0, 0, -3, 1, -1, 0, 1, -1,
1, -1, 2, 2, 1, 1, 2, 0, 0, 0, -1, 1, 1, 0, 0, 0,
1, -1, 0, 1, -1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 0, 0,
-2, 0, 0, -2, 0, 0, -2, 0, -2, -1, -2, -1, 0, 0, -1, 0,
1, 0, 1, -1, 2, 2, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1,
},{
-2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1,
0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1,
2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0,
-2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3,
1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1,
1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2,
},{
0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2,
1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1,
-1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3,
4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1,
-1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2,
3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0,
},{
0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6,
-2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1,
-4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0,
-3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4,
5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0,
-3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 1,
}
};
static const int8_t svq1_intra_codebook_sum[4][16*6] = {
{
0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0,
1, 0, -1, 1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 1, 0, 0,
-1, 0, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 0, 0, -1, 1,
0, 1, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 1, 0, -2, 1,
0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0,
0, 1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, 1, -1,
},{
-1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2,
0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0,
1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1,
1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2,
-2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1,
0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0,
},{
-2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1,
3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1,
-3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2,
0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2,
2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1,
-2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1,
},{
-2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1,
-3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0,
-1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3,
1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3,
4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4,
-1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2,
}
};
#endif /* AVCODEC_SVQ1ENC_CB_H */
| 123linslouis-android-video-cutter | jni/libavcodec/svq1enc_cb.h | C | asf20 | 4,277 |
/*
* Westwood SNDx codecs
* Copyright (c) 2005 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
/**
* @file
* Westwood SNDx codecs.
*
* Reference documents about VQA format and its audio codecs
* can be found here:
* http://www.multimedia.cx
*/
static const char ws_adpcm_2bit[] = { -2, -1, 0, 1};
static const char ws_adpcm_4bit[] = {
-9, -8, -6, -5, -4, -3, -2, -1,
0, 1, 2, 3, 4, 5, 6, 8 };
#define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128;
static av_cold int ws_snd_decode_init(AVCodecContext * avctx)
{
// WSSNDContext *c = avctx->priv_data;
avctx->sample_fmt = SAMPLE_FMT_S16;
return 0;
}
static int ws_snd_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
// WSSNDContext *c = avctx->priv_data;
int in_size, out_size;
int sample = 0;
int i;
short *samples = data;
if (!buf_size)
return 0;
out_size = AV_RL16(&buf[0]);
*data_size = out_size * 2;
in_size = AV_RL16(&buf[2]);
buf += 4;
if (out_size > *data_size) {
av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
return -1;
}
if (in_size > buf_size) {
av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");
return -1;
}
if (in_size == out_size) {
for (i = 0; i < out_size; i++)
*samples++ = (*buf++ - 0x80) << 8;
return buf_size;
}
while (out_size > 0) {
int code;
uint8_t count;
code = (*buf) >> 6;
count = (*buf) & 0x3F;
buf++;
switch(code) {
case 0: /* ADPCM 2-bit */
for (count++; count > 0; count--) {
code = *buf++;
sample += ws_adpcm_2bit[code & 0x3];
CLIP8(sample);
*samples++ = sample << 8;
sample += ws_adpcm_2bit[(code >> 2) & 0x3];
CLIP8(sample);
*samples++ = sample << 8;
sample += ws_adpcm_2bit[(code >> 4) & 0x3];
CLIP8(sample);
*samples++ = sample << 8;
sample += ws_adpcm_2bit[(code >> 6) & 0x3];
CLIP8(sample);
*samples++ = sample << 8;
out_size -= 4;
}
break;
case 1: /* ADPCM 4-bit */
for (count++; count > 0; count--) {
code = *buf++;
sample += ws_adpcm_4bit[code & 0xF];
CLIP8(sample);
*samples++ = sample << 8;
sample += ws_adpcm_4bit[code >> 4];
CLIP8(sample);
*samples++ = sample << 8;
out_size -= 2;
}
break;
case 2: /* no compression */
if (count & 0x20) { /* big delta */
char t;
t = count;
t <<= 3;
sample += t >> 3;
*samples++ = sample << 8;
out_size--;
} else { /* copy */
for (count++; count > 0; count--) {
*samples++ = (*buf++ - 0x80) << 8;
out_size--;
}
sample = buf[-1] - 0x80;
}
break;
default: /* run */
for(count++; count > 0; count--) {
*samples++ = sample << 8;
out_size--;
}
}
}
return buf_size;
}
AVCodec ws_snd1_decoder = {
"ws_snd1",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_WESTWOOD_SND1,
0,
ws_snd_decode_init,
NULL,
NULL,
ws_snd_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Westwood Audio (SND1)"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/ws-snd1.c | C | asf20 | 4,591 |
/*
* LCL (LossLess Codec Library) Codec
* Copyright (c) 2002-2004 Roberto Togni
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* LCL (LossLess Codec Library) Video Codec
* Decoder for MSZH and ZLIB codecs
* Experimental encoder for ZLIB RGB24
*
* Fourcc: MSZH, ZLIB
*
* Original Win32 dll:
* Ver2.23 By Kenji Oshima 2000.09.20
* avimszh.dll, avizlib.dll
*
* A description of the decoding algorithm can be found here:
* http://www.pcisys.net/~melanson/codecs
*
* Supports: BGR24 (RGB 24bpp)
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "avcodec.h"
#include "bytestream.h"
#include "lcl.h"
#include "libavutil/lzo.h"
#if CONFIG_ZLIB_DECODER
#include <zlib.h>
#endif
/*
* Decoder context
*/
typedef struct LclDecContext {
AVFrame pic;
// Image type
int imgtype;
// Compression type
int compression;
// Flags
int flags;
// Decompressed data size
unsigned int decomp_size;
// Decompression buffer
unsigned char* decomp_buf;
#if CONFIG_ZLIB_DECODER
z_stream zstream;
#endif
} LclDecContext;
/**
* \param srcptr compressed source buffer, must be padded with at least 5 extra bytes
* \param destptr must be padded sufficiently for av_memcpy_backptr
*/
static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize)
{
unsigned char *destptr_bak = destptr;
unsigned char *destptr_end = destptr + destsize;
const unsigned char *srcptr_end = srcptr + srclen;
unsigned mask = *srcptr++;
unsigned maskbit = 0x80;
while (srcptr < srcptr_end && destptr < destptr_end) {
if (!(mask & maskbit)) {
memcpy(destptr, srcptr, 4);
destptr += 4;
srcptr += 4;
} else {
unsigned ofs = bytestream_get_le16(&srcptr);
unsigned cnt = (ofs >> 11) + 1;
ofs &= 0x7ff;
ofs = FFMIN(ofs, destptr - destptr_bak);
cnt *= 4;
cnt = FFMIN(cnt, destptr_end - destptr);
av_memcpy_backptr(destptr, ofs, cnt);
destptr += cnt;
}
maskbit >>= 1;
if (!maskbit) {
mask = *srcptr++;
while (!mask) {
if (destptr_end - destptr < 32 || srcptr_end - srcptr < 32) break;
memcpy(destptr, srcptr, 32);
destptr += 32;
srcptr += 32;
mask = *srcptr++;
}
maskbit = 0x80;
}
}
return destptr - destptr_bak;
}
/**
* \brief decompress a zlib-compressed data block into decomp_buf
* \param src compressed input buffer
* \param src_len data length in input buffer
* \param offset offset in decomp_buf
* \param expected expected decompressed length
*/
#if CONFIG_ZLIB_DECODER
static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected)
{
LclDecContext *c = avctx->priv_data;
int zret = inflateReset(&c->zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
return -1;
}
c->zstream.next_in = src;
c->zstream.avail_in = src_len;
c->zstream.next_out = c->decomp_buf + offset;
c->zstream.avail_out = c->decomp_size - offset;
zret = inflate(&c->zstream, Z_FINISH);
if (zret != Z_OK && zret != Z_STREAM_END) {
av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
return -1;
}
if (expected != (unsigned int)c->zstream.total_out) {
av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n",
expected, c->zstream.total_out);
return -1;
}
return c->zstream.total_out;
}
#endif
/*
*
* Decode a frame
*
*/
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LclDecContext * const c = avctx->priv_data;
unsigned char *encoded = (unsigned char *)buf;
unsigned int pixel_ptr;
int row, col;
unsigned char *outptr;
uint8_t *y_out, *u_out, *v_out;
unsigned int width = avctx->width; // Real image width
unsigned int height = avctx->height; // Real image height
unsigned int mszh_dlen;
unsigned char yq, y1q, uq, vq;
int uqvq;
unsigned int mthread_inlen, mthread_outlen;
unsigned int len = buf_size;
if(c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
c->pic.reference = 0;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
if(avctx->get_buffer(avctx, &c->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
outptr = c->pic.data[0]; // Output image pointer
/* Decompress frame */
switch (avctx->codec_id) {
case CODEC_ID_MSZH:
switch (c->compression) {
case COMP_MSZH:
if (c->flags & FLAG_MULTITHREAD) {
mthread_inlen = AV_RL32(encoded);
mthread_inlen = FFMIN(mthread_inlen, len - 8);
mthread_outlen = AV_RL32(encoded+4);
mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size);
if (mthread_outlen != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n",
mthread_outlen, mszh_dlen);
return -1;
}
mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen);
if (mthread_outlen != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n",
mthread_outlen, mszh_dlen);
return -1;
}
encoded = c->decomp_buf;
len = c->decomp_size;
} else {
mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size);
if (c->decomp_size != mszh_dlen) {
av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n",
c->decomp_size, mszh_dlen);
return -1;
}
encoded = c->decomp_buf;
len = mszh_dlen;
}
break;
case COMP_MSZH_NOCOMP:
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
return -1;
}
break;
#if CONFIG_ZLIB_DECODER
case CODEC_ID_ZLIB:
/* Using the original dll with normal compression (-1) and RGB format
* gives a file with ZLIB fourcc, but frame is really uncompressed.
* To be sure that's true check also frame size */
if (c->compression == COMP_ZLIB_NORMAL && c->imgtype == IMGTYPE_RGB24 &&
len == width * height * 3)
break;
if (c->flags & FLAG_MULTITHREAD) {
int ret;
mthread_inlen = AV_RL32(encoded);
mthread_inlen = FFMIN(mthread_inlen, len - 8);
mthread_outlen = AV_RL32(encoded+4);
mthread_outlen = FFMIN(mthread_outlen, c->decomp_size);
ret = zlib_decomp(avctx, encoded + 8, mthread_inlen, 0, mthread_outlen);
if (ret < 0) return ret;
ret = zlib_decomp(avctx, encoded + 8 + mthread_inlen, len - 8 - mthread_inlen,
mthread_outlen, mthread_outlen);
if (ret < 0) return ret;
} else {
int ret = zlib_decomp(avctx, encoded, len, 0, c->decomp_size);
if (ret < 0) return ret;
}
encoded = c->decomp_buf;
len = c->decomp_size;
break;
#endif
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n");
return -1;
}
/* Apply PNG filter */
if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER)) {
switch (c->imgtype) {
case IMGTYPE_YUV111:
case IMGTYPE_RGB24:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 3;
yq = encoded[pixel_ptr++];
uqvq = AV_RL16(encoded+pixel_ptr);
pixel_ptr += 2;
for (col = 1; col < width; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
uqvq -= AV_RL16(encoded+pixel_ptr+1);
AV_WL16(encoded+pixel_ptr+1, uqvq);
pixel_ptr += 3;
}
}
break;
case IMGTYPE_YUV422:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 2;
yq = uq = vq =0;
for (col = 0; col < width/4; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5];
encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6];
encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7];
pixel_ptr += 8;
}
}
break;
case IMGTYPE_YUV411:
for (row = 0; row < height; row++) {
pixel_ptr = row * width / 2 * 3;
yq = uq = vq =0;
for (col = 0; col < width/4; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
pixel_ptr += 6;
}
}
break;
case IMGTYPE_YUV211:
for (row = 0; row < height; row++) {
pixel_ptr = row * width * 2;
yq = uq = vq =0;
for (col = 0; col < width/2; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3];
pixel_ptr += 4;
}
}
break;
case IMGTYPE_YUV420:
for (row = 0; row < height/2; row++) {
pixel_ptr = row * width * 3;
yq = y1q = uq = vq =0;
for (col = 0; col < width/2; col++) {
encoded[pixel_ptr] = yq -= encoded[pixel_ptr];
encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1];
encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2];
encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3];
encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4];
encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5];
pixel_ptr += 6;
}
}
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n");
return -1;
}
}
/* Convert colorspace */
y_out = c->pic.data[0] + (height - 1) * c->pic.linesize[0];
u_out = c->pic.data[1] + (height - 1) * c->pic.linesize[1];
v_out = c->pic.data[2] + (height - 1) * c->pic.linesize[2];
switch (c->imgtype) {
case IMGTYPE_YUV111:
for (row = 0; row < height; row++) {
for (col = 0; col < width; col++) {
y_out[col] = *encoded++;
u_out[col] = *encoded++ + 128;
v_out[col] = *encoded++ + 128;
}
y_out -= c->pic.linesize[0];
u_out -= c->pic.linesize[1];
v_out -= c->pic.linesize[2];
}
break;
case IMGTYPE_YUV422:
for (row = 0; row < height; row++) {
for (col = 0; col < width - 3; col += 4) {
memcpy(y_out + col, encoded, 4);
encoded += 4;
u_out[ col >> 1 ] = *encoded++ + 128;
u_out[(col >> 1) + 1] = *encoded++ + 128;
v_out[ col >> 1 ] = *encoded++ + 128;
v_out[(col >> 1) + 1] = *encoded++ + 128;
}
y_out -= c->pic.linesize[0];
u_out -= c->pic.linesize[1];
v_out -= c->pic.linesize[2];
}
break;
case IMGTYPE_RGB24:
for (row = height - 1; row >= 0; row--) {
pixel_ptr = row * c->pic.linesize[0];
memcpy(outptr + pixel_ptr, encoded, 3 * width);
encoded += 3 * width;
}
break;
case IMGTYPE_YUV411:
for (row = 0; row < height; row++) {
for (col = 0; col < width - 3; col += 4) {
memcpy(y_out + col, encoded, 4);
encoded += 4;
u_out[col >> 2] = *encoded++ + 128;
v_out[col >> 2] = *encoded++ + 128;
}
y_out -= c->pic.linesize[0];
u_out -= c->pic.linesize[1];
v_out -= c->pic.linesize[2];
}
break;
case IMGTYPE_YUV211:
for (row = 0; row < height; row++) {
for (col = 0; col < width - 1; col += 2) {
memcpy(y_out + col, encoded, 2);
encoded += 2;
u_out[col >> 1] = *encoded++ + 128;
v_out[col >> 1] = *encoded++ + 128;
}
y_out -= c->pic.linesize[0];
u_out -= c->pic.linesize[1];
v_out -= c->pic.linesize[2];
}
break;
case IMGTYPE_YUV420:
u_out = c->pic.data[1] + ((height >> 1) - 1) * c->pic.linesize[1];
v_out = c->pic.data[2] + ((height >> 1) - 1) * c->pic.linesize[2];
for (row = 0; row < height - 1; row += 2) {
for (col = 0; col < width - 1; col += 2) {
memcpy(y_out + col, encoded, 2);
encoded += 2;
memcpy(y_out + col - c->pic.linesize[0], encoded, 2);
encoded += 2;
u_out[col >> 1] = *encoded++ + 128;
v_out[col >> 1] = *encoded++ + 128;
}
y_out -= c->pic.linesize[0] << 1;
u_out -= c->pic.linesize[1];
v_out -= c->pic.linesize[2];
}
break;
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n");
return -1;
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
/*
*
* Init lcl decoder
*
*/
static av_cold int decode_init(AVCodecContext *avctx)
{
LclDecContext * const c = avctx->priv_data;
unsigned int basesize = avctx->width * avctx->height;
unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING;
unsigned int max_decomp_size;
if (avctx->extradata_size < 8) {
av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n");
return 1;
}
/* Check codec type */
if ((avctx->codec_id == CODEC_ID_MSZH && avctx->extradata[7] != CODEC_MSZH) ||
(avctx->codec_id == CODEC_ID_ZLIB && avctx->extradata[7] != CODEC_ZLIB)) {
av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n");
}
/* Detect image type */
switch (c->imgtype = avctx->extradata[4]) {
case IMGTYPE_YUV111:
c->decomp_size = basesize * 3;
max_decomp_size = max_basesize * 3;
avctx->pix_fmt = PIX_FMT_YUV444P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 1:1:1.\n");
break;
case IMGTYPE_YUV422:
c->decomp_size = basesize * 2;
max_decomp_size = max_basesize * 2;
avctx->pix_fmt = PIX_FMT_YUV422P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n");
break;
case IMGTYPE_RGB24:
c->decomp_size = basesize * 3;
max_decomp_size = max_basesize * 3;
avctx->pix_fmt = PIX_FMT_BGR24;
av_log(avctx, AV_LOG_DEBUG, "Image type is RGB 24.\n");
break;
case IMGTYPE_YUV411:
c->decomp_size = basesize / 2 * 3;
max_decomp_size = max_basesize / 2 * 3;
avctx->pix_fmt = PIX_FMT_YUV411P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:1:1.\n");
break;
case IMGTYPE_YUV211:
c->decomp_size = basesize * 2;
max_decomp_size = max_basesize * 2;
avctx->pix_fmt = PIX_FMT_YUV422P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 2:1:1.\n");
break;
case IMGTYPE_YUV420:
c->decomp_size = basesize / 2 * 3;
max_decomp_size = max_basesize / 2 * 3;
avctx->pix_fmt = PIX_FMT_YUV420P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:0.\n");
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype);
return 1;
}
/* Detect compression method */
c->compression = (int8_t)avctx->extradata[5];
switch (avctx->codec_id) {
case CODEC_ID_MSZH:
switch (c->compression) {
case COMP_MSZH:
av_log(avctx, AV_LOG_DEBUG, "Compression enabled.\n");
break;
case COMP_MSZH_NOCOMP:
c->decomp_size = 0;
av_log(avctx, AV_LOG_DEBUG, "No compression.\n");
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression);
return 1;
}
break;
#if CONFIG_ZLIB_DECODER
case CODEC_ID_ZLIB:
switch (c->compression) {
case COMP_ZLIB_HISPEED:
av_log(avctx, AV_LOG_DEBUG, "High speed compression.\n");
break;
case COMP_ZLIB_HICOMP:
av_log(avctx, AV_LOG_DEBUG, "High compression.\n");
break;
case COMP_ZLIB_NORMAL:
av_log(avctx, AV_LOG_DEBUG, "Normal compression.\n");
break;
default:
if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) {
av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression);
return 1;
}
av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression);
}
break;
#endif
default:
av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n");
return 1;
}
/* Allocate decompression buffer */
if (c->decomp_size) {
if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
return 1;
}
}
/* Detect flags */
c->flags = avctx->extradata[6];
if (c->flags & FLAG_MULTITHREAD)
av_log(avctx, AV_LOG_DEBUG, "Multithread encoder flag set.\n");
if (c->flags & FLAG_NULLFRAME)
av_log(avctx, AV_LOG_DEBUG, "Nullframe insertion flag set.\n");
if (avctx->codec_id == CODEC_ID_ZLIB && (c->flags & FLAG_PNGFILTER))
av_log(avctx, AV_LOG_DEBUG, "PNG filter flag set.\n");
if (c->flags & FLAGMASK_UNUSED)
av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags);
/* If needed init zlib */
#if CONFIG_ZLIB_DECODER
if (avctx->codec_id == CODEC_ID_ZLIB) {
int zret;
c->zstream.zalloc = Z_NULL;
c->zstream.zfree = Z_NULL;
c->zstream.opaque = Z_NULL;
zret = inflateInit(&c->zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
av_freep(&c->decomp_buf);
return 1;
}
}
#endif
return 0;
}
/*
*
* Uninit lcl decoder
*
*/
static av_cold int decode_end(AVCodecContext *avctx)
{
LclDecContext * const c = avctx->priv_data;
av_freep(&c->decomp_buf);
if (c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
#if CONFIG_ZLIB_DECODER
if (avctx->codec_id == CODEC_ID_ZLIB)
inflateEnd(&c->zstream);
#endif
return 0;
}
#if CONFIG_MSZH_DECODER
AVCodec mszh_decoder = {
"mszh",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_MSZH,
sizeof(LclDecContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"),
};
#endif
#if CONFIG_ZLIB_DECODER
AVCodec zlib_decoder = {
"zlib",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_ZLIB,
sizeof(LclDecContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"),
};
#endif
| 123linslouis-android-video-cutter | jni/libavcodec/lcldec.c | C | asf20 | 22,124 |
/*
* QCELP decoder
* Copyright (c) 2007 Reynaldo H. Verdejo Pinochet
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* QCELP decoder
* @author Reynaldo H. Verdejo Pinochet
* @remark FFmpeg merging spearheaded by Kenan Gillet
* @remark Development mentored by Benjamin Larson
*/
#include <stddef.h>
#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "qcelpdata.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "lsp.h"
#undef NDEBUG
#include <assert.h>
typedef enum
{
I_F_Q = -1, /*!< insufficient frame quality */
SILENCE,
RATE_OCTAVE,
RATE_QUARTER,
RATE_HALF,
RATE_FULL
} qcelp_packet_rate;
typedef struct
{
GetBitContext gb;
qcelp_packet_rate bitrate;
QCELPFrame frame; /*!< unpacked data frame */
uint8_t erasure_count;
uint8_t octave_count; /*!< count the consecutive RATE_OCTAVE frames */
float prev_lspf[10];
float predictor_lspf[10];/*!< LSP predictor for RATE_OCTAVE and I_F_Q */
float pitch_synthesis_filter_mem[303];
float pitch_pre_filter_mem[303];
float rnd_fir_filter_mem[180];
float formant_mem[170];
float last_codebook_gain;
int prev_g1[2];
int prev_bitrate;
float pitch_gain[4];
uint8_t pitch_lag[4];
uint16_t first16bits;
uint8_t warned_buf_mismatch_bitrate;
/* postfilter */
float postfilter_synth_mem[10];
float postfilter_agc_mem;
float postfilter_tilt_mem;
} QCELPContext;
/**
* Initialize the speech codec according to the specification.
*
* TIA/EIA/IS-733 2.4.9
*/
static av_cold int qcelp_decode_init(AVCodecContext *avctx)
{
QCELPContext *q = avctx->priv_data;
int i;
avctx->sample_fmt = SAMPLE_FMT_FLT;
for(i=0; i<10; i++)
q->prev_lspf[i] = (i+1)/11.;
return 0;
}
/**
* Decodes the 10 quantized LSP frequencies from the LSPV/LSP
* transmission codes of any bitrate and checks for badly received packets.
*
* @param q the context
* @param lspf line spectral pair frequencies
*
* @return 0 on success, -1 if the packet is badly received
*
* TIA/EIA/IS-733 2.4.3.2.6.2-2, 2.4.8.7.3
*/
static int decode_lspf(QCELPContext *q, float *lspf)
{
int i;
float tmp_lspf, smooth, erasure_coeff;
const float *predictors;
if(q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q)
{
predictors = (q->prev_bitrate != RATE_OCTAVE &&
q->prev_bitrate != I_F_Q ?
q->prev_lspf : q->predictor_lspf);
if(q->bitrate == RATE_OCTAVE)
{
q->octave_count++;
for(i=0; i<10; i++)
{
q->predictor_lspf[i] =
lspf[i] = (q->frame.lspv[i] ? QCELP_LSP_SPREAD_FACTOR
: -QCELP_LSP_SPREAD_FACTOR)
+ predictors[i] * QCELP_LSP_OCTAVE_PREDICTOR
+ (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR)/11);
}
smooth = (q->octave_count < 10 ? .875 : 0.1);
}else
{
erasure_coeff = QCELP_LSP_OCTAVE_PREDICTOR;
assert(q->bitrate == I_F_Q);
if(q->erasure_count > 1)
erasure_coeff *= (q->erasure_count < 4 ? 0.9 : 0.7);
for(i=0; i<10; i++)
{
q->predictor_lspf[i] =
lspf[i] = (i + 1) * ( 1 - erasure_coeff)/11
+ erasure_coeff * predictors[i];
}
smooth = 0.125;
}
// Check the stability of the LSP frequencies.
lspf[0] = FFMAX(lspf[0], QCELP_LSP_SPREAD_FACTOR);
for(i=1; i<10; i++)
lspf[i] = FFMAX(lspf[i], (lspf[i-1] + QCELP_LSP_SPREAD_FACTOR));
lspf[9] = FFMIN(lspf[9], (1.0 - QCELP_LSP_SPREAD_FACTOR));
for(i=9; i>0; i--)
lspf[i-1] = FFMIN(lspf[i-1], (lspf[i] - QCELP_LSP_SPREAD_FACTOR));
// Low-pass filter the LSP frequencies.
ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10);
}else
{
q->octave_count = 0;
tmp_lspf = 0.;
for(i=0; i<5 ; i++)
{
lspf[2*i+0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001;
lspf[2*i+1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001;
}
// Check for badly received packets.
if(q->bitrate == RATE_QUARTER)
{
if(lspf[9] <= .70 || lspf[9] >= .97)
return -1;
for(i=3; i<10; i++)
if(fabs(lspf[i] - lspf[i-2]) < .08)
return -1;
}else
{
if(lspf[9] <= .66 || lspf[9] >= .985)
return -1;
for(i=4; i<10; i++)
if (fabs(lspf[i] - lspf[i-4]) < .0931)
return -1;
}
}
return 0;
}
/**
* Converts codebook transmission codes to GAIN and INDEX.
*
* @param q the context
* @param gain array holding the decoded gain
*
* TIA/EIA/IS-733 2.4.6.2
*/
static void decode_gain_and_index(QCELPContext *q,
float *gain) {
int i, subframes_count, g1[16];
float slope;
if(q->bitrate >= RATE_QUARTER)
{
switch(q->bitrate)
{
case RATE_FULL: subframes_count = 16; break;
case RATE_HALF: subframes_count = 4; break;
default: subframes_count = 5;
}
for(i=0; i<subframes_count; i++)
{
g1[i] = 4 * q->frame.cbgain[i];
if(q->bitrate == RATE_FULL && !((i+1) & 3))
{
g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32);
}
gain[i] = qcelp_g12ga[g1[i]];
if(q->frame.cbsign[i])
{
gain[i] = -gain[i];
q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127;
}
}
q->prev_g1[0] = g1[i-2];
q->prev_g1[1] = g1[i-1];
q->last_codebook_gain = qcelp_g12ga[g1[i-1]];
if(q->bitrate == RATE_QUARTER)
{
// Provide smoothing of the unvoiced excitation energy.
gain[7] = gain[4];
gain[6] = 0.4*gain[3] + 0.6*gain[4];
gain[5] = gain[3];
gain[4] = 0.8*gain[2] + 0.2*gain[3];
gain[3] = 0.2*gain[1] + 0.8*gain[2];
gain[2] = gain[1];
gain[1] = 0.6*gain[0] + 0.4*gain[1];
}
}else if (q->bitrate != SILENCE)
{
if(q->bitrate == RATE_OCTAVE)
{
g1[0] = 2 * q->frame.cbgain[0]
+ av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54);
subframes_count = 8;
}else
{
assert(q->bitrate == I_F_Q);
g1[0] = q->prev_g1[1];
switch(q->erasure_count)
{
case 1 : break;
case 2 : g1[0] -= 1; break;
case 3 : g1[0] -= 2; break;
default: g1[0] -= 6;
}
if(g1[0] < 0)
g1[0] = 0;
subframes_count = 4;
}
// This interpolation is done to produce smoother background noise.
slope = 0.5*(qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count;
for(i=1; i<=subframes_count; i++)
gain[i-1] = q->last_codebook_gain + slope * i;
q->last_codebook_gain = gain[i-2];
q->prev_g1[0] = q->prev_g1[1];
q->prev_g1[1] = g1[0];
}
}
/**
* If the received packet is Rate 1/4 a further sanity check is made of the
* codebook gain.
*
* @param cbgain the unpacked cbgain array
* @return -1 if the sanity check fails, 0 otherwise
*
* TIA/EIA/IS-733 2.4.8.7.3
*/
static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain)
{
int i, diff, prev_diff=0;
for(i=1; i<5; i++)
{
diff = cbgain[i] - cbgain[i-1];
if(FFABS(diff) > 10)
return -1;
else if(FFABS(diff - prev_diff) > 12)
return -1;
prev_diff = diff;
}
return 0;
}
/**
* Computes the scaled codebook vector Cdn From INDEX and GAIN
* for all rates.
*
* The specification lacks some information here.
*
* TIA/EIA/IS-733 has an omission on the codebook index determination
* formula for RATE_FULL and RATE_HALF frames at section 2.4.8.1.1. It says
* you have to subtract the decoded index parameter from the given scaled
* codebook vector index 'n' to get the desired circular codebook index, but
* it does not mention that you have to clamp 'n' to [0-9] in order to get
* RI-compliant results.
*
* The reason for this mistake seems to be the fact they forgot to mention you
* have to do these calculations per codebook subframe and adjust given
* equation values accordingly.
*
* @param q the context
* @param gain array holding the 4 pitch subframe gain values
* @param cdn_vector array for the generated scaled codebook vector
*/
static void compute_svector(QCELPContext *q, const float *gain,
float *cdn_vector)
{
int i, j, k;
uint16_t cbseed, cindex;
float *rnd, tmp_gain, fir_filter_value;
switch(q->bitrate)
{
case RATE_FULL:
for(i=0; i<16; i++)
{
tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
cindex = -q->frame.cindex[i];
for(j=0; j<10; j++)
*cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cindex++ & 127];
}
break;
case RATE_HALF:
for(i=0; i<4; i++)
{
tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO;
cindex = -q->frame.cindex[i];
for (j = 0; j < 40; j++)
*cdn_vector++ = tmp_gain * qcelp_rate_half_codebook[cindex++ & 127];
}
break;
case RATE_QUARTER:
cbseed = (0x0003 & q->frame.lspv[4])<<14 |
(0x003F & q->frame.lspv[3])<< 8 |
(0x0060 & q->frame.lspv[2])<< 1 |
(0x0007 & q->frame.lspv[1])<< 3 |
(0x0038 & q->frame.lspv[0])>> 3 ;
rnd = q->rnd_fir_filter_mem + 20;
for(i=0; i<8; i++)
{
tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
for(k=0; k<20; k++)
{
cbseed = 521 * cbseed + 259;
*rnd = (int16_t)cbseed;
// FIR filter
fir_filter_value = 0.0;
for(j=0; j<10; j++)
fir_filter_value += qcelp_rnd_fir_coefs[j ]
* (rnd[-j ] + rnd[-20+j]);
fir_filter_value += qcelp_rnd_fir_coefs[10] * rnd[-10];
*cdn_vector++ = tmp_gain * fir_filter_value;
rnd++;
}
}
memcpy(q->rnd_fir_filter_mem, q->rnd_fir_filter_mem + 160, 20 * sizeof(float));
break;
case RATE_OCTAVE:
cbseed = q->first16bits;
for(i=0; i<8; i++)
{
tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0);
for(j=0; j<20; j++)
{
cbseed = 521 * cbseed + 259;
*cdn_vector++ = tmp_gain * (int16_t)cbseed;
}
}
break;
case I_F_Q:
cbseed = -44; // random codebook index
for(i=0; i<4; i++)
{
tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO;
for(j=0; j<40; j++)
*cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127];
}
break;
case SILENCE:
memset(cdn_vector, 0, 160 * sizeof(float));
break;
}
}
/**
* Apply generic gain control.
*
* @param v_out output vector
* @param v_in gain-controlled vector
* @param v_ref vector to control gain of
*
* TIA/EIA/IS-733 2.4.8.3, 2.4.8.6
*/
static void apply_gain_ctrl(float *v_out, const float *v_ref,
const float *v_in)
{
int i;
for (i = 0; i < 160; i += 40)
ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i,
ff_dot_productf(v_ref + i,
v_ref + i, 40),
40);
}
/**
* Apply filter in pitch-subframe steps.
*
* @param memory buffer for the previous state of the filter
* - must be able to contain 303 elements
* - the 143 first elements are from the previous state
* - the next 160 are for output
* @param v_in input filter vector
* @param gain per-subframe gain array, each element is between 0.0 and 2.0
* @param lag per-subframe lag array, each element is
* - between 16 and 143 if its corresponding pfrac is 0,
* - between 16 and 139 otherwise
* @param pfrac per-subframe boolean array, 1 if the lag is fractional, 0
* otherwise
*
* @return filter output vector
*/
static const float *do_pitchfilter(float memory[303], const float v_in[160],
const float gain[4], const uint8_t *lag,
const uint8_t pfrac[4])
{
int i, j;
float *v_lag, *v_out;
const float *v_len;
v_out = memory + 143; // Output vector starts at memory[143].
for(i=0; i<4; i++)
{
if(gain[i])
{
v_lag = memory + 143 + 40 * i - lag[i];
for(v_len=v_in+40; v_in<v_len; v_in++)
{
if(pfrac[i]) // If it is a fractional lag...
{
for(j=0, *v_out=0.; j<4; j++)
*v_out += qcelp_hammsinc_table[j] * (v_lag[j-4] + v_lag[3-j]);
}else
*v_out = *v_lag;
*v_out = *v_in + gain[i] * *v_out;
v_lag++;
v_out++;
}
}else
{
memcpy(v_out, v_in, 40 * sizeof(float));
v_in += 40;
v_out += 40;
}
}
memmove(memory, memory + 160, 143 * sizeof(float));
return memory + 143;
}
/**
* Apply pitch synthesis filter and pitch prefilter to the scaled codebook vector.
* TIA/EIA/IS-733 2.4.5.2, 2.4.8.7.2
*
* @param q the context
* @param cdn_vector the scaled codebook vector
*/
static void apply_pitch_filters(QCELPContext *q, float *cdn_vector)
{
int i;
const float *v_synthesis_filtered, *v_pre_filtered;
if(q->bitrate >= RATE_HALF ||
q->bitrate == SILENCE ||
(q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF)))
{
if(q->bitrate >= RATE_HALF)
{
// Compute gain & lag for the whole frame.
for(i=0; i<4; i++)
{
q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0;
q->pitch_lag[i] = q->frame.plag[i] + 16;
}
}else
{
float max_pitch_gain;
if (q->bitrate == I_F_Q)
{
if (q->erasure_count < 3)
max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1);
else
max_pitch_gain = 0.0;
}else
{
assert(q->bitrate == SILENCE);
max_pitch_gain = 1.0;
}
for(i=0; i<4; i++)
q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain);
memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac));
}
// pitch synthesis filter
v_synthesis_filtered = do_pitchfilter(q->pitch_synthesis_filter_mem,
cdn_vector, q->pitch_gain,
q->pitch_lag, q->frame.pfrac);
// pitch prefilter update
for(i=0; i<4; i++)
q->pitch_gain[i] = 0.5 * FFMIN(q->pitch_gain[i], 1.0);
v_pre_filtered = do_pitchfilter(q->pitch_pre_filter_mem,
v_synthesis_filtered,
q->pitch_gain, q->pitch_lag,
q->frame.pfrac);
apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered);
}else
{
memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17,
143 * sizeof(float));
memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float));
memset(q->pitch_gain, 0, sizeof(q->pitch_gain));
memset(q->pitch_lag, 0, sizeof(q->pitch_lag));
}
}
/**
* Reconstructs LPC coefficients from the line spectral pair frequencies
* and performs bandwidth expansion.
*
* @param lspf line spectral pair frequencies
* @param lpc linear predictive coding coefficients
*
* @note: bandwidth_expansion_coeff could be precalculated into a table
* but it seems to be slower on x86
*
* TIA/EIA/IS-733 2.4.3.3.5
*/
static void lspf2lpc(const float *lspf, float *lpc)
{
double lsp[10];
double bandwidth_expansion_coeff = QCELP_BANDWIDTH_EXPANSION_COEFF;
int i;
for (i=0; i<10; i++)
lsp[i] = cos(M_PI * lspf[i]);
ff_acelp_lspd2lpc(lsp, lpc, 5);
for (i=0; i<10; i++)
{
lpc[i] *= bandwidth_expansion_coeff;
bandwidth_expansion_coeff *= QCELP_BANDWIDTH_EXPANSION_COEFF;
}
}
/**
* Interpolates LSP frequencies and computes LPC coefficients
* for a given bitrate & pitch subframe.
*
* TIA/EIA/IS-733 2.4.3.3.4, 2.4.8.7.2
*
* @param q the context
* @param curr_lspf LSP frequencies vector of the current frame
* @param lpc float vector for the resulting LPC
* @param subframe_num frame number in decoded stream
*/
static void interpolate_lpc(QCELPContext *q, const float *curr_lspf,
float *lpc, const int subframe_num)
{
float interpolated_lspf[10];
float weight;
if(q->bitrate >= RATE_QUARTER)
weight = 0.25 * (subframe_num + 1);
else if(q->bitrate == RATE_OCTAVE && !subframe_num)
weight = 0.625;
else
weight = 1.0;
if(weight != 1.0)
{
ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
weight, 1.0 - weight, 10);
lspf2lpc(interpolated_lspf, lpc);
}else if(q->bitrate >= RATE_QUARTER ||
(q->bitrate == I_F_Q && !subframe_num))
lspf2lpc(curr_lspf, lpc);
else if(q->bitrate == SILENCE && !subframe_num)
lspf2lpc(q->prev_lspf, lpc);
}
static qcelp_packet_rate buf_size2bitrate(const int buf_size)
{
switch(buf_size)
{
case 35: return RATE_FULL;
case 17: return RATE_HALF;
case 8: return RATE_QUARTER;
case 4: return RATE_OCTAVE;
case 1: return SILENCE;
}
return I_F_Q;
}
/**
* Determine the bitrate from the frame size and/or the first byte of the frame.
*
* @param avctx the AV codec context
* @param buf_size length of the buffer
* @param buf the bufffer
*
* @return the bitrate on success,
* I_F_Q if the bitrate cannot be satisfactorily determined
*
* TIA/EIA/IS-733 2.4.8.7.1
*/
static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_size,
const uint8_t **buf)
{
qcelp_packet_rate bitrate;
if((bitrate = buf_size2bitrate(buf_size)) >= 0)
{
if(bitrate > **buf)
{
QCELPContext *q = avctx->priv_data;
if (!q->warned_buf_mismatch_bitrate)
{
av_log(avctx, AV_LOG_WARNING,
"Claimed bitrate and buffer size mismatch.\n");
q->warned_buf_mismatch_bitrate = 1;
}
bitrate = **buf;
}else if(bitrate < **buf)
{
av_log(avctx, AV_LOG_ERROR,
"Buffer is too small for the claimed bitrate.\n");
return I_F_Q;
}
(*buf)++;
}else if((bitrate = buf_size2bitrate(buf_size + 1)) >= 0)
{
av_log(avctx, AV_LOG_WARNING,
"Bitrate byte is missing, guessing the bitrate from packet size.\n");
}else
return I_F_Q;
if(bitrate == SILENCE)
{
//FIXME: Remove experimental warning when tested with samples.
av_log_ask_for_sample(avctx, "'Blank frame handling is experimental.");
}
return bitrate;
}
static void warn_insufficient_frame_quality(AVCodecContext *avctx,
const char *message)
{
av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number,
message);
}
static void postfilter(QCELPContext *q, float *samples, float *lpc)
{
static const float pow_0_775[10] = {
0.775000, 0.600625, 0.465484, 0.360750, 0.279582,
0.216676, 0.167924, 0.130141, 0.100859, 0.078166
}, pow_0_625[10] = {
0.625000, 0.390625, 0.244141, 0.152588, 0.095367,
0.059605, 0.037253, 0.023283, 0.014552, 0.009095
};
float lpc_s[10], lpc_p[10], pole_out[170], zero_out[160];
int n;
for (n = 0; n < 10; n++) {
lpc_s[n] = lpc[n] * pow_0_625[n];
lpc_p[n] = lpc[n] * pow_0_775[n];
}
ff_celp_lp_zero_synthesis_filterf(zero_out, lpc_s,
q->formant_mem + 10, 160, 10);
memcpy(pole_out, q->postfilter_synth_mem, sizeof(float) * 10);
ff_celp_lp_synthesis_filterf(pole_out + 10, lpc_p, zero_out, 160, 10);
memcpy(q->postfilter_synth_mem, pole_out + 160, sizeof(float) * 10);
ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160);
ff_adaptive_gain_control(samples, pole_out + 10,
ff_dot_productf(q->formant_mem + 10, q->formant_mem + 10, 160),
160, 0.9375, &q->postfilter_agc_mem);
}
static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
QCELPContext *q = avctx->priv_data;
float *outbuffer = data;
int i;
float quantized_lspf[10], lpc[10];
float gain[16];
float *formant_mem;
if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q)
{
warn_insufficient_frame_quality(avctx, "bitrate cannot be determined.");
goto erasure;
}
if(q->bitrate == RATE_OCTAVE &&
(q->first16bits = AV_RB16(buf)) == 0xFFFF)
{
warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on.");
goto erasure;
}
if(q->bitrate > SILENCE)
{
const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate];
const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate]
+ qcelp_unpacking_bitmaps_lengths[q->bitrate];
uint8_t *unpacked_data = (uint8_t *)&q->frame;
init_get_bits(&q->gb, buf, 8*buf_size);
memset(&q->frame, 0, sizeof(QCELPFrame));
for(; bitmaps < bitmaps_end; bitmaps++)
unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos;
// Check for erasures/blanks on rates 1, 1/4 and 1/8.
if(q->frame.reserved)
{
warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area.");
goto erasure;
}
if(q->bitrate == RATE_QUARTER &&
codebook_sanity_check_for_rate_quarter(q->frame.cbgain))
{
warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed.");
goto erasure;
}
if(q->bitrate >= RATE_HALF)
{
for(i=0; i<4; i++)
{
if(q->frame.pfrac[i] && q->frame.plag[i] >= 124)
{
warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter.");
goto erasure;
}
}
}
}
decode_gain_and_index(q, gain);
compute_svector(q, gain, outbuffer);
if(decode_lspf(q, quantized_lspf) < 0)
{
warn_insufficient_frame_quality(avctx, "Badly received packets in frame.");
goto erasure;
}
apply_pitch_filters(q, outbuffer);
if(q->bitrate == I_F_Q)
{
erasure:
q->bitrate = I_F_Q;
q->erasure_count++;
decode_gain_and_index(q, gain);
compute_svector(q, gain, outbuffer);
decode_lspf(q, quantized_lspf);
apply_pitch_filters(q, outbuffer);
}else
q->erasure_count = 0;
formant_mem = q->formant_mem + 10;
for(i=0; i<4; i++)
{
interpolate_lpc(q, quantized_lspf, lpc, i);
ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40,
10);
formant_mem += 40;
}
// postfilter, as per TIA/EIA/IS-733 2.4.8.6
postfilter(q, outbuffer, lpc);
memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float));
memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf));
q->prev_bitrate = q->bitrate;
*data_size = 160 * sizeof(*outbuffer);
return *data_size;
}
AVCodec qcelp_decoder =
{
.name = "qcelp",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_QCELP,
.init = qcelp_decode_init,
.decode = qcelp_decode_frame,
.priv_data_size = sizeof(QCELPContext),
.long_name = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/qcelpdec.c | C | asf20 | 26,568 |
/**
* @file
* VP5 compatible video decoder
*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#include <string.h>
#include "avcodec.h"
#include "dsputil.h"
#include "get_bits.h"
#include "vp56.h"
#include "vp56data.h"
#include "vp5data.h"
static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size,
int *golden_frame)
{
VP56RangeCoder *c = &s->c;
int rows, cols;
vp56_init_range_decoder(&s->c, buf, buf_size);
s->framep[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
vp56_rac_get(c);
vp56_init_dequant(s, vp56_rac_gets(c, 6));
if (s->framep[VP56_FRAME_CURRENT]->key_frame)
{
vp56_rac_gets(c, 8);
if(vp56_rac_gets(c, 5) > 5)
return 0;
vp56_rac_gets(c, 2);
if (vp56_rac_get(c)) {
av_log(s->avctx, AV_LOG_ERROR, "interlacing not supported\n");
return 0;
}
rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */
cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */
vp56_rac_gets(c, 8); /* number of displayed macroblock rows */
vp56_rac_gets(c, 8); /* number of displayed macroblock cols */
vp56_rac_gets(c, 2);
if (!s->macroblocks || /* first frame */
16*cols != s->avctx->coded_width ||
16*rows != s->avctx->coded_height) {
avcodec_set_dimensions(s->avctx, 16*cols, 16*rows);
return 2;
}
} else if (!s->macroblocks)
return 0;
return 1;
}
static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int comp, di;
for (comp=0; comp<2; comp++) {
int delta = 0;
if (vp56_rac_get_prob(c, model->vector_dct[comp])) {
int sign = vp56_rac_get_prob(c, model->vector_sig[comp]);
di = vp56_rac_get_prob(c, model->vector_pdi[comp][0]);
di |= vp56_rac_get_prob(c, model->vector_pdi[comp][1]) << 1;
delta = vp56_rac_get_tree(c, vp56_pva_tree,
model->vector_pdv[comp]);
delta = di | (delta << 2);
delta = (delta ^ -sign) + sign;
}
if (!comp)
vect->x = delta;
else
vect->y = delta;
}
}
static void vp5_parse_vector_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int comp, node;
for (comp=0; comp<2; comp++) {
if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][0]))
model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][1]))
model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][2]))
model->vector_pdi[comp][0] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][3]))
model->vector_pdi[comp][1] = vp56_rac_gets_nn(c, 7);
}
for (comp=0; comp<2; comp++)
for (node=0; node<7; node++)
if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][4 + node]))
model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
}
static void vp5_parse_coeff_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
uint8_t def_prob[11];
int node, cg, ctx;
int ct; /* code type */
int pt; /* plane type (0 for Y, 1 for U or V) */
memset(def_prob, 0x80, sizeof(def_prob));
for (pt=0; pt<2; pt++)
for (node=0; node<11; node++)
if (vp56_rac_get_prob(c, vp5_dccv_pct[pt][node])) {
def_prob[node] = vp56_rac_gets_nn(c, 7);
model->coeff_dccv[pt][node] = def_prob[node];
} else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
model->coeff_dccv[pt][node] = def_prob[node];
}
for (ct=0; ct<3; ct++)
for (pt=0; pt<2; pt++)
for (cg=0; cg<6; cg++)
for (node=0; node<11; node++)
if (vp56_rac_get_prob(c, vp5_ract_pct[ct][pt][cg][node])) {
def_prob[node] = vp56_rac_gets_nn(c, 7);
model->coeff_ract[pt][ct][cg][node] = def_prob[node];
} else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {
model->coeff_ract[pt][ct][cg][node] = def_prob[node];
}
/* coeff_dcct is a linear combination of coeff_dccv */
for (pt=0; pt<2; pt++)
for (ctx=0; ctx<36; ctx++)
for (node=0; node<5; node++)
model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254);
/* coeff_acct is a linear combination of coeff_ract */
for (ct=0; ct<3; ct++)
for (pt=0; pt<2; pt++)
for (cg=0; cg<3; cg++)
for (ctx=0; ctx<6; ctx++)
for (node=0; node<5; node++)
model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254);
}
static void vp5_parse_coeff(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VP56Model *model = s->modelp;
uint8_t *permute = s->scantable.permutated;
uint8_t *model1, *model2;
int coeff, sign, coeff_idx;
int b, i, cg, idx, ctx, ctx_last;
int pt = 0; /* plane type (0 for Y, 1 for U or V) */
for (b=0; b<6; b++) {
int ct = 1; /* code type */
if (b > 3) pt = 1;
ctx = 6*s->coeff_ctx[vp56_b6to4[b]][0]
+ s->above_blocks[s->above_block_idx[b]].not_null_dc;
model1 = model->coeff_dccv[pt];
model2 = model->coeff_dcct[pt][ctx];
for (coeff_idx=0; coeff_idx<64; ) {
if (vp56_rac_get_prob(c, model2[0])) {
if (vp56_rac_get_prob(c, model2[2])) {
if (vp56_rac_get_prob(c, model2[3])) {
s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4;
idx = vp56_rac_get_tree(c, vp56_pc_tree, model1);
sign = vp56_rac_get(c);
coeff = vp56_coeff_bias[idx+5];
for (i=vp56_coeff_bit_length[idx]; i>=0; i--)
coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i;
} else {
if (vp56_rac_get_prob(c, model2[4])) {
coeff = 3 + vp56_rac_get_prob(c, model1[5]);
s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 3;
} else {
coeff = 2;
s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 2;
}
sign = vp56_rac_get(c);
}
ct = 2;
} else {
ct = 1;
s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 1;
sign = vp56_rac_get(c);
coeff = 1;
}
coeff = (coeff ^ -sign) + sign;
if (coeff_idx)
coeff *= s->dequant_ac;
s->block_coeff[b][permute[coeff_idx]] = coeff;
} else {
if (ct && !vp56_rac_get_prob(c, model2[1]))
break;
ct = 0;
s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 0;
}
cg = vp5_coeff_groups[++coeff_idx];
ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx];
model1 = model->coeff_ract[pt][ct][cg];
model2 = cg > 2 ? model1 : model->coeff_acct[pt][ct][cg][ctx];
}
ctx_last = FFMIN(s->coeff_ctx_last[vp56_b6to4[b]], 24);
s->coeff_ctx_last[vp56_b6to4[b]] = coeff_idx;
if (coeff_idx < ctx_last)
for (i=coeff_idx; i<=ctx_last; i++)
s->coeff_ctx[vp56_b6to4[b]][i] = 5;
s->above_blocks[s->above_block_idx[b]].not_null_dc = s->coeff_ctx[vp56_b6to4[b]][0];
}
}
static void vp5_default_models_init(VP56Context *s)
{
VP56Model *model = s->modelp;
int i;
for (i=0; i<2; i++) {
model->vector_sig[i] = 0x80;
model->vector_dct[i] = 0x80;
model->vector_pdi[i][0] = 0x55;
model->vector_pdi[i][1] = 0x80;
}
memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));
memset(model->vector_pdv, 0x80, sizeof(model->vector_pdv));
}
static av_cold int vp5_decode_init(AVCodecContext *avctx)
{
VP56Context *s = avctx->priv_data;
vp56_init(avctx, 1, 0);
s->vp56_coord_div = vp5_coord_div;
s->parse_vector_adjustment = vp5_parse_vector_adjustment;
s->parse_coeff = vp5_parse_coeff;
s->default_models_init = vp5_default_models_init;
s->parse_vector_models = vp5_parse_vector_models;
s->parse_coeff_models = vp5_parse_coeff_models;
s->parse_header = vp5_parse_header;
return 0;
}
AVCodec vp5_decoder = {
"vp5",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_VP5,
sizeof(VP56Context),
vp5_decode_init,
NULL,
vp56_free,
vp56_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("On2 VP5"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/vp5.c | C | asf20 | 10,147 |
/*
* Sierra VMD Audio & Video Decoders
* Copyright (C) 2004 the ffmpeg project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Sierra VMD audio & video decoders
* by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
* for more information on the Sierra VMD format, visit:
* http://www.pcisys.net/~melanson/codecs/
*
* The video decoder outputs PAL8 colorspace data. The decoder expects
* a 0x330-byte VMD file header to be transmitted via extradata during
* codec initialization. Each encoded frame that is sent to this decoder
* is expected to be prepended with the appropriate 16-byte frame
* information record from the VMD file.
*
* The audio decoder, like the video decoder, expects each encoded data
* chunk to be prepended with the appropriate 16-byte frame information
* record from the VMD file. It does not require the 0x330-byte VMD file
* header, but it does need the audio setup parameters passed in through
* normal libavcodec API means.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#define VMD_HEADER_SIZE 0x330
#define PALETTE_COUNT 256
/*
* Video Decoder
*/
typedef struct VmdVideoContext {
AVCodecContext *avctx;
AVFrame frame;
AVFrame prev_frame;
const unsigned char *buf;
int size;
unsigned char palette[PALETTE_COUNT * 4];
unsigned char *unpack_buffer;
int unpack_buffer_size;
int x_off, y_off;
} VmdVideoContext;
#define QUEUE_SIZE 0x1000
#define QUEUE_MASK 0x0FFF
static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_len)
{
const unsigned char *s;
unsigned char *d;
unsigned char *d_end;
unsigned char queue[QUEUE_SIZE];
unsigned int qpos;
unsigned int dataleft;
unsigned int chainofs;
unsigned int chainlen;
unsigned int speclen;
unsigned char tag;
unsigned int i, j;
s = src;
d = dest;
d_end = d + dest_len;
dataleft = AV_RL32(s);
s += 4;
memset(queue, 0x20, QUEUE_SIZE);
if (AV_RL32(s) == 0x56781234) {
s += 4;
qpos = 0x111;
speclen = 0xF + 3;
} else {
qpos = 0xFEE;
speclen = 100; /* no speclen */
}
while (dataleft > 0) {
tag = *s++;
if ((tag == 0xFF) && (dataleft > 8)) {
if (d + 8 > d_end)
return;
for (i = 0; i < 8; i++) {
queue[qpos++] = *d++ = *s++;
qpos &= QUEUE_MASK;
}
dataleft -= 8;
} else {
for (i = 0; i < 8; i++) {
if (dataleft == 0)
break;
if (tag & 0x01) {
if (d + 1 > d_end)
return;
queue[qpos++] = *d++ = *s++;
qpos &= QUEUE_MASK;
dataleft--;
} else {
chainofs = *s++;
chainofs |= ((*s & 0xF0) << 4);
chainlen = (*s++ & 0x0F) + 3;
if (chainlen == speclen)
chainlen = *s++ + 0xF + 3;
if (d + chainlen > d_end)
return;
for (j = 0; j < chainlen; j++) {
*d = queue[chainofs++ & QUEUE_MASK];
queue[qpos++] = *d++;
qpos &= QUEUE_MASK;
}
dataleft -= chainlen;
}
tag >>= 1;
}
}
}
}
static int rle_unpack(const unsigned char *src, unsigned char *dest,
int src_len, int dest_len)
{
const unsigned char *ps;
unsigned char *pd;
int i, l;
unsigned char *dest_end = dest + dest_len;
ps = src;
pd = dest;
if (src_len & 1)
*pd++ = *ps++;
src_len >>= 1;
i = 0;
do {
l = *ps++;
if (l & 0x80) {
l = (l & 0x7F) * 2;
if (pd + l > dest_end)
return ps - src;
memcpy(pd, ps, l);
ps += l;
pd += l;
} else {
if (pd + i > dest_end)
return ps - src;
for (i = 0; i < l; i++) {
*pd++ = ps[0];
*pd++ = ps[1];
}
ps += 2;
}
i += l;
} while (i < src_len);
return ps - src;
}
static void vmd_decode(VmdVideoContext *s)
{
int i;
unsigned int *palette32;
unsigned char r, g, b;
/* point to the start of the encoded data */
const unsigned char *p = s->buf + 16;
const unsigned char *pb;
unsigned char meth;
unsigned char *dp; /* pointer to current frame */
unsigned char *pp; /* pointer to previous frame */
unsigned char len;
int ofs;
int frame_x, frame_y;
int frame_width, frame_height;
int dp_size;
frame_x = AV_RL16(&s->buf[6]);
frame_y = AV_RL16(&s->buf[8]);
frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;
frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;
if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&
(frame_x || frame_y)) {
s->x_off = frame_x;
s->y_off = frame_y;
}
frame_x -= s->x_off;
frame_y -= s->y_off;
/* if only a certain region will be updated, copy the entire previous
* frame before the decode */
if (frame_x || frame_y || (frame_width != s->avctx->width) ||
(frame_height != s->avctx->height)) {
memcpy(s->frame.data[0], s->prev_frame.data[0],
s->avctx->height * s->frame.linesize[0]);
}
/* check if there is a new palette */
if (s->buf[15] & 0x02) {
p += 2;
palette32 = (unsigned int *)s->palette;
for (i = 0; i < PALETTE_COUNT; i++) {
r = *p++ * 4;
g = *p++ * 4;
b = *p++ * 4;
palette32[i] = (r << 16) | (g << 8) | (b);
}
s->size -= (256 * 3 + 2);
}
if (s->size >= 0) {
/* originally UnpackFrame in VAG's code */
pb = p;
meth = *pb++;
if (meth & 0x80) {
lz_unpack(pb, s->unpack_buffer, s->unpack_buffer_size);
meth &= 0x7F;
pb = s->unpack_buffer;
}
dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];
dp_size = s->frame.linesize[0] * s->avctx->height;
pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
switch (meth) {
case 1:
for (i = 0; i < frame_height; i++) {
ofs = 0;
do {
len = *pb++;
if (len & 0x80) {
len = (len & 0x7F) + 1;
if (ofs + len > frame_width)
return;
memcpy(&dp[ofs], pb, len);
pb += len;
ofs += len;
} else {
/* interframe pixel copy */
if (ofs + len + 1 > frame_width)
return;
memcpy(&dp[ofs], &pp[ofs], len + 1);
ofs += len + 1;
}
} while (ofs < frame_width);
if (ofs > frame_width) {
av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
ofs, frame_width);
break;
}
dp += s->frame.linesize[0];
pp += s->prev_frame.linesize[0];
}
break;
case 2:
for (i = 0; i < frame_height; i++) {
memcpy(dp, pb, frame_width);
pb += frame_width;
dp += s->frame.linesize[0];
pp += s->prev_frame.linesize[0];
}
break;
case 3:
for (i = 0; i < frame_height; i++) {
ofs = 0;
do {
len = *pb++;
if (len & 0x80) {
len = (len & 0x7F) + 1;
if (*pb++ == 0xFF)
len = rle_unpack(pb, &dp[ofs], len, frame_width - ofs);
else
memcpy(&dp[ofs], pb, len);
pb += len;
ofs += len;
} else {
/* interframe pixel copy */
if (ofs + len + 1 > frame_width)
return;
memcpy(&dp[ofs], &pp[ofs], len + 1);
ofs += len + 1;
}
} while (ofs < frame_width);
if (ofs > frame_width) {
av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n",
ofs, frame_width);
}
dp += s->frame.linesize[0];
pp += s->prev_frame.linesize[0];
}
break;
}
}
}
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
{
VmdVideoContext *s = avctx->priv_data;
int i;
unsigned int *palette32;
int palette_index = 0;
unsigned char r, g, b;
unsigned char *vmd_header;
unsigned char *raw_palette;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
/* make sure the VMD header made it */
if (s->avctx->extradata_size != VMD_HEADER_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, "VMD video: expected extradata size of %d\n",
VMD_HEADER_SIZE);
return -1;
}
vmd_header = (unsigned char *)avctx->extradata;
s->unpack_buffer_size = AV_RL32(&vmd_header[800]);
s->unpack_buffer = av_malloc(s->unpack_buffer_size);
if (!s->unpack_buffer)
return -1;
/* load up the initial palette */
raw_palette = &vmd_header[28];
palette32 = (unsigned int *)s->palette;
for (i = 0; i < PALETTE_COUNT; i++) {
r = raw_palette[palette_index++] * 4;
g = raw_palette[palette_index++] * 4;
b = raw_palette[palette_index++] * 4;
palette32[i] = (r << 16) | (g << 8) | (b);
}
return 0;
}
static int vmdvideo_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VmdVideoContext *s = avctx->priv_data;
s->buf = buf;
s->size = buf_size;
if (buf_size < 16)
return buf_size;
s->frame.reference = 1;
if (avctx->get_buffer(avctx, &s->frame)) {
av_log(s->avctx, AV_LOG_ERROR, "VMD Video: get_buffer() failed\n");
return -1;
}
vmd_decode(s);
/* make the palette available on the way out */
memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
/* shuffle frames */
FFSWAP(AVFrame, s->frame, s->prev_frame);
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->prev_frame;
/* report that the buffer was completely consumed */
return buf_size;
}
static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
{
VmdVideoContext *s = avctx->priv_data;
if (s->prev_frame.data[0])
avctx->release_buffer(avctx, &s->prev_frame);
av_free(s->unpack_buffer);
return 0;
}
/*
* Audio Decoder
*/
typedef struct VmdAudioContext {
AVCodecContext *avctx;
int channels;
int bits;
int block_align;
int predictors[2];
} VmdAudioContext;
static const uint16_t vmdaudio_table[128] = {
0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080,
0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120,
0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0,
0x1D0, 0x1E0, 0x1F0, 0x200, 0x208, 0x210, 0x218, 0x220, 0x228, 0x230,
0x238, 0x240, 0x248, 0x250, 0x258, 0x260, 0x268, 0x270, 0x278, 0x280,
0x288, 0x290, 0x298, 0x2A0, 0x2A8, 0x2B0, 0x2B8, 0x2C0, 0x2C8, 0x2D0,
0x2D8, 0x2E0, 0x2E8, 0x2F0, 0x2F8, 0x300, 0x308, 0x310, 0x318, 0x320,
0x328, 0x330, 0x338, 0x340, 0x348, 0x350, 0x358, 0x360, 0x368, 0x370,
0x378, 0x380, 0x388, 0x390, 0x398, 0x3A0, 0x3A8, 0x3B0, 0x3B8, 0x3C0,
0x3C8, 0x3D0, 0x3D8, 0x3E0, 0x3E8, 0x3F0, 0x3F8, 0x400, 0x440, 0x480,
0x4C0, 0x500, 0x540, 0x580, 0x5C0, 0x600, 0x640, 0x680, 0x6C0, 0x700,
0x740, 0x780, 0x7C0, 0x800, 0x900, 0xA00, 0xB00, 0xC00, 0xD00, 0xE00,
0xF00, 0x1000, 0x1400, 0x1800, 0x1C00, 0x2000, 0x3000, 0x4000
};
static av_cold int vmdaudio_decode_init(AVCodecContext *avctx)
{
VmdAudioContext *s = avctx->priv_data;
s->avctx = avctx;
s->channels = avctx->channels;
s->bits = avctx->bits_per_coded_sample;
s->block_align = avctx->block_align;
avctx->sample_fmt = SAMPLE_FMT_S16;
av_log(s->avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, block align = %d, sample rate = %d\n",
s->channels, s->bits, s->block_align, avctx->sample_rate);
return 0;
}
static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data,
const uint8_t *buf, int buf_size, int stereo)
{
int i;
int chan = 0;
int16_t *out = (int16_t*)data;
for(i = 0; i < buf_size; i++) {
if(buf[i] & 0x80)
s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F];
else
s->predictors[chan] += vmdaudio_table[buf[i]];
s->predictors[chan] = av_clip_int16(s->predictors[chan]);
out[i] = s->predictors[chan];
chan ^= stereo;
}
}
static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data,
const uint8_t *buf, int silence, int data_size)
{
int bytes_decoded = 0;
int i;
// if (silence)
// av_log(s->avctx, AV_LOG_INFO, "silent block!\n");
if (s->channels == 2) {
/* stereo handling */
if (silence) {
memset(data, 0, data_size * 2);
} else {
if (s->bits == 16)
vmdaudio_decode_audio(s, data, buf, data_size, 1);
else {
/* copy the data but convert it to signed */
for (i = 0; i < data_size; i++){
*data++ = buf[i] + 0x80;
*data++ = buf[i] + 0x80;
}
}
}
} else {
bytes_decoded = data_size * 2;
/* mono handling */
if (silence) {
memset(data, 0, data_size * 2);
} else {
if (s->bits == 16) {
vmdaudio_decode_audio(s, data, buf, data_size, 0);
} else {
/* copy the data but convert it to signed */
for (i = 0; i < data_size; i++){
*data++ = buf[i] + 0x80;
*data++ = buf[i] + 0x80;
}
}
}
}
return data_size * 2;
}
static int vmdaudio_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VmdAudioContext *s = avctx->priv_data;
unsigned char *output_samples = (unsigned char *)data;
/* point to the start of the encoded data */
const unsigned char *p = buf + 16;
if (buf_size < 16)
return buf_size;
if (buf[6] == 1) {
/* the chunk contains audio */
*data_size = vmdaudio_loadsound(s, output_samples, p, 0, buf_size - 16);
} else if (buf[6] == 2) {
/* initial chunk, may contain audio and silence */
uint32_t flags = AV_RB32(p);
int raw_block_size = s->block_align * s->bits / 8;
int silent_chunks;
if(flags == 0xFFFFFFFF)
silent_chunks = 32;
else
silent_chunks = av_log2(flags + 1);
if(*data_size < (s->block_align*silent_chunks + buf_size - 20) * 2)
return -1;
*data_size = 0;
memset(output_samples, 0, raw_block_size * silent_chunks);
output_samples += raw_block_size * silent_chunks;
*data_size = raw_block_size * silent_chunks;
*data_size += vmdaudio_loadsound(s, output_samples, p + 4, 0, buf_size - 20);
} else if (buf[6] == 3) {
/* silent chunk */
*data_size = vmdaudio_loadsound(s, output_samples, p, 1, 0);
}
return buf_size;
}
/*
* Public Data Structures
*/
AVCodec vmdvideo_decoder = {
"vmdvideo",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_VMDVIDEO,
sizeof(VmdVideoContext),
vmdvideo_decode_init,
NULL,
vmdvideo_decode_end,
vmdvideo_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Sierra VMD video"),
};
AVCodec vmdaudio_decoder = {
"vmdaudio",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_VMDAUDIO,
sizeof(VmdAudioContext),
vmdaudio_decode_init,
NULL,
NULL,
vmdaudio_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Sierra VMD audio"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/vmdav.c | C | asf20 | 17,805 |
/*
* Copyright (c) 2009 Mans Rullgard <mans@mansr.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_MIPS_MATHOPS_H
#define AVCODEC_MIPS_MATHOPS_H
#include <stdint.h>
#include "config.h"
#include "libavutil/common.h"
#if HAVE_LOONGSON
static inline av_const int64_t MAC64(int64_t d, int a, int b)
{
int64_t m;
__asm__ ("dmult.g %1, %2, %3 \n\t"
"daddu %0, %0, %1 \n\t"
: "+r"(d), "=&r"(m) : "r"(a), "r"(b));
return d;
}
#define MAC64(d, a, b) ((d) = MAC64(d, a, b))
static inline av_const int64_t MLS64(int64_t d, int a, int b)
{
int64_t m;
__asm__ ("dmult.g %1, %2, %3 \n\t"
"dsubu %0, %0, %1 \n\t"
: "+r"(d), "=&r"(m) : "r"(a), "r"(b));
return d;
}
#define MLS64(d, a, b) ((d) = MLS64(d, a, b))
#elif ARCH_MIPS64
static inline av_const int64_t MAC64(int64_t d, int a, int b)
{
int64_t m;
__asm__ ("dmult %2, %3 \n\t"
"mflo %1 \n\t"
"daddu %0, %0, %1 \n\t"
: "+r"(d), "=&r"(m) : "r"(a), "r"(b));
return d;
}
#define MAC64(d, a, b) ((d) = MAC64(d, a, b))
static inline av_const int64_t MLS64(int64_t d, int a, int b)
{
int64_t m;
__asm__ ("dmult %2, %3 \n\t"
"mflo %1 \n\t"
"dsubu %0, %0, %1 \n\t"
: "+r"(d), "=&r"(m) : "r"(a), "r"(b));
return d;
}
#define MLS64(d, a, b) ((d) = MLS64(d, a, b))
#endif
#endif /* AVCODEC_MIPS_MATHOPS_H */
| 123linslouis-android-video-cutter | jni/libavcodec/mips/mathops.h | C | asf20 | 2,190 |
OBJS-$(HAVE_MMI) += ps2/dsputil_mmi.o \
ps2/idct_mmi.o \
ps2/mpegvideo_mmi.o \
| 123linslouis-android-video-cutter | jni/libavcodec/mips/Makefile | Makefile | asf20 | 222 |
/*
* Fraps FPS1 decoder
* Copyright (c) 2005 Roine Gustafsson
* Copyright (c) 2006 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Lossless Fraps 'FPS1' decoder
* @author Roine Gustafsson <roine at users sf net>
* @author Konstantin Shishkov
*
* Codec algorithm for version 0 is taken from Transcode <www.transcoding.org>
*
* Version 2 files support by Konstantin Shishkov
*/
#include "avcodec.h"
#include "get_bits.h"
#include "huffman.h"
#include "bytestream.h"
#include "dsputil.h"
#define FPS_TAG MKTAG('F', 'P', 'S', 'x')
/**
* local variable storage
*/
typedef struct FrapsContext{
AVCodecContext *avctx;
AVFrame frame;
uint8_t *tmpbuf;
DSPContext dsp;
} FrapsContext;
/**
* initializes decoder
* @param avctx codec context
* @return 0 on success or negative if fails
*/
static av_cold int decode_init(AVCodecContext *avctx)
{
FrapsContext * const s = avctx->priv_data;
avctx->coded_frame = (AVFrame*)&s->frame;
avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */
s->avctx = avctx;
s->tmpbuf = NULL;
dsputil_init(&s->dsp, avctx);
return 0;
}
/**
* Comparator - our nodes should ascend by count
* but with preserved symbol order
*/
static int huff_cmp(const void *va, const void *vb){
const Node *a = va, *b = vb;
return (a->count - b->count)*256 + a->sym - b->sym;
}
/**
* decode Fraps v2 packed plane
*/
static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w,
int h, const uint8_t *src, int size, int Uoff,
const int step)
{
int i, j;
GetBitContext gb;
VLC vlc;
Node nodes[512];
for(i = 0; i < 256; i++)
nodes[i].count = bytestream_get_le32(&src);
size -= 1024;
if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp,
FF_HUFFMAN_FLAG_ZERO_COUNT) < 0)
return -1;
/* we have built Huffman table and are ready to decode plane */
/* convert bits so they may be used by standard bitreader */
s->dsp.bswap_buf((uint32_t *)s->tmpbuf, (const uint32_t *)src, size >> 2);
init_get_bits(&gb, s->tmpbuf, size * 8);
for(j = 0; j < h; j++){
for(i = 0; i < w*step; i += step){
dst[i] = get_vlc2(&gb, vlc.table, 9, 3);
/* lines are stored as deltas between previous lines
* and we need to add 0x80 to the first lines of chroma planes
*/
if(j) dst[i] += dst[i - stride];
else if(Uoff) dst[i] += 0x80;
}
dst += stride;
}
free_vlc(&vlc);
return 0;
}
/**
* decode a frame
* @param avctx codec context
* @param data output AVFrame
* @param data_size size of output data or 0 if no picture is returned
* @param buf input data frame
* @param buf_size size of input data frame
* @return number of consumed bytes on success or negative if decode fails
*/
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
FrapsContext * const s = avctx->priv_data;
AVFrame *frame = data;
AVFrame * const f = (AVFrame*)&s->frame;
uint32_t header;
unsigned int version,header_size;
unsigned int x, y;
const uint32_t *buf32;
uint32_t *luma1,*luma2,*cb,*cr;
uint32_t offs[4];
int i, j, is_chroma, planes;
header = AV_RL32(buf);
version = header & 0xff;
header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */
if (version > 5) {
av_log(avctx, AV_LOG_ERROR,
"This file is encoded with Fraps version %d. " \
"This codec can only decode versions <= 5.\n", version);
return -1;
}
buf+=4;
if (header_size == 8)
buf+=4;
switch(version) {
case 0:
default:
/* Fraps v0 is a reordered YUV420 */
avctx->pix_fmt = PIX_FMT_YUV420P;
if ( (buf_size != avctx->width*avctx->height*3/2+header_size) &&
(buf_size != header_size) ) {
av_log(avctx, AV_LOG_ERROR,
"Invalid frame length %d (should be %d)\n",
buf_size, avctx->width*avctx->height*3/2+header_size);
return -1;
}
if (( (avctx->width % 8) != 0) || ( (avctx->height % 2) != 0 )) {
av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n",
avctx->width, avctx->height);
return -1;
}
f->reference = 1;
f->buffer_hints = FF_BUFFER_HINTS_VALID |
FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, f)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
/* bit 31 means same as previous pic */
f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE;
f->key_frame = f->pict_type == FF_I_TYPE;
if (f->pict_type == FF_I_TYPE) {
buf32=(const uint32_t*)buf;
for(y=0; y<avctx->height/2; y++){
luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ];
luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ];
cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ];
cb=(uint32_t*)&f->data[2][ y*f->linesize[2] ];
for(x=0; x<avctx->width; x+=8){
*(luma1++) = *(buf32++);
*(luma1++) = *(buf32++);
*(luma2++) = *(buf32++);
*(luma2++) = *(buf32++);
*(cr++) = *(buf32++);
*(cb++) = *(buf32++);
}
}
}
break;
case 1:
/* Fraps v1 is an upside-down BGR24 */
avctx->pix_fmt = PIX_FMT_BGR24;
if ( (buf_size != avctx->width*avctx->height*3+header_size) &&
(buf_size != header_size) ) {
av_log(avctx, AV_LOG_ERROR,
"Invalid frame length %d (should be %d)\n",
buf_size, avctx->width*avctx->height*3+header_size);
return -1;
}
f->reference = 1;
f->buffer_hints = FF_BUFFER_HINTS_VALID |
FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, f)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
/* bit 31 means same as previous pic */
f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE;
f->key_frame = f->pict_type == FF_I_TYPE;
if (f->pict_type == FF_I_TYPE) {
for(y=0; y<avctx->height; y++)
memcpy(&f->data[0][ (avctx->height-y)*f->linesize[0] ],
&buf[y*avctx->width*3],
3*avctx->width);
}
break;
case 2:
case 4:
/**
* Fraps v2 is Huffman-coded YUV420 planes
* Fraps v4 is virtually the same
*/
avctx->pix_fmt = PIX_FMT_YUV420P;
planes = 3;
f->reference = 1;
f->buffer_hints = FF_BUFFER_HINTS_VALID |
FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, f)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
/* skip frame */
if(buf_size == 8) {
f->pict_type = FF_P_TYPE;
f->key_frame = 0;
break;
}
f->pict_type = FF_I_TYPE;
f->key_frame = 1;
if ((AV_RL32(buf) != FPS_TAG)||(buf_size < (planes*1024 + 24))) {
av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n");
return -1;
}
for(i = 0; i < planes; i++) {
offs[i] = AV_RL32(buf + 4 + i * 4);
if(offs[i] >= buf_size || (i && offs[i] <= offs[i - 1] + 1024)) {
av_log(avctx, AV_LOG_ERROR, "Fraps: plane %i offset is out of bounds\n", i);
return -1;
}
}
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
is_chroma = !!i;
s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width >> is_chroma,
avctx->height >> is_chroma, buf + offs[i], offs[i + 1] - offs[i], is_chroma, 1) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
return -1;
}
}
break;
case 3:
case 5:
/* Virtually the same as version 4, but is for RGB24 */
avctx->pix_fmt = PIX_FMT_BGR24;
planes = 3;
f->reference = 1;
f->buffer_hints = FF_BUFFER_HINTS_VALID |
FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE;
if (avctx->reget_buffer(avctx, f)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
/* skip frame */
if(buf_size == 8) {
f->pict_type = FF_P_TYPE;
f->key_frame = 0;
break;
}
f->pict_type = FF_I_TYPE;
f->key_frame = 1;
if ((AV_RL32(buf) != FPS_TAG)||(buf_size < (planes*1024 + 24))) {
av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n");
return -1;
}
for(i = 0; i < planes; i++) {
offs[i] = AV_RL32(buf + 4 + i * 4);
if(offs[i] >= buf_size || (i && offs[i] <= offs[i - 1] + 1024)) {
av_log(avctx, AV_LOG_ERROR, "Fraps: plane %i offset is out of bounds\n", i);
return -1;
}
}
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0],
avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
return -1;
}
}
// convert pseudo-YUV into real RGB
for(j = 0; j < avctx->height; j++){
for(i = 0; i < avctx->width; i++){
f->data[0][0 + i*3 + j*f->linesize[0]] += f->data[0][1 + i*3 + j*f->linesize[0]];
f->data[0][2 + i*3 + j*f->linesize[0]] += f->data[0][1 + i*3 + j*f->linesize[0]];
}
}
break;
}
*frame = *f;
*data_size = sizeof(AVFrame);
return buf_size;
}
/**
* closes decoder
* @param avctx codec context
* @return 0 on success or negative if fails
*/
static av_cold int decode_end(AVCodecContext *avctx)
{
FrapsContext *s = (FrapsContext*)avctx->priv_data;
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
av_freep(&s->tmpbuf);
return 0;
}
AVCodec fraps_decoder = {
"fraps",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_FRAPS,
sizeof(FrapsContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Fraps"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/fraps.c | C | asf20 | 12,252 |
/*
* copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
int cmd= args ? *args : 0;
AVCodecParserContext *s;
if(!bsfc->parser){
bsfc->parser= av_parser_init(avctx->codec_id);
}
s= bsfc->parser;
if(s && s->parser->split){
if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a')
||(!keyframe && cmd=='k')
||(cmd=='e' || !cmd)
){
int i= s->parser->split(avctx, buf, buf_size);
buf += i;
buf_size -= i;
}
}
*poutbuf= (uint8_t *) buf;
*poutbuf_size= buf_size;
return 0;
}
AVBitStreamFilter remove_extradata_bsf={
"remove_extra",
0,
remove_extradata,
};
| 123linslouis-android-video-cutter | jni/libavcodec/remove_extradata_bsf.c | C | asf20 | 1,773 |
/*
* RTJpeg decoding functions
* copyright (c) 2006 Reimar Doeffinger
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_RTJPEG_H
#define AVCODEC_RTJPEG_H
#include <stdint.h>
#include "dsputil.h"
typedef struct {
int w, h;
DSPContext *dsp;
uint8_t scan[64];
uint32_t lquant[64];
uint32_t cquant[64];
DECLARE_ALIGNED(16, DCTELEM, block)[64];
} RTJpegContext;
void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp,
int width, int height,
const uint32_t *lquant, const uint32_t *cquant);
int rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f,
const uint8_t *buf, int buf_size);
#endif /* AVCODEC_RTJPEG_H */
| 123linslouis-android-video-cutter | jni/libavcodec/rtjpeg.h | C | asf20 | 1,453 |
/*
* Musepack decoder
* Copyright (c) 2006 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_MPC7DATA_H
#define AVCODEC_MPC7DATA_H
#include <stdint.h>
static const int8_t mpc7_idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1};
static const int8_t mpc7_idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1};
static const int8_t mpc7_idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
static const int8_t mpc7_idx50[] = { -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};
static const int8_t mpc7_idx51[] = { -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};
#define MPC7_SCFI_SIZE 4
#define MPC7_SCFI_BITS 3
static const uint8_t mpc7_scfi[MPC7_SCFI_SIZE * 2] = {
0x2, 3, 0x1, 1, 0x3, 3, 0x0, 2
};
#define MPC7_DSCF_SIZE 16
#define MPC7_DSCF_BITS 6
static const uint8_t mpc7_dscf[MPC7_DSCF_SIZE * 2] = {
0x20, 6, 0x04, 5, 0x11, 5, 0x1E, 5, 0x0D, 4, 0x00, 3, 0x03, 3, 0x09, 4,
0x05, 3, 0x02, 3, 0x0E, 4, 0x03, 4, 0x1F, 5, 0x05, 5, 0x21, 6, 0x0C, 4
};
#define MPC7_HDR_SIZE 10
#define MPC7_HDR_BITS 9
static const uint8_t mpc7_hdr[MPC7_HDR_SIZE * 2] = {
0x5C, 8, 0x2F, 7, 0x0A, 5, 0x04, 4, 0x00, 2,
0x01, 1, 0x03, 3, 0x16, 6, 0xBB, 9, 0xBA, 9
};
#define MPC7_QUANT_VLC_TABLES 7
static const uint8_t mpc7_quant_vlc_sizes[MPC7_QUANT_VLC_TABLES * 2] = {
27, 25, 7, 9, 15, 31, 63
};
static const uint8_t mpc7_quant_vlc_off[MPC7_QUANT_VLC_TABLES] = {
0, 0, 3, 4, 7, 15, 31
};
static const uint16_t mpc7_quant_vlc[MPC7_QUANT_VLC_TABLES][2][64 * 2] = {
{
{
0x0036, 6, 0x0009, 5, 0x0020, 6, 0x0005, 5, 0x000A, 4, 0x0007, 5,
0x0034, 6, 0x0000, 5, 0x0023, 6, 0x000A, 5, 0x0006, 4, 0x0004, 5,
0x000B, 4, 0x0007, 3, 0x000C, 4, 0x0003, 5, 0x0007, 4, 0x000B, 5,
0x0022, 6, 0x0001, 5, 0x0035, 6, 0x0006, 5, 0x0009, 4, 0x0002, 5,
0x0021, 6, 0x0008, 5, 0x0037, 6
},
{
0x0067, 8, 0x003E, 7, 0x00E1, 9, 0x0037, 7, 0x0003, 4, 0x0034, 7,
0x0065, 8, 0x003C, 7, 0x00E3, 9, 0x0018, 6, 0x0000, 4, 0x003D, 7,
0x0004, 4, 0x0001, 1, 0x0005, 4, 0x003F, 7, 0x0001, 4, 0x003B, 7,
0x00E2, 9, 0x0039, 7, 0x0064, 8, 0x0035, 7, 0x0002, 4, 0x0036, 7,
0x00E0, 9, 0x003A, 7, 0x0066, 8
}
},
{
{
0x0059, 7, 0x002F, 6, 0x000F, 5, 0x0000, 5, 0x005B, 7, 0x0004, 5,
0x0006, 4, 0x000D, 4, 0x0004, 4, 0x0005, 5, 0x0014, 5, 0x000C, 4,
0x0004, 3, 0x000F, 4, 0x000E, 5, 0x0003, 5, 0x0003, 4, 0x000E, 4,
0x0005, 4, 0x0001, 5, 0x005A, 7, 0x0002, 5, 0x0015, 5, 0x002E, 6,
0x0058, 7
},
{
0x0399, 10, 0x0071, 7, 0x0033, 6, 0x00E7, 8, 0x039A, 10, 0x0068, 7,
0x001E, 5, 0x0000, 3, 0x001D, 5, 0x0069, 7, 0x0032, 6, 0x0001, 3,
0x0002, 2, 0x0003, 3, 0x0031, 6, 0x006B, 7, 0x001B, 5, 0x0002, 3,
0x001F, 5, 0x0070, 7, 0x0398, 10, 0x006A, 7, 0x0030, 6, 0x0072, 7,
0x039B, 10
}
},
{
{
0x000C, 4, 0x0004, 3, 0x0000, 2, 0x0001, 2, 0x0007, 3, 0x0005, 3, 0x000D, 4
},
{
0x0004, 5, 0x0003, 4, 0x0002, 2, 0x0003, 2, 0x0001, 2, 0x0000, 3, 0x0005, 5
}
},
{
{
0x0005, 4, 0x0000, 3, 0x0004, 3, 0x0006, 3, 0x0007, 3, 0x0005, 3, 0x0003, 3, 0x0001, 3, 0x0004, 4
},
{
0x0009, 5, 0x000C, 4, 0x0003, 3, 0x0000, 2, 0x0002, 2, 0x0007, 3, 0x000D, 4, 0x0005, 4, 0x0008, 5
}
},
{
{
0x0039, 6, 0x0017, 5, 0x0008, 4, 0x000A, 4, 0x000D, 4, 0x0000, 3,
0x0002, 3, 0x0003, 3, 0x0001, 3, 0x000F, 4, 0x000C, 4, 0x0009, 4,
0x001D, 5, 0x0016, 5, 0x0038, 6,
},
{
0x00E5, 8, 0x0038, 6, 0x0007, 5, 0x0002, 4, 0x0000, 3, 0x0003, 3,
0x0005, 3, 0x0006, 3, 0x0004, 3, 0x0002, 3, 0x000F, 4, 0x001D, 5,
0x0006, 5, 0x0073, 7, 0x00E4, 8,
},
},
{
{
0x0041, 7, 0x0006, 6, 0x002C, 6, 0x002D, 6, 0x003B, 6, 0x000D, 5,
0x0011, 5, 0x0013, 5, 0x0017, 5, 0x0015, 5, 0x001A, 5, 0x001E, 5,
0x0000, 4, 0x0002, 4, 0x0005, 4, 0x0007, 4, 0x0003, 4, 0x0004, 4,
0x001F, 5, 0x001C, 5, 0x0019, 5, 0x001B, 5, 0x0018, 5, 0x0014, 5,
0x0012, 5, 0x000C, 5, 0x0002, 5, 0x003A, 6, 0x0021, 6, 0x0007, 6,
0x0040, 7
},
{
0x1948, 13, 0x194A, 13, 0x0328, 10, 0x0195, 9, 0x00CB, 8, 0x0066, 7,
0x0031, 6, 0x0009, 5, 0x000F, 5, 0x001F, 5, 0x0002, 4, 0x0006, 4,
0x0008, 4, 0x000B, 4, 0x000D, 4, 0x0000, 3, 0x000E, 4, 0x000A, 4,
0x0009, 4, 0x0005, 4, 0x0003, 4, 0x001E, 5, 0x000E, 5, 0x0008, 5,
0x0030, 6, 0x0067, 7, 0x00C9, 8, 0x00C8, 8, 0x0653, 11, 0x1949, 13,
0x194B, 13
}
},
{
{
0x0067, 8, 0x0099, 8, 0x00B5, 8, 0x00E9, 8, 0x0040, 7, 0x0041, 7,
0x004D, 7, 0x0051, 7, 0x005B, 7, 0x0071, 7, 0x0070, 7, 0x0018, 6,
0x001D, 6, 0x0023, 6, 0x0025, 6, 0x0029, 6, 0x002C, 6, 0x002E, 6,
0x0033, 6, 0x0031, 6, 0x0036, 6, 0x0037, 6, 0x0039, 6, 0x003C, 6,
0x0000, 5, 0x0002, 5, 0x000A, 5, 0x0005, 5, 0x0009, 5, 0x0006, 5,
0x000D, 5, 0x0007, 5, 0x000B, 5, 0x000F, 5, 0x0008, 5, 0x0004, 5,
0x0003, 5, 0x0001, 5, 0x003F, 6, 0x003E, 6, 0x003D, 6, 0x0035, 6,
0x003B, 6, 0x0034, 6, 0x0030, 6, 0x002F, 6, 0x002B, 6, 0x002A, 6,
0x0027, 6, 0x0024, 6, 0x0021, 6, 0x001C, 6, 0x0075, 7, 0x0065, 7,
0x0064, 7, 0x0050, 7, 0x0045, 7, 0x0044, 7, 0x0032, 7, 0x00E8, 8,
0x00B4, 8, 0x0098, 8, 0x0066, 8
},
{
0x37A4, 14, 0x37AD, 14, 0x37A6, 14, 0x37AE, 14, 0x0DEA, 12, 0x02F0, 10,
0x02F1, 10, 0x00A0, 9, 0x00A2, 9, 0x01BC, 9, 0x007A, 8, 0x00DF, 8,
0x003C, 7, 0x0049, 7, 0x006E, 7, 0x000E, 6, 0x0018, 6, 0x0019, 6,
0x0022, 6, 0x0025, 6, 0x0036, 6, 0x0003, 5, 0x0009, 5, 0x000B, 5,
0x0010, 5, 0x0013, 5, 0x0015, 5, 0x0018, 5, 0x001A, 5, 0x001D, 5,
0x001F, 5, 0x0002, 4, 0x0000, 4, 0x001E, 5, 0x001C, 5, 0x0019, 5,
0x0016, 5, 0x0014, 5, 0x000E, 5, 0x000D, 5, 0x0008, 5, 0x0006, 5,
0x0002, 5, 0x002E, 6, 0x0023, 6, 0x001F, 6, 0x0015, 6, 0x000F, 6,
0x005F, 7, 0x0048, 7, 0x0029, 7, 0x00BD, 8, 0x007B, 8, 0x0179, 9,
0x00A1, 9, 0x037B, 10, 0x0147, 10, 0x0146, 10, 0x0DE8, 12, 0x37AF, 14,
0x37A7, 14, 0x37AC, 14, 0x37A5, 14
}
}
};
#endif /* AVCODEC_MPC7DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/mpc7data.h | C | asf20 | 7,412 |
/*
* VMware Screen Codec (VMnc) decoder
* Copyright (c) 2006 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VMware Screen Codec (VMnc) decoder
* As Alex Beregszaszi discovered, this is effectively RFB data dump
*/
#include <stdio.h>
#include <stdlib.h>
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
enum EncTypes {
MAGIC_WMVd = 0x574D5664,
MAGIC_WMVe,
MAGIC_WMVf,
MAGIC_WMVg,
MAGIC_WMVh,
MAGIC_WMVi,
MAGIC_WMVj
};
enum HexTile_Flags {
HT_RAW = 1, // tile is raw
HT_BKG = 2, // background color is present
HT_FG = 4, // foreground color is present
HT_SUB = 8, // subrects are present
HT_CLR = 16 // each subrect has own color
};
/*
* Decoder context
*/
typedef struct VmncContext {
AVCodecContext *avctx;
AVFrame pic;
int bpp;
int bpp2;
int bigendian;
uint8_t pal[768];
int width, height;
/* cursor data */
int cur_w, cur_h;
int cur_x, cur_y;
int cur_hx, cur_hy;
uint8_t* curbits, *curmask;
uint8_t* screendta;
} VmncContext;
/* read pixel value from stream */
static av_always_inline int vmnc_get_pixel(const uint8_t* buf, int bpp, int be) {
switch(bpp * 2 + be) {
case 2:
case 3: return *buf;
case 4: return AV_RL16(buf);
case 5: return AV_RB16(buf);
case 8: return AV_RL32(buf);
case 9: return AV_RB32(buf);
default: return 0;
}
}
static void load_cursor(VmncContext *c, const uint8_t *src)
{
int i, j, p;
const int bpp = c->bpp2;
uint8_t *dst8 = c->curbits;
uint16_t *dst16 = (uint16_t*)c->curbits;
uint32_t *dst32 = (uint32_t*)c->curbits;
for(j = 0; j < c->cur_h; j++) {
for(i = 0; i < c->cur_w; i++) {
p = vmnc_get_pixel(src, bpp, c->bigendian);
src += bpp;
if(bpp == 1) *dst8++ = p;
if(bpp == 2) *dst16++ = p;
if(bpp == 4) *dst32++ = p;
}
}
dst8 = c->curmask;
dst16 = (uint16_t*)c->curmask;
dst32 = (uint32_t*)c->curmask;
for(j = 0; j < c->cur_h; j++) {
for(i = 0; i < c->cur_w; i++) {
p = vmnc_get_pixel(src, bpp, c->bigendian);
src += bpp;
if(bpp == 1) *dst8++ = p;
if(bpp == 2) *dst16++ = p;
if(bpp == 4) *dst32++ = p;
}
}
}
static void put_cursor(uint8_t *dst, int stride, VmncContext *c, int dx, int dy)
{
int i, j;
int w, h, x, y;
w = c->cur_w;
if(c->width < c->cur_x + c->cur_w) w = c->width - c->cur_x;
h = c->cur_h;
if(c->height < c->cur_y + c->cur_h) h = c->height - c->cur_y;
x = c->cur_x;
y = c->cur_y;
if(x < 0) {
w += x;
x = 0;
}
if(y < 0) {
h += y;
y = 0;
}
if((w < 1) || (h < 1)) return;
dst += x * c->bpp2 + y * stride;
if(c->bpp2 == 1) {
uint8_t* cd = c->curbits, *msk = c->curmask;
for(j = 0; j < h; j++) {
for(i = 0; i < w; i++)
dst[i] = (dst[i] & cd[i]) ^ msk[i];
msk += c->cur_w;
cd += c->cur_w;
dst += stride;
}
} else if(c->bpp2 == 2) {
uint16_t* cd = (uint16_t*)c->curbits, *msk = (uint16_t*)c->curmask;
uint16_t* dst2;
for(j = 0; j < h; j++) {
dst2 = (uint16_t*)dst;
for(i = 0; i < w; i++)
dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
msk += c->cur_w;
cd += c->cur_w;
dst += stride;
}
} else if(c->bpp2 == 4) {
uint32_t* cd = (uint32_t*)c->curbits, *msk = (uint32_t*)c->curmask;
uint32_t* dst2;
for(j = 0; j < h; j++) {
dst2 = (uint32_t*)dst;
for(i = 0; i < w; i++)
dst2[i] = (dst2[i] & cd[i]) ^ msk[i];
msk += c->cur_w;
cd += c->cur_w;
dst += stride;
}
}
}
/* fill rectangle with given color */
static av_always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride)
{
int i, j;
dst += dx * bpp + dy * stride;
if(bpp == 1){
for(j = 0; j < h; j++) {
memset(dst, color, w);
dst += stride;
}
}else if(bpp == 2){
uint16_t* dst2;
for(j = 0; j < h; j++) {
dst2 = (uint16_t*)dst;
for(i = 0; i < w; i++) {
*dst2++ = color;
}
dst += stride;
}
}else if(bpp == 4){
uint32_t* dst2;
for(j = 0; j < h; j++) {
dst2 = (uint32_t*)dst;
for(i = 0; i < w; i++) {
dst2[i] = color;
}
dst += stride;
}
}
}
static av_always_inline void paint_raw(uint8_t *dst, int w, int h, const uint8_t* src, int bpp, int be, int stride)
{
int i, j, p;
for(j = 0; j < h; j++) {
for(i = 0; i < w; i++) {
p = vmnc_get_pixel(src, bpp, be);
src += bpp;
switch(bpp){
case 1:
dst[i] = p;
break;
case 2:
((uint16_t*)dst)[i] = p;
break;
case 4:
((uint32_t*)dst)[i] = p;
break;
}
}
dst += stride;
}
}
static int decode_hextile(VmncContext *c, uint8_t* dst, const uint8_t* src, int ssize, int w, int h, int stride)
{
int i, j, k;
int bg = 0, fg = 0, rects, color, flags, xy, wh;
const int bpp = c->bpp2;
uint8_t *dst2;
int bw = 16, bh = 16;
const uint8_t *ssrc=src;
for(j = 0; j < h; j += 16) {
dst2 = dst;
bw = 16;
if(j + 16 > h) bh = h - j;
for(i = 0; i < w; i += 16, dst2 += 16 * bpp) {
if(src - ssrc >= ssize) {
av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
return -1;
}
if(i + 16 > w) bw = w - i;
flags = *src++;
if(flags & HT_RAW) {
if(src - ssrc > ssize - bw * bh * bpp) {
av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
return -1;
}
paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);
src += bw * bh * bpp;
} else {
if(flags & HT_BKG) {
bg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
}
if(flags & HT_FG) {
fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
}
rects = 0;
if(flags & HT_SUB)
rects = *src++;
color = !!(flags & HT_CLR);
paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);
if(src - ssrc > ssize - rects * (color * bpp + 2)) {
av_log(c->avctx, AV_LOG_ERROR, "Premature end of data!\n");
return -1;
}
for(k = 0; k < rects; k++) {
if(color) {
fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
}
xy = *src++;
wh = *src++;
paint_rect(dst2, xy >> 4, xy & 0xF, (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride);
}
}
}
dst += stride * 16;
}
return src - ssrc;
}
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VmncContext * const c = avctx->priv_data;
uint8_t *outptr;
const uint8_t *src = buf;
int dx, dy, w, h, depth, enc, chunks, res, size_left;
c->pic.reference = 1;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
if(avctx->reget_buffer(avctx, &c->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
c->pic.key_frame = 0;
c->pic.pict_type = FF_P_TYPE;
//restore screen after cursor
if(c->screendta) {
int i;
w = c->cur_w;
if(c->width < c->cur_x + w) w = c->width - c->cur_x;
h = c->cur_h;
if(c->height < c->cur_y + h) h = c->height - c->cur_y;
dx = c->cur_x;
if(dx < 0) {
w += dx;
dx = 0;
}
dy = c->cur_y;
if(dy < 0) {
h += dy;
dy = 0;
}
if((w > 0) && (h > 0)) {
outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
for(i = 0; i < h; i++) {
memcpy(outptr, c->screendta + i * c->cur_w * c->bpp2, w * c->bpp2);
outptr += c->pic.linesize[0];
}
}
}
src += 2;
chunks = AV_RB16(src); src += 2;
while(chunks--) {
dx = AV_RB16(src); src += 2;
dy = AV_RB16(src); src += 2;
w = AV_RB16(src); src += 2;
h = AV_RB16(src); src += 2;
enc = AV_RB32(src); src += 4;
outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
size_left = buf_size - (src - buf);
switch(enc) {
case MAGIC_WMVd: // cursor
if(size_left < 2 + w * h * c->bpp2 * 2) {
av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", 2 + w * h * c->bpp2 * 2, size_left);
return -1;
}
src += 2;
c->cur_w = w;
c->cur_h = h;
c->cur_hx = dx;
c->cur_hy = dy;
if((c->cur_hx > c->cur_w) || (c->cur_hy > c->cur_h)) {
av_log(avctx, AV_LOG_ERROR, "Cursor hot spot is not in image: %ix%i of %ix%i cursor size\n", c->cur_hx, c->cur_hy, c->cur_w, c->cur_h);
c->cur_hx = c->cur_hy = 0;
}
c->curbits = av_realloc(c->curbits, c->cur_w * c->cur_h * c->bpp2);
c->curmask = av_realloc(c->curmask, c->cur_w * c->cur_h * c->bpp2);
c->screendta = av_realloc(c->screendta, c->cur_w * c->cur_h * c->bpp2);
load_cursor(c, src);
src += w * h * c->bpp2 * 2;
break;
case MAGIC_WMVe: // unknown
src += 2;
break;
case MAGIC_WMVf: // update cursor position
c->cur_x = dx - c->cur_hx;
c->cur_y = dy - c->cur_hy;
break;
case MAGIC_WMVg: // unknown
src += 10;
break;
case MAGIC_WMVh: // unknown
src += 4;
break;
case MAGIC_WMVi: // ServerInitialization struct
c->pic.key_frame = 1;
c->pic.pict_type = FF_I_TYPE;
depth = *src++;
if(depth != c->bpp) {
av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth);
}
src++;
c->bigendian = *src++;
if(c->bigendian & (~1)) {
av_log(avctx, AV_LOG_INFO, "Invalid header: bigendian flag = %i\n", c->bigendian);
return -1;
}
//skip the rest of pixel format data
src += 13;
break;
case MAGIC_WMVj: // unknown
src += 2;
break;
case 0x00000000: // raw rectangle data
if((dx + w > c->width) || (dy + h > c->height)) {
av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
return -1;
}
if(size_left < w * h * c->bpp2) {
av_log(avctx, AV_LOG_ERROR, "Premature end of data! (need %i got %i)\n", w * h * c->bpp2, size_left);
return -1;
}
paint_raw(outptr, w, h, src, c->bpp2, c->bigendian, c->pic.linesize[0]);
src += w * h * c->bpp2;
break;
case 0x00000005: // HexTile encoded rectangle
if((dx + w > c->width) || (dy + h > c->height)) {
av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height);
return -1;
}
res = decode_hextile(c, outptr, src, size_left, w, h, c->pic.linesize[0]);
if(res < 0)
return -1;
src += res;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported block type 0x%08X\n", enc);
chunks = 0; // leave chunks decoding loop
}
}
if(c->screendta){
int i;
//save screen data before painting cursor
w = c->cur_w;
if(c->width < c->cur_x + w) w = c->width - c->cur_x;
h = c->cur_h;
if(c->height < c->cur_y + h) h = c->height - c->cur_y;
dx = c->cur_x;
if(dx < 0) {
w += dx;
dx = 0;
}
dy = c->cur_y;
if(dy < 0) {
h += dy;
dy = 0;
}
if((w > 0) && (h > 0)) {
outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
for(i = 0; i < h; i++) {
memcpy(c->screendta + i * c->cur_w * c->bpp2, outptr, w * c->bpp2);
outptr += c->pic.linesize[0];
}
outptr = c->pic.data[0];
put_cursor(outptr, c->pic.linesize[0], c, c->cur_x, c->cur_y);
}
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
/*
*
* Init VMnc decoder
*
*/
static av_cold int decode_init(AVCodecContext *avctx)
{
VmncContext * const c = avctx->priv_data;
c->avctx = avctx;
c->width = avctx->width;
c->height = avctx->height;
c->bpp = avctx->bits_per_coded_sample;
c->bpp2 = c->bpp/8;
switch(c->bpp){
case 8:
avctx->pix_fmt = PIX_FMT_PAL8;
break;
case 16:
avctx->pix_fmt = PIX_FMT_RGB555;
break;
case 32:
avctx->pix_fmt = PIX_FMT_RGB32;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
}
return 0;
}
/*
*
* Uninit VMnc decoder
*
*/
static av_cold int decode_end(AVCodecContext *avctx)
{
VmncContext * const c = avctx->priv_data;
if (c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
av_free(c->curbits);
av_free(c->curmask);
av_free(c->screendta);
return 0;
}
AVCodec vmnc_decoder = {
"vmnc",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_VMNC,
sizeof(VmncContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("VMware Screen Codec / VMware Video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/vmnc.c | C | asf20 | 15,517 |
/*
* MJPEG encoder
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
* Support for external huffman table, various fixes (AVID workaround),
* aspecting, new decode_frame mechanism and apple mjpeg-b support
* by Alex Beregszaszi
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MJPEG encoder.
*/
//#define DEBUG
#include <assert.h>
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "mjpeg.h"
#include "mjpegenc.h"
/* use two quantizer tables (one for luminance and one for chrominance) */
/* not yet working */
#undef TWOMATRIXES
av_cold int ff_mjpeg_encode_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 */
ff_mjpeg_build_huffman_codes(m->huff_size_dc_luminance,
m->huff_code_dc_luminance,
ff_mjpeg_bits_dc_luminance,
ff_mjpeg_val_dc);
ff_mjpeg_build_huffman_codes(m->huff_size_dc_chrominance,
m->huff_code_dc_chrominance,
ff_mjpeg_bits_dc_chrominance,
ff_mjpeg_val_dc);
ff_mjpeg_build_huffman_codes(m->huff_size_ac_luminance,
m->huff_code_ac_luminance,
ff_mjpeg_bits_ac_luminance,
ff_mjpeg_val_ac_luminance);
ff_mjpeg_build_huffman_codes(m->huff_size_ac_chrominance,
m->huff_code_ac_chrominance,
ff_mjpeg_bits_ac_chrominance,
ff_mjpeg_val_ac_chrominance);
s->mjpeg_ctx = m;
return 0;
}
void ff_mjpeg_encode_close(MpegEncContext *s)
{
av_free(s->mjpeg_ctx);
}
/* 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 = put_bits_ptr(p);
put_bits(p, 16, 0); /* patched later */
size = 2;
size += put_huffman_table(s, 0, 0, ff_mjpeg_bits_dc_luminance,
ff_mjpeg_val_dc);
size += put_huffman_table(s, 0, 1, ff_mjpeg_bits_dc_chrominance,
ff_mjpeg_val_dc);
size += put_huffman_table(s, 1, 0, ff_mjpeg_bits_ac_luminance,
ff_mjpeg_val_ac_luminance);
size += put_huffman_table(s, 1, 1, ff_mjpeg_bits_ac_chrominance,
ff_mjpeg_val_ac_chrominance);
AV_WB16(ptr, 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);
ff_put_string(p, "JFIF", 1); /* 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 */
put_bits(p, 16, s->avctx->sample_aspect_ratio.num);
put_bits(p, 16, s->avctx->sample_aspect_ratio.den);
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 = put_bits_ptr(p);
put_bits(p, 16, 0); /* patched later */
ff_put_string(p, LIBAVCODEC_IDENT, 1);
size = strlen(LIBAVCODEC_IDENT)+3;
AV_WB16(ptr, size);
}
if( s->avctx->pix_fmt == PIX_FMT_YUV420P
||s->avctx->pix_fmt == PIX_FMT_YUV422P
||s->avctx->pix_fmt == PIX_FMT_YUV444P){
put_marker(p, COM);
flush_put_bits(p);
ptr = put_bits_ptr(p);
put_bits(p, 16, 0); /* patched later */
ff_put_string(p, "CS=ITU601", 1);
size = strlen("CS=ITU601")+3;
AV_WB16(ptr, size);
}
}
void ff_mjpeg_encode_picture_header(MpegEncContext *s)
{
const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG;
put_marker(&s->pb, SOI);
jpeg_put_comments(s);
jpeg_table_header(s);
switch(s->avctx->codec_id){
case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break;
case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break;
default: assert(0);
}
put_bits(&s->pb, 16, 17);
if(lossless && s->avctx->pix_fmt == PIX_FMT_BGRA)
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) */
switch(s->avctx->codec_id){
case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */
case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */
default: assert(0);
}
put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */
}
static void escape_FF(MpegEncContext *s, int start)
{
int size= put_bits_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;
flush_put_bits(&s->pb);
skip_put_bytes(&s->pb, ff_count);
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 ff_mjpeg_encode_stuffing(PutBitContext * pbc)
{
int length;
length= (-put_bits_count(pbc))&7;
if(length) put_bits(pbc, length, (1<<length)-1);
}
void ff_mjpeg_encode_picture_trailer(MpegEncContext *s)
{
ff_mjpeg_encode_stuffing(&s->pb);
flush_put_bits(&s->pb);
assert((s->header_bits&7)==0);
escape_FF(s, s->header_bits>>3);
put_marker(&s->pb, EOI);
}
void ff_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_sbits(&s->pb, nbits, mant);
}
}
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&1) + 1);
dc = block[0]; /* overflow is impossible */
val = dc - s->last_dc[component];
if (n < 4) {
ff_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 {
ff_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_sbits(&s->pb, nbits, mant);
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 ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64])
{
int i;
for(i=0;i<5;i++) {
encode_block(s, block[i], i);
}
if (s->chroma_format == CHROMA_420) {
encode_block(s, block[5], 5);
} else {
encode_block(s, block[6], 6);
encode_block(s, block[5], 5);
encode_block(s, block[7], 7);
}
}
AVCodec mjpeg_encoder = {
"mjpeg",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_MJPEG,
sizeof(MpegEncContext),
MPV_encode_init,
MPV_encode_picture,
MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/mjpegenc.c | C | asf20 | 13,234 |
/*
* copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_VORBIS_ENC_DATA_H
#define AVCODEC_VORBIS_ENC_DATA_H
#include <stdint.h>
static const uint8_t codebook0[] = {
2, 10, 8, 14, 7, 12, 11, 14, 1, 5, 3, 7, 4, 9, 7, 13,
};
static const uint8_t codebook1[] = {
1, 4, 2, 6, 3, 7, 5, 7,
};
static const uint8_t codebook2[] = {
1, 5, 7, 21, 5, 8, 9, 21, 10, 9, 12, 20, 20, 16, 20,
20, 4, 8, 9, 20, 6, 8, 9, 20, 11, 11, 13, 20, 20, 15,
17, 20, 9, 11, 14, 20, 8, 10, 15, 20, 11, 13, 15, 20, 20,
20, 20, 20, 20, 20, 20, 20, 13, 20, 20, 20, 18, 18, 20, 20,
20, 20, 20, 20, 3, 6, 8, 20, 6, 7, 9, 20, 10, 9, 12,
20, 20, 20, 20, 20, 5, 7, 9, 20, 6, 6, 9, 20, 10, 9,
12, 20, 20, 20, 20, 20, 8, 10, 13, 20, 8, 9, 12, 20, 11,
10, 12, 20, 20, 20, 20, 20, 18, 20, 20, 20, 15, 17, 18, 20,
18, 17, 18, 20, 20, 20, 20, 20, 7, 10, 12, 20, 8, 9, 11,
20, 14, 13, 14, 20, 20, 20, 20, 20, 6, 9, 12, 20, 7, 8,
11, 20, 12, 11, 13, 20, 20, 20, 20, 20, 9, 11, 15, 20, 8,
10, 14, 20, 12, 11, 14, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 11, 16, 18,
20, 15, 15, 17, 20, 20, 17, 20, 20, 20, 20, 20, 20, 9, 14,
16, 20, 12, 12, 15, 20, 17, 15, 18, 20, 20, 20, 20, 20, 16,
19, 18, 20, 15, 16, 20, 20, 17, 17, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20,
};
static const uint8_t codebook3[] = {
2, 3, 7, 13, 4, 4, 7, 15, 8, 6, 9, 17, 21, 16, 15,
21, 2, 5, 7, 11, 5, 5, 7, 14, 9, 7, 10, 16, 17, 15,
16, 21, 4, 7, 10, 17, 7, 7, 9, 15, 11, 9, 11, 16, 21,
18, 15, 21, 18, 21, 21, 21, 15, 17, 17, 19, 21, 19, 18, 20,
21, 21, 21, 20,
};
static const uint8_t codebook4[] = {
5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6,
5, 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5,
7, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 10, 6, 10,
6, 11, 6, 11, 7, 11, 7, 12, 7, 12, 7, 12, 7, 12, 7,
12, 7, 12, 7, 12, 7, 12, 8, 13, 8, 12, 8, 12, 8, 13,
8, 13, 9, 13, 9, 13, 9, 13, 9, 12, 10, 12, 10, 13, 10,
14, 11, 14, 12, 14, 13, 14, 13, 14, 14, 15, 16, 15, 15, 15,
14, 15, 17, 21, 22, 22, 21, 22, 22, 22, 22, 22, 22, 21, 21,
21, 21, 21, 21, 21, 21, 21, 21,
};
static const uint8_t codebook5[] = {
2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6,
5, 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6,
9, 6,
};
static const uint8_t codebook6[] = {
8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9,
4, 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5,
9, 5, 9, 5, 9, 6, 10, 6, 10, 7, 10, 8, 11, 9, 11,
11, 12, 13, 12, 14, 13, 15, 13, 15, 14, 16, 14, 17, 15, 17,
15, 15, 16, 16, 15, 16, 16, 16, 15, 18, 16, 15, 17, 17, 19,
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
19, 19, 19, 19, 19, 19,
};
static const uint8_t codebook7[] = {
1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6,
5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8, 10, 9,
10, 9,
};
static const uint8_t codebook8[] = {
4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6,
5, 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8,
9, 9, 9, 9, 10, 10, 10, 11, 9, 12, 9, 12, 9, 15, 10,
14, 9, 13, 10, 13, 10, 12, 10, 12, 10, 13, 10, 12, 11, 13,
11, 14, 12, 13, 13, 14, 14, 13, 14, 15, 14, 16, 13, 13, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 15, 15,
};
static const uint8_t codebook9[] = {
4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
5, 5,
};
static const uint8_t codebook10[] = {
3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 5,
7, 5, 8, 6, 8, 6, 9, 7, 10, 7, 10, 8, 10, 8, 11,
9, 11,
};
static const uint8_t codebook11[] = {
3, 7, 3, 8, 3, 10, 3, 8, 3, 9, 3, 8, 4, 9, 4,
9, 5, 9, 6, 10, 6, 9, 7, 11, 7, 12, 9, 13, 10, 13,
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 uint8_t codebook12[] = {
4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
5, 4,
};
static const uint8_t codebook13[] = {
4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8, 7,
8, 7, 8, 7, 9, 8, 9, 8, 9, 8, 10, 8, 11, 9, 12,
9, 12,
};
static const uint8_t codebook14[] = {
2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5, 11, 6,
11, 6, 11, 7, 11, 6, 11, 6, 11, 9, 11, 8, 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, 10, 10, 10,
10, 10, 10,
};
static const uint8_t codebook15[] = {
5, 6, 11, 11, 11, 11, 10, 10, 12, 11, 5, 2, 11, 5, 6,
6, 7, 9, 11, 13, 13, 10, 7, 11, 6, 7, 8, 9, 10, 12,
11, 5, 11, 6, 8, 7, 9, 11, 14, 15, 11, 6, 6, 8, 4,
5, 7, 8, 10, 13, 10, 5, 7, 7, 5, 5, 6, 8, 10, 11,
10, 7, 7, 8, 6, 5, 5, 7, 9, 9, 11, 8, 8, 11, 8,
7, 6, 6, 7, 9, 12, 11, 10, 13, 9, 9, 7, 7, 7, 9,
11, 13, 12, 15, 12, 11, 9, 8, 8, 8,
};
static const uint8_t codebook16[] = {
2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0,
0, 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0,
7, 8, 8, 0, 0, 0, 0, 0, 0, 6, 7, 8, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7,
0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0, 0, 0, 0, 0,
7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0,
0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0,
0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0,
7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8,
0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0, 0,
0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 8, 9,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
0, 0, 0, 8, 9, 8,
};
static const uint8_t codebook17[] = {
2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0,
0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0,
0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 10, 10, 0, 0,
0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0,
0, 7, 7, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0,
0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0,
0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0,
5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0,
0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 10, 0, 0,
0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0, 10, 10, 0, 0,
0, 0, 0, 0, 0, 8, 10, 10, 0, 0, 0, 9, 9, 0, 0,
0, 9, 9, 0, 0, 0, 10, 10,
};
static const uint8_t codebook18[] = {
2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 7, 9, 9,
};
static const uint8_t codebook19[] = {
2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0,
0, 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5,
6, 6, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0,
0, 0, 0, 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0,
0, 0, 0, 0, 0, 0, 9, 9,
};
static const uint8_t codebook20[] = {
1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7,
8, 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7,
8, 8, 8, 8, 10, 10, 0, 0, 0, 8, 8, 8, 8, 10, 10,
0, 0, 0, 9, 9, 9, 9, 10, 10, 0, 0, 0, 9, 9, 9,
9, 10, 10, 0, 0, 0, 10, 10, 10, 10, 11, 11, 0, 0, 0,
0, 0, 10, 10, 11, 11,
};
static const uint8_t codebook21[] = {
2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10,
11, 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10,
10, 10, 11, 11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,
10, 10, 10, 10, 11, 11, 0, 6, 6, 7, 7, 8, 8, 9, 9,
9, 9, 10, 10, 11, 11, 11, 11, 0, 0, 0, 7, 7, 8, 8,
9, 9, 9, 9, 10, 10, 11, 11, 11, 12, 0, 0, 0, 8, 8,
8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0, 0, 0,
8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 12, 12, 0,
0, 0, 9, 9, 9, 9, 10, 10, 10, 10, 11, 10, 11, 11, 12,
12, 0, 0, 0, 0, 0, 9, 9, 10, 10, 10, 10, 11, 11, 11,
11, 12, 12, 0, 0, 0, 0, 0, 9, 8, 9, 9, 10, 10, 11,
11, 12, 12, 12, 12, 0, 0, 0, 0, 0, 8, 8, 9, 9, 10,
10, 11, 11, 12, 11, 12, 12, 0, 0, 0, 0, 0, 9, 10, 10,
10, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 0,
0, 10, 10, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0,
0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 0, 0,
0, 0, 0, 0, 0, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13,
0, 0, 0, 0, 0, 0, 0, 11, 11, 12, 12, 12, 12, 13, 13,
13, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12,
13, 13, 13, 13,
};
static const uint8_t codebook22[] = {
1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7, 10, 9, 9,
11, 9, 9, 4, 7, 7, 10, 9, 9, 11, 9, 9, 7, 10, 10,
11, 11, 10, 12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10,
6, 9, 9, 11, 10, 10, 11, 10, 10, 7, 11, 11, 11, 11, 11,
12, 11, 11, 6, 9, 9, 11, 10, 10, 11, 10, 10, 6, 9, 9,
11, 10, 10, 11, 10, 10,
};
static const uint8_t codebook23[] = {
2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 10, 5, 5, 6,
6, 7, 7, 8, 8, 8, 8, 10, 5, 5, 6, 6, 7, 7, 8,
8, 8, 8, 10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 10,
10, 10, 7, 7, 8, 7, 8, 8, 8, 8, 10, 10, 10, 8, 8,
8, 8, 8, 8, 8, 8, 10, 10, 10, 7, 8, 8, 8, 8, 8,
8, 8, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10,
10, 10, 10, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, 9,
9, 8, 8, 9, 8, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8,
8,
};
static const uint8_t codebook24[] = {
1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 6, 5,
5, 7, 7, 8, 8, 8, 8, 9, 9, 10, 10, 7, 5, 5, 7,
7, 8, 8, 8, 8, 9, 9, 11, 10, 0, 8, 8, 8, 8, 9,
9, 9, 9, 10, 10, 11, 11, 0, 8, 8, 8, 8, 9, 9, 9,
9, 10, 10, 11, 11, 0, 12, 12, 9, 9, 10, 10, 10, 10, 11,
11, 11, 12, 0, 13, 13, 9, 9, 10, 10, 10, 10, 11, 11, 12,
12, 0, 0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0,
0, 0, 10, 10, 10, 10, 11, 11, 12, 12, 12, 12, 0, 0, 0,
14, 14, 11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 14, 14,
11, 11, 11, 11, 12, 12, 13, 13, 0, 0, 0, 0, 0, 12, 12,
12, 12, 13, 13, 14, 13, 0, 0, 0, 0, 0, 13, 13, 12, 12,
13, 12, 14, 13,
};
static const uint8_t codebook25[] = {
2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5,
6, 5, 5, 5, 5, 6, 6, 6, 5, 5,
};
static const uint8_t codebook26[] = {
1, 4, 4, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 9,
8, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 2, 9, 7, 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, 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, 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,
};
static const uint8_t codebook27[] = {
1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9, 10, 10, 10, 10,
6, 5, 5, 7, 7, 8, 8, 10, 8, 11, 10, 12, 12, 13, 13,
6, 5, 5, 7, 7, 8, 8, 10, 9, 11, 11, 12, 12, 13, 12,
18, 8, 8, 8, 8, 9, 9, 10, 9, 11, 10, 12, 12, 13, 13,
18, 8, 8, 8, 8, 9, 9, 10, 10, 11, 11, 13, 12, 14, 13,
18, 11, 11, 9, 9, 10, 10, 11, 11, 11, 12, 13, 12, 13, 14,
18, 11, 11, 9, 8, 11, 10, 11, 11, 11, 11, 12, 12, 14, 13,
18, 18, 18, 10, 11, 10, 11, 12, 12, 12, 12, 13, 12, 14, 13,
18, 18, 18, 10, 11, 11, 9, 12, 11, 12, 12, 12, 13, 13, 13,
18, 18, 17, 14, 14, 11, 11, 12, 12, 13, 12, 14, 12, 14, 13,
18, 18, 18, 14, 14, 11, 10, 12, 9, 12, 13, 13, 13, 13, 13,
18, 18, 17, 16, 18, 13, 13, 12, 12, 13, 11, 14, 12, 14, 14,
17, 18, 18, 17, 18, 13, 12, 13, 10, 12, 11, 14, 14, 14, 14,
17, 18, 18, 18, 18, 15, 16, 12, 12, 13, 10, 14, 12, 14, 15,
18, 18, 18, 16, 17, 16, 14, 12, 11, 13, 10, 13, 13, 14, 15,
};
static const uint8_t codebook28[] = {
2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
8, 8, 10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9,
9, 9, 9, 9, 10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 10, 7, 7, 7, 7, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 7, 7, 8, 8,
8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 8, 8,
8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10,
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10,
10, 10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10,
9, 10, 10, 10, 11, 11, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9, 9, 10,
10, 9, 9, 10, 9, 11, 10, 11, 11, 11, 9, 9, 9, 9, 9,
9, 9, 9, 10, 10, 10, 9, 11, 11, 11, 11, 11, 9, 9, 9,
9, 10, 10, 9, 9, 9, 9, 10, 9, 11, 11, 11, 11, 11, 11,
11, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11,
11, 11, 11, 10, 9, 10, 10, 9, 10, 9, 9, 10, 9, 11, 10,
10, 11, 11, 11, 11, 9, 10, 9, 9, 9, 9, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 10, 10, 10, 9, 9, 10, 9, 10, 9,
10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 9, 9, 9, 9,
9, 10, 10, 10,
};
static const struct {
int dim;
int len;
int real_len;
const uint8_t *clens;
int lookup;
float min;
float delta;
const uint8_t *quant;
} cvectors[] = {
{ 2, 16, 16, codebook0, 0 },
{ 2, 8, 8, codebook1, 0 },
{ 2, 256, 256, codebook2, 0 },
{ 2, 64, 64, codebook3, 0 },
{ 2, 128, 128, codebook4, 0 },
{ 2, 32, 32, codebook5, 0 },
{ 2, 96, 96, codebook6, 0 },
{ 2, 32, 32, codebook7, 0 },
{ 2, 96, 96, codebook8, 0 },
{ 2, 17, 17, codebook9, 0 },
{ 2, 32, 32, codebook10, 0 },
{ 2, 78, 78, codebook11, 0 },
{ 2, 17, 17, codebook12, 0 },
{ 2, 32, 32, codebook13, 0 },
{ 2, 78, 78, codebook14, 0 },
{ 2, 100, 100, codebook15, 0 },
{ 8, 1641, 6561, codebook16, 1, -1.0, 1.0, (const uint8_t[]){ 1, 0, 2, } },
{ 4, 443, 625, codebook17, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
{ 4, 105, 625, codebook18, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
{ 2, 68, 81, codebook19, 1, -4.0, 1.0, (const uint8_t[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } },
{ 2, 81, 81, codebook20, 1, -4.0, 1.0, (const uint8_t[]){ 4, 3, 5, 2, 6, 1, 7, 0, 8, } },
{ 2, 289, 289, codebook21, 1, -8.0, 1.0, (const uint8_t[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } },
{ 4, 81, 81, codebook22, 1, -11.0, 11.0, (const uint8_t[]){ 1, 0, 2, } },
{ 2, 121, 121, codebook23, 1, -5.0, 1.0, (const uint8_t[]){ 5, 4, 6, 3, 7, 2, 8, 1, 9, 0, 10, } },
{ 2, 169, 169, codebook24, 1, -30.0, 5.0, (const uint8_t[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } },
{ 2, 25, 25, codebook25, 1, -2.0, 1.0, (const uint8_t[]){ 2, 1, 3, 0, 4, } },
{ 2, 169, 169, codebook26, 1, -1530.0, 255.0, (const uint8_t[]){ 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12, } },
{ 2, 225, 225, codebook27, 1, -119.0, 17.0, (const uint8_t[]){ 7, 6, 8, 5, 9, 4, 10, 3, 11, 2, 12, 1, 13, 0, 14, } },
{ 2, 289, 289, codebook28, 1, -8.0, 1.0, (const uint8_t[]){ 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15, 0, 16, } },
};
static const struct {
int dim;
int subclass;
int masterbook;
const int *nbooks;
} floor_classes[] = {
{ 3, 0, 0, (const int[]){ 4 } },
{ 4, 1, 0, (const int[]){ 5, 6 } },
{ 3, 1, 1, (const int[]){ 7, 8 } },
{ 4, 2, 2, (const int[]){ -1, 9, 10, 11 } },
{ 3, 2, 3, (const int[]){ -1, 12, 13, 14 } },
};
#endif /* AVCODEC_VORBIS_ENC_DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/vorbis_enc_data.h | C | asf20 | 25,205 |
/*
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
#include "pnm.h"
static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf,
int buf_size, void *data)
{
PNMContext *s = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p = (AVFrame*)&s->picture;
int i, h, h1, c, n, linesize;
uint8_t *ptr, *ptr1, *ptr2;
if (buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200) {
av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
*p = *pict;
p->pict_type = FF_I_TYPE;
p->key_frame = 1;
s->bytestream_start =
s->bytestream = outbuf;
s->bytestream_end = outbuf + buf_size;
h = avctx->height;
h1 = h;
switch (avctx->pix_fmt) {
case PIX_FMT_MONOWHITE:
c = '4';
n = (avctx->width + 7) >> 3;
break;
case PIX_FMT_GRAY8:
c = '5';
n = avctx->width;
break;
case PIX_FMT_GRAY16BE:
c = '5';
n = avctx->width * 2;
break;
case PIX_FMT_RGB24:
c = '6';
n = avctx->width * 3;
break;
case PIX_FMT_RGB48BE:
c = '6';
n = avctx->width * 6;
break;
case PIX_FMT_YUV420P:
c = '5';
n = avctx->width;
h1 = (h * 3) / 2;
break;
default:
return -1;
}
snprintf(s->bytestream, s->bytestream_end - s->bytestream,
"P%c\n%d %d\n", c, avctx->width, h1);
s->bytestream += strlen(s->bytestream);
if (avctx->pix_fmt != PIX_FMT_MONOWHITE) {
snprintf(s->bytestream, s->bytestream_end - s->bytestream,
"%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE && avctx->pix_fmt != PIX_FMT_RGB48BE) ? 255 : 65535);
s->bytestream += strlen(s->bytestream);
}
ptr = p->data[0];
linesize = p->linesize[0];
for (i = 0; i < h; i++) {
memcpy(s->bytestream, ptr, n);
s->bytestream += n;
ptr += linesize;
}
if (avctx->pix_fmt == PIX_FMT_YUV420P) {
h >>= 1;
n >>= 1;
ptr1 = p->data[1];
ptr2 = p->data[2];
for (i = 0; i < h; i++) {
memcpy(s->bytestream, ptr1, n);
s->bytestream += n;
memcpy(s->bytestream, ptr2, n);
s->bytestream += n;
ptr1 += p->linesize[1];
ptr2 += p->linesize[2];
}
}
return s->bytestream - s->bytestream_start;
}
#if CONFIG_PGM_ENCODER
AVCodec pgm_encoder = {
"pgm",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_PGM,
sizeof(PNMContext),
ff_pnm_init,
pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"),
};
#endif
#if CONFIG_PGMYUV_ENCODER
AVCodec pgmyuv_encoder = {
"pgmyuv",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_PGMYUV,
sizeof(PNMContext),
ff_pnm_init,
pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"),
};
#endif
#if CONFIG_PPM_ENCODER
AVCodec ppm_encoder = {
"ppm",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_PPM,
sizeof(PNMContext),
ff_pnm_init,
pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"),
};
#endif
#if CONFIG_PBM_ENCODER
AVCodec pbm_encoder = {
"pbm",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_PBM,
sizeof(PNMContext),
ff_pnm_init,
pnm_encode_frame,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"),
};
#endif
| 123linslouis-android-video-cutter | jni/libavcodec/pnmenc.c | C | asf20 | 4,689 |
/*
* VC3/DNxHD encoder
* Copyright (c) 2007 Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
*
* VC-3 encoder funded by the British Broadcasting Corporation
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//#define DEBUG
#define RC_VARIANCE 1 // use variance or ssd for fast rc
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "dnxhdenc.h"
int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
#define LAMBDA_FRAC_BITS 10
static av_always_inline void dnxhd_get_pixels_8x4(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
{
int i;
for (i = 0; i < 4; 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;
}
memcpy(block , block- 8, sizeof(*block)*8);
memcpy(block+ 8, block-16, sizeof(*block)*8);
memcpy(block+16, block-24, sizeof(*block)*8);
memcpy(block+24, block-32, sizeof(*block)*8);
}
static int dnxhd_init_vlc(DNXHDEncContext *ctx)
{
int i, j, level, run;
int max_level = 1<<(ctx->cid_table->bit_depth+2);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2 , fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63 , fail);
ctx->vlc_codes += max_level*2;
ctx->vlc_bits += max_level*2;
for (level = -max_level; level < max_level; level++) {
for (run = 0; run < 2; run++) {
int index = (level<<1)|run;
int sign, offset = 0, alevel = level;
MASK_ABS(sign, alevel);
if (alevel > 64) {
offset = (alevel-1)>>6;
alevel -= offset<<6;
}
for (j = 0; j < 257; j++) {
if (ctx->cid_table->ac_level[j] == alevel &&
(!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&
(!run || (ctx->cid_table->ac_run_flag [j] && run))) {
assert(!ctx->vlc_codes[index]);
if (alevel) {
ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1);
ctx->vlc_bits [index] = ctx->cid_table->ac_bits[j]+1;
} else {
ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];
ctx->vlc_bits [index] = ctx->cid_table->ac_bits [j];
}
break;
}
}
assert(!alevel || j < 257);
if (offset) {
ctx->vlc_codes[index] = (ctx->vlc_codes[index]<<ctx->cid_table->index_bits)|offset;
ctx->vlc_bits [index]+= ctx->cid_table->index_bits;
}
}
}
for (i = 0; i < 62; i++) {
int run = ctx->cid_table->run[i];
assert(run < 63);
ctx->run_codes[run] = ctx->cid_table->run_codes[i];
ctx->run_bits [run] = ctx->cid_table->run_bits[i];
}
return 0;
fail:
return -1;
}
static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
{
// init first elem to 1 to avoid div by 0 in convert_matrix
uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t*
int qscale, i;
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail);
for (i = 1; i < 64; i++) {
int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
weight_matrix[j] = ctx->cid_table->luma_weight[i];
}
ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix,
ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
for (i = 1; i < 64; i++) {
int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];
weight_matrix[j] = ctx->cid_table->chroma_weight[i];
}
ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix,
ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);
for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {
for (i = 0; i < 64; i++) {
ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2;
ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2;
ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2;
}
}
return 0;
fail:
return -1;
}
static int dnxhd_init_rc(DNXHDEncContext *ctx)
{
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry), fail);
if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD)
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry), fail);
ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8;
ctx->qscale = 1;
ctx->lambda = 2<<LAMBDA_FRAC_BITS; // qscale 2
return 0;
fail:
return -1;
}
static int dnxhd_encode_init(AVCodecContext *avctx)
{
DNXHDEncContext *ctx = avctx->priv_data;
int i, index;
ctx->cid = ff_dnxhd_find_cid(avctx);
if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) {
av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n");
return -1;
}
av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid);
index = ff_dnxhd_get_cid_table(ctx->cid);
ctx->cid_table = &ff_dnxhd_cid_table[index];
ctx->m.avctx = avctx;
ctx->m.mb_intra = 1;
ctx->m.h263_aic = 1;
ctx->get_pixels_8x4_sym = dnxhd_get_pixels_8x4;
dsputil_init(&ctx->m.dsp, avctx);
ff_dct_common_init(&ctx->m);
#if HAVE_MMX
ff_dnxhd_init_mmx(ctx);
#endif
if (!ctx->m.dct_quantize)
ctx->m.dct_quantize = dct_quantize_c;
ctx->m.mb_height = (avctx->height + 15) / 16;
ctx->m.mb_width = (avctx->width + 15) / 16;
if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {
ctx->interlaced = 1;
ctx->m.mb_height /= 2;
}
ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width;
if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)
ctx->m.intra_quant_bias = avctx->intra_quant_bias;
if (dnxhd_init_qmat(ctx, ctx->m.intra_quant_bias, 0) < 0) // XXX tune lbias/cbias
return -1;
if (dnxhd_init_vlc(ctx) < 0)
return -1;
if (dnxhd_init_rc(ctx) < 0)
return -1;
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_offs, ctx->m.mb_height*sizeof(uint32_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t), fail);
FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t) , fail);
ctx->frame.key_frame = 1;
ctx->frame.pict_type = FF_I_TYPE;
ctx->m.avctx->coded_frame = &ctx->frame;
if (avctx->thread_count > MAX_THREADS) {
av_log(avctx, AV_LOG_ERROR, "too many threads\n");
return -1;
}
ctx->thread[0] = ctx;
for (i = 1; i < avctx->thread_count; i++) {
ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext));
memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext));
}
return 0;
fail: //for FF_ALLOCZ_OR_GOTO
return -1;
}
static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf)
{
DNXHDEncContext *ctx = avctx->priv_data;
const uint8_t header_prefix[5] = { 0x00,0x00,0x02,0x80,0x01 };
memset(buf, 0, 640);
memcpy(buf, header_prefix, 5);
buf[5] = ctx->interlaced ? ctx->cur_field+2 : 0x01;
buf[6] = 0x80; // crc flag off
buf[7] = 0xa0; // reserved
AV_WB16(buf + 0x18, avctx->height); // ALPF
AV_WB16(buf + 0x1a, avctx->width); // SPL
AV_WB16(buf + 0x1d, avctx->height); // NAL
buf[0x21] = 0x38; // FIXME 8 bit per comp
buf[0x22] = 0x88 + (ctx->frame.interlaced_frame<<2);
AV_WB32(buf + 0x28, ctx->cid); // CID
buf[0x2c] = ctx->interlaced ? 0 : 0x80;
buf[0x5f] = 0x01; // UDL
buf[0x167] = 0x02; // reserved
AV_WB16(buf + 0x16a, ctx->m.mb_height * 4 + 4); // MSIPS
buf[0x16d] = ctx->m.mb_height; // Ns
buf[0x16f] = 0x10; // reserved
ctx->msip = buf + 0x170;
return 0;
}
static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
{
int nbits;
if (diff < 0) {
nbits = av_log2_16bit(-2*diff);
diff--;
} else {
nbits = av_log2_16bit(2*diff);
}
put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits,
(ctx->cid_table->dc_codes[nbits]<<nbits) + (diff & ((1 << nbits) - 1)));
}
static av_always_inline void dnxhd_encode_block(DNXHDEncContext *ctx, DCTELEM *block, int last_index, int n)
{
int last_non_zero = 0;
int slevel, i, j;
dnxhd_encode_dc(ctx, block[0] - ctx->m.last_dc[n]);
ctx->m.last_dc[n] = block[0];
for (i = 1; i <= last_index; i++) {
j = ctx->m.intra_scantable.permutated[i];
slevel = block[j];
if (slevel) {
int run_level = i - last_non_zero - 1;
int rlevel = (slevel<<1)|!!run_level;
put_bits(&ctx->m.pb, ctx->vlc_bits[rlevel], ctx->vlc_codes[rlevel]);
if (run_level)
put_bits(&ctx->m.pb, ctx->run_bits[run_level], ctx->run_codes[run_level]);
last_non_zero = i;
}
}
put_bits(&ctx->m.pb, ctx->vlc_bits[0], ctx->vlc_codes[0]); // EOB
}
static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, DCTELEM *block, int n, int qscale, int last_index)
{
const uint8_t *weight_matrix;
int level;
int i;
weight_matrix = (n&2) ? ctx->cid_table->chroma_weight : ctx->cid_table->luma_weight;
for (i = 1; i <= last_index; i++) {
int j = ctx->m.intra_scantable.permutated[i];
level = block[j];
if (level) {
if (level < 0) {
level = (1-2*level) * qscale * weight_matrix[i];
if (weight_matrix[i] != 32)
level += 32;
level >>= 6;
level = -level;
} else {
level = (2*level+1) * qscale * weight_matrix[i];
if (weight_matrix[i] != 32)
level += 32;
level >>= 6;
}
block[j] = level;
}
}
}
static av_always_inline int dnxhd_ssd_block(DCTELEM *qblock, DCTELEM *block)
{
int score = 0;
int i;
for (i = 0; i < 64; i++)
score += (block[i]-qblock[i])*(block[i]-qblock[i]);
return score;
}
static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, DCTELEM *block, int last_index)
{
int last_non_zero = 0;
int bits = 0;
int i, j, level;
for (i = 1; i <= last_index; i++) {
j = ctx->m.intra_scantable.permutated[i];
level = block[j];
if (level) {
int run_level = i - last_non_zero - 1;
bits += ctx->vlc_bits[(level<<1)|!!run_level]+ctx->run_bits[run_level];
last_non_zero = i;
}
}
return bits;
}
static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y)
{
const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << 4);
const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3);
const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3);
DSPContext *dsp = &ctx->m.dsp;
dsp->get_pixels(ctx->blocks[0], ptr_y , ctx->m.linesize);
dsp->get_pixels(ctx->blocks[1], ptr_y + 8, ctx->m.linesize);
dsp->get_pixels(ctx->blocks[2], ptr_u , ctx->m.uvlinesize);
dsp->get_pixels(ctx->blocks[3], ptr_v , ctx->m.uvlinesize);
if (mb_y+1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) {
if (ctx->interlaced) {
ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize);
ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize);
ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize);
ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize);
} else {
dsp->clear_block(ctx->blocks[4]); dsp->clear_block(ctx->blocks[5]);
dsp->clear_block(ctx->blocks[6]); dsp->clear_block(ctx->blocks[7]);
}
} else {
dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize);
dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize);
dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize);
dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize);
}
}
static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
{
if (i&2) {
ctx->m.q_intra_matrix16 = ctx->qmatrix_c16;
ctx->m.q_intra_matrix = ctx->qmatrix_c;
return 1 + (i&1);
} else {
ctx->m.q_intra_matrix16 = ctx->qmatrix_l16;
ctx->m.q_intra_matrix = ctx->qmatrix_l;
return 0;
}
}
static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
{
DNXHDEncContext *ctx = avctx->priv_data;
int mb_y = jobnr, mb_x;
int qscale = ctx->qscale;
LOCAL_ALIGNED_16(DCTELEM, block, [64]);
ctx = ctx->thread[threadnr];
ctx->m.last_dc[0] =
ctx->m.last_dc[1] =
ctx->m.last_dc[2] = 1024;
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
int ssd = 0;
int ac_bits = 0;
int dc_bits = 0;
int i;
dnxhd_get_blocks(ctx, mb_x, mb_y);
for (i = 0; i < 8; i++) {
DCTELEM *src_block = ctx->blocks[i];
int overflow, nbits, diff, last_index;
int n = dnxhd_switch_matrix(ctx, i);
memcpy(block, src_block, 64*sizeof(*block));
last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow);
ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index);
diff = block[0] - ctx->m.last_dc[n];
if (diff < 0) nbits = av_log2_16bit(-2*diff);
else nbits = av_log2_16bit( 2*diff);
dc_bits += ctx->cid_table->dc_bits[nbits] + nbits;
ctx->m.last_dc[n] = block[0];
if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) {
dnxhd_unquantize_c(ctx, block, i, qscale, last_index);
ctx->m.dsp.idct(block);
ssd += dnxhd_ssd_block(block, src_block);
}
}
ctx->mb_rc[qscale][mb].ssd = ssd;
ctx->mb_rc[qscale][mb].bits = ac_bits+dc_bits+12+8*ctx->vlc_bits[0];
}
return 0;
}
static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
{
DNXHDEncContext *ctx = avctx->priv_data;
int mb_y = jobnr, mb_x;
ctx = ctx->thread[threadnr];
init_put_bits(&ctx->m.pb, (uint8_t *)arg + 640 + ctx->slice_offs[jobnr], ctx->slice_size[jobnr]);
ctx->m.last_dc[0] =
ctx->m.last_dc[1] =
ctx->m.last_dc[2] = 1024;
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
int qscale = ctx->mb_qscale[mb];
int i;
put_bits(&ctx->m.pb, 12, qscale<<1);
dnxhd_get_blocks(ctx, mb_x, mb_y);
for (i = 0; i < 8; i++) {
DCTELEM *block = ctx->blocks[i];
int last_index, overflow;
int n = dnxhd_switch_matrix(ctx, i);
last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow);
//START_TIMER;
dnxhd_encode_block(ctx, block, last_index, n);
//STOP_TIMER("encode_block");
}
}
if (put_bits_count(&ctx->m.pb)&31)
put_bits(&ctx->m.pb, 32-(put_bits_count(&ctx->m.pb)&31), 0);
flush_put_bits(&ctx->m.pb);
return 0;
}
static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
{
int mb_y, mb_x;
int offset = 0;
for (mb_y = 0; mb_y < ctx->m.mb_height; mb_y++) {
int thread_size;
ctx->slice_offs[mb_y] = offset;
ctx->slice_size[mb_y] = 0;
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
ctx->slice_size[mb_y] += ctx->mb_bits[mb];
}
ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31;
ctx->slice_size[mb_y] >>= 3;
thread_size = ctx->slice_size[mb_y];
offset += thread_size;
}
}
static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
{
DNXHDEncContext *ctx = avctx->priv_data;
int mb_y = jobnr, mb_x;
ctx = ctx->thread[threadnr];
for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
unsigned mb = mb_y * ctx->m.mb_width + mb_x;
uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4);
int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize);
int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)(sum*sum))>>8)+128)>>8;
ctx->mb_cmp[mb].value = varc;
ctx->mb_cmp[mb].mb = mb;
}
return 0;
}
static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
{
int lambda, up_step, down_step;
int last_lower = INT_MAX, last_higher = 0;
int x, y, q;
for (q = 1; q < avctx->qmax; q++) {
ctx->qscale = q;
avctx->execute2(avctx, dnxhd_calc_bits_thread, NULL, NULL, ctx->m.mb_height);
}
up_step = down_step = 2<<LAMBDA_FRAC_BITS;
lambda = ctx->lambda;
for (;;) {
int bits = 0;
int end = 0;
if (lambda == last_higher) {
lambda++;
end = 1; // need to set final qscales/bits
}
for (y = 0; y < ctx->m.mb_height; y++) {
for (x = 0; x < ctx->m.mb_width; x++) {
unsigned min = UINT_MAX;
int qscale = 1;
int mb = y*ctx->m.mb_width+x;
for (q = 1; q < avctx->qmax; q++) {
unsigned score = ctx->mb_rc[q][mb].bits*lambda+(ctx->mb_rc[q][mb].ssd<<LAMBDA_FRAC_BITS);
if (score < min) {
min = score;
qscale = q;
}
}
bits += ctx->mb_rc[qscale][mb].bits;
ctx->mb_qscale[mb] = qscale;
ctx->mb_bits[mb] = ctx->mb_rc[qscale][mb].bits;
}
bits = (bits+31)&~31; // padding
if (bits > ctx->frame_bits)
break;
}
//dprintf(ctx->m.avctx, "lambda %d, up %u, down %u, bits %d, frame %d\n",
// lambda, last_higher, last_lower, bits, ctx->frame_bits);
if (end) {
if (bits > ctx->frame_bits)
return -1;
break;
}
if (bits < ctx->frame_bits) {
last_lower = FFMIN(lambda, last_lower);
if (last_higher != 0)
lambda = (lambda+last_higher)>>1;
else
lambda -= down_step;
down_step *= 5; // XXX tune ?
up_step = 1<<LAMBDA_FRAC_BITS;
lambda = FFMAX(1, lambda);
if (lambda == last_lower)
break;
} else {
last_higher = FFMAX(lambda, last_higher);
if (last_lower != INT_MAX)
lambda = (lambda+last_lower)>>1;
else if ((int64_t)lambda + up_step > INT_MAX)
return -1;
else
lambda += up_step;
up_step = FFMIN((int64_t)up_step*5, INT_MAX);
down_step = 1<<LAMBDA_FRAC_BITS;
}
}
//dprintf(ctx->m.avctx, "out lambda %d\n", lambda);
ctx->lambda = lambda;
return 0;
}
static int dnxhd_find_qscale(DNXHDEncContext *ctx)
{
int bits = 0;
int up_step = 1;
int down_step = 1;
int last_higher = 0;
int last_lower = INT_MAX;
int qscale;
int x, y;
qscale = ctx->qscale;
for (;;) {
bits = 0;
ctx->qscale = qscale;
// XXX avoid recalculating bits
ctx->m.avctx->execute2(ctx->m.avctx, dnxhd_calc_bits_thread, NULL, NULL, ctx->m.mb_height);
for (y = 0; y < ctx->m.mb_height; y++) {
for (x = 0; x < ctx->m.mb_width; x++)
bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits;
bits = (bits+31)&~31; // padding
if (bits > ctx->frame_bits)
break;
}
//dprintf(ctx->m.avctx, "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n",
// ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits, last_higher, last_lower);
if (bits < ctx->frame_bits) {
if (qscale == 1)
return 1;
if (last_higher == qscale - 1) {
qscale = last_higher;
break;
}
last_lower = FFMIN(qscale, last_lower);
if (last_higher != 0)
qscale = (qscale+last_higher)>>1;
else
qscale -= down_step++;
if (qscale < 1)
qscale = 1;
up_step = 1;
} else {
if (last_lower == qscale + 1)
break;
last_higher = FFMAX(qscale, last_higher);
if (last_lower != INT_MAX)
qscale = (qscale+last_lower)>>1;
else
qscale += up_step++;
down_step = 1;
if (qscale >= ctx->m.avctx->qmax)
return -1;
}
}
//dprintf(ctx->m.avctx, "out qscale %d\n", qscale);
ctx->qscale = qscale;
return 0;
}
#define BUCKET_BITS 8
#define RADIX_PASSES 4
#define NBUCKETS (1 << BUCKET_BITS)
static inline int get_bucket(int value, int shift)
{
value >>= shift;
value &= NBUCKETS - 1;
return NBUCKETS - 1 - value;
}
static void radix_count(const RCCMPEntry *data, int size, int buckets[RADIX_PASSES][NBUCKETS])
{
int i, j;
memset(buckets, 0, sizeof(buckets[0][0]) * RADIX_PASSES * NBUCKETS);
for (i = 0; i < size; i++) {
int v = data[i].value;
for (j = 0; j < RADIX_PASSES; j++) {
buckets[j][get_bucket(v, 0)]++;
v >>= BUCKET_BITS;
}
assert(!v);
}
for (j = 0; j < RADIX_PASSES; j++) {
int offset = size;
for (i = NBUCKETS - 1; i >= 0; i--)
buckets[j][i] = offset -= buckets[j][i];
assert(!buckets[j][0]);
}
}
static void radix_sort_pass(RCCMPEntry *dst, const RCCMPEntry *data, int size, int buckets[NBUCKETS], int pass)
{
int shift = pass * BUCKET_BITS;
int i;
for (i = 0; i < size; i++) {
int v = get_bucket(data[i].value, shift);
int pos = buckets[v]++;
dst[pos] = data[i];
}
}
static void radix_sort(RCCMPEntry *data, int size)
{
int buckets[RADIX_PASSES][NBUCKETS];
RCCMPEntry *tmp = av_malloc(sizeof(*tmp) * size);
radix_count(data, size, buckets);
radix_sort_pass(tmp, data, size, buckets[0], 0);
radix_sort_pass(data, tmp, size, buckets[1], 1);
if (buckets[2][NBUCKETS - 1] || buckets[3][NBUCKETS - 1]) {
radix_sort_pass(tmp, data, size, buckets[2], 2);
radix_sort_pass(data, tmp, size, buckets[3], 3);
}
av_free(tmp);
}
static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
{
int max_bits = 0;
int ret, x, y;
if ((ret = dnxhd_find_qscale(ctx)) < 0)
return -1;
for (y = 0; y < ctx->m.mb_height; y++) {
for (x = 0; x < ctx->m.mb_width; x++) {
int mb = y*ctx->m.mb_width+x;
int delta_bits;
ctx->mb_qscale[mb] = ctx->qscale;
ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale][mb].bits;
max_bits += ctx->mb_rc[ctx->qscale][mb].bits;
if (!RC_VARIANCE) {
delta_bits = ctx->mb_rc[ctx->qscale][mb].bits-ctx->mb_rc[ctx->qscale+1][mb].bits;
ctx->mb_cmp[mb].mb = mb;
ctx->mb_cmp[mb].value = delta_bits ?
((ctx->mb_rc[ctx->qscale][mb].ssd-ctx->mb_rc[ctx->qscale+1][mb].ssd)*100)/delta_bits
: INT_MIN; //avoid increasing qscale
}
}
max_bits += 31; //worst padding
}
if (!ret) {
if (RC_VARIANCE)
avctx->execute2(avctx, dnxhd_mb_var_thread, NULL, NULL, ctx->m.mb_height);
radix_sort(ctx->mb_cmp, ctx->m.mb_num);
for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) {
int mb = ctx->mb_cmp[x].mb;
max_bits -= ctx->mb_rc[ctx->qscale][mb].bits - ctx->mb_rc[ctx->qscale+1][mb].bits;
ctx->mb_qscale[mb] = ctx->qscale+1;
ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale+1][mb].bits;
}
}
return 0;
}
static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame)
{
int i;
for (i = 0; i < 3; i++) {
ctx->frame.data[i] = frame->data[i];
ctx->frame.linesize[i] = frame->linesize[i];
}
for (i = 0; i < ctx->m.avctx->thread_count; i++) {
ctx->thread[i]->m.linesize = ctx->frame.linesize[0]<<ctx->interlaced;
ctx->thread[i]->m.uvlinesize = ctx->frame.linesize[1]<<ctx->interlaced;
ctx->thread[i]->dct_y_offset = ctx->m.linesize *8;
ctx->thread[i]->dct_uv_offset = ctx->m.uvlinesize*8;
}
ctx->frame.interlaced_frame = frame->interlaced_frame;
ctx->cur_field = frame->interlaced_frame && !frame->top_field_first;
}
static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
{
DNXHDEncContext *ctx = avctx->priv_data;
int first_field = 1;
int offset, i, ret;
if (buf_size < ctx->cid_table->frame_size) {
av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
return -1;
}
dnxhd_load_picture(ctx, data);
encode_coding_unit:
for (i = 0; i < 3; i++) {
ctx->src[i] = ctx->frame.data[i];
if (ctx->interlaced && ctx->cur_field)
ctx->src[i] += ctx->frame.linesize[i];
}
dnxhd_write_header(avctx, buf);
if (avctx->mb_decision == FF_MB_DECISION_RD)
ret = dnxhd_encode_rdo(avctx, ctx);
else
ret = dnxhd_encode_fast(avctx, ctx);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR,
"picture could not fit ratecontrol constraints, increase qmax\n");
return -1;
}
dnxhd_setup_threads_slices(ctx);
offset = 0;
for (i = 0; i < ctx->m.mb_height; i++) {
AV_WB32(ctx->msip + i * 4, offset);
offset += ctx->slice_size[i];
assert(!(ctx->slice_size[i] & 3));
}
avctx->execute2(avctx, dnxhd_encode_thread, buf, NULL, ctx->m.mb_height);
assert(640 + offset + 4 <= ctx->cid_table->coding_unit_size);
memset(buf + 640 + offset, 0, ctx->cid_table->coding_unit_size - 4 - offset - 640);
AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF
if (ctx->interlaced && first_field) {
first_field = 0;
ctx->cur_field ^= 1;
buf += ctx->cid_table->coding_unit_size;
buf_size -= ctx->cid_table->coding_unit_size;
goto encode_coding_unit;
}
ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
return ctx->cid_table->frame_size;
}
static int dnxhd_encode_end(AVCodecContext *avctx)
{
DNXHDEncContext *ctx = avctx->priv_data;
int max_level = 1<<(ctx->cid_table->bit_depth+2);
int i;
av_free(ctx->vlc_codes-max_level*2);
av_free(ctx->vlc_bits -max_level*2);
av_freep(&ctx->run_codes);
av_freep(&ctx->run_bits);
av_freep(&ctx->mb_bits);
av_freep(&ctx->mb_qscale);
av_freep(&ctx->mb_rc);
av_freep(&ctx->mb_cmp);
av_freep(&ctx->slice_size);
av_freep(&ctx->slice_offs);
av_freep(&ctx->qmatrix_c);
av_freep(&ctx->qmatrix_l);
av_freep(&ctx->qmatrix_c16);
av_freep(&ctx->qmatrix_l16);
for (i = 1; i < avctx->thread_count; i++)
av_freep(&ctx->thread[i]);
return 0;
}
AVCodec dnxhd_encoder = {
"dnxhd",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_DNXHD,
sizeof(DNXHDEncContext),
dnxhd_encode_init,
dnxhd_encode_picture,
dnxhd_encode_end,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/dnxhdenc.c | C | asf20 | 29,916 |
/*
* Motion estimation
* Copyright (c) 2002-2004 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Motion estimation template.
*/
//Let us hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
#define LOAD_COMMON\
uint32_t av_unused * const score_map= c->score_map;\
const int av_unused xmin= c->xmin;\
const int av_unused ymin= c->ymin;\
const int av_unused xmax= c->xmax;\
const int av_unused ymax= c->ymax;\
uint8_t *mv_penalty= c->current_mv_penalty;\
const int pred_x= c->pred_x;\
const int pred_y= c->pred_y;\
#define CHECK_HALF_MV(dx, dy, x, y)\
{\
const int hx= 2*(x)+(dx);\
const int hy= 2*(y)+(dy);\
d= cmp_hpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
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 hpel_motion_search)(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
uint8_t *ref_data[3],
int size)
{
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= c->sub_penalty_factor;
LOAD_COMMON
// 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];
}
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= 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(c->skip){ //FIXME somehow move up (benchmark)
*mx_ptr = 0;
*my_ptr = 0;
return dmin;
}
if(c->avctx->me_cmp != c->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 hpel_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
int src_index, int ref_index,
int size, int h)
{
MotionEstContext * const c= &s->me;
const int mx = *mx_ptr;
const int my = *my_ptr;
const int penalty_factor= c->sub_penalty_factor;
me_cmp_func cmp_sub, chroma_cmp_sub;
int bx=2*mx, by=2*my;
LOAD_COMMON
int flags= c->sub_flags;
//FIXME factorize
cmp_sub= s->dsp.me_sub_cmp[size];
chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
if(c->skip){ //FIXME move out of hpel?
*mx_ptr = 0;
*my_ptr = 0;
return dmin;
}
if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
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])*c->penalty_factor;
const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
+ (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
+ (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->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])*c->penalty_factor;
#if 1
int key;
int map_generation= c->map_generation;
#ifndef NDEBUG
uint32_t *map= c->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 no_sub_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
int src_index, int ref_index,
int size, int h)
{
(*mx_ptr)<<=1;
(*my_ptr)<<=1;
return dmin;
}
inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
int ref_index, int size, int h, int add_rate)
{
// const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
MotionEstContext * const c= &s->me;
const int penalty_factor= c->mb_penalty_factor;
const int flags= c->mb_flags;
const int qpel= flags & FLAG_QPEL;
const int mask= 1+2*qpel;
me_cmp_func cmp_sub, chroma_cmp_sub;
int d;
LOAD_COMMON
//FIXME factorize
cmp_sub= s->dsp.mb_cmp[size];
chroma_cmp_sub= s->dsp.mb_cmp[size+1];
// assert(!c->skip);
// assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
//FIXME check cbp before adding penalty for (0,0) vector
if(add_rate && (mx || my || size>0))
d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
return d;
}
#define CHECK_QUARTER_MV(dx, dy, x, y)\
{\
const int hx= 4*(x)+(dx);\
const int hy= 4*(y)+(dy);\
d= cmp_qpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}
static int qpel_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
int src_index, int ref_index,
int size, int h)
{
MotionEstContext * const c= &s->me;
const int mx = *mx_ptr;
const int my = *my_ptr;
const int penalty_factor= c->sub_penalty_factor;
const int map_generation= c->map_generation;
const int subpel_quality= c->avctx->me_subpel_quality;
uint32_t *map= c->map;
me_cmp_func cmpf, chroma_cmpf;
me_cmp_func cmp_sub, chroma_cmp_sub;
LOAD_COMMON
int flags= c->sub_flags;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= 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(c->skip){ //FIXME somehow move up (benchmark)
*mx_ptr = 0;
*my_ptr = 0;
return dmin;
}
if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
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++){
//FIXME this could overflow (unlikely though)
const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
const int64_t 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 + 512)>>10;
int i;
if((nx&3)==0 && (ny&3)==0) continue;
score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
// if(nx&1) score-=1024*c->penalty_factor;
// if(ny&1) score-=1024*c->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;
//FIXME this could overflow (unlikely though)
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{
tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);//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++){
//FIXME this could overflow (unlikely though)
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*c->penalty_factor;
// if(ny&1) score-=32*c->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;
}
#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);\
assert((x) >= xmin);\
assert((x) <= xmax);\
assert((y) >= ymin);\
assert((y) <= ymax);\
/*printf("check_mv %d %d\n", x, y);*/\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
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_CLIPPED_MV(ax,ay)\
{\
const int Lx= ax;\
const int Ly= ay;\
const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
CHECK_MV(Lx2, Ly2)\
}
#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){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
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);\
#define LOAD_COMMON2\
uint32_t *map= c->map;\
const int qpel= flags&FLAG_QPEL;\
const int shift= 1+qpel;\
static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
int next_dir=-1;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= 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
score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
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 int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
int dia_size;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= 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= FFABS(x-best[0]);
dy= FFABS(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;
}
static int hex_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags, int dia_size)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y,d;
const int dec= dia_size & (dia_size-1);
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
do{
x= best[0];
y= best[1];
CHECK_CLIPPED_MV(x -dia_size , y);
CHECK_CLIPPED_MV(x+ dia_size , y);
CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
if(dia_size>1){
CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
}
}while(best[0] != x || best[1] != y);
}
return dmin;
}
static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y,i,d;
int dia_size= c->dia_size&0xFF;
const int dec= dia_size & (dia_size-1);
static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},
{ 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
do{
x= best[0];
y= best[1];
for(i=0; i<8; i++){
CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);
}
}while(best[0] != x || best[1] != y);
}
x= best[0];
y= best[1];
CHECK_CLIPPED_MV(x+1, y);
CHECK_CLIPPED_MV(x, y+1);
CHECK_CLIPPED_MV(x-1, y);
CHECK_CLIPPED_MV(x, y-1);
return dmin;
}
static int umh_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y,x2,y2, i, j, d;
const int dia_size= c->dia_size&0xFE;
static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
{ 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
{-2, 3}, { 0, 4}, { 2, 3},
{-2,-3}, { 0,-4}, { 2,-3},};
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
x= best[0];
y= best[1];
for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){
CHECK_MV(x2, y);
}
for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){
CHECK_MV(x, y2);
}
x= best[0];
y= best[1];
for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
CHECK_MV(x2, y2);
}
}
//FIXME prevent the CLIP stuff
for(j=1; j<=dia_size/4; j++){
for(i=0; i<16; i++){
CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
}
}
return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);
}
static int full_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y, d;
const int dia_size= c->dia_size&0xFF;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
CHECK_MV(x, y);
}
}
x= best[0];
y= best[1];
d= dmin;
CHECK_CLIPPED_MV(x , y);
CHECK_CLIPPED_MV(x+1, y);
CHECK_CLIPPED_MV(x, y+1);
CHECK_CLIPPED_MV(x-1, y);
CHECK_CLIPPED_MV(x, y-1);
best[0]= x;
best[1]= y;
return d;
}
#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){\
d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
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 ME_MAP_SIZE
static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
Minima minima[MAX_SAB_SIZE];
const int minima_count= FFABS(c->dia_size);
int i, j;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
/*Note j<MAX_SAB_SIZE is needed if MAX_SAB_SIZE < ME_MAP_SIZE as j can
become larger due to MVs overflowing their ME_MAP_MV_BITS bits space in map
*/
for(j=i=0; i<ME_MAP_SIZE && j<MAX_SAB_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;
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));
// all entries in map should be in range except if the mv overflows their ME_MAP_MV_BITS bits space
if( minima[j].x > xmax || minima[j].x < xmin
|| minima[j].y > ymax || minima[j].y < ymin)
continue;
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 int var_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
int dia_size;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(dia_size=1; dia_size<=c->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= FFABS(x-best[0]);
dy= FFABS(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 av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags){
MotionEstContext * const c= &s->me;
if(c->dia_size==-1)
return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else if(c->dia_size<-1)
return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else if(c->dia_size<2)
return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else if(c->dia_size>1024)
return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else if(c->dia_size>768)
return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else if(c->dia_size>512)
return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);
else if(c->dia_size>256)
return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
else
return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
}
/*!
\param P[10][2] a list of candidate mvs to check before starting the
iterative search. If one of the candidates is close to the optimal mv, then
it takes fewer iterations. And it increases the chance that we find the
optimal mv.
*/
static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
int ref_mv_scale, int flags, int size, int h)
{
MotionEstContext * const c= &s->me;
int best[2]={0, 0}; /*!< x and y coordinates of the best motion vector.
i.e. the difference between the position of the
block currently being encoded and the position of
the block chosen to predict it from. */
int d; ///< the score (cmp + penalty) of any given mv
int dmin; /*!< the best value of d, i.e. the score
corresponding to the mv stored in best[]. */
int map_generation;
int penalty_factor;
const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
if(c->pre_pass){
penalty_factor= c->pre_penalty_factor;
cmpf= s->dsp.me_pre_cmp[size];
chroma_cmpf= s->dsp.me_pre_cmp[size+1];
}else{
penalty_factor= c->penalty_factor;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
}
map_generation= update_map_generation(c);
assert(cmpf);
dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
map[0]= map_generation;
score_map[0]= dmin;
//FIXME precalc first term below?
if((s->pict_type == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)
dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;
/* first line */
if (s->first_slice_line) {
CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
CHECK_CLIPPED_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<((h*h*s->avctx->mv0_threshold)>>8)
&& ( 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;
c->skip=1;
return dmin;
}
CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)
CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)
CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)
CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )
CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )
CHECK_CLIPPED_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>h*h*4){
if(c->pre_pass){
CHECK_CLIPPED_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)
if(!s->first_slice_line)
CHECK_CLIPPED_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_CLIPPED_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)
if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
CHECK_CLIPPED_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(c->avctx->last_predictor_count){
const int count= c->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)
dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
//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;
}
//this function is dedicated to the braindamaged gcc
inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
int ref_mv_scale, int size, int h)
{
MotionEstContext * const c= &s->me;
//FIXME convert other functions in the same way if faster
if(c->flags==0 && h==16 && size==0){
return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
// case FLAG_QPEL:
// return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
}else{
return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
}
}
static int epzs_motion_search4(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int P[10][2],
int src_index, int ref_index, int16_t (*last_mv)[2],
int ref_mv_scale)
{
MotionEstContext * const c= &s->me;
int best[2]={0, 0};
int d, dmin;
int map_generation;
const int penalty_factor= c->penalty_factor;
const int size=1;
const int h=8;
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 cmpf, chroma_cmpf;
LOAD_COMMON
int flags= c->flags;
LOAD_COMMON2
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
map_generation= update_map_generation(c);
dmin = 1000000;
//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
/* first line */
if (s->first_slice_line) {
CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
CHECK_CLIPPED_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
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_CLIPPED_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_CLIPPED_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)
if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
CHECK_CLIPPED_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)
}
dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
*mx_ptr= best[0];
*my_ptr= best[1];
// printf("%d %d %d \n", best[0], best[1], dmin);
return dmin;
}
//try to merge with above FIXME (needs PSNR test)
static int epzs_motion_search2(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int P[10][2],
int src_index, int ref_index, int16_t (*last_mv)[2],
int ref_mv_scale)
{
MotionEstContext * const c= &s->me;
int best[2]={0, 0};
int d, dmin;
int map_generation;
const int penalty_factor= c->penalty_factor;
const int size=0; //FIXME pass as arg
const int h=8;
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 cmpf, chroma_cmpf;
LOAD_COMMON
int flags= c->flags;
LOAD_COMMON2
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
map_generation= update_map_generation(c);
dmin = 1000000;
//printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
/* first line */
if (s->first_slice_line) {
CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
CHECK_CLIPPED_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
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_CLIPPED_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_CLIPPED_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)
if(s->mb_y+1<s->end_mb_y) //FIXME replace at least with last_slice_line
CHECK_CLIPPED_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)
}
dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
*mx_ptr= best[0];
*my_ptr= best[1];
// printf("%d %d %d \n", best[0], best[1], dmin);
return dmin;
}
| 123linslouis-android-video-cutter | jni/libavcodec/motion_est_template.c | C | asf20 | 45,537 |
/*
* H.26L/H.264/AVC/JVT/14496-10/... cavlc bitstream decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* H.264 / AVC / MPEG4 part10 cavlc bitstream decoding.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#define CABAC 0
#include "internal.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "h264.h"
#include "h264data.h" // FIXME FIXME FIXME
#include "h264_mvpred.h"
#include "golomb.h"
//#undef NDEBUG
#include <assert.h>
static const uint8_t golomb_to_inter_cbp_gray[16]={
0, 1, 2, 4, 8, 3, 5,10,12,15, 7,11,13,14, 6, 9,
};
static const uint8_t golomb_to_intra4x4_cbp_gray[16]={
15, 0, 7,11,13,14, 3, 5,10,12, 1, 2, 4, 8, 6, 9,
};
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},
};
static VLC coeff_token_vlc[4];
static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2];
static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
static VLC chroma_dc_coeff_token_vlc;
static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
static const int chroma_dc_coeff_token_vlc_table_size = 256;
static VLC total_zeros_vlc[15];
static VLC_TYPE total_zeros_vlc_tables[15][512][2];
static const int total_zeros_vlc_tables_size = 512;
static VLC chroma_dc_total_zeros_vlc[3];
static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
static const int chroma_dc_total_zeros_vlc_tables_size = 8;
static VLC run_vlc[6];
static VLC_TYPE run_vlc_tables[6][8][2];
static const int run_vlc_tables_size = 8;
static VLC run7_vlc;
static VLC_TYPE run7_vlc_table[96][2];
static const int run7_vlc_table_size = 96;
#define LEVEL_TAB_BITS 8
static int8_t cavlc_level_tab[7][1<<LEVEL_TAB_BITS][2];
/**
* 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(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31);
return i&31;
}
static av_cold void init_cavlc_level_tab(void){
int suffix_length, mask;
unsigned int i;
for(suffix_length=0; suffix_length<7; suffix_length++){
for(i=0; i<(1<<LEVEL_TAB_BITS); i++){
int prefix= LEVEL_TAB_BITS - av_log2(2*i);
int level_code= (prefix<<suffix_length) + (i>>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<<suffix_length);
mask= -(level_code&1);
level_code= (((2+level_code)>>1) ^ mask) - mask;
if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){
cavlc_level_tab[suffix_length][i][0]= level_code;
cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length;
}else if(prefix + 1 <= LEVEL_TAB_BITS){
cavlc_level_tab[suffix_length][i][0]= prefix+100;
cavlc_level_tab[suffix_length][i][1]= prefix + 1;
}else{
cavlc_level_tab[suffix_length][i][0]= LEVEL_TAB_BITS+100;
cavlc_level_tab[suffix_length][i][1]= LEVEL_TAB_BITS;
}
}
}
}
av_cold void ff_h264_decode_init_vlc(void){
static int done = 0;
if (!done) {
int i;
int offset;
done = 1;
chroma_dc_coeff_token_vlc.table = chroma_dc_coeff_token_vlc_table;
chroma_dc_coeff_token_vlc.table_allocated = chroma_dc_coeff_token_vlc_table_size;
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,
INIT_VLC_USE_NEW_STATIC);
offset = 0;
for(i=0; i<4; i++){
coeff_token_vlc[i].table = coeff_token_vlc_tables+offset;
coeff_token_vlc[i].table_allocated = coeff_token_vlc_tables_size[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,
INIT_VLC_USE_NEW_STATIC);
offset += coeff_token_vlc_tables_size[i];
}
/*
* This is a one time safety check to make sure that
* the packed static coeff_token_vlc table sizes
* were initialized correctly.
*/
assert(offset == FF_ARRAY_ELEMS(coeff_token_vlc_tables));
for(i=0; i<3; i++){
chroma_dc_total_zeros_vlc[i].table = chroma_dc_total_zeros_vlc_tables[i];
chroma_dc_total_zeros_vlc[i].table_allocated = chroma_dc_total_zeros_vlc_tables_size;
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,
INIT_VLC_USE_NEW_STATIC);
}
for(i=0; i<15; i++){
total_zeros_vlc[i].table = total_zeros_vlc_tables[i];
total_zeros_vlc[i].table_allocated = total_zeros_vlc_tables_size;
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,
INIT_VLC_USE_NEW_STATIC);
}
for(i=0; i<6; i++){
run_vlc[i].table = run_vlc_tables[i];
run_vlc[i].table_allocated = run_vlc_tables_size;
init_vlc(&run_vlc[i],
RUN_VLC_BITS, 7,
&run_len [i][0], 1, 1,
&run_bits[i][0], 1, 1,
INIT_VLC_USE_NEW_STATIC);
}
run7_vlc.table = run7_vlc_table,
run7_vlc.table_allocated = run7_vlc_table_size;
init_vlc(&run7_vlc, RUN7_VLC_BITS, 16,
&run_len [6][0], 1, 1,
&run_bits[6][0], 1, 1,
INIT_VLC_USE_NEW_STATIC);
init_cavlc_level_tab();
}
}
/**
*
*/
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);
av_log(NULL, AV_LOG_DEBUG, "%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 occurred
*/
static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){
MpegEncContext * const s = &h->s;
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];
int zeros_left, coeff_num, coeff_token, total_coeff, i, j, trailing_ones, run_before;
//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;
if(total_coeff > (unsigned)max_coeff) {
av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff);
return -1;
}
trailing_ones= coeff_token&3;
tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff);
assert(total_coeff<=16);
i = show_bits(gb, 3);
skip_bits(gb, trailing_ones);
level[0] = 1-((i&4)>>1);
level[1] = 1-((i&2) );
level[2] = 1-((i&1)<<1);
if(trailing_ones<total_coeff) {
int mask, prefix;
int suffix_length = total_coeff > 10 & trailing_ones < 3;
int bitsi= show_bits(gb, LEVEL_TAB_BITS);
int level_code= cavlc_level_tab[suffix_length][bitsi][0];
skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
if(level_code >= 100){
prefix= level_code - 100;
if(prefix == LEVEL_TAB_BITS)
prefix += get_level_prefix(gb);
//first coefficient has suffix_length equal to 0 or 1
if(prefix<14){ //FIXME try to build a large unified VLC table for all this
if(suffix_length)
level_code= (prefix<<1) + get_bits1(gb); //part
else
level_code= prefix; //part
}else if(prefix==14){
if(suffix_length)
level_code= (prefix<<1) + get_bits1(gb); //part
else
level_code= prefix + get_bits(gb, 4); //part
}else{
level_code= 30 + get_bits(gb, prefix-3); //part
if(prefix>=16){
if(prefix > 25+3){
av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n");
return -1;
}
level_code += (1<<(prefix-3))-4096;
}
}
if(trailing_ones < 3) level_code += 2;
suffix_length = 2;
mask= -(level_code&1);
level[trailing_ones]= (((2+level_code)>>1) ^ mask) - mask;
}else{
level_code += ((level_code>>31)|1) & -(trailing_ones < 3);
suffix_length = 1 + (level_code + 3U > 6U);
level[trailing_ones]= level_code;
}
//remaining coefficients have suffix_length > 0
for(i=trailing_ones+1;i<total_coeff;i++) {
static const unsigned int suffix_limit[7] = {0,3,6,12,24,48,INT_MAX };
int bitsi= show_bits(gb, LEVEL_TAB_BITS);
level_code= cavlc_level_tab[suffix_length][bitsi][0];
skip_bits(gb, cavlc_level_tab[suffix_length][bitsi][1]);
if(level_code >= 100){
prefix= level_code - 100;
if(prefix == LEVEL_TAB_BITS){
prefix += get_level_prefix(gb);
}
if(prefix<15){
level_code = (prefix<<suffix_length) + get_bits(gb, suffix_length);
}else{
level_code = (15<<suffix_length) + get_bits(gb, prefix-3);
if(prefix>=16)
level_code += (1<<(prefix-3))-4096;
}
mask= -(level_code&1);
level_code= (((2+level_code)>>1) ^ mask) - mask;
}
level[i]= level_code;
suffix_length+= suffix_limit[suffix_length] + level_code > 2U*suffix_limit[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-1)[ total_coeff ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1);
else
zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1);
}
coeff_num = zeros_left + total_coeff - 1;
j = scantable[coeff_num];
if(n > 24){
block[j] = level[0];
for(i=1;i<total_coeff;i++) {
if(zeros_left <= 0)
run_before = 0;
else if(zeros_left < 7){
run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
}else{
run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
}
zeros_left -= run_before;
coeff_num -= 1 + run_before;
j= scantable[ coeff_num ];
block[j]= level[i];
}
}else{
block[j] = (level[0] * qmul[j] + 32)>>6;
for(i=1;i<total_coeff;i++) {
if(zeros_left <= 0)
run_before = 0;
else if(zeros_left < 7){
run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1);
}else{
run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2);
}
zeros_left -= run_before;
coeff_num -= 1 + run_before;
j= scantable[ coeff_num ];
block[j]= (level[i] * qmul[j] + 32)>>6;
}
}
if(zeros_left<0){
av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
return 0;
}
int ff_h264_decode_mb_cavlc(H264Context *h){
MpegEncContext * const s = &h->s;
int mb_xy;
int partition_count;
unsigned int mb_type, cbp;
int dct8x8_allowed= h->pps.transform_8x8_mode;
mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;
tprintf(s->avctx, "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_nos != FF_I_TYPE){
if(s->mb_skip_run==-1)
s->mb_skip_run= get_ue_golomb(&s->gb);
if (s->mb_skip_run--) {
if(FRAME_MBAFF && (s->mb_y&1) == 0){
if(s->mb_skip_run==0)
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
}
decode_mb_skip(h);
return 0;
}
}
if(FRAME_MBAFF){
if( (s->mb_y&1) == 0 )
h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);
}
h->prev_mb_skipped= 0;
mb_type= get_ue_golomb(&s->gb);
if(h->slice_type_nos == FF_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_nos == FF_P_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_nos == FF_I_TYPE);
if(h->slice_type == FF_SI_TYPE && mb_type)
mb_type--;
decode_intra_mb:
if(mb_type > 25){
av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too 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(MB_FIELD)
mb_type |= MB_TYPE_INTERLACED;
h->slice_table[ mb_xy ]= h->slice_num;
if(IS_INTRA_PCM(mb_type)){
unsigned int x;
// We assume these blocks are very rare so we do not optimize it.
align_get_bits(&s->gb);
// The pixels are stored in the same order as levels in h->mb array.
for(x=0; x < (CHROMA ? 384 : 256); x++){
((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);
}
// In deblocking, the quantizer is 0
s->current_picture.qscale_table[mb_xy]= 0;
// All coeffs are present
memset(h->non_zero_count[mb_xy], 16, 32);
s->current_picture.mb_type[mb_xy]= mb_type;
return 0;
}
if(MB_MBAFF){
h->ref_count[0] <<= 1;
h->ref_count[1] <<= 1;
}
fill_decode_neighbors(h, mb_type);
fill_decode_caches(h, mb_type);
//mb_pred
if(IS_INTRA(mb_type)){
int pred_mode;
// init_top_left_availability(h);
if(IS_INTRA4x4(mb_type)){
int i;
int di = 1;
if(dct8x8_allowed && get_bits1(&s->gb)){
mb_type |= MB_TYPE_8x8DCT;
di = 4;
}
// fill_intra4x4_pred_table(h);
for(i=0; i<16; i+=di){
int mode= pred_intra_mode(h, i);
if(!get_bits1(&s->gb)){
const int rem_mode= get_bits(&s->gb, 3);
mode = rem_mode + (rem_mode >= mode);
}
if(di==4)
fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );
else
h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;
}
ff_h264_write_back_intra_pred_mode(h);
if( ff_h264_check_intra4x4_pred_mode(h) < 0)
return -1;
}else{
h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode);
if(h->intra16x16_pred_mode < 0)
return -1;
}
if(CHROMA){
pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));
if(pred_mode < 0)
return -1;
h->chroma_pred_mode= pred_mode;
}
}else if(partition_count==4){
int i, j, sub_partition_count[4], list, ref[2][4];
if(h->slice_type_nos == FF_B_TYPE){
for(i=0; i<4; i++){
h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
if(h->sub_mb_type[i] >=13){
av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u 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;
}
if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) {
ff_h264_pred_direct_motion(h, &mb_type);
h->ref_cache[0][scan8[4]] =
h->ref_cache[1][scan8[4]] =
h->ref_cache[0][scan8[12]] =
h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;
}
}else{
assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ?
for(i=0; i<4; i++){
h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);
if(h->sub_mb_type[i] >=4){
av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u 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<h->list_count; list++){
int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];
for(i=0; i<4; i++){
if(IS_DIRECT(h->sub_mb_type[i])) continue;
if(IS_DIR(h->sub_mb_type[i], 0, list)){
unsigned int tmp;
if(ref_count == 1){
tmp= 0;
}else if(ref_count == 2){
tmp= get_bits1(&s->gb)^1;
}else{
tmp= get_ue_golomb_31(&s->gb);
if(tmp>=ref_count){
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp);
return -1;
}
}
ref[list][i]= tmp;
}else{
//FIXME
ref[list][i] = -1;
}
}
}
if(dct8x8_allowed)
dct8x8_allowed = get_dct8x8_allowed(h);
for(list=0; list<h->list_count; list++){
for(i=0; i<4; i++){
if(IS_DIRECT(h->sub_mb_type[i])) {
h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ];
continue;
}
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)){
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(s->avctx, "final mv:%d %d\n", mx, my);
if(IS_SUB_8X8(sub_mb_type)){
mv_cache[ 1 ][0]=
mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
mv_cache[ 1 ][1]=
mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
}else if(IS_SUB_8X4(sub_mb_type)){
mv_cache[ 1 ][0]= mx;
mv_cache[ 1 ][1]= my;
}else if(IS_SUB_4X8(sub_mb_type)){
mv_cache[ 8 ][0]= mx;
mv_cache[ 8 ][1]= my;
}
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)){
ff_h264_pred_direct_motion(h, &mb_type);
dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
}else{
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<h->list_count; list++){
unsigned int val;
if(IS_DIR(mb_type, 0, list)){
if(h->ref_count[list]==1){
val= 0;
}else if(h->ref_count[list]==2){
val= get_bits1(&s->gb)^1;
}else{
val= get_ue_golomb_31(&s->gb);
if(val >= h->ref_count[list]){
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
return -1;
}
}
fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);
}
}
for(list=0; list<h->list_count; 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(s->avctx, "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<h->list_count; list++){
for(i=0; i<2; i++){
unsigned int val;
if(IS_DIR(mb_type, i, list)){
if(h->ref_count[list] == 1){
val= 0;
}else if(h->ref_count[list] == 2){
val= get_bits1(&s->gb)^1;
}else{
val= get_ue_golomb_31(&s->gb);
if(val >= h->ref_count[list]){
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
return -1;
}
}
}else
val= LIST_NOT_USED&0xFF;
fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);
}
}
for(list=0; list<h->list_count; list++){
for(i=0; i<2; i++){
unsigned int val;
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(s->avctx, "final mv:%d %d\n", mx, my);
val= pack16to32(mx,my);
}else
val=0;
fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);
}
}
}else{
assert(IS_8X16(mb_type));
for(list=0; list<h->list_count; list++){
for(i=0; i<2; i++){
unsigned int val;
if(IS_DIR(mb_type, i, list)){ //FIXME optimize
if(h->ref_count[list]==1){
val= 0;
}else if(h->ref_count[list]==2){
val= get_bits1(&s->gb)^1;
}else{
val= get_ue_golomb_31(&s->gb);
if(val >= h->ref_count[list]){
av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val);
return -1;
}
}
}else
val= LIST_NOT_USED&0xFF;
fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);
}
}
for(list=0; list<h->list_count; list++){
for(i=0; i<2; i++){
unsigned int val;
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(s->avctx, "final mv:%d %d\n", mx, my);
val= pack16to32(mx,my);
}else
val=0;
fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 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){
av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y);
return -1;
}
if(CHROMA){
if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];
else cbp= golomb_to_inter_cbp [cbp];
}else{
if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];
else cbp= golomb_to_inter_cbp_gray[cbp];
}
}
if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){
mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb);
}
h->cbp=
h->cbp_table[mb_xy]= cbp;
s->current_picture.mb_type[mb_xy]= mb_type;
if(cbp || IS_INTRA16x16(mb_type)){
int i8x8, i4x4, chroma_idx;
int dquant;
GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;
const uint8_t *scan, *scan8x8, *dc_scan;
if(IS_INTERLACED(mb_type)){
scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;
scan= s->qscale ? h->field_scan : h->field_scan_q0;
dc_scan= luma_dc_field_scan;
}else{
scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;
scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;
dc_scan= luma_dc_zigzag_scan;
}
dquant= get_se_golomb(&s->gb);
s->qscale += dquant;
if(((unsigned)s->qscale) > 51){
if(s->qscale<0) s->qscale+= 52;
else s->qscale-= 52;
if(((unsigned)s->qscale) > 51){
av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y);
return -1;
}
}
h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);
h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);
if(IS_INTRA16x16(mb_type)){
if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
return -1; //FIXME continue if partitioned and other return -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, h->dequant4_coeff[0][s->qscale], 15) < 0 ){
return -1;
}
}
}
}else{
fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);
}
}else{
for(i8x8=0; i8x8<4; i8x8++){
if(cbp & (1<<i8x8)){
if(IS_8x8DCT(mb_type)){
DCTELEM *buf = &h->mb[64*i8x8];
uint8_t *nnz;
for(i4x4=0; i4x4<4; i4x4++){
if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4,
h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 )
return -1;
}
nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];
nnz[0] += nnz[1] + nnz[8] + nnz[9];
}else{
for(i4x4=0; i4x4<4; i4x4++){
const int index= i4x4 + 4*i8x8;
if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][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, NULL, 4) < 0){
return -1;
}
}
if(cbp&0x20){
for(chroma_idx=0; chroma_idx<2; chroma_idx++){
const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[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, qmul, 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{
uint8_t * const nnz= &h->non_zero_count_cache[0];
fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);
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;
}
s->current_picture.qscale_table[mb_xy]= s->qscale;
write_back_non_zero_count(h);
if(MB_MBAFF){
h->ref_count[0] >>= 1;
h->ref_count[1] >>= 1;
}
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/h264_cavlc.c | C | asf20 | 38,018 |
/*
* ITU H263 bitstream encoder
* Copyright (c) 2000,2001 Fabrice Bellard
* H263+ support.
* Copyright (c) 2001 Juan J. Sierralta P
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* h263 bitstream encoder.
*/
//#define DEBUG
#include <limits.h>
#include "dsputil.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "h263.h"
#include "mathops.h"
#include "unary.h"
#include "flv.h"
#include "mpeg4video.h"
#include "internal.h"
//#undef NDEBUG
//#include <assert.h>
/**
* Table of number of bits a motion vector component needs.
*/
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
/**
* Minimal fcode that a motion vector component would need.
*/
static uint8_t fcode_tab[MAX_MV*2+1];
/**
* Minimal fcode that a motion vector component would need in umv.
* All entries in this table are 1.
*/
static uint8_t umv_fcode_tab[MAX_MV*2+1];
//unified encoding tables for run length encoding of coefficients
//unified in the sense that the specification specifies the encoding in several steps.
static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2];
static uint8_t uni_h263_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))
static const uint8_t wrong_run[102] = {
1, 2, 3, 5, 4, 10, 9, 8,
11, 15, 17, 16, 23, 22, 21, 20,
19, 18, 25, 24, 27, 26, 11, 7,
6, 1, 2, 13, 2, 2, 2, 2,
6, 12, 3, 9, 1, 3, 4, 3,
7, 4, 1, 1, 5, 5, 14, 6,
1, 7, 1, 8, 1, 1, 1, 1,
10, 1, 1, 5, 9, 17, 25, 24,
29, 33, 32, 41, 2, 23, 28, 31,
3, 22, 30, 4, 27, 40, 8, 26,
6, 39, 7, 38, 16, 37, 15, 10,
11, 12, 13, 14, 1, 21, 20, 18,
19, 2, 1, 34, 35, 36
};
/**
* Returns the 4 bit value that specifies the given aspect ratio.
* This may be one of the standard aspect ratios or it specifies
* that the aspect will be stored explicitly later.
*/
av_const int ff_h263_aspect_to_info(AVRational aspect){
int i;
if(aspect.num==0) aspect= (AVRational){1,1};
for(i=1; i<6; i++){
if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){
return i;
}
}
return FF_ASPECT_EXTENDED;
}
void h263_encode_picture_header(MpegEncContext * s, int picture_number)
{
int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
int best_clock_code=1;
int best_divisor=60;
int best_error= INT_MAX;
if(s->h263_plus){
for(i=0; i<2; i++){
int div, error;
div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den);
div= av_clip(div, 1, 127);
error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
if(error < best_error){
best_error= error;
best_divisor= div;
best_clock_code= i;
}
}
}
s->custom_pcf= best_clock_code!=1 || best_divisor!=60;
coded_frame_rate= 1800000;
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
align_put_bits(&s->pb);
/* Update the pointer to last GOB */
s->ptr_lastgob = put_bits_ptr(&s->pb);
put_bits(&s->pb, 22, 0x20); /* PSC */
temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp
(coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */
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 = ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_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 == FF_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, s->obmc); /* Advanced Prediction */
put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */
put_bits(&s->pb, 5, s->qscale);
put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
} else {
int ufep=1;
/* H.263v2 */
/* H.263 Plus PTYPE */
put_bits(&s->pb, 3, 7);
put_bits(&s->pb,3,ufep); /* 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, s->custom_pcf);
put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
put_bits(&s->pb,1,0); /* SAC: off */
put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
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,s->alt_inter_vlc); /* Alternative Inter VLC */
put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */
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 == FF_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) */
s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_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->avctx->sample_aspect_ratio.num);
put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
}
}
if(s->custom_pcf){
if(ufep){
put_bits(&s->pb, 1, best_clock_code);
put_bits(&s->pb, 7, best_divisor);
}
put_sbits(&s->pb, 2, temp_ref>>8);
}
/* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
if (s->umvplus)
// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
//FIXME check actual requested range
put_bits(&s->pb,2,1); /* unlimited */
if(s->h263_slice_structured)
put_bits(&s->pb,2,0); /* no weird submodes */
put_bits(&s->pb, 5, s->qscale);
}
put_bits(&s->pb, 1, 0); /* no PEI */
if(s->h263_slice_structured){
put_bits(&s->pb, 1, 1);
assert(s->mb_x == 0 && s->mb_y == 0);
ff_h263_encode_mba(s);
put_bits(&s->pb, 1, 1);
}
if(s->h263_aic){
s->y_dc_scale_table=
s->c_dc_scale_table= ff_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.
*/
void h263_encode_gob_header(MpegEncContext * s, int mb_line)
{
put_bits(&s->pb, 17, 1); /* GBSC */
if(s->h263_slice_structured){
put_bits(&s->pb, 1, 1);
ff_h263_encode_mba(s);
if(s->mb_num > 1583)
put_bits(&s->pb, 1, 1);
put_bits(&s->pb, 5, s->qscale); /* GQUANT */
put_bits(&s->pb, 1, 1);
put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */
}else{
int gob_number= mb_line / s->gob_index;
put_bits(&s->pb, 5, gob_number); /* GN */
put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */
put_bits(&s->pb, 5, s->qscale); /* GQUANT */
}
}
/**
* 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;
ff_init_qscale_tab(s);
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;
}
if(s->codec_id != CODEC_ID_H263P){
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]&CANDIDATE_MB_TYPE_INTER4V)){
s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER;
}
}
}
}
static const int dquant_code[5]= {1,0,9,2,3};
/**
* 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 = &ff_h263_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);
i = 1;
} else {
i = 0;
if (s->h263_aic && s->mb_intra)
rl = &rl_intra_aic;
if(s->alt_inter_vlc && !s->mb_intra){
int aic_vlc_bits=0;
int inter_vlc_bits=0;
int wrong_pos=-1;
int aic_code;
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);
if(level<0) level= -level;
code = get_rl_index(rl, last, run, level);
aic_code = get_rl_index(&rl_intra_aic, last, run, level);
inter_vlc_bits += rl->table_vlc[code][1]+1;
aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1;
if (code == rl->n) {
inter_vlc_bits += 1+6+8-1;
}
if (aic_code == rl_intra_aic.n) {
aic_vlc_bits += 1+6+8-1;
wrong_pos += run + 1;
}else
wrong_pos += wrong_run[aic_code];
last_non_zero = i;
}
}
i = 0;
if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
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(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){
put_bits(&s->pb, 1, last);
put_bits(&s->pb, 6, run);
assert(slevel != 0);
if(level < 128)
put_sbits(&s->pb, 8, slevel);
else{
put_bits(&s->pb, 8, 128);
put_sbits(&s->pb, 5, slevel);
put_sbits(&s->pb, 6, slevel>>5);
}
}else{
ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
}
} else {
put_bits(&s->pb, 1, sign);
}
last_non_zero = i;
}
}
}
/* 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);
}
}
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];
int16_t *dc_ptr[6];
const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);
if (!s->mb_intra) {
/* compute cbp */
cbp= get_p_cbp(s, block, motion_x, motion_y);
if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) {
/* 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 */
cbpc = cbp & 3;
cbpy = cbp >> 2;
if(s->alt_inter_vlc==0 || cbpc!=3)
cbpy ^= 0xF;
if(s->dquant) cbpc+= 8;
if(s->mv_type==MV_TYPE_16X16){
put_bits(&s->pb,
ff_h263_inter_MCBPC_bits[cbpc],
ff_h263_inter_MCBPC_code[cbpc]);
put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_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 */
h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
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);
}
}else{
put_bits(&s->pb,
ff_h263_inter_MCBPC_bits[cbpc+16],
ff_h263_inter_MCBPC_code[cbpc+16]);
put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_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<4; i++){
/* motion vectors: 8x8 mode*/
h263_pred_motion(s, i, 0, &pred_x, &pred_y);
motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
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 {
assert(s->mb_intra);
cbp = 0;
if (s->h263_aic) {
/* Predict DC */
for(i=0; i<6; i++) {
int16_t level = block[i][0];
int scale;
if(i<4) scale= s->y_dc_scale;
else scale= s->c_dc_scale;
pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
level -= pred_dc;
/* Quant */
if (level >= 0)
level = (level + (scale>>1))/scale;
else
level = (level - (scale>>1))/scale;
/* AIC can change CBP */
if (level == 0 && s->block_last_index[i] == 0)
s->block_last_index[i] = -1;
if(!s->modified_quant){
if (level < -127)
level = -127;
else if (level > 127)
level = 127;
}
block[i][0] = level;
/* Reconstruction */
rec_intradc[i] = 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];
if (s->block_last_index[i] >= 0)
cbp |= 1 << (5 - i);
}
}else{
for(i=0; i<6; i++) {
/* compute cbp */
if (s->block_last_index[i] >= 1)
cbp |= 1 << (5 - i);
}
}
cbpc = cbp & 3;
if (s->pict_type == FF_I_TYPE) {
if(s->dquant) cbpc+=4;
put_bits(&s->pb,
ff_h263_intra_MCBPC_bits[cbpc],
ff_h263_intra_MCBPC_code[cbpc]);
} else {
if(s->dquant) cbpc+=8;
put_bits(&s->pb, 1, 0); /* mb coded */
put_bits(&s->pb,
ff_h263_inter_MCBPC_bits[cbpc + 4],
ff_h263_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, ff_h263_cbpy_tab[cbpy][1], ff_h263_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++;
}
}
}
void ff_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= INT_BIT - 6 - bit_size;
val = (val<<l)>>l;
sign = val>>31;
val= (val^sign)-sign;
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);
}
}
}
static void init_mv_penalty_and_fcode(MpegEncContext *s)
{
int f_code;
int mv;
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, code;
bit_size = f_code - 1;
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] + av_log2(code>>5) + 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;
}
}
static void init_uni_h263_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;
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]){
if(bits_tab) bits_tab[index]= bits;
len_tab [index]= len;
}
/* ESC */
bits= rl->table_vlc[rl->n][0];
len = rl->table_vlc[rl->n][1];
bits=bits*2+last; len++;
bits=bits*64+run; len+=6;
bits=bits*256+(level&0xff); len+=8;
if(len < len_tab[index]){
if(bits_tab) bits_tab[index]= bits;
len_tab [index]= len;
}
}
}
}
}
void h263_encode_init(MpegEncContext *s)
{
static int done = 0;
if (!done) {
done = 1;
init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
init_rl(&rl_intra_aic, ff_h263_static_rl_table_store[1]);
init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len);
init_uni_h263_rl_tab(&ff_h263_rl_inter , NULL, uni_h263_inter_rl_len);
init_mv_penalty_and_fcode(s);
}
s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p
s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64;
if(s->h263_aic){
s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len;
s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64;
}
s->ac_esc_length= 7+1+6+8;
// use fcodes >1 only for mpeg4 & h263 & h263p FIXME
switch(s->codec_id){
case CODEC_ID_MPEG4:
s->fcode_tab= fcode_tab;
break;
case CODEC_ID_H263P:
if(s->umvplus)
s->fcode_tab= umv_fcode_tab;
if(s->modified_quant){
s->min_qcoeff= -2047;
s->max_qcoeff= 2047;
}else{
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 already 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;
}
}
void ff_h263_encode_mba(MpegEncContext *s)
{
int i, mb_pos;
for(i=0; i<6; i++){
if(s->mb_num-1 <= ff_mba_max[i]) break;
}
mb_pos= s->mb_x + s->mb_width*s->mb_y;
put_bits(&s->pb, ff_mba_length[i], mb_pos);
}
| 123linslouis-android-video-cutter | jni/libavcodec/ituh263enc.c | C | asf20 | 27,199 |
/*
* Bink Audio decoder
* Copyright (c) 2007-2010 Peter Ross (pross@xvid.org)
* Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu)
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Bink Audio decoder
*
* Technical details here:
* http://wiki.multimedia.cx/index.php?title=Bink_Audio
*/
#include "avcodec.h"
#define ALT_BITSTREAM_READER_LE
#include "get_bits.h"
#include "dsputil.h"
#include "fft.h"
extern const uint16_t ff_wma_critical_freqs[25];
#define MAX_CHANNELS 2
#define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11)
typedef struct {
AVCodecContext *avctx;
GetBitContext gb;
DSPContext dsp;
int first;
int channels;
int frame_len; ///< transform size (samples)
int overlap_len; ///< overlap size (samples)
int block_size;
int num_bands;
unsigned int *bands;
float root;
DECLARE_ALIGNED(16, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE];
DECLARE_ALIGNED(16, short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block
float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for float_to_int16_interleave
union {
RDFTContext rdft;
DCTContext dct;
} trans;
} BinkAudioContext;
static av_cold int decode_init(AVCodecContext *avctx)
{
BinkAudioContext *s = avctx->priv_data;
int sample_rate = avctx->sample_rate;
int sample_rate_half;
int i;
int frame_len_bits;
s->avctx = avctx;
dsputil_init(&s->dsp, avctx);
/* determine frame length */
if (avctx->sample_rate < 22050) {
frame_len_bits = 9;
} else if (avctx->sample_rate < 44100) {
frame_len_bits = 10;
} else {
frame_len_bits = 11;
}
s->frame_len = 1 << frame_len_bits;
if (s->channels > MAX_CHANNELS) {
av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
return -1;
}
if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) {
// audio is already interleaved for the RDFT format variant
sample_rate *= avctx->channels;
s->frame_len *= avctx->channels;
s->channels = 1;
if (avctx->channels == 2)
frame_len_bits++;
} else {
s->channels = avctx->channels;
}
s->overlap_len = s->frame_len / 16;
s->block_size = (s->frame_len - s->overlap_len) * s->channels;
sample_rate_half = (sample_rate + 1) / 2;
s->root = 2.0 / sqrt(s->frame_len);
/* calculate number of bands */
for (s->num_bands = 1; s->num_bands < 25; s->num_bands++)
if (sample_rate_half <= ff_wma_critical_freqs[s->num_bands - 1])
break;
s->bands = av_malloc((s->num_bands + 1) * sizeof(*s->bands));
if (!s->bands)
return AVERROR(ENOMEM);
/* populate bands data */
s->bands[0] = 1;
for (i = 1; i < s->num_bands; i++)
s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample_rate_half;
s->bands[s->num_bands] = s->frame_len / 2;
s->first = 1;
avctx->sample_fmt = SAMPLE_FMT_S16;
for (i = 0; i < s->channels; i++)
s->coeffs_ptr[i] = s->coeffs + i * s->frame_len;
if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT)
ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R);
else if (CONFIG_BINKAUDIO_DCT_DECODER)
ff_dct_init(&s->trans.dct, frame_len_bits, DCT_III);
else
return -1;
return 0;
}
static float get_float(GetBitContext *gb)
{
int power = get_bits(gb, 5);
float f = ldexpf(get_bits_long(gb, 23), power - 23);
if (get_bits1(gb))
f = -f;
return f;
}
static const uint8_t rle_length_tab[16] = {
2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
};
/**
* Decode Bink Audio block
* @param[out] out Output buffer (must contain s->block_size elements)
*/
static void decode_block(BinkAudioContext *s, short *out, int use_dct)
{
int ch, i, j, k;
float q, quant[25];
int width, coeff;
GetBitContext *gb = &s->gb;
if (use_dct)
skip_bits(gb, 2);
for (ch = 0; ch < s->channels; ch++) {
FFTSample *coeffs = s->coeffs_ptr[ch];
q = 0.0f;
coeffs[0] = get_float(gb) * s->root;
coeffs[1] = get_float(gb) * s->root;
for (i = 0; i < s->num_bands; i++) {
/* constant is result of 0.066399999/log10(M_E) */
int value = get_bits(gb, 8);
quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root;
}
// find band (k)
for (k = 0; s->bands[k] < 1; k++) {
q = quant[k];
}
// parse coefficients
i = 2;
while (i < s->frame_len) {
if (get_bits1(gb)) {
j = i + rle_length_tab[get_bits(gb, 4)] * 8;
} else {
j = i + 8;
}
j = FFMIN(j, s->frame_len);
width = get_bits(gb, 4);
if (width == 0) {
memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));
i = j;
while (s->bands[k] * 2 < i)
q = quant[k++];
} else {
while (i < j) {
if (s->bands[k] * 2 == i)
q = quant[k++];
coeff = get_bits(gb, width);
if (coeff) {
if (get_bits1(gb))
coeffs[i] = -q * coeff;
else
coeffs[i] = q * coeff;
} else {
coeffs[i] = 0.0f;
}
i++;
}
}
}
if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {
coeffs[0] /= 0.5;
ff_dct_calc (&s->trans.dct, coeffs);
s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len);
}
else if (CONFIG_BINKAUDIO_RDFT_DECODER)
ff_rdft_calc(&s->trans.rdft, coeffs);
}
if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
for (i = 0; i < s->channels; i++)
for (j = 0; j < s->frame_len; j++)
s->coeffs_ptr[i][j] = 385.0 + s->coeffs_ptr[i][j]*(1.0/32767.0);
}
s->dsp.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->frame_len, s->channels);
if (!s->first) {
int count = s->overlap_len * s->channels;
int shift = av_log2(count);
for (i = 0; i < count; i++) {
out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift;
}
}
memcpy(s->previous, out + s->block_size,
s->overlap_len * s->channels * sizeof(*out));
s->first = 0;
}
static av_cold int decode_end(AVCodecContext *avctx)
{
BinkAudioContext * s = avctx->priv_data;
av_freep(&s->bands);
if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT)
ff_rdft_end(&s->trans.rdft);
else if (CONFIG_BINKAUDIO_DCT_DECODER)
ff_dct_end(&s->trans.dct);
return 0;
}
static void get_bits_align32(GetBitContext *s)
{
int n = (-get_bits_count(s)) & 31;
if (n) skip_bits(s, n);
}
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
BinkAudioContext *s = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
short *samples = data;
short *samples_end = (short*)((uint8_t*)data + *data_size);
int reported_size;
GetBitContext *gb = &s->gb;
init_get_bits(gb, buf, buf_size * 8);
reported_size = get_bits_long(gb, 32);
while (get_bits_count(gb) / 8 < buf_size &&
samples + s->block_size <= samples_end) {
decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT);
samples += s->block_size;
get_bits_align32(gb);
}
*data_size = FFMIN(reported_size, (uint8_t*)samples - (uint8_t*)data);
return buf_size;
}
AVCodec binkaudio_rdft_decoder = {
"binkaudio_rdft",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_BINKAUDIO_RDFT,
sizeof(BinkAudioContext),
decode_init,
NULL,
decode_end,
decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)")
};
AVCodec binkaudio_dct_decoder = {
"binkaudio_dct",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_BINKAUDIO_DCT,
sizeof(BinkAudioContext),
decode_init,
NULL,
decode_end,
decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)")
};
| 123linslouis-android-video-cutter | jni/libavcodec/binkaudio.c | C | asf20 | 9,298 |
/*
* FFT/IFFT transforms
* Copyright (c) 2008 Loren Merritt
* Copyright (c) 2002 Fabrice Bellard
* Partly based on libdjbfft by D. J. Bernstein
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* FFT/IFFT transforms.
*/
#include <stdlib.h>
#include <string.h>
#include "libavutil/mathematics.h"
#include "fft.h"
/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */
#if !CONFIG_HARDCODED_TABLES
COSTABLE(16);
COSTABLE(32);
COSTABLE(64);
COSTABLE(128);
COSTABLE(256);
COSTABLE(512);
COSTABLE(1024);
COSTABLE(2048);
COSTABLE(4096);
COSTABLE(8192);
COSTABLE(16384);
COSTABLE(32768);
COSTABLE(65536);
#endif
COSTABLE_CONST FFTSample * const ff_cos_tabs[] = {
NULL, NULL, NULL, NULL,
ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024,
ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536,
};
static int split_radix_permutation(int i, int n, int inverse)
{
int m;
if(n <= 2) return i&1;
m = n >> 1;
if(!(i&m)) return split_radix_permutation(i, m, inverse)*2;
m >>= 1;
if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1;
else return split_radix_permutation(i, m, inverse)*4 - 1;
}
av_cold void ff_init_ff_cos_tabs(int index)
{
#if !CONFIG_HARDCODED_TABLES
int i;
int m = 1<<index;
double freq = 2*M_PI/m;
FFTSample *tab = ff_cos_tabs[index];
for(i=0; i<=m/4; i++)
tab[i] = cos(i*freq);
for(i=1; i<m/4; i++)
tab[m/2-i] = tab[i];
#endif
}
av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
{
int i, j, m, n;
float alpha, c1, s1, s2;
int av_unused has_vectors;
if (nbits < 2 || nbits > 16)
goto fail;
s->nbits = nbits;
n = 1 << nbits;
s->tmp_buf = NULL;
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;
s->fft_permute = ff_fft_permute_c;
s->fft_calc = ff_fft_calc_c;
#if CONFIG_MDCT
s->imdct_calc = ff_imdct_calc_c;
s->imdct_half = ff_imdct_half_c;
s->mdct_calc = ff_mdct_calc_c;
#endif
s->exptab1 = NULL;
s->split_radix = 1;
if (ARCH_ARM) ff_fft_init_arm(s);
if (HAVE_ALTIVEC) ff_fft_init_altivec(s);
if (HAVE_MMX) ff_fft_init_mmx(s);
if (s->split_radix) {
for(j=4; j<=nbits; j++) {
ff_init_ff_cos_tabs(j);
}
for(i=0; i<n; i++)
s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i;
s->tmp_buf = av_malloc(n * sizeof(FFTComplex));
} else {
int np, nblocks, np2, l;
FFTComplex *q;
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;
}
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);
/* 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);
av_freep(&s->tmp_buf);
return -1;
}
void ff_fft_permute_c(FFTContext *s, FFTComplex *z)
{
int j, k, np;
FFTComplex tmp;
const uint16_t *revtab = s->revtab;
np = 1 << s->nbits;
if (s->tmp_buf) {
/* TODO: handle split-radix permute in a more optimal way, probably in-place */
for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j];
memcpy(z, s->tmp_buf, np * sizeof(FFTComplex));
return;
}
/* reverse */
for(j=0;j<np;j++) {
k = revtab[j];
if (k < j) {
tmp = z[k];
z[k] = z[j];
z[j] = tmp;
}
}
}
av_cold void ff_fft_end(FFTContext *s)
{
av_freep(&s->revtab);
av_freep(&s->exptab);
av_freep(&s->exptab1);
av_freep(&s->tmp_buf);
}
#define sqrthalf (float)M_SQRT1_2
#define BF(x,y,a,b) {\
x = a - b;\
y = a + b;\
}
#define BUTTERFLIES(a0,a1,a2,a3) {\
BF(t3, t5, t5, t1);\
BF(a2.re, a0.re, a0.re, t5);\
BF(a3.im, a1.im, a1.im, t3);\
BF(t4, t6, t2, t6);\
BF(a3.re, a1.re, a1.re, t4);\
BF(a2.im, a0.im, a0.im, t6);\
}
// force loading all the inputs before storing any.
// this is slightly slower for small data, but avoids store->load aliasing
// for addresses separated by large powers of 2.
#define BUTTERFLIES_BIG(a0,a1,a2,a3) {\
FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\
BF(t3, t5, t5, t1);\
BF(a2.re, a0.re, r0, t5);\
BF(a3.im, a1.im, i1, t3);\
BF(t4, t6, t2, t6);\
BF(a3.re, a1.re, r1, t4);\
BF(a2.im, a0.im, i0, t6);\
}
#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
t1 = a2.re * wre + a2.im * wim;\
t2 = a2.im * wre - a2.re * wim;\
t5 = a3.re * wre - a3.im * wim;\
t6 = a3.im * wre + a3.re * wim;\
BUTTERFLIES(a0,a1,a2,a3)\
}
#define TRANSFORM_ZERO(a0,a1,a2,a3) {\
t1 = a2.re;\
t2 = a2.im;\
t5 = a3.re;\
t6 = a3.im;\
BUTTERFLIES(a0,a1,a2,a3)\
}
/* z[0...8n-1], w[1...2n-1] */
#define PASS(name)\
static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\
{\
FFTSample t1, t2, t3, t4, t5, t6;\
int o1 = 2*n;\
int o2 = 4*n;\
int o3 = 6*n;\
const FFTSample *wim = wre+o1;\
n--;\
\
TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\
TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
do {\
z += 2;\
wre += 2;\
wim -= 2;\
TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\
TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\
} while(--n);\
}
PASS(pass)
#undef BUTTERFLIES
#define BUTTERFLIES BUTTERFLIES_BIG
PASS(pass_big)
#define DECL_FFT(n,n2,n4)\
static void fft##n(FFTComplex *z)\
{\
fft##n2(z);\
fft##n4(z+n4*2);\
fft##n4(z+n4*3);\
pass(z,ff_cos_##n,n4/2);\
}
static void fft4(FFTComplex *z)
{
FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
BF(t3, t1, z[0].re, z[1].re);
BF(t8, t6, z[3].re, z[2].re);
BF(z[2].re, z[0].re, t1, t6);
BF(t4, t2, z[0].im, z[1].im);
BF(t7, t5, z[2].im, z[3].im);
BF(z[3].im, z[1].im, t4, t8);
BF(z[3].re, z[1].re, t3, t7);
BF(z[2].im, z[0].im, t2, t5);
}
static void fft8(FFTComplex *z)
{
FFTSample t1, t2, t3, t4, t5, t6, t7, t8;
fft4(z);
BF(t1, z[5].re, z[4].re, -z[5].re);
BF(t2, z[5].im, z[4].im, -z[5].im);
BF(t3, z[7].re, z[6].re, -z[7].re);
BF(t4, z[7].im, z[6].im, -z[7].im);
BF(t8, t1, t3, t1);
BF(t7, t2, t2, t4);
BF(z[4].re, z[0].re, z[0].re, t1);
BF(z[4].im, z[0].im, z[0].im, t2);
BF(z[6].re, z[2].re, z[2].re, t7);
BF(z[6].im, z[2].im, z[2].im, t8);
TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf);
}
#if !CONFIG_SMALL
static void fft16(FFTComplex *z)
{
FFTSample t1, t2, t3, t4, t5, t6;
fft8(z);
fft4(z+8);
fft4(z+12);
TRANSFORM_ZERO(z[0],z[4],z[8],z[12]);
TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf);
TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]);
TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]);
}
#else
DECL_FFT(16,8,4)
#endif
DECL_FFT(32,16,8)
DECL_FFT(64,32,16)
DECL_FFT(128,64,32)
DECL_FFT(256,128,64)
DECL_FFT(512,256,128)
#if !CONFIG_SMALL
#define pass pass_big
#endif
DECL_FFT(1024,512,256)
DECL_FFT(2048,1024,512)
DECL_FFT(4096,2048,1024)
DECL_FFT(8192,4096,2048)
DECL_FFT(16384,8192,4096)
DECL_FFT(32768,16384,8192)
DECL_FFT(65536,32768,16384)
static void (* const fft_dispatch[])(FFTComplex*) = {
fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024,
fft2048, fft4096, fft8192, fft16384, fft32768, fft65536,
};
void ff_fft_calc_c(FFTContext *s, FFTComplex *z)
{
fft_dispatch[s->nbits-2](z);
}
| 123linslouis-android-video-cutter | jni/libavcodec/fft.c | C | asf20 | 9,357 |
/*
* MPEG-4 Audio common code
* Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
* Copyright (c) 2009 Alex Converse <alex.converse@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "get_bits.h"
#include "put_bits.h"
#include "mpeg4audio.h"
/**
* Parse MPEG-4 audio configuration for ALS object type.
* @param[in] gb bit reader context
* @param[in] c MPEG4AudioConfig structure to fill
* @return on success 0 is returned, otherwise a value < 0
*/
static int parse_config_ALS(GetBitContext *gb, MPEG4AudioConfig *c)
{
if (get_bits_left(gb) < 112)
return -1;
if (get_bits_long(gb, 32) != MKBETAG('A','L','S','\0'))
return -1;
// override AudioSpecificConfig channel configuration and sample rate
// which are buggy in old ALS conformance files
c->sample_rate = get_bits_long(gb, 32);
// skip number of samples
skip_bits_long(gb, 32);
// read number of channels
c->chan_config = 0;
c->channels = get_bits(gb, 16) + 1;
return 0;
}
const int ff_mpeg4audio_sample_rates[16] = {
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
};
const uint8_t ff_mpeg4audio_channels[8] = {
0, 1, 2, 3, 4, 5, 6, 8
};
static inline int get_object_type(GetBitContext *gb)
{
int object_type = get_bits(gb, 5);
if (object_type == AOT_ESCAPE)
object_type = 32 + get_bits(gb, 6);
return object_type;
}
static inline int get_sample_rate(GetBitContext *gb, int *index)
{
*index = get_bits(gb, 4);
return *index == 0x0f ? get_bits(gb, 24) :
ff_mpeg4audio_sample_rates[*index];
}
int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int specific_config_bitindex;
init_get_bits(&gb, buf, buf_size*8);
c->object_type = get_object_type(&gb);
c->sample_rate = get_sample_rate(&gb, &c->sampling_index);
c->chan_config = get_bits(&gb, 4);
if (c->chan_config < FF_ARRAY_ELEMS(ff_mpeg4audio_channels))
c->channels = ff_mpeg4audio_channels[c->chan_config];
c->sbr = -1;
c->ps = -1;
if (c->object_type == AOT_SBR || (c->object_type == AOT_PS &&
// check for W6132 Annex YYYY draft MP3onMP4
!(show_bits(&gb, 3) & 0x03 && !(show_bits(&gb, 9) & 0x3F)))) {
if (c->object_type == AOT_PS)
c->ps = 1;
c->ext_object_type = AOT_SBR;
c->sbr = 1;
c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
c->object_type = get_object_type(&gb);
if (c->object_type == AOT_ER_BSAC)
c->ext_chan_config = get_bits(&gb, 4);
} else {
c->ext_object_type = AOT_NULL;
c->ext_sample_rate = 0;
}
specific_config_bitindex = get_bits_count(&gb);
if (c->object_type == AOT_ALS) {
skip_bits(&gb, 5);
if (show_bits_long(&gb, 24) != MKBETAG('\0','A','L','S'))
skip_bits_long(&gb, 24);
specific_config_bitindex = get_bits_count(&gb);
if (parse_config_ALS(&gb, c))
return -1;
}
if (c->ext_object_type != AOT_SBR) {
while (get_bits_left(&gb) > 15) {
if (show_bits(&gb, 11) == 0x2b7) { // sync extension
get_bits(&gb, 11);
c->ext_object_type = get_object_type(&gb);
if (c->ext_object_type == AOT_SBR && (c->sbr = get_bits1(&gb)) == 1)
c->ext_sample_rate = get_sample_rate(&gb, &c->ext_sampling_index);
if (get_bits_left(&gb) > 11 && get_bits(&gb, 11) == 0x548)
c->ps = get_bits1(&gb);
break;
} else
get_bits1(&gb); // skip 1 bit
}
}
return specific_config_bitindex;
}
static av_always_inline unsigned int copy_bits(PutBitContext *pb,
GetBitContext *gb,
int bits)
{
unsigned int el = get_bits(gb, bits);
put_bits(pb, bits, el);
return el;
}
int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
{
int five_bit_ch, four_bit_ch, comment_size, bits;
int offset = put_bits_count(pb);
copy_bits(pb, gb, 10); //Tag, Object Type, Frequency
five_bit_ch = copy_bits(pb, gb, 4); //Front
five_bit_ch += copy_bits(pb, gb, 4); //Side
five_bit_ch += copy_bits(pb, gb, 4); //Back
four_bit_ch = copy_bits(pb, gb, 2); //LFE
four_bit_ch += copy_bits(pb, gb, 3); //Data
five_bit_ch += copy_bits(pb, gb, 4); //Coupling
if (copy_bits(pb, gb, 1)) //Mono Mixdown
copy_bits(pb, gb, 4);
if (copy_bits(pb, gb, 1)) //Stereo Mixdown
copy_bits(pb, gb, 4);
if (copy_bits(pb, gb, 1)) //Matrix Mixdown
copy_bits(pb, gb, 3);
for (bits = five_bit_ch*5+four_bit_ch*4; bits > 16; bits -= 16)
copy_bits(pb, gb, 16);
if (bits)
copy_bits(pb, gb, bits);
align_put_bits(pb);
align_get_bits(gb);
comment_size = copy_bits(pb, gb, 8);
for (; comment_size > 0; comment_size--)
copy_bits(pb, gb, 8);
return put_bits_count(pb) - offset;
}
| 123linslouis-android-video-cutter | jni/libavcodec/mpeg4audio.c | C | asf20 | 5,948 |
/*
* Microsoft RLE decoder
* Copyright (C) 2008 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MS RLE decoder based on decoder by Mike Melanson and my own for TSCC
* For more information about the MS RLE format, visit:
* http://www.multimedia.cx/msrle.txt
*/
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "msrledec.h"
#define FETCH_NEXT_STREAM_BYTE() \
if (stream_ptr >= data_size) \
{ \
av_log(avctx, AV_LOG_ERROR, " MS RLE: stream ptr just went out of bounds (1)\n"); \
return -1; \
} \
stream_byte = data[stream_ptr++];
static int msrle_decode_pal4(AVCodecContext *avctx, AVPicture *pic,
const uint8_t *data, int data_size)
{
int stream_ptr = 0;
unsigned char rle_code;
unsigned char extra_byte, odd_pixel;
unsigned char stream_byte;
int pixel_ptr = 0;
int row_dec = pic->linesize[0];
int row_ptr = (avctx->height - 1) * row_dec;
int frame_size = row_dec * avctx->height;
int i;
while (row_ptr >= 0) {
FETCH_NEXT_STREAM_BYTE();
rle_code = stream_byte;
if (rle_code == 0) {
/* fetch the next byte to see how to handle escape code */
FETCH_NEXT_STREAM_BYTE();
if (stream_byte == 0) {
/* line is done, goto the next one */
row_ptr -= row_dec;
pixel_ptr = 0;
} else if (stream_byte == 1) {
/* decode is done */
return 0;
} else if (stream_byte == 2) {
/* reposition frame decode coordinates */
FETCH_NEXT_STREAM_BYTE();
pixel_ptr += stream_byte;
FETCH_NEXT_STREAM_BYTE();
row_ptr -= stream_byte * row_dec;
} else {
// copy pixels from encoded stream
odd_pixel = stream_byte & 1;
rle_code = (stream_byte + 1) / 2;
extra_byte = rle_code & 0x01;
if ((row_ptr + pixel_ptr + stream_byte > frame_size) ||
(row_ptr < 0)) {
av_log(avctx, AV_LOG_ERROR, " MS RLE: frame ptr just went out of bounds (1)\n");
return -1;
}
for (i = 0; i < rle_code; i++) {
if (pixel_ptr >= avctx->width)
break;
FETCH_NEXT_STREAM_BYTE();
pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
pixel_ptr++;
if (i + 1 == rle_code && odd_pixel)
break;
if (pixel_ptr >= avctx->width)
break;
pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
pixel_ptr++;
}
// if the RLE code is odd, skip a byte in the stream
if (extra_byte)
stream_ptr++;
}
} else {
// decode a run of data
if ((row_ptr + pixel_ptr + stream_byte > frame_size) ||
(row_ptr < 0)) {
av_log(avctx, AV_LOG_ERROR, " MS RLE: frame ptr just went out of bounds (1)\n");
return -1;
}
FETCH_NEXT_STREAM_BYTE();
for (i = 0; i < rle_code; i++) {
if (pixel_ptr >= avctx->width)
break;
if ((i & 1) == 0)
pic->data[0][row_ptr + pixel_ptr] = stream_byte >> 4;
else
pic->data[0][row_ptr + pixel_ptr] = stream_byte & 0x0F;
pixel_ptr++;
}
}
}
/* one last sanity check on the way out */
if (stream_ptr < data_size) {
av_log(avctx, AV_LOG_ERROR, " MS RLE: ended frame decode with bytes left over (%d < %d)\n",
stream_ptr, data_size);
return -1;
}
return 0;
}
static int msrle_decode_8_16_24_32(AVCodecContext *avctx, AVPicture *pic, int depth,
const uint8_t *data, int srcsize)
{
uint8_t *output, *output_end;
const uint8_t* src = data;
int p1, p2, line=avctx->height - 1, pos=0, i;
uint16_t av_uninit(pix16);
uint32_t av_uninit(pix32);
output = pic->data[0] + (avctx->height - 1) * pic->linesize[0];
output_end = pic->data[0] + (avctx->height) * pic->linesize[0];
while(src < data + srcsize) {
p1 = *src++;
if(p1 == 0) { //Escape code
p2 = *src++;
if(p2 == 0) { //End-of-line
output = pic->data[0] + (--line) * pic->linesize[0];
if (line < 0 && !(src+1 < data + srcsize && AV_RB16(src) == 1)) {
av_log(avctx, AV_LOG_ERROR, "Next line is beyond picture bounds\n");
return -1;
}
pos = 0;
continue;
} else if(p2 == 1) { //End-of-picture
return 0;
} else if(p2 == 2) { //Skip
p1 = *src++;
p2 = *src++;
line -= p2;
if (line < 0){
av_log(avctx, AV_LOG_ERROR, "Skip beyond picture bounds\n");
return -1;
}
pos += p1;
output = pic->data[0] + line * pic->linesize[0] + pos * (depth >> 3);
continue;
}
// Copy data
if ((pic->linesize[0] > 0 && output + p2 * (depth >> 3) > output_end)
||(pic->linesize[0] < 0 && output + p2 * (depth >> 3) < output_end)) {
src += p2 * (depth >> 3);
continue;
}
if ((depth == 8) || (depth == 24)) {
for(i = 0; i < p2 * (depth >> 3); i++) {
*output++ = *src++;
}
// RLE8 copy is actually padded - and runs are not!
if(depth == 8 && (p2 & 1)) {
src++;
}
} else if (depth == 16) {
for(i = 0; i < p2; i++) {
pix16 = AV_RL16(src);
src += 2;
*(uint16_t*)output = pix16;
output += 2;
}
} else if (depth == 32) {
for(i = 0; i < p2; i++) {
pix32 = AV_RL32(src);
src += 4;
*(uint32_t*)output = pix32;
output += 4;
}
}
pos += p2;
} else { //run of pixels
uint8_t pix[3]; //original pixel
switch(depth){
case 8: pix[0] = *src++;
break;
case 16: pix16 = AV_RL16(src);
src += 2;
break;
case 24: pix[0] = *src++;
pix[1] = *src++;
pix[2] = *src++;
break;
case 32: pix32 = AV_RL32(src);
src += 4;
break;
}
if ((pic->linesize[0] > 0 && output + p1 * (depth >> 3) > output_end)
||(pic->linesize[0] < 0 && output + p1 * (depth >> 3) < output_end))
continue;
for(i = 0; i < p1; i++) {
switch(depth){
case 8: *output++ = pix[0];
break;
case 16: *(uint16_t*)output = pix16;
output += 2;
break;
case 24: *output++ = pix[0];
*output++ = pix[1];
*output++ = pix[2];
break;
case 32: *(uint32_t*)output = pix32;
output += 4;
break;
}
}
pos += p1;
}
}
av_log(avctx, AV_LOG_WARNING, "MS RLE warning: no end-of-picture code\n");
return 0;
}
int ff_msrle_decode(AVCodecContext *avctx, AVPicture *pic, int depth,
const uint8_t* data, int data_size)
{
switch(depth){
case 4:
return msrle_decode_pal4(avctx, pic, data, data_size);
case 8:
case 16:
case 24:
case 32:
return msrle_decode_8_16_24_32(avctx, pic, depth, data, data_size);
default:
av_log(avctx, AV_LOG_ERROR, "Unknown depth %d\n", depth);
return -1;
}
}
| 123linslouis-android-video-cutter | jni/libavcodec/msrledec.c | C | asf20 | 9,130 |
/*
* MPEG Audio parser
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "parser.h"
#include "mpegaudio.h"
#include "mpegaudiodecheader.h"
typedef struct MpegAudioParseContext {
ParseContext pc;
int frame_size;
uint32_t header;
int header_count;
} MpegAudioParseContext;
#define MPA_HEADER_SIZE 4
/* header + layer + bitrate + freq + lsf/mpeg25 */
#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */
#define SAME_HEADER_MASK \
(0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19))
/* useful helper to get mpeg audio stream infos. Return -1 if error in
header, otherwise the coded frame size in bytes */
int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{
MPADecodeHeader s1, *s = &s1;
if (ff_mpa_check_header(head) != 0)
return -1;
if (ff_mpegaudio_decode_header(s, head) != 0) {
return -1;
}
switch(s->layer) {
case 1:
avctx->codec_id = CODEC_ID_MP1;
*frame_size = 384;
break;
case 2:
avctx->codec_id = CODEC_ID_MP2;
*frame_size = 1152;
break;
default:
case 3:
avctx->codec_id = CODEC_ID_MP3;
if (s->lsf)
*frame_size = 576;
else
*frame_size = 1152;
break;
}
*sample_rate = s->sample_rate;
*channels = s->nb_channels;
*bit_rate = s->bit_rate;
avctx->sub_id = s->layer;
return s->frame_size;
}
static int mpegaudio_parse(AVCodecParserContext *s1,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
MpegAudioParseContext *s = s1->priv_data;
ParseContext *pc = &s->pc;
uint32_t state= pc->state;
int i;
int next= END_NOT_FOUND;
for(i=0; i<buf_size; ){
if(s->frame_size){
int inc= FFMIN(buf_size - i, s->frame_size);
i += inc;
s->frame_size -= inc;
if(!s->frame_size){
next= i;
break;
}
}else{
while(i<buf_size){
int ret, sr, channels, bit_rate, frame_size;
state= (state<<8) + buf[i++];
ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
if (ret < 4) {
s->header_count= -2;
} else {
if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
s->header_count= -3;
s->header= state;
s->header_count++;
s->frame_size = ret-4;
if(s->header_count > 1){
avctx->sample_rate= sr;
avctx->channels = channels;
avctx->frame_size = frame_size;
avctx->bit_rate = bit_rate;
}
break;
}
}
}
}
pc->state= state;
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
*poutbuf = NULL;
*poutbuf_size = 0;
return buf_size;
}
*poutbuf = buf;
*poutbuf_size = buf_size;
return next;
}
AVCodecParser mpegaudio_parser = {
{ CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 },
sizeof(MpegAudioParseContext),
NULL,
mpegaudio_parse,
ff_parse_close,
};
| 123linslouis-android-video-cutter | jni/libavcodec/mpegaudio_parser.c | C | asf20 | 4,322 |
/*
* H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Context Adaptive Binary Arithmetic Coder.
*/
#ifndef AVCODEC_CABAC_H
#define AVCODEC_CABAC_H
#include "put_bits.h"
//#undef NDEBUG
#include <assert.h>
#include "libavutil/x86_cpu.h"
#define CABAC_BITS 16
#define CABAC_MASK ((1<<CABAC_BITS)-1)
#define BRANCHLESS_CABAC_DECODER 1
//#define ARCH_X86_DISABLED 1
typedef struct CABACContext{
int low;
int range;
int outstanding_count;
#ifdef STRICT_LIMITS
int symCount;
#endif
const uint8_t *bytestream_start;
const uint8_t *bytestream;
const uint8_t *bytestream_end;
PutBitContext pb;
}CABACContext;
extern uint8_t ff_h264_mlps_state[4*64];
extern uint8_t ff_h264_lps_range[4*2*64]; ///< rangeTabLPS
extern uint8_t ff_h264_mps_state[2*64]; ///< transIdxMPS
extern uint8_t ff_h264_lps_state[2*64]; ///< transIdxLPS
extern const uint8_t ff_h264_norm_shift[512];
void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size);
void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size);
void ff_init_cabac_states(CABACContext *c);
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;
}
}
#ifdef TEST
static void put_cabac(CABACContext *c, uint8_t * const state, int bit){
int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state];
if(bit == ((*state)&1)){
c->range -= RangeLPS;
*state= ff_h264_mps_state[*state];
}else{
c->low += c->range - RangeLPS;
c->range = RangeLPS;
*state= ff_h264_lps_state[*state];
}
renorm_cabac_encoder(c);
#ifdef STRICT_LIMITS
c->symCount++;
#endif
}
static 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 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 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 (put_bits_count(&c->pb)+7)>>3;
}
/**
* put (truncated) unary binarization.
*/
static 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 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= FFABS(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);
}
}
#endif /* TEST */
static void refill(CABACContext *c){
#if CABAC_BITS == 16
c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
#else
c->low+= c->bytestream[0]<<1;
#endif
c->low -= CABAC_MASK;
c->bytestream+= CABAC_BITS/8;
}
#if ! ( ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) )
static void refill2(CABACContext *c){
int i, x;
x= c->low ^ (c->low-1);
i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)];
x= -CABAC_MASK;
#if CABAC_BITS == 16
x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1);
#else
x+= c->bytestream[0]<<1;
#endif
c->low += x<<i;
c->bytestream+= CABAC_BITS/8;
}
#endif
static inline void renorm_cabac_decoder(CABACContext *c){
while(c->range < 0x100){
c->range+= c->range;
c->low+= c->low;
if(!(c->low & CABAC_MASK))
refill(c);
}
}
static inline void renorm_cabac_decoder_once(CABACContext *c){
#ifdef ARCH_X86_DISABLED
int temp;
#if 0
//P3:683 athlon:475
__asm__(
"lea -0x100(%0), %2 \n\t"
"shr $31, %2 \n\t" //FIXME 31->63 for x86-64
"shl %%cl, %0 \n\t"
"shl %%cl, %1 \n\t"
: "+r"(c->range), "+r"(c->low), "+c"(temp)
);
#elif 0
//P3:680 athlon:474
__asm__(
"cmp $0x100, %0 \n\t"
"setb %%cl \n\t" //FIXME 31->63 for x86-64
"shl %%cl, %0 \n\t"
"shl %%cl, %1 \n\t"
: "+r"(c->range), "+r"(c->low), "+c"(temp)
);
#elif 1
int temp2;
//P3:665 athlon:517
__asm__(
"lea -0x100(%0), %%eax \n\t"
"cltd \n\t"
"mov %0, %%eax \n\t"
"and %%edx, %0 \n\t"
"and %1, %%edx \n\t"
"add %%eax, %0 \n\t"
"add %%edx, %1 \n\t"
: "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
);
#elif 0
int temp2;
//P3:673 athlon:509
__asm__(
"cmp $0x100, %0 \n\t"
"sbb %%edx, %%edx \n\t"
"mov %0, %%eax \n\t"
"and %%edx, %0 \n\t"
"and %1, %%edx \n\t"
"add %%eax, %0 \n\t"
"add %%edx, %1 \n\t"
: "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
);
#else
int temp2;
//P3:677 athlon:511
__asm__(
"cmp $0x100, %0 \n\t"
"lea (%0, %0), %%eax \n\t"
"lea (%1, %1), %%edx \n\t"
"cmovb %%eax, %0 \n\t"
"cmovb %%edx, %1 \n\t"
: "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2)
);
#endif
#else
//P3:675 athlon:476
int shift= (uint32_t)(c->range - 0x100)>>31;
c->range<<= shift;
c->low <<= shift;
#endif
if(!(c->low & CABAC_MASK))
refill(c);
}
static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){
//FIXME gcc generates duplicate load/stores for c->low and c->range
#define LOW "0"
#define RANGE "4"
#if ARCH_X86_64
#define BYTESTART "16"
#define BYTE "24"
#define BYTEEND "32"
#else
#define BYTESTART "12"
#define BYTE "16"
#define BYTEEND "20"
#endif
#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS)
int bit;
#ifndef BRANCHLESS_CABAC_DECODER
__asm__ volatile(
"movzbl (%1), %0 \n\t"
"movl "RANGE "(%2), %%ebx \n\t"
"movl "RANGE "(%2), %%edx \n\t"
"andl $0xC0, %%ebx \n\t"
"movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t"
"movl "LOW "(%2), %%ebx \n\t"
//eax:state ebx:low, edx:range, esi:RangeLPS
"subl %%esi, %%edx \n\t"
"movl %%edx, %%ecx \n\t"
"shll $17, %%ecx \n\t"
"cmpl %%ecx, %%ebx \n\t"
" ja 1f \n\t"
#if 1
//athlon:4067 P3:4110
"lea -0x100(%%edx), %%ecx \n\t"
"shr $31, %%ecx \n\t"
"shl %%cl, %%edx \n\t"
"shl %%cl, %%ebx \n\t"
#else
//athlon:4057 P3:4130
"cmp $0x100, %%edx \n\t" //FIXME avoidable
"setb %%cl \n\t"
"shl %%cl, %%edx \n\t"
"shl %%cl, %%ebx \n\t"
#endif
"movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t"
"movb %%cl, (%1) \n\t"
//eax:state ebx:low, edx:range, esi:RangeLPS
"test %%bx, %%bx \n\t"
" jnz 2f \n\t"
"mov "BYTE "(%2), %%"REG_S" \n\t"
"subl $0xFFFF, %%ebx \n\t"
"movzwl (%%"REG_S"), %%ecx \n\t"
"bswap %%ecx \n\t"
"shrl $15, %%ecx \n\t"
"add $2, %%"REG_S" \n\t"
"addl %%ecx, %%ebx \n\t"
"mov %%"REG_S", "BYTE "(%2) \n\t"
"jmp 2f \n\t"
"1: \n\t"
//eax:state ebx:low, edx:range, esi:RangeLPS
"subl %%ecx, %%ebx \n\t"
"movl %%esi, %%edx \n\t"
"movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t"
"shll %%cl, %%ebx \n\t"
"shll %%cl, %%edx \n\t"
"movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t"
"movb %%cl, (%1) \n\t"
"add $1, %0 \n\t"
"test %%bx, %%bx \n\t"
" jnz 2f \n\t"
"mov "BYTE "(%2), %%"REG_c" \n\t"
"movzwl (%%"REG_c"), %%esi \n\t"
"bswap %%esi \n\t"
"shrl $15, %%esi \n\t"
"subl $0xFFFF, %%esi \n\t"
"add $2, %%"REG_c" \n\t"
"mov %%"REG_c", "BYTE "(%2) \n\t"
"leal -1(%%ebx), %%ecx \n\t"
"xorl %%ebx, %%ecx \n\t"
"shrl $15, %%ecx \n\t"
"movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"
"neg %%ecx \n\t"
"add $7, %%ecx \n\t"
"shll %%cl , %%esi \n\t"
"addl %%esi, %%ebx \n\t"
"2: \n\t"
"movl %%edx, "RANGE "(%2) \n\t"
"movl %%ebx, "LOW "(%2) \n\t"
:"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or miscompiles it (for example if "+a"(bit) or "+m"(*state) is used
:"r"(state), "r"(c)
: "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory"
);
bit&=1;
#else /* BRANCHLESS_CABAC_DECODER */
#if HAVE_FAST_CMOV
#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
"mov "tmp" , %%ecx \n\t"\
"shl $17 , "tmp" \n\t"\
"cmp "low" , "tmp" \n\t"\
"cmova %%ecx , "range" \n\t"\
"sbb %%ecx , %%ecx \n\t"\
"and %%ecx , "tmp" \n\t"\
"sub "tmp" , "low" \n\t"\
"xor %%ecx , "ret" \n\t"
#else /* HAVE_FAST_CMOV */
#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
"mov "tmp" , %%ecx \n\t"\
"shl $17 , "tmp" \n\t"\
"sub "low" , "tmp" \n\t"\
"sar $31 , "tmp" \n\t" /*lps_mask*/\
"sub %%ecx , "range" \n\t" /*RangeLPS - range*/\
"and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\
"add %%ecx , "range" \n\t" /*new range*/\
"shl $17 , %%ecx \n\t"\
"and "tmp" , %%ecx \n\t"\
"sub %%ecx , "low" \n\t"\
"xor "tmp" , "ret" \n\t"
#endif /* HAVE_FAST_CMOV */
#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
"movzbl "statep" , "ret" \n\t"\
"mov "range" , "tmp" \n\t"\
"and $0xC0 , "range" \n\t"\
"movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\
"sub "range" , "tmp" \n\t"\
BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\
"movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\
"shl %%cl , "range" \n\t"\
"movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\
"mov "tmpbyte" , "statep" \n\t"\
"shl %%cl , "low" \n\t"\
"test "lowword" , "lowword" \n\t"\
" jnz 1f \n\t"\
"mov "BYTE"("cabac"), %%"REG_c" \n\t"\
"movzwl (%%"REG_c") , "tmp" \n\t"\
"bswap "tmp" \n\t"\
"shr $15 , "tmp" \n\t"\
"sub $0xFFFF , "tmp" \n\t"\
"add $2 , %%"REG_c" \n\t"\
"mov %%"REG_c" , "BYTE "("cabac") \n\t"\
"lea -1("low") , %%ecx \n\t"\
"xor "low" , %%ecx \n\t"\
"shr $15 , %%ecx \n\t"\
"movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\
"neg %%ecx \n\t"\
"add $7 , %%ecx \n\t"\
"shl %%cl , "tmp" \n\t"\
"add "tmp" , "low" \n\t"\
"1: \n\t"
__asm__ volatile(
"movl "RANGE "(%2), %%esi \n\t"
"movl "LOW "(%2), %%ebx \n\t"
BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl")
"movl %%esi, "RANGE "(%2) \n\t"
"movl %%ebx, "LOW "(%2) \n\t"
:"=&a"(bit)
:"r"(state), "r"(c)
: "%"REG_c, "%ebx", "%edx", "%esi", "memory"
);
bit&=1;
#endif /* BRANCHLESS_CABAC_DECODER */
#else /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
int s = *state;
int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s];
int bit, lps_mask av_unused;
c->range -= RangeLPS;
#ifndef BRANCHLESS_CABAC_DECODER
if(c->low < (c->range<<(CABAC_BITS+1))){
bit= s&1;
*state= ff_h264_mps_state[s];
renorm_cabac_decoder_once(c);
}else{
bit= ff_h264_norm_shift[RangeLPS];
c->low -= (c->range<<(CABAC_BITS+1));
*state= ff_h264_lps_state[s];
c->range = RangeLPS<<bit;
c->low <<= bit;
bit= (s&1)^1;
if(!(c->low & CABAC_MASK)){
refill2(c);
}
}
#else /* BRANCHLESS_CABAC_DECODER */
lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31;
c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask;
c->range += (RangeLPS - c->range) & lps_mask;
s^=lps_mask;
*state= (ff_h264_mlps_state+128)[s];
bit= s&1;
lps_mask= ff_h264_norm_shift[c->range];
c->range<<= lps_mask;
c->low <<= lps_mask;
if(!(c->low & CABAC_MASK))
refill2(c);
#endif /* BRANCHLESS_CABAC_DECODER */
#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */
return bit;
}
static int av_noinline av_unused get_cabac_noinline(CABACContext *c, uint8_t * const state){
return get_cabac_inline(c,state);
}
static int av_unused get_cabac(CABACContext *c, uint8_t * const state){
return get_cabac_inline(c,state);
}
static int av_unused get_cabac_bypass(CABACContext *c){
#if 0 //not faster
int bit;
__asm__ volatile(
"movl "RANGE "(%1), %%ebx \n\t"
"movl "LOW "(%1), %%eax \n\t"
"shl $17, %%ebx \n\t"
"add %%eax, %%eax \n\t"
"sub %%ebx, %%eax \n\t"
"cltd \n\t"
"and %%edx, %%ebx \n\t"
"add %%ebx, %%eax \n\t"
"test %%ax, %%ax \n\t"
" jnz 1f \n\t"
"movl "BYTE "(%1), %%"REG_b" \n\t"
"subl $0xFFFF, %%eax \n\t"
"movzwl (%%"REG_b"), %%ecx \n\t"
"bswap %%ecx \n\t"
"shrl $15, %%ecx \n\t"
"addl $2, %%"REG_b" \n\t"
"addl %%ecx, %%eax \n\t"
"movl %%"REG_b", "BYTE "(%1) \n\t"
"1: \n\t"
"movl %%eax, "LOW "(%1) \n\t"
:"=&d"(bit)
:"r"(c)
: "%eax", "%"REG_b, "%ecx", "memory"
);
return bit+1;
#else
int range;
c->low += c->low;
if(!(c->low & CABAC_MASK))
refill(c);
range= c->range<<(CABAC_BITS+1);
if(c->low < range){
return 0;
}else{
c->low -= range;
return 1;
}
#endif
}
static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){
#if ARCH_X86 && HAVE_EBX_AVAILABLE
__asm__ volatile(
"movl "RANGE "(%1), %%ebx \n\t"
"movl "LOW "(%1), %%eax \n\t"
"shl $17, %%ebx \n\t"
"add %%eax, %%eax \n\t"
"sub %%ebx, %%eax \n\t"
"cltd \n\t"
"and %%edx, %%ebx \n\t"
"add %%ebx, %%eax \n\t"
"xor %%edx, %%ecx \n\t"
"sub %%edx, %%ecx \n\t"
"test %%ax, %%ax \n\t"
" jnz 1f \n\t"
"mov "BYTE "(%1), %%"REG_b" \n\t"
"subl $0xFFFF, %%eax \n\t"
"movzwl (%%"REG_b"), %%edx \n\t"
"bswap %%edx \n\t"
"shrl $15, %%edx \n\t"
"add $2, %%"REG_b" \n\t"
"addl %%edx, %%eax \n\t"
"mov %%"REG_b", "BYTE "(%1) \n\t"
"1: \n\t"
"movl %%eax, "LOW "(%1) \n\t"
:"+c"(val)
:"r"(c)
: "%eax", "%"REG_b, "%edx", "memory"
);
return val;
#else
int range, mask;
c->low += c->low;
if(!(c->low & CABAC_MASK))
refill(c);
range= c->range<<(CABAC_BITS+1);
c->low -= range;
mask= c->low >> 31;
range &= mask;
c->low += range;
return (val^mask)-mask;
#endif
}
/**
*
* @return the number of bytes read or 0 if no end
*/
static int av_unused get_cabac_terminate(CABACContext *c){
c->range -= 2;
if(c->low < c->range<<(CABAC_BITS+1)){
renorm_cabac_decoder_once(c);
return 0;
}else{
return c->bytestream - c->bytestream_start;
}
}
#if 0
/**
* Get (truncated) unary binarization.
*/
static 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 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;
}
#endif /* 0 */
#endif /* AVCODEC_CABAC_H */
| 123linslouis-android-video-cutter | jni/libavcodec/cabac.h | C | asf20 | 24,470 |
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/mem.h"
#include "avfft.h"
#include "fft.h"
/* FFT */
FFTContext *av_fft_init(int nbits, int inverse)
{
FFTContext *s = av_malloc(sizeof(*s));
if (s)
ff_fft_init(s, nbits, inverse);
return s;
}
void av_fft_permute(FFTContext *s, FFTComplex *z)
{
s->fft_permute(s, z);
}
void av_fft_calc(FFTContext *s, FFTComplex *z)
{
s->fft_calc(s, z);
}
void av_fft_end(FFTContext *s)
{
if (s) {
ff_fft_end(s);
av_free(s);
}
}
#if CONFIG_MDCT
FFTContext *av_mdct_init(int nbits, int inverse, double scale)
{
FFTContext *s = av_malloc(sizeof(*s));
if (s)
ff_mdct_init(s, nbits, inverse, scale);
return s;
}
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
{
s->imdct_calc(s, output, input);
}
void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
{
s->imdct_half(s, output, input);
}
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
{
s->mdct_calc(s, output, input);
}
void av_mdct_end(FFTContext *s)
{
if (s) {
ff_mdct_end(s);
av_free(s);
}
}
#endif /* CONFIG_MDCT */
#if CONFIG_RDFT
RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
{
RDFTContext *s = av_malloc(sizeof(*s));
if (s)
ff_rdft_init(s, nbits, trans);
return s;
}
void av_rdft_calc(RDFTContext *s, FFTSample *data)
{
ff_rdft_calc(s, data);
}
void av_rdft_end(RDFTContext *s)
{
if (s) {
ff_rdft_end(s);
av_free(s);
}
}
#endif /* CONFIG_RDFT */
#if CONFIG_DCT
DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
{
DCTContext *s = av_malloc(sizeof(*s));
if (s)
ff_dct_init(s, nbits, inverse);
return s;
}
void av_dct_calc(DCTContext *s, FFTSample *data)
{
ff_dct_calc(s, data);
}
void av_dct_end(DCTContext *s)
{
if (s) {
ff_dct_end(s);
av_free(s);
}
}
#endif /* CONFIG_DCT */
| 123linslouis-android-video-cutter | jni/libavcodec/avfft.c | C | asf20 | 2,747 |
/*
* Copyright (c) 2010, Google, Inc.
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VP8 decoder support via libvpx
*/
#define VPX_CODEC_DISABLE_COMPAT 1
#include <vpx/vpx_decoder.h>
#include <vpx/vp8dx.h>
#include "avcodec.h"
typedef struct VP8DecoderContext {
struct vpx_codec_ctx decoder;
} VP8Context;
static av_cold int vp8_init(AVCodecContext *avctx)
{
VP8Context *ctx = avctx->priv_data;
const struct vpx_codec_iface *iface = &vpx_codec_vp8_dx_algo;
struct vpx_codec_dec_cfg deccfg = {
/* token partitions+1 would be a decent choice */
.threads = FFMIN(avctx->thread_count, 16)
};
av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
if (vpx_codec_dec_init(&ctx->decoder, iface, &deccfg, 0) != VPX_CODEC_OK) {
const char *error = vpx_codec_error(&ctx->decoder);
av_log(avctx, AV_LOG_ERROR, "Failed to initialize decoder: %s\n",
error);
return AVERROR(EINVAL);
}
avctx->pix_fmt = PIX_FMT_YUV420P;
return 0;
}
static int vp8_decode(AVCodecContext *avctx,
void *data, int *data_size, AVPacket *avpkt)
{
VP8Context *ctx = avctx->priv_data;
AVFrame *picture = data;
const void *iter = NULL;
struct vpx_image *img;
if (vpx_codec_decode(&ctx->decoder, avpkt->data, avpkt->size, NULL, 0) !=
VPX_CODEC_OK) {
const char *error = vpx_codec_error(&ctx->decoder);
const char *detail = vpx_codec_error_detail(&ctx->decoder);
av_log(avctx, AV_LOG_ERROR, "Failed to decode frame: %s\n", error);
if (detail)
av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n",
detail);
return AVERROR_INVALIDDATA;
}
if ((img = vpx_codec_get_frame(&ctx->decoder, &iter))) {
if (img->fmt != VPX_IMG_FMT_I420) {
av_log(avctx, AV_LOG_ERROR, "Unsupported output colorspace (%d)\n",
img->fmt);
return AVERROR_INVALIDDATA;
}
if ((int) img->d_w != avctx->width || (int) img->d_h != avctx->height) {
av_log(avctx, AV_LOG_INFO, "dimension change! %dx%d -> %dx%d\n",
avctx->width, avctx->height, img->d_w, img->d_h);
if (avcodec_check_dimensions(avctx, img->d_w, img->d_h))
return AVERROR_INVALIDDATA;
avcodec_set_dimensions(avctx, img->d_w, img->d_h);
}
picture->data[0] = img->planes[0];
picture->data[1] = img->planes[1];
picture->data[2] = img->planes[2];
picture->data[3] = NULL;
picture->linesize[0] = img->stride[0];
picture->linesize[1] = img->stride[1];
picture->linesize[2] = img->stride[2];
picture->linesize[3] = 0;
*data_size = sizeof(AVPicture);
}
return avpkt->size;
}
static av_cold int vp8_free(AVCodecContext *avctx)
{
VP8Context *ctx = avctx->priv_data;
vpx_codec_destroy(&ctx->decoder);
return 0;
}
AVCodec libvpx_decoder = {
"libvpx",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_VP8,
sizeof(VP8Context),
vp8_init,
NULL, /* encode */
vp8_free,
vp8_decode,
0, /* capabilities */
.long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/libvpxdec.c | C | asf20 | 4,062 |
/*
* DCA compatible decoder
* Copyright (C) 2004 Gildas Bazin
* Copyright (C) 2004 Benjamin Zores
* Copyright (C) 2006 Benjamin Larsson
* Copyright (C) 2007 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include "libavutil/intmath.h"
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "dsputil.h"
#include "fft.h"
#include "get_bits.h"
#include "put_bits.h"
#include "dcadata.h"
#include "dcahuff.h"
#include "dca.h"
#include "synth_filter.h"
#include "dcadsp.h"
//#define TRACE
#define DCA_PRIM_CHANNELS_MAX (5)
#define DCA_SUBBANDS (32)
#define DCA_ABITS_MAX (32) /* Should be 28 */
#define DCA_SUBSUBFAMES_MAX (4)
#define DCA_LFE_MAX (3)
enum DCAMode {
DCA_MONO = 0,
DCA_CHANNEL,
DCA_STEREO,
DCA_STEREO_SUMDIFF,
DCA_STEREO_TOTAL,
DCA_3F,
DCA_2F1R,
DCA_3F1R,
DCA_2F2R,
DCA_3F2R,
DCA_4F2R
};
/* Tables for mapping dts channel configurations to libavcodec multichannel api.
* Some compromises have been made for special configurations. Most configurations
* are never used so complete accuracy is not needed.
*
* L = left, R = right, C = center, S = surround, F = front, R = rear, T = total, OV = overhead.
* S -> side, when both rear and back are configured move one of them to the side channel
* OV -> center back
* All 2 channel configurations -> CH_LAYOUT_STEREO
*/
static const int64_t dca_core_channel_layout[] = {
CH_FRONT_CENTER, ///< 1, A
CH_LAYOUT_STEREO, ///< 2, A + B (dual mono)
CH_LAYOUT_STEREO, ///< 2, L + R (stereo)
CH_LAYOUT_STEREO, ///< 2, (L+R) + (L-R) (sum-difference)
CH_LAYOUT_STEREO, ///< 2, LT +RT (left and right total)
CH_LAYOUT_STEREO|CH_FRONT_CENTER, ///< 3, C+L+R
CH_LAYOUT_STEREO|CH_BACK_CENTER, ///< 3, L+R+S
CH_LAYOUT_STEREO|CH_FRONT_CENTER|CH_BACK_CENTER, ///< 4, C + L + R+ S
CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 4, L + R +SL+ SR
CH_LAYOUT_STEREO|CH_FRONT_CENTER|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 5, C + L + R+ SL+SR
CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER, ///< 6, CL + CR + L + R + SL + SR
CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT|CH_FRONT_CENTER|CH_BACK_CENTER, ///< 6, C + L + R+ LR + RR + OV
CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_FRONT_LEFT_OF_CENTER|CH_BACK_CENTER|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 6, CF+ CR+LF+ RF+LR + RR
CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR
CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_SIDE_RIGHT|CH_BACK_LEFT|CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2+ SR1 + SR2
CH_FRONT_LEFT_OF_CENTER|CH_FRONT_CENTER|CH_FRONT_RIGHT_OF_CENTER|CH_LAYOUT_STEREO|CH_SIDE_LEFT|CH_BACK_CENTER|CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR
};
static const int8_t dca_lfe_index[] = {
1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3
};
static const int8_t dca_channel_reorder_lfe[][8] = {
{ 0, -1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 2, 0, 1, -1, -1, -1, -1, -1},
{ 0, 1, 3, -1, -1, -1, -1, -1},
{ 2, 0, 1, 4, -1, -1, -1, -1},
{ 0, 1, 3, 4, -1, -1, -1, -1},
{ 2, 0, 1, 4, 5, -1, -1, -1},
{ 3, 4, 0, 1, 5, 6, -1, -1},
{ 2, 0, 1, 4, 5, 6, -1, -1},
{ 0, 6, 4, 5, 2, 3, -1, -1},
{ 4, 2, 5, 0, 1, 6, 7, -1},
{ 5, 6, 0, 1, 7, 3, 8, 4},
{ 4, 2, 5, 0, 1, 6, 8, 7},
};
static const int8_t dca_channel_reorder_nolfe[][8] = {
{ 0, -1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 0, 1, -1, -1, -1, -1, -1, -1},
{ 2, 0, 1, -1, -1, -1, -1, -1},
{ 0, 1, 2, -1, -1, -1, -1, -1},
{ 2, 0, 1, 3, -1, -1, -1, -1},
{ 0, 1, 2, 3, -1, -1, -1, -1},
{ 2, 0, 1, 3, 4, -1, -1, -1},
{ 2, 3, 0, 1, 4, 5, -1, -1},
{ 2, 0, 1, 3, 4, 5, -1, -1},
{ 0, 5, 3, 4, 1, 2, -1, -1},
{ 3, 2, 4, 0, 1, 5, 6, -1},
{ 4, 5, 0, 1, 6, 2, 7, 3},
{ 3, 2, 4, 0, 1, 5, 7, 6},
};
#define DCA_DOLBY 101 /* FIXME */
#define DCA_CHANNEL_BITS 6
#define DCA_CHANNEL_MASK 0x3F
#define DCA_LFE 0x80
#define HEADER_SIZE 14
#define DCA_MAX_FRAME_SIZE 16384
/** Bit allocation */
typedef struct {
int offset; ///< code values offset
int maxbits[8]; ///< max bits in VLC
int wrap; ///< wrap for get_vlc2()
VLC vlc[8]; ///< actual codes
} BitAlloc;
static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select
static BitAlloc dca_tmode; ///< transition mode VLCs
static BitAlloc dca_scalefactor; ///< scalefactor VLCs
static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs
static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
{
return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset;
}
typedef struct {
AVCodecContext *avctx;
/* Frame header */
int frame_type; ///< type of the current frame
int samples_deficit; ///< deficit sample count
int crc_present; ///< crc is present in the bitstream
int sample_blocks; ///< number of PCM sample blocks
int frame_size; ///< primary frame byte size
int amode; ///< audio channels arrangement
int sample_rate; ///< audio sampling rate
int bit_rate; ///< transmission bit rate
int bit_rate_index; ///< transmission bit rate index
int downmix; ///< embedded downmix enabled
int dynrange; ///< embedded dynamic range flag
int timestamp; ///< embedded time stamp flag
int aux_data; ///< auxiliary data flag
int hdcd; ///< source material is mastered in HDCD
int ext_descr; ///< extension audio descriptor flag
int ext_coding; ///< extended coding flag
int aspf; ///< audio sync word insertion flag
int lfe; ///< low frequency effects flag
int predictor_history; ///< predictor history flag
int header_crc; ///< header crc check bytes
int multirate_inter; ///< multirate interpolator switch
int version; ///< encoder software revision
int copy_history; ///< copy history
int source_pcm_res; ///< source pcm resolution
int front_sum; ///< front sum/difference flag
int surround_sum; ///< surround sum/difference flag
int dialog_norm; ///< dialog normalisation parameter
/* Primary audio coding header */
int subframes; ///< number of subframes
int total_channels; ///< number of channels including extensions
int prim_channels; ///< number of primary audio channels
int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count
int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband
int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index
int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book
int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select
int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment
/* Primary audio coding side information */
int subsubframes; ///< number of subsubframes
int partial_samples; ///< partial subsubframe samples count
int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)
int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs
int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index
int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients)
int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]; ///< scale factors (2 if transient)
int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook
int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]; ///< stereo downmix coefficients
int dynrange_coef; ///< dynamic range coefficient
int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands
float lfe_data[2 * DCA_SUBSUBFAMES_MAX * DCA_LFE_MAX *
2 /*history */ ]; ///< Low frequency effect data
int lfe_scale_factor;
/* Subband samples history (for ADPCM) */
float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4];
DECLARE_ALIGNED(16, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512];
DECLARE_ALIGNED(16, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32];
int hist_index[DCA_PRIM_CHANNELS_MAX];
DECLARE_ALIGNED(16, float, raXin)[32];
int output; ///< type of output
float add_bias; ///< output bias
float scale_bias; ///< output scale
DECLARE_ALIGNED(16, float, samples)[1536]; /* 6 * 256 = 1536, might only need 5 */
const float *samples_chanptr[6];
uint8_t dca_buffer[DCA_MAX_FRAME_SIZE];
int dca_buffer_size; ///< how much data is in the dca_buffer
const int8_t* channel_order_tab; ///< channel reordering table, lfe and non lfe
GetBitContext gb;
/* Current position in DCA frame */
int current_subframe;
int current_subsubframe;
int debug_flag; ///< used for suppressing repeated error messages output
DSPContext dsp;
FFTContext imdct;
SynthFilterContext synth;
DCADSPContext dcadsp;
} DCAContext;
static const uint16_t dca_vlc_offs[] = {
0, 512, 640, 768, 1282, 1794, 2436, 3080, 3770, 4454, 5364,
5372, 5380, 5388, 5392, 5396, 5412, 5420, 5428, 5460, 5492, 5508,
5572, 5604, 5668, 5796, 5860, 5892, 6412, 6668, 6796, 7308, 7564,
7820, 8076, 8620, 9132, 9388, 9910, 10166, 10680, 11196, 11726, 12240,
12752, 13298, 13810, 14326, 14840, 15500, 16022, 16540, 17158, 17678, 18264,
18796, 19352, 19926, 20468, 21472, 22398, 23014, 23622,
};
static av_cold void dca_init_vlcs(void)
{
static int vlcs_initialized = 0;
int i, j, c = 14;
static VLC_TYPE dca_table[23622][2];
if (vlcs_initialized)
return;
dca_bitalloc_index.offset = 1;
dca_bitalloc_index.wrap = 2;
for (i = 0; i < 5; i++) {
dca_bitalloc_index.vlc[i].table = &dca_table[dca_vlc_offs[i]];
dca_bitalloc_index.vlc[i].table_allocated = dca_vlc_offs[i + 1] - dca_vlc_offs[i];
init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
bitalloc_12_bits[i], 1, 1,
bitalloc_12_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
dca_scalefactor.offset = -64;
dca_scalefactor.wrap = 2;
for (i = 0; i < 5; i++) {
dca_scalefactor.vlc[i].table = &dca_table[dca_vlc_offs[i + 5]];
dca_scalefactor.vlc[i].table_allocated = dca_vlc_offs[i + 6] - dca_vlc_offs[i + 5];
init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
scales_bits[i], 1, 1,
scales_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
dca_tmode.offset = 0;
dca_tmode.wrap = 1;
for (i = 0; i < 4; i++) {
dca_tmode.vlc[i].table = &dca_table[dca_vlc_offs[i + 10]];
dca_tmode.vlc[i].table_allocated = dca_vlc_offs[i + 11] - dca_vlc_offs[i + 10];
init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
tmode_bits[i], 1, 1,
tmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
}
for(i = 0; i < 10; i++)
for(j = 0; j < 7; j++){
if(!bitalloc_codes[i][j]) break;
dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i];
dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4);
dca_smpl_bitalloc[i+1].vlc[j].table = &dca_table[dca_vlc_offs[c]];
dca_smpl_bitalloc[i+1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c];
init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j],
bitalloc_sizes[i],
bitalloc_bits[i][j], 1, 1,
bitalloc_codes[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC);
c++;
}
vlcs_initialized = 1;
}
static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
{
while(len--)
*dst++ = get_bits(gb, bits);
}
static int dca_parse_frame_header(DCAContext * s)
{
int i, j;
static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
/* Sync code */
get_bits(&s->gb, 32);
/* Frame header */
s->frame_type = get_bits(&s->gb, 1);
s->samples_deficit = get_bits(&s->gb, 5) + 1;
s->crc_present = get_bits(&s->gb, 1);
s->sample_blocks = get_bits(&s->gb, 7) + 1;
s->frame_size = get_bits(&s->gb, 14) + 1;
if (s->frame_size < 95)
return -1;
s->amode = get_bits(&s->gb, 6);
s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)];
if (!s->sample_rate)
return -1;
s->bit_rate_index = get_bits(&s->gb, 5);
s->bit_rate = dca_bit_rates[s->bit_rate_index];
if (!s->bit_rate)
return -1;
s->downmix = get_bits(&s->gb, 1);
s->dynrange = get_bits(&s->gb, 1);
s->timestamp = get_bits(&s->gb, 1);
s->aux_data = get_bits(&s->gb, 1);
s->hdcd = get_bits(&s->gb, 1);
s->ext_descr = get_bits(&s->gb, 3);
s->ext_coding = get_bits(&s->gb, 1);
s->aspf = get_bits(&s->gb, 1);
s->lfe = get_bits(&s->gb, 2);
s->predictor_history = get_bits(&s->gb, 1);
/* TODO: check CRC */
if (s->crc_present)
s->header_crc = get_bits(&s->gb, 16);
s->multirate_inter = get_bits(&s->gb, 1);
s->version = get_bits(&s->gb, 4);
s->copy_history = get_bits(&s->gb, 2);
s->source_pcm_res = get_bits(&s->gb, 3);
s->front_sum = get_bits(&s->gb, 1);
s->surround_sum = get_bits(&s->gb, 1);
s->dialog_norm = get_bits(&s->gb, 4);
/* FIXME: channels mixing levels */
s->output = s->amode;
if(s->lfe) s->output |= DCA_LFE;
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type);
av_log(s->avctx, AV_LOG_DEBUG, "samples deficit: %i\n", s->samples_deficit);
av_log(s->avctx, AV_LOG_DEBUG, "crc present: %i\n", s->crc_present);
av_log(s->avctx, AV_LOG_DEBUG, "sample blocks: %i (%i samples)\n",
s->sample_blocks, s->sample_blocks * 32);
av_log(s->avctx, AV_LOG_DEBUG, "frame size: %i bytes\n", s->frame_size);
av_log(s->avctx, AV_LOG_DEBUG, "amode: %i (%i channels)\n",
s->amode, dca_channels[s->amode]);
av_log(s->avctx, AV_LOG_DEBUG, "sample rate: %i Hz\n",
s->sample_rate);
av_log(s->avctx, AV_LOG_DEBUG, "bit rate: %i bits/s\n",
s->bit_rate);
av_log(s->avctx, AV_LOG_DEBUG, "downmix: %i\n", s->downmix);
av_log(s->avctx, AV_LOG_DEBUG, "dynrange: %i\n", s->dynrange);
av_log(s->avctx, AV_LOG_DEBUG, "timestamp: %i\n", s->timestamp);
av_log(s->avctx, AV_LOG_DEBUG, "aux_data: %i\n", s->aux_data);
av_log(s->avctx, AV_LOG_DEBUG, "hdcd: %i\n", s->hdcd);
av_log(s->avctx, AV_LOG_DEBUG, "ext descr: %i\n", s->ext_descr);
av_log(s->avctx, AV_LOG_DEBUG, "ext coding: %i\n", s->ext_coding);
av_log(s->avctx, AV_LOG_DEBUG, "aspf: %i\n", s->aspf);
av_log(s->avctx, AV_LOG_DEBUG, "lfe: %i\n", s->lfe);
av_log(s->avctx, AV_LOG_DEBUG, "predictor history: %i\n",
s->predictor_history);
av_log(s->avctx, AV_LOG_DEBUG, "header crc: %i\n", s->header_crc);
av_log(s->avctx, AV_LOG_DEBUG, "multirate inter: %i\n",
s->multirate_inter);
av_log(s->avctx, AV_LOG_DEBUG, "version number: %i\n", s->version);
av_log(s->avctx, AV_LOG_DEBUG, "copy history: %i\n", s->copy_history);
av_log(s->avctx, AV_LOG_DEBUG,
"source pcm resolution: %i (%i bits/sample)\n",
s->source_pcm_res, dca_bits_per_sample[s->source_pcm_res]);
av_log(s->avctx, AV_LOG_DEBUG, "front sum: %i\n", s->front_sum);
av_log(s->avctx, AV_LOG_DEBUG, "surround sum: %i\n", s->surround_sum);
av_log(s->avctx, AV_LOG_DEBUG, "dialog norm: %i\n", s->dialog_norm);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
#endif
/* Primary audio coding header */
s->subframes = get_bits(&s->gb, 4) + 1;
s->total_channels = get_bits(&s->gb, 3) + 1;
s->prim_channels = s->total_channels;
if (s->prim_channels > DCA_PRIM_CHANNELS_MAX)
s->prim_channels = DCA_PRIM_CHANNELS_MAX; /* We only support DTS core */
for (i = 0; i < s->prim_channels; i++) {
s->subband_activity[i] = get_bits(&s->gb, 5) + 2;
if (s->subband_activity[i] > DCA_SUBBANDS)
s->subband_activity[i] = DCA_SUBBANDS;
}
for (i = 0; i < s->prim_channels; i++) {
s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
if (s->vq_start_subband[i] > DCA_SUBBANDS)
s->vq_start_subband[i] = DCA_SUBBANDS;
}
get_array(&s->gb, s->joint_intensity, s->prim_channels, 3);
get_array(&s->gb, s->transient_huffman, s->prim_channels, 2);
get_array(&s->gb, s->scalefactor_huffman, s->prim_channels, 3);
get_array(&s->gb, s->bitalloc_huffman, s->prim_channels, 3);
/* Get codebooks quantization indexes */
memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));
for (j = 1; j < 11; j++)
for (i = 0; i < s->prim_channels; i++)
s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
/* Get scale factor adjustment */
for (j = 0; j < 11; j++)
for (i = 0; i < s->prim_channels; i++)
s->scalefactor_adj[i][j] = 1;
for (j = 1; j < 11; j++)
for (i = 0; i < s->prim_channels; i++)
if (s->quant_index_huffman[i][j] < thr[j])
s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
if (s->crc_present) {
/* Audio header CRC check */
get_bits(&s->gb, 16);
}
s->current_subframe = 0;
s->current_subsubframe = 0;
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes);
av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels);
for(i = 0; i < s->prim_channels; i++){
av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]);
av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]);
av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]);
av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]);
av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]);
av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]);
av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:");
for (j = 0; j < 11; j++)
av_log(s->avctx, AV_LOG_DEBUG, " %i",
s->quant_index_huffman[i][j]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:");
for (j = 0; j < 11; j++)
av_log(s->avctx, AV_LOG_DEBUG, " %1.3f", s->scalefactor_adj[i][j]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
#endif
return 0;
}
static inline int get_scale(GetBitContext *gb, int level, int value)
{
if (level < 5) {
/* huffman encoded */
value += get_bitalloc(gb, &dca_scalefactor, level);
} else if(level < 8)
value = get_bits(gb, level + 1);
return value;
}
static int dca_subframe_header(DCAContext * s)
{
/* Primary audio coding side information */
int j, k;
s->subsubframes = get_bits(&s->gb, 2) + 1;
s->partial_samples = get_bits(&s->gb, 3);
for (j = 0; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++)
s->prediction_mode[j][k] = get_bits(&s->gb, 1);
}
/* Get prediction codebook */
for (j = 0; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++) {
if (s->prediction_mode[j][k] > 0) {
/* (Prediction coefficient VQ address) */
s->prediction_vq[j][k] = get_bits(&s->gb, 12);
}
}
}
/* Bit allocation index */
for (j = 0; j < s->prim_channels; j++) {
for (k = 0; k < s->vq_start_subband[j]; k++) {
if (s->bitalloc_huffman[j] == 6)
s->bitalloc[j][k] = get_bits(&s->gb, 5);
else if (s->bitalloc_huffman[j] == 5)
s->bitalloc[j][k] = get_bits(&s->gb, 4);
else if (s->bitalloc_huffman[j] == 7) {
av_log(s->avctx, AV_LOG_ERROR,
"Invalid bit allocation index\n");
return -1;
} else {
s->bitalloc[j][k] =
get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
}
if (s->bitalloc[j][k] > 26) {
// av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n",
// j, k, s->bitalloc[j][k]);
return -1;
}
}
}
/* Transition mode */
for (j = 0; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++) {
s->transition_mode[j][k] = 0;
if (s->subsubframes > 1 &&
k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
s->transition_mode[j][k] =
get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
}
}
}
for (j = 0; j < s->prim_channels; j++) {
const uint32_t *scale_table;
int scale_sum;
memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
if (s->scalefactor_huffman[j] == 6)
scale_table = scale_factor_quant7;
else
scale_table = scale_factor_quant6;
/* When huffman coded, only the difference is encoded */
scale_sum = 0;
for (k = 0; k < s->subband_activity[j]; k++) {
if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
s->scale_factor[j][k][0] = scale_table[scale_sum];
}
if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
/* Get second scale factor */
scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
s->scale_factor[j][k][1] = scale_table[scale_sum];
}
}
}
/* Joint subband scale factor codebook select */
for (j = 0; j < s->prim_channels; j++) {
/* Transmitted only if joint subband coding enabled */
if (s->joint_intensity[j] > 0)
s->joint_huff[j] = get_bits(&s->gb, 3);
}
/* Scale factors for joint subband coding */
for (j = 0; j < s->prim_channels; j++) {
int source_channel;
/* Transmitted only if joint subband coding enabled */
if (s->joint_intensity[j] > 0) {
int scale = 0;
source_channel = s->joint_intensity[j] - 1;
/* When huffman coded, only the difference is encoded
* (is this valid as well for joint scales ???) */
for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
scale = get_scale(&s->gb, s->joint_huff[j], 0);
scale += 64; /* bias */
s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */
}
if (!(s->debug_flag & 0x02)) {
av_log(s->avctx, AV_LOG_DEBUG,
"Joint stereo coding not supported\n");
s->debug_flag |= 0x02;
}
}
}
/* Stereo downmix coefficients */
if (s->prim_channels > 2) {
if(s->downmix) {
for (j = 0; j < s->prim_channels; j++) {
s->downmix_coef[j][0] = get_bits(&s->gb, 7);
s->downmix_coef[j][1] = get_bits(&s->gb, 7);
}
} else {
int am = s->amode & DCA_CHANNEL_MASK;
for (j = 0; j < s->prim_channels; j++) {
s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
}
}
}
/* Dynamic range coefficient */
if (s->dynrange)
s->dynrange_coef = get_bits(&s->gb, 8);
/* Side information CRC check word */
if (s->crc_present) {
get_bits(&s->gb, 16);
}
/*
* Primary audio data arrays
*/
/* VQ encoded high frequency subbands */
for (j = 0; j < s->prim_channels; j++)
for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
/* 1 vector -> 32 samples */
s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
/* Low frequency effect data */
if (s->lfe) {
/* LFE samples */
int lfe_samples = 2 * s->lfe * s->subsubframes;
float lfe_scale;
for (j = lfe_samples; j < lfe_samples * 2; j++) {
/* Signed 8 bits int */
s->lfe_data[j] = get_sbits(&s->gb, 8);
}
/* Scale factor index */
s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];
/* Quantization step size * scale factor */
lfe_scale = 0.035 * s->lfe_scale_factor;
for (j = lfe_samples; j < lfe_samples * 2; j++)
s->lfe_data[j] *= lfe_scale;
}
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes);
av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
s->partial_samples);
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = 0; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG,
"prediction coefs: %f, %f, %f, %f\n",
(float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
}
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
for (k = 0; k < s->vq_start_subband[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
for (k = 0; k < s->subband_activity[j]; k++) {
if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = 0; j < s->prim_channels; j++) {
if (s->joint_intensity[j] > 0) {
int source_channel = s->joint_intensity[j] - 1;
av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
}
if (s->prim_channels > 2 && s->downmix) {
av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);
av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = 0; j < s->prim_channels; j++)
for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
if(s->lfe){
int lfe_samples = 2 * s->lfe * s->subsubframes;
av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
for (j = lfe_samples; j < lfe_samples * 2; j++)
av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
#endif
return 0;
}
static void qmf_32_subbands(DCAContext * s, int chans,
float samples_in[32][8], float *samples_out,
float scale, float bias)
{
const float *prCoeff;
int i;
int sb_act = s->subband_activity[chans];
int subindex;
scale *= sqrt(1/8.0);
/* Select filter */
if (!s->multirate_inter) /* Non-perfect reconstruction */
prCoeff = fir_32bands_nonperfect;
else /* Perfect reconstruction */
prCoeff = fir_32bands_perfect;
/* Reconstructed channel sample index */
for (subindex = 0; subindex < 8; subindex++) {
/* Load in one sample from each subband and clear inactive subbands */
for (i = 0; i < sb_act; i++){
uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30;
AV_WN32A(&s->raXin[i], v);
}
for (; i < 32; i++)
s->raXin[i] = 0.0;
s->synth.synth_filter_float(&s->imdct,
s->subband_fir_hist[chans], &s->hist_index[chans],
s->subband_fir_noidea[chans], prCoeff,
samples_out, s->raXin, scale, bias);
samples_out+= 32;
}
}
static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
int num_deci_sample, float *samples_in,
float *samples_out, float scale,
float bias)
{
/* samples_in: An array holding decimated samples.
* Samples in current subframe starts from samples_in[0],
* while samples_in[-1], samples_in[-2], ..., stores samples
* from last subframe as history.
*
* samples_out: An array holding interpolated samples
*/
int decifactor;
const float *prCoeff;
int deciindex;
/* Select decimation filter */
if (decimation_select == 1) {
decifactor = 64;
prCoeff = lfe_fir_128;
} else {
decifactor = 32;
prCoeff = lfe_fir_64;
}
/* Interpolation */
for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor,
scale, bias);
samples_in++;
samples_out += 2 * decifactor;
}
}
/* downmixing routines */
#define MIX_REAR1(samples, si1, rs, coef) \
samples[i] += samples[si1] * coef[rs][0]; \
samples[i+256] += samples[si1] * coef[rs][1];
#define MIX_REAR2(samples, si1, si2, rs, coef) \
samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \
samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1];
#define MIX_FRONT3(samples, coef) \
t = samples[i]; \
samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \
samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1];
#define DOWNMIX_TO_STEREO(op1, op2) \
for(i = 0; i < 256; i++){ \
op1 \
op2 \
}
static void dca_downmix(float *samples, int srcfmt,
int downmix_coef[DCA_PRIM_CHANNELS_MAX][2])
{
int i;
float t;
float coef[DCA_PRIM_CHANNELS_MAX][2];
for(i=0; i<DCA_PRIM_CHANNELS_MAX; i++) {
coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]];
coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]];
}
switch (srcfmt) {
case DCA_MONO:
case DCA_CHANNEL:
case DCA_STEREO_TOTAL:
case DCA_STEREO_SUMDIFF:
case DCA_4F2R:
av_log(NULL, 0, "Not implemented!\n");
break;
case DCA_STEREO:
break;
case DCA_3F:
DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),);
break;
case DCA_2F1R:
DOWNMIX_TO_STEREO(MIX_REAR1(samples, i + 512, 2, coef),);
break;
case DCA_3F1R:
DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
MIX_REAR1(samples, i + 768, 3, coef));
break;
case DCA_2F2R:
DOWNMIX_TO_STEREO(MIX_REAR2(samples, i + 512, i + 768, 2, coef),);
break;
case DCA_3F2R:
DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
MIX_REAR2(samples, i + 768, i + 1024, 3, coef));
break;
}
}
/* Very compact version of the block code decoder that does not use table
* look-up but is slightly slower */
static int decode_blockcode(int code, int levels, int *values)
{
int i;
int offset = (levels - 1) >> 1;
for (i = 0; i < 4; i++) {
int div = FASTDIV(code, levels);
values[i] = code - offset - div*levels;
code = div;
}
if (code == 0)
return 0;
else {
av_log(NULL, AV_LOG_ERROR, "ERROR: block code look-up failed\n");
return -1;
}
}
static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
static int dca_subsubframe(DCAContext * s)
{
int k, l;
int subsubframe = s->current_subsubframe;
const float *quant_step_table;
/* FIXME */
LOCAL_ALIGNED_16(float, subband_samples, [DCA_PRIM_CHANNELS_MAX], [DCA_SUBBANDS][8]);
LOCAL_ALIGNED_16(int, block, [8]);
/*
* Audio data
*/
/* Select quantization step size table */
if (s->bit_rate_index == 0x1f)
quant_step_table = lossless_quant_d;
else
quant_step_table = lossy_quant_d;
for (k = 0; k < s->prim_channels; k++) {
for (l = 0; l < s->vq_start_subband[k]; l++) {
int m;
/* Select the mid-tread linear quantizer */
int abits = s->bitalloc[k][l];
float quant_step_size = quant_step_table[abits];
/*
* Determine quantization index code book and its type
*/
/* Select quantization index code book */
int sel = s->quant_index_huffman[k][abits];
/*
* Extract bits from the bit stream
*/
if(!abits){
memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0]));
} else {
/* Deal with transients */
int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l];
float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel];
if(abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){
if(abits <= 7){
/* Block code */
int block_code1, block_code2, size, levels;
size = abits_sizes[abits-1];
levels = abits_levels[abits-1];
block_code1 = get_bits(&s->gb, size);
/* FIXME Should test return value */
decode_blockcode(block_code1, levels, block);
block_code2 = get_bits(&s->gb, size);
decode_blockcode(block_code2, levels, &block[4]);
}else{
/* no coding */
for (m = 0; m < 8; m++)
block[m] = get_sbits(&s->gb, abits - 3);
}
}else{
/* Huffman coded */
for (m = 0; m < 8; m++)
block[m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel);
}
s->dsp.int32_to_float_fmul_scalar(subband_samples[k][l],
block, rscale, 8);
}
/*
* Inverse ADPCM if in prediction mode
*/
if (s->prediction_mode[k][l]) {
int n;
for (m = 0; m < 8; m++) {
for (n = 1; n <= 4; n++)
if (m >= n)
subband_samples[k][l][m] +=
(adpcm_vb[s->prediction_vq[k][l]][n - 1] *
subband_samples[k][l][m - n] / 8192);
else if (s->predictor_history)
subband_samples[k][l][m] +=
(adpcm_vb[s->prediction_vq[k][l]][n - 1] *
s->subband_samples_hist[k][l][m - n +
4] / 8192);
}
}
}
/*
* Decode VQ encoded high frequencies
*/
for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) {
/* 1 vector -> 32 samples but we only need the 8 samples
* for this subsubframe. */
int m;
if (!s->debug_flag & 0x01) {
av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n");
s->debug_flag |= 0x01;
}
for (m = 0; m < 8; m++) {
subband_samples[k][l][m] =
high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 +
m]
* (float) s->scale_factor[k][l][0] / 16.0;
}
}
}
/* Check for DSYNC after subsubframe */
if (s->aspf || subsubframe == s->subsubframes - 1) {
if (0xFFFF == get_bits(&s->gb, 16)) { /* 0xFFFF */
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "Got subframe DSYNC\n");
#endif
} else {
av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
}
}
/* Backup predictor history for adpcm */
for (k = 0; k < s->prim_channels; k++)
for (l = 0; l < s->vq_start_subband[k]; l++)
memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4],
4 * sizeof(subband_samples[0][0][0]));
/* 32 subbands QMF */
for (k = 0; k < s->prim_channels; k++) {
/* static float pcm_to_double[8] =
{32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/
qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * s->channel_order_tab[k]],
M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ ,
s->add_bias );
}
/* Down mixing */
if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) {
dca_downmix(s->samples, s->amode, s->downmix_coef);
}
/* Generate LFE samples for this subsubframe FIXME!!! */
if (s->output & DCA_LFE) {
int lfe_samples = 2 * s->lfe * s->subsubframes;
lfe_interpolation_fir(s, s->lfe, 2 * s->lfe,
s->lfe_data + lfe_samples +
2 * s->lfe * subsubframe,
&s->samples[256 * dca_lfe_index[s->amode]],
(1.0/256.0)*s->scale_bias, s->add_bias);
/* Outputs 20bits pcm samples */
}
return 0;
}
static int dca_subframe_footer(DCAContext * s)
{
int aux_data_count = 0, i;
int lfe_samples;
/*
* Unpack optional information
*/
if (s->timestamp)
get_bits(&s->gb, 32);
if (s->aux_data)
aux_data_count = get_bits(&s->gb, 6);
for (i = 0; i < aux_data_count; i++)
get_bits(&s->gb, 8);
if (s->crc_present && (s->downmix || s->dynrange))
get_bits(&s->gb, 16);
lfe_samples = 2 * s->lfe * s->subsubframes;
for (i = 0; i < lfe_samples; i++) {
s->lfe_data[i] = s->lfe_data[i + lfe_samples];
}
return 0;
}
/**
* Decode a dca frame block
*
* @param s pointer to the DCAContext
*/
static int dca_decode_block(DCAContext * s)
{
/* Sanity check */
if (s->current_subframe >= s->subframes) {
av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",
s->current_subframe, s->subframes);
return -1;
}
if (!s->current_subsubframe) {
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n");
#endif
/* Read subframe header */
if (dca_subframe_header(s))
return -1;
}
/* Read subsubframe */
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n");
#endif
if (dca_subsubframe(s))
return -1;
/* Update state */
s->current_subsubframe++;
if (s->current_subsubframe >= s->subsubframes) {
s->current_subsubframe = 0;
s->current_subframe++;
}
if (s->current_subframe >= s->subframes) {
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n");
#endif
/* Read subframe footer */
if (dca_subframe_footer(s))
return -1;
}
return 0;
}
/**
* Convert bitstream to one representation based on sync marker
*/
static int dca_convert_bitstream(const uint8_t * src, int src_size, uint8_t * dst,
int max_size)
{
uint32_t mrk;
int i, tmp;
const uint16_t *ssrc = (const uint16_t *) src;
uint16_t *sdst = (uint16_t *) dst;
PutBitContext pb;
if((unsigned)src_size > (unsigned)max_size) {
// av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n");
// return -1;
src_size = max_size;
}
mrk = AV_RB32(src);
switch (mrk) {
case DCA_MARKER_RAW_BE:
memcpy(dst, src, src_size);
return src_size;
case DCA_MARKER_RAW_LE:
for (i = 0; i < (src_size + 1) >> 1; i++)
*sdst++ = bswap_16(*ssrc++);
return src_size;
case DCA_MARKER_14B_BE:
case DCA_MARKER_14B_LE:
init_put_bits(&pb, dst, max_size);
for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
put_bits(&pb, 14, tmp);
}
flush_put_bits(&pb);
return (put_bits_count(&pb) + 7) >> 3;
default:
return -1;
}
}
/**
* Main frame decoding function
* FIXME add arguments
*/
static int dca_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
int i;
int16_t *samples = data;
DCAContext *s = avctx->priv_data;
int channels;
s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE);
if (s->dca_buffer_size == -1) {
av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
return -1;
}
init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
if (dca_parse_frame_header(s) < 0) {
//seems like the frame is corrupt, try with the next one
*data_size=0;
return buf_size;
}
//set AVCodec values with parsed data
avctx->sample_rate = s->sample_rate;
avctx->bit_rate = s->bit_rate;
channels = s->prim_channels + !!s->lfe;
if (s->amode<16) {
avctx->channel_layout = dca_core_channel_layout[s->amode];
if (s->lfe) {
avctx->channel_layout |= CH_LOW_FREQUENCY;
s->channel_order_tab = dca_channel_reorder_lfe[s->amode];
} else
s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
if (s->prim_channels > 0 &&
s->channel_order_tab[s->prim_channels - 1] < 0)
return -1;
if(avctx->request_channels == 2 && s->prim_channels > 2) {
channels = 2;
s->output = DCA_STEREO;
avctx->channel_layout = CH_LAYOUT_STEREO;
}
} else {
av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode);
return -1;
}
/* There is nothing that prevents a dts frame to change channel configuration
but FFmpeg doesn't support that so only set the channels if it is previously
unset. Ideally during the first probe for channels the crc should be checked
and only set avctx->channels when the crc is ok. Right now the decoder could
set the channels based on a broken first frame.*/
if (!avctx->channels)
avctx->channels = channels;
if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)
return -1;
*data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels;
for (i = 0; i < (s->sample_blocks / 8); i++) {
dca_decode_block(s);
s->dsp.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels);
samples += 256 * channels;
}
return buf_size;
}
/**
* DCA initialization
*
* @param avctx pointer to the AVCodecContext
*/
static av_cold int dca_decode_init(AVCodecContext * avctx)
{
DCAContext *s = avctx->priv_data;
int i;
s->avctx = avctx;
dca_init_vlcs();
dsputil_init(&s->dsp, avctx);
ff_mdct_init(&s->imdct, 6, 1, 1.0);
ff_synth_filter_init(&s->synth);
ff_dcadsp_init(&s->dcadsp);
for(i = 0; i < 6; i++)
s->samples_chanptr[i] = s->samples + i * 256;
avctx->sample_fmt = SAMPLE_FMT_S16;
if(s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
s->add_bias = 385.0f;
s->scale_bias = 1.0 / 32768.0;
} else {
s->add_bias = 0.0f;
s->scale_bias = 1.0;
/* allow downmixing to stereo */
if (avctx->channels > 0 && avctx->request_channels < avctx->channels &&
avctx->request_channels == 2) {
avctx->channels = avctx->request_channels;
}
}
return 0;
}
static av_cold int dca_decode_end(AVCodecContext * avctx)
{
DCAContext *s = avctx->priv_data;
ff_mdct_end(&s->imdct);
return 0;
}
AVCodec dca_decoder = {
.name = "dca",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_DTS,
.priv_data_size = sizeof(DCAContext),
.init = dca_decode_init,
.decode = dca_decode_frame,
.close = dca_decode_end,
.long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/dca.c | C | asf20 | 49,552 |
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
*@brief IntraX8 frame subdecoder image manipulation routines
*/
#include "dsputil.h"
/*
area positions, #3 is 1 pixel only, other are 8 pixels
|66666666|
3|44444444|55555555|
- -+--------+--------+
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
1 2|XXXXXXXX|
^-start
*/
#define area1 (0)
#define area2 (8)
#define area3 (8+8)
#define area4 (8+8+1)
#define area5 (8+8+1+8)
#define area6 (8+8+1+16)
/**
Collect statistics and prepare the edge pixels required by the other spatial compensation functions.
* @param src pointer to the beginning of the processed block
* @param dst pointer to emu_edge, edge pixels are stored the way other compensation routines do.
* @param linesize byte offset between 2 vertical pixels in the source image
* @param range pointer to the variable where the edge pixel range is to be stored (max-min values)
* @param psum pointer to the variable where the edge pixel sum is to be stored
* @param edges Informs this routine that the block is on an image border, so it has to interpolate the missing edge pixels.
and some of the edge pixels should be interpolated, the flag has the following meaning:
1 - mb_x==0 - first block in the row, interpolate area #1,#2,#3;
2 - mb_y==0 - first row, interpolate area #3,#4,#5,#6;
note: 1|2 - mb_x==mb_y==0 - first block, use 0x80 value for all areas;
4 - mb_x>= (mb_width-1) last block in the row, interpolate area #5;
*/
static void x8_setup_spatial_compensation(uint8_t *src, uint8_t *dst, int linesize,
int * range, int * psum, int edges){
uint8_t * ptr;
int sum;
int i;
int min_pix,max_pix;
uint8_t c;
if((edges&3)==3){
*psum=0x80*(8+1+8+2);
*range=0;
memset(dst,0x80,16+1+16+8);
//this triggers flat_dc for sure.
//flat_dc avoids all (other) prediction modes, but requires dc_level decoding.
return;
}
min_pix=256;
max_pix=-1;
sum=0;
if(!(edges&1)){//(mb_x!=0)//there is previous block on this row
ptr=src-1;//left column, area 2
for(i=7;i>=0;i--){
c=*(ptr-1);//area1, same mb as area2, no need to check
dst[area1+i]=c;
c=*(ptr);
sum+=c;
min_pix=FFMIN(min_pix,c);
max_pix=FFMAX(max_pix,c);
dst[area2+i]=c;
ptr+=linesize;
}
}
if(!(edges&2)){ //(mb_y!=0)//there is row above
ptr=src-linesize;//top line
for(i=0;i<8;i++){
c=*(ptr+i);
sum+=c;
min_pix=FFMIN(min_pix, c);
max_pix=FFMAX(max_pix, c);
}
if(edges&4){//last block on the row?
memset(dst+area5,c,8);//set with last pixel fr
memcpy(dst+area4, ptr, 8);
}else{
memcpy(dst+area4, ptr, 16);//both area4 and 5
}
memcpy(dst+area6, ptr-linesize, 8);//area6 always present in the above block
}
//now calculate the stuff we need
if(edges&3){//mb_x==0 || mb_y==0){
int avg=(sum+4)>>3;
if(edges&1){ //(mb_x==0) {//implies mb_y!=0
memset(dst+area1,avg,8+8+1);//areas 1,2 and 3 are averaged
}else{//implies y==0 x!=0
memset(dst+area3,avg, 1+16+8);//areas 3, 4,5,6
}
sum+=avg*9;
}else{
uint8_t c=*(src-1-linesize);//the edge pixel, in the top line and left column
dst[area3]=c;
sum+=c;
//edge pixel is not part of min/max
}
(*range) = max_pix - min_pix;
sum += *(dst+area5) + *(dst+area5+1);
*psum = sum;
}
static const uint16_t zero_prediction_weights[64*2] = {
640, 640, 669, 480, 708, 354, 748, 257, 792, 198, 760, 143, 808, 101, 772, 72,
480, 669, 537, 537, 598, 416, 661, 316, 719, 250, 707, 185, 768, 134, 745, 97,
354, 708, 416, 598, 488, 488, 564, 388, 634, 317, 642, 241, 716, 179, 706, 132,
257, 748, 316, 661, 388, 564, 469, 469, 543, 395, 571, 311, 655, 238, 660, 180,
198, 792, 250, 719, 317, 634, 395, 543, 469, 469, 507, 380, 597, 299, 616, 231,
161, 855, 206, 788, 266, 710, 340, 623, 411, 548, 455, 455, 548, 366, 576, 288,
122, 972, 159, 914, 211, 842, 276, 758, 341, 682, 389, 584, 483, 483, 520, 390,
110, 1172, 144, 1107, 193, 1028, 254, 932, 317, 846, 366, 731, 458, 611, 499, 499
};
static void spatial_compensation_0(uint8_t *src , uint8_t *dst, int linesize){
int i,j;
int x,y;
unsigned int p;//power divided by 2
int a;
uint16_t left_sum[2][8];
uint16_t top_sum[2][8];
memset(left_sum,0,2*8*sizeof(uint16_t));
memset( top_sum,0,2*8*sizeof(uint16_t));
for(i=0;i<8;i++){
a=src[area2+7-i]<<4;
for(j=0;j<8;j++){
p=abs(i-j);
left_sum[p&1][j]+= a>>(p>>1);
}
}
for(i=0;i<8;i++){
a=src[area4+i]<<4;
for(j=0;j<8;j++){
p=abs(i-j);
top_sum[p&1][j]+= a>>(p>>1);
}
}
for(;i<10;i++){
a=src[area4+i]<<4;
for(j=5;j<8;j++){
p=abs(i-j);
top_sum[p&1][j]+= a>>(p>>1);
}
}
for(;i<12;i++){
a=src[area4+i]<<4;
for(j=7;j<8;j++){
p=abs(i-j);
top_sum[p&1][j]+= a>>(p>>1);
}
}
for(i=0;i<8;i++){
top_sum [0][i]+=(top_sum [1][i]*181 + 128 )>>8;//181 is sqrt(2)/2
left_sum[0][i]+=(left_sum[1][i]*181 + 128 )>>8;
}
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x] = (
(uint32_t)top_sum [0][x]*zero_prediction_weights[y*16+x*2+0] +
(uint32_t)left_sum[0][y]*zero_prediction_weights[y*16+x*2+1] +
0x8000
)>>16;
}
dst+=linesize;
}
}
static void spatial_compensation_1(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=src[area4 + FFMIN(2*y+x+2, 15) ];
}
dst+=linesize;
}
}
static void spatial_compensation_2(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=src[area4 +1+y+x];
}
dst+=linesize;
}
}
static void spatial_compensation_3(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=src[area4 +((y+1)>>1)+x];
}
dst+=linesize;
}
}
static void spatial_compensation_4(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=( src[area4+x] + src[area6+x] + 1 )>>1;
}
dst+=linesize;
}
}
static void spatial_compensation_5(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
if(2*x-y<0){
dst[x]=src[area2+9+2*x-y];
}else{
dst[x]=src[area4 +x-((y+1)>>1)];
}
}
dst+=linesize;
}
}
static void spatial_compensation_6(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=src[area3+x-y];
}
dst+=linesize;
}
}
static void spatial_compensation_7(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
if(x-2*y>0){
dst[x]=( src[area3-1+x-2*y] + src[area3+x-2*y] + 1)>>1;
}else{
dst[x]=src[area2+8-y +(x>>1)];
}
}
dst+=linesize;
}
}
static void spatial_compensation_8(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=( src[area1+7-y] + src[area2+7-y] + 1 )>>1;
}
dst+=linesize;
}
}
static void spatial_compensation_9(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=src[area2+6-FFMIN(x+y,6)];
}
dst+=linesize;
}
}
static void spatial_compensation_10(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=(src[area2+7-y]*(8-x)+src[area4+x]*x+4)>>3;
}
dst+=linesize;
}
}
static void spatial_compensation_11(uint8_t *src , uint8_t *dst, int linesize){
int x,y;
for(y=0;y<8;y++){
for(x=0;x<8;x++){
dst[x]=(src[area2+7-y]*y+src[area4+x]*(8-y)+4)>>3;
}
dst+=linesize;
}
}
static void x8_loop_filter(uint8_t * ptr, const int a_stride, const int b_stride, int quant){
int i,t;
int p0,p1,p2,p3,p4,p5,p6,p7,p8,p9;
int ql=(quant+10)>>3;
for(i=0; i<8; i++,ptr+=b_stride){
p0=ptr[-5*a_stride];
p1=ptr[-4*a_stride];
p2=ptr[-3*a_stride];
p3=ptr[-2*a_stride];
p4=ptr[-1*a_stride];
p5=ptr[ 0 ];
p6=ptr[ 1*a_stride];
p7=ptr[ 2*a_stride];
p8=ptr[ 3*a_stride];
p9=ptr[ 4*a_stride];
t=
(FFABS(p1-p2) <= ql) +
(FFABS(p2-p3) <= ql) +
(FFABS(p3-p4) <= ql) +
(FFABS(p4-p5) <= ql);
if(t>0){//You need at least 1 to be able to reach a total score of 6.
t+=
(FFABS(p5-p6) <= ql) +
(FFABS(p6-p7) <= ql) +
(FFABS(p7-p8) <= ql) +
(FFABS(p8-p9) <= ql) +
(FFABS(p0-p1) <= ql);
if(t>=6){
int min,max;
min=max=p1;
min=FFMIN(min,p3); max=FFMAX(max,p3);
min=FFMIN(min,p5); max=FFMAX(max,p5);
min=FFMIN(min,p8); max=FFMAX(max,p8);
if(max-min<2*quant){//early stop
min=FFMIN(min,p2); max=FFMAX(max,p2);
min=FFMIN(min,p4); max=FFMAX(max,p4);
min=FFMIN(min,p6); max=FFMAX(max,p6);
min=FFMIN(min,p7); max=FFMAX(max,p7);
if(max-min<2*quant){
ptr[-2*a_stride]=(4*p2 + 3*p3 + 1*p7 + 4)>>3;
ptr[-1*a_stride]=(3*p2 + 3*p4 + 2*p7 + 4)>>3;
ptr[ 0 ]=(2*p2 + 3*p5 + 3*p7 + 4)>>3;
ptr[ 1*a_stride]=(1*p2 + 3*p6 + 4*p7 + 4)>>3;
continue;
};
}
}
}
{
int x,x0,x1,x2;
int m;
x0 = (2*p3 - 5*p4 + 5*p5 - 2*p6 + 4)>>3;
if(FFABS(x0) < quant){
x1=(2*p1 - 5*p2 + 5*p3 - 2*p4 + 4)>>3;
x2=(2*p5 - 5*p6 + 5*p7 - 2*p8 + 4)>>3;
x=FFABS(x0) - FFMIN( FFABS(x1), FFABS(x2) );
m=p4-p5;
if( x > 0 && (m^x0) <0){
int32_t sign;
sign=m>>31;
m=(m^sign)-sign;//abs(m)
m>>=1;
x=(5*x)>>3;
if(x>m) x=m;
x=(x^sign)-sign;
ptr[-1*a_stride] -= x;
ptr[ 0] += x;
}
}
}
}
}
static void x8_h_loop_filter(uint8_t *src, int stride, int qscale){
x8_loop_filter(src, stride, 1, qscale);
}
static void x8_v_loop_filter(uint8_t *src, int stride, int qscale){
x8_loop_filter(src, 1, stride, qscale);
}
av_cold void ff_intrax8dsp_init(DSPContext* dsp, AVCodecContext *avctx) {
dsp->x8_h_loop_filter=x8_h_loop_filter;
dsp->x8_v_loop_filter=x8_v_loop_filter;
dsp->x8_setup_spatial_compensation=x8_setup_spatial_compensation;
dsp->x8_spatial_compensation[0]=spatial_compensation_0;
dsp->x8_spatial_compensation[1]=spatial_compensation_1;
dsp->x8_spatial_compensation[2]=spatial_compensation_2;
dsp->x8_spatial_compensation[3]=spatial_compensation_3;
dsp->x8_spatial_compensation[4]=spatial_compensation_4;
dsp->x8_spatial_compensation[5]=spatial_compensation_5;
dsp->x8_spatial_compensation[6]=spatial_compensation_6;
dsp->x8_spatial_compensation[7]=spatial_compensation_7;
dsp->x8_spatial_compensation[8]=spatial_compensation_8;
dsp->x8_spatial_compensation[9]=spatial_compensation_9;
dsp->x8_spatial_compensation[10]=spatial_compensation_10;
dsp->x8_spatial_compensation[11]=spatial_compensation_11;
}
| 123linslouis-android-video-cutter | jni/libavcodec/intrax8dsp.c | C | asf20 | 13,338 |
/*
* Quicktime Animation (RLE) Video Encoder
* Copyright (C) 2007 Clemens Fruhwirth
* Copyright (C) 2007 Alexis Ballier
*
* This file is based on flashsvenc.c.
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
/** Maximum RLE code for bulk copy */
#define MAX_RLE_BULK 127
/** Maximum RLE code for repeat */
#define MAX_RLE_REPEAT 128
/** Maximum RLE code for skip */
#define MAX_RLE_SKIP 254
typedef struct QtrleEncContext {
AVCodecContext *avctx;
AVFrame frame;
int pixel_size;
AVPicture previous_frame;
unsigned int max_buf_size;
/**
* This array will contain at ith position the value of the best RLE code
* if the line started at pixel i
* There can be 3 values :
* skip (0) : skip as much as possible pixels because they are equal to the
* previous frame ones
* repeat (<-1) : repeat that pixel -rle_code times, still as much as
* possible
* copy (>0) : copy the raw next rle_code pixels */
signed char *rlecode_table;
/**
* This array will contain the length of the best rle encoding of the line
* starting at ith pixel */
int *length_table;
/**
* Will contain at ith position the number of consecutive pixels equal to the previous
* frame starting from pixel i */
uint8_t* skip_table;
} QtrleEncContext;
static av_cold int qtrle_encode_init(AVCodecContext *avctx)
{
QtrleEncContext *s = avctx->priv_data;
if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
return -1;
}
s->avctx=avctx;
switch (avctx->pix_fmt) {
case PIX_FMT_RGB555BE:
s->pixel_size = 2;
break;
case PIX_FMT_RGB24:
s->pixel_size = 3;
break;
case PIX_FMT_ARGB:
s->pixel_size = 4;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported colorspace.\n");
break;
}
avctx->bits_per_coded_sample = s->pixel_size*8;
s->rlecode_table = av_mallocz(s->avctx->width);
s->skip_table = av_mallocz(s->avctx->width);
s->length_table = av_mallocz((s->avctx->width + 1)*sizeof(int));
if (!s->skip_table || !s->length_table || !s->rlecode_table) {
av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n");
return -1;
}
if (avpicture_alloc(&s->previous_frame, avctx->pix_fmt, avctx->width, avctx->height) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error allocating picture\n");
return -1;
}
s->max_buf_size = s->avctx->width*s->avctx->height*s->pixel_size /* image base material */
+ 15 /* header + footer */
+ s->avctx->height*2 /* skip code+rle end */
+ s->avctx->width/MAX_RLE_BULK + 1 /* rle codes */;
avctx->coded_frame = &s->frame;
return 0;
}
/**
* Computes the best RLE sequence for a line
*/
static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t **buf)
{
int width=s->avctx->width;
int i;
signed char rlecode;
/* We will use it to compute the best bulk copy sequence */
unsigned int bulkcount;
/* This will be the number of pixels equal to the preivous frame one's
* starting from the ith pixel */
unsigned int skipcount;
/* This will be the number of consecutive equal pixels in the current
* frame, starting from the ith one also */
unsigned int av_uninit(repeatcount);
/* The cost of the three different possibilities */
int total_bulk_cost;
int total_skip_cost;
int total_repeat_cost;
int temp_cost;
int j;
uint8_t *this_line = p-> data[0] + line*p-> linesize[0] +
(width - 1)*s->pixel_size;
uint8_t *prev_line = s->previous_frame.data[0] + line*s->previous_frame.linesize[0] +
(width - 1)*s->pixel_size;
s->length_table[width] = 0;
skipcount = 0;
for (i = width - 1; i >= 0; i--) {
if (!s->frame.key_frame && !memcmp(this_line, prev_line, s->pixel_size))
skipcount = FFMIN(skipcount + 1, MAX_RLE_SKIP);
else
skipcount = 0;
total_skip_cost = s->length_table[i + skipcount] + 2;
s->skip_table[i] = skipcount;
if (i < width - 1 && !memcmp(this_line, this_line + s->pixel_size, s->pixel_size))
repeatcount = FFMIN(repeatcount + 1, MAX_RLE_REPEAT);
else
repeatcount = 1;
total_repeat_cost = s->length_table[i + repeatcount] + 1 + s->pixel_size;
/* skip code is free for the first pixel, it costs one byte for repeat and bulk copy
* so let's make it aware */
if (i == 0) {
total_skip_cost--;
total_repeat_cost++;
}
if (repeatcount > 1 && (skipcount == 0 || total_repeat_cost < total_skip_cost)) {
/* repeat is the best */
s->length_table[i] = total_repeat_cost;
s->rlecode_table[i] = -repeatcount;
}
else if (skipcount > 0) {
/* skip is the best choice here */
s->length_table[i] = total_skip_cost;
s->rlecode_table[i] = 0;
}
else {
/* We cannot do neither skip nor repeat
* thus we search for the best bulk copy to do */
int limit = FFMIN(width - i, MAX_RLE_BULK);
temp_cost = 1 + s->pixel_size + !i;
total_bulk_cost = INT_MAX;
for (j = 1; j <= limit; j++) {
if (s->length_table[i + j] + temp_cost < total_bulk_cost) {
/* We have found a better bulk copy ... */
total_bulk_cost = s->length_table[i + j] + temp_cost;
bulkcount = j;
}
temp_cost += s->pixel_size;
}
s->length_table[i] = total_bulk_cost;
s->rlecode_table[i] = bulkcount;
}
this_line -= s->pixel_size;
prev_line -= s->pixel_size;
}
/* Good ! Now we have the best sequence for this line, let's ouput it */
/* We do a special case for the first pixel so that we avoid testing it in
* the whole loop */
i=0;
this_line = p-> data[0] + line*p->linesize[0];
if (s->rlecode_table[0] == 0) {
bytestream_put_byte(buf, s->skip_table[0] + 1);
i += s->skip_table[0];
}
else bytestream_put_byte(buf, 1);
while (i < width) {
rlecode = s->rlecode_table[i];
bytestream_put_byte(buf, rlecode);
if (rlecode == 0) {
/* Write a skip sequence */
bytestream_put_byte(buf, s->skip_table[i] + 1);
i += s->skip_table[i];
}
else if (rlecode > 0) {
/* bulk copy */
bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size);
i += rlecode;
}
else {
/* repeat the bits */
bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size);
i -= rlecode;
}
}
bytestream_put_byte(buf, -1); // end RLE line
}
/** Encodes frame including header */
static int encode_frame(QtrleEncContext *s, AVFrame *p, uint8_t *buf)
{
int i;
int start_line = 0;
int end_line = s->avctx->height;
uint8_t *orig_buf = buf;
if (!s->frame.key_frame) {
unsigned line_size = s->avctx->width * s->pixel_size;
for (start_line = 0; start_line < s->avctx->height; start_line++)
if (memcmp(p->data[0] + start_line*p->linesize[0],
s->previous_frame.data[0] + start_line*s->previous_frame.linesize[0],
line_size))
break;
for (end_line=s->avctx->height; end_line > start_line; end_line--)
if (memcmp(p->data[0] + (end_line - 1)*p->linesize[0],
s->previous_frame.data[0] + (end_line - 1)*s->previous_frame.linesize[0],
line_size))
break;
}
bytestream_put_be32(&buf, 0); // CHUNK SIZE, patched later
if ((start_line == 0 && end_line == s->avctx->height) || start_line == s->avctx->height)
bytestream_put_be16(&buf, 0); // header
else {
bytestream_put_be16(&buf, 8); // header
bytestream_put_be16(&buf, start_line); // starting line
bytestream_put_be16(&buf, 0); // unknown
bytestream_put_be16(&buf, end_line - start_line); // lines to update
bytestream_put_be16(&buf, 0); // unknown
}
for (i = start_line; i < end_line; i++)
qtrle_encode_line(s, p, i, &buf);
bytestream_put_byte(&buf, 0); // zero skip code = frame finished
AV_WB32(orig_buf, buf - orig_buf); // patch the chunk size
return buf - orig_buf;
}
static int qtrle_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data)
{
QtrleEncContext * const s = avctx->priv_data;
AVFrame *pict = data;
AVFrame * const p = &s->frame;
int chunksize;
*p = *pict;
if (buf_size < s->max_buf_size) {
/* Upper bound check for compressed data */
av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->max_buf_size);
return -1;
}
if (avctx->gop_size == 0 || (s->avctx->frame_number % avctx->gop_size) == 0) {
/* I-Frame */
p->pict_type = FF_I_TYPE;
p->key_frame = 1;
} else {
/* P-Frame */
p->pict_type = FF_P_TYPE;
p->key_frame = 0;
}
chunksize = encode_frame(s, pict, buf);
/* save the current frame */
av_picture_copy(&s->previous_frame, (AVPicture *)p, avctx->pix_fmt, avctx->width, avctx->height);
return chunksize;
}
static av_cold int qtrle_encode_end(AVCodecContext *avctx)
{
QtrleEncContext *s = avctx->priv_data;
avpicture_free(&s->previous_frame);
av_free(s->rlecode_table);
av_free(s->length_table);
av_free(s->skip_table);
return 0;
}
AVCodec qtrle_encoder = {
"qtrle",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_QTRLE,
sizeof(QtrleEncContext),
qtrle_encode_init,
qtrle_encode_frame,
qtrle_encode_end,
.pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/qtrleenc.c | C | asf20 | 11,299 |
/*
* Simple IDCT
*
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* 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 "mathops.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
static inline void idctRowCondDC (DCTELEM * row)
{
int a0, a1, a2, a3, b0, b1, b2, b3;
#if HAVE_FAST_64BIT
uint64_t temp;
#else
uint32_t temp;
#endif
#if HAVE_FAST_64BIT
#if HAVE_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];
b0 = MUL16(W1, row[1]);
MAC16(b0, W3, row[3]);
b1 = MUL16(W3, row[1]);
MAC16(b1, -W7, row[3]);
b2 = MUL16(W5, row[1]);
MAC16(b2, -W1, row[3]);
b3 = MUL16(W7, row[1]);
MAC16(b3, -W5, row[3]);
#if HAVE_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 = ff_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];
b0 = MUL16(W1, col[8*1]);
b1 = MUL16(W3, col[8*1]);
b2 = MUL16(W5, col[8*1]);
b3 = MUL16(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 = ff_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];
b0 = MUL16(W1, col[8*1]);
b1 = MUL16(W3, col[8*1]);
b2 = MUL16(W5, col[8*1]);
b3 = MUL16(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];
b0 = MUL16(W1, col[8*1]);
b1 = MUL16(W3, col[8*1]);
b2 = MUL16(W5, col[8*1]);
b3 = MUL16(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 ff_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 ff_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 ff_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_put(uint8_t *dest, int line_size, const DCTELEM *col)
{
int c0, c1, c2, c3, a0, a1, a2, a3;
const uint8_t *cm = ff_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 ff_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_put(dest + i, 2 * line_size, block + i);
idct4col_put(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 = ff_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 = ff_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 ff_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 ff_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);
}
}
void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block)
{
int i;
/* IDCT4 on each line */
for(i=0; i<4; i++) {
idct4row(block + i*8);
}
/* IDCT4 and store */
for(i=0; i<4; i++){
idct4col_add(dest + i, line_size, block + i);
}
}
| 123linslouis-android-video-cutter | jni/libavcodec/simple_idct.c | C | asf20 | 16,151 |
/*
* Interplay C93 video decoder
* Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
typedef struct {
AVFrame pictures[2];
int currentpic;
} C93DecoderContext;
typedef enum {
C93_8X8_FROM_PREV = 0x02,
C93_4X4_FROM_PREV = 0x06,
C93_4X4_FROM_CURR = 0x07,
C93_8X8_2COLOR = 0x08,
C93_4X4_2COLOR = 0x0A,
C93_4X4_4COLOR_GRP = 0x0B,
C93_4X4_4COLOR = 0x0D,
C93_NOOP = 0x0E,
C93_8X8_INTRA = 0x0F,
} C93BlockType;
#define WIDTH 320
#define HEIGHT 192
#define C93_HAS_PALETTE 0x01
#define C93_FIRST_FRAME 0x02
static av_cold int decode_init(AVCodecContext *avctx)
{
avctx->pix_fmt = PIX_FMT_PAL8;
return 0;
}
static av_cold int decode_end(AVCodecContext *avctx)
{
C93DecoderContext * const c93 = avctx->priv_data;
if (c93->pictures[0].data[0])
avctx->release_buffer(avctx, &c93->pictures[0]);
if (c93->pictures[1].data[0])
avctx->release_buffer(avctx, &c93->pictures[1]);
return 0;
}
static inline int copy_block(AVCodecContext *avctx, uint8_t *to,
uint8_t *from, int offset, int height, int stride)
{
int i;
int width = height;
int from_x = offset % WIDTH;
int from_y = offset / WIDTH;
int overflow = from_x + width - WIDTH;
if (!from) {
/* silently ignoring predictive blocks in first frame */
return 0;
}
if (from_y + height > HEIGHT) {
av_log(avctx, AV_LOG_ERROR, "invalid offset %d during C93 decoding\n",
offset);
return -1;
}
if (overflow > 0) {
width -= overflow;
for (i = 0; i < height; i++) {
memcpy(&to[i*stride+width], &from[(from_y+i)*stride], overflow);
}
}
for (i = 0; i < height; i++) {
memcpy(&to[i*stride], &from[(from_y+i)*stride+from_x], width);
}
return 0;
}
static inline void draw_n_color(uint8_t *out, int stride, int width,
int height, int bpp, uint8_t cols[4], uint8_t grps[4], uint32_t col)
{
int x, y;
for (y = 0; y < height; y++) {
if (grps)
cols[0] = grps[3 * (y >> 1)];
for (x = 0; x < width; x++) {
if (grps)
cols[1]= grps[(x >> 1) + 1];
out[x + y*stride] = cols[col & ((1 << bpp) - 1)];
col >>= bpp;
}
}
}
static int decode_frame(AVCodecContext *avctx, void *data,
int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
C93DecoderContext * const c93 = avctx->priv_data;
AVFrame * const newpic = &c93->pictures[c93->currentpic];
AVFrame * const oldpic = &c93->pictures[c93->currentpic^1];
AVFrame *picture = data;
uint8_t *out;
int stride, i, x, y, bt = 0;
c93->currentpic ^= 1;
newpic->reference = 1;
newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE |
FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE;
if (avctx->reget_buffer(avctx, newpic)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
stride = newpic->linesize[0];
if (buf[0] & C93_FIRST_FRAME) {
newpic->pict_type = FF_I_TYPE;
newpic->key_frame = 1;
} else {
newpic->pict_type = FF_P_TYPE;
newpic->key_frame = 0;
}
if (*buf++ & C93_HAS_PALETTE) {
uint32_t *palette = (uint32_t *) newpic->data[1];
const uint8_t *palbuf = buf + buf_size - 768 - 1;
for (i = 0; i < 256; i++) {
palette[i] = bytestream_get_be24(&palbuf);
}
} else {
if (oldpic->data[1])
memcpy(newpic->data[1], oldpic->data[1], 256 * 4);
}
for (y = 0; y < HEIGHT; y += 8) {
out = newpic->data[0] + y * stride;
for (x = 0; x < WIDTH; x += 8) {
uint8_t *copy_from = oldpic->data[0];
unsigned int offset, j;
uint8_t cols[4], grps[4];
C93BlockType block_type;
if (!bt)
bt = *buf++;
block_type= bt & 0x0F;
switch (block_type) {
case C93_8X8_FROM_PREV:
offset = bytestream_get_le16(&buf);
if (copy_block(avctx, out, copy_from, offset, 8, stride))
return -1;
break;
case C93_4X4_FROM_CURR:
copy_from = newpic->data[0];
case C93_4X4_FROM_PREV:
for (j = 0; j < 8; j += 4) {
for (i = 0; i < 8; i += 4) {
offset = bytestream_get_le16(&buf);
if (copy_block(avctx, &out[j*stride+i],
copy_from, offset, 4, stride))
return -1;
}
}
break;
case C93_8X8_2COLOR:
bytestream_get_buffer(&buf, cols, 2);
for (i = 0; i < 8; i++) {
draw_n_color(out + i*stride, stride, 8, 1, 1, cols,
NULL, *buf++);
}
break;
case C93_4X4_2COLOR:
case C93_4X4_4COLOR:
case C93_4X4_4COLOR_GRP:
for (j = 0; j < 8; j += 4) {
for (i = 0; i < 8; i += 4) {
if (block_type == C93_4X4_2COLOR) {
bytestream_get_buffer(&buf, cols, 2);
draw_n_color(out + i + j*stride, stride, 4, 4,
1, cols, NULL, bytestream_get_le16(&buf));
} else if (block_type == C93_4X4_4COLOR) {
bytestream_get_buffer(&buf, cols, 4);
draw_n_color(out + i + j*stride, stride, 4, 4,
2, cols, NULL, bytestream_get_le32(&buf));
} else {
bytestream_get_buffer(&buf, grps, 4);
draw_n_color(out + i + j*stride, stride, 4, 4,
1, cols, grps, bytestream_get_le16(&buf));
}
}
}
break;
case C93_NOOP:
break;
case C93_8X8_INTRA:
for (j = 0; j < 8; j++)
bytestream_get_buffer(&buf, out + j*stride, 8);
break;
default:
av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n",
block_type, x, y);
return -1;
}
bt >>= 4;
out += 8;
}
}
*picture = *newpic;
*data_size = sizeof(AVFrame);
return buf_size;
}
AVCodec c93_decoder = {
"c93",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_C93,
sizeof(C93DecoderContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Interplay C93"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/c93.c | C | asf20 | 7,863 |
/*
* RealVideo 3/4 decoder
* Copyright (c) 2007 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* RV30/40 VLC tables
*/
#ifndef AVCODEC_RV34VLC_H
#define AVCODEC_RV34VLC_H
#include <stdint.h>
#define NUM_INTRA_TABLES 5
#define NUM_INTER_TABLES 7
#define CBPPAT_VLC_SIZE 1296
#define CBP_VLC_SIZE 16
#define FIRSTBLK_VLC_SIZE 864
#define OTHERBLK_VLC_SIZE 108
#define COEFF_VLC_SIZE 32
static const uint8_t rv34_table_intra_cbppat[NUM_INTRA_TABLES][2][CBPPAT_VLC_SIZE] = {
{
{
8, 10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 6,
12, 12, 13, 12, 13, 12, 13, 11, 13, 13, 13, 12, 13, 12, 12, 8,
14, 13, 16, 13, 15, 13, 16, 12, 16, 16, 16, 14, 16, 13, 14, 10,
12, 13, 12, 12, 13, 13, 13, 12, 13, 13, 12, 12, 13, 12, 12, 8,
13, 14, 14, 12, 14, 14, 14, 12, 14, 15, 14, 12, 14, 13, 13, 8,
16, 16, 16, 12, 16, 16, 16, 13, 16, 16, 16, 13, 16, 14, 14, 9,
14, 16, 13, 13, 16, 16, 16, 14, 15, 16, 14, 13, 15, 15, 14, 10,
16, 16, 14, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 15, 14, 10,
16, 16, 16, 11, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 15, 9,
12, 13, 13, 13, 12, 12, 14, 12, 12, 14, 13, 12, 12, 12, 12, 8,
14, 14, 16, 14, 13, 12, 14, 12, 14, 15, 14, 13, 13, 12, 13, 8,
16, 16, 16, 15, 16, 13, 16, 13, 16, 16, 16, 15, 16, 13, 15, 10,
14, 16, 14, 14, 14, 14, 15, 13, 14, 16, 14, 13, 13, 13, 13, 9,
16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 14, 13, 14, 13, 13, 8,
16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 14, 16, 14, 14, 9,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 14, 10,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 14, 16, 15, 14, 9,
16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 16, 13, 16, 15, 15, 8,
14, 16, 16, 16, 14, 14, 16, 14, 16, 16, 16, 15, 13, 13, 14, 10,
16, 16, 16, 16, 15, 13, 16, 13, 16, 16, 16, 16, 16, 13, 14, 10,
16, 16, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16, 12, 16, 9,
16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 14, 14, 10,
16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 15, 16, 13, 14, 9,
16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16, 13, 14, 8,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 11,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, 9,
16, 16, 16, 14, 16, 15, 16, 11, 16, 16, 16, 14, 16, 14, 14, 8,
12, 13, 13, 13, 13, 13, 14, 12, 12, 13, 12, 12, 12, 12, 12, 8,
14, 14, 16, 14, 15, 14, 16, 13, 14, 15, 14, 13, 14, 13, 13, 9,
16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 14, 16, 14, 16, 10,
14, 15, 14, 14, 15, 14, 15, 13, 14, 14, 13, 12, 13, 13, 13, 9,
15, 16, 15, 14, 16, 16, 16, 13, 15, 16, 14, 12, 14, 13, 13, 8,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 13, 16, 14, 14, 9,
16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 13, 13, 16, 16, 14, 10,
16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 13, 16, 14, 14, 9,
16, 16, 16, 12, 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 15, 8,
13, 14, 14, 14, 14, 14, 16, 13, 13, 14, 14, 13, 12, 12, 12, 8,
16, 16, 16, 14, 15, 14, 16, 13, 15, 16, 14, 13, 13, 12, 13, 8,
16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 14, 16, 13, 14, 9,
15, 16, 16, 15, 16, 15, 16, 13, 14, 16, 14, 13, 13, 13, 12, 8,
16, 16, 16, 14, 16, 14, 15, 12, 15, 15, 14, 12, 13, 12, 12, 7,
16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 13, 16, 13, 13, 7,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 14, 14, 16, 14, 13, 9,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 14, 12, 16, 13, 12, 7,
16, 16, 16, 12, 16, 16, 16, 11, 16, 16, 15, 12, 16, 13, 13, 6,
16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 13, 13, 14, 10,
16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 14, 13, 14, 9,
16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 16, 16, 12, 14, 8,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14, 13, 13, 9,
16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 13, 14, 12, 12, 7,
16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 6,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 14, 9,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 15, 13, 12, 7,
16, 16, 16, 13, 16, 14, 16, 11, 16, 16, 16, 12, 16, 12, 12, 5,
14, 16, 15, 16, 16, 16, 16, 15, 14, 15, 14, 14, 13, 14, 13, 10,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 16, 10,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 11,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 14, 15, 14, 13, 10,
16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, 13, 16, 14, 14, 9,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 9,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 13, 16, 16, 13, 10,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 16, 13, 9,
16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 12, 16, 16, 14, 8,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 15, 14, 13, 13, 13, 9,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14, 13, 13, 9,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 15, 9,
16, 16, 16, 16, 16, 16, 16, 15, 15, 16, 14, 14, 14, 13, 13, 9,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 12, 13, 12, 12, 7,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 16, 13, 13, 7,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 14, 13, 9,
16, 16, 16, 15, 16, 16, 16, 13, 16, 16, 13, 12, 14, 13, 12, 6,
16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 14, 10, 15, 12, 12, 5,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 13, 13, 9,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 13, 12, 13, 8,
16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 15, 12, 14, 8,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 13, 13, 13, 8,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 15, 13, 12, 11, 12, 6,
16, 16, 16, 15, 16, 14, 16, 12, 16, 16, 16, 12, 13, 10, 12, 5,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 13, 14, 12, 8,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 13, 12, 13, 12, 10, 5,
16, 16, 16, 13, 16, 13, 16, 10, 16, 16, 13, 10, 13, 10, 10, 1,
},
{
2, 7, 7, 8, 7, 8, 9, 8, 7, 9, 8, 8, 8, 8, 9, 7,
6, 9, 10, 10, 10, 10, 11, 10, 10, 11, 11, 11, 10, 11, 11, 9,
9, 11, 12, 12, 12, 13, 14, 13, 13, 14, 14, 13, 13, 13, 14, 11,
6, 10, 9, 10, 10, 11, 11, 11, 10, 11, 10, 11, 11, 11, 11, 9,
6, 9, 10, 10, 10, 11, 12, 11, 10, 12, 11, 11, 11, 11, 11, 8,
9, 11, 12, 12, 12, 13, 13, 13, 12, 14, 14, 13, 13, 13, 13, 10,
9, 13, 11, 13, 13, 14, 14, 13, 13, 14, 13, 13, 14, 14, 14, 12,
9, 12, 12, 12, 12, 14, 14, 13, 13, 14, 13, 13, 13, 14, 13, 11,
8, 12, 12, 11, 12, 14, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11,
6, 10, 10, 11, 9, 10, 12, 11, 10, 12, 11, 11, 10, 11, 11, 9,
7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9,
9, 12, 13, 13, 12, 12, 14, 13, 13, 14, 14, 13, 14, 13, 14, 11,
8, 11, 11, 12, 11, 12, 12, 12, 11, 13, 12, 12, 12, 12, 12, 10,
7, 10, 10, 11, 10, 11, 12, 11, 10, 12, 11, 11, 11, 11, 11, 8,
9, 11, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 13, 12, 13, 10,
10, 13, 13, 14, 14, 14, 15, 14, 14, 15, 14, 15, 14, 14, 14, 12,
9, 12, 12, 13, 12, 13, 14, 13, 12, 13, 13, 12, 13, 13, 13, 10,
9, 12, 12, 12, 12, 13, 14, 12, 12, 14, 13, 12, 13, 13, 13, 10,
9, 12, 13, 13, 11, 13, 14, 13, 13, 14, 14, 14, 12, 13, 13, 11,
10, 12, 13, 13, 12, 12, 14, 13, 13, 14, 14, 14, 13, 13, 14, 11,
10, 13, 14, 14, 13, 12, 15, 13, 14, 14, 14, 14, 15, 13, 14, 11,
11, 14, 14, 14, 13, 14, 15, 14, 14, 15, 15, 14, 13, 14, 14, 12,
10, 13, 12, 13, 12, 12, 14, 13, 13, 14, 13, 13, 13, 13, 13, 10,
10, 12, 13, 13, 13, 12, 14, 12, 13, 14, 14, 13, 13, 13, 13, 10,
13, 15, 16, 16, 15, 15, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14,
11, 14, 14, 14, 14, 14, 15, 14, 14, 15, 15, 14, 14, 14, 15, 11,
10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 14, 13, 13, 13, 13, 10,
6, 10, 10, 11, 10, 11, 12, 11, 10, 12, 10, 11, 10, 11, 11, 9,
8, 11, 11, 12, 11, 12, 13, 12, 11, 12, 12, 12, 12, 12, 12, 10,
11, 13, 14, 14, 13, 14, 15, 14, 13, 15, 15, 14, 14, 14, 15, 12,
7, 11, 10, 12, 11, 12, 12, 12, 11, 12, 11, 12, 11, 12, 12, 10,
7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9,
10, 12, 13, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13, 13, 13, 10,
10, 13, 12, 14, 13, 14, 14, 14, 13, 14, 12, 14, 15, 14, 14, 11,
10, 12, 12, 12, 12, 13, 14, 13, 13, 14, 13, 12, 13, 13, 13, 10,
9, 12, 13, 13, 13, 14, 14, 13, 13, 14, 14, 13, 13, 13, 13, 10,
7, 10, 10, 11, 10, 11, 12, 11, 10, 12, 12, 11, 9, 11, 11, 9,
7, 10, 11, 11, 10, 11, 12, 11, 10, 12, 12, 11, 11, 11, 11, 9,
10, 12, 13, 13, 13, 13, 15, 13, 13, 14, 13, 13, 13, 13, 13, 10,
8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 12, 11, 9,
6, 9, 9, 10, 9, 10, 10, 10, 9, 11, 10, 10, 9, 10, 10, 7,
8, 10, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 11, 11, 8,
10, 13, 13, 13, 13, 14, 14, 13, 13, 14, 13, 13, 13, 13, 13, 11,
8, 11, 11, 11, 11, 12, 12, 11, 11, 12, 11, 11, 11, 11, 11, 8,
8, 11, 11, 11, 11, 12, 12, 10, 11, 12, 12, 11, 11, 11, 11, 8,
10, 13, 13, 13, 12, 13, 14, 13, 12, 14, 14, 14, 10, 13, 13, 11,
10, 12, 12, 13, 12, 13, 14, 12, 12, 13, 13, 13, 12, 12, 13, 10,
11, 13, 14, 14, 13, 13, 14, 13, 13, 15, 14, 13, 13, 13, 13, 10,
10, 12, 13, 13, 12, 13, 14, 13, 13, 14, 14, 13, 12, 13, 13, 11,
8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 11, 11, 8,
9, 11, 12, 12, 11, 11, 12, 11, 12, 12, 12, 11, 12, 11, 11, 8,
12, 15, 14, 14, 14, 15, 15, 14, 14, 15, 15, 14, 14, 14, 15, 12,
10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 12, 12, 12, 9,
9, 11, 11, 11, 11, 11, 12, 10, 11, 12, 12, 11, 11, 11, 11, 7,
10, 13, 13, 13, 13, 14, 15, 14, 13, 14, 14, 14, 12, 14, 15, 12,
11, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 15, 14, 15, 15, 12,
13, 16, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 14,
10, 13, 13, 14, 13, 15, 14, 14, 13, 15, 13, 14, 14, 14, 14, 12,
10, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 13, 13, 13, 14, 11,
12, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 14, 15, 14, 14, 12,
11, 14, 14, 15, 14, 15, 15, 14, 14, 15, 12, 14, 15, 16, 15, 12,
11, 13, 13, 14, 13, 14, 14, 14, 14, 14, 13, 13, 14, 14, 14, 11,
11, 14, 14, 14, 14, 15, 15, 14, 14, 16, 14, 13, 14, 14, 14, 11,
10, 13, 13, 13, 12, 14, 14, 14, 12, 15, 14, 14, 11, 13, 13, 12,
10, 12, 13, 14, 12, 13, 14, 13, 13, 14, 14, 13, 12, 13, 13, 11,
12, 14, 14, 15, 14, 15, 16, 15, 15, 15, 15, 15, 14, 14, 15, 12,
10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 13, 13, 12, 13, 13, 11,
9, 11, 11, 12, 11, 12, 12, 11, 11, 12, 12, 11, 11, 11, 11, 9,
10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 13, 12, 12, 9,
11, 13, 13, 15, 14, 14, 15, 14, 14, 15, 14, 14, 14, 14, 14, 11,
10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 11, 11, 12, 12, 12, 8,
9, 12, 12, 11, 12, 12, 13, 11, 12, 12, 12, 11, 12, 11, 11, 8,
10, 13, 13, 14, 12, 14, 15, 14, 13, 15, 15, 14, 10, 13, 13, 11,
11, 13, 14, 13, 13, 14, 14, 13, 13, 14, 14, 14, 11, 13, 13, 11,
12, 14, 14, 14, 14, 14, 15, 14, 15, 16, 15, 14, 13, 13, 14, 11,
11, 14, 13, 14, 13, 14, 15, 14, 13, 15, 14, 14, 11, 13, 13, 11,
9, 12, 12, 12, 11, 12, 13, 11, 12, 13, 12, 11, 10, 11, 11, 8,
10, 12, 12, 12, 12, 12, 13, 11, 12, 12, 12, 11, 11, 11, 11, 8,
12, 15, 14, 15, 14, 15, 16, 15, 15, 15, 15, 14, 14, 14, 14, 12,
10, 12, 12, 12, 12, 12, 13, 11, 12, 13, 12, 11, 11, 11, 11, 8,
8, 10, 10, 10, 10, 10, 11, 9, 10, 11, 10, 9, 10, 9, 9, 5,
},
},
{
{
12, 12, 11, 9, 11, 10, 11, 9, 11, 11, 10, 9, 9, 8, 9, 5,
14, 13, 14, 11, 14, 11, 13, 10, 14, 13, 12, 10, 12, 10, 11, 6,
16, 13, 16, 12, 16, 12, 16, 11, 16, 14, 16, 12, 15, 12, 13, 8,
14, 14, 12, 11, 14, 12, 13, 10, 13, 13, 11, 10, 12, 11, 10, 6,
16, 15, 14, 11, 16, 13, 14, 10, 15, 14, 13, 10, 13, 11, 11, 7,
16, 16, 16, 11, 16, 14, 16, 11, 16, 16, 15, 12, 15, 13, 13, 8,
16, 16, 13, 12, 16, 16, 15, 12, 16, 16, 12, 11, 15, 13, 12, 8,
16, 16, 14, 11, 16, 16, 16, 11, 16, 16, 14, 11, 15, 14, 13, 8,
16, 16, 15, 10, 16, 16, 16, 10, 16, 16, 15, 11, 16, 14, 14, 8,
14, 14, 14, 12, 13, 11, 13, 10, 13, 13, 12, 11, 11, 10, 10, 6,
16, 15, 16, 13, 13, 11, 14, 11, 15, 14, 13, 11, 12, 10, 11, 7,
16, 15, 16, 14, 16, 11, 16, 11, 16, 16, 16, 13, 16, 12, 13, 8,
16, 16, 14, 13, 15, 13, 14, 11, 14, 15, 13, 11, 13, 11, 11, 7,
16, 16, 15, 13, 15, 13, 14, 11, 16, 15, 14, 11, 13, 11, 11, 7,
16, 16, 16, 13, 16, 13, 16, 11, 16, 16, 16, 12, 16, 12, 13, 8,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 14, 13, 15, 14, 13, 9,
16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 14, 12, 15, 13, 13, 8,
16, 16, 16, 12, 16, 16, 16, 11, 16, 16, 15, 12, 16, 13, 13, 7,
16, 16, 16, 16, 13, 12, 16, 12, 16, 16, 14, 13, 12, 11, 12, 8,
16, 16, 16, 15, 14, 11, 16, 11, 16, 16, 16, 13, 14, 11, 13, 8,
16, 16, 16, 16, 15, 10, 16, 11, 16, 16, 16, 14, 15, 11, 13, 8,
16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 14, 14, 14, 12, 13, 9,
16, 16, 16, 15, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 8,
16, 16, 16, 14, 16, 12, 16, 11, 16, 16, 16, 13, 15, 12, 13, 7,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 14, 13, 9,
16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 14, 16, 13, 13, 8,
16, 16, 16, 14, 16, 14, 16, 10, 16, 16, 16, 13, 16, 13, 13, 7,
14, 14, 13, 12, 13, 12, 13, 11, 12, 13, 11, 10, 11, 10, 10, 6,
16, 16, 15, 13, 16, 13, 15, 11, 14, 14, 13, 11, 13, 11, 11, 7,
16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 13, 16, 13, 14, 9,
16, 16, 13, 13, 15, 14, 14, 11, 13, 14, 11, 11, 12, 11, 11, 7,
16, 16, 15, 12, 16, 14, 15, 11, 14, 14, 12, 11, 13, 11, 11, 7,
16, 16, 16, 13, 16, 14, 16, 12, 16, 16, 14, 12, 16, 13, 13, 8,
16, 16, 14, 14, 16, 16, 16, 13, 16, 16, 12, 11, 15, 13, 12, 8,
16, 16, 15, 13, 16, 16, 16, 12, 16, 16, 13, 11, 16, 13, 12, 8,
16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 14, 11, 16, 14, 13, 7,
16, 16, 15, 13, 14, 13, 14, 11, 14, 14, 12, 11, 11, 10, 11, 7,
16, 16, 16, 13, 14, 12, 15, 11, 15, 14, 13, 11, 12, 11, 11, 7,
16, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 8,
16, 16, 15, 13, 15, 14, 14, 12, 14, 14, 12, 11, 12, 11, 11, 7,
16, 16, 14, 12, 15, 13, 14, 11, 15, 14, 13, 11, 12, 11, 11, 6,
16, 16, 16, 13, 16, 13, 16, 11, 16, 15, 14, 11, 14, 11, 12, 6,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13, 12, 14, 13, 12, 8,
16, 16, 15, 13, 16, 14, 15, 11, 16, 16, 13, 11, 14, 12, 11, 6,
16, 16, 16, 12, 16, 14, 15, 11, 16, 16, 13, 10, 14, 12, 12, 6,
16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 14, 13, 12, 11, 12, 8,
16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 15, 13, 13, 11, 12, 8,
16, 16, 16, 15, 16, 12, 16, 12, 16, 16, 16, 14, 14, 11, 13, 7,
16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 14, 13, 13, 12, 12, 8,
16, 16, 16, 14, 15, 13, 15, 11, 16, 15, 14, 12, 13, 11, 11, 6,
16, 16, 16, 14, 16, 12, 15, 11, 16, 16, 15, 12, 14, 11, 12, 6,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 15, 13, 14, 13, 12, 8,
16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 14, 12, 13, 12, 11, 6,
16, 16, 16, 13, 16, 13, 15, 10, 16, 16, 14, 11, 14, 11, 11, 5,
16, 16, 15, 14, 16, 16, 16, 13, 14, 14, 12, 12, 12, 12, 12, 8,
16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 13, 14, 13, 13, 9,
16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 16, 13, 15, 9,
16, 16, 14, 15, 16, 16, 16, 14, 14, 16, 12, 12, 13, 13, 12, 8,
16, 16, 16, 14, 16, 16, 16, 13, 16, 15, 13, 12, 14, 12, 12, 8,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 12, 16, 13, 13, 8,
16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 11, 11, 15, 14, 12, 8,
16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 12, 11, 15, 13, 12, 8,
16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 13, 10, 16, 13, 12, 7,
16, 16, 16, 16, 16, 15, 16, 13, 14, 16, 13, 13, 12, 12, 12, 8,
16, 16, 16, 15, 16, 14, 16, 13, 16, 16, 14, 13, 13, 12, 12, 8,
16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 13, 15, 12, 14, 8,
16, 16, 16, 15, 16, 16, 16, 13, 14, 16, 13, 12, 12, 12, 11, 8,
16, 16, 16, 14, 16, 14, 16, 12, 14, 14, 13, 11, 13, 11, 11, 6,
16, 16, 16, 14, 16, 14, 16, 12, 16, 15, 14, 11, 14, 11, 12, 6,
16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 12, 12, 14, 13, 11, 8,
16, 16, 15, 14, 16, 16, 16, 12, 16, 15, 12, 11, 13, 12, 11, 6,
16, 16, 16, 13, 16, 14, 16, 11, 16, 14, 13, 10, 14, 11, 11, 5,
16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 15, 13, 11, 11, 11, 8,
16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 13, 12, 11, 12, 7,
16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 13, 13, 11, 13, 7,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 13, 12, 12, 11, 7,
16, 16, 16, 15, 16, 14, 15, 12, 16, 14, 13, 12, 12, 11, 11, 6,
16, 16, 16, 14, 16, 13, 15, 11, 16, 14, 14, 11, 13, 10, 11, 5,
16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 13, 12, 12, 12, 11, 7,
16, 16, 16, 14, 16, 14, 15, 12, 16, 15, 12, 11, 12, 11, 10, 5,
16, 16, 16, 13, 16, 13, 14, 10, 16, 14, 12, 9, 12, 10, 9, 3,
},
{
2, 6, 6, 7, 6, 7, 8, 7, 7, 8, 7, 8, 7, 8, 8, 5,
5, 8, 9, 9, 9, 9, 12, 10, 10, 11, 10, 10, 10, 11, 11, 8,
9, 10, 13, 12, 13, 12, 15, 13, 13, 14, 13, 14, 13, 13, 14, 11,
5, 10, 9, 10, 10, 10, 12, 10, 10, 12, 10, 11, 11, 11, 11, 8,
6, 9, 10, 9, 10, 11, 12, 10, 10, 12, 11, 11, 10, 11, 11, 8,
9, 11, 12, 11, 12, 13, 14, 12, 13, 14, 14, 12, 13, 13, 13, 11,
10, 13, 11, 12, 14, 14, 15, 13, 13, 15, 12, 13, 14, 14, 14, 12,
9, 12, 12, 12, 13, 13, 15, 13, 13, 14, 13, 13, 14, 13, 15, 11,
8, 11, 12, 10, 12, 13, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11,
5, 9, 10, 10, 9, 10, 12, 11, 10, 12, 11, 11, 9, 11, 11, 9,
6, 10, 10, 11, 10, 10, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9,
9, 11, 13, 13, 12, 11, 14, 12, 13, 15, 13, 13, 14, 13, 14, 11,
8, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 13, 12, 12, 12, 10,
7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 12, 9,
9, 12, 12, 12, 12, 12, 14, 12, 13, 14, 13, 13, 13, 13, 13, 11,
11, 14, 13, 15, 15, 16, 16, 15, 15, 16, 15, 15, 16, 16, 15, 13,
10, 12, 13, 13, 13, 14, 15, 13, 13, 14, 13, 13, 14, 14, 14, 11,
9, 12, 12, 12, 13, 13, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11,
9, 13, 13, 13, 11, 12, 15, 13, 13, 15, 14, 14, 11, 13, 14, 11,
10, 13, 13, 13, 12, 12, 15, 13, 13, 15, 14, 14, 13, 13, 14, 11,
10, 12, 13, 13, 12, 11, 14, 12, 13, 15, 13, 13, 13, 13, 14, 11,
11, 14, 15, 15, 13, 14, 16, 14, 14, 16, 16, 14, 14, 15, 15, 13,
10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 14, 14, 13, 13, 14, 11,
10, 12, 13, 13, 13, 12, 14, 13, 13, 14, 14, 13, 13, 13, 13, 11,
13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
12, 15, 15, 15, 14, 15, 16, 14, 15, 16, 16, 15, 16, 15, 15, 13,
10, 12, 12, 12, 13, 13, 14, 12, 13, 14, 13, 13, 13, 13, 13, 11,
6, 10, 10, 11, 10, 11, 12, 11, 10, 12, 11, 11, 10, 11, 11, 9,
8, 11, 12, 12, 12, 12, 13, 12, 12, 13, 12, 13, 12, 13, 13, 10,
11, 13, 15, 14, 15, 14, 16, 14, 15, 16, 16, 14, 15, 15, 15, 13,
7, 11, 10, 12, 11, 11, 13, 11, 11, 13, 10, 11, 12, 12, 12, 10,
7, 11, 11, 11, 11, 11, 13, 11, 11, 13, 11, 12, 12, 12, 12, 9,
10, 12, 13, 13, 13, 13, 15, 13, 14, 15, 14, 14, 14, 14, 15, 11,
10, 13, 12, 14, 14, 14, 15, 13, 13, 15, 12, 13, 15, 15, 14, 12,
10, 13, 12, 12, 13, 13, 15, 14, 13, 15, 13, 13, 14, 14, 14, 11,
10, 13, 13, 12, 13, 14, 15, 13, 13, 15, 13, 13, 14, 14, 14, 11,
7, 10, 11, 11, 10, 11, 12, 11, 10, 12, 12, 12, 9, 11, 12, 9,
7, 11, 11, 11, 11, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 9,
10, 12, 14, 13, 13, 13, 16, 13, 14, 16, 14, 14, 13, 13, 14, 11,
8, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10,
6, 9, 9, 10, 9, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 8,
8, 11, 11, 11, 12, 11, 13, 11, 12, 13, 12, 12, 12, 12, 12, 10,
11, 14, 13, 14, 14, 14, 16, 14, 14, 16, 14, 14, 15, 15, 14, 12,
9, 12, 11, 12, 12, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10,
8, 11, 11, 11, 11, 11, 13, 11, 12, 12, 12, 12, 12, 12, 12, 9,
10, 13, 14, 13, 11, 13, 14, 14, 13, 15, 15, 14, 10, 13, 14, 11,
10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 14, 14, 13, 13, 13, 11,
10, 13, 14, 13, 13, 12, 15, 13, 14, 15, 14, 14, 14, 13, 14, 12,
11, 14, 14, 14, 13, 13, 15, 14, 14, 15, 14, 15, 13, 14, 14, 12,
9, 11, 12, 12, 11, 11, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10,
9, 11, 12, 12, 12, 11, 13, 11, 12, 13, 12, 12, 12, 12, 12, 10,
13, 15, 15, 16, 15, 16, 16, 15, 16, 16, 16, 15, 15, 15, 16, 14,
10, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 13, 13, 13, 13, 11,
8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 12, 11, 12, 9,
11, 14, 14, 15, 14, 15, 15, 14, 13, 15, 14, 15, 12, 14, 15, 13,
12, 15, 15, 15, 15, 15, 16, 15, 15, 16, 16, 16, 15, 16, 15, 13,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
11, 14, 13, 15, 14, 14, 16, 14, 14, 16, 13, 14, 15, 14, 15, 12,
11, 14, 13, 14, 14, 14, 16, 15, 14, 16, 14, 14, 15, 15, 15, 12,
13, 15, 15, 15, 15, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 13,
11, 14, 13, 14, 14, 14, 15, 14, 14, 16, 12, 14, 16, 16, 14, 12,
11, 14, 14, 14, 14, 15, 16, 15, 14, 16, 13, 14, 16, 15, 14, 12,
12, 14, 14, 14, 14, 14, 16, 14, 15, 16, 14, 14, 14, 15, 15, 12,
11, 14, 14, 14, 13, 14, 16, 15, 13, 16, 15, 15, 11, 14, 14, 12,
11, 14, 14, 15, 14, 14, 16, 14, 14, 15, 14, 14, 13, 15, 15, 12,
13, 15, 16, 15, 15, 15, 16, 15, 16, 16, 16, 16, 15, 15, 16, 13,
11, 14, 14, 14, 14, 14, 15, 14, 14, 16, 14, 14, 14, 15, 14, 12,
9, 12, 12, 12, 12, 12, 13, 12, 12, 13, 12, 13, 12, 12, 12, 10,
11, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 14, 13, 13, 14, 11,
12, 15, 14, 15, 15, 15, 16, 15, 14, 16, 14, 14, 16, 16, 14, 13,
10, 12, 12, 12, 12, 12, 14, 12, 13, 13, 12, 12, 13, 13, 13, 10,
10, 12, 12, 12, 12, 12, 14, 12, 12, 13, 12, 12, 12, 12, 12, 10,
10, 14, 14, 14, 12, 14, 16, 14, 13, 16, 16, 16, 10, 13, 14, 12,
11, 14, 14, 14, 13, 14, 16, 14, 14, 16, 15, 14, 12, 13, 14, 12,
12, 14, 14, 14, 14, 14, 16, 14, 14, 16, 15, 15, 14, 14, 15, 12,
12, 14, 15, 15, 14, 15, 16, 14, 15, 15, 15, 15, 13, 15, 14, 12,
9, 12, 12, 12, 12, 13, 13, 12, 12, 13, 13, 12, 11, 12, 12, 10,
10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10,
13, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 15, 13,
10, 12, 12, 13, 12, 13, 13, 12, 13, 14, 13, 13, 12, 13, 13, 10,
7, 10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 7,
},
},
{
{
10, 10, 9, 8, 9, 8, 9, 7, 9, 9, 8, 7, 8, 7, 7, 4,
13, 11, 12, 9, 12, 9, 12, 9, 12, 11, 11, 9, 10, 9, 9, 6,
15, 12, 15, 11, 14, 10, 14, 10, 14, 13, 13, 11, 13, 11, 12, 7,
13, 12, 11, 9, 12, 11, 12, 9, 12, 12, 10, 9, 10, 10, 9, 6,
14, 13, 12, 10, 13, 12, 13, 9, 13, 12, 11, 10, 12, 11, 10, 6,
16, 14, 14, 10, 15, 13, 14, 10, 15, 15, 14, 11, 14, 12, 12, 8,
15, 14, 12, 11, 15, 14, 13, 11, 14, 14, 11, 10, 13, 12, 11, 8,
15, 16, 13, 11, 16, 14, 14, 11, 15, 15, 12, 10, 14, 13, 12, 8,
16, 15, 14, 10, 16, 14, 14, 10, 16, 15, 14, 10, 14, 13, 12, 7,
13, 12, 12, 11, 11, 9, 12, 9, 12, 12, 11, 10, 10, 9, 9, 6,
13, 13, 14, 12, 12, 10, 12, 10, 14, 13, 12, 11, 11, 10, 10, 7,
16, 14, 16, 13, 14, 11, 15, 10, 16, 15, 14, 12, 14, 11, 12, 8,
14, 14, 13, 12, 13, 12, 13, 10, 13, 13, 12, 11, 11, 10, 10, 7,
15, 14, 14, 12, 14, 12, 13, 10, 14, 13, 12, 11, 12, 11, 11, 7,
16, 15, 16, 13, 15, 13, 15, 10, 16, 15, 14, 12, 14, 12, 12, 7,
15, 16, 14, 13, 16, 14, 14, 12, 15, 15, 12, 12, 13, 12, 12, 8,
16, 16, 14, 13, 16, 14, 14, 11, 15, 15, 14, 11, 14, 12, 12, 8,
16, 16, 15, 12, 16, 14, 15, 10, 16, 16, 13, 12, 14, 13, 12, 7,
14, 14, 14, 13, 13, 11, 13, 11, 14, 14, 13, 12, 11, 10, 11, 8,
16, 15, 16, 13, 13, 11, 14, 11, 15, 14, 14, 13, 12, 11, 12, 8,
15, 15, 16, 14, 14, 10, 14, 10, 16, 15, 15, 13, 14, 10, 12, 8,
16, 16, 16, 14, 15, 13, 14, 12, 15, 15, 13, 13, 13, 12, 12, 8,
16, 16, 16, 14, 15, 13, 14, 11, 16, 16, 14, 13, 13, 12, 12, 8,
16, 16, 16, 14, 16, 12, 15, 11, 16, 15, 15, 13, 14, 12, 12, 8,
16, 16, 16, 16, 16, 15, 15, 13, 16, 16, 14, 13, 14, 13, 12, 9,
16, 16, 16, 14, 16, 15, 15, 11, 16, 16, 14, 13, 15, 13, 12, 8,
16, 16, 16, 14, 16, 14, 14, 10, 16, 16, 15, 13, 14, 12, 12, 7,
12, 12, 12, 11, 12, 11, 12, 10, 11, 11, 10, 9, 9, 9, 9, 6,
14, 13, 14, 12, 13, 12, 13, 10, 13, 13, 12, 10, 12, 10, 11, 7,
16, 14, 16, 13, 15, 13, 16, 12, 15, 14, 14, 12, 14, 12, 13, 8,
14, 14, 13, 11, 14, 12, 13, 11, 12, 12, 10, 10, 11, 10, 10, 7,
14, 14, 13, 12, 14, 12, 13, 11, 13, 13, 12, 10, 12, 11, 10, 7,
16, 15, 15, 12, 16, 14, 15, 11, 16, 14, 13, 11, 14, 12, 12, 8,
16, 16, 13, 13, 16, 15, 14, 12, 14, 14, 11, 11, 13, 12, 11, 8,
16, 16, 14, 12, 16, 14, 14, 12, 15, 14, 12, 11, 14, 12, 12, 8,
16, 15, 14, 11, 16, 15, 15, 11, 16, 15, 13, 11, 14, 13, 12, 8,
14, 13, 13, 12, 13, 11, 13, 10, 12, 13, 11, 10, 10, 10, 10, 7,
15, 14, 14, 13, 13, 12, 13, 11, 14, 13, 12, 11, 12, 10, 11, 7,
16, 15, 16, 14, 15, 12, 15, 11, 16, 14, 14, 12, 14, 11, 12, 8,
14, 15, 13, 12, 14, 13, 13, 11, 13, 13, 11, 11, 11, 10, 10, 7,
14, 14, 14, 12, 14, 13, 13, 10, 14, 13, 12, 10, 12, 10, 10, 6,
16, 15, 15, 13, 16, 13, 15, 11, 15, 14, 13, 11, 13, 11, 11, 7,
16, 16, 14, 13, 16, 15, 14, 12, 15, 15, 12, 11, 13, 12, 11, 8,
16, 16, 14, 13, 16, 14, 14, 11, 15, 14, 12, 11, 13, 12, 11, 7,
16, 16, 15, 12, 16, 14, 14, 11, 15, 15, 13, 11, 14, 12, 11, 6,
16, 15, 15, 14, 14, 12, 14, 12, 13, 14, 13, 12, 11, 11, 11, 8,
16, 16, 16, 14, 14, 12, 15, 12, 15, 14, 14, 12, 12, 11, 12, 8,
16, 16, 16, 15, 14, 12, 15, 12, 16, 15, 14, 13, 13, 11, 12, 8,
16, 16, 16, 15, 15, 14, 15, 12, 14, 14, 13, 12, 12, 11, 11, 8,
16, 16, 15, 14, 14, 12, 14, 11, 14, 14, 13, 12, 12, 11, 11, 7,
16, 16, 16, 14, 15, 12, 14, 11, 15, 15, 14, 12, 13, 11, 12, 7,
16, 16, 16, 16, 16, 15, 16, 13, 15, 15, 14, 12, 13, 12, 11, 8,
16, 16, 16, 14, 15, 14, 14, 12, 16, 15, 13, 12, 13, 12, 11, 7,
16, 16, 16, 13, 16, 13, 14, 10, 16, 15, 14, 11, 13, 11, 11, 6,
14, 15, 13, 13, 14, 13, 14, 12, 12, 13, 11, 11, 11, 11, 10, 8,
16, 16, 15, 13, 16, 14, 16, 13, 14, 14, 13, 12, 13, 12, 12, 8,
16, 16, 16, 14, 16, 14, 16, 13, 16, 14, 15, 13, 15, 13, 13, 9,
15, 15, 14, 14, 15, 14, 14, 12, 13, 14, 11, 11, 12, 12, 11, 8,
15, 16, 15, 13, 15, 14, 14, 12, 14, 14, 12, 11, 13, 12, 12, 8,
16, 16, 16, 13, 16, 15, 15, 13, 16, 15, 14, 11, 15, 12, 13, 8,
16, 16, 14, 13, 16, 15, 15, 13, 14, 14, 10, 11, 14, 12, 11, 8,
16, 16, 15, 13, 16, 16, 15, 13, 15, 14, 12, 11, 14, 13, 12, 8,
16, 16, 15, 13, 16, 15, 16, 12, 16, 14, 13, 10, 15, 13, 12, 7,
15, 15, 15, 14, 14, 14, 15, 12, 13, 14, 12, 12, 11, 11, 11, 8,
16, 15, 16, 14, 15, 13, 15, 12, 14, 14, 13, 12, 12, 11, 12, 8,
16, 16, 16, 15, 16, 14, 16, 13, 16, 15, 14, 12, 14, 11, 13, 8,
16, 16, 15, 14, 16, 14, 15, 13, 14, 14, 12, 11, 12, 11, 11, 8,
15, 16, 15, 14, 15, 14, 14, 12, 14, 13, 12, 11, 12, 11, 11, 7,
16, 16, 16, 14, 16, 13, 16, 12, 15, 14, 13, 11, 13, 11, 12, 7,
16, 16, 15, 14, 16, 15, 15, 13, 14, 15, 11, 11, 13, 12, 11, 8,
16, 16, 15, 13, 16, 14, 15, 12, 15, 14, 12, 11, 13, 11, 11, 7,
16, 16, 15, 13, 16, 14, 16, 12, 15, 14, 13, 10, 13, 11, 11, 6,
16, 16, 16, 14, 14, 14, 15, 13, 14, 14, 14, 12, 11, 11, 11, 8,
16, 16, 16, 14, 15, 14, 16, 13, 15, 14, 14, 13, 12, 11, 11, 7,
16, 16, 16, 16, 15, 13, 16, 12, 15, 15, 14, 12, 13, 10, 12, 7,
16, 16, 16, 14, 15, 15, 14, 13, 14, 14, 13, 12, 12, 11, 11, 8,
16, 15, 16, 14, 16, 13, 15, 12, 14, 14, 13, 12, 12, 10, 10, 6,
16, 15, 16, 14, 16, 13, 16, 11, 16, 14, 13, 11, 13, 10, 11, 6,
16, 16, 16, 15, 16, 16, 15, 13, 14, 16, 12, 12, 12, 12, 10, 7,
16, 16, 16, 14, 16, 14, 14, 12, 15, 15, 12, 11, 12, 11, 10, 6,
16, 16, 16, 13, 16, 13, 15, 10, 15, 14, 13, 10, 13, 10, 10, 4,
},
{
1, 6, 6, 7, 6, 7, 9, 8, 7, 9, 7, 8, 7, 8, 8, 6,
6, 9, 10, 10, 10, 10, 12, 11, 10, 12, 11, 11, 11, 11, 12, 9,
9, 10, 13, 11, 13, 12, 14, 13, 14, 14, 14, 14, 14, 14, 14, 12,
6, 10, 9, 10, 10, 11, 13, 11, 11, 13, 10, 12, 11, 12, 12, 9,
6, 10, 10, 10, 10, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 9,
9, 11, 13, 12, 13, 14, 15, 13, 14, 16, 14, 14, 14, 14, 15, 12,
10, 13, 11, 13, 14, 14, 16, 14, 14, 15, 13, 14, 15, 15, 16, 12,
9, 13, 12, 12, 14, 14, 16, 14, 14, 15, 14, 14, 15, 15, 15, 12,
8, 11, 12, 11, 13, 14, 15, 13, 13, 15, 14, 14, 13, 15, 15, 11,
6, 10, 10, 11, 9, 10, 13, 11, 10, 13, 11, 12, 10, 12, 12, 9,
6, 10, 10, 11, 11, 10, 13, 11, 11, 13, 11, 12, 12, 12, 13, 10,
9, 12, 13, 13, 13, 12, 16, 13, 14, 15, 14, 14, 15, 14, 15, 12,
8, 12, 12, 13, 12, 13, 15, 14, 13, 15, 13, 14, 13, 13, 14, 11,
7, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 13, 12, 13, 13, 10,
9, 12, 13, 13, 13, 13, 16, 13, 13, 15, 14, 14, 14, 15, 15, 12,
11, 15, 14, 15, 15, 16, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14,
10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 15, 15, 15, 15, 16, 13,
9, 12, 13, 13, 13, 14, 16, 14, 13, 15, 14, 14, 14, 16, 15, 12,
10, 13, 14, 14, 11, 13, 16, 14, 14, 16, 15, 15, 12, 14, 15, 12,
10, 13, 14, 14, 12, 12, 16, 15, 14, 16, 15, 15, 14, 14, 16, 12,
9, 12, 13, 14, 13, 11, 16, 13, 14, 15, 13, 14, 14, 14, 15, 12,
11, 15, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 13, 14, 14, 13, 14, 16, 15, 14, 16, 16, 16, 14, 15, 16, 13,
10, 13, 13, 14, 13, 13, 16, 13, 13, 14, 14, 15, 15, 14, 15, 13,
13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
12, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 12, 13, 14, 13, 13, 14, 13, 13, 14, 13, 14, 14, 14, 15, 12,
6, 10, 11, 11, 10, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 10,
8, 12, 13, 13, 12, 13, 14, 14, 13, 15, 14, 14, 14, 14, 15, 12,
12, 14, 16, 15, 15, 15, 16, 15, 16, 16, 16, 16, 16, 16, 16, 14,
7, 11, 11, 12, 12, 12, 14, 13, 12, 14, 11, 12, 13, 13, 13, 11,
8, 11, 12, 12, 12, 12, 14, 13, 12, 14, 12, 13, 13, 14, 14, 11,
11, 13, 14, 14, 14, 14, 16, 15, 15, 16, 15, 15, 16, 16, 16, 13,
10, 14, 12, 14, 14, 15, 16, 15, 13, 16, 12, 14, 16, 16, 15, 13,
10, 13, 13, 14, 14, 15, 16, 15, 14, 16, 14, 15, 15, 16, 16, 12,
10, 13, 14, 13, 14, 14, 16, 15, 14, 16, 15, 15, 14, 16, 16, 13,
7, 11, 11, 11, 10, 12, 14, 13, 11, 14, 13, 13, 10, 12, 13, 10,
8, 11, 12, 12, 11, 12, 14, 13, 12, 15, 13, 13, 12, 13, 14, 11,
11, 13, 14, 14, 14, 14, 16, 15, 14, 16, 15, 16, 16, 16, 16, 14,
8, 12, 12, 13, 12, 13, 15, 14, 12, 15, 13, 13, 13, 14, 14, 11,
6, 10, 10, 11, 10, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 9,
9, 12, 13, 13, 13, 13, 14, 13, 13, 15, 14, 14, 14, 14, 14, 12,
11, 15, 14, 15, 14, 15, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14,
9, 13, 12, 13, 13, 13, 15, 14, 13, 14, 13, 14, 14, 15, 14, 12,
9, 12, 12, 12, 12, 13, 14, 13, 13, 14, 13, 13, 13, 13, 14, 11,
10, 13, 15, 14, 12, 14, 16, 14, 14, 16, 15, 15, 12, 14, 16, 12,
10, 14, 14, 14, 13, 14, 16, 15, 14, 16, 16, 16, 13, 14, 16, 13,
11, 13, 14, 14, 14, 13, 16, 14, 14, 16, 15, 15, 15, 15, 16, 13,
11, 15, 15, 15, 14, 15, 16, 16, 15, 16, 16, 16, 14, 16, 16, 13,
9, 13, 13, 13, 12, 13, 15, 14, 13, 15, 14, 14, 13, 14, 15, 11,
9, 12, 12, 13, 12, 12, 14, 13, 13, 14, 13, 14, 14, 14, 14, 11,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
11, 14, 14, 15, 15, 14, 16, 16, 14, 16, 14, 15, 15, 16, 16, 12,
9, 12, 12, 13, 12, 12, 14, 12, 12, 14, 13, 13, 13, 13, 14, 11,
11, 14, 14, 16, 14, 16, 16, 16, 13, 16, 14, 16, 14, 16, 16, 13,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 15, 14, 16, 14, 15, 16, 16, 15, 16, 14, 15, 16, 16, 16, 13,
11, 15, 14, 16, 15, 16, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
11, 14, 13, 14, 15, 14, 16, 15, 14, 16, 12, 14, 16, 16, 15, 13,
11, 14, 14, 16, 14, 15, 16, 16, 15, 16, 14, 15, 16, 16, 16, 14,
12, 14, 14, 15, 14, 16, 16, 15, 14, 16, 15, 15, 15, 16, 16, 13,
11, 14, 15, 15, 13, 15, 16, 16, 14, 16, 16, 16, 12, 15, 15, 13,
11, 15, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
11, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 14, 15, 14, 14, 15, 12,
12, 15, 14, 16, 14, 15, 16, 15, 15, 16, 15, 15, 16, 15, 16, 13,
12, 16, 14, 16, 15, 16, 16, 16, 16, 16, 14, 15, 16, 16, 16, 14,
10, 13, 13, 14, 14, 13, 16, 14, 13, 16, 13, 14, 15, 15, 15, 12,
10, 13, 13, 14, 13, 13, 16, 14, 14, 15, 14, 14, 14, 14, 15, 12,
10, 14, 15, 14, 13, 15, 16, 15, 14, 16, 16, 16, 11, 14, 16, 12,
11, 14, 14, 16, 14, 15, 16, 15, 15, 16, 16, 16, 13, 15, 16, 13,
12, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13,
12, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13,
10, 13, 14, 14, 13, 14, 16, 14, 13, 16, 15, 14, 12, 14, 16, 11,
10, 13, 13, 14, 13, 14, 16, 14, 14, 15, 14, 14, 13, 14, 14, 11,
13, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
11, 13, 14, 15, 14, 14, 16, 15, 14, 16, 14, 15, 14, 15, 16, 12,
8, 11, 11, 11, 11, 12, 13, 12, 11, 13, 11, 12, 11, 12, 12, 9,
},
},
{
{
8, 8, 8, 7, 8, 7, 8, 6, 8, 8, 7, 6, 7, 6, 6, 4,
11, 10, 11, 9, 11, 9, 11, 8, 11, 10, 10, 9, 10, 8, 9, 6,
13, 11, 13, 10, 12, 10, 13, 9, 13, 12, 13, 10, 12, 10, 11, 7,
11, 11, 10, 9, 11, 10, 11, 9, 10, 11, 9, 8, 10, 9, 9, 6,
12, 12, 11, 9, 12, 11, 12, 9, 12, 12, 11, 9, 11, 10, 10, 7,
14, 13, 13, 10, 15, 12, 13, 10, 15, 13, 13, 10, 13, 12, 12, 8,
13, 13, 11, 10, 14, 13, 12, 10, 13, 13, 10, 10, 12, 11, 10, 8,
15, 14, 13, 10, 14, 13, 13, 10, 14, 13, 12, 10, 13, 12, 11, 8,
14, 14, 13, 10, 16, 13, 13, 10, 15, 14, 13, 10, 13, 12, 12, 8,
11, 11, 11, 10, 10, 9, 10, 9, 10, 10, 10, 9, 9, 8, 9, 6,
12, 12, 12, 11, 11, 9, 12, 9, 12, 12, 11, 10, 11, 9, 10, 7,
14, 13, 14, 12, 13, 10, 13, 10, 15, 13, 14, 12, 12, 10, 12, 8,
13, 13, 12, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7,
14, 13, 13, 11, 13, 12, 12, 10, 13, 13, 12, 11, 12, 10, 10, 7,
16, 15, 15, 12, 14, 12, 13, 10, 15, 14, 13, 12, 13, 12, 12, 8,
15, 15, 13, 13, 14, 14, 14, 12, 14, 14, 12, 11, 13, 12, 11, 8,
15, 16, 14, 12, 15, 14, 13, 11, 15, 15, 13, 12, 13, 12, 11, 8,
16, 15, 15, 12, 16, 14, 14, 10, 15, 15, 14, 12, 14, 12, 12, 8,
13, 13, 13, 13, 11, 10, 12, 10, 12, 13, 12, 11, 10, 10, 10, 8,
14, 13, 14, 13, 12, 10, 13, 10, 14, 14, 13, 12, 12, 10, 11, 8,
15, 14, 16, 14, 13, 10, 14, 10, 16, 14, 14, 13, 13, 10, 12, 8,
15, 15, 14, 14, 14, 13, 13, 12, 14, 14, 13, 12, 12, 11, 11, 9,
15, 15, 15, 14, 14, 12, 14, 11, 15, 14, 13, 13, 13, 11, 11, 8,
16, 15, 16, 14, 15, 12, 14, 11, 16, 16, 15, 13, 14, 12, 12, 8,
16, 16, 16, 14, 15, 14, 14, 12, 15, 15, 14, 13, 13, 12, 11, 9,
16, 16, 15, 15, 16, 14, 14, 11, 16, 16, 14, 13, 14, 12, 12, 8,
16, 16, 16, 13, 15, 13, 14, 10, 16, 16, 15, 13, 14, 12, 12, 8,
11, 11, 11, 10, 11, 10, 11, 9, 10, 10, 9, 8, 9, 9, 9, 6,
12, 12, 13, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7,
15, 13, 15, 12, 14, 13, 14, 11, 14, 13, 13, 11, 13, 11, 12, 8,
12, 13, 12, 11, 13, 11, 12, 10, 11, 12, 10, 9, 11, 10, 10, 7,
14, 13, 13, 11, 14, 12, 13, 11, 12, 12, 11, 10, 12, 11, 10, 7,
15, 14, 15, 12, 15, 13, 15, 11, 15, 14, 13, 11, 13, 12, 12, 8,
14, 14, 13, 12, 15, 14, 13, 12, 13, 13, 11, 10, 13, 12, 11, 8,
16, 15, 13, 12, 15, 14, 14, 12, 14, 14, 12, 11, 14, 12, 11, 8,
16, 15, 14, 12, 16, 15, 15, 11, 15, 14, 13, 11, 14, 13, 12, 8,
12, 12, 12, 11, 12, 11, 12, 10, 11, 11, 11, 10, 10, 9, 9, 7,
13, 13, 14, 12, 13, 11, 13, 11, 13, 12, 12, 11, 11, 10, 10, 7,
15, 14, 16, 13, 14, 12, 14, 11, 14, 14, 14, 12, 13, 11, 12, 8,
13, 13, 13, 12, 13, 12, 13, 11, 12, 12, 11, 10, 11, 10, 10, 7,
14, 14, 13, 12, 13, 12, 13, 10, 13, 13, 11, 10, 12, 10, 10, 7,
16, 15, 15, 13, 15, 12, 14, 11, 15, 14, 13, 11, 13, 11, 11, 7,
15, 16, 14, 13, 15, 14, 14, 12, 14, 14, 12, 11, 13, 12, 11, 8,
16, 15, 14, 13, 15, 14, 14, 11, 14, 14, 12, 11, 13, 12, 11, 7,
16, 15, 15, 12, 16, 14, 14, 11, 15, 14, 13, 11, 14, 12, 11, 7,
14, 15, 14, 14, 13, 12, 13, 12, 13, 13, 12, 12, 11, 10, 11, 8,
15, 15, 15, 14, 13, 12, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8,
16, 15, 16, 14, 14, 12, 15, 12, 16, 14, 14, 13, 13, 11, 12, 8,
15, 15, 15, 14, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8,
15, 15, 15, 14, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7,
16, 15, 16, 14, 15, 12, 15, 11, 15, 14, 14, 12, 13, 11, 12, 7,
16, 16, 16, 15, 16, 15, 14, 13, 15, 15, 13, 12, 13, 12, 11, 9,
16, 16, 16, 14, 15, 14, 14, 12, 15, 15, 13, 12, 14, 12, 11, 8,
16, 16, 16, 14, 16, 14, 14, 11, 15, 15, 14, 12, 14, 12, 11, 7,
13, 13, 13, 12, 13, 12, 13, 11, 11, 12, 11, 10, 10, 10, 10, 8,
15, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 13, 11, 11, 8,
16, 15, 16, 14, 16, 14, 16, 13, 15, 14, 14, 12, 14, 12, 13, 9,
14, 15, 13, 13, 14, 13, 14, 12, 12, 13, 11, 11, 12, 11, 11, 8,
15, 15, 14, 13, 15, 14, 14, 12, 13, 13, 12, 11, 13, 12, 11, 8,
16, 16, 16, 13, 16, 15, 16, 13, 15, 14, 14, 12, 14, 13, 13, 9,
14, 15, 13, 13, 16, 15, 15, 13, 13, 14, 11, 11, 13, 12, 11, 9,
16, 16, 14, 13, 16, 15, 16, 13, 14, 14, 12, 11, 14, 13, 12, 8,
16, 16, 15, 12, 16, 15, 15, 12, 15, 14, 13, 11, 14, 13, 12, 8,
14, 14, 14, 13, 14, 13, 14, 12, 12, 13, 12, 11, 11, 11, 11, 8,
15, 15, 15, 14, 14, 13, 15, 12, 14, 13, 13, 12, 12, 11, 11, 8,
16, 16, 16, 15, 15, 14, 16, 13, 15, 14, 14, 12, 14, 12, 12, 9,
15, 15, 14, 14, 14, 14, 14, 13, 13, 14, 12, 11, 12, 11, 11, 8,
15, 15, 15, 13, 15, 14, 14, 12, 13, 13, 12, 11, 12, 11, 11, 7,
16, 15, 16, 14, 16, 14, 15, 12, 15, 14, 14, 12, 13, 12, 12, 8,
16, 16, 15, 14, 16, 15, 15, 13, 14, 14, 12, 11, 13, 12, 11, 8,
16, 16, 15, 13, 16, 14, 14, 12, 14, 15, 12, 11, 13, 12, 11, 7,
16, 16, 16, 13, 16, 15, 15, 12, 15, 14, 13, 11, 14, 12, 11, 7,
15, 15, 15, 14, 13, 13, 14, 13, 13, 14, 13, 12, 11, 11, 11, 8,
16, 16, 16, 14, 15, 13, 15, 12, 14, 14, 14, 13, 12, 11, 12, 8,
16, 16, 16, 14, 15, 13, 15, 12, 15, 14, 14, 12, 13, 11, 12, 8,
15, 16, 16, 14, 15, 14, 15, 13, 14, 14, 12, 12, 11, 11, 11, 8,
16, 15, 15, 14, 15, 14, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7,
16, 16, 16, 13, 15, 13, 15, 12, 15, 14, 14, 12, 13, 11, 11, 7,
16, 16, 16, 15, 15, 16, 15, 13, 14, 14, 12, 12, 12, 12, 11, 8,
16, 16, 16, 14, 16, 14, 14, 12, 15, 15, 13, 11, 12, 11, 10, 7,
16, 16, 15, 13, 16, 14, 14, 11, 15, 14, 13, 10, 13, 11, 10, 5,
},
{
1, 6, 6, 7, 6, 7, 9, 7, 6, 9, 7, 8, 7, 8, 8, 5,
5, 8, 10, 10, 10, 10, 12, 11, 11, 12, 11, 11, 11, 12, 12, 9,
9, 10, 12, 11, 13, 12, 15, 13, 14, 15, 15, 14, 14, 15, 15, 12,
6, 10, 9, 10, 10, 11, 13, 12, 11, 13, 11, 12, 12, 12, 12, 10,
6, 10, 10, 10, 11, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 10,
9, 12, 13, 12, 13, 13, 16, 13, 14, 16, 15, 14, 14, 15, 16, 12,
9, 13, 11, 13, 14, 14, 16, 15, 14, 16, 13, 15, 15, 15, 15, 12,
9, 13, 12, 13, 14, 15, 16, 15, 14, 16, 15, 15, 15, 15, 16, 12,
8, 12, 12, 11, 13, 14, 15, 13, 13, 15, 14, 14, 14, 14, 14, 12,
6, 10, 10, 11, 9, 10, 13, 11, 11, 13, 12, 12, 10, 12, 12, 9,
6, 10, 11, 11, 11, 10, 13, 12, 11, 13, 12, 12, 12, 12, 13, 10,
9, 12, 13, 13, 13, 12, 16, 13, 14, 16, 14, 15, 16, 14, 15, 12,
8, 12, 13, 13, 13, 13, 16, 14, 13, 16, 13, 14, 14, 14, 14, 12,
7, 11, 11, 12, 11, 12, 14, 13, 12, 14, 13, 13, 12, 13, 13, 11,
9, 12, 13, 13, 13, 13, 15, 14, 14, 16, 16, 15, 15, 15, 16, 12,
11, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 14, 14, 15, 15, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13,
9, 13, 13, 13, 14, 14, 16, 14, 14, 16, 15, 14, 14, 16, 16, 13,
9, 13, 14, 14, 11, 13, 16, 14, 13, 16, 15, 16, 13, 14, 15, 12,
10, 13, 14, 15, 13, 12, 16, 14, 14, 16, 15, 15, 14, 14, 16, 13,
9, 12, 13, 14, 12, 11, 15, 13, 13, 15, 13, 14, 15, 14, 16, 12,
11, 15, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13,
11, 14, 14, 15, 13, 14, 16, 15, 15, 16, 16, 16, 16, 16, 16, 13,
10, 12, 13, 14, 13, 13, 16, 14, 14, 14, 14, 16, 15, 14, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
9, 12, 13, 14, 13, 13, 16, 13, 13, 15, 15, 16, 15, 15, 16, 12,
6, 11, 11, 12, 10, 12, 13, 12, 11, 13, 11, 12, 11, 12, 13, 10,
9, 12, 13, 13, 13, 13, 16, 14, 14, 15, 14, 14, 14, 14, 14, 12,
12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
7, 11, 11, 12, 12, 12, 14, 13, 12, 14, 11, 13, 13, 13, 13, 11,
8, 12, 12, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13, 14, 14, 11,
11, 14, 14, 15, 16, 15, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13,
10, 14, 12, 14, 15, 15, 16, 16, 14, 16, 12, 15, 16, 16, 16, 13,
11, 14, 13, 15, 15, 15, 16, 16, 14, 16, 14, 14, 16, 16, 16, 13,
11, 14, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 13,
7, 11, 12, 11, 10, 12, 14, 13, 12, 14, 13, 13, 10, 12, 13, 10,
8, 12, 12, 13, 12, 12, 15, 13, 13, 14, 13, 13, 13, 13, 14, 11,
11, 13, 15, 16, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
9, 12, 13, 13, 13, 13, 15, 14, 13, 15, 13, 14, 13, 14, 14, 12,
7, 11, 11, 11, 11, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 10,
9, 12, 13, 13, 13, 13, 16, 13, 14, 16, 15, 14, 14, 14, 16, 12,
12, 14, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14,
10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 14, 14, 16, 15, 15, 12,
9, 12, 13, 13, 13, 15, 16, 14, 13, 16, 14, 13, 13, 14, 14, 11,
10, 14, 15, 14, 12, 14, 16, 15, 13, 16, 16, 16, 12, 14, 16, 12,
11, 14, 14, 14, 14, 14, 16, 15, 15, 16, 16, 16, 14, 15, 16, 13,
11, 14, 14, 16, 14, 13, 16, 15, 14, 16, 15, 16, 15, 15, 16, 13,
12, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14,
10, 13, 14, 14, 13, 14, 16, 14, 13, 16, 15, 15, 13, 14, 14, 12,
9, 12, 13, 14, 13, 12, 16, 14, 13, 16, 14, 14, 14, 14, 15, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
9, 12, 13, 13, 13, 13, 14, 13, 12, 15, 14, 14, 14, 14, 14, 11,
11, 14, 14, 16, 14, 16, 16, 16, 13, 16, 14, 16, 14, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 14, 14, 16, 16, 15, 16, 16, 15, 16, 14, 16, 16, 16, 16, 14,
12, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 14, 12, 15, 15, 15, 16, 16, 14, 16, 12, 14, 16, 16, 15, 14,
12, 15, 14, 16, 16, 16, 16, 16, 15, 16, 14, 16, 16, 16, 16, 14,
12, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14,
11, 15, 15, 16, 14, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
11, 15, 14, 16, 14, 14, 16, 15, 14, 16, 15, 16, 15, 16, 16, 12,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
12, 16, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14,
10, 14, 13, 14, 15, 14, 16, 15, 14, 16, 13, 16, 16, 16, 15, 13,
10, 14, 14, 14, 13, 14, 16, 15, 15, 16, 14, 14, 14, 16, 16, 12,
10, 14, 15, 14, 13, 16, 16, 15, 13, 16, 16, 16, 12, 14, 16, 12,
11, 16, 16, 16, 14, 15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13,
12, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14,
11, 14, 14, 14, 14, 15, 16, 14, 14, 16, 16, 16, 13, 15, 15, 12,
10, 14, 13, 14, 14, 14, 16, 15, 14, 16, 15, 15, 14, 14, 16, 12,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
12, 14, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 13,
8, 11, 11, 12, 12, 12, 13, 12, 11, 13, 12, 12, 12, 13, 12, 10,
},
},
{
{
5, 6, 6, 6, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 4,
9, 9, 9, 8, 9, 8, 10, 8, 10, 10, 9, 9, 9, 8, 9, 6,
11, 10, 12, 10, 11, 10, 12, 9, 12, 11, 11, 10, 11, 10, 11, 8,
9, 10, 9, 8, 10, 10, 10, 9, 9, 10, 8, 8, 9, 9, 8, 7,
10, 11, 10, 9, 11, 11, 11, 9, 11, 11, 10, 9, 10, 10, 10, 7,
13, 12, 12, 10, 13, 12, 13, 10, 13, 12, 12, 11, 13, 12, 11, 9,
11, 12, 10, 10, 12, 12, 11, 10, 11, 12, 10, 10, 11, 11, 10, 8,
12, 12, 11, 10, 13, 13, 13, 10, 13, 13, 12, 11, 13, 12, 11, 9,
12, 12, 12, 10, 13, 13, 13, 10, 13, 13, 12, 10, 13, 12, 12, 9,
9, 9, 10, 10, 9, 8, 10, 9, 9, 10, 9, 9, 8, 8, 9, 6,
10, 11, 11, 11, 10, 9, 11, 9, 11, 11, 11, 10, 10, 9, 10, 7,
12, 12, 13, 12, 12, 10, 13, 10, 13, 13, 13, 12, 12, 11, 11, 9,
11, 12, 11, 11, 11, 11, 11, 10, 11, 12, 10, 10, 10, 10, 10, 8,
12, 12, 12, 11, 12, 11, 11, 10, 12, 12, 11, 11, 11, 11, 10, 8,
14, 13, 13, 12, 13, 12, 13, 10, 14, 14, 13, 12, 13, 12, 12, 9,
13, 14, 13, 12, 13, 13, 13, 12, 13, 13, 12, 12, 12, 12, 11, 9,
14, 14, 13, 12, 13, 13, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9,
14, 15, 14, 12, 15, 13, 13, 11, 15, 14, 14, 12, 14, 13, 12, 9,
11, 11, 12, 12, 10, 10, 12, 11, 11, 12, 11, 11, 10, 10, 10, 8,
12, 12, 14, 13, 11, 10, 12, 11, 13, 13, 13, 12, 12, 10, 11, 9,
13, 13, 14, 14, 12, 10, 13, 11, 14, 14, 14, 13, 12, 11, 12, 9,
13, 13, 13, 13, 12, 13, 13, 12, 13, 14, 12, 12, 12, 12, 11, 9,
13, 14, 14, 13, 13, 12, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9,
14, 14, 14, 14, 14, 12, 13, 11, 15, 15, 15, 13, 14, 12, 12, 9,
14, 15, 15, 13, 14, 14, 13, 12, 13, 14, 13, 13, 12, 12, 11, 10,
16, 16, 15, 14, 15, 14, 13, 11, 15, 15, 14, 13, 13, 13, 12, 9,
15, 15, 15, 13, 14, 13, 13, 11, 15, 15, 15, 13, 14, 13, 12, 9,
8, 9, 9, 9, 9, 9, 10, 9, 8, 10, 9, 9, 8, 8, 9, 7,
11, 11, 11, 11, 11, 11, 12, 10, 11, 11, 11, 10, 10, 10, 10, 8,
13, 13, 14, 12, 13, 12, 14, 11, 13, 13, 13, 12, 13, 11, 12, 9,
10, 11, 10, 11, 11, 11, 12, 10, 10, 11, 10, 10, 10, 10, 10, 8,
12, 12, 12, 11, 12, 12, 12, 11, 11, 12, 11, 10, 11, 11, 10, 8,
14, 13, 14, 12, 14, 13, 14, 12, 14, 13, 13, 11, 13, 12, 12, 9,
12, 13, 12, 12, 13, 13, 13, 12, 12, 13, 11, 11, 12, 12, 11, 9,
13, 14, 13, 12, 14, 14, 14, 12, 14, 13, 12, 11, 13, 12, 12, 9,
14, 14, 13, 12, 15, 14, 15, 12, 14, 14, 13, 11, 13, 13, 12, 9,
10, 11, 11, 11, 10, 10, 12, 10, 10, 11, 10, 10, 9, 9, 10, 7,
12, 12, 13, 12, 12, 11, 12, 11, 12, 12, 12, 11, 11, 10, 10, 8,
14, 13, 14, 13, 14, 12, 13, 12, 14, 13, 14, 12, 13, 11, 12, 9,
12, 13, 12, 12, 12, 12, 12, 11, 11, 12, 11, 10, 10, 10, 10, 8,
12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 10, 11, 10, 10, 7,
14, 14, 14, 12, 14, 12, 14, 11, 14, 13, 13, 11, 13, 11, 11, 8,
13, 15, 13, 13, 14, 14, 14, 12, 13, 14, 12, 12, 12, 12, 11, 9,
14, 15, 13, 12, 14, 13, 13, 11, 13, 13, 12, 11, 13, 12, 11, 8,
15, 15, 15, 12, 15, 14, 14, 11, 14, 14, 13, 11, 13, 12, 12, 8,
12, 13, 13, 13, 12, 12, 13, 12, 12, 13, 12, 12, 11, 11, 11, 9,
13, 14, 15, 14, 13, 12, 14, 12, 13, 13, 14, 12, 12, 11, 12, 9,
14, 14, 15, 14, 14, 12, 14, 12, 14, 14, 14, 13, 13, 11, 12, 9,
13, 14, 14, 14, 13, 13, 14, 13, 13, 13, 12, 12, 12, 12, 11, 9,
14, 14, 14, 13, 13, 13, 13, 12, 13, 14, 13, 12, 12, 11, 11, 8,
15, 14, 15, 14, 14, 13, 14, 11, 15, 14, 14, 12, 13, 11, 12, 8,
14, 15, 14, 14, 15, 14, 14, 13, 14, 15, 13, 13, 12, 12, 11, 10,
16, 15, 14, 14, 14, 14, 13, 12, 14, 14, 13, 12, 13, 12, 11, 9,
15, 15, 15, 14, 16, 14, 14, 11, 15, 15, 14, 12, 13, 12, 11, 8,
11, 12, 11, 12, 12, 12, 12, 11, 10, 11, 10, 10, 10, 10, 10, 8,
13, 13, 13, 13, 13, 13, 14, 12, 12, 12, 12, 12, 12, 11, 12, 9,
14, 14, 14, 13, 15, 13, 15, 13, 14, 14, 14, 12, 14, 12, 13, 10,
12, 13, 12, 13, 13, 13, 13, 12, 11, 12, 11, 11, 12, 11, 11, 9,
14, 14, 13, 13, 14, 14, 14, 12, 12, 13, 12, 11, 13, 12, 12, 9,
14, 14, 15, 13, 15, 15, 15, 13, 15, 13, 13, 12, 14, 12, 13, 10,
13, 15, 12, 13, 14, 14, 14, 13, 12, 13, 11, 11, 13, 12, 11, 10,
14, 15, 14, 13, 15, 14, 15, 13, 14, 14, 12, 11, 13, 13, 12, 9,
14, 15, 14, 13, 15, 14, 15, 13, 14, 14, 13, 11, 14, 13, 12, 9,
12, 13, 13, 13, 12, 13, 13, 12, 11, 12, 12, 11, 11, 11, 11, 9,
13, 14, 14, 13, 14, 13, 14, 12, 13, 13, 13, 12, 12, 11, 11, 9,
15, 15, 16, 14, 15, 14, 14, 13, 15, 14, 14, 13, 13, 12, 13, 10,
13, 14, 14, 13, 13, 14, 14, 13, 12, 13, 12, 12, 11, 11, 11, 9,
14, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 12, 11, 11, 8,
15, 15, 15, 13, 15, 14, 14, 12, 14, 13, 13, 12, 13, 12, 12, 9,
14, 15, 14, 14, 15, 15, 14, 13, 13, 14, 12, 12, 13, 12, 12, 9,
15, 15, 14, 13, 15, 14, 14, 13, 14, 14, 12, 11, 13, 12, 11, 8,
15, 16, 14, 13, 15, 15, 15, 12, 14, 14, 13, 11, 14, 12, 12, 8,
12, 14, 13, 13, 13, 13, 14, 12, 12, 13, 12, 12, 10, 11, 11, 9,
14, 15, 15, 14, 13, 13, 15, 13, 13, 14, 14, 12, 12, 11, 12, 9,
15, 15, 16, 14, 14, 13, 15, 13, 14, 14, 14, 13, 13, 11, 12, 9,
14, 15, 14, 14, 14, 14, 14, 13, 13, 14, 13, 12, 12, 12, 11, 9,
14, 15, 15, 14, 14, 14, 14, 12, 13, 14, 13, 12, 12, 11, 11, 8,
15, 15, 15, 14, 14, 13, 15, 12, 15, 14, 14, 12, 13, 11, 11, 8,
14, 16, 14, 14, 14, 15, 14, 13, 13, 14, 12, 12, 12, 12, 11, 9,
15, 15, 15, 14, 15, 14, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8,
15, 15, 14, 13, 15, 13, 14, 12, 14, 14, 13, 11, 13, 11, 11, 7,
},
{
1, 5, 6, 7, 6, 7, 9, 8, 6, 9, 8, 8, 7, 8, 8, 6,
5, 8, 10, 10, 10, 11, 13, 12, 11, 13, 12, 12, 12, 12, 13, 10,
8, 10, 13, 12, 13, 13, 16, 14, 14, 16, 16, 14, 16, 16, 16, 12,
5, 10, 9, 11, 11, 12, 13, 12, 11, 13, 11, 12, 12, 12, 13, 10,
6, 10, 11, 11, 11, 12, 14, 12, 11, 13, 13, 13, 12, 13, 13, 11,
8, 12, 13, 12, 14, 14, 16, 14, 14, 16, 16, 16, 16, 16, 16, 13,
9, 13, 11, 14, 14, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13,
9, 13, 13, 13, 14, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 14,
8, 12, 13, 12, 13, 14, 16, 14, 14, 16, 16, 16, 14, 16, 16, 13,
5, 10, 11, 12, 9, 11, 13, 12, 11, 13, 13, 13, 11, 12, 13, 10,
6, 10, 11, 12, 11, 11, 14, 13, 12, 14, 12, 13, 13, 13, 13, 11,
9, 12, 14, 15, 13, 13, 16, 16, 14, 16, 16, 16, 16, 16, 16, 13,
8, 13, 13, 14, 13, 14, 16, 16, 14, 16, 14, 16, 14, 16, 14, 13,
7, 11, 12, 13, 12, 12, 14, 13, 12, 14, 13, 14, 13, 14, 14, 12,
9, 13, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 15, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
9, 13, 14, 14, 14, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14,
9, 13, 14, 15, 11, 13, 16, 14, 14, 16, 16, 16, 13, 14, 16, 13,
9, 13, 14, 16, 13, 13, 16, 16, 14, 16, 16, 16, 16, 15, 16, 14,
8, 12, 13, 16, 13, 12, 16, 14, 13, 16, 14, 16, 16, 16, 16, 13,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 14, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
9, 13, 16, 16, 14, 14, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 13, 14, 15, 14, 14, 16, 14, 13, 16, 16, 16, 14, 16, 16, 14,
6, 11, 11, 12, 11, 12, 14, 13, 11, 14, 12, 13, 12, 13, 13, 11,
9, 13, 13, 14, 13, 14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 13,
11, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
7, 11, 11, 13, 12, 13, 16, 14, 12, 16, 12, 14, 14, 14, 14, 12,
8, 12, 12, 13, 12, 14, 16, 14, 13, 16, 14, 14, 14, 14, 14, 12,
11, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 14, 13, 16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16,
10, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
7, 11, 12, 12, 11, 13, 16, 14, 12, 15, 14, 14, 11, 13, 13, 12,
8, 12, 12, 13, 13, 13, 16, 14, 13, 16, 13, 15, 13, 14, 14, 12,
11, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
8, 12, 13, 14, 13, 14, 16, 16, 14, 16, 14, 16, 14, 16, 15, 13,
6, 11, 11, 12, 11, 12, 13, 13, 11, 13, 12, 13, 12, 13, 13, 11,
9, 13, 14, 14, 14, 14, 16, 14, 14, 16, 16, 16, 16, 16, 14, 13,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 14, 13, 14, 14, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13,
9, 13, 14, 13, 13, 16, 16, 14, 13, 16, 16, 16, 13, 16, 14, 13,
10, 14, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 13, 14, 16, 14,
11, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 14, 16, 16, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 14, 14, 14, 14, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 13,
9, 13, 13, 16, 14, 14, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 13, 14, 14, 13, 16, 16, 14, 13, 16, 14, 16, 14, 14, 16, 12,
10, 14, 14, 16, 16, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 14,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 14, 13, 16, 16, 16, 16, 16, 14, 16, 12, 16, 16, 16, 16, 14,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 14,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15,
11, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 15, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 14,
10, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
10, 14, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 14,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16,
11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 15, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13,
10, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
8, 12, 12, 13, 12, 14, 14, 14, 12, 16, 13, 14, 12, 14, 14, 11,
},
},
};
static const uint8_t rv34_table_intra_cbp[NUM_INTRA_TABLES][8][CBP_VLC_SIZE] = {
{
{ 0, 3, 3, 4, 3, 5, 5, 5, 2, 5, 4, 6, 4, 6, 6, 6, },
{ 0, 2, 3, 4, 2, 5, 6, 7, 3, 6, 5, 7, 4, 7, 8, 8, },
{ 0, 3, 4, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 6, 3, 5, 6, 5, },
{ 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 4, 5, 4, 4, 4, 2, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 6, 6, 5, 6, 5, 6, 4, 6, 6, 5, 4, 4, 4, 4, 1, },
{ 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, },
},
{
{ 0, 4, 3, 4, 3, 4, 5, 4, 3, 5, 4, 5, 3, 5, 5, 5, },
{ 0, 2, 3, 4, 2, 5, 6, 7, 3, 6, 5, 7, 4, 7, 8, 8, },
{ 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 3, 4, 4, 3, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 6, 3, 5, 6, 5, },
{ 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 5, 5, 4, 4, 4, 2, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 5, 6, 5, 5, 5, 6, 4, 6, 6, 5, 4, 5, 4, 4, 1, },
{ 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 5, 4, 4, 4, 5, 2, },
},
{
{ 0, 3, 3, 4, 3, 4, 4, 5, 3, 5, 4, 5, 4, 5, 5, 5, },
{ 0, 2, 3, 4, 2, 4, 6, 7, 3, 6, 5, 7, 5, 7, 8, 8, },
{ 0, 4, 4, 4, 4, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4, 3, },
{ 0, 3, 3, 4, 3, 3, 6, 6, 3, 6, 4, 6, 3, 6, 6, 5, },
{ 0, 4, 4, 4, 3, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 5, 5, 4, 4, 1, },
{ 0, 4, 4, 4, 4, 4, 6, 4, 4, 6, 5, 4, 4, 4, 4, 2, },
},
{
{ 0, 3, 3, 4, 3, 4, 4, 5, 3, 5, 4, 5, 4, 5, 5, 5, },
{ 0, 2, 3, 4, 2, 4, 7, 6, 3, 7, 5, 7, 5, 7, 7, 7, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 3, 3, 3, 3, 4, 6, 6, 3, 6, 4, 6, 3, 6, 6, 5, },
{ 0, 3, 4, 4, 3, 4, 5, 4, 4, 5, 4, 5, 4, 5, 4, 3, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 4, 5, 4, 4, 4, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, },
{ 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, },
},
{
{ 0, 3, 3, 4, 3, 4, 5, 6, 2, 5, 4, 7, 4, 6, 6, 7, },
{ 0, 2, 3, 4, 2, 4, 6, 7, 3, 7, 5, 7, 5, 7, 7, 7, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 2, 3, 4, 3, 4, 6, 5, 3, 6, 4, 6, 4, 6, 6, 6, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, },
{ 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, },
{ 0, 3, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3, },
},
};
static const uint8_t rv34_table_intra_firstpat[NUM_INTRA_TABLES][4][FIRSTBLK_VLC_SIZE] = {
{
{
0, 10, 5, 10, 7, 12, 9, 11, 8, 13, 9, 12, 10, 13, 11, 12,
16, 16, 14, 15, 15, 16, 13, 14, 5, 12, 6, 11, 9, 13, 10, 11,
9, 14, 9, 12, 11, 14, 11, 12, 16, 16, 14, 15, 15, 16, 13, 13,
10, 15, 9, 12, 12, 16, 11, 12, 12, 16, 10, 13, 13, 16, 11, 12,
16, 16, 13, 14, 15, 16, 13, 12, 6, 12, 8, 11, 8, 12, 10, 11,
9, 14, 10, 12, 10, 13, 11, 12, 15, 16, 14, 15, 14, 16, 13, 13,
8, 13, 9, 12, 10, 13, 10, 12, 10, 14, 9, 12, 11, 14, 10, 12,
15, 16, 13, 15, 14, 16, 13, 13, 11, 16, 10, 13, 13, 16, 11, 12,
12, 16, 11, 13, 13, 16, 11, 12, 16, 16, 13, 14, 15, 16, 12, 12,
10, 16, 12, 14, 10, 14, 11, 12, 12, 16, 13, 14, 11, 14, 12, 12,
16, 16, 15, 16, 14, 15, 13, 13, 11, 16, 12, 14, 11, 14, 11, 12,
12, 16, 12, 14, 11, 14, 11, 12, 16, 16, 14, 15, 13, 15, 13, 12,
14, 16, 13, 14, 13, 16, 12, 12, 14, 16, 13, 14, 13, 16, 12, 12,
16, 16, 14, 14, 14, 15, 12, 11, 2, 10, 6, 10, 7, 12, 9, 11,
8, 12, 9, 11, 10, 13, 10, 11, 15, 16, 14, 15, 14, 16, 13, 13,
5, 12, 6, 11, 9, 13, 10, 11, 9, 13, 9, 11, 10, 13, 10, 11,
15, 16, 13, 14, 14, 16, 13, 13, 9, 15, 8, 12, 12, 15, 11, 11,
11, 16, 10, 12, 13, 15, 11, 11, 15, 16, 13, 14, 15, 16, 12, 12,
6, 12, 8, 11, 8, 12, 9, 11, 9, 14, 9, 12, 10, 13, 10, 11,
15, 16, 14, 15, 14, 16, 13, 13, 7, 13, 8, 11, 9, 13, 10, 11,
9, 14, 9, 12, 10, 13, 10, 11, 14, 16, 13, 14, 13, 16, 12, 12,
11, 16, 10, 12, 12, 15, 11, 11, 11, 16, 10, 12, 12, 15, 11, 11,
15, 16, 12, 13, 14, 16, 12, 11, 9, 15, 11, 13, 9, 13, 11, 12,
11, 16, 12, 14, 10, 14, 11, 12, 16, 16, 14, 15, 13, 15, 12, 12,
11, 16, 11, 14, 10, 14, 11, 12, 11, 16, 12, 13, 11, 14, 11, 11,
15, 16, 14, 15, 13, 14, 12, 12, 13, 16, 12, 14, 13, 15, 11, 11,
13, 16, 12, 14, 13, 15, 11, 11, 16, 16, 13, 14, 13, 15, 11, 10,
5, 12, 7, 11, 8, 13, 10, 11, 9, 13, 9, 12, 10, 14, 11, 12,
16, 16, 14, 15, 14, 16, 13, 13, 7, 13, 7, 11, 9, 13, 10, 11,
9, 14, 9, 12, 11, 14, 11, 12, 16, 16, 14, 14, 14, 16, 13, 13,
9, 15, 8, 12, 12, 15, 11, 12, 11, 16, 10, 12, 13, 16, 11, 12,
16, 16, 13, 14, 15, 16, 12, 12, 7, 13, 8, 12, 9, 13, 10, 11,
10, 14, 10, 12, 10, 14, 11, 12, 16, 16, 14, 15, 14, 16, 13, 13,
8, 14, 9, 12, 10, 13, 10, 11, 9, 14, 9, 12, 10, 14, 10, 11,
15, 16, 13, 14, 14, 16, 12, 12, 11, 16, 10, 12, 12, 15, 11, 12,
11, 16, 10, 12, 12, 15, 11, 11, 15, 16, 12, 14, 14, 16, 12, 11,
10, 16, 11, 13, 9, 14, 11, 12, 12, 16, 12, 14, 11, 14, 11, 12,
16, 16, 14, 16, 14, 15, 13, 12, 11, 16, 11, 14, 10, 14, 11, 12,
11, 16, 12, 14, 11, 14, 11, 11, 15, 16, 14, 15, 13, 15, 12, 12,
13, 16, 12, 14, 13, 15, 11, 11, 13, 16, 12, 14, 12, 14, 11, 11,
15, 16, 12, 13, 13, 14, 11, 10, 6, 13, 8, 11, 9, 13, 10, 11,
10, 14, 10, 12, 10, 13, 10, 11, 15, 16, 13, 13, 13, 14, 12, 11,
7, 13, 8, 11, 9, 13, 9, 11, 10, 14, 9, 11, 10, 13, 10, 11,
15, 16, 13, 13, 13, 14, 11, 11, 9, 14, 8, 11, 10, 13, 9, 10,
11, 15, 9, 11, 11, 13, 9, 10, 15, 16, 12, 13, 13, 14, 10, 9,
7, 13, 8, 11, 9, 13, 9, 11, 10, 14, 10, 12, 10, 13, 10, 11,
15, 16, 13, 13, 13, 14, 11, 11, 8, 13, 8, 11, 9, 13, 9, 10,
9, 14, 9, 11, 10, 13, 9, 10, 14, 16, 12, 13, 13, 14, 11, 10,
9, 14, 8, 11, 10, 13, 9, 9, 10, 14, 8, 11, 10, 13, 9, 9,
14, 16, 11, 12, 12, 14, 10, 9, 9, 14, 9, 12, 8, 12, 9, 10,
11, 15, 10, 12, 10, 13, 9, 10, 15, 16, 13, 13, 12, 13, 11, 10,
9, 14, 9, 12, 9, 12, 9, 10, 10, 14, 10, 12, 9, 12, 9, 9,
14, 16, 12, 13, 11, 13, 10, 9, 10, 14, 9, 11, 10, 12, 8, 8,
10, 14, 9, 11, 10, 12, 8, 8, 12, 14, 9, 10, 10, 11, 8, 7,
},
{
0, 9, 6, 9, 6, 10, 8, 9, 7, 11, 8, 11, 9, 11, 9, 10,
14, 16, 13, 14, 13, 14, 12, 11, 5, 11, 7, 10, 8, 10, 8, 9,
8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11,
10, 14, 9, 11, 11, 13, 10, 10, 11, 15, 9, 11, 12, 13, 10, 10,
15, 16, 12, 12, 13, 14, 11, 9, 6, 11, 7, 10, 7, 10, 8, 9,
8, 12, 9, 11, 9, 11, 9, 10, 14, 16, 13, 13, 13, 14, 11, 11,
7, 12, 8, 11, 8, 11, 9, 9, 9, 13, 9, 11, 9, 12, 9, 10,
14, 16, 12, 13, 12, 14, 11, 10, 11, 14, 10, 12, 11, 13, 10, 10,
12, 15, 10, 12, 12, 13, 10, 10, 15, 16, 12, 12, 13, 14, 10, 9,
10, 14, 11, 13, 9, 12, 10, 10, 11, 15, 12, 13, 10, 12, 10, 10,
14, 16, 13, 14, 12, 13, 11, 10, 11, 14, 11, 13, 10, 12, 10, 10,
12, 15, 11, 13, 10, 12, 10, 10, 15, 16, 13, 13, 12, 13, 11, 9,
13, 16, 12, 13, 12, 13, 10, 9, 14, 16, 12, 13, 12, 13, 10, 9,
16, 16, 12, 12, 13, 13, 10, 7, 4, 10, 6, 9, 7, 10, 8, 9,
8, 12, 9, 11, 9, 11, 9, 9, 14, 16, 13, 13, 13, 14, 11, 11,
6, 11, 7, 10, 8, 11, 8, 9, 9, 12, 9, 11, 9, 12, 9, 9,
14, 16, 12, 13, 13, 14, 11, 10, 10, 14, 9, 11, 11, 13, 9, 9,
11, 14, 9, 11, 11, 13, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9,
6, 11, 8, 10, 7, 10, 8, 9, 9, 12, 9, 11, 9, 11, 9, 9,
14, 16, 13, 13, 12, 13, 11, 10, 8, 12, 8, 10, 8, 11, 9, 9,
9, 12, 9, 11, 9, 11, 9, 9, 14, 16, 12, 13, 12, 13, 11, 10,
11, 14, 10, 11, 11, 13, 9, 9, 11, 14, 10, 11, 11, 13, 9, 9,
14, 16, 11, 12, 13, 14, 10, 8, 10, 14, 11, 12, 9, 12, 10, 10,
11, 14, 11, 13, 10, 12, 10, 10, 14, 16, 13, 14, 12, 13, 11, 9,
11, 14, 11, 12, 10, 12, 10, 10, 11, 14, 11, 12, 10, 12, 10, 9,
14, 16, 13, 13, 11, 12, 10, 9, 13, 16, 12, 13, 12, 13, 10, 9,
13, 16, 11, 12, 11, 13, 10, 8, 15, 16, 12, 12, 12, 12, 9, 7,
8, 12, 8, 11, 9, 12, 9, 10, 10, 14, 10, 12, 11, 13, 10, 10,
16, 16, 14, 14, 14, 14, 12, 11, 8, 13, 8, 11, 9, 12, 10, 10,
11, 14, 10, 12, 11, 13, 10, 10, 16, 16, 13, 14, 14, 14, 12, 11,
11, 14, 9, 12, 11, 13, 10, 10, 12, 15, 10, 12, 12, 14, 10, 10,
15, 16, 12, 12, 14, 14, 11, 9, 9, 13, 9, 11, 9, 12, 10, 10,
11, 14, 10, 12, 10, 12, 10, 10, 15, 16, 14, 14, 13, 14, 12, 11,
9, 13, 9, 11, 10, 12, 10, 10, 10, 14, 10, 12, 10, 12, 10, 10,
15, 16, 13, 13, 13, 14, 11, 10, 11, 15, 10, 12, 11, 13, 10, 10,
11, 15, 10, 12, 12, 13, 10, 9, 15, 16, 11, 12, 13, 14, 10, 9,
11, 15, 11, 13, 10, 12, 10, 10, 12, 16, 12, 13, 11, 13, 10, 10,
16, 16, 14, 14, 12, 13, 11, 9, 11, 15, 11, 13, 10, 13, 10, 10,
12, 15, 12, 13, 10, 12, 10, 10, 14, 16, 13, 13, 12, 13, 10, 9,
13, 16, 12, 13, 12, 13, 10, 9, 13, 16, 11, 12, 11, 13, 10, 9,
14, 16, 11, 12, 12, 12, 9, 7, 10, 15, 10, 12, 11, 13, 10, 10,
12, 16, 12, 13, 12, 13, 11, 10, 16, 16, 14, 14, 14, 15, 12, 10,
10, 14, 10, 12, 10, 13, 10, 10, 12, 15, 11, 12, 11, 13, 10, 10,
16, 16, 14, 13, 14, 14, 11, 9, 11, 14, 10, 11, 11, 12, 9, 9,
12, 15, 10, 11, 11, 13, 9, 8, 16, 16, 12, 12, 13, 13, 10, 7,
10, 15, 10, 12, 10, 13, 10, 10, 12, 15, 11, 12, 11, 13, 10, 10,
16, 16, 14, 13, 14, 14, 11, 9, 10, 14, 10, 12, 10, 12, 10, 10,
12, 15, 11, 12, 11, 13, 10, 10, 16, 16, 13, 13, 13, 14, 11, 9,
11, 14, 10, 11, 10, 12, 9, 8, 11, 14, 9, 11, 11, 12, 9, 8,
14, 16, 10, 11, 12, 13, 9, 7, 11, 15, 11, 12, 10, 12, 10, 9,
13, 16, 11, 12, 11, 12, 10, 9, 16, 16, 13, 13, 12, 13, 10, 7,
11, 15, 10, 12, 10, 12, 9, 8, 12, 15, 11, 12, 10, 12, 9, 8,
14, 16, 12, 12, 11, 12, 9, 7, 11, 14, 10, 11, 10, 12, 8, 7,
11, 14, 9, 10, 10, 11, 8, 6, 12, 15, 9, 9, 9, 10, 7, 4,
},
{
0, 6, 3, 7, 3, 7, 6, 7, 5, 9, 6, 9, 7, 9, 8, 8,
16, 16, 16, 16, 16, 16, 16, 11, 3, 8, 5, 8, 6, 8, 7, 7,
7, 11, 7, 10, 8, 10, 8, 9, 16, 16, 16, 16, 16, 16, 14, 10,
8, 16, 7, 11, 10, 16, 9, 9, 11, 16, 9, 14, 16, 16, 10, 9,
16, 16, 16, 16, 16, 16, 16, 10, 3, 8, 5, 8, 5, 8, 7, 7,
7, 11, 8, 10, 8, 10, 8, 9, 16, 16, 16, 16, 16, 16, 16, 11,
6, 10, 7, 9, 7, 10, 8, 8, 8, 11, 8, 10, 8, 11, 8, 8,
16, 16, 16, 16, 16, 16, 11, 10, 10, 16, 9, 13, 11, 16, 10, 9,
11, 16, 9, 11, 16, 16, 10, 9, 16, 16, 11, 16, 16, 16, 11, 9,
9, 16, 10, 11, 8, 11, 9, 9, 11, 16, 12, 16, 10, 16, 10, 10,
16, 16, 16, 16, 16, 16, 16, 10, 10, 16, 11, 16, 10, 16, 10, 10,
11, 16, 11, 16, 10, 16, 10, 9, 16, 16, 16, 16, 16, 16, 11, 9,
16, 16, 16, 16, 16, 16, 11, 9, 16, 16, 16, 16, 16, 16, 11, 9,
16, 16, 11, 16, 16, 16, 9, 7, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
2, 8, 5, 9, 6, 9, 8, 8, 8, 12, 9, 11, 9, 11, 10, 10,
16, 16, 14, 16, 14, 16, 14, 12, 5, 10, 6, 9, 8, 10, 8, 9,
9, 12, 9, 11, 10, 12, 10, 10, 16, 16, 14, 15, 15, 16, 13, 12,
10, 13, 9, 12, 11, 12, 10, 10, 12, 15, 11, 12, 12, 13, 11, 10,
16, 16, 15, 14, 15, 16, 13, 12, 6, 10, 8, 10, 7, 10, 8, 9,
9, 13, 10, 11, 10, 12, 10, 10, 16, 16, 14, 16, 14, 16, 13, 12,
7, 11, 8, 11, 9, 11, 9, 9, 10, 13, 10, 11, 10, 12, 10, 9,
16, 16, 14, 14, 14, 15, 12, 11, 11, 14, 11, 12, 11, 13, 10, 10,
12, 15, 11, 13, 12, 13, 11, 10, 16, 16, 14, 16, 15, 15, 13, 11,
10, 13, 11, 12, 10, 12, 10, 10, 12, 15, 12, 13, 11, 13, 11, 11,
16, 16, 15, 16, 14, 15, 13, 11, 11, 14, 11, 13, 11, 12, 11, 10,
12, 16, 12, 13, 12, 13, 11, 10, 16, 16, 15, 16, 13, 15, 12, 11,
13, 15, 12, 13, 13, 14, 11, 11, 14, 16, 13, 13, 13, 14, 11, 11,
16, 16, 15, 14, 15, 15, 12, 10, 3, 8, 6, 9, 7, 9, 8, 8,
8, 12, 9, 11, 9, 11, 9, 9, 16, 16, 15, 15, 15, 16, 13, 12,
6, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 11, 10, 12, 10, 9,
16, 16, 14, 14, 14, 15, 13, 11, 10, 13, 9, 11, 11, 12, 10, 10,
12, 14, 11, 12, 12, 13, 11, 10, 16, 16, 14, 14, 15, 15, 13, 11,
6, 10, 8, 10, 7, 10, 8, 9, 10, 12, 10, 11, 10, 11, 10, 9,
16, 16, 14, 15, 14, 15, 13, 11, 8, 11, 8, 10, 9, 11, 9, 9,
9, 13, 9, 11, 10, 11, 9, 9, 16, 16, 13, 14, 14, 14, 12, 10,
11, 14, 10, 12, 11, 12, 10, 10, 12, 14, 11, 12, 12, 13, 10, 10,
16, 16, 13, 14, 15, 15, 12, 10, 10, 13, 11, 12, 10, 12, 10, 10,
12, 14, 12, 13, 11, 13, 11, 10, 16, 16, 15, 14, 14, 14, 12, 11,
11, 14, 11, 12, 10, 12, 10, 10, 12, 15, 12, 12, 11, 13, 10, 10,
16, 16, 14, 15, 13, 14, 12, 10, 13, 15, 12, 13, 12, 13, 11, 10,
13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 15, 11, 9,
6, 10, 8, 10, 8, 11, 9, 10, 11, 13, 11, 12, 11, 13, 11, 10,
16, 16, 16, 16, 16, 16, 13, 12, 8, 11, 9, 11, 9, 11, 10, 10,
11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 15, 15, 16, 16, 13, 12,
11, 14, 10, 12, 12, 13, 11, 10, 13, 16, 12, 13, 13, 14, 11, 11,
16, 16, 15, 16, 16, 16, 13, 12, 8, 12, 9, 11, 9, 11, 10, 10,
11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 16, 16, 16, 16, 13, 12,
9, 12, 10, 11, 10, 12, 10, 10, 11, 14, 11, 12, 11, 13, 10, 10,
16, 16, 15, 14, 15, 15, 13, 11, 12, 14, 11, 13, 12, 13, 11, 10,
12, 15, 11, 12, 13, 13, 11, 10, 16, 16, 14, 15, 16, 15, 13, 11,
11, 15, 12, 13, 11, 13, 11, 10, 13, 16, 13, 14, 12, 14, 11, 11,
16, 16, 16, 16, 15, 15, 13, 12, 12, 14, 12, 13, 11, 13, 11, 10,
13, 15, 12, 13, 11, 13, 11, 10, 16, 16, 15, 15, 13, 15, 13, 11,
13, 16, 13, 13, 13, 13, 12, 11, 13, 16, 13, 13, 13, 13, 11, 10,
16, 16, 13, 15, 14, 14, 12, 9, 9, 13, 10, 12, 11, 13, 11, 11,
13, 16, 13, 14, 13, 14, 12, 11, 16, 16, 16, 16, 16, 16, 14, 12,
10, 14, 11, 13, 11, 13, 11, 10, 13, 16, 13, 13, 13, 14, 12, 11,
16, 16, 16, 16, 16, 16, 14, 12, 11, 15, 11, 13, 12, 13, 11, 10,
14, 16, 12, 13, 13, 14, 12, 10, 16, 16, 15, 16, 16, 16, 13, 11,
10, 14, 11, 12, 11, 13, 11, 10, 13, 16, 12, 13, 12, 14, 12, 11,
16, 16, 16, 16, 16, 16, 14, 12, 11, 14, 11, 12, 11, 13, 11, 10,
13, 15, 12, 13, 12, 13, 11, 10, 16, 16, 15, 15, 16, 16, 13, 11,
12, 15, 12, 13, 12, 13, 11, 10, 13, 16, 12, 13, 13, 13, 11, 10,
16, 16, 14, 14, 16, 15, 13, 10, 12, 15, 12, 13, 12, 13, 11, 10,
14, 16, 13, 14, 13, 14, 12, 11, 16, 16, 16, 16, 15, 16, 13, 11,
12, 16, 12, 13, 12, 13, 11, 10, 13, 16, 13, 13, 12, 14, 11, 10,
16, 16, 15, 16, 14, 15, 13, 10, 12, 15, 12, 14, 12, 13, 11, 10,
13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 14, 11, 8,
},
},
{
{
0, 11, 5, 11, 7, 13, 10, 12, 7, 13, 9, 13, 10, 14, 12, 13,
16, 16, 15, 16, 16, 16, 15, 15, 4, 13, 6, 12, 10, 14, 11, 12,
8, 14, 9, 13, 11, 15, 12, 13, 16, 16, 15, 16, 15, 16, 15, 14,
9, 16, 9, 13, 13, 16, 12, 13, 12, 16, 10, 14, 14, 16, 13, 13,
16, 16, 14, 16, 16, 16, 14, 14, 5, 13, 8, 13, 8, 13, 11, 12,
9, 14, 10, 13, 10, 14, 12, 13, 16, 16, 15, 16, 15, 16, 14, 15,
7, 14, 9, 13, 10, 14, 11, 13, 9, 15, 10, 13, 11, 14, 12, 13,
16, 16, 14, 16, 15, 16, 14, 14, 11, 16, 11, 14, 13, 16, 12, 13,
12, 16, 11, 14, 14, 16, 12, 13, 16, 16, 14, 15, 16, 16, 14, 13,
10, 16, 12, 15, 10, 15, 12, 14, 12, 16, 13, 16, 11, 15, 13, 14,
16, 16, 16, 16, 14, 16, 14, 14, 11, 16, 12, 15, 11, 16, 12, 13,
12, 16, 13, 15, 12, 16, 12, 13, 16, 16, 16, 16, 14, 16, 14, 14,
14, 16, 13, 15, 14, 16, 13, 13, 14, 16, 14, 15, 14, 16, 13, 13,
16, 16, 15, 16, 15, 16, 13, 13, 2, 12, 6, 11, 7, 13, 10, 12,
7, 13, 9, 12, 10, 14, 11, 12, 16, 16, 15, 16, 15, 16, 14, 15,
5, 13, 6, 12, 9, 13, 10, 12, 8, 14, 9, 13, 11, 14, 11, 13,
16, 16, 14, 16, 15, 16, 14, 14, 9, 16, 8, 13, 12, 16, 11, 13,
11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 15, 16, 16, 13, 13,
5, 13, 8, 12, 7, 13, 10, 12, 8, 14, 10, 13, 10, 14, 11, 13,
16, 16, 14, 16, 15, 16, 14, 14, 7, 14, 8, 12, 9, 14, 11, 12,
8, 14, 9, 13, 10, 14, 11, 12, 15, 16, 14, 15, 14, 16, 13, 14,
11, 16, 10, 13, 13, 16, 12, 13, 11, 16, 10, 13, 13, 16, 12, 13,
16, 16, 13, 15, 15, 16, 13, 13, 9, 16, 12, 15, 9, 14, 11, 13,
11, 16, 13, 15, 11, 14, 12, 13, 16, 16, 15, 16, 14, 16, 14, 14,
11, 16, 12, 14, 11, 15, 12, 13, 11, 16, 12, 14, 11, 15, 12, 13,
16, 16, 15, 16, 14, 16, 13, 13, 13, 16, 13, 15, 13, 16, 12, 13,
14, 16, 13, 15, 13, 16, 12, 12, 16, 16, 14, 15, 14, 16, 12, 12,
4, 13, 7, 12, 8, 14, 11, 12, 9, 14, 10, 13, 11, 14, 12, 13,
16, 16, 15, 16, 16, 16, 15, 15, 6, 14, 7, 12, 10, 14, 11, 12,
9, 15, 10, 13, 11, 15, 12, 13, 16, 16, 15, 16, 16, 16, 14, 14,
9, 16, 8, 13, 12, 16, 11, 13, 12, 16, 10, 14, 13, 16, 12, 13,
16, 16, 14, 16, 16, 16, 14, 14, 6, 14, 8, 13, 8, 14, 11, 13,
9, 15, 10, 13, 11, 14, 12, 13, 16, 16, 15, 16, 16, 16, 14, 14,
7, 15, 9, 13, 10, 14, 11, 13, 9, 15, 10, 13, 11, 14, 11, 13,
16, 16, 14, 16, 15, 16, 14, 14, 10, 16, 10, 13, 12, 16, 12, 13,
11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 14, 15, 16, 13, 13,
9, 16, 12, 14, 9, 14, 11, 13, 12, 16, 12, 15, 11, 15, 12, 13,
16, 16, 16, 16, 15, 16, 14, 14, 10, 16, 12, 15, 11, 15, 12, 13,
11, 16, 12, 14, 11, 15, 12, 13, 16, 16, 14, 16, 13, 16, 13, 13,
13, 16, 13, 15, 13, 16, 12, 13, 13, 16, 12, 14, 13, 16, 12, 12,
15, 16, 13, 14, 13, 16, 12, 12, 6, 14, 8, 13, 9, 14, 10, 12,
10, 15, 10, 12, 11, 14, 11, 12, 16, 16, 14, 14, 14, 16, 13, 13,
7, 15, 8, 13, 9, 14, 10, 12, 10, 15, 10, 13, 11, 14, 11, 12,
16, 16, 14, 14, 14, 16, 13, 12, 9, 16, 8, 12, 11, 14, 10, 11,
11, 16, 10, 13, 11, 14, 10, 11, 16, 16, 13, 14, 14, 16, 12, 11,
7, 14, 9, 13, 9, 14, 10, 12, 10, 16, 10, 13, 11, 14, 11, 12,
16, 16, 14, 14, 14, 15, 13, 12, 7, 14, 9, 13, 9, 14, 10, 12,
9, 14, 10, 12, 10, 14, 11, 12, 15, 16, 13, 14, 14, 15, 12, 12,
9, 15, 9, 12, 11, 14, 10, 11, 10, 15, 9, 12, 11, 14, 10, 11,
14, 16, 11, 13, 13, 15, 11, 11, 9, 16, 10, 13, 9, 14, 10, 11,
11, 16, 11, 13, 10, 14, 10, 11, 16, 16, 14, 15, 13, 15, 12, 12,
9, 16, 10, 13, 9, 13, 10, 11, 10, 15, 10, 13, 10, 13, 10, 11,
14, 16, 13, 14, 12, 14, 11, 11, 11, 16, 10, 13, 11, 13, 9, 10,
11, 14, 10, 12, 10, 13, 9, 9, 13, 15, 10, 11, 11, 12, 9, 8,
},
{
0, 10, 5, 10, 6, 11, 8, 10, 7, 12, 8, 11, 9, 12, 9, 10,
14, 16, 13, 13, 13, 14, 12, 11, 5, 12, 6, 10, 8, 12, 9, 10,
8, 13, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11,
9, 15, 8, 12, 11, 14, 10, 10, 11, 16, 9, 12, 12, 14, 10, 10,
14, 16, 11, 12, 13, 14, 11, 10, 5, 12, 8, 11, 7, 11, 9, 10,
8, 13, 9, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11,
7, 13, 8, 11, 9, 12, 9, 10, 9, 13, 9, 11, 9, 12, 9, 10,
14, 16, 12, 13, 12, 13, 11, 10, 11, 15, 10, 12, 12, 14, 10, 10,
12, 16, 10, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 10, 9,
10, 15, 11, 13, 9, 13, 10, 10, 11, 15, 12, 13, 10, 12, 10, 10,
14, 16, 13, 14, 12, 13, 11, 10, 11, 16, 11, 13, 10, 13, 10, 10,
11, 16, 11, 13, 10, 13, 10, 10, 14, 16, 13, 14, 12, 13, 11, 9,
13, 16, 12, 13, 12, 14, 11, 10, 14, 16, 12, 13, 12, 14, 10, 9,
16, 16, 12, 13, 13, 13, 10, 8, 3, 11, 6, 10, 7, 11, 9, 10,
8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 13, 13, 13, 14, 11, 11,
5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10,
14, 16, 12, 13, 13, 14, 11, 10, 9, 14, 8, 11, 11, 14, 10, 10,
11, 15, 9, 11, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 9,
6, 12, 8, 11, 7, 11, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10,
14, 16, 12, 13, 13, 13, 11, 10, 7, 13, 8, 11, 8, 12, 9, 10,
9, 13, 9, 11, 9, 12, 9, 9, 14, 16, 12, 13, 12, 13, 11, 10,
10, 15, 9, 12, 11, 14, 10, 10, 11, 15, 9, 11, 11, 13, 10, 9,
14, 16, 11, 12, 13, 14, 10, 9, 9, 15, 11, 13, 9, 12, 10, 10,
11, 15, 11, 13, 9, 12, 10, 10, 14, 16, 13, 14, 12, 13, 11, 10,
10, 15, 11, 13, 10, 13, 10, 10, 11, 15, 11, 13, 10, 12, 10, 10,
14, 16, 12, 13, 11, 12, 10, 9, 13, 16, 12, 13, 12, 14, 10, 9,
13, 16, 11, 12, 12, 13, 10, 9, 14, 16, 11, 12, 12, 13, 9, 8,
7, 13, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 11,
16, 16, 13, 14, 14, 14, 12, 11, 8, 14, 8, 12, 9, 13, 10, 10,
10, 14, 10, 12, 11, 13, 10, 10, 16, 16, 13, 13, 14, 14, 12, 11,
10, 15, 9, 12, 11, 14, 10, 10, 12, 16, 10, 12, 12, 14, 10, 10,
16, 16, 12, 13, 14, 15, 11, 10, 8, 14, 9, 12, 9, 13, 10, 11,
10, 15, 10, 12, 10, 13, 10, 11, 16, 16, 13, 14, 14, 14, 12, 11,
8, 14, 9, 12, 9, 13, 10, 10, 10, 14, 10, 12, 10, 13, 10, 10,
15, 16, 13, 13, 13, 14, 11, 10, 10, 15, 10, 12, 12, 14, 10, 10,
11, 16, 9, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 10, 9,
11, 16, 11, 13, 10, 13, 10, 10, 12, 16, 12, 13, 10, 13, 11, 10,
15, 16, 14, 14, 12, 13, 11, 10, 11, 16, 11, 13, 10, 13, 10, 10,
11, 16, 12, 13, 10, 12, 10, 10, 14, 16, 13, 14, 11, 13, 11, 9,
13, 16, 12, 13, 12, 14, 10, 10, 12, 16, 11, 12, 12, 13, 10, 9,
14, 16, 11, 12, 11, 12, 9, 8, 10, 16, 10, 13, 11, 14, 11, 11,
12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 13, 14, 14, 12, 10,
10, 15, 10, 13, 10, 13, 10, 11, 12, 16, 11, 13, 11, 13, 11, 10,
16, 16, 14, 13, 14, 14, 12, 10, 11, 15, 9, 12, 11, 13, 10, 9,
12, 16, 10, 12, 12, 13, 10, 9, 16, 16, 12, 12, 13, 14, 10, 8,
10, 16, 10, 13, 10, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 10,
16, 16, 14, 13, 14, 14, 12, 10, 9, 15, 9, 12, 10, 13, 10, 10,
11, 16, 10, 12, 11, 13, 10, 10, 16, 16, 13, 13, 13, 14, 11, 9,
10, 15, 9, 11, 11, 13, 9, 9, 11, 15, 9, 11, 11, 13, 9, 8,
14, 16, 10, 11, 13, 13, 10, 8, 11, 16, 11, 13, 10, 13, 10, 9,
13, 16, 11, 13, 11, 13, 10, 9, 16, 16, 13, 13, 13, 13, 10, 8,
11, 16, 10, 12, 10, 13, 10, 9, 11, 16, 11, 12, 10, 12, 9, 9,
15, 16, 12, 13, 11, 12, 10, 8, 11, 16, 10, 12, 11, 12, 9, 8,
11, 15, 9, 11, 10, 12, 9, 7, 13, 15, 9, 9, 10, 10, 7, 5,
},
{
0, 7, 3, 8, 4, 9, 7, 8, 5, 10, 7, 10, 8, 11, 8, 9,
16, 16, 16, 16, 16, 16, 11, 10, 2, 10, 4, 9, 7, 10, 7, 8,
7, 16, 7, 10, 9, 16, 8, 9, 16, 16, 16, 16, 16, 16, 11, 10,
8, 16, 7, 10, 10, 16, 9, 8, 10, 16, 9, 11, 16, 16, 9, 9,
16, 16, 16, 16, 16, 16, 11, 9, 3, 10, 6, 9, 6, 11, 8, 8,
7, 16, 8, 10, 9, 16, 9, 9, 16, 16, 16, 16, 16, 16, 11, 10,
5, 16, 7, 10, 8, 11, 8, 8, 8, 16, 8, 10, 9, 16, 8, 8,
16, 16, 11, 16, 16, 16, 10, 9, 9, 16, 9, 11, 11, 16, 9, 9,
11, 16, 9, 11, 11, 16, 9, 8, 16, 16, 10, 16, 16, 16, 10, 9,
8, 16, 10, 16, 8, 16, 10, 9, 12, 16, 11, 16, 10, 16, 10, 9,
16, 16, 16, 16, 16, 16, 12, 10, 10, 16, 11, 16, 10, 16, 10, 9,
11, 16, 11, 16, 10, 16, 10, 9, 16, 16, 16, 16, 16, 16, 11, 9,
16, 16, 16, 16, 16, 16, 10, 9, 16, 16, 11, 16, 16, 16, 10, 9,
16, 16, 10, 11, 11, 16, 9, 7, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
2, 9, 6, 9, 6, 10, 8, 9, 8, 12, 9, 11, 9, 12, 10, 10,
16, 16, 14, 14, 15, 15, 13, 12, 5, 11, 7, 10, 8, 11, 9, 9,
9, 13, 9, 11, 10, 12, 10, 10, 15, 16, 14, 14, 14, 16, 12, 11,
10, 14, 9, 11, 11, 13, 10, 10, 12, 15, 10, 12, 12, 13, 11, 10,
16, 16, 14, 15, 14, 15, 12, 11, 5, 11, 8, 10, 7, 11, 9, 9,
9, 13, 9, 12, 9, 12, 10, 10, 15, 16, 13, 14, 13, 16, 12, 11,
7, 12, 8, 11, 9, 11, 9, 10, 9, 13, 9, 11, 10, 12, 9, 9,
16, 16, 13, 14, 13, 14, 11, 11, 10, 14, 10, 12, 11, 13, 10, 10,
11, 16, 11, 12, 12, 13, 10, 10, 16, 16, 13, 14, 13, 14, 12, 11,
10, 14, 11, 13, 10, 13, 10, 11, 12, 16, 12, 13, 10, 12, 11, 11,
16, 16, 14, 15, 13, 14, 12, 11, 11, 15, 11, 13, 11, 13, 10, 10,
12, 15, 12, 13, 11, 13, 11, 10, 15, 16, 14, 15, 13, 15, 12, 11,
12, 16, 12, 13, 12, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 10,
16, 16, 13, 14, 13, 14, 11, 10, 3, 10, 6, 9, 7, 10, 8, 9,
9, 12, 9, 11, 10, 12, 9, 10, 15, 16, 14, 14, 14, 14, 12, 11,
6, 11, 7, 10, 8, 10, 9, 9, 9, 13, 9, 11, 10, 12, 9, 9,
15, 16, 13, 14, 14, 15, 12, 11, 10, 14, 9, 11, 11, 12, 10, 10,
12, 14, 10, 12, 11, 13, 10, 10, 15, 16, 13, 14, 14, 16, 12, 11,
6, 11, 8, 10, 7, 11, 9, 9, 9, 13, 9, 11, 9, 12, 9, 9,
15, 16, 14, 14, 13, 14, 12, 11, 7, 11, 8, 11, 8, 11, 9, 9,
9, 12, 9, 11, 9, 12, 9, 9, 15, 16, 13, 13, 13, 14, 11, 10,
10, 13, 10, 12, 11, 13, 10, 10, 11, 15, 10, 12, 11, 13, 10, 10,
14, 16, 12, 13, 13, 14, 11, 10, 10, 14, 11, 12, 9, 12, 10, 10,
11, 15, 11, 13, 10, 13, 10, 10, 15, 16, 14, 14, 13, 14, 12, 11,
10, 14, 10, 12, 10, 12, 10, 10, 11, 15, 11, 12, 10, 12, 10, 10,
15, 16, 13, 14, 12, 14, 11, 10, 12, 16, 11, 13, 12, 14, 11, 10,
12, 16, 12, 13, 11, 13, 10, 10, 15, 16, 12, 14, 12, 14, 11, 9,
7, 12, 9, 11, 9, 12, 10, 10, 11, 14, 11, 12, 11, 13, 11, 11,
16, 16, 15, 16, 15, 16, 13, 12, 8, 12, 9, 11, 9, 12, 10, 10,
11, 14, 11, 12, 11, 13, 10, 10, 16, 16, 14, 15, 15, 16, 13, 12,
11, 14, 10, 12, 11, 13, 10, 10, 12, 16, 11, 13, 12, 14, 11, 10,
16, 16, 14, 15, 14, 16, 12, 11, 8, 13, 9, 11, 9, 12, 10, 10,
11, 14, 11, 12, 11, 13, 10, 10, 16, 16, 15, 15, 14, 15, 13, 12,
9, 13, 9, 12, 9, 12, 10, 10, 11, 14, 10, 12, 10, 12, 10, 10,
16, 16, 14, 15, 14, 14, 12, 11, 11, 15, 11, 12, 11, 13, 11, 10,
12, 16, 11, 12, 12, 13, 11, 10, 16, 16, 13, 15, 14, 15, 11, 11,
11, 16, 11, 13, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11,
16, 16, 14, 15, 14, 15, 13, 11, 11, 16, 11, 13, 11, 13, 11, 10,
12, 16, 12, 13, 10, 13, 11, 10, 16, 16, 14, 14, 12, 14, 12, 10,
12, 16, 12, 14, 12, 14, 11, 11, 13, 16, 12, 14, 12, 14, 11, 10,
15, 16, 12, 14, 12, 14, 11, 9, 9, 14, 11, 13, 11, 13, 11, 11,
13, 16, 12, 14, 13, 14, 12, 11, 16, 16, 16, 16, 16, 16, 14, 12,
9, 14, 10, 12, 10, 13, 11, 11, 12, 16, 12, 13, 13, 14, 11, 11,
16, 16, 16, 16, 16, 14, 13, 12, 10, 15, 11, 13, 11, 14, 11, 10,
13, 16, 12, 13, 12, 15, 11, 10, 16, 16, 14, 16, 15, 16, 13, 11,
10, 14, 10, 13, 11, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 11,
16, 16, 16, 16, 15, 16, 13, 12, 10, 14, 10, 12, 10, 13, 10, 11,
12, 15, 12, 13, 12, 13, 11, 10, 16, 16, 14, 14, 15, 15, 13, 11,
11, 16, 11, 13, 11, 14, 11, 10, 12, 16, 11, 13, 12, 14, 11, 10,
16, 16, 13, 14, 14, 15, 12, 10, 11, 16, 12, 13, 11, 14, 11, 10,
13, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 15, 15, 12, 11,
11, 16, 12, 13, 11, 14, 11, 10, 13, 16, 12, 13, 11, 14, 11, 10,
16, 16, 14, 15, 13, 14, 12, 10, 12, 16, 12, 14, 12, 14, 10, 10,
12, 16, 11, 13, 11, 14, 10, 10, 14, 16, 11, 13, 12, 13, 10, 8,
},
},
{
{
0, 12, 6, 13, 7, 14, 11, 14, 8, 14, 10, 14, 11, 15, 13, 15,
16, 16, 16, 16, 16, 16, 16, 16, 5, 14, 7, 13, 10, 16, 12, 14,
9, 16, 10, 14, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 9, 14, 14, 16, 13, 16, 12, 16, 11, 16, 16, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 5, 14, 9, 14, 8, 14, 12, 14,
9, 16, 11, 14, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 14, 11, 16, 12, 14, 10, 16, 11, 15, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 14, 16,
13, 16, 12, 16, 15, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 13, 16, 11, 16, 14, 16, 13, 16, 14, 16, 13, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 14, 16, 13, 16, 14, 16,
13, 16, 14, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 12, 6, 12, 8, 14, 11, 13,
8, 14, 10, 13, 11, 14, 13, 14, 16, 16, 16, 16, 16, 16, 16, 16,
5, 14, 7, 13, 10, 14, 11, 14, 9, 16, 10, 14, 12, 16, 13, 15,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 14, 13, 16, 13, 14,
12, 16, 11, 15, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 14, 9, 13, 8, 14, 12, 14, 9, 16, 11, 14, 11, 16, 13, 14,
16, 16, 16, 16, 16, 16, 16, 16, 7, 15, 9, 14, 10, 16, 12, 14,
9, 16, 10, 14, 11, 16, 12, 14, 16, 16, 16, 16, 16, 16, 15, 16,
11, 16, 11, 15, 14, 16, 13, 15, 12, 16, 11, 15, 14, 16, 13, 14,
16, 16, 14, 16, 16, 16, 14, 16, 10, 16, 13, 16, 10, 16, 13, 16,
12, 16, 14, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 15, 16, 14, 16, 14, 16, 16, 16, 14, 16,
15, 16, 14, 16, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 14,
4, 14, 8, 13, 9, 16, 12, 14, 9, 16, 11, 14, 11, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 15, 8, 13, 10, 16, 12, 14,
10, 16, 11, 14, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 9, 14, 13, 16, 13, 15, 12, 16, 11, 16, 14, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 9, 14, 9, 16, 12, 14,
10, 16, 11, 15, 12, 16, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 14, 11, 16, 12, 14, 10, 16, 11, 14, 12, 16, 13, 15,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 15, 14, 16, 13, 15,
12, 16, 11, 15, 14, 16, 13, 14, 16, 16, 14, 16, 16, 16, 14, 16,
10, 16, 13, 16, 10, 16, 13, 15, 13, 16, 14, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 12, 16, 13, 16,
12, 16, 13, 16, 11, 16, 13, 16, 16, 16, 16, 16, 15, 16, 15, 16,
14, 16, 14, 16, 15, 16, 14, 16, 14, 16, 14, 16, 14, 16, 14, 14,
16, 16, 14, 16, 15, 16, 14, 14, 6, 16, 9, 14, 10, 16, 12, 14,
10, 16, 11, 13, 12, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14,
7, 16, 9, 14, 10, 16, 12, 13, 11, 16, 11, 14, 12, 16, 12, 14,
16, 16, 16, 16, 16, 16, 14, 14, 9, 16, 9, 14, 12, 16, 11, 13,
12, 16, 11, 14, 12, 16, 12, 13, 16, 16, 14, 16, 16, 16, 13, 14,
7, 16, 10, 14, 10, 16, 12, 14, 11, 16, 11, 14, 11, 16, 12, 14,
16, 16, 16, 16, 16, 16, 14, 14, 8, 16, 10, 14, 10, 16, 11, 13,
10, 16, 11, 13, 11, 16, 12, 13, 16, 16, 14, 16, 16, 16, 14, 14,
10, 16, 9, 13, 12, 16, 11, 13, 11, 16, 10, 13, 12, 16, 11, 12,
16, 16, 13, 15, 15, 16, 13, 13, 9, 16, 11, 14, 9, 16, 11, 13,
12, 16, 12, 16, 12, 16, 12, 13, 16, 16, 16, 16, 15, 16, 14, 14,
10, 16, 11, 14, 10, 16, 11, 13, 11, 16, 12, 14, 10, 15, 11, 13,
16, 16, 15, 16, 13, 16, 13, 13, 12, 16, 11, 13, 12, 16, 11, 12,
12, 16, 11, 13, 11, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 11,
},
{
0, 10, 5, 10, 6, 11, 8, 10, 7, 12, 8, 11, 8, 12, 9, 10,
14, 16, 13, 13, 13, 14, 12, 11, 4, 12, 6, 10, 8, 12, 9, 10,
8, 13, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11,
9, 15, 8, 12, 12, 14, 10, 11, 11, 16, 9, 12, 12, 14, 10, 10,
14, 16, 11, 13, 13, 15, 11, 11, 4, 12, 8, 11, 6, 11, 9, 10,
8, 13, 9, 11, 8, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11,
7, 13, 8, 11, 9, 12, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10,
14, 16, 12, 13, 12, 13, 11, 10, 11, 16, 10, 12, 12, 14, 10, 11,
11, 16, 10, 12, 12, 14, 10, 10, 15, 16, 11, 13, 13, 14, 11, 10,
10, 16, 11, 13, 9, 13, 10, 11, 11, 15, 12, 13, 10, 12, 10, 11,
15, 16, 13, 14, 12, 13, 11, 11, 11, 16, 11, 13, 10, 13, 10, 11,
12, 16, 11, 13, 10, 13, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10,
13, 16, 12, 13, 13, 14, 11, 11, 14, 16, 12, 13, 12, 14, 11, 10,
16, 16, 13, 13, 13, 14, 11, 9, 3, 11, 6, 10, 6, 11, 9, 10,
8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 13, 13, 13, 13, 12, 11,
5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10,
14, 16, 12, 13, 13, 14, 11, 11, 9, 15, 8, 11, 11, 14, 10, 10,
11, 15, 9, 11, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 10,
5, 12, 8, 11, 7, 11, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10,
14, 16, 12, 13, 13, 13, 11, 11, 7, 13, 8, 11, 8, 12, 9, 10,
8, 13, 8, 11, 9, 12, 9, 9, 13, 16, 11, 13, 12, 13, 11, 10,
10, 15, 9, 12, 11, 14, 10, 10, 11, 15, 9, 11, 11, 13, 10, 10,
14, 16, 11, 12, 13, 14, 10, 10, 9, 16, 11, 13, 9, 12, 10, 10,
11, 16, 11, 13, 9, 12, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10,
11, 16, 11, 13, 10, 13, 10, 10, 11, 15, 11, 13, 9, 12, 10, 10,
14, 16, 12, 13, 11, 13, 10, 10, 13, 16, 12, 13, 12, 14, 11, 10,
13, 16, 11, 13, 12, 13, 10, 10, 14, 16, 11, 12, 12, 13, 10, 9,
7, 14, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 11,
16, 16, 14, 14, 14, 14, 12, 12, 7, 14, 8, 12, 9, 13, 10, 11,
10, 14, 10, 12, 11, 13, 10, 11, 16, 16, 13, 13, 14, 14, 12, 11,
10, 15, 9, 12, 12, 14, 10, 10, 12, 16, 9, 12, 12, 14, 10, 10,
16, 16, 12, 13, 14, 15, 12, 11, 8, 14, 9, 12, 9, 13, 10, 11,
10, 15, 10, 12, 10, 13, 10, 11, 16, 16, 14, 14, 14, 14, 12, 11,
8, 14, 9, 12, 9, 13, 10, 11, 10, 14, 10, 12, 10, 13, 10, 10,
15, 16, 13, 13, 13, 14, 12, 11, 10, 15, 10, 12, 12, 14, 10, 10,
11, 16, 9, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 10,
11, 16, 11, 14, 9, 13, 10, 11, 12, 16, 12, 14, 10, 13, 11, 11,
16, 16, 14, 15, 13, 14, 12, 11, 11, 16, 12, 14, 10, 13, 11, 11,
11, 16, 11, 13, 10, 13, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10,
13, 16, 12, 14, 13, 14, 11, 10, 12, 16, 11, 13, 12, 13, 10, 10,
14, 16, 11, 12, 11, 13, 10, 9, 10, 16, 10, 13, 11, 14, 11, 11,
12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 13, 14, 15, 12, 11,
10, 16, 10, 13, 10, 14, 11, 11, 12, 16, 11, 13, 11, 14, 11, 11,
16, 16, 14, 13, 14, 14, 12, 11, 11, 15, 9, 12, 11, 14, 10, 10,
13, 16, 10, 12, 12, 14, 10, 10, 16, 16, 13, 13, 14, 14, 11, 10,
10, 16, 10, 13, 11, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11,
16, 16, 14, 14, 14, 14, 12, 11, 9, 16, 10, 13, 10, 14, 11, 11,
11, 15, 11, 12, 11, 13, 11, 11, 16, 16, 13, 13, 14, 14, 12, 10,
10, 15, 9, 12, 11, 14, 10, 10, 11, 16, 9, 11, 11, 13, 10, 9,
15, 16, 11, 12, 13, 14, 10, 9, 11, 16, 11, 13, 10, 13, 10, 10,
13, 16, 12, 13, 11, 13, 10, 10, 16, 16, 14, 14, 13, 13, 11, 10,
11, 16, 11, 13, 10, 13, 10, 10, 12, 16, 11, 13, 10, 13, 10, 10,
15, 16, 13, 13, 12, 13, 11, 9, 11, 16, 11, 12, 11, 13, 10, 9,
11, 15, 10, 11, 11, 12, 9, 8, 13, 15, 10, 10, 10, 11, 8, 7,
},
{
0, 9, 3, 8, 5, 9, 7, 8, 5, 11, 6, 9, 8, 11, 8, 9,
16, 16, 16, 16, 16, 16, 11, 10, 2, 10, 4, 9, 7, 10, 7, 8,
7, 16, 7, 10, 9, 11, 8, 9, 16, 16, 11, 16, 16, 16, 11, 10,
7, 16, 7, 10, 10, 16, 8, 9, 10, 16, 8, 10, 11, 16, 9, 9,
16, 16, 16, 16, 16, 16, 11, 10, 3, 11, 6, 9, 6, 11, 8, 8,
7, 16, 8, 10, 8, 11, 8, 9, 16, 16, 15, 16, 16, 16, 11, 10,
5, 11, 7, 9, 8, 11, 8, 8, 7, 16, 7, 10, 8, 11, 8, 8,
16, 16, 11, 16, 16, 16, 10, 9, 9, 16, 8, 11, 11, 16, 9, 9,
10, 16, 8, 11, 11, 16, 9, 9, 16, 16, 10, 16, 16, 16, 10, 9,
8, 16, 10, 11, 8, 16, 9, 9, 11, 16, 11, 16, 10, 16, 10, 9,
16, 16, 16, 16, 16, 16, 11, 10, 9, 16, 10, 16, 10, 16, 9, 9,
10, 16, 10, 16, 9, 16, 9, 9, 16, 16, 16, 16, 15, 16, 10, 9,
16, 16, 11, 16, 16, 16, 10, 10, 13, 16, 11, 16, 11, 16, 10, 9,
16, 16, 10, 11, 11, 16, 9, 8, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 10, 6, 10, 7, 11, 9, 10, 8, 12, 9, 12, 9, 12, 10, 10,
16, 16, 14, 16, 14, 15, 13, 12, 5, 12, 7, 10, 9, 11, 9, 10,
9, 13, 9, 12, 10, 13, 10, 10, 16, 16, 14, 15, 14, 14, 13, 12,
10, 15, 10, 12, 12, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11,
16, 16, 14, 16, 15, 16, 13, 12, 6, 12, 8, 11, 8, 11, 10, 10,
9, 13, 10, 12, 10, 12, 10, 10, 15, 16, 13, 15, 13, 14, 12, 12,
7, 13, 9, 11, 9, 12, 10, 10, 9, 14, 10, 12, 10, 13, 10, 10,
15, 16, 13, 15, 13, 14, 12, 11, 11, 15, 11, 13, 12, 14, 11, 11,
12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 11,
10, 16, 12, 14, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11,
16, 16, 15, 16, 14, 16, 13, 12, 11, 16, 12, 14, 11, 14, 11, 11,
12, 16, 12, 14, 11, 14, 11, 11, 16, 16, 14, 15, 13, 15, 12, 12,
13, 16, 13, 15, 13, 15, 12, 12, 13, 16, 12, 15, 12, 15, 11, 11,
16, 16, 13, 16, 13, 15, 12, 11, 4, 11, 7, 10, 7, 11, 9, 10,
9, 13, 9, 12, 10, 12, 10, 10, 15, 16, 14, 15, 14, 15, 13, 12,
6, 12, 7, 11, 9, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10,
15, 16, 14, 15, 14, 15, 12, 12, 10, 15, 9, 12, 12, 13, 11, 11,
12, 15, 11, 13, 12, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 12,
6, 12, 8, 11, 8, 11, 9, 10, 9, 14, 10, 12, 10, 12, 10, 10,
14, 16, 13, 14, 13, 14, 12, 12, 8, 13, 9, 11, 9, 12, 10, 10,
9, 13, 9, 12, 9, 12, 9, 10, 14, 16, 13, 14, 13, 14, 12, 11,
11, 15, 11, 13, 11, 14, 11, 11, 12, 16, 10, 13, 12, 13, 11, 10,
15, 16, 12, 15, 13, 16, 12, 11, 10, 15, 11, 13, 10, 13, 11, 11,
12, 16, 12, 14, 11, 13, 11, 11, 16, 16, 14, 15, 13, 16, 13, 12,
11, 16, 11, 14, 11, 13, 11, 11, 12, 16, 12, 14, 10, 13, 11, 11,
15, 16, 13, 16, 12, 14, 12, 11, 12, 16, 12, 14, 12, 15, 11, 11,
13, 16, 12, 14, 12, 14, 11, 11, 15, 16, 13, 15, 13, 15, 11, 10,
7, 13, 9, 12, 10, 13, 11, 11, 11, 15, 12, 13, 12, 13, 11, 11,
16, 16, 15, 16, 16, 16, 14, 13, 8, 13, 9, 12, 10, 13, 11, 11,
12, 15, 11, 13, 12, 13, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12,
11, 16, 11, 13, 12, 14, 11, 11, 13, 16, 12, 14, 13, 15, 12, 11,
16, 16, 14, 16, 15, 16, 13, 12, 9, 15, 10, 13, 10, 13, 11, 11,
12, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 16, 16, 16, 13, 12,
9, 14, 10, 13, 10, 13, 11, 11, 11, 14, 11, 13, 11, 13, 11, 11,
16, 16, 14, 16, 14, 16, 12, 12, 11, 16, 11, 14, 12, 14, 12, 11,
12, 16, 11, 13, 13, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 11,
12, 16, 12, 14, 11, 14, 11, 11, 13, 16, 13, 14, 12, 15, 12, 11,
16, 16, 16, 16, 14, 16, 13, 12, 12, 16, 12, 14, 11, 14, 12, 11,
12, 16, 12, 15, 11, 14, 11, 11, 16, 16, 14, 16, 13, 15, 12, 12,
13, 16, 13, 16, 13, 16, 12, 12, 13, 16, 12, 15, 12, 16, 11, 11,
14, 16, 12, 15, 12, 15, 11, 10, 9, 16, 11, 14, 12, 14, 12, 12,
13, 16, 13, 15, 14, 16, 12, 12, 16, 16, 16, 16, 16, 16, 14, 13,
10, 16, 11, 14, 12, 14, 12, 12, 13, 16, 13, 14, 13, 16, 12, 12,
16, 16, 15, 16, 16, 16, 13, 12, 11, 16, 11, 14, 12, 15, 12, 11,
13, 16, 12, 14, 13, 16, 12, 11, 16, 16, 14, 16, 16, 16, 13, 12,
11, 16, 11, 14, 12, 14, 12, 12, 13, 16, 12, 15, 13, 16, 12, 12,
16, 16, 16, 16, 16, 16, 14, 13, 10, 16, 11, 14, 11, 15, 11, 11,
13, 16, 12, 14, 12, 14, 12, 11, 16, 16, 14, 16, 16, 16, 13, 12,
11, 16, 11, 15, 12, 15, 12, 11, 13, 16, 11, 14, 13, 15, 12, 11,
16, 16, 13, 16, 14, 16, 12, 11, 12, 16, 12, 15, 11, 15, 12, 11,
14, 16, 13, 15, 12, 16, 12, 11, 16, 16, 15, 16, 14, 16, 13, 12,
11, 16, 12, 15, 11, 15, 11, 11, 13, 16, 13, 16, 11, 15, 11, 11,
16, 16, 14, 16, 13, 15, 12, 11, 12, 16, 12, 15, 12, 16, 11, 11,
12, 16, 11, 15, 12, 14, 11, 11, 13, 16, 12, 13, 11, 13, 10, 9,
},
},
{
{
0, 13, 6, 13, 8, 14, 12, 16, 8, 16, 11, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 7, 14, 11, 16, 13, 16,
9, 16, 11, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 10, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 5, 16, 10, 16, 8, 16, 13, 16,
10, 16, 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 11, 16, 13, 16, 10, 16, 12, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 16, 16, 16, 16,
14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 11, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16,
14, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 13, 7, 13, 8, 16, 12, 16,
8, 16, 10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
4, 16, 7, 14, 10, 16, 12, 16, 9, 16, 10, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 9, 16, 14, 16, 14, 16,
13, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 9, 16, 8, 16, 12, 16, 9, 16, 11, 16, 11, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 11, 16, 13, 16,
9, 16, 11, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 12, 16, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 13, 16, 11, 16, 14, 16,
13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 14, 16, 13, 16, 14, 16, 13, 16, 14, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
4, 16, 8, 16, 9, 16, 13, 16, 10, 16, 11, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 8, 16, 11, 16, 13, 16,
10, 16, 11, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 9, 16, 13, 16, 13, 16, 13, 16, 12, 16, 16, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 13, 16,
10, 16, 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 11, 16, 13, 16, 10, 16, 11, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 14, 16,
12, 16, 11, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 13, 16, 10, 16, 13, 16, 13, 16, 16, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 12, 16, 14, 16,
12, 16, 15, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 13, 16,
11, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 9, 16, 11, 16, 12, 16, 11, 16, 11, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 12, 16, 12, 16,
13, 16, 11, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 10, 16, 12, 16, 11, 16, 12, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 10, 16, 11, 16, 12, 16,
10, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 10, 14, 12, 16, 12, 16, 11, 16, 10, 14, 13, 16, 12, 14,
16, 16, 14, 16, 16, 16, 14, 16, 9, 16, 12, 16, 10, 16, 12, 16,
13, 16, 13, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 11, 16, 12, 16, 11, 16, 12, 16, 11, 16, 12, 15,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 12, 16, 13, 16, 12, 13,
12, 16, 12, 16, 12, 16, 12, 13, 16, 16, 13, 14, 13, 16, 13, 13,
},
{
0, 10, 5, 10, 5, 10, 8, 10, 6, 11, 8, 11, 8, 11, 9, 10,
14, 16, 13, 14, 13, 14, 12, 12, 4, 12, 5, 10, 8, 12, 9, 10,
7, 12, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 12, 12,
9, 16, 8, 12, 12, 14, 10, 11, 11, 16, 9, 12, 12, 14, 11, 11,
14, 16, 12, 13, 14, 15, 12, 12, 4, 12, 7, 11, 6, 11, 9, 10,
8, 12, 9, 11, 8, 11, 9, 10, 14, 16, 12, 14, 13, 14, 12, 12,
7, 13, 8, 11, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10,
14, 16, 12, 13, 12, 13, 11, 11, 11, 16, 10, 12, 12, 14, 11, 11,
12, 16, 10, 12, 12, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 11,
10, 16, 11, 14, 9, 13, 10, 11, 11, 16, 12, 14, 10, 13, 11, 11,
15, 16, 13, 14, 13, 14, 12, 12, 11, 16, 12, 14, 10, 13, 11, 11,
12, 16, 12, 14, 11, 13, 11, 11, 15, 16, 13, 14, 13, 14, 12, 11,
14, 16, 13, 14, 13, 15, 12, 12, 14, 16, 12, 14, 13, 15, 11, 11,
16, 16, 13, 14, 14, 15, 12, 11, 3, 11, 5, 10, 6, 11, 9, 10,
7, 12, 8, 11, 9, 11, 9, 10, 14, 16, 13, 13, 13, 14, 12, 12,
5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10,
14, 16, 12, 13, 13, 14, 12, 12, 9, 16, 8, 11, 11, 14, 10, 11,
11, 16, 9, 12, 12, 14, 10, 11, 15, 16, 12, 13, 14, 15, 12, 11,
5, 12, 7, 11, 6, 11, 9, 10, 8, 13, 9, 11, 8, 11, 9, 10,
14, 16, 12, 14, 13, 13, 12, 12, 7, 13, 8, 11, 8, 12, 9, 10,
8, 12, 8, 11, 9, 12, 9, 10, 13, 16, 12, 13, 12, 13, 11, 11,
10, 16, 9, 12, 12, 14, 10, 11, 11, 15, 9, 12, 12, 14, 10, 11,
14, 16, 11, 13, 13, 14, 11, 11, 9, 16, 11, 14, 8, 13, 10, 11,
11, 16, 12, 13, 10, 13, 10, 11, 16, 16, 13, 15, 13, 14, 12, 12,
11, 16, 11, 14, 10, 13, 10, 11, 11, 16, 11, 13, 10, 13, 10, 11,
14, 16, 13, 14, 12, 13, 11, 11, 14, 16, 12, 14, 13, 15, 11, 11,
13, 16, 12, 13, 12, 14, 11, 11, 14, 16, 12, 13, 12, 13, 11, 10,
6, 14, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 12,
16, 16, 14, 14, 14, 14, 13, 12, 7, 14, 8, 12, 9, 13, 10, 11,
10, 14, 10, 12, 11, 13, 11, 11, 16, 16, 13, 14, 14, 15, 13, 12,
10, 16, 8, 12, 12, 14, 10, 11, 12, 16, 10, 12, 13, 15, 11, 11,
16, 16, 13, 14, 15, 16, 12, 12, 8, 15, 9, 13, 9, 13, 10, 11,
10, 15, 10, 13, 10, 13, 11, 11, 16, 16, 14, 14, 14, 14, 13, 12,
8, 15, 9, 12, 10, 13, 10, 11, 10, 14, 10, 12, 10, 13, 10, 11,
16, 16, 13, 14, 13, 14, 12, 12, 10, 16, 10, 13, 12, 15, 11, 11,
11, 16, 9, 12, 12, 14, 11, 11, 14, 16, 11, 13, 14, 16, 12, 11,
10, 16, 12, 14, 9, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11,
16, 16, 15, 16, 14, 14, 13, 12, 11, 16, 12, 14, 11, 14, 11, 11,
11, 16, 12, 14, 10, 13, 11, 11, 15, 16, 13, 15, 12, 14, 12, 11,
14, 16, 13, 14, 13, 16, 12, 12, 12, 16, 12, 13, 12, 14, 11, 11,
14, 16, 11, 12, 12, 13, 10, 10, 9, 16, 10, 14, 11, 15, 12, 12,
12, 16, 11, 13, 12, 15, 12, 12, 16, 16, 14, 13, 15, 15, 13, 12,
10, 16, 10, 14, 11, 15, 11, 12, 12, 16, 11, 13, 12, 14, 12, 12,
16, 16, 14, 13, 15, 14, 13, 12, 11, 16, 9, 12, 12, 14, 11, 11,
13, 16, 11, 13, 13, 15, 11, 11, 16, 16, 14, 14, 16, 16, 12, 12,
10, 16, 10, 14, 11, 14, 11, 12, 12, 16, 11, 13, 12, 14, 12, 12,
16, 16, 14, 14, 15, 15, 13, 12, 10, 16, 10, 13, 11, 14, 11, 12,
11, 16, 11, 13, 11, 14, 11, 12, 16, 16, 14, 14, 14, 14, 13, 12,
11, 16, 10, 12, 12, 15, 11, 11, 12, 16, 9, 12, 12, 14, 10, 11,
16, 16, 12, 13, 14, 15, 11, 11, 11, 16, 12, 14, 10, 14, 11, 11,
13, 16, 12, 14, 12, 14, 11, 11, 16, 16, 15, 15, 14, 15, 12, 12,
11, 16, 12, 14, 11, 14, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11,
16, 16, 14, 14, 13, 14, 12, 11, 12, 16, 11, 13, 12, 14, 10, 10,
12, 15, 11, 12, 12, 13, 10, 10, 14, 15, 11, 11, 12, 12, 10, 9,
},
{
0, 8, 3, 8, 5, 9, 7, 8, 5, 10, 6, 10, 8, 11, 8, 9,
16, 16, 15, 16, 16, 16, 11, 11, 2, 10, 4, 9, 7, 10, 7, 8,
7, 16, 7, 10, 9, 11, 8, 9, 16, 16, 15, 16, 16, 16, 11, 11,
7, 16, 6, 11, 10, 16, 9, 10, 10, 16, 9, 11, 11, 16, 9, 10,
16, 16, 16, 16, 16, 16, 16, 11, 3, 10, 6, 9, 5, 10, 7, 9,
7, 16, 8, 10, 8, 11, 8, 9, 16, 16, 16, 16, 16, 16, 11, 11,
5, 11, 7, 10, 8, 11, 8, 9, 7, 14, 7, 10, 8, 11, 8, 9,
16, 16, 11, 16, 16, 16, 10, 11, 9, 16, 9, 11, 11, 16, 9, 10,
10, 16, 8, 11, 11, 16, 9, 10, 16, 16, 11, 16, 16, 16, 11, 10,
8, 16, 9, 16, 7, 16, 9, 10, 11, 16, 11, 16, 10, 16, 10, 10,
16, 16, 16, 16, 16, 16, 16, 11, 9, 16, 10, 16, 9, 16, 9, 10,
10, 16, 10, 16, 9, 16, 9, 10, 16, 16, 16, 16, 11, 16, 11, 11,
16, 16, 16, 16, 16, 16, 10, 10, 11, 16, 11, 16, 11, 16, 10, 10,
16, 16, 11, 16, 11, 16, 10, 9, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 10, 6, 10, 7, 11, 9, 10, 8, 12, 9, 12, 9, 12, 10, 10,
15, 16, 14, 15, 14, 16, 13, 12, 5, 12, 7, 11, 8, 11, 9, 10,
9, 13, 9, 12, 10, 12, 10, 10, 16, 16, 14, 15, 13, 16, 13, 12,
10, 15, 10, 13, 12, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11,
16, 16, 14, 16, 14, 16, 13, 12, 5, 12, 8, 11, 7, 11, 9, 10,
9, 13, 10, 12, 9, 12, 10, 10, 14, 16, 14, 15, 13, 14, 13, 12,
7, 13, 9, 12, 9, 12, 10, 10, 9, 13, 9, 12, 9, 12, 10, 10,
14, 16, 13, 14, 13, 15, 12, 12, 11, 16, 11, 13, 12, 14, 11, 11,
12, 16, 11, 14, 12, 14, 11, 11, 16, 16, 14, 16, 14, 16, 13, 12,
10, 16, 11, 14, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11,
15, 16, 15, 16, 14, 16, 13, 12, 11, 16, 12, 14, 11, 14, 11, 12,
12, 16, 12, 14, 11, 14, 11, 11, 15, 16, 14, 16, 13, 16, 13, 12,
13, 16, 13, 16, 13, 16, 12, 12, 13, 16, 13, 16, 13, 16, 12, 12,
16, 16, 14, 15, 14, 16, 13, 12, 4, 11, 7, 10, 7, 11, 9, 10,
9, 13, 9, 11, 9, 12, 10, 10, 15, 16, 14, 15, 14, 15, 13, 12,
6, 12, 7, 11, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10,
15, 16, 13, 14, 14, 15, 12, 12, 10, 14, 10, 12, 12, 13, 11, 11,
12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12,
6, 12, 8, 11, 8, 11, 9, 10, 9, 13, 10, 12, 9, 12, 10, 10,
16, 16, 14, 15, 13, 14, 12, 12, 8, 13, 9, 11, 9, 12, 9, 10,
9, 13, 9, 12, 9, 12, 9, 10, 14, 16, 13, 14, 13, 14, 12, 11,
11, 15, 11, 13, 12, 14, 11, 11, 11, 16, 10, 13, 12, 14, 11, 11,
15, 16, 13, 15, 14, 16, 12, 11, 10, 16, 12, 13, 10, 13, 11, 11,
11, 16, 12, 14, 10, 13, 11, 11, 16, 16, 14, 16, 13, 16, 13, 12,
11, 16, 12, 14, 10, 14, 11, 11, 11, 16, 12, 14, 10, 13, 11, 11,
16, 16, 14, 16, 12, 15, 12, 11, 13, 16, 13, 15, 13, 15, 12, 12,
13, 16, 12, 15, 12, 15, 12, 11, 15, 16, 13, 16, 13, 16, 12, 11,
8, 14, 9, 12, 10, 13, 11, 11, 11, 16, 11, 13, 11, 13, 11, 11,
16, 16, 16, 16, 16, 16, 14, 13, 9, 14, 10, 12, 10, 13, 11, 11,
11, 16, 11, 13, 12, 13, 11, 11, 16, 16, 15, 16, 15, 16, 14, 12,
11, 16, 11, 13, 12, 14, 12, 11, 13, 16, 12, 14, 13, 14, 12, 11,
16, 16, 15, 16, 16, 16, 14, 13, 9, 14, 10, 13, 10, 13, 11, 11,
11, 16, 11, 13, 11, 13, 11, 11, 16, 16, 15, 16, 14, 15, 14, 13,
9, 14, 10, 13, 10, 13, 11, 11, 11, 15, 11, 13, 11, 13, 11, 11,
16, 16, 14, 16, 14, 16, 13, 12, 12, 16, 12, 14, 13, 14, 12, 11,
12, 16, 11, 14, 12, 15, 12, 11, 16, 16, 13, 16, 15, 16, 13, 11,
11, 16, 12, 14, 11, 14, 12, 11, 13, 16, 13, 15, 12, 14, 12, 12,
16, 16, 16, 16, 14, 16, 14, 13, 12, 16, 13, 15, 11, 14, 12, 12,
12, 16, 13, 14, 11, 15, 12, 11, 16, 16, 15, 16, 13, 15, 13, 12,
13, 16, 13, 15, 13, 16, 12, 12, 13, 16, 13, 15, 13, 15, 12, 12,
15, 16, 13, 16, 13, 15, 11, 10, 10, 16, 12, 14, 12, 15, 12, 12,
14, 16, 13, 15, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 15, 13,
10, 16, 12, 14, 12, 15, 12, 12, 13, 16, 13, 15, 13, 15, 13, 12,
16, 16, 16, 16, 16, 16, 14, 13, 11, 16, 12, 15, 13, 16, 12, 12,
14, 16, 13, 16, 13, 16, 12, 12, 16, 16, 15, 16, 15, 16, 14, 12,
11, 16, 12, 14, 12, 16, 12, 12, 14, 16, 13, 15, 13, 15, 13, 12,
16, 16, 16, 16, 16, 16, 15, 13, 11, 16, 12, 14, 12, 15, 12, 12,
13, 16, 12, 14, 12, 15, 12, 12, 16, 16, 16, 16, 16, 16, 14, 12,
12, 16, 12, 15, 13, 16, 12, 12, 13, 16, 12, 15, 13, 15, 12, 11,
16, 16, 14, 16, 15, 16, 13, 12, 12, 16, 13, 16, 12, 16, 12, 12,
15, 16, 14, 16, 13, 16, 12, 12, 16, 16, 16, 16, 16, 16, 14, 13,
12, 16, 13, 15, 12, 16, 12, 12, 13, 16, 13, 15, 12, 15, 12, 12,
16, 16, 15, 16, 14, 16, 13, 12, 13, 16, 13, 16, 12, 16, 12, 12,
13, 16, 12, 16, 12, 15, 12, 12, 14, 16, 12, 14, 12, 14, 11, 10,
},
},
{
{
0, 16, 6, 16, 8, 16, 16, 16, 9, 16, 11, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 7, 16, 11, 16, 16, 16,
10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 10, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 5, 16, 10, 16, 9, 16, 16, 16,
10, 16, 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 11, 16, 12, 16, 16, 16, 10, 16, 12, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 16, 7, 16, 8, 16, 13, 16,
9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
4, 16, 7, 16, 11, 16, 13, 16, 9, 16, 11, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 16, 16, 16, 16,
13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
4, 16, 10, 16, 8, 16, 16, 16, 10, 16, 12, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 11, 16, 16, 16,
9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 12, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 16, 16, 11, 16, 16, 16,
16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
4, 16, 8, 16, 10, 16, 16, 16, 10, 16, 11, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 8, 16, 11, 16, 16, 16,
10, 16, 12, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 9, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 16, 16,
11, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 11, 16, 11, 16, 16, 16, 10, 16, 12, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16,
12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 12, 16, 16, 16,
12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 11, 16, 16, 16,
11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 9, 16, 11, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 13, 16, 12, 16,
13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 10, 16, 14, 16, 12, 16, 12, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 11, 16, 13, 16,
10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 10, 16, 13, 16, 12, 16, 12, 16, 11, 16, 16, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 10, 16, 13, 16,
16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 13, 16, 11, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 12, 16,
13, 16, 12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
0, 10, 4, 10, 5, 11, 9, 11, 6, 11, 8, 11, 8, 12, 10, 12,
15, 16, 13, 15, 14, 15, 13, 14, 4, 12, 5, 11, 8, 12, 9, 11,
7, 13, 8, 12, 9, 13, 10, 12, 15, 16, 13, 15, 14, 16, 13, 14,
10, 16, 9, 13, 12, 16, 11, 13, 11, 16, 10, 14, 13, 16, 12, 13,
16, 16, 14, 16, 15, 16, 14, 15, 4, 12, 7, 12, 6, 12, 9, 11,
8, 13, 9, 12, 9, 12, 10, 12, 15, 16, 13, 15, 14, 15, 13, 14,
7, 13, 8, 12, 9, 13, 10, 12, 8, 13, 9, 12, 9, 13, 10, 12,
14, 16, 13, 15, 13, 15, 13, 14, 12, 16, 11, 14, 13, 16, 12, 13,
12, 16, 11, 14, 13, 16, 12, 13, 16, 16, 14, 16, 15, 16, 14, 15,
10, 16, 12, 16, 10, 14, 12, 13, 12, 16, 13, 16, 11, 14, 12, 13,
16, 16, 16, 16, 15, 16, 14, 15, 12, 16, 13, 16, 11, 15, 12, 13,
13, 16, 13, 16, 12, 15, 12, 14, 16, 16, 16, 16, 14, 16, 13, 14,
16, 16, 14, 16, 14, 16, 13, 15, 16, 16, 14, 16, 14, 16, 13, 15,
16, 16, 16, 16, 16, 16, 14, 16, 2, 11, 5, 11, 6, 11, 9, 11,
7, 12, 8, 11, 9, 12, 10, 12, 15, 16, 14, 14, 14, 14, 13, 14,
4, 13, 6, 11, 8, 12, 9, 11, 8, 13, 8, 12, 10, 13, 10, 12,
15, 16, 13, 15, 14, 15, 13, 14, 9, 16, 8, 13, 12, 15, 11, 12,
11, 16, 10, 14, 13, 16, 12, 13, 16, 16, 14, 16, 16, 16, 14, 15,
5, 13, 8, 12, 7, 12, 9, 11, 8, 13, 9, 12, 9, 12, 10, 12,
16, 16, 14, 15, 14, 15, 13, 13, 7, 13, 8, 12, 9, 13, 10, 12,
8, 13, 8, 12, 9, 13, 10, 12, 14, 16, 13, 14, 13, 15, 12, 13,
11, 16, 10, 14, 13, 16, 12, 13, 11, 16, 10, 13, 12, 15, 11, 13,
14, 16, 12, 14, 14, 16, 13, 14, 10, 16, 12, 15, 9, 14, 11, 13,
12, 16, 12, 16, 11, 14, 12, 13, 16, 16, 15, 16, 16, 16, 14, 15,
11, 16, 12, 15, 11, 15, 12, 13, 12, 16, 12, 15, 11, 14, 12, 13,
16, 16, 14, 16, 13, 15, 13, 14, 15, 16, 14, 16, 14, 16, 13, 14,
14, 16, 13, 16, 14, 16, 13, 14, 16, 16, 14, 16, 14, 16, 13, 14,
7, 15, 8, 13, 9, 14, 11, 13, 10, 14, 10, 13, 11, 14, 12, 13,
16, 16, 15, 16, 15, 16, 15, 14, 7, 16, 8, 13, 10, 14, 11, 13,
11, 15, 10, 13, 12, 14, 12, 13, 16, 16, 16, 16, 16, 16, 15, 15,
10, 16, 9, 13, 13, 16, 12, 13, 13, 16, 11, 14, 14, 16, 13, 14,
16, 16, 16, 16, 16, 16, 15, 16, 8, 16, 10, 14, 9, 14, 11, 13,
11, 16, 11, 14, 11, 14, 12, 13, 16, 16, 16, 16, 16, 16, 14, 15,
8, 16, 10, 14, 10, 14, 11, 13, 10, 15, 10, 14, 11, 14, 12, 13,
16, 16, 14, 16, 15, 16, 14, 14, 11, 16, 10, 14, 13, 16, 12, 13,
11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 16, 16, 16, 14, 14,
11, 16, 12, 16, 10, 15, 12, 13, 14, 16, 14, 16, 12, 16, 13, 14,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 11, 16, 12, 14,
12, 16, 13, 16, 11, 14, 12, 13, 16, 16, 16, 16, 14, 16, 14, 14,
15, 16, 14, 16, 16, 16, 13, 14, 13, 16, 13, 15, 14, 16, 13, 14,
14, 16, 13, 14, 14, 15, 13, 14, 9, 16, 11, 16, 12, 16, 13, 14,
12, 16, 12, 15, 13, 16, 13, 14, 16, 16, 16, 15, 16, 16, 15, 15,
10, 16, 10, 16, 12, 16, 12, 14, 12, 16, 12, 14, 13, 16, 13, 14,
16, 16, 16, 16, 16, 16, 15, 15, 11, 16, 10, 14, 14, 16, 12, 13,
14, 16, 12, 16, 14, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 15,
10, 16, 12, 16, 11, 16, 12, 14, 13, 16, 12, 15, 13, 16, 13, 14,
16, 16, 16, 16, 16, 16, 16, 15, 10, 16, 11, 16, 12, 16, 12, 14,
12, 16, 12, 15, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14,
11, 16, 10, 14, 14, 16, 12, 13, 13, 16, 11, 14, 14, 16, 12, 13,
16, 16, 15, 16, 16, 16, 14, 14, 12, 16, 13, 16, 11, 16, 12, 14,
15, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 16,
12, 16, 13, 16, 12, 16, 12, 14, 13, 16, 13, 16, 12, 16, 12, 13,
16, 16, 16, 16, 16, 16, 14, 15, 13, 16, 13, 16, 14, 16, 12, 13,
13, 16, 13, 14, 14, 16, 12, 13, 16, 16, 14, 14, 14, 15, 13, 13,
},
{
0, 9, 3, 9, 5, 9, 7, 9, 5, 10, 7, 11, 8, 11, 9, 10,
16, 16, 16, 16, 16, 16, 16, 16, 2, 11, 4, 10, 7, 11, 8, 10,
7, 16, 7, 11, 9, 16, 9, 11, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 7, 16, 11, 16, 10, 11, 11, 16, 10, 16, 16, 16, 11, 16,
16, 16, 16, 16, 16, 16, 16, 16, 2, 11, 6, 10, 6, 10, 8, 10,
7, 16, 8, 16, 8, 11, 9, 11, 16, 16, 16, 16, 16, 16, 16, 16,
5, 13, 7, 11, 8, 11, 9, 11, 6, 12, 8, 12, 8, 12, 9, 11,
16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 10, 16, 12, 16, 10, 13,
10, 16, 9, 16, 11, 16, 11, 12, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 8, 16, 10, 12, 11, 16, 12, 16, 10, 16, 11, 16,
16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 11, 16, 10, 16, 11, 16,
11, 16, 12, 16, 10, 16, 11, 12, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 10, 5, 10, 6, 10, 9, 10, 7, 12, 9, 12, 9, 12, 10, 10,
16, 16, 15, 16, 14, 16, 13, 13, 5, 12, 7, 11, 8, 11, 9, 10,
8, 13, 9, 12, 10, 12, 10, 11, 16, 16, 16, 16, 14, 16, 13, 12,
10, 16, 10, 13, 12, 14, 12, 12, 12, 16, 11, 14, 13, 15, 12, 12,
16, 16, 16, 15, 16, 16, 14, 13, 5, 12, 8, 11, 7, 11, 9, 10,
8, 13, 10, 12, 9, 12, 10, 10, 15, 16, 14, 15, 14, 14, 13, 13,
7, 13, 9, 12, 9, 12, 10, 10, 9, 13, 10, 13, 10, 13, 10, 10,
14, 16, 14, 15, 14, 16, 13, 12, 11, 16, 12, 14, 12, 15, 12, 12,
12, 16, 12, 15, 13, 16, 12, 12, 16, 16, 15, 16, 16, 16, 14, 13,
10, 16, 12, 14, 10, 14, 12, 12, 12, 16, 13, 14, 11, 14, 12, 12,
16, 16, 16, 16, 14, 16, 14, 13, 11, 16, 12, 14, 11, 14, 12, 12,
12, 16, 13, 16, 11, 15, 12, 12, 16, 16, 16, 16, 14, 16, 14, 13,
13, 16, 14, 16, 14, 16, 13, 13, 13, 16, 13, 16, 13, 16, 13, 12,
16, 16, 16, 16, 16, 16, 13, 13, 4, 11, 7, 10, 7, 11, 9, 10,
8, 12, 9, 12, 9, 12, 10, 11, 15, 16, 14, 15, 14, 16, 13, 13,
6, 12, 7, 11, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10,
16, 16, 15, 16, 15, 16, 13, 12, 10, 16, 10, 13, 12, 14, 12, 11,
12, 16, 11, 14, 13, 14, 12, 12, 16, 16, 16, 14, 16, 16, 14, 13,
6, 12, 8, 11, 7, 11, 9, 10, 9, 14, 10, 12, 9, 12, 10, 10,
15, 16, 14, 16, 14, 16, 14, 13, 7, 13, 9, 12, 9, 12, 10, 10,
9, 13, 9, 12, 9, 12, 10, 10, 14, 16, 13, 14, 14, 16, 12, 11,
11, 16, 11, 14, 12, 14, 12, 12, 12, 16, 11, 14, 12, 14, 12, 11,
16, 16, 13, 16, 14, 16, 13, 12, 10, 16, 12, 14, 10, 14, 11, 11,
12, 16, 13, 14, 11, 14, 12, 12, 16, 16, 16, 16, 14, 16, 13, 13,
11, 16, 12, 16, 11, 14, 12, 12, 12, 16, 12, 14, 11, 14, 12, 11,
16, 16, 15, 16, 13, 15, 13, 12, 13, 16, 14, 16, 13, 16, 13, 12,
13, 16, 13, 16, 13, 16, 13, 12, 16, 16, 14, 16, 14, 16, 12, 11,
8, 13, 10, 12, 10, 13, 11, 11, 11, 14, 12, 14, 12, 14, 12, 12,
16, 16, 16, 16, 16, 16, 14, 13, 9, 14, 10, 13, 10, 13, 11, 11,
12, 16, 12, 13, 12, 13, 12, 11, 16, 16, 16, 16, 16, 16, 15, 14,
12, 16, 11, 14, 13, 15, 12, 12, 13, 16, 12, 15, 14, 15, 13, 12,
16, 16, 16, 16, 16, 16, 15, 13, 9, 14, 11, 13, 10, 13, 11, 11,
11, 16, 12, 14, 12, 14, 12, 12, 16, 16, 16, 16, 16, 16, 16, 13,
10, 15, 11, 13, 11, 14, 12, 11, 11, 16, 12, 14, 11, 14, 12, 11,
16, 16, 16, 16, 16, 16, 14, 12, 12, 16, 12, 14, 13, 15, 13, 12,
12, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 16, 16, 16, 14, 12,
12, 16, 13, 16, 11, 14, 12, 12, 14, 16, 14, 16, 12, 16, 13, 12,
16, 16, 16, 16, 16, 16, 16, 13, 12, 16, 13, 16, 12, 16, 13, 12,
12, 16, 13, 16, 12, 16, 12, 12, 16, 16, 16, 16, 14, 16, 14, 12,
14, 16, 14, 16, 14, 16, 14, 13, 13, 16, 13, 16, 13, 16, 13, 12,
16, 16, 13, 16, 13, 16, 12, 11, 9, 16, 12, 15, 13, 16, 13, 12,
13, 16, 14, 16, 14, 16, 14, 13, 16, 16, 16, 16, 16, 16, 16, 14,
10, 16, 12, 15, 12, 15, 13, 12, 13, 16, 14, 16, 13, 16, 13, 12,
16, 16, 16, 16, 16, 16, 16, 13, 12, 16, 12, 16, 13, 16, 13, 12,
14, 16, 13, 16, 14, 16, 13, 12, 16, 16, 16, 16, 16, 16, 16, 13,
11, 16, 12, 15, 12, 16, 13, 12, 14, 16, 14, 16, 13, 16, 13, 13,
16, 16, 16, 16, 16, 16, 15, 13, 11, 16, 12, 16, 12, 16, 13, 12,
13, 16, 13, 15, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 15, 13,
12, 16, 12, 16, 13, 16, 13, 12, 13, 16, 12, 16, 13, 16, 13, 12,
16, 16, 14, 16, 16, 16, 14, 12, 12, 16, 14, 16, 11, 16, 13, 12,
14, 16, 14, 16, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 16, 13,
12, 16, 13, 16, 12, 16, 13, 12, 13, 16, 13, 16, 12, 16, 13, 12,
16, 16, 16, 16, 14, 16, 14, 12, 13, 16, 13, 16, 13, 16, 13, 13,
13, 16, 12, 16, 12, 16, 12, 12, 14, 16, 13, 15, 13, 16, 12, 11,
},
},
};
static const uint8_t rv34_table_intra_secondpat[NUM_INTRA_TABLES][2][OTHERBLK_VLC_SIZE] = {
{
{
0, 5, 10, 3, 6, 10, 7, 8, 9, 4, 6, 10, 6, 7, 9, 8,
8, 9, 8, 8, 9, 8, 9, 9, 9, 9, 8, 3, 6, 10, 4, 6,
10, 7, 7, 9, 5, 7, 10, 6, 7, 9, 7, 7, 8, 7, 8, 9,
8, 8, 9, 8, 8, 7, 6, 8, 10, 6, 8, 10, 7, 8, 9, 7,
8, 10, 7, 8, 10, 8, 8, 8, 8, 9, 9, 8, 8, 9, 9, 8,
7, 7, 8, 9, 7, 8, 9, 7, 7, 7, 8, 8, 9, 7, 8, 9,
7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 6, 5,
},
{
0, 5, 11, 3, 6, 11, 8, 9, 11, 3, 6, 10, 6, 7, 11, 9,
9, 11, 7, 9, 11, 9, 9, 11, 10, 10, 11, 2, 6, 10, 4, 7,
10, 7, 9, 11, 4, 7, 11, 6, 7, 10, 9, 9, 11, 7, 9, 11,
8, 9, 10, 10, 10, 10, 5, 8, 11, 6, 8, 11, 8, 9, 11, 6,
8, 11, 7, 8, 11, 9, 9, 11, 8, 10, 11, 9, 9, 11, 10, 10,
10, 8, 9, 11, 8, 9, 11, 9, 9, 10, 8, 9, 11, 8, 9, 11,
9, 9, 10, 8, 9, 10, 9, 9, 10, 9, 9, 8,
},
},
{
{
0, 5, 10, 4, 6, 10, 7, 8, 10, 4, 6, 10, 6, 7, 9, 8,
8, 9, 8, 8, 9, 8, 9, 9, 9, 9, 9, 2, 6, 10, 4, 6,
10, 7, 7, 9, 5, 7, 10, 6, 7, 9, 7, 7, 9, 7, 8, 9,
8, 8, 9, 9, 8, 8, 6, 8, 10, 6, 8, 10, 7, 8, 9, 6,
8, 10, 7, 8, 10, 8, 8, 9, 8, 9, 10, 8, 8, 9, 9, 9,
8, 8, 8, 10, 7, 8, 9, 7, 8, 8, 7, 8, 10, 7, 8, 9,
7, 7, 8, 8, 8, 9, 8, 8, 8, 7, 7, 6,
},
{
0, 5, 12, 4, 7, 12, 8, 10, 13, 4, 7, 12, 6, 8, 12, 10,
10, 12, 8, 9, 12, 10, 10, 12, 12, 12, 12, 1, 6, 12, 4, 7,
12, 8, 9, 12, 4, 7, 12, 6, 8, 11, 9, 10, 12, 8, 9, 12,
9, 10, 11, 11, 11, 12, 6, 8, 12, 7, 9, 12, 9, 10, 13, 6,
9, 12, 8, 9, 12, 10, 10, 12, 9, 10, 12, 10, 10, 12, 12, 12,
12, 8, 10, 12, 9, 10, 12, 10, 10, 12, 8, 10, 12, 9, 10, 12,
10, 10, 11, 9, 10, 12, 10, 10, 11, 11, 10, 10,
},
},
{
{
0, 5, 10, 3, 6, 10, 7, 8, 11, 4, 6, 10, 6, 7, 10, 8,
9, 10, 8, 8, 10, 9, 9, 10, 10, 10, 10, 2, 6, 10, 4, 6,
10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, 8, 10, 7, 8, 10,
8, 8, 9, 10, 9, 9, 5, 8, 11, 6, 8, 10, 7, 9, 10, 6,
8, 11, 7, 8, 10, 8, 8, 10, 8, 9, 11, 9, 9, 10, 10, 9,
9, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 8, 10,
8, 8, 9, 8, 9, 10, 8, 8, 9, 9, 8, 8,
},
{
0, 6, 13, 4, 7, 14, 9, 11, 14, 3, 7, 13, 7, 8, 13, 11,
11, 14, 8, 10, 13, 10, 11, 13, 13, 13, 14, 1, 6, 12, 4, 8,
13, 9, 10, 15, 4, 8, 13, 7, 8, 12, 11, 11, 14, 8, 10, 13,
10, 10, 13, 13, 13, 14, 5, 9, 13, 7, 9, 13, 10, 11, 14, 6,
10, 14, 8, 10, 14, 11, 11, 14, 9, 11, 14, 11, 11, 13, 13, 13,
14, 9, 10, 14, 9, 11, 13, 11, 12, 14, 9, 11, 13, 9, 11, 14,
11, 12, 13, 10, 12, 15, 11, 11, 13, 13, 12, 13,
},
},
{
{
0, 5, 11, 3, 6, 11, 7, 9, 12, 3, 6, 11, 6, 7, 11, 9,
9, 11, 8, 9, 11, 9, 9, 11, 11, 11, 12, 2, 6, 11, 4, 6,
11, 7, 9, 11, 4, 7, 11, 5, 7, 10, 9, 9, 11, 7, 8, 11,
9, 9, 10, 11, 11, 11, 5, 8, 11, 6, 8, 11, 8, 9, 12, 6,
8, 11, 7, 8, 11, 9, 9, 11, 8, 9, 12, 9, 9, 11, 11, 11,
11, 8, 10, 12, 8, 10, 11, 9, 10, 12, 8, 10, 12, 8, 9, 12,
10, 10, 12, 9, 10, 12, 9, 9, 11, 11, 10, 11,
},
{
0, 6, 13, 3, 8, 14, 10, 12, 16, 3, 8, 15, 7, 9, 15, 12,
13, 15, 9, 11, 15, 11, 12, 16, 14, 16, 16, 1, 7, 13, 4, 8,
14, 9, 11, 15, 4, 8, 14, 7, 9, 14, 12, 13, 15, 8, 10, 14,
11, 11, 14, 16, 14, 16, 6, 9, 14, 7, 10, 14, 11, 13, 15, 7,
10, 14, 9, 10, 13, 12, 12, 15, 10, 11, 14, 11, 11, 14, 14, 14,
16, 9, 11, 14, 10, 11, 14, 13, 14, 15, 9, 12, 14, 10, 12, 16,
13, 14, 16, 10, 13, 16, 12, 12, 14, 15, 14, 15,
},
},
{
{
0, 6, 12, 3, 7, 12, 9, 11, 13, 4, 7, 12, 6, 8, 12, 10,
11, 13, 8, 10, 13, 10, 11, 13, 13, 13, 14, 1, 6, 12, 4, 7,
12, 9, 10, 14, 4, 7, 12, 6, 7, 12, 10, 11, 13, 8, 9, 13,
10, 10, 12, 13, 13, 14, 6, 9, 13, 7, 9, 13, 10, 12, 14, 7,
9, 13, 8, 10, 13, 11, 11, 14, 9, 11, 13, 11, 11, 14, 13, 13,
14, 10, 12, 14, 10, 12, 14, 12, 13, 15, 10, 12, 14, 10, 12, 14,
12, 13, 15, 11, 13, 15, 12, 12, 15, 14, 14, 14,
},
{
0, 6, 16, 3, 8, 16, 10, 13, 16, 3, 8, 16, 7, 9, 16, 13,
16, 16, 8, 10, 16, 11, 13, 16, 16, 16, 16, 1, 7, 14, 4, 8,
16, 10, 12, 16, 4, 8, 13, 7, 9, 16, 13, 14, 16, 8, 10, 16,
11, 11, 14, 16, 16, 16, 6, 9, 14, 8, 10, 14, 12, 16, 16, 6,
10, 13, 9, 11, 16, 13, 14, 16, 9, 12, 16, 12, 11, 16, 16, 16,
16, 10, 12, 16, 11, 12, 16, 16, 14, 16, 9, 12, 16, 11, 12, 16,
16, 15, 16, 10, 13, 16, 12, 13, 16, 16, 16, 16,
},
},
};
static const uint8_t rv34_table_intra_thirdpat[NUM_INTRA_TABLES][2][OTHERBLK_VLC_SIZE] = {
{
{
0, 5, 10, 3, 6, 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8,
8, 10, 8, 9, 10, 9, 9, 10, 9, 9, 9, 2, 6, 10, 4, 7,
10, 7, 8, 9, 5, 7, 10, 6, 7, 10, 8, 8, 9, 8, 9, 10,
8, 8, 9, 9, 9, 8, 6, 8, 11, 6, 8, 10, 7, 8, 10, 6,
8, 11, 7, 8, 10, 8, 8, 9, 8, 9, 10, 9, 9, 10, 9, 9,
9, 7, 8, 10, 7, 8, 10, 7, 8, 8, 7, 8, 10, 7, 8, 9,
7, 8, 8, 8, 8, 9, 8, 8, 8, 7, 7, 7,
},
{
0, 4, 10, 3, 6, 10, 7, 8, 11, 3, 6, 10, 5, 7, 10, 9,
9, 11, 9, 10, 11, 9, 10, 11, 11, 11, 11, 2, 6, 10, 4, 6,
10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, 9, 10, 8, 9, 11,
9, 9, 11, 10, 10, 11, 6, 8, 11, 6, 8, 11, 8, 9, 11, 7,
9, 11, 7, 8, 11, 9, 9, 11, 9, 10, 12, 10, 10, 12, 11, 11,
11, 8, 9, 11, 8, 9, 11, 9, 9, 11, 9, 10, 11, 9, 10, 11,
9, 10, 11, 10, 11, 12, 10, 10, 12, 10, 10, 10,
},
},
{
{
0, 5, 10, 3, 6, 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8,
9, 10, 8, 9, 11, 8, 9, 10, 10, 10, 10, 2, 6, 10, 4, 6,
10, 7, 8, 10, 4, 7, 10, 5, 7, 10, 8, 8, 10, 8, 9, 10,
8, 9, 10, 9, 9, 9, 5, 7, 11, 6, 8, 11, 7, 8, 11, 6,
8, 11, 7, 8, 10, 8, 9, 10, 8, 9, 11, 9, 9, 10, 10, 9,
10, 7, 8, 10, 7, 8, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10,
8, 8, 10, 9, 9, 10, 9, 9, 10, 9, 9, 9,
},
{
0, 5, 11, 3, 6, 11, 8, 9, 12, 4, 7, 12, 6, 7, 12, 9,
10, 13, 10, 11, 13, 10, 11, 14, 12, 13, 14, 1, 6, 11, 4, 7,
11, 8, 9, 12, 5, 7, 11, 6, 8, 12, 9, 10, 13, 10, 11, 14,
10, 11, 13, 12, 12, 14, 6, 8, 12, 7, 9, 13, 9, 10, 14, 7,
10, 13, 8, 10, 12, 11, 11, 13, 11, 13, 14, 11, 12, 14, 13, 13,
15, 9, 10, 12, 9, 11, 14, 10, 11, 14, 11, 11, 13, 10, 11, 13,
11, 12, 14, 12, 14, 15, 13, 13, 14, 13, 13, 14,
},
},
{
{
0, 5, 11, 3, 6, 11, 7, 9, 11, 4, 6, 11, 5, 7, 10, 9,
9, 11, 8, 9, 11, 9, 10, 11, 11, 11, 11, 2, 6, 10, 3, 6,
10, 7, 9, 11, 4, 7, 10, 5, 7, 10, 8, 9, 11, 8, 9, 11,
9, 9, 11, 11, 11, 11, 5, 8, 11, 6, 8, 11, 8, 10, 12, 6,
8, 11, 7, 8, 11, 9, 10, 11, 9, 10, 12, 9, 10, 11, 11, 11,
11, 8, 9, 11, 8, 10, 12, 9, 11, 12, 8, 10, 12, 9, 10, 12,
10, 11, 12, 10, 11, 12, 10, 10, 11, 11, 11, 11,
},
{
0, 5, 13, 2, 7, 16, 9, 11, 16, 4, 8, 16, 7, 9, 16, 12,
12, 16, 12, 16, 16, 12, 16, 16, 16, 16, 16, 1, 6, 13, 4, 8,
16, 9, 11, 16, 6, 9, 16, 7, 10, 16, 13, 13, 16, 13, 15, 16,
12, 16, 16, 16, 16, 16, 7, 9, 16, 8, 11, 15, 11, 13, 16, 10,
12, 16, 10, 12, 16, 16, 13, 16, 16, 16, 16, 14, 16, 16, 16, 16,
16, 12, 12, 16, 12, 16, 16, 16, 16, 16, 13, 14, 16, 12, 13, 16,
16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16,
},
},
{
{
0, 6, 11, 3, 7, 11, 8, 10, 12, 4, 7, 11, 6, 8, 11, 10,
11, 12, 9, 10, 12, 10, 10, 12, 12, 12, 13, 1, 6, 11, 4, 7,
11, 8, 10, 12, 4, 7, 11, 6, 8, 11, 10, 10, 12, 9, 10, 12,
10, 10, 12, 13, 13, 13, 6, 8, 12, 7, 10, 12, 10, 12, 13, 7,
9, 12, 8, 10, 12, 11, 11, 13, 11, 12, 14, 11, 11, 13, 13, 13,
13, 9, 11, 13, 10, 12, 14, 12, 13, 15, 10, 12, 14, 11, 12, 14,
13, 13, 14, 12, 13, 15, 13, 13, 14, 14, 14, 14,
},
{
0, 5, 16, 2, 6, 16, 10, 14, 16, 4, 8, 16, 7, 9, 16, 11,
16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 1, 6, 12, 4, 8,
12, 12, 12, 16, 6, 8, 16, 8, 10, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 12, 16, 16, 7, 10, 16, 8, 11, 14, 16, 16, 16, 10,
12, 16, 10, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 5, 11, 3, 6, 11, 10, 10, 12, 3, 7, 11, 6, 8, 11, 11,
11, 12, 10, 10, 12, 11, 11, 13, 14, 13, 14, 1, 6, 11, 4, 7,
11, 10, 11, 13, 5, 7, 11, 7, 8, 11, 11, 11, 13, 10, 11, 13,
11, 11, 12, 13, 13, 14, 7, 10, 12, 9, 11, 13, 12, 13, 14, 9,
10, 13, 9, 10, 13, 12, 11, 13, 12, 13, 16, 12, 13, 13, 14, 14,
14, 11, 14, 16, 12, 14, 15, 14, 13, 16, 13, 13, 15, 13, 14, 16,
14, 13, 16, 13, 13, 16, 13, 14, 15, 15, 14, 15,
},
{
0, 4, 16, 2, 7, 16, 10, 16, 16, 4, 10, 16, 7, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 6, 13, 4, 11,
16, 16, 16, 16, 6, 10, 16, 8, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 8, 16, 16, 10, 16, 16, 16, 16, 16, 10,
16, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 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 uint8_t rv34_intra_coeff[NUM_INTRA_TABLES][COEFF_VLC_SIZE] = {
{
1, 3, 3, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,
9, 9, 10, 10, 10, 11, 11, 11, 10, 10, 10, 12, 13, 14, 15, 15,
},
{
1, 2, 3, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10, 10, 11,
11, 11, 12, 12, 13, 13, 13, 13, 13, 13, 13, 14, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 12, 12, 12,
13, 13, 14, 14, 14, 14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 12, 12, 12,
13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 7, 7, 8, 8, 9, 10, 10, 12, 11, 13, 12,
15, 13, 14, 13, 12, 15, 14, 13, 12, 12, 10, 11, 16, 16, 16, 16,
}
};
static const uint8_t rv34_inter_cbppat[NUM_INTER_TABLES][CBPPAT_VLC_SIZE] = {
{
7, 9, 9, 8, 9, 8, 9, 8, 9, 9, 8, 8, 8, 8, 8, 4,
7, 10, 11, 10, 11, 10, 12, 10, 12, 11, 11, 10, 11, 10, 10, 7,
10, 11, 15, 12, 15, 12, 15, 12, 15, 14, 14, 12, 14, 12, 14, 9,
7, 11, 10, 10, 12, 11, 11, 10, 11, 12, 10, 10, 11, 10, 10, 7,
8, 12, 12, 11, 13, 12, 12, 10, 13, 13, 12, 10, 12, 11, 11, 7,
11, 13, 15, 11, 15, 13, 15, 12, 16, 14, 14, 12, 15, 13, 13, 9,
10, 15, 11, 12, 15, 14, 14, 12, 15, 15, 12, 12, 14, 14, 12, 9,
11, 15, 13, 12, 16, 15, 14, 12, 15, 15, 13, 12, 15, 14, 13, 9,
13, 15, 14, 10, 16, 15, 16, 11, 16, 16, 15, 12, 16, 15, 15, 9,
7, 11, 11, 11, 11, 10, 11, 10, 11, 12, 11, 10, 10, 10, 10, 7,
9, 12, 13, 12, 12, 11, 13, 10, 13, 13, 12, 11, 12, 10, 11, 7,
12, 13, 16, 14, 15, 12, 16, 12, 16, 15, 15, 13, 15, 12, 14, 9,
9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7,
9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 13, 11, 12, 11, 11, 7,
12, 14, 15, 13, 16, 13, 15, 11, 16, 14, 15, 12, 15, 12, 13, 8,
12, 16, 14, 14, 16, 15, 15, 13, 16, 15, 14, 13, 15, 14, 13, 9,
12, 15, 14, 13, 15, 14, 15, 12, 16, 15, 14, 12, 14, 13, 13, 8,
13, 16, 16, 12, 16, 14, 16, 11, 16, 16, 15, 12, 16, 14, 14, 8,
10, 15, 15, 15, 12, 12, 14, 12, 14, 15, 15, 14, 12, 12, 13, 9,
11, 15, 16, 14, 13, 12, 15, 12, 16, 15, 15, 14, 14, 12, 13, 9,
14, 15, 16, 16, 15, 11, 16, 12, 16, 16, 16, 15, 16, 12, 15, 9,
12, 16, 16, 15, 14, 14, 14, 13, 16, 16, 15, 14, 14, 13, 13, 9,
12, 15, 15, 14, 14, 13, 15, 12, 16, 15, 14, 13, 14, 13, 13, 8,
13, 16, 16, 15, 16, 12, 16, 11, 16, 16, 16, 14, 16, 13, 14, 8,
14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 15, 16, 15, 14, 11,
13, 16, 16, 15, 16, 15, 15, 12, 16, 16, 16, 14, 15, 14, 14, 9,
14, 16, 16, 13, 16, 14, 16, 10, 16, 16, 16, 13, 16, 14, 14, 8,
7, 12, 11, 11, 11, 11, 12, 10, 11, 11, 10, 10, 10, 10, 10, 7,
9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 8,
12, 14, 16, 14, 16, 14, 16, 13, 16, 14, 15, 13, 15, 13, 14, 9,
9, 13, 12, 12, 13, 12, 13, 11, 12, 13, 11, 10, 12, 11, 11, 7,
9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7,
12, 14, 16, 13, 16, 14, 15, 12, 15, 15, 14, 12, 15, 13, 13, 8,
11, 15, 13, 14, 15, 15, 14, 13, 15, 15, 12, 12, 14, 14, 12, 9,
11, 15, 14, 13, 15, 14, 14, 12, 15, 14, 13, 11, 14, 13, 12, 8,
13, 16, 15, 12, 16, 15, 16, 12, 16, 16, 14, 11, 15, 14, 14, 8,
8, 13, 13, 12, 12, 12, 13, 11, 12, 13, 12, 11, 11, 10, 10, 7,
9, 13, 14, 12, 13, 12, 13, 11, 13, 13, 13, 11, 12, 11, 11, 7,
12, 14, 16, 14, 15, 13, 15, 12, 15, 15, 15, 13, 14, 12, 13, 8,
9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7,
9, 13, 12, 12, 13, 12, 12, 10, 13, 13, 12, 10, 12, 10, 10, 6,
11, 14, 14, 12, 14, 12, 14, 11, 14, 14, 13, 11, 13, 11, 12, 7,
12, 16, 14, 14, 15, 15, 14, 13, 15, 15, 13, 12, 14, 13, 12, 8,
11, 14, 13, 12, 14, 13, 13, 11, 14, 14, 13, 11, 13, 12, 11, 7,
11, 14, 14, 12, 15, 13, 14, 11, 15, 14, 13, 11, 14, 12, 12, 6,
11, 16, 15, 15, 13, 14, 15, 13, 14, 15, 15, 13, 12, 12, 12, 9,
12, 15, 15, 14, 14, 13, 15, 12, 15, 15, 14, 13, 13, 11, 12, 8,
13, 16, 16, 15, 16, 13, 16, 13, 16, 16, 15, 14, 14, 12, 14, 8,
11, 16, 15, 14, 14, 14, 14, 13, 15, 15, 14, 13, 13, 12, 12, 8,
11, 14, 14, 13, 13, 12, 14, 11, 14, 14, 13, 12, 12, 11, 11, 7,
12, 14, 15, 13, 14, 12, 14, 11, 15, 14, 14, 12, 13, 11, 12, 7,
13, 16, 16, 16, 16, 15, 16, 14, 16, 16, 15, 14, 15, 14, 13, 9,
12, 15, 14, 13, 15, 13, 14, 12, 15, 15, 13, 12, 13, 12, 12, 7,
11, 15, 14, 12, 14, 13, 14, 10, 15, 14, 13, 11, 13, 11, 11, 5,
10, 15, 15, 15, 15, 14, 15, 13, 12, 14, 12, 12, 12, 13, 12, 9,
12, 16, 16, 15, 16, 15, 16, 14, 14, 15, 14, 13, 14, 13, 13, 9,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 11,
11, 15, 15, 14, 15, 15, 15, 14, 14, 15, 12, 12, 13, 13, 12, 9,
12, 15, 15, 14, 16, 14, 15, 13, 14, 14, 13, 12, 14, 13, 12, 8,
13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 15, 12, 16, 14, 14, 9,
13, 16, 14, 16, 16, 16, 16, 15, 15, 16, 11, 12, 16, 15, 12, 9,
13, 16, 15, 14, 16, 15, 16, 14, 15, 16, 12, 11, 15, 14, 13, 8,
13, 16, 16, 13, 16, 16, 16, 13, 16, 16, 13, 11, 16, 14, 14, 8,
11, 15, 15, 15, 14, 14, 15, 13, 13, 15, 14, 13, 12, 12, 12, 9,
11, 15, 16, 14, 15, 14, 15, 13, 14, 14, 14, 13, 13, 12, 13, 8,
13, 16, 16, 16, 16, 15, 16, 14, 16, 16, 16, 13, 15, 12, 14, 9,
11, 16, 15, 14, 14, 14, 15, 13, 14, 14, 13, 12, 13, 12, 11, 8,
11, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 12, 11, 11, 7,
12, 15, 15, 13, 15, 14, 15, 12, 15, 14, 14, 11, 13, 12, 12, 7,
13, 16, 15, 15, 16, 16, 16, 14, 15, 16, 12, 12, 14, 14, 12, 8,
11, 15, 14, 13, 15, 13, 14, 12, 14, 14, 12, 11, 13, 12, 11, 6,
11, 14, 14, 12, 15, 13, 14, 11, 15, 14, 12, 10, 13, 11, 11, 5,
12, 16, 16, 16, 15, 15, 16, 15, 14, 16, 15, 15, 10, 12, 12, 9,
13, 16, 16, 16, 15, 14, 16, 13, 15, 15, 15, 14, 12, 11, 13, 8,
14, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 14, 14, 11, 14, 8,
13, 16, 16, 15, 15, 15, 15, 14, 15, 16, 14, 13, 12, 12, 11, 8,
11, 15, 15, 13, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 6,
11, 15, 15, 13, 15, 12, 14, 11, 14, 14, 13, 11, 12, 10, 11, 5,
13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 14, 14, 13, 11, 8,
11, 14, 14, 13, 14, 13, 14, 11, 14, 14, 12, 11, 12, 11, 10, 5,
10, 13, 13, 11, 13, 12, 13, 9, 13, 13, 12, 9, 12, 10, 10, 3,
},
{
5, 7, 7, 7, 7, 7, 8, 7, 7, 8, 7, 7, 7, 7, 7, 4,
7, 9, 11, 9, 11, 9, 11, 9, 11, 10, 10, 9, 10, 9, 10, 6,
11, 11, 14, 11, 14, 11, 14, 11, 15, 13, 14, 12, 14, 12, 13, 9,
6, 11, 10, 9, 11, 10, 11, 9, 11, 11, 9, 9, 10, 10, 9, 6,
8, 11, 11, 10, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 7,
11, 13, 14, 11, 15, 13, 15, 11, 15, 14, 14, 12, 14, 13, 13, 9,
10, 14, 11, 11, 15, 14, 13, 12, 14, 14, 11, 11, 14, 13, 12, 9,
11, 14, 13, 11, 15, 14, 14, 11, 15, 15, 13, 11, 14, 14, 13, 9,
12, 14, 14, 10, 16, 15, 16, 11, 16, 16, 15, 11, 16, 15, 14, 9,
6, 10, 11, 10, 10, 9, 11, 9, 10, 11, 10, 10, 9, 9, 9, 6,
9, 12, 12, 11, 12, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 7,
12, 13, 15, 13, 14, 11, 15, 11, 15, 15, 14, 13, 14, 12, 14, 9,
9, 12, 12, 11, 12, 11, 12, 11, 12, 13, 11, 11, 12, 11, 11, 7,
9, 12, 12, 11, 13, 11, 12, 10, 13, 13, 12, 11, 12, 11, 11, 7,
12, 14, 15, 12, 15, 12, 14, 11, 15, 15, 14, 12, 14, 13, 13, 8,
12, 15, 14, 13, 15, 14, 14, 13, 16, 16, 14, 13, 15, 14, 13, 9,
12, 15, 14, 13, 15, 14, 14, 12, 15, 15, 13, 12, 14, 13, 13, 9,
13, 15, 15, 12, 16, 14, 15, 11, 16, 16, 15, 12, 15, 14, 14, 9,
10, 14, 14, 14, 12, 11, 13, 12, 14, 15, 14, 13, 12, 11, 12, 9,
12, 14, 15, 14, 13, 11, 14, 12, 15, 15, 15, 14, 13, 11, 13, 9,
13, 15, 16, 15, 14, 11, 16, 11, 16, 16, 16, 14, 15, 12, 15, 9,
12, 15, 15, 14, 14, 14, 14, 13, 15, 15, 14, 14, 14, 13, 13, 9,
12, 15, 15, 14, 14, 13, 14, 12, 15, 15, 14, 13, 14, 13, 13, 9,
13, 15, 16, 14, 15, 13, 16, 11, 16, 16, 15, 14, 15, 13, 14, 9,
14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 16, 16, 16, 14, 11,
14, 16, 16, 14, 16, 15, 15, 12, 16, 16, 16, 14, 15, 14, 14, 9,
14, 16, 16, 14, 16, 14, 16, 11, 16, 16, 16, 14, 16, 14, 14, 9,
6, 11, 10, 10, 10, 10, 11, 10, 10, 11, 9, 9, 9, 9, 9, 6,
9, 12, 12, 11, 13, 11, 13, 11, 12, 12, 11, 11, 12, 11, 11, 7,
12, 14, 16, 13, 16, 14, 16, 13, 15, 14, 15, 12, 15, 13, 14, 9,
8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 7,
9, 12, 12, 11, 13, 12, 13, 11, 13, 12, 11, 10, 12, 11, 11, 7,
12, 14, 15, 12, 15, 14, 15, 12, 15, 14, 14, 12, 14, 13, 13, 9,
11, 15, 13, 13, 15, 14, 14, 13, 14, 15, 11, 11, 14, 14, 12, 9,
11, 14, 13, 12, 15, 14, 14, 12, 14, 14, 12, 11, 14, 13, 12, 8,
13, 15, 15, 12, 16, 15, 15, 12, 15, 15, 14, 11, 15, 14, 14, 8,
8, 12, 12, 11, 11, 11, 12, 11, 11, 12, 11, 11, 10, 10, 10, 7,
9, 13, 13, 12, 13, 11, 13, 11, 12, 13, 12, 11, 11, 10, 11, 7,
12, 14, 15, 14, 15, 13, 15, 12, 15, 14, 14, 13, 14, 12, 13, 9,
9, 13, 12, 12, 12, 12, 12, 11, 12, 13, 11, 11, 11, 11, 10, 7,
9, 12, 12, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7,
11, 13, 14, 12, 14, 12, 14, 11, 14, 13, 13, 11, 13, 11, 12, 7,
12, 15, 14, 13, 15, 14, 14, 13, 15, 15, 13, 12, 13, 13, 12, 9,
11, 14, 13, 12, 14, 13, 13, 11, 14, 14, 12, 11, 13, 12, 11, 7,
11, 14, 14, 12, 14, 13, 14, 11, 14, 14, 13, 11, 13, 12, 12, 7,
11, 15, 15, 14, 13, 13, 14, 13, 14, 15, 14, 13, 11, 11, 12, 9,
12, 15, 15, 14, 14, 12, 14, 12, 14, 14, 14, 13, 12, 11, 12, 8,
13, 16, 16, 15, 15, 12, 16, 13, 16, 15, 15, 14, 14, 12, 14, 9,
12, 15, 15, 14, 14, 14, 14, 13, 15, 15, 14, 13, 12, 12, 12, 9,
11, 14, 14, 13, 13, 12, 13, 11, 14, 13, 13, 12, 12, 11, 11, 7,
12, 14, 15, 13, 14, 12, 14, 11, 15, 14, 13, 12, 13, 11, 12, 7,
13, 16, 16, 15, 16, 15, 15, 14, 16, 16, 15, 14, 14, 14, 12, 9,
12, 15, 14, 13, 14, 13, 14, 12, 15, 14, 13, 12, 13, 12, 12, 8,
12, 14, 14, 13, 15, 13, 14, 11, 14, 14, 13, 12, 13, 12, 12, 6,
10, 14, 14, 13, 14, 14, 14, 13, 12, 13, 12, 12, 12, 12, 11, 9,
12, 15, 15, 14, 15, 14, 16, 14, 14, 14, 13, 12, 14, 13, 13, 9,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 16, 11,
11, 15, 14, 14, 15, 14, 14, 14, 13, 14, 11, 12, 13, 13, 12, 9,
12, 15, 14, 14, 15, 14, 15, 13, 14, 14, 13, 12, 14, 13, 13, 9,
13, 16, 16, 14, 16, 15, 16, 14, 16, 15, 15, 12, 16, 14, 14, 9,
13, 16, 14, 15, 16, 16, 16, 14, 14, 16, 11, 12, 15, 14, 12, 9,
13, 16, 15, 14, 16, 15, 16, 14, 15, 15, 12, 11, 15, 14, 13, 9,
14, 16, 16, 13, 16, 16, 16, 14, 16, 15, 13, 11, 16, 14, 14, 9,
11, 15, 15, 14, 14, 14, 14, 13, 13, 14, 13, 13, 11, 11, 11, 9,
12, 15, 15, 14, 15, 14, 15, 13, 14, 14, 13, 13, 13, 12, 12, 9,
13, 16, 16, 16, 16, 14, 16, 14, 16, 15, 16, 14, 15, 12, 14, 9,
11, 15, 14, 14, 15, 14, 14, 13, 14, 14, 12, 12, 12, 12, 11, 8,
11, 14, 14, 13, 14, 13, 13, 12, 13, 13, 12, 11, 12, 11, 11, 7,
12, 14, 15, 13, 15, 13, 14, 13, 14, 14, 13, 12, 13, 12, 12, 8,
13, 16, 15, 15, 16, 15, 15, 14, 15, 16, 12, 12, 14, 14, 11, 9,
12, 15, 14, 13, 15, 13, 14, 12, 14, 14, 12, 11, 13, 12, 11, 7,
12, 14, 14, 13, 15, 13, 14, 12, 15, 14, 13, 10, 13, 12, 12, 6,
12, 16, 16, 15, 14, 14, 15, 14, 13, 15, 14, 14, 10, 11, 11, 9,
13, 16, 16, 15, 15, 14, 15, 14, 15, 15, 15, 14, 12, 11, 12, 8,
14, 16, 16, 16, 16, 14, 16, 14, 16, 15, 15, 14, 14, 11, 14, 8,
12, 16, 16, 15, 15, 14, 15, 14, 14, 16, 14, 14, 12, 12, 11, 8,
11, 14, 14, 13, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7,
12, 14, 15, 13, 14, 13, 14, 12, 14, 14, 13, 12, 13, 11, 12, 6,
14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 14, 13, 13, 13, 11, 8,
12, 15, 15, 13, 15, 13, 14, 12, 14, 14, 13, 12, 13, 12, 10, 6,
11, 14, 13, 12, 14, 12, 13, 10, 14, 13, 12, 10, 12, 10, 10, 4,
},
{
4, 6, 6, 6, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 3,
6, 9, 10, 9, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 6,
10, 11, 14, 11, 14, 11, 14, 11, 14, 13, 14, 11, 14, 11, 13, 9,
6, 10, 9, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 6,
8, 11, 11, 9, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 7,
11, 13, 14, 11, 15, 13, 15, 11, 15, 14, 14, 11, 15, 13, 14, 9,
10, 13, 11, 11, 14, 14, 13, 11, 14, 14, 11, 11, 13, 13, 11, 9,
11, 14, 12, 11, 15, 14, 14, 11, 15, 15, 13, 11, 14, 14, 13, 9,
12, 14, 13, 10, 16, 15, 16, 11, 16, 16, 14, 11, 16, 14, 14, 9,
6, 10, 10, 10, 9, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 6,
8, 11, 12, 11, 11, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 7,
11, 13, 15, 13, 14, 11, 15, 11, 15, 14, 14, 13, 14, 12, 14, 9,
8, 12, 12, 12, 12, 12, 12, 11, 12, 13, 11, 11, 11, 11, 11, 8,
9, 12, 12, 11, 12, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 8,
11, 14, 15, 13, 14, 13, 15, 11, 15, 15, 14, 13, 15, 13, 14, 9,
12, 16, 14, 14, 15, 15, 14, 12, 15, 16, 14, 13, 14, 14, 13, 10,
11, 15, 14, 13, 15, 14, 15, 12, 15, 16, 14, 13, 15, 14, 13, 9,
13, 15, 15, 12, 16, 15, 16, 12, 16, 16, 15, 13, 15, 14, 14, 9,
10, 14, 14, 14, 11, 11, 13, 11, 14, 14, 14, 13, 11, 11, 11, 9,
11, 14, 15, 14, 13, 11, 14, 12, 15, 15, 15, 14, 13, 11, 13, 9,
13, 14, 16, 15, 14, 11, 16, 12, 16, 16, 16, 14, 15, 12, 15, 10,
12, 16, 15, 15, 14, 14, 14, 12, 16, 16, 14, 14, 14, 13, 13, 10,
12, 15, 15, 14, 14, 13, 14, 12, 15, 16, 14, 14, 14, 13, 13, 9,
13, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 14, 16, 13, 15, 10,
14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 16, 16, 16, 14, 11,
13, 16, 16, 15, 16, 16, 16, 13, 16, 16, 16, 15, 16, 15, 14, 10,
14, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 15, 16, 15, 15, 10,
6, 10, 10, 10, 10, 10, 11, 10, 9, 10, 9, 9, 9, 9, 9, 6,
9, 12, 12, 11, 12, 11, 13, 11, 12, 12, 11, 10, 12, 11, 11, 8,
12, 14, 15, 14, 15, 14, 16, 13, 15, 14, 14, 12, 15, 13, 14, 10,
8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 7,
9, 12, 12, 11, 13, 12, 13, 11, 12, 13, 11, 10, 12, 12, 11, 8,
11, 14, 14, 13, 15, 14, 15, 13, 15, 14, 14, 12, 15, 13, 14, 9,
11, 15, 12, 13, 15, 15, 14, 13, 14, 15, 11, 11, 14, 14, 12, 9,
11, 14, 13, 13, 15, 14, 15, 13, 15, 15, 13, 11, 15, 14, 13, 9,
13, 15, 15, 12, 16, 15, 16, 13, 16, 15, 14, 11, 16, 15, 14, 9,
8, 12, 12, 11, 11, 11, 12, 11, 11, 12, 11, 11, 9, 10, 10, 7,
9, 12, 13, 12, 12, 11, 13, 11, 12, 13, 12, 12, 11, 11, 11, 8,
12, 14, 15, 14, 15, 13, 16, 13, 15, 14, 15, 13, 14, 12, 14, 9,
9, 13, 12, 12, 12, 12, 13, 12, 12, 13, 11, 11, 11, 11, 10, 8,
9, 12, 12, 12, 12, 12, 13, 11, 12, 13, 11, 11, 12, 11, 11, 7,
11, 13, 14, 13, 14, 13, 15, 12, 14, 14, 14, 12, 14, 12, 13, 8,
12, 15, 14, 14, 15, 15, 14, 13, 15, 16, 13, 13, 14, 14, 12, 9,
11, 14, 13, 13, 14, 14, 14, 12, 14, 15, 13, 12, 14, 13, 12, 8,
11, 14, 14, 13, 15, 14, 15, 12, 15, 15, 14, 12, 14, 13, 13, 8,
11, 14, 14, 14, 13, 13, 14, 13, 13, 14, 14, 13, 11, 11, 11, 9,
11, 15, 15, 14, 14, 13, 15, 13, 14, 15, 14, 14, 13, 11, 13, 9,
13, 16, 16, 16, 15, 13, 16, 13, 16, 16, 16, 15, 15, 12, 15, 10,
11, 15, 15, 15, 14, 14, 14, 13, 15, 15, 14, 14, 13, 13, 12, 9,
11, 14, 14, 13, 13, 13, 14, 12, 14, 14, 13, 13, 13, 12, 12, 8,
12, 15, 15, 14, 15, 13, 15, 12, 15, 15, 14, 13, 14, 12, 13, 8,
13, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 15, 15, 15, 13, 10,
12, 15, 15, 14, 15, 14, 15, 13, 15, 16, 14, 13, 14, 14, 13, 9,
12, 15, 15, 14, 15, 14, 15, 12, 15, 15, 14, 13, 14, 13, 13, 8,
10, 14, 13, 13, 14, 13, 14, 13, 11, 13, 11, 11, 11, 11, 11, 9,
12, 15, 16, 14, 15, 14, 16, 14, 14, 14, 14, 13, 14, 13, 13, 10,
14, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13, 16, 14, 16, 11,
11, 15, 14, 14, 15, 14, 15, 14, 13, 14, 11, 12, 13, 13, 11, 9,
12, 15, 15, 14, 15, 15, 16, 14, 14, 14, 13, 12, 14, 13, 13, 9,
13, 16, 16, 15, 16, 16, 16, 15, 16, 15, 15, 12, 16, 14, 15, 10,
12, 16, 14, 15, 16, 16, 16, 14, 14, 16, 11, 12, 14, 15, 12, 9,
13, 16, 15, 14, 16, 16, 16, 14, 15, 16, 13, 12, 15, 15, 13, 9,
14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 14, 12, 16, 15, 15, 10,
11, 14, 14, 14, 14, 14, 14, 13, 12, 14, 13, 13, 11, 11, 11, 9,
11, 15, 15, 14, 14, 14, 16, 14, 14, 14, 14, 13, 13, 12, 13, 9,
13, 16, 16, 16, 16, 15, 16, 15, 16, 15, 16, 14, 15, 13, 15, 10,
11, 15, 15, 14, 14, 14, 15, 14, 14, 15, 13, 13, 12, 13, 11, 9,
11, 14, 14, 13, 14, 14, 14, 13, 13, 14, 13, 12, 13, 12, 12, 8,
12, 15, 15, 14, 16, 14, 16, 14, 15, 15, 15, 13, 14, 13, 14, 9,
13, 16, 15, 16, 16, 16, 16, 15, 15, 16, 13, 13, 14, 14, 12, 9,
12, 15, 14, 14, 15, 15, 15, 13, 14, 15, 13, 12, 14, 13, 12, 8,
12, 15, 14, 14, 15, 15, 15, 13, 15, 15, 14, 12, 14, 13, 13, 8,
12, 16, 15, 15, 13, 14, 15, 14, 13, 15, 14, 14, 10, 11, 11, 9,
12, 16, 16, 15, 15, 14, 16, 14, 15, 15, 15, 14, 13, 12, 13, 9,
14, 16, 16, 16, 16, 14, 16, 15, 16, 15, 16, 15, 14, 12, 15, 10,
12, 16, 15, 15, 15, 15, 15, 14, 15, 16, 14, 14, 12, 13, 11, 9,
11, 15, 15, 14, 14, 14, 15, 13, 14, 15, 14, 13, 13, 12, 12, 8,
12, 15, 15, 14, 15, 14, 15, 13, 15, 15, 14, 13, 14, 12, 13, 8,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, 14, 14, 14, 11, 9,
12, 15, 15, 14, 15, 15, 15, 13, 15, 15, 14, 13, 14, 13, 12, 8,
11, 14, 14, 13, 14, 13, 14, 12, 13, 14, 13, 12, 13, 12, 12, 7,
},
{
2, 6, 6, 5, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 3,
6, 9, 10, 9, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 7,
10, 11, 14, 11, 14, 11, 14, 11, 14, 13, 14, 12, 14, 12, 13, 9,
6, 10, 9, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 7,
8, 11, 11, 9, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 8,
11, 13, 14, 11, 16, 13, 15, 12, 16, 14, 14, 12, 15, 13, 14, 10,
10, 13, 11, 11, 14, 14, 13, 11, 13, 14, 11, 11, 13, 13, 11, 9,
11, 13, 13, 11, 15, 14, 14, 12, 15, 15, 13, 12, 15, 14, 13, 10,
12, 14, 14, 11, 16, 15, 16, 12, 16, 16, 15, 12, 16, 15, 15, 10,
6, 10, 10, 10, 9, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 7,
8, 11, 12, 11, 11, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 8,
12, 13, 16, 13, 14, 11, 16, 12, 16, 15, 15, 13, 14, 12, 14, 10,
9, 13, 12, 12, 12, 12, 12, 11, 13, 13, 12, 12, 12, 12, 11, 8,
10, 13, 13, 12, 13, 12, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9,
12, 14, 16, 13, 15, 13, 15, 12, 16, 16, 16, 13, 16, 14, 14, 10,
12, 16, 14, 14, 16, 15, 14, 13, 16, 16, 14, 14, 15, 15, 13, 11,
12, 16, 15, 14, 16, 15, 15, 12, 16, 16, 15, 14, 16, 15, 14, 10,
14, 16, 16, 14, 16, 15, 16, 13, 16, 16, 16, 14, 16, 16, 15, 11,
10, 14, 14, 13, 11, 11, 13, 12, 14, 14, 13, 13, 11, 11, 12, 9,
12, 14, 16, 14, 13, 11, 14, 12, 16, 15, 15, 14, 14, 12, 13, 10,
13, 14, 16, 15, 14, 11, 16, 12, 16, 16, 16, 15, 16, 13, 15, 11,
12, 16, 15, 15, 14, 14, 14, 13, 16, 16, 15, 15, 14, 14, 13, 11,
13, 16, 16, 15, 14, 14, 15, 13, 16, 16, 16, 15, 15, 14, 14, 11,
14, 16, 16, 15, 16, 14, 16, 13, 16, 16, 16, 15, 16, 14, 15, 11,
15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, 12,
15, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 15, 12,
15, 16, 16, 15, 16, 15, 16, 13, 16, 16, 16, 16, 16, 16, 16, 11,
6, 10, 10, 10, 10, 10, 11, 10, 9, 10, 9, 9, 9, 9, 9, 7,
9, 12, 13, 12, 13, 12, 14, 12, 12, 12, 12, 11, 12, 11, 11, 8,
12, 14, 16, 14, 16, 14, 16, 14, 15, 14, 15, 13, 16, 13, 14, 11,
8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 8,
10, 13, 13, 12, 14, 13, 14, 12, 13, 13, 12, 11, 13, 12, 12, 9,
12, 15, 15, 13, 16, 15, 16, 14, 16, 15, 15, 12, 16, 14, 15, 10,
11, 15, 13, 13, 16, 15, 14, 13, 14, 15, 11, 12, 14, 14, 12, 10,
12, 16, 14, 13, 16, 16, 16, 14, 16, 15, 13, 12, 15, 15, 14, 10,
14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 13, 16, 16, 15, 11,
8, 12, 12, 12, 11, 11, 12, 11, 11, 12, 11, 11, 9, 10, 10, 8,
10, 13, 14, 13, 13, 12, 14, 12, 13, 13, 13, 12, 12, 11, 12, 9,
13, 15, 16, 15, 16, 14, 16, 14, 16, 15, 16, 14, 15, 13, 15, 11,
10, 13, 13, 13, 13, 13, 13, 12, 13, 14, 12, 12, 12, 12, 11, 9,
10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 13, 12, 12, 12, 12, 9,
12, 15, 15, 14, 16, 14, 16, 13, 16, 15, 15, 13, 15, 13, 14, 10,
13, 16, 15, 15, 16, 16, 15, 14, 16, 16, 13, 14, 15, 15, 12, 10,
12, 16, 14, 14, 16, 16, 15, 13, 16, 16, 14, 13, 15, 14, 13, 10,
13, 16, 16, 14, 16, 15, 16, 13, 16, 16, 16, 13, 16, 15, 15, 10,
11, 15, 15, 14, 13, 13, 14, 13, 13, 15, 14, 14, 11, 12, 12, 10,
12, 15, 16, 15, 14, 13, 16, 14, 16, 15, 16, 14, 13, 12, 13, 10,
14, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16, 13, 16, 11,
12, 16, 16, 16, 15, 15, 15, 14, 15, 16, 14, 14, 13, 14, 12, 10,
12, 16, 16, 15, 15, 14, 16, 13, 16, 16, 15, 14, 14, 13, 13, 10,
13, 16, 16, 15, 16, 14, 16, 13, 16, 16, 16, 15, 16, 14, 15, 10,
15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13, 12,
14, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 15, 14, 11,
14, 16, 16, 15, 16, 16, 16, 13, 16, 16, 16, 15, 16, 15, 14, 10,
10, 14, 13, 13, 13, 13, 14, 13, 11, 13, 11, 11, 11, 11, 11, 9,
12, 15, 16, 15, 16, 15, 16, 14, 14, 14, 14, 13, 14, 13, 14, 11,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 16, 12,
11, 15, 14, 14, 15, 15, 15, 14, 13, 14, 11, 12, 13, 13, 12, 10,
13, 16, 15, 15, 16, 16, 16, 15, 15, 15, 13, 12, 15, 14, 13, 10,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 12,
13, 16, 14, 15, 16, 16, 16, 15, 14, 16, 11, 12, 15, 15, 12, 10,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 16, 14, 11,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 11,
11, 15, 15, 14, 13, 14, 14, 14, 13, 14, 13, 13, 11, 12, 11, 10,
12, 16, 16, 16, 16, 15, 16, 15, 15, 15, 15, 14, 13, 12, 14, 10,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 16, 12,
12, 16, 15, 15, 16, 16, 16, 14, 14, 15, 13, 13, 13, 13, 12, 10,
12, 16, 16, 15, 15, 15, 16, 14, 14, 15, 14, 13, 14, 13, 13, 10,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 11,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 15, 15, 12, 11,
13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 13, 16, 14, 13, 10,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 10,
12, 16, 16, 15, 14, 15, 16, 14, 13, 15, 14, 14, 11, 12, 12, 10,
13, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 15, 13, 12, 14, 11,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 11,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 15, 15, 13, 14, 12, 11,
13, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 14, 13, 13, 10,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 15, 14, 14, 10,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 15, 16, 13, 11,
14, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 14, 15, 14, 13, 10,
12, 15, 15, 14, 15, 14, 16, 14, 14, 16, 15, 13, 14, 13, 13, 9,
},
{
2, 5, 5, 5, 5, 5, 6, 6, 5, 6, 5, 6, 5, 6, 6, 4,
6, 8, 10, 8, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 8,
10, 11, 13, 11, 13, 11, 14, 11, 14, 13, 13, 12, 13, 12, 13, 10,
6, 10, 8, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 7,
8, 11, 11, 10, 12, 11, 12, 10, 12, 12, 11, 10, 12, 12, 11, 9,
11, 13, 14, 11, 15, 14, 15, 12, 16, 14, 14, 12, 15, 14, 14, 11,
10, 13, 11, 11, 14, 13, 13, 12, 13, 14, 11, 11, 13, 13, 12, 10,
11, 14, 13, 11, 16, 14, 14, 12, 15, 15, 14, 12, 15, 14, 14, 11,
12, 14, 14, 11, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 15, 12,
6, 10, 10, 10, 8, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 8,
8, 11, 12, 12, 11, 10, 12, 11, 12, 12, 12, 12, 12, 11, 12, 9,
11, 13, 16, 14, 14, 12, 15, 12, 16, 15, 16, 14, 14, 13, 14, 11,
9, 13, 12, 12, 12, 12, 12, 11, 13, 13, 12, 12, 12, 12, 11, 10,
10, 13, 13, 12, 13, 12, 13, 11, 14, 14, 13, 13, 13, 13, 12, 10,
13, 14, 16, 14, 15, 14, 16, 13, 16, 16, 16, 14, 16, 14, 15, 12,
12, 16, 14, 14, 16, 15, 14, 13, 16, 16, 14, 14, 15, 15, 13, 12,
13, 16, 15, 14, 16, 16, 15, 13, 16, 16, 15, 14, 16, 16, 14, 12,
14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 12,
10, 13, 14, 13, 11, 11, 13, 12, 13, 14, 13, 13, 11, 12, 12, 10,
11, 14, 15, 15, 13, 12, 14, 13, 16, 16, 16, 15, 14, 13, 14, 11,
12, 14, 16, 16, 14, 12, 16, 13, 16, 16, 16, 16, 15, 13, 16, 12,
12, 16, 15, 16, 14, 15, 14, 14, 16, 16, 15, 16, 14, 14, 13, 12,
13, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16, 14, 15, 12,
14, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16, 15, 16, 13,
15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 15, 13,
16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 13,
15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 13,
6, 10, 10, 10, 10, 10, 10, 10, 8, 10, 9, 9, 8, 9, 9, 7,
9, 12, 13, 12, 13, 12, 13, 12, 12, 12, 12, 11, 12, 11, 12, 10,
12, 14, 16, 14, 16, 14, 16, 14, 16, 15, 15, 14, 16, 14, 15, 12,
8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 12, 10, 9,
10, 13, 13, 12, 14, 13, 14, 12, 13, 13, 12, 11, 13, 13, 12, 10,
13, 15, 16, 14, 16, 16, 16, 14, 16, 15, 15, 13, 16, 15, 15, 12,
11, 15, 13, 13, 15, 15, 15, 14, 14, 14, 11, 12, 14, 14, 12, 11,
13, 16, 14, 14, 16, 16, 16, 14, 16, 15, 13, 13, 16, 14, 14, 11,
14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 12,
8, 12, 12, 12, 11, 11, 12, 12, 11, 12, 11, 11, 9, 10, 10, 9,
10, 13, 14, 13, 13, 12, 14, 13, 13, 13, 13, 13, 12, 11, 12, 10,
13, 15, 16, 15, 16, 14, 16, 14, 16, 16, 16, 15, 16, 13, 15, 12,
10, 14, 13, 13, 13, 13, 13, 13, 13, 14, 12, 12, 12, 12, 11, 10,
10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 13, 12, 13, 12, 12, 10,
13, 16, 16, 14, 16, 15, 16, 14, 16, 16, 15, 14, 16, 14, 15, 11,
13, 16, 15, 16, 16, 16, 15, 14, 16, 16, 14, 14, 15, 15, 13, 12,
13, 16, 15, 14, 16, 16, 16, 14, 16, 16, 14, 14, 15, 15, 14, 11,
14, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 15, 16, 16, 15, 12,
11, 14, 15, 14, 13, 13, 14, 14, 13, 15, 14, 14, 11, 12, 12, 11,
13, 16, 16, 16, 14, 14, 16, 14, 16, 16, 16, 15, 14, 13, 14, 12,
14, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13,
13, 16, 16, 16, 15, 16, 15, 15, 16, 16, 15, 16, 14, 14, 13, 12,
13, 16, 16, 15, 15, 14, 16, 14, 16, 16, 16, 15, 14, 14, 14, 11,
14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 15, 16, 12,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 13,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12,
9, 13, 13, 13, 13, 13, 14, 13, 10, 12, 11, 12, 11, 12, 11, 10,
12, 15, 16, 15, 16, 16, 16, 16, 14, 14, 14, 13, 14, 13, 14, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14,
11, 15, 14, 14, 15, 14, 15, 14, 13, 14, 11, 12, 13, 13, 12, 11,
13, 16, 16, 15, 16, 16, 16, 15, 15, 15, 14, 13, 16, 15, 14, 12,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 13,
12, 16, 14, 15, 16, 16, 16, 16, 14, 16, 11, 13, 15, 16, 13, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 16, 15, 12,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 13,
11, 15, 14, 14, 13, 14, 15, 14, 12, 14, 13, 13, 11, 12, 12, 11,
13, 16, 16, 16, 16, 15, 16, 16, 15, 15, 15, 15, 14, 13, 14, 12,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13,
13, 16, 16, 16, 16, 16, 16, 15, 14, 16, 13, 14, 13, 14, 13, 11,
13, 16, 16, 16, 16, 16, 16, 15, 15, 16, 15, 14, 14, 14, 14, 11,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 15, 16, 16, 13, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 16, 15, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12,
11, 16, 16, 15, 13, 15, 16, 15, 13, 15, 15, 15, 11, 12, 12, 11,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 15, 12,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 14, 13, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 12,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 13,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 12,
12, 14, 14, 14, 14, 15, 16, 14, 14, 16, 15, 14, 14, 15, 14, 11,
},
{
1, 5, 5, 6, 5, 6, 7, 7, 5, 7, 6, 7, 5, 6, 6, 6,
6, 9, 10, 9, 10, 9, 11, 10, 11, 11, 11, 10, 11, 10, 11, 9,
10, 11, 14, 12, 14, 12, 16, 12, 16, 13, 16, 13, 14, 13, 16, 12,
6, 10, 9, 9, 10, 11, 11, 10, 10, 11, 9, 10, 10, 11, 10, 9,
8, 11, 11, 10, 13, 12, 13, 12, 13, 13, 12, 12, 13, 13, 13, 11,
11, 13, 16, 12, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 13,
10, 14, 11, 12, 14, 14, 13, 13, 13, 16, 12, 13, 14, 16, 13, 12,
11, 14, 13, 12, 16, 16, 16, 14, 16, 16, 14, 14, 16, 16, 16, 13,
12, 14, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
6, 10, 10, 11, 9, 9, 11, 10, 10, 11, 11, 11, 9, 10, 10, 9,
9, 12, 13, 12, 12, 11, 13, 12, 13, 13, 13, 13, 12, 12, 13, 11,
12, 13, 16, 16, 16, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 13,
9, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 13, 13, 13, 12, 11,
10, 14, 14, 13, 14, 13, 14, 13, 16, 16, 14, 15, 14, 14, 14, 12,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 14, 14, 16, 11, 12, 14, 13, 14, 16, 16, 16, 12, 13, 13, 12,
12, 16, 16, 16, 13, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 13,
13, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
6, 10, 10, 10, 10, 11, 11, 11, 9, 11, 9, 10, 9, 10, 10, 9,
9, 13, 13, 13, 13, 13, 14, 13, 12, 13, 13, 12, 13, 12, 13, 11,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
8, 13, 12, 12, 13, 13, 13, 13, 11, 13, 10, 12, 12, 13, 12, 11,
10, 14, 13, 13, 16, 16, 16, 14, 14, 14, 13, 13, 14, 14, 14, 12,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
11, 16, 13, 16, 16, 16, 16, 16, 14, 16, 12, 13, 16, 16, 14, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 13, 13, 13, 11, 12, 13, 13, 11, 13, 12, 13, 10, 12, 12, 11,
10, 14, 16, 16, 14, 13, 16, 14, 14, 16, 16, 14, 13, 13, 14, 12,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
10, 16, 14, 16, 14, 14, 14, 14, 13, 16, 13, 14, 13, 14, 12, 12,
10, 14, 14, 14, 14, 16, 16, 14, 14, 16, 14, 14, 14, 14, 14, 12,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 14, 14, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 14, 13, 14, 13, 14, 16, 16, 11, 13, 12, 13, 11, 13, 12, 12,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 14, 16, 16, 16, 16, 16, 13, 16, 12, 13, 14, 16, 13, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 14, 16, 12, 16, 16, 16, 14, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 14, 16, 16, 16, 13, 16, 14, 16, 12, 13, 13, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 12, 16, 14, 14,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13,
},
{
1, 5, 5, 6, 5, 6, 7, 8, 5, 7, 6, 8, 6, 7, 7, 7,
5, 9, 10, 10, 10, 10, 12, 11, 10, 11, 11, 11, 10, 11, 12, 10,
9, 11, 13, 12, 13, 12, 16, 14, 16, 14, 16, 16, 16, 13, 16, 13,
5, 10, 9, 10, 10, 11, 11, 11, 10, 11, 9, 11, 10, 11, 11, 10,
8, 11, 11, 11, 12, 13, 13, 13, 12, 13, 12, 12, 13, 13, 13, 12,
11, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 14, 11, 12, 14, 16, 13, 14, 13, 16, 12, 14, 16, 16, 13, 13,
11, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 14, 14, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 10, 11, 11, 9, 10, 11, 11, 10, 12, 11, 12, 9, 11, 11, 11,
8, 12, 13, 13, 11, 11, 14, 13, 13, 14, 13, 16, 12, 12, 13, 12,
11, 13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 13, 12, 13, 12, 13, 13, 14, 13, 16, 13, 16, 13, 16, 13, 13,
10, 14, 13, 14, 13, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 14, 16, 16, 11, 12, 14, 16, 13, 16, 16, 16, 12, 14, 13, 13,
11, 16, 16, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 14, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 10, 10, 11, 10, 11, 12, 12, 8, 11, 10, 11, 9, 11, 11, 11,
9, 12, 13, 13, 13, 13, 16, 16, 12, 13, 13, 13, 13, 13, 16, 13,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 13, 11, 13, 12, 13, 13, 14, 11, 13, 10, 13, 12, 14, 12, 12,
10, 14, 13, 14, 16, 16, 16, 16, 13, 16, 13, 14, 16, 16, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 13, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 13, 13, 13, 11, 13, 14, 16, 11, 13, 13, 14, 10, 12, 12, 12,
10, 14, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 13, 16, 14,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 14, 16, 13, 16, 16, 16, 13, 16, 13, 16, 13, 16, 13, 14,
10, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 14, 13, 16, 13, 16, 16, 16, 10, 14, 12, 14, 11, 13, 13, 13,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14,
}
};
static const uint8_t rv34_inter_cbp[NUM_INTER_TABLES][4][CBP_VLC_SIZE] = {
{
{ 0, 6, 6, 3, 6, 4, 5, 3, 6, 5, 4, 3, 3, 4, 4, 3 },
{ 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 },
{ 0, 7, 7, 4, 7, 5, 5, 4, 7, 5, 5, 4, 5, 4, 4, 1 },
{ 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 }
},
{
{ 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 },
{ 0, 6, 6, 4, 6, 4, 4, 4, 6, 4, 4, 3, 4, 4, 4, 2 },
{ 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 },
{ 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 }
},
{
{ 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 },
{ 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 },
{ 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 },
{ 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 }
},
{
{ 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 },
{ 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 },
{ 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 },
{ 0, 7, 7, 4, 7, 5, 6, 4, 7, 6, 5, 4, 4, 4, 4, 1 }
},
{
{ 0, 5, 5, 3, 5, 3, 5, 4, 5, 5, 3, 4, 3, 4, 4, 4 },
{ 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, 4, 3, 4, 4, 3 },
{ 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 },
{ 0, 7, 7, 4, 7, 5, 6, 4, 7, 6, 5, 4, 4, 4, 4, 1 }
},
{
{ 0, 5, 5, 3, 5, 3, 5, 4, 5, 5, 3, 4, 3, 4, 4, 4 },
{ 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, 4, 3, 4, 4, 3 },
{ 0, 5, 5, 3, 5, 4, 4, 4, 5, 4, 4, 4, 3, 4, 4, 3 },
{ 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 }
},
{
{ 0, 4, 4, 3, 4, 3, 5, 5, 4, 5, 3, 5, 3, 5, 4, 5 },
{ 0, 4, 4, 3, 4, 4, 5, 4, 4, 5, 3, 5, 3, 5, 4, 4 },
{ 0, 4, 4, 3, 4, 4, 5, 4, 4, 5, 4, 4, 3, 4, 4, 4 },
{ 0, 4, 4, 3, 5, 4, 5, 4, 5, 5, 4, 4, 3, 4, 4, 3 }
}
};
static const uint8_t rv34_table_inter_firstpat[NUM_INTER_TABLES][2][FIRSTBLK_VLC_SIZE] = {
{
{
0, 7, 5, 7, 5, 7, 6, 6, 7, 10, 7, 9, 8, 9, 8, 7,
12, 14, 11, 12, 12, 12, 11, 9, 6, 9, 6, 8, 7, 9, 7, 7,
8, 11, 8, 9, 9, 10, 9, 8, 13, 15, 12, 12, 12, 13, 11, 9,
10, 13, 9, 10, 11, 12, 9, 8, 12, 14, 10, 11, 12, 13, 10, 9,
16, 16, 12, 12, 14, 13, 11, 9, 6, 9, 7, 9, 7, 9, 8, 7,
9, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 13, 11, 9,
8, 11, 8, 10, 9, 10, 9, 8, 10, 13, 10, 11, 10, 11, 9, 8,
14, 16, 12, 12, 13, 13, 11, 9, 12, 14, 10, 11, 12, 13, 10, 9,
13, 16, 11, 12, 13, 13, 10, 9, 16, 16, 13, 12, 14, 14, 11, 9,
11, 13, 11, 12, 10, 11, 10, 9, 13, 14, 12, 12, 11, 12, 10, 9,
16, 16, 13, 13, 13, 13, 11, 9, 12, 15, 12, 12, 11, 12, 10, 9,
13, 16, 13, 13, 12, 12, 11, 9, 16, 16, 14, 13, 13, 13, 11, 9,
14, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 14, 14, 11, 9,
16, 16, 13, 13, 14, 13, 11, 8, 4, 9, 6, 8, 6, 9, 7, 7,
8, 11, 8, 9, 9, 10, 8, 8, 13, 15, 12, 12, 13, 13, 11, 9,
7, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 8,
14, 16, 12, 12, 13, 13, 11, 9, 11, 13, 9, 10, 11, 12, 9, 8,
12, 14, 10, 11, 12, 13, 10, 9, 16, 16, 13, 12, 14, 14, 11, 9,
7, 10, 8, 9, 8, 10, 8, 8, 10, 12, 10, 11, 10, 11, 9, 8,
14, 16, 13, 13, 13, 13, 11, 9, 9, 12, 9, 10, 9, 11, 9, 8,
11, 13, 10, 11, 10, 11, 10, 9, 15, 16, 13, 13, 13, 13, 11, 9,
12, 14, 11, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 13, 10, 9,
16, 16, 12, 12, 14, 13, 11, 8, 11, 14, 11, 12, 10, 11, 10, 9,
13, 15, 12, 13, 11, 12, 10, 9, 16, 16, 14, 13, 13, 13, 11, 9,
12, 15, 12, 13, 11, 12, 10, 9, 13, 16, 13, 13, 12, 12, 11, 9,
16, 16, 14, 13, 13, 13, 11, 9, 15, 16, 13, 13, 13, 13, 11, 9,
16, 16, 13, 13, 13, 13, 11, 9, 16, 16, 13, 12, 13, 13, 10, 7,
8, 11, 8, 10, 9, 11, 9, 9, 10, 13, 10, 11, 11, 12, 10, 9,
15, 16, 13, 13, 14, 14, 12, 10, 9, 12, 9, 11, 10, 11, 9, 9,
12, 14, 11, 11, 11, 12, 10, 9, 16, 16, 13, 13, 14, 14, 12, 10,
12, 14, 10, 11, 12, 13, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9,
16, 16, 13, 13, 15, 14, 11, 9, 9, 12, 10, 11, 9, 11, 10, 9,
12, 14, 11, 12, 11, 12, 10, 9, 16, 16, 14, 13, 14, 14, 12, 10,
11, 14, 10, 12, 11, 12, 10, 9, 12, 15, 11, 12, 12, 13, 11, 10,
16, 16, 14, 13, 14, 14, 12, 10, 13, 16, 11, 12, 13, 14, 11, 9,
14, 16, 12, 12, 13, 14, 11, 9, 16, 16, 13, 13, 14, 14, 11, 9,
12, 15, 12, 13, 10, 12, 10, 9, 14, 16, 13, 13, 11, 12, 11, 10,
16, 16, 14, 14, 14, 13, 12, 9, 13, 16, 13, 13, 12, 13, 11, 10,
14, 16, 13, 13, 12, 13, 11, 10, 16, 16, 14, 14, 13, 13, 12, 9,
15, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 13, 14, 11, 9,
16, 16, 13, 12, 13, 13, 10, 8, 10, 13, 10, 11, 10, 12, 10, 9,
12, 14, 11, 12, 12, 13, 11, 10, 16, 16, 13, 13, 14, 14, 12, 9,
11, 14, 10, 11, 11, 12, 10, 9, 13, 16, 11, 12, 12, 13, 11, 10,
16, 16, 14, 13, 14, 14, 12, 9, 12, 15, 10, 11, 12, 13, 9, 8,
14, 16, 11, 11, 13, 14, 10, 8, 16, 16, 12, 12, 14, 14, 10, 8,
11, 14, 11, 12, 11, 12, 10, 9, 13, 16, 12, 13, 12, 13, 11, 10,
16, 16, 14, 13, 14, 14, 12, 9, 12, 15, 11, 12, 11, 13, 10, 10,
13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 14, 13, 14, 14, 12, 9,
13, 16, 11, 11, 13, 13, 10, 8, 14, 16, 11, 12, 13, 14, 10, 8,
16, 16, 12, 12, 14, 14, 10, 8, 12, 15, 12, 13, 10, 11, 10, 9,
14, 16, 13, 13, 11, 12, 10, 9, 16, 16, 14, 13, 13, 13, 11, 8,
13, 16, 12, 13, 11, 12, 10, 9, 14, 16, 13, 13, 12, 12, 10, 9,
16, 16, 14, 13, 13, 12, 10, 8, 14, 16, 12, 12, 12, 13, 10, 8,
14, 16, 12, 12, 12, 13, 10, 7, 16, 16, 11, 11, 12, 11, 8, 5,
},
{
0, 7, 4, 8, 5, 8, 7, 8, 6, 10, 7, 10, 8, 10, 9, 9,
13, 16, 12, 13, 13, 14, 12, 12, 4, 10, 6, 9, 8, 11, 8, 9,
8, 12, 8, 11, 10, 12, 10, 10, 14, 16, 12, 13, 14, 15, 12, 12,
9, 14, 9, 11, 12, 14, 11, 11, 11, 15, 10, 12, 13, 14, 11, 11,
15, 16, 13, 14, 15, 16, 13, 12, 5, 10, 7, 10, 7, 10, 9, 9,
8, 12, 9, 11, 10, 11, 10, 10, 14, 16, 13, 14, 14, 14, 12, 12,
8, 12, 8, 11, 10, 12, 10, 10, 10, 14, 10, 12, 11, 13, 10, 11,
15, 16, 13, 14, 14, 15, 13, 12, 11, 16, 10, 12, 13, 15, 11, 11,
13, 16, 11, 13, 14, 15, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12,
11, 15, 11, 13, 11, 13, 11, 11, 13, 16, 12, 14, 12, 13, 12, 12,
16, 16, 14, 15, 15, 15, 13, 12, 12, 16, 12, 14, 12, 14, 12, 12,
14, 16, 13, 14, 13, 14, 12, 12, 16, 16, 14, 16, 16, 16, 13, 12,
14, 16, 13, 14, 15, 16, 13, 12, 16, 16, 14, 15, 16, 16, 13, 12,
16, 16, 15, 16, 16, 16, 13, 12, 2, 9, 5, 8, 6, 9, 8, 9,
7, 11, 8, 10, 9, 11, 9, 10, 13, 16, 12, 13, 14, 14, 12, 12,
5, 11, 6, 10, 9, 11, 9, 9, 9, 13, 9, 11, 10, 12, 10, 10,
14, 16, 12, 14, 14, 15, 12, 12, 9, 14, 9, 11, 12, 14, 10, 11,
11, 16, 10, 12, 13, 14, 11, 11, 16, 16, 13, 14, 15, 16, 13, 12,
6, 11, 7, 10, 8, 11, 9, 9, 9, 13, 9, 11, 10, 12, 10, 10,
14, 16, 13, 14, 14, 14, 12, 12, 8, 13, 8, 11, 10, 12, 10, 10,
10, 13, 10, 12, 11, 13, 10, 11, 14, 16, 13, 14, 14, 15, 12, 12,
11, 15, 10, 12, 13, 15, 11, 11, 12, 16, 11, 13, 13, 15, 12, 11,
16, 16, 13, 14, 15, 16, 13, 12, 11, 15, 11, 13, 10, 13, 11, 11,
13, 16, 12, 14, 12, 13, 12, 11, 16, 16, 14, 15, 15, 15, 13, 12,
12, 16, 12, 13, 12, 14, 12, 12, 13, 16, 12, 14, 13, 14, 12, 12,
16, 16, 14, 15, 15, 15, 13, 12, 14, 16, 13, 14, 15, 16, 12, 12,
16, 16, 13, 14, 15, 16, 12, 12, 16, 16, 14, 15, 16, 16, 13, 12,
6, 12, 7, 10, 9, 12, 9, 10, 9, 13, 9, 12, 11, 13, 11, 11,
14, 16, 13, 14, 15, 15, 13, 12, 8, 13, 8, 11, 10, 13, 10, 10,
10, 14, 10, 12, 12, 14, 11, 11, 15, 16, 13, 14, 16, 16, 13, 12,
10, 15, 9, 12, 12, 15, 11, 11, 12, 16, 11, 13, 14, 16, 12, 12,
16, 16, 14, 14, 16, 16, 13, 12, 8, 13, 9, 11, 10, 12, 10, 11,
11, 14, 11, 12, 11, 13, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12,
10, 14, 10, 12, 11, 13, 11, 11, 11, 15, 11, 13, 12, 14, 11, 11,
15, 16, 13, 14, 15, 16, 13, 12, 12, 16, 11, 13, 13, 16, 12, 12,
13, 16, 11, 13, 14, 16, 12, 12, 16, 16, 13, 14, 16, 16, 13, 12,
12, 16, 12, 14, 11, 13, 11, 11, 13, 16, 13, 14, 12, 14, 12, 12,
16, 16, 15, 16, 16, 16, 14, 13, 13, 16, 12, 14, 12, 14, 12, 12,
14, 16, 13, 14, 13, 14, 12, 12, 16, 16, 14, 16, 14, 16, 13, 12,
15, 16, 13, 15, 15, 16, 13, 12, 15, 16, 13, 15, 14, 16, 13, 12,
16, 16, 14, 15, 15, 16, 13, 11, 8, 13, 8, 11, 10, 13, 10, 11,
11, 15, 10, 12, 12, 14, 11, 11, 15, 16, 13, 14, 15, 15, 13, 12,
9, 14, 9, 12, 11, 14, 10, 11, 11, 16, 10, 12, 13, 14, 11, 11,
16, 16, 13, 14, 15, 16, 13, 12, 11, 15, 9, 12, 12, 14, 10, 10,
12, 16, 11, 12, 14, 15, 11, 11, 16, 16, 13, 14, 16, 16, 12, 11,
9, 14, 10, 12, 11, 13, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11,
16, 16, 14, 14, 15, 15, 13, 12, 10, 15, 10, 12, 12, 14, 11, 11,
12, 16, 11, 13, 13, 14, 11, 11, 16, 16, 14, 14, 15, 16, 13, 12,
12, 16, 10, 12, 13, 15, 11, 11, 13, 16, 11, 13, 14, 15, 11, 11,
16, 16, 13, 13, 15, 16, 12, 11, 12, 16, 11, 13, 10, 13, 11, 11,
14, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 14, 15, 13, 11,
13, 16, 12, 14, 12, 14, 11, 11, 13, 16, 12, 14, 12, 14, 11, 11,
16, 16, 14, 15, 14, 14, 12, 11, 14, 16, 12, 13, 13, 15, 11, 11,
14, 16, 12, 13, 13, 14, 11, 11, 15, 16, 12, 13, 13, 13, 10, 9,
},
},
{
{
0, 7, 4, 7, 5, 7, 6, 6, 6, 10, 7, 8, 8, 9, 8, 7,
13, 14, 11, 12, 12, 12, 11, 9, 5, 9, 6, 8, 7, 9, 7, 7,
8, 11, 8, 9, 9, 10, 9, 8, 13, 16, 12, 12, 12, 13, 11, 9,
10, 13, 8, 10, 11, 12, 9, 9, 12, 14, 10, 11, 12, 13, 10, 9,
15, 16, 12, 12, 14, 14, 11, 9, 6, 10, 7, 9, 7, 9, 8, 7,
8, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 12, 11, 9,
8, 11, 8, 10, 9, 10, 9, 8, 10, 13, 10, 11, 10, 11, 9, 9,
14, 16, 12, 12, 13, 13, 11, 9, 12, 15, 10, 11, 12, 13, 10, 9,
13, 16, 11, 12, 13, 13, 10, 9, 16, 16, 12, 13, 14, 14, 11, 9,
10, 14, 11, 12, 9, 11, 10, 9, 12, 15, 12, 13, 11, 12, 11, 9,
16, 16, 13, 13, 13, 13, 11, 9, 12, 15, 12, 13, 11, 12, 11, 9,
13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 13, 13, 13, 11, 9,
14, 16, 13, 13, 13, 14, 11, 10, 16, 16, 13, 13, 13, 14, 11, 10,
16, 16, 13, 13, 14, 14, 11, 9, 4, 9, 6, 8, 6, 9, 7, 7,
8, 11, 8, 9, 9, 10, 9, 8, 13, 15, 12, 12, 13, 13, 11, 9,
6, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 8,
14, 16, 12, 12, 13, 13, 11, 10, 10, 13, 8, 10, 11, 12, 9, 9,
12, 15, 10, 11, 12, 13, 10, 9, 16, 16, 12, 12, 14, 14, 11, 9,
7, 11, 8, 9, 7, 10, 8, 8, 9, 12, 10, 11, 9, 11, 9, 9,
14, 16, 12, 13, 13, 13, 11, 10, 9, 12, 9, 10, 9, 11, 9, 9,
10, 13, 10, 11, 10, 11, 10, 9, 14, 16, 12, 13, 13, 13, 11, 9,
12, 15, 10, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 13, 10, 9,
16, 16, 12, 12, 14, 14, 11, 9, 10, 14, 11, 12, 9, 11, 10, 9,
12, 16, 12, 13, 11, 12, 11, 9, 16, 16, 14, 14, 13, 13, 11, 9,
12, 16, 12, 13, 11, 12, 10, 10, 13, 16, 12, 13, 11, 12, 11, 10,
16, 16, 13, 13, 13, 13, 11, 9, 14, 16, 13, 13, 13, 14, 11, 9,
15, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 13, 13, 10, 8,
7, 11, 8, 10, 9, 11, 9, 9, 10, 13, 10, 11, 11, 12, 10, 10,
15, 16, 13, 13, 14, 14, 12, 10, 9, 13, 9, 11, 10, 12, 10, 9,
11, 14, 10, 12, 12, 13, 10, 10, 16, 16, 13, 13, 14, 14, 12, 10,
11, 15, 9, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 14, 11, 10,
16, 16, 13, 13, 15, 15, 11, 10, 9, 13, 10, 11, 9, 11, 10, 9,
11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 14, 14, 14, 14, 12, 10,
10, 14, 10, 12, 11, 12, 10, 10, 12, 15, 11, 12, 12, 13, 11, 10,
16, 16, 13, 13, 14, 14, 12, 10, 13, 16, 11, 12, 13, 14, 11, 10,
13, 16, 11, 12, 13, 14, 11, 10, 16, 16, 12, 13, 14, 14, 11, 9,
11, 15, 12, 13, 10, 12, 10, 10, 13, 16, 13, 14, 11, 13, 11, 10,
16, 16, 14, 14, 14, 14, 12, 10, 13, 16, 13, 13, 11, 13, 11, 10,
14, 16, 13, 14, 12, 13, 11, 10, 16, 16, 14, 14, 13, 13, 12, 10,
15, 16, 13, 14, 14, 14, 11, 10, 15, 16, 13, 13, 13, 14, 11, 10,
16, 16, 12, 13, 13, 13, 10, 8, 9, 13, 10, 11, 10, 12, 10, 10,
12, 15, 11, 12, 12, 13, 11, 10, 16, 16, 14, 13, 14, 14, 12, 10,
10, 14, 10, 12, 11, 13, 10, 10, 13, 16, 11, 12, 12, 14, 11, 10,
16, 16, 13, 13, 14, 14, 12, 10, 12, 16, 9, 11, 12, 14, 10, 9,
13, 16, 10, 12, 13, 14, 10, 9, 16, 16, 12, 12, 14, 14, 11, 9,
10, 14, 11, 12, 10, 12, 10, 10, 13, 16, 12, 13, 12, 13, 11, 10,
16, 16, 14, 14, 14, 14, 12, 10, 11, 16, 11, 12, 11, 13, 11, 10,
13, 16, 12, 13, 12, 14, 11, 10, 16, 16, 14, 14, 14, 14, 12, 10,
13, 16, 11, 12, 13, 14, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9,
16, 16, 12, 12, 14, 14, 10, 8, 12, 16, 12, 13, 10, 12, 10, 9,
14, 16, 13, 13, 11, 12, 11, 9, 16, 16, 14, 14, 13, 13, 11, 9,
13, 16, 12, 13, 11, 12, 10, 9, 14, 16, 13, 13, 11, 13, 11, 9,
16, 16, 14, 14, 13, 13, 11, 9, 14, 16, 12, 13, 12, 13, 10, 8,
14, 16, 12, 12, 12, 13, 10, 8, 15, 16, 11, 11, 11, 12, 9, 6,
},
{
0, 7, 4, 7, 5, 8, 7, 8, 5, 10, 7, 10, 8, 10, 9, 10,
13, 16, 12, 14, 14, 14, 13, 12, 4, 10, 6, 9, 8, 11, 9, 9,
8, 12, 8, 11, 10, 12, 10, 10, 14, 16, 13, 14, 14, 15, 13, 12,
9, 14, 9, 12, 12, 14, 11, 11, 12, 16, 11, 13, 13, 15, 12, 12,
15, 16, 14, 15, 15, 16, 13, 13, 5, 10, 7, 10, 7, 10, 9, 9,
8, 12, 9, 11, 9, 11, 10, 10, 14, 16, 13, 14, 14, 15, 13, 12,
7, 12, 8, 11, 10, 12, 10, 10, 10, 13, 10, 12, 11, 13, 11, 11,
15, 16, 13, 15, 14, 16, 13, 13, 11, 16, 11, 13, 13, 16, 12, 12,
13, 16, 12, 14, 14, 16, 12, 12, 16, 16, 14, 16, 16, 16, 14, 13,
11, 15, 12, 14, 11, 13, 11, 12, 13, 16, 12, 14, 12, 14, 12, 12,
16, 16, 14, 16, 14, 16, 13, 13, 13, 16, 12, 14, 12, 14, 12, 12,
14, 16, 13, 15, 13, 15, 13, 13, 16, 16, 15, 16, 16, 16, 14, 13,
15, 16, 13, 16, 15, 16, 13, 13, 16, 16, 14, 16, 16, 16, 14, 13,
16, 16, 16, 16, 16, 16, 14, 13, 2, 9, 5, 8, 6, 9, 8, 9,
7, 11, 8, 10, 9, 11, 9, 10, 14, 16, 13, 14, 14, 15, 13, 12,
5, 11, 6, 10, 9, 11, 9, 10, 8, 13, 9, 11, 11, 12, 10, 11,
14, 16, 13, 14, 14, 16, 13, 13, 9, 15, 9, 12, 12, 14, 11, 11,
12, 16, 11, 13, 13, 15, 12, 12, 16, 16, 14, 15, 16, 16, 14, 13,
6, 11, 7, 10, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 11,
14, 16, 13, 14, 14, 15, 13, 13, 8, 12, 8, 11, 10, 12, 10, 11,
9, 13, 10, 12, 11, 13, 11, 11, 14, 16, 13, 14, 14, 16, 13, 13,
12, 16, 11, 13, 13, 15, 12, 12, 13, 16, 11, 13, 14, 16, 12, 12,
16, 16, 14, 15, 16, 16, 13, 13, 11, 15, 11, 14, 10, 13, 11, 12,
13, 16, 13, 15, 12, 14, 12, 12, 16, 16, 15, 16, 15, 16, 14, 13,
12, 16, 12, 14, 12, 14, 12, 12, 13, 16, 13, 15, 13, 14, 12, 13,
16, 16, 15, 16, 15, 16, 13, 13, 15, 16, 13, 16, 15, 16, 13, 13,
16, 16, 14, 16, 16, 16, 13, 13, 16, 16, 15, 16, 16, 16, 14, 13,
5, 12, 7, 10, 9, 12, 10, 10, 9, 13, 9, 12, 11, 13, 11, 11,
15, 16, 13, 14, 15, 15, 13, 13, 7, 13, 8, 11, 10, 13, 10, 11,
10, 14, 10, 12, 12, 14, 11, 12, 16, 16, 14, 15, 16, 16, 14, 13,
10, 16, 9, 12, 13, 15, 11, 12, 13, 16, 11, 13, 14, 16, 12, 12,
16, 16, 14, 16, 16, 16, 14, 13, 8, 13, 9, 12, 9, 12, 10, 11,
11, 15, 11, 13, 11, 13, 11, 12, 16, 16, 14, 16, 16, 16, 14, 13,
9, 14, 10, 12, 11, 13, 11, 12, 11, 15, 11, 13, 12, 14, 12, 12,
16, 16, 14, 16, 15, 16, 14, 13, 12, 16, 11, 14, 14, 16, 12, 12,
13, 16, 12, 14, 14, 16, 13, 13, 16, 16, 13, 15, 16, 16, 14, 13,
11, 16, 12, 14, 10, 13, 12, 12, 13, 16, 13, 15, 12, 14, 12, 13,
16, 16, 16, 16, 16, 16, 14, 14, 13, 16, 13, 15, 12, 15, 12, 13,
13, 16, 13, 15, 12, 15, 13, 13, 16, 16, 15, 16, 14, 16, 14, 13,
16, 16, 14, 16, 16, 16, 14, 13, 15, 16, 14, 16, 15, 16, 14, 13,
16, 16, 14, 16, 15, 16, 13, 12, 8, 14, 9, 12, 10, 14, 11, 12,
11, 16, 10, 13, 12, 14, 12, 12, 16, 16, 14, 15, 15, 16, 14, 13,
9, 15, 9, 12, 12, 14, 11, 12, 12, 16, 11, 13, 13, 15, 12, 12,
16, 16, 14, 15, 16, 16, 14, 13, 11, 16, 9, 12, 13, 15, 11, 11,
13, 16, 11, 13, 14, 16, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12,
9, 15, 10, 13, 11, 14, 11, 12, 12, 16, 11, 14, 12, 14, 12, 12,
16, 16, 14, 16, 16, 16, 14, 13, 10, 16, 10, 13, 12, 15, 12, 12,
12, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 16, 16, 16, 14, 13,
12, 16, 11, 13, 13, 16, 12, 12, 13, 16, 11, 13, 14, 16, 12, 12,
16, 16, 13, 14, 16, 16, 13, 12, 11, 16, 12, 14, 10, 13, 11, 12,
13, 16, 13, 15, 12, 14, 12, 12, 16, 16, 16, 16, 15, 16, 13, 12,
12, 16, 12, 15, 12, 14, 12, 12, 13, 16, 13, 15, 12, 14, 12, 12,
16, 16, 15, 16, 14, 15, 13, 12, 14, 16, 13, 14, 13, 16, 12, 12,
13, 16, 12, 14, 13, 15, 12, 12, 14, 16, 12, 13, 13, 14, 11, 10,
},
},
{
{
0, 7, 4, 7, 5, 7, 6, 6, 6, 10, 7, 8, 8, 9, 8, 8,
13, 14, 11, 12, 12, 12, 11, 10, 5, 9, 6, 8, 7, 9, 7, 7,
8, 11, 8, 9, 9, 10, 9, 8, 13, 16, 12, 12, 13, 13, 11, 10,
10, 14, 8, 10, 11, 13, 9, 9, 12, 15, 10, 11, 12, 13, 10, 10,
16, 16, 12, 13, 14, 14, 11, 10, 5, 10, 7, 9, 6, 9, 8, 8,
8, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 13, 11, 10,
8, 12, 8, 10, 9, 10, 9, 9, 10, 13, 9, 11, 10, 11, 9, 9,
14, 16, 12, 13, 13, 13, 11, 10, 12, 16, 10, 12, 12, 13, 10, 10,
13, 16, 11, 12, 13, 14, 11, 10, 16, 16, 12, 13, 14, 14, 11, 10,
10, 14, 11, 13, 9, 11, 10, 10, 12, 16, 12, 13, 11, 12, 11, 10,
16, 16, 13, 14, 13, 13, 12, 10, 12, 16, 12, 13, 11, 13, 11, 10,
13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 14, 12, 10,
14, 16, 13, 14, 13, 14, 12, 11, 16, 16, 13, 14, 14, 15, 12, 11,
16, 16, 13, 14, 14, 14, 11, 10, 3, 9, 5, 8, 6, 9, 7, 7,
8, 11, 8, 10, 9, 10, 9, 8, 14, 15, 12, 12, 13, 13, 11, 10,
6, 11, 6, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 9,
14, 16, 12, 13, 13, 13, 11, 10, 10, 14, 8, 11, 12, 13, 9, 9,
12, 16, 10, 11, 12, 13, 10, 10, 16, 16, 12, 13, 14, 14, 11, 10,
6, 11, 8, 10, 7, 10, 8, 8, 9, 12, 10, 11, 9, 11, 9, 9,
14, 16, 12, 13, 13, 13, 12, 10, 9, 12, 9, 11, 9, 11, 9, 9,
10, 13, 10, 11, 10, 12, 10, 9, 14, 16, 12, 13, 13, 13, 11, 10,
12, 16, 10, 12, 12, 14, 10, 10, 13, 16, 10, 12, 13, 14, 11, 10,
16, 16, 12, 13, 14, 14, 11, 10, 10, 15, 11, 13, 9, 11, 10, 10,
12, 16, 12, 13, 11, 12, 11, 10, 16, 16, 14, 14, 13, 14, 12, 10,
12, 16, 12, 13, 11, 13, 11, 10, 13, 16, 12, 13, 11, 13, 11, 10,
16, 16, 13, 14, 13, 13, 12, 10, 14, 16, 13, 14, 14, 14, 11, 11,
15, 16, 13, 14, 13, 14, 11, 10, 16, 16, 13, 13, 13, 14, 11, 9,
7, 12, 8, 11, 9, 11, 9, 10, 10, 14, 10, 12, 11, 12, 11, 10,
16, 16, 13, 13, 14, 14, 12, 11, 9, 13, 9, 11, 10, 12, 10, 10,
11, 15, 10, 12, 12, 13, 11, 10, 16, 16, 13, 14, 14, 14, 12, 11,
11, 16, 9, 11, 12, 14, 10, 10, 13, 16, 10, 12, 13, 14, 11, 10,
16, 16, 13, 14, 16, 16, 12, 11, 9, 13, 10, 12, 9, 12, 10, 10,
11, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 14, 14, 14, 13, 11,
10, 14, 10, 12, 11, 13, 11, 10, 12, 16, 11, 13, 12, 13, 11, 11,
16, 16, 13, 14, 14, 14, 12, 11, 13, 16, 11, 13, 13, 14, 11, 11,
13, 16, 11, 13, 13, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 10,
11, 16, 12, 14, 10, 12, 11, 10, 13, 16, 13, 14, 11, 13, 11, 11,
16, 16, 15, 16, 14, 14, 13, 11, 13, 16, 13, 14, 12, 13, 11, 11,
13, 16, 13, 14, 12, 13, 11, 11, 16, 16, 14, 14, 13, 14, 12, 11,
15, 16, 13, 14, 14, 16, 12, 11, 14, 16, 13, 14, 13, 14, 12, 11,
16, 16, 12, 13, 13, 14, 11, 9, 9, 14, 10, 12, 10, 13, 11, 11,
12, 16, 12, 13, 12, 14, 12, 11, 16, 16, 14, 14, 14, 14, 13, 11,
10, 16, 10, 13, 12, 14, 11, 11, 13, 16, 12, 13, 13, 14, 12, 11,
16, 16, 14, 14, 15, 15, 13, 11, 12, 16, 9, 12, 13, 14, 10, 10,
14, 16, 11, 12, 13, 15, 11, 10, 16, 16, 13, 13, 15, 16, 11, 10,
10, 16, 11, 13, 11, 13, 11, 11, 13, 16, 12, 14, 12, 14, 12, 11,
16, 16, 14, 14, 14, 14, 13, 11, 11, 16, 11, 13, 12, 14, 11, 11,
13, 16, 12, 14, 13, 14, 12, 11, 16, 16, 14, 14, 14, 15, 13, 11,
13, 16, 11, 13, 13, 14, 11, 10, 14, 16, 11, 13, 13, 14, 11, 10,
16, 16, 12, 13, 14, 15, 11, 9, 12, 16, 12, 14, 10, 13, 11, 10,
14, 16, 13, 14, 11, 13, 11, 10, 16, 16, 14, 15, 13, 14, 12, 10,
13, 16, 13, 14, 11, 13, 11, 10, 14, 16, 13, 14, 12, 13, 11, 10,
16, 16, 14, 14, 13, 13, 11, 10, 14, 16, 12, 13, 13, 14, 11, 9,
14, 16, 12, 13, 12, 13, 10, 9, 14, 16, 11, 11, 12, 12, 9, 7,
},
{
0, 7, 3, 8, 5, 8, 7, 9, 5, 10, 7, 10, 8, 11, 10, 10,
14, 16, 14, 15, 14, 16, 14, 14, 4, 10, 6, 10, 8, 11, 9, 10,
8, 12, 9, 11, 10, 12, 11, 11, 15, 16, 14, 16, 15, 16, 14, 14,
10, 16, 10, 13, 13, 16, 12, 13, 13, 16, 12, 14, 14, 16, 13, 13,
16, 16, 16, 16, 16, 16, 14, 15, 4, 10, 7, 10, 7, 10, 9, 10,
8, 12, 9, 12, 10, 12, 11, 12, 14, 16, 14, 16, 15, 16, 14, 14,
8, 12, 9, 12, 10, 13, 11, 12, 10, 14, 11, 13, 11, 14, 12, 13,
16, 16, 14, 16, 16, 16, 14, 15, 12, 16, 12, 14, 14, 16, 13, 14,
14, 16, 13, 16, 16, 16, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 12, 16, 11, 14, 13, 13, 13, 16, 13, 16, 13, 15, 13, 14,
16, 16, 16, 16, 16, 16, 15, 16, 13, 16, 13, 16, 13, 16, 13, 14,
14, 16, 14, 16, 14, 16, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 2, 9, 5, 9, 6, 10, 8, 10,
7, 11, 8, 11, 9, 12, 10, 11, 14, 16, 14, 16, 15, 16, 14, 14,
5, 11, 6, 10, 9, 12, 10, 11, 9, 13, 9, 12, 11, 13, 11, 12,
16, 16, 14, 16, 16, 16, 14, 14, 10, 16, 9, 13, 13, 16, 12, 13,
13, 16, 12, 14, 14, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 14,
5, 11, 8, 11, 7, 11, 10, 11, 9, 13, 10, 13, 10, 13, 11, 12,
16, 16, 14, 16, 16, 16, 14, 14, 8, 13, 9, 12, 10, 13, 11, 12,
10, 14, 10, 13, 11, 14, 12, 12, 16, 16, 14, 16, 15, 16, 14, 14,
12, 16, 12, 14, 14, 16, 13, 14, 14, 16, 12, 16, 15, 16, 13, 14,
16, 16, 15, 16, 16, 16, 15, 15, 11, 16, 12, 16, 10, 14, 12, 13,
13, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 15, 16,
13, 16, 13, 16, 13, 16, 13, 14, 14, 16, 14, 16, 13, 16, 13, 14,
16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 15, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16,
5, 13, 7, 12, 9, 13, 11, 12, 10, 14, 10, 13, 11, 13, 12, 13,
16, 16, 16, 16, 16, 16, 16, 15, 7, 14, 8, 12, 11, 14, 11, 12,
11, 16, 11, 13, 13, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 10, 14, 14, 16, 12, 13, 13, 16, 12, 15, 16, 16, 14, 14,
16, 16, 16, 16, 16, 16, 16, 16, 8, 14, 10, 13, 9, 13, 11, 12,
11, 16, 12, 14, 12, 14, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 11, 14, 12, 14, 12, 13, 11, 16, 12, 14, 12, 15, 13, 13,
16, 16, 15, 16, 16, 16, 15, 16, 13, 16, 12, 16, 15, 16, 14, 14,
13, 16, 12, 16, 16, 16, 14, 14, 16, 16, 14, 16, 16, 16, 14, 16,
11, 16, 13, 16, 10, 14, 12, 13, 14, 16, 14, 16, 13, 16, 14, 14,
16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 14, 16, 13, 16, 14, 15,
13, 16, 14, 16, 13, 16, 14, 15, 16, 16, 16, 16, 15, 16, 15, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16,
16, 16, 15, 16, 16, 16, 14, 14, 8, 16, 10, 14, 11, 16, 12, 13,
12, 16, 12, 14, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 14,
10, 16, 10, 14, 12, 16, 12, 13, 13, 16, 12, 15, 14, 16, 13, 14,
16, 16, 16, 16, 16, 16, 16, 15, 11, 16, 10, 13, 13, 16, 12, 13,
14, 16, 12, 14, 15, 16, 13, 13, 16, 16, 16, 16, 16, 16, 15, 14,
10, 16, 11, 14, 11, 16, 12, 13, 13, 16, 13, 16, 13, 16, 13, 14,
16, 16, 16, 16, 16, 16, 16, 15, 11, 16, 12, 14, 13, 16, 13, 14,
13, 16, 13, 16, 14, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 15,
13, 16, 12, 14, 14, 16, 13, 13, 13, 16, 12, 15, 14, 16, 13, 13,
16, 16, 14, 16, 16, 16, 14, 13, 11, 16, 12, 16, 11, 15, 12, 13,
14, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14,
12, 16, 13, 16, 12, 16, 13, 14, 13, 16, 14, 16, 13, 16, 13, 14,
16, 16, 16, 16, 14, 16, 14, 14, 14, 16, 13, 16, 14, 16, 13, 13,
13, 16, 13, 16, 14, 16, 13, 13, 15, 16, 13, 14, 13, 15, 12, 12,
},
},
{
{
0, 7, 4, 6, 4, 7, 6, 7, 6, 9, 7, 8, 7, 9, 8, 8,
13, 14, 12, 12, 12, 13, 11, 11, 5, 9, 5, 8, 7, 9, 7, 8,
8, 11, 8, 10, 9, 10, 9, 9, 13, 15, 12, 13, 12, 13, 11, 11,
9, 14, 8, 11, 11, 13, 10, 10, 11, 15, 10, 12, 12, 13, 10, 11,
14, 16, 12, 13, 14, 14, 12, 11, 5, 9, 7, 9, 6, 9, 8, 8,
8, 11, 8, 10, 8, 10, 9, 9, 13, 16, 12, 13, 13, 13, 11, 11,
7, 11, 8, 10, 9, 11, 9, 9, 9, 13, 9, 11, 10, 11, 10, 10,
14, 16, 12, 13, 13, 13, 12, 11, 11, 16, 10, 12, 12, 14, 11, 11,
13, 16, 11, 13, 13, 14, 11, 11, 16, 16, 13, 14, 14, 15, 12, 11,
10, 15, 11, 13, 9, 12, 10, 10, 12, 16, 12, 13, 11, 12, 11, 11,
15, 16, 13, 14, 13, 14, 12, 11, 12, 16, 12, 14, 11, 13, 11, 11,
13, 16, 12, 14, 12, 13, 12, 11, 16, 16, 13, 14, 14, 14, 12, 11,
14, 16, 13, 14, 14, 15, 12, 12, 16, 16, 13, 14, 14, 16, 12, 12,
16, 16, 14, 14, 14, 15, 12, 11, 3, 9, 5, 8, 6, 9, 7, 8,
7, 11, 8, 10, 9, 10, 9, 9, 13, 14, 12, 13, 13, 13, 12, 11,
6, 11, 6, 9, 8, 10, 8, 9, 9, 12, 8, 10, 10, 11, 9, 10,
14, 16, 12, 13, 13, 14, 12, 11, 9, 14, 8, 11, 11, 13, 10, 10,
12, 16, 10, 12, 12, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 11,
6, 11, 8, 10, 7, 10, 8, 9, 9, 12, 9, 11, 9, 11, 10, 10,
14, 16, 13, 13, 13, 14, 12, 11, 8, 12, 9, 11, 9, 11, 9, 10,
10, 13, 9, 11, 10, 12, 10, 10, 14, 16, 12, 13, 13, 14, 12, 11,
12, 16, 10, 12, 12, 14, 11, 11, 12, 16, 10, 12, 13, 14, 11, 11,
15, 16, 12, 13, 14, 14, 11, 11, 10, 15, 11, 13, 9, 12, 10, 10,
12, 16, 12, 14, 11, 13, 11, 11, 16, 16, 14, 14, 14, 14, 12, 11,
12, 16, 12, 14, 11, 13, 11, 11, 13, 16, 12, 14, 11, 13, 11, 11,
16, 16, 13, 14, 13, 14, 12, 11, 14, 16, 13, 14, 14, 15, 12, 11,
14, 16, 13, 14, 13, 15, 12, 11, 16, 16, 13, 14, 13, 14, 11, 10,
6, 13, 8, 11, 9, 12, 10, 10, 10, 14, 10, 12, 11, 13, 11, 11,
16, 16, 13, 14, 14, 14, 13, 12, 8, 14, 8, 12, 10, 13, 10, 11,
11, 15, 10, 12, 12, 13, 11, 11, 16, 16, 14, 14, 15, 16, 13, 12,
11, 16, 9, 12, 12, 14, 11, 11, 13, 16, 11, 13, 13, 16, 11, 11,
16, 16, 13, 14, 16, 16, 13, 12, 8, 14, 10, 12, 9, 12, 10, 11,
11, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 15, 14, 15, 13, 12,
10, 15, 10, 13, 11, 13, 11, 11, 11, 15, 11, 13, 12, 13, 11, 11,
16, 16, 13, 15, 14, 15, 13, 12, 12, 16, 11, 13, 13, 15, 11, 11,
13, 16, 11, 13, 13, 15, 11, 11, 16, 16, 12, 14, 14, 16, 12, 11,
11, 16, 12, 14, 10, 13, 11, 11, 13, 16, 13, 15, 12, 14, 12, 12,
16, 16, 15, 16, 14, 15, 13, 12, 12, 16, 13, 14, 12, 14, 12, 12,
13, 16, 13, 14, 12, 14, 12, 12, 16, 16, 14, 15, 13, 14, 12, 12,
15, 16, 13, 15, 14, 16, 12, 12, 14, 16, 13, 14, 13, 15, 12, 12,
15, 16, 12, 13, 13, 14, 11, 10, 9, 15, 10, 13, 11, 14, 11, 12,
12, 16, 12, 14, 12, 14, 12, 12, 16, 16, 14, 14, 14, 15, 13, 12,
10, 16, 10, 13, 12, 14, 12, 12, 13, 16, 12, 14, 13, 15, 12, 12,
16, 16, 14, 14, 15, 16, 13, 12, 11, 16, 9, 12, 13, 15, 11, 11,
14, 16, 11, 13, 14, 16, 11, 11, 16, 16, 13, 14, 16, 16, 12, 11,
10, 16, 11, 14, 11, 14, 12, 12, 13, 16, 13, 14, 12, 14, 12, 12,
16, 16, 14, 15, 15, 15, 13, 12, 11, 16, 12, 14, 12, 15, 12, 12,
13, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 15, 15, 16, 13, 12,
12, 16, 11, 13, 13, 15, 11, 11, 13, 16, 11, 13, 13, 15, 11, 11,
16, 16, 12, 13, 14, 16, 12, 10, 11, 16, 12, 14, 10, 13, 11, 11,
14, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 14, 14, 12, 11,
12, 16, 13, 14, 11, 14, 11, 11, 13, 16, 13, 14, 12, 14, 11, 11,
16, 16, 14, 15, 13, 14, 12, 11, 14, 16, 12, 14, 13, 14, 11, 10,
13, 16, 12, 13, 12, 14, 11, 10, 14, 16, 11, 12, 12, 12, 10, 8,
},
{
0, 8, 4, 9, 5, 9, 8, 10, 6, 11, 8, 11, 9, 12, 11, 12,
16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 6, 11, 9, 12, 10, 12,
9, 13, 10, 13, 11, 16, 12, 13, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 11, 16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 8, 12, 7, 12, 10, 12,
8, 13, 10, 13, 10, 13, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16,
8, 13, 10, 14, 11, 16, 12, 14, 11, 16, 12, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 14, 16, 12, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 10, 5, 10, 7, 11, 9, 11,
8, 12, 9, 12, 10, 13, 12, 13, 16, 16, 16, 16, 16, 16, 16, 16,
5, 12, 7, 12, 10, 13, 11, 12, 9, 16, 10, 13, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 14, 16,
14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
6, 12, 9, 13, 8, 12, 11, 13, 10, 16, 11, 16, 11, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 10, 14, 11, 16, 12, 16,
10, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 14, 16, 11, 16, 14, 16,
16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
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,
6, 16, 9, 13, 10, 16, 12, 14, 11, 16, 12, 16, 12, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 14, 12, 16, 13, 16,
12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 10, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 10, 16, 12, 16,
12, 16, 13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 13, 16, 14, 16, 11, 16, 13, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16,
14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 11, 16, 14, 16, 16, 16, 16, 16, 14, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 12, 16, 13, 16,
13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 11, 16, 13, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 13, 16,
16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 12, 16, 13, 16, 13, 16, 16, 16, 14, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 14, 16, 16, 16,
13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 12, 16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 11, 16, 13, 16,
16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 15,
},
},
{
{
0, 7, 3, 7, 4, 7, 6, 7, 6, 9, 7, 9, 7, 9, 8, 9,
13, 14, 12, 13, 13, 13, 12, 12, 4, 9, 5, 9, 7, 9, 8, 9,
7, 11, 8, 10, 9, 11, 9, 10, 13, 16, 12, 14, 13, 14, 12, 12,
9, 14, 8, 12, 12, 14, 10, 11, 11, 16, 10, 13, 13, 14, 11, 12,
15, 16, 13, 14, 14, 16, 12, 12, 5, 10, 7, 9, 6, 9, 8, 9,
8, 11, 8, 11, 8, 10, 9, 10, 14, 16, 12, 14, 13, 14, 12, 12,
7, 12, 8, 11, 9, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 11,
14, 16, 12, 14, 13, 14, 12, 12, 12, 16, 11, 13, 13, 15, 11, 12,
13, 16, 11, 14, 13, 15, 12, 12, 15, 16, 13, 15, 14, 16, 13, 13,
10, 15, 12, 14, 9, 13, 11, 12, 12, 16, 12, 14, 11, 13, 12, 12,
15, 16, 13, 15, 14, 15, 13, 13, 12, 16, 12, 14, 12, 14, 12, 12,
13, 16, 13, 14, 12, 14, 12, 12, 16, 16, 14, 15, 14, 16, 13, 13,
15, 16, 13, 15, 14, 16, 12, 13, 16, 16, 14, 16, 14, 16, 13, 13,
16, 16, 14, 16, 15, 16, 13, 13, 3, 9, 5, 9, 6, 9, 8, 9,
7, 11, 8, 10, 9, 11, 9, 10, 14, 15, 13, 14, 13, 14, 12, 12,
5, 11, 6, 10, 8, 11, 9, 10, 9, 12, 9, 11, 10, 12, 10, 11,
14, 16, 13, 14, 14, 15, 13, 13, 9, 15, 8, 12, 12, 14, 10, 11,
12, 16, 10, 13, 13, 15, 11, 12, 15, 16, 13, 14, 14, 16, 13, 13,
6, 11, 8, 11, 7, 10, 9, 10, 9, 13, 10, 12, 9, 12, 10, 11,
14, 16, 13, 14, 14, 14, 13, 13, 8, 13, 9, 12, 9, 12, 10, 11,
9, 13, 9, 12, 10, 12, 10, 11, 14, 16, 12, 14, 13, 14, 12, 12,
12, 16, 11, 13, 13, 15, 11, 12, 12, 16, 11, 13, 13, 15, 11, 12,
14, 16, 12, 14, 14, 15, 12, 12, 10, 15, 11, 14, 9, 13, 11, 12,
12, 16, 12, 14, 11, 14, 12, 12, 16, 16, 14, 16, 14, 15, 13, 13,
12, 16, 12, 14, 11, 14, 12, 12, 12, 16, 13, 14, 11, 14, 12, 12,
15, 16, 14, 15, 13, 15, 12, 13, 14, 16, 13, 15, 14, 16, 13, 13,
14, 16, 13, 15, 14, 16, 12, 13, 15, 16, 13, 15, 13, 15, 12, 12,
6, 13, 8, 12, 9, 12, 10, 11, 10, 14, 11, 13, 11, 13, 12, 12,
15, 16, 14, 15, 15, 15, 14, 13, 8, 14, 9, 12, 11, 13, 11, 12,
11, 15, 11, 13, 12, 14, 12, 12, 16, 16, 14, 15, 15, 16, 14, 14,
10, 16, 9, 13, 12, 15, 11, 12, 13, 16, 11, 14, 13, 16, 12, 12,
16, 16, 14, 15, 16, 16, 13, 13, 8, 14, 10, 13, 9, 13, 11, 12,
11, 15, 12, 14, 11, 14, 12, 12, 16, 16, 15, 16, 15, 16, 14, 14,
10, 15, 10, 13, 11, 14, 11, 12, 11, 15, 11, 14, 12, 14, 12, 12,
15, 16, 14, 15, 14, 16, 13, 13, 12, 16, 11, 14, 13, 16, 12, 12,
12, 16, 11, 14, 13, 15, 12, 12, 15, 16, 12, 14, 15, 16, 13, 13,
11, 16, 12, 14, 10, 14, 11, 12, 13, 16, 13, 16, 12, 14, 12, 13,
16, 16, 16, 16, 15, 16, 14, 13, 12, 16, 13, 15, 12, 14, 12, 13,
13, 16, 13, 15, 12, 14, 12, 13, 16, 16, 14, 16, 13, 15, 13, 13,
15, 16, 14, 16, 14, 16, 13, 13, 14, 16, 13, 15, 13, 16, 13, 13,
14, 16, 12, 14, 13, 14, 12, 12, 9, 16, 11, 14, 11, 15, 12, 13,
13, 16, 12, 14, 12, 15, 13, 13, 16, 16, 14, 15, 15, 15, 14, 13,
11, 16, 11, 14, 12, 16, 12, 13, 13, 16, 12, 14, 13, 16, 13, 13,
16, 16, 14, 15, 16, 16, 14, 13, 11, 16, 10, 13, 13, 16, 11, 12,
14, 16, 11, 14, 14, 16, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12,
11, 16, 12, 14, 11, 15, 12, 13, 13, 16, 13, 15, 13, 16, 13, 13,
16, 16, 15, 16, 15, 16, 14, 13, 11, 16, 12, 15, 12, 16, 12, 13,
13, 16, 13, 15, 13, 16, 13, 13, 16, 16, 15, 16, 15, 16, 14, 13,
12, 16, 11, 14, 13, 16, 12, 12, 13, 16, 11, 14, 13, 16, 12, 12,
16, 16, 13, 14, 15, 16, 12, 12, 11, 16, 12, 14, 10, 14, 11, 12,
14, 16, 13, 15, 12, 15, 12, 12, 16, 16, 16, 16, 14, 15, 13, 12,
12, 16, 13, 15, 12, 14, 12, 12, 13, 16, 13, 15, 12, 14, 12, 12,
16, 16, 14, 16, 14, 15, 12, 12, 14, 16, 13, 15, 13, 16, 11, 12,
13, 16, 12, 14, 13, 15, 11, 11, 14, 16, 12, 13, 12, 13, 11, 10,
},
{
0, 8, 4, 9, 5, 10, 9, 11, 5, 11, 9, 12, 9, 13, 12, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 6, 12, 9, 13, 11, 13,
9, 16, 10, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 8, 13, 7, 12, 11, 16,
8, 16, 11, 16, 11, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 10, 16, 11, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 10, 6, 11, 7, 12, 10, 13,
7, 12, 10, 13, 10, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 13, 7, 12, 10, 16, 12, 16, 10, 16, 11, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 16, 16,
16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 13, 9, 16, 8, 16, 12, 16, 9, 16, 12, 16, 11, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 12, 16, 13, 16,
10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
6, 16, 9, 16, 10, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 16, 12, 16, 13, 16,
12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 10, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 11, 16, 13, 16,
12, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 13, 16, 16, 16, 11, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16,
16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 11, 16, 12, 16, 16, 16,
13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 16, 16,
16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 7, 4, 8, 4, 8, 7, 8, 6, 10, 7, 10, 8, 10, 9, 10,
13, 16, 13, 15, 13, 15, 13, 14, 4, 10, 5, 10, 7, 10, 9, 10,
7, 12, 8, 11, 9, 12, 10, 11, 13, 16, 13, 15, 13, 16, 13, 14,
9, 16, 9, 13, 12, 16, 11, 13, 11, 16, 11, 14, 13, 16, 12, 14,
15, 16, 14, 16, 15, 16, 14, 14, 4, 10, 7, 10, 6, 10, 9, 10,
8, 12, 9, 12, 9, 11, 10, 12, 13, 16, 13, 16, 14, 16, 13, 14,
7, 12, 8, 12, 9, 12, 10, 12, 9, 13, 10, 13, 10, 13, 11, 12,
14, 16, 13, 16, 14, 16, 13, 14, 12, 16, 11, 14, 13, 16, 12, 14,
13, 16, 12, 16, 14, 16, 13, 14, 16, 16, 14, 16, 15, 16, 14, 14,
10, 16, 12, 15, 10, 14, 12, 13, 12, 16, 13, 16, 12, 14, 13, 14,
15, 16, 14, 16, 14, 16, 14, 14, 12, 16, 13, 16, 12, 16, 13, 14,
13, 16, 13, 16, 13, 16, 13, 14, 16, 16, 14, 16, 15, 16, 14, 15,
15, 16, 14, 16, 15, 16, 13, 15, 16, 16, 14, 16, 15, 16, 14, 15,
16, 16, 16, 16, 16, 16, 15, 15, 2, 9, 5, 10, 6, 10, 8, 10,
7, 11, 8, 11, 9, 11, 10, 11, 14, 16, 13, 15, 14, 15, 14, 14,
5, 11, 6, 11, 8, 12, 9, 11, 8, 13, 9, 12, 10, 13, 11, 12,
14, 16, 13, 15, 14, 16, 14, 14, 9, 16, 8, 13, 12, 16, 11, 13,
12, 16, 11, 14, 13, 16, 12, 13, 16, 16, 14, 16, 15, 16, 14, 15,
5, 12, 8, 11, 7, 11, 9, 11, 9, 13, 10, 13, 10, 13, 11, 12,
14, 16, 14, 16, 14, 16, 14, 15, 8, 13, 9, 13, 10, 13, 11, 12,
9, 13, 10, 13, 10, 13, 11, 13, 13, 16, 13, 15, 13, 16, 13, 14,
12, 16, 11, 14, 13, 16, 12, 14, 12, 16, 11, 14, 13, 16, 12, 14,
14, 16, 13, 16, 14, 16, 13, 14, 10, 16, 12, 15, 9, 14, 11, 13,
12, 16, 13, 16, 12, 15, 12, 14, 16, 16, 15, 16, 15, 16, 14, 14,
12, 16, 13, 16, 12, 16, 12, 14, 12, 16, 13, 16, 12, 15, 13, 14,
15, 16, 14, 16, 14, 16, 14, 14, 15, 16, 14, 16, 14, 16, 14, 15,
14, 16, 13, 16, 14, 16, 13, 14, 16, 16, 14, 16, 14, 16, 13, 14,
6, 14, 9, 13, 9, 14, 11, 12, 10, 14, 11, 13, 11, 14, 12, 13,
16, 16, 15, 16, 15, 16, 14, 15, 8, 15, 9, 13, 11, 14, 11, 13,
11, 16, 11, 14, 12, 15, 12, 14, 16, 16, 15, 16, 16, 16, 15, 16,
10, 16, 9, 14, 12, 16, 12, 13, 13, 16, 11, 15, 14, 16, 13, 14,
16, 16, 15, 16, 16, 16, 15, 16, 8, 15, 10, 13, 10, 14, 11, 13,
11, 16, 12, 14, 12, 14, 12, 14, 16, 16, 16, 16, 16, 16, 15, 16,
10, 16, 11, 14, 11, 15, 12, 13, 11, 16, 11, 14, 12, 15, 12, 14,
16, 16, 14, 16, 15, 16, 14, 15, 12, 16, 11, 15, 13, 16, 13, 14,
12, 16, 11, 14, 13, 16, 13, 14, 15, 16, 13, 16, 16, 16, 14, 15,
10, 16, 12, 15, 10, 15, 12, 13, 13, 16, 13, 16, 12, 16, 13, 14,
16, 16, 16, 16, 16, 16, 15, 15, 12, 16, 13, 16, 12, 16, 13, 14,
12, 16, 13, 16, 12, 16, 13, 14, 16, 16, 15, 16, 14, 16, 14, 15,
15, 16, 14, 16, 15, 16, 14, 15, 14, 16, 13, 16, 14, 16, 13, 14,
14, 16, 13, 15, 14, 16, 13, 14, 9, 16, 11, 16, 11, 16, 12, 14,
13, 16, 12, 16, 13, 16, 13, 14, 16, 16, 15, 16, 16, 16, 15, 15,
11, 16, 11, 16, 12, 16, 13, 14, 13, 16, 12, 16, 13, 16, 13, 14,
16, 16, 15, 16, 16, 16, 15, 15, 11, 16, 10, 15, 13, 16, 12, 13,
14, 16, 12, 16, 14, 16, 13, 14, 16, 16, 15, 16, 16, 16, 14, 14,
11, 16, 12, 16, 11, 16, 13, 14, 13, 16, 13, 16, 13, 16, 13, 14,
16, 16, 16, 16, 16, 16, 15, 15, 11, 16, 12, 16, 12, 16, 13, 14,
13, 16, 13, 16, 13, 16, 13, 14, 16, 16, 15, 16, 16, 16, 15, 14,
12, 16, 12, 15, 13, 16, 12, 14, 13, 16, 12, 16, 14, 16, 13, 14,
16, 16, 14, 16, 16, 16, 14, 14, 11, 16, 12, 16, 11, 16, 12, 14,
14, 16, 14, 16, 12, 16, 13, 14, 16, 16, 16, 16, 16, 16, 15, 14,
12, 16, 13, 16, 12, 16, 12, 14, 13, 16, 13, 16, 12, 16, 13, 14,
16, 16, 16, 16, 15, 16, 14, 14, 14, 16, 13, 16, 14, 16, 12, 14,
13, 16, 13, 16, 13, 16, 12, 13, 15, 16, 13, 14, 14, 15, 13, 13,
},
{
0, 8, 4, 10, 5, 11, 10, 16, 5, 12, 9, 16, 10, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 7, 12, 9, 16, 12, 16,
9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 9, 16, 8, 16, 12, 16,
8, 16, 11, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
8, 16, 11, 16, 12, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 11, 6, 12, 7, 16, 11, 16,
7, 16, 10, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 7, 16, 10, 16, 12, 16, 9, 16, 11, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 10, 16, 8, 16, 12, 16, 9, 16, 12, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 12, 16, 16, 16,
10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 9, 16, 10, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 16, 12, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 11, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
11, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 12, 16, 16, 16,
12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 9, 16, 16, 16, 16, 16,
16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 8, 4, 10, 5, 9, 8, 10, 6, 11, 8, 12, 8, 11, 10, 13,
14, 16, 14, 16, 14, 16, 16, 16, 3, 11, 5, 11, 8, 12, 10, 12,
7, 12, 9, 13, 10, 13, 11, 13, 14, 16, 14, 16, 16, 16, 16, 16,
9, 16, 9, 16, 12, 16, 12, 16, 11, 16, 11, 16, 14, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 7, 12, 6, 11, 10, 12,
8, 13, 9, 13, 9, 13, 11, 14, 13, 16, 14, 16, 14, 16, 16, 16,
7, 13, 9, 13, 9, 13, 11, 13, 9, 14, 10, 16, 11, 16, 12, 16,
15, 16, 14, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 13, 16,
13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 10, 16, 13, 16, 12, 16, 13, 16, 12, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 13, 16, 14, 16,
13, 16, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 2, 10, 5, 11, 6, 11, 9, 11,
7, 12, 9, 13, 9, 13, 11, 13, 14, 16, 16, 16, 16, 16, 16, 16,
4, 12, 6, 12, 8, 13, 10, 13, 8, 13, 9, 13, 11, 16, 12, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 8, 16, 12, 16, 12, 16,
12, 16, 11, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 12, 8, 13, 7, 13, 10, 13, 8, 14, 10, 14, 10, 14, 12, 14,
16, 16, 16, 16, 16, 16, 16, 16, 7, 14, 9, 16, 10, 16, 11, 14,
8, 14, 10, 16, 11, 16, 12, 16, 13, 16, 14, 16, 16, 16, 16, 16,
11, 16, 11, 16, 13, 16, 13, 16, 12, 16, 12, 16, 14, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 10, 16, 12, 16,
12, 16, 13, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 13, 16, 12, 16, 14, 16, 12, 16, 13, 16, 12, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
6, 16, 8, 16, 9, 16, 11, 13, 10, 16, 11, 16, 11, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 9, 16, 10, 16, 12, 16,
11, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 9, 16, 12, 16, 13, 16, 13, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 9, 16, 12, 16,
11, 16, 12, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 11, 16, 11, 16, 12, 16, 11, 16, 12, 16, 13, 16, 13, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 14, 16,
12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 10, 16, 13, 16, 13, 16, 14, 16, 13, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 12, 16, 14, 16,
12, 16, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 11, 16, 13, 16,
12, 16, 13, 16, 13, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 11, 16, 13, 16, 13, 16, 13, 16, 13, 16, 14, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 14, 16, 13, 16,
14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 12, 16, 12, 16, 13, 16, 13, 16, 13, 16, 13, 16, 14, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 12, 16, 13, 16, 14, 16,
13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 12, 16, 14, 16, 14, 16, 14, 16, 14, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 11, 16, 14, 16,
16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 14, 16, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
0, 10, 4, 12, 5, 16, 11, 16, 6, 16, 10, 16, 11, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 3, 16, 7, 16, 10, 16, 16, 16,
9, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 10, 16, 9, 16, 16, 16,
9, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 12, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 1, 16, 6, 16, 8, 16, 16, 16,
8, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 8, 16, 11, 16, 16, 16, 10, 16, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 11, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 11, 16, 9, 16, 16, 16, 10, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 16, 16, 16, 16,
10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
5, 16, 9, 16, 11, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 10, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 16, 16, 11, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
12, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 11, 16, 15, 16, 16, 16,
15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
9, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 9, 16, 16, 16, 16, 16,
16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 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 uint8_t rv34_table_inter_secondpat[NUM_INTER_TABLES][2][OTHERBLK_VLC_SIZE] = {
{
{
0, 4, 8, 3, 6, 8, 6, 7, 8, 4, 6, 8, 6, 7, 8, 7,
8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 3, 6, 8, 4, 6,
9, 7, 7, 8, 5, 7, 9, 6, 7, 9, 8, 8, 8, 7, 8, 8,
8, 8, 8, 8, 8, 7, 6, 8, 9, 7, 8, 9, 7, 8, 9, 7,
8, 9, 7, 8, 9, 8, 8, 9, 8, 8, 9, 8, 9, 9, 8, 8,
8, 8, 9, 9, 8, 9, 9, 7, 8, 8, 8, 9, 9, 8, 9, 9,
8, 8, 8, 7, 8, 8, 8, 8, 8, 7, 7, 6,
},
{
0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 5, 7, 10, 9,
9, 10, 7, 8, 10, 8, 9, 10, 10, 10, 10, 2, 6, 9, 4, 7,
10, 8, 9, 10, 4, 7, 10, 6, 7, 10, 9, 9, 10, 7, 8, 10,
8, 9, 10, 10, 10, 10, 6, 8, 10, 7, 9, 11, 9, 10, 11, 7,
9, 11, 8, 9, 11, 10, 10, 11, 8, 9, 11, 9, 10, 11, 11, 11,
10, 8, 10, 11, 9, 10, 11, 9, 10, 11, 8, 10, 11, 9, 10, 11,
10, 10, 11, 8, 10, 11, 9, 10, 10, 10, 10, 9,
},
},
{
{
0, 4, 8, 3, 6, 8, 6, 7, 9, 4, 6, 8, 5, 7, 8, 8,
8, 9, 7, 7, 8, 8, 8, 8, 8, 9, 8, 3, 6, 8, 4, 6,
9, 7, 7, 9, 5, 6, 9, 6, 7, 9, 8, 8, 9, 7, 8, 8,
8, 8, 8, 8, 8, 8, 6, 8, 9, 7, 8, 10, 7, 8, 9, 7,
8, 10, 7, 8, 10, 8, 8, 9, 7, 8, 9, 8, 9, 9, 9, 9,
8, 7, 9, 10, 8, 9, 10, 8, 8, 8, 8, 9, 10, 8, 9, 9,
8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 7, 6,
},
{
0, 4, 9, 3, 6, 10, 8, 9, 11, 3, 5, 9, 5, 7, 10, 9,
10, 11, 7, 8, 10, 9, 9, 11, 11, 11, 12, 2, 5, 10, 4, 7,
10, 8, 9, 11, 4, 6, 10, 6, 7, 10, 9, 10, 11, 7, 9, 10,
9, 9, 11, 11, 11, 11, 6, 8, 11, 7, 9, 11, 9, 10, 12, 7,
9, 11, 8, 9, 12, 10, 10, 12, 8, 10, 11, 10, 10, 11, 12, 11,
11, 8, 10, 12, 9, 11, 12, 10, 11, 12, 9, 10, 12, 10, 11, 12,
11, 11, 12, 9, 10, 12, 10, 10, 11, 11, 11, 10,
},
},
{
{
0, 4, 8, 3, 6, 9, 7, 8, 9, 4, 6, 8, 5, 7, 9, 8,
9, 9, 7, 8, 9, 8, 8, 9, 9, 9, 9, 2, 6, 9, 4, 6,
9, 7, 8, 10, 5, 7, 9, 6, 7, 9, 8, 8, 9, 7, 8, 9,
8, 8, 9, 9, 9, 9, 6, 8, 10, 7, 8, 10, 8, 9, 10, 6,
8, 10, 8, 8, 10, 9, 9, 10, 8, 9, 10, 9, 9, 10, 10, 10,
9, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10, 9, 9, 10,
9, 9, 9, 8, 9, 9, 8, 9, 9, 9, 9, 8,
},
{
0, 4, 10, 3, 6, 10, 8, 10, 12, 2, 6, 10, 6, 8, 11, 10,
11, 12, 7, 9, 11, 9, 10, 12, 12, 13, 13, 2, 6, 10, 4, 7,
11, 9, 10, 13, 4, 7, 11, 7, 8, 11, 10, 11, 12, 8, 9, 12,
10, 10, 12, 12, 12, 13, 6, 9, 12, 8, 10, 13, 10, 12, 14, 7,
10, 13, 9, 10, 13, 11, 11, 13, 9, 11, 13, 11, 11, 13, 13, 13,
13, 9, 11, 13, 10, 12, 14, 11, 12, 14, 9, 11, 14, 11, 12, 14,
12, 12, 14, 9, 12, 13, 11, 12, 13, 13, 12, 12,
},
},
{
{
0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 6, 7, 9, 9,
9, 10, 7, 8, 9, 8, 9, 10, 10, 10, 11, 2, 6, 9, 4, 7,
10, 7, 9, 10, 4, 7, 10, 6, 7, 10, 9, 9, 10, 7, 8, 10,
8, 9, 10, 10, 10, 10, 6, 8, 11, 7, 9, 11, 8, 10, 11, 6,
9, 11, 8, 9, 11, 9, 9, 11, 8, 9, 11, 9, 10, 11, 11, 10,
10, 8, 10, 11, 9, 10, 11, 9, 10, 11, 8, 10, 11, 9, 10, 11,
10, 10, 11, 8, 10, 11, 9, 10, 11, 10, 10, 10,
},
{
0, 4, 12, 3, 7, 12, 10, 11, 14, 3, 6, 12, 7, 9, 13, 12,
13, 14, 8, 11, 13, 11, 12, 14, 14, 14, 14, 1, 7, 12, 5, 8,
13, 10, 12, 14, 4, 8, 13, 8, 9, 13, 12, 13, 14, 9, 11, 14,
11, 12, 14, 14, 14, 14, 7, 10, 14, 9, 11, 14, 11, 13, 16, 8,
11, 14, 10, 12, 14, 13, 13, 16, 10, 12, 15, 12, 13, 15, 15, 15,
15, 10, 13, 15, 12, 13, 14, 13, 15, 15, 10, 13, 15, 12, 13, 15,
13, 14, 15, 10, 13, 14, 12, 13, 14, 14, 14, 14,
},
},
{
{
0, 4, 9, 3, 6, 10, 7, 9, 11, 3, 5, 9, 5, 7, 10, 9,
10, 12, 7, 8, 10, 9, 10, 11, 11, 12, 12, 2, 6, 10, 4, 7,
10, 7, 9, 12, 4, 7, 10, 6, 7, 11, 9, 10, 12, 7, 9, 11,
9, 9, 11, 11, 11, 12, 5, 8, 11, 7, 9, 12, 9, 10, 13, 6,
9, 12, 8, 9, 12, 10, 10, 12, 8, 10, 12, 10, 10, 12, 12, 12,
12, 8, 10, 12, 9, 11, 13, 10, 11, 13, 9, 11, 13, 10, 11, 13,
11, 11, 13, 9, 11, 12, 10, 11, 12, 11, 11, 12,
},
{
0, 4, 12, 3, 7, 13, 10, 12, 15, 3, 7, 13, 7, 9, 14, 12,
12, 13, 8, 11, 14, 11, 13, 15, 15, 14, 14, 1, 6, 13, 5, 8,
13, 10, 13, 15, 4, 8, 13, 8, 9, 14, 13, 13, 15, 8, 11, 14,
12, 12, 15, 15, 14, 14, 7, 10, 13, 9, 11, 13, 12, 14, 16, 8,
11, 14, 10, 12, 15, 13, 13, 16, 10, 12, 15, 12, 13, 15, 15, 14,
15, 11, 12, 14, 12, 14, 14, 13, 15, 15, 10, 12, 14, 12, 13, 15,
14, 15, 15, 10, 13, 13, 12, 13, 15, 14, 14, 15,
},
},
{
{
0, 5, 10, 3, 7, 11, 9, 11, 14, 3, 7, 11, 7, 8, 12, 11,
12, 14, 7, 9, 12, 10, 11, 14, 13, 14, 16, 1, 7, 11, 5, 8,
12, 9, 11, 15, 4, 8, 12, 7, 9, 13, 11, 12, 15, 8, 10, 13,
10, 11, 14, 14, 14, 16, 6, 9, 13, 8, 11, 14, 10, 13, 16, 7,
10, 14, 9, 11, 15, 12, 13, 16, 9, 11, 15, 12, 12, 15, 14, 14,
16, 10, 12, 14, 11, 13, 15, 12, 14, 16, 10, 12, 15, 11, 13, 16,
13, 14, 16, 10, 13, 16, 12, 13, 15, 14, 15, 16,
},
{
0, 5, 16, 3, 8, 14, 11, 13, 14, 2, 8, 14, 8, 10, 16, 13,
13, 14, 9, 13, 16, 12, 13, 16, 16, 14, 16, 1, 7, 14, 6, 10,
14, 12, 16, 16, 5, 9, 14, 9, 11, 16, 15, 16, 16, 10, 12, 16,
13, 13, 16, 16, 14, 16, 8, 11, 14, 11, 13, 14, 14, 14, 16, 8,
12, 14, 11, 13, 16, 16, 16, 16, 10, 12, 15, 13, 14, 16, 16, 16,
16, 11, 14, 14, 14, 15, 16, 16, 15, 16, 10, 13, 16, 13, 14, 14,
16, 16, 16, 10, 13, 16, 13, 14, 16, 16, 16, 16,
},
},
{
{
0, 5, 11, 3, 7, 13, 9, 12, 16, 3, 7, 12, 6, 9, 14, 11,
13, 16, 7, 10, 16, 11, 12, 16, 16, 16, 16, 1, 6, 12, 5, 9,
16, 9, 13, 16, 4, 8, 16, 7, 10, 16, 12, 15, 16, 7, 11, 16,
11, 12, 16, 16, 16, 16, 6, 10, 15, 8, 11, 16, 11, 14, 16, 7,
11, 16, 10, 12, 16, 13, 16, 16, 9, 13, 16, 13, 14, 16, 16, 16,
16, 10, 12, 16, 12, 16, 16, 16, 16, 16, 11, 13, 16, 13, 16, 16,
16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
0, 5, 16, 3, 8, 16, 12, 12, 16, 2, 8, 16, 8, 10, 16, 13,
13, 16, 9, 13, 16, 12, 13, 16, 16, 16, 16, 1, 8, 16, 6, 10,
16, 12, 16, 16, 5, 9, 16, 9, 11, 16, 13, 16, 16, 9, 12, 14,
12, 12, 16, 16, 16, 16, 8, 11, 13, 11, 12, 16, 14, 16, 16, 8,
12, 16, 11, 13, 16, 16, 15, 16, 9, 13, 14, 12, 13, 16, 16, 16,
16, 10, 12, 13, 14, 13, 16, 16, 16, 16, 9, 13, 16, 13, 12, 16,
16, 16, 16, 10, 12, 16, 14, 15, 16, 16, 16, 16,
},
},
};
static const uint8_t rv34_table_inter_thirdpat[NUM_INTER_TABLES][2][OTHERBLK_VLC_SIZE] = {
{
{
0, 5, 8, 3, 6, 9, 6, 7, 9, 4, 6, 9, 6, 7, 9, 8,
8, 9, 7, 8, 9, 8, 9, 9, 9, 9, 9, 2, 6, 9, 4, 7,
9, 7, 8, 9, 5, 7, 9, 6, 7, 9, 8, 8, 9, 7, 8, 9,
8, 9, 9, 9, 9, 8, 5, 8, 10, 6, 8, 10, 8, 9, 9, 7,
8, 10, 7, 9, 10, 8, 9, 9, 8, 9, 10, 9, 9, 10, 9, 9,
9, 7, 9, 10, 8, 9, 10, 8, 8, 9, 8, 9, 10, 8, 9, 10,
8, 8, 9, 8, 9, 9, 8, 9, 9, 8, 8, 7,
},
{
0, 4, 9, 2, 6, 10, 7, 8, 10, 3, 6, 10, 6, 7, 10, 9,
9, 10, 8, 9, 11, 9, 10, 11, 10, 11, 11, 2, 6, 10, 4, 7,
10, 8, 9, 10, 5, 7, 10, 7, 8, 10, 9, 9, 10, 9, 10, 11,
10, 10, 11, 11, 11, 11, 6, 9, 11, 7, 9, 11, 9, 10, 12, 8,
9, 11, 8, 10, 11, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11,
11, 9, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12,
11, 11, 12, 11, 12, 12, 11, 12, 12, 12, 11, 11,
},
},
{
{
0, 4, 9, 3, 6, 9, 6, 8, 9, 4, 6, 9, 5, 7, 9, 8,
8, 9, 7, 8, 10, 8, 9, 10, 9, 9, 9, 2, 6, 9, 4, 7,
9, 7, 8, 9, 5, 7, 9, 6, 7, 10, 8, 9, 9, 7, 9, 10,
8, 9, 10, 9, 9, 9, 5, 8, 10, 6, 8, 10, 8, 9, 10, 7,
8, 10, 7, 9, 11, 9, 9, 10, 8, 9, 10, 9, 10, 10, 10, 10,
9, 7, 9, 10, 8, 9, 11, 8, 9, 10, 8, 9, 11, 8, 9, 11,
9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 8,
},
{
0, 4, 9, 2, 5, 10, 7, 8, 11, 3, 6, 10, 6, 7, 10, 9,
10, 11, 8, 9, 11, 9, 10, 11, 11, 11, 12, 2, 6, 10, 4, 7,
10, 8, 9, 11, 5, 7, 10, 6, 8, 10, 9, 10, 11, 9, 10, 12,
10, 10, 12, 11, 12, 12, 6, 9, 11, 8, 9, 12, 9, 11, 13, 8,
10, 12, 9, 10, 12, 11, 11, 12, 10, 12, 13, 11, 12, 13, 13, 12,
13, 10, 11, 13, 10, 12, 13, 11, 12, 13, 11, 12, 13, 11, 12, 13,
12, 12, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13,
},
},
{
{
0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 5, 7, 10, 8,
9, 10, 7, 9, 10, 8, 9, 10, 10, 10, 10, 2, 6, 9, 4, 7,
10, 7, 9, 10, 4, 7, 10, 6, 8, 10, 8, 9, 10, 8, 9, 10,
9, 9, 10, 10, 10, 10, 5, 8, 11, 7, 9, 11, 8, 10, 11, 7,
9, 11, 8, 9, 11, 9, 10, 11, 9, 10, 11, 10, 10, 11, 11, 11,
11, 8, 10, 11, 9, 10, 11, 9, 10, 11, 9, 10, 12, 9, 10, 12,
10, 11, 11, 9, 10, 11, 10, 11, 11, 10, 10, 10,
},
{
0, 4, 10, 3, 6, 11, 8, 10, 12, 3, 6, 11, 6, 8, 11, 10,
11, 13, 9, 10, 13, 11, 12, 14, 13, 13, 14, 1, 6, 10, 5, 8,
12, 9, 10, 13, 5, 8, 11, 7, 9, 12, 11, 11, 13, 10, 12, 13,
11, 12, 14, 14, 13, 15, 7, 10, 12, 9, 11, 14, 11, 12, 15, 9,
11, 13, 10, 11, 14, 12, 12, 14, 12, 14, 16, 13, 13, 16, 14, 14,
16, 12, 13, 15, 12, 14, 15, 13, 14, 16, 13, 14, 16, 14, 14, 16,
14, 15, 16, 14, 16, 16, 15, 16, 16, 15, 15, 16,
},
},
{
{
0, 4, 9, 2, 6, 9, 7, 9, 11, 3, 6, 10, 6, 7, 10, 9,
10, 11, 7, 9, 10, 9, 10, 11, 11, 11, 12, 2, 6, 10, 4, 7,
10, 8, 9, 11, 5, 7, 10, 7, 8, 10, 9, 10, 11, 8, 9, 11,
9, 10, 11, 11, 12, 11, 6, 9, 11, 7, 10, 12, 9, 11, 12, 7,
10, 12, 9, 10, 12, 11, 11, 12, 9, 11, 12, 10, 11, 12, 12, 12,
12, 9, 11, 12, 9, 11, 13, 11, 12, 13, 9, 11, 13, 10, 12, 13,
11, 12, 13, 11, 12, 13, 11, 12, 13, 12, 13, 12,
},
{
0, 4, 11, 2, 6, 12, 9, 11, 16, 4, 7, 12, 7, 9, 15, 11,
12, 16, 10, 11, 16, 11, 13, 16, 16, 16, 16, 1, 6, 11, 5, 8,
16, 9, 12, 16, 6, 9, 15, 8, 10, 16, 12, 13, 16, 12, 14, 16,
12, 16, 16, 16, 16, 16, 8, 11, 14, 10, 12, 16, 12, 16, 16, 10,
13, 16, 12, 16, 16, 13, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16,
16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 5, 9, 3, 6, 10, 8, 10, 12, 3, 6, 10, 6, 8, 10, 10,
11, 12, 8, 9, 11, 10, 10, 12, 13, 13, 13, 1, 6, 10, 5, 8,
11, 9, 11, 13, 5, 8, 11, 7, 9, 11, 11, 11, 13, 8, 9, 11,
10, 10, 12, 13, 13, 14, 6, 9, 12, 8, 11, 13, 11, 13, 15, 8,
10, 13, 10, 11, 13, 12, 13, 15, 10, 12, 13, 12, 12, 13, 14, 14,
14, 9, 12, 14, 11, 13, 15, 13, 15, 16, 11, 13, 15, 12, 14, 15,
14, 15, 16, 13, 14, 15, 14, 14, 15, 15, 16, 16,
},
{
0, 4, 16, 2, 7, 16, 10, 13, 16, 3, 8, 16, 7, 10, 16, 16,
16, 16, 12, 16, 16, 15, 16, 16, 16, 16, 16, 1, 7, 16, 6, 9,
16, 10, 16, 16, 7, 12, 16, 9, 13, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 9, 16, 16, 11, 13, 16, 16, 16, 16, 12,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 4, 9, 3, 6, 11, 9, 12, 16, 3, 6, 10, 6, 8, 11, 12,
13, 16, 8, 9, 12, 10, 11, 13, 16, 16, 16, 1, 6, 10, 5, 8,
12, 10, 13, 16, 5, 8, 11, 8, 9, 13, 13, 14, 16, 9, 10, 14,
11, 12, 15, 16, 16, 16, 6, 10, 13, 9, 12, 16, 14, 16, 16, 9,
12, 14, 11, 13, 16, 16, 16, 16, 12, 14, 16, 14, 16, 16, 16, 16,
16, 11, 16, 16, 13, 16, 16, 16, 16, 16, 12, 16, 16, 13, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
0, 4, 16, 2, 8, 16, 10, 16, 16, 3, 9, 16, 8, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 7, 16, 5, 10,
16, 16, 16, 16, 7, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 10, 15, 16, 10, 16, 16, 16, 16, 16, 14,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
},
{
{
0, 3, 9, 3, 7, 11, 11, 15, 16, 3, 6, 11, 7, 9, 12, 16,
16, 16, 8, 10, 16, 11, 16, 16, 16, 16, 16, 1, 6, 11, 6, 9,
15, 16, 16, 16, 5, 8, 16, 9, 11, 16, 16, 16, 16, 10, 16, 16,
16, 16, 16, 16, 16, 16, 7, 11, 16, 11, 16, 16, 16, 16, 16, 11,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
0, 4, 16, 2, 8, 16, 16, 16, 16, 3, 12, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 7, 16, 5, 12,
16, 16, 16, 16, 6, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 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 uint8_t rv34_inter_coeff[NUM_INTER_TABLES][COEFF_VLC_SIZE] = {
{
1, 2, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10,
10, 10, 10, 11, 11, 11, 11, 12, 11, 11, 11, 13, 14, 15, 16, 16,
},
{
1, 2, 3, 5, 5, 6, 6, 7, 7, 8, 9, 9, 9, 10, 10, 10,
11, 11, 12, 12, 12, 12, 13, 13, 12, 12, 13, 14, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12,
12, 12, 13, 13, 13, 14, 14, 15, 14, 14, 16, 16, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12,
13, 13, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 11, 11, 13, 12, 12, 13,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
},
{
1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 10, 11, 14, 13, 15, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16,
}
};
#endif /* AVCODEC_RV34VLC_H */
| 123linslouis-android-video-cutter | jni/libavcodec/rv34vlc.h | C | asf20 | 255,167 |
/*
* LZW encoder
* Copyright (c) 2007 Bartlomiej Wolowiec
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* LZW encoder
* @file
* @author Bartlomiej Wolowiec
*/
#include "avcodec.h"
#include "put_bits.h"
#include "lzw.h"
#define LZW_MAXBITS 12
#define LZW_SIZTABLE (1<<LZW_MAXBITS)
#define LZW_HASH_SIZE 16411
#define LZW_HASH_SHIFT 6
#define LZW_PREFIX_EMPTY -1
#define LZW_PREFIX_FREE -2
/** One code in hash table */
typedef struct Code{
/// Hash code of prefix, LZW_PREFIX_EMPTY if empty prefix, or LZW_PREFIX_FREE if no code
int hash_prefix;
int code; ///< LZW code
uint8_t suffix; ///< Last character in code block
}Code;
/** LZW encode state */
typedef struct LZWEncodeState {
int clear_code; ///< Value of clear code
int end_code; ///< Value of end code
Code tab[LZW_HASH_SIZE]; ///< Hash table
int tabsize; ///< Number of values in hash table
int bits; ///< Actual bits code
int bufsize; ///< Size of output buffer
PutBitContext pb; ///< Put bit context for output
int maxbits; ///< Max bits code
int maxcode; ///< Max value of code
int output_bytes; ///< Number of written bytes
int last_code; ///< Value of last output code or LZW_PREFIX_EMPTY
enum FF_LZW_MODES mode; ///< TIFF or GIF
void (*put_bits)(PutBitContext *, int, unsigned); ///< GIF is LE while TIFF is BE
}LZWEncodeState;
const int ff_lzw_encode_state_size = sizeof(LZWEncodeState);
/**
* Hash function adding character
* @param head LZW code for prefix
* @param add Character to add
* @return New hash value
*/
static inline int hash(int head, const int add)
{
head ^= (add << LZW_HASH_SHIFT);
if (head >= LZW_HASH_SIZE)
head -= LZW_HASH_SIZE;
assert(head >= 0 && head < LZW_HASH_SIZE);
return head;
}
/**
* Hash function calculates next hash value
* @param head Actual hash code
* @param offset Offset calculated by hashOffset
* @return New hash value
*/
static inline int hashNext(int head, const int offset)
{
head -= offset;
if(head < 0)
head += LZW_HASH_SIZE;
return head;
}
/**
* Hash function calculates hash offset
* @param head Actual hash code
* @return Hash offset
*/
static inline int hashOffset(const int head)
{
return head ? LZW_HASH_SIZE - head : 1;
}
/**
* Write one code to stream
* @param s LZW state
* @param c code to write
*/
static inline void writeCode(LZWEncodeState * s, int c)
{
assert(0 <= c && c < 1 << s->bits);
s->put_bits(&s->pb, s->bits, c);
}
/**
* Find LZW code for block
* @param s LZW state
* @param c Last character in block
* @param hash_prefix LZW code for prefix
* @return LZW code for block or -1 if not found in table
*/
static inline int findCode(LZWEncodeState * s, uint8_t c, int hash_prefix)
{
int h = hash(FFMAX(hash_prefix, 0), c);
int hash_offset = hashOffset(h);
while (s->tab[h].hash_prefix != LZW_PREFIX_FREE) {
if ((s->tab[h].suffix == c)
&& (s->tab[h].hash_prefix == hash_prefix))
return h;
h = hashNext(h, hash_offset);
}
return h;
}
/**
* Add block to LZW code table
* @param s LZW state
* @param c Last character in block
* @param hash_prefix LZW code for prefix
* @param hash_code LZW code for bytes block
*/
static inline void addCode(LZWEncodeState * s, uint8_t c, int hash_prefix, int hash_code)
{
s->tab[hash_code].code = s->tabsize;
s->tab[hash_code].suffix = c;
s->tab[hash_code].hash_prefix = hash_prefix;
s->tabsize++;
if (s->tabsize >= (1 << s->bits) + (s->mode == FF_LZW_GIF))
s->bits++;
}
/**
* Clear LZW code table
* @param s LZW state
*/
static void clearTable(LZWEncodeState * s)
{
int i, h;
writeCode(s, s->clear_code);
s->bits = 9;
for (i = 0; i < LZW_HASH_SIZE; i++) {
s->tab[i].hash_prefix = LZW_PREFIX_FREE;
}
for (i = 0; i < 256; i++) {
h = hash(0, i);
s->tab[h].code = i;
s->tab[h].suffix = i;
s->tab[h].hash_prefix = LZW_PREFIX_EMPTY;
}
s->tabsize = 258;
}
/**
* Calculate number of bytes written
* @param s LZW encode state
* @return Number of bytes written
*/
static int writtenBytes(LZWEncodeState *s){
int ret = put_bits_count(&s->pb) >> 3;
ret -= s->output_bytes;
s->output_bytes += ret;
return ret;
}
/**
* Initialize LZW encoder. Please set s->clear_code, s->end_code and s->maxbits before run.
* @param s LZW state
* @param outbuf Output buffer
* @param outsize Size of output buffer
* @param maxbits Maximum length of code
*/
void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize,
int maxbits, enum FF_LZW_MODES mode,
void (*lzw_put_bits)(PutBitContext *, int, unsigned))
{
s->clear_code = 256;
s->end_code = 257;
s->maxbits = maxbits;
init_put_bits(&s->pb, outbuf, outsize);
s->bufsize = outsize;
assert(s->maxbits >= 9 && s->maxbits <= LZW_MAXBITS);
s->maxcode = 1 << s->maxbits;
s->output_bytes = 0;
s->last_code = LZW_PREFIX_EMPTY;
s->bits = 9;
s->mode = mode;
s->put_bits = lzw_put_bits;
}
/**
* LZW main compress function
* @param s LZW state
* @param inbuf Input buffer
* @param insize Size of input buffer
* @return Number of bytes written or -1 on error
*/
int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize)
{
int i;
if(insize * 3 > (s->bufsize - s->output_bytes) * 2){
return -1;
}
if (s->last_code == LZW_PREFIX_EMPTY)
clearTable(s);
for (i = 0; i < insize; i++) {
uint8_t c = *inbuf++;
int code = findCode(s, c, s->last_code);
if (s->tab[code].hash_prefix == LZW_PREFIX_FREE) {
writeCode(s, s->last_code);
addCode(s, c, s->last_code, code);
code= hash(0, c);
}
s->last_code = s->tab[code].code;
if (s->tabsize >= s->maxcode - 1) {
clearTable(s);
}
}
return writtenBytes(s);
}
/**
* Write end code and flush bitstream
* @param s LZW state
* @return Number of bytes written or -1 on error
*/
int ff_lzw_encode_flush(LZWEncodeState *s,
void (*lzw_flush_put_bits)(PutBitContext *))
{
if (s->last_code != -1)
writeCode(s, s->last_code);
writeCode(s, s->end_code);
lzw_flush_put_bits(&s->pb);
s->last_code = -1;
return writtenBytes(s);
}
| 123linslouis-android-video-cutter | jni/libavcodec/lzwenc.c | C | asf20 | 7,282 |
/*
* DPX (.dpx) image decoder
* Copyright (c) 2009 Jimmy Christensen
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "bytestream.h"
#include "avcodec.h"
typedef struct DPXContext {
AVFrame picture;
} DPXContext;
static unsigned int read32(const uint8_t **ptr, int is_big)
{
unsigned int temp;
if (is_big) {
temp = AV_RB32(*ptr);
} else {
temp = AV_RL32(*ptr);
}
*ptr += 4;
return temp;
}
static inline unsigned make_16bit(unsigned value)
{
// mask away invalid bits
value &= 0xFFC0;
// correctly expand to 16 bits
return value + (value >> 10);
}
static int decode_frame(AVCodecContext *avctx,
void *data,
int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
DPXContext *const s = avctx->priv_data;
AVFrame *picture = data;
AVFrame *const p = &s->picture;
uint8_t *ptr;
int magic_num, offset, endian;
int x, y;
int w, h, stride, bits_per_color, descriptor, elements, target_packet_size, source_packet_size;
unsigned int rgbBuffer;
magic_num = AV_RB32(buf);
buf += 4;
/* Check if the files "magic number" is "SDPX" which means it uses
* big-endian or XPDS which is for little-endian files */
if (magic_num == AV_RL32("SDPX")) {
endian = 0;
} else if (magic_num == AV_RB32("SDPX")) {
endian = 1;
} else {
av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n");
return -1;
}
offset = read32(&buf, endian);
// Need to end in 0x304 offset from start of file
buf = avpkt->data + 0x304;
w = read32(&buf, endian);
h = read32(&buf, endian);
// Need to end in 0x320 to read the descriptor
buf += 20;
descriptor = buf[0];
// Need to end in 0x323 to read the bits per color
buf += 3;
avctx->bits_per_raw_sample =
bits_per_color = buf[0];
switch (descriptor) {
case 51: // RGBA
elements = 4;
break;
case 50: // RGB
elements = 3;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported descriptor %d\n", descriptor);
return -1;
}
switch (bits_per_color) {
case 8:
if (elements == 4) {
avctx->pix_fmt = PIX_FMT_RGBA;
} else {
avctx->pix_fmt = PIX_FMT_RGB24;
}
source_packet_size = elements;
target_packet_size = elements;
break;
case 10:
avctx->pix_fmt = PIX_FMT_RGB48;
target_packet_size = 6;
source_packet_size = elements * 2;
break;
case 12:
case 16:
if (endian) {
avctx->pix_fmt = PIX_FMT_RGB48BE;
} else {
avctx->pix_fmt = PIX_FMT_RGB48LE;
}
target_packet_size = 6;
source_packet_size = elements * 2;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported color depth : %d\n", bits_per_color);
return -1;
}
if (s->picture.data[0])
avctx->release_buffer(avctx, &s->picture);
if (avcodec_check_dimensions(avctx, w, h))
return -1;
if (w != avctx->width || h != avctx->height)
avcodec_set_dimensions(avctx, w, h);
if (avctx->get_buffer(avctx, p) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
// Move pointer to offset from start of file
buf = avpkt->data + offset;
ptr = p->data[0];
stride = p->linesize[0];
switch (bits_per_color) {
case 10:
for (x = 0; x < avctx->height; x++) {
uint16_t *dst = (uint16_t*)ptr;
for (y = 0; y < avctx->width; y++) {
rgbBuffer = read32(&buf, endian);
// Read out the 10-bit colors and convert to 16-bit
*dst++ = make_16bit(rgbBuffer >> 16);
*dst++ = make_16bit(rgbBuffer >> 6);
*dst++ = make_16bit(rgbBuffer << 4);
}
ptr += stride;
}
break;
case 8:
case 12: // Treat 12-bit as 16-bit
case 16:
if (source_packet_size == target_packet_size) {
for (x = 0; x < avctx->height; x++) {
memcpy(ptr, buf, target_packet_size*avctx->width);
ptr += stride;
buf += source_packet_size*avctx->width;
}
} else {
for (x = 0; x < avctx->height; x++) {
uint8_t *dst = ptr;
for (y = 0; y < avctx->width; y++) {
memcpy(dst, buf, target_packet_size);
dst += target_packet_size;
buf += source_packet_size;
}
ptr += stride;
}
}
break;
}
*picture = s->picture;
*data_size = sizeof(AVPicture);
return buf_size;
}
static av_cold int decode_init(AVCodecContext *avctx)
{
DPXContext *s = avctx->priv_data;
avcodec_get_frame_defaults(&s->picture);
avctx->coded_frame = &s->picture;
return 0;
}
static av_cold int decode_end(AVCodecContext *avctx)
{
DPXContext *s = avctx->priv_data;
if (s->picture.data[0])
avctx->release_buffer(avctx, &s->picture);
return 0;
}
AVCodec dpx_decoder = {
"dpx",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_DPX,
sizeof(DPXContext),
decode_init,
NULL,
decode_end,
decode_frame,
0,
NULL,
.long_name = NULL_IF_CONFIG_SMALL("DPX image"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/dpx.c | C | asf20 | 6,556 |
/*
* copyright (C) 2003 the ffmpeg project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_SVQ1_VLC_H
#define AVCODEC_SVQ1_VLC_H
#include <stdint.h>
/* values in this table range from 0..3; adjust retrieved value by +0 */
const uint8_t ff_svq1_block_type_vlc[4][2] = {
/* { code, length } */
{ 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 }
};
/* values in this table range from -1..6; adjust retrieved value by -1 */
const uint8_t ff_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 */
const uint8_t ff_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 */
const uint16_t ff_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 */
const uint16_t ff_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 /* AVCODEC_SVQ1_VLC_H */
| 123linslouis-android-video-cutter | jni/libavcodec/svq1_vlc.h | C | asf20 | 14,901 |
/*
* MSMPEG4 backend for ffmpeg encoder and decoder
* copyright (c) 2001 Fabrice Bellard
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MSMPEG4 data tables.
*/
#ifndef AVCODEC_MSMPEG4DATA_H
#define AVCODEC_MSMPEG4DATA_H
#include "libavutil/common.h"
#include "get_bits.h"
#include "rl.h"
/* 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;
extern VLC ff_msmp4_mb_i_vlc;
extern VLC ff_msmp4_dc_luma_vlc[2];
extern VLC ff_msmp4_dc_chroma_vlc[2];
/* intra picture macroblock coded block pattern */
extern const uint16_t ff_msmp4_mb_i_table[64][2];
#define WMV1_SCANTABLE_COUNT 4
extern const uint8_t wmv1_scantable[WMV1_SCANTABLE_COUNT][64];
#define NB_RL_TABLES 6
extern RLTable rl_table[NB_RL_TABLES];
extern const uint8_t wmv1_y_dc_scale_table[32];
extern const uint8_t wmv1_c_dc_scale_table[32];
extern const uint8_t old_ff_y_dc_scale_table[32];
extern MVTable mv_tables[2];
extern const uint8_t v2_mb_type[8][2];
extern const uint8_t v2_intra_cbpc[4][2];
extern const uint32_t table_mb_non_intra[128][2];
extern const uint8_t table_inter_intra[4][2];
extern const uint32_t ff_table0_dc_lum[120][2];
extern const uint32_t ff_table1_dc_lum[120][2];
extern const uint32_t ff_table0_dc_chroma[120][2];
extern const uint32_t ff_table1_dc_chroma[120][2];
#define WMV2_INTER_CBP_TABLE_COUNT 4
extern const uint32_t (* const wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2];
extern const uint8_t wmv2_scantableA[64];
extern const uint8_t wmv2_scantableB[64];
#endif /* AVCODEC_MSMPEG4DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/msmpeg4data.h | C | asf20 | 2,654 |
/*
* The simplest AC-3 encoder
* Copyright (c) 2000 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* The simplest AC-3 encoder.
*/
//#define DEBUG
//#define DEBUG_BITALLOC
#include "libavutil/crc.h"
#include "avcodec.h"
#include "libavutil/common.h" /* for av_reverse */
#include "put_bits.h"
#include "ac3.h"
#include "audioconvert.h"
typedef struct AC3EncodeContext {
PutBitContext pb;
int nb_channels;
int nb_all_channels;
int lfe_channel;
const uint8_t *channel_map;
int bit_rate;
unsigned int sample_rate;
unsigned int bitstream_id;
unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */
unsigned int frame_size; /* current frame size in words */
unsigned int bits_written;
unsigned int samples_written;
int sr_shift;
unsigned int frame_size_code;
unsigned int sr_code; /* frequency */
unsigned int channel_mode;
int lfe;
unsigned int bitstream_mode;
short last_samples[AC3_MAX_CHANNELS][256];
unsigned int chbwcod[AC3_MAX_CHANNELS];
int nb_coefs[AC3_MAX_CHANNELS];
/* bitrate allocation control */
int slow_gain_code, slow_decay_code, fast_decay_code, db_per_bit_code, floor_code;
AC3BitAllocParameters bit_alloc;
int coarse_snr_offset;
int fast_gain_code[AC3_MAX_CHANNELS];
int fine_snr_offset[AC3_MAX_CHANNELS];
/* mantissa encoding */
int mant1_cnt, mant2_cnt, mant4_cnt;
} AC3EncodeContext;
static int16_t costab[64];
static int16_t sintab[64];
static int16_t xcos1[128];
static int16_t xsin1[128];
#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 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;
}
typedef struct IComplex {
short re,im;
} IComplex;
static av_cold void fft_init(int ln)
{
int i, 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));
}
}
/* 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 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 = av_reverse[j] >> (8 - ln);
if (k < j)
FFSWAP(IComplex, z[k], z[j]);
}
/* 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);
dprintf(NULL, "exp_diff=%d\n", exp_diff);
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, exp_min;
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;
/* Decrease the delta between each groups to within 2
* so that they can be differentially encoded */
for (i=1;i<=nb_groups;i++)
exp1[i] = FFMIN(exp1[i], exp1[i-1] + 2);
for (i=nb_groups-1;i>=0;i--)
exp1[i] = FFMIN(exp1[i], exp1[i+1] + 2);
/* 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)
av_log(NULL, AV_LOG_DEBUG, "exponents: strategy=%d\n", exp_strategy);
for(i=0;i<=nb_groups * group_size;i++) {
av_log(NULL, AV_LOG_DEBUG, "%d ", encoded_exp[i]);
}
av_log(NULL, AV_LOG_DEBUG, "\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 void bit_alloc_masking(AC3EncodeContext *s,
uint8_t encoded_exp[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
uint8_t exp_strategy[NB_BLOCKS][AC3_MAX_CHANNELS],
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50])
{
int blk, ch;
int16_t band_psd[NB_BLOCKS][AC3_MAX_CHANNELS][50];
for(blk=0; blk<NB_BLOCKS; blk++) {
for(ch=0;ch<s->nb_all_channels;ch++) {
if(exp_strategy[blk][ch] == EXP_REUSE) {
memcpy(psd[blk][ch], psd[blk-1][ch], (N/2)*sizeof(int16_t));
memcpy(mask[blk][ch], mask[blk-1][ch], 50*sizeof(int16_t));
} else {
ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0,
s->nb_coefs[ch],
psd[blk][ch], band_psd[blk][ch]);
ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, band_psd[blk][ch],
0, s->nb_coefs[ch],
ff_ac3_fast_gain_tab[s->fast_gain_code[ch]],
ch == s->lfe_channel,
DBA_NONE, 0, NULL, NULL, NULL,
mask[blk][ch]);
}
}
}
}
static int bit_alloc(AC3EncodeContext *s,
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50],
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2],
int frame_bits, int coarse_snr_offset, int fine_snr_offset)
{
int i, ch;
int snr_offset;
snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2;
/* 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++) {
ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0,
s->nb_coefs[ch], snr_offset,
s->bit_alloc.floor, ff_ac3_bap_tab,
bap[i][ch]);
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",
coarse_snr_offset, fine_snr_offset, 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 coarse_snr_offset, fine_snr_offset;
uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2];
int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50];
static const int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 };
/* init default parameters */
s->slow_decay_code = 2;
s->fast_decay_code = 1;
s->slow_gain_code = 1;
s->db_per_bit_code = 2;
s->floor_code = 4;
for(ch=0;ch<s->nb_all_channels;ch++)
s->fast_gain_code[ch] = 4;
/* compute real values */
s->bit_alloc.sr_code = s->sr_code;
s->bit_alloc.sr_shift = s->sr_shift;
s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->sr_shift;
s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->sr_shift;
s->bit_alloc.slow_gain = ff_ac3_slow_gain_tab[s->slow_gain_code];
s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code];
s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code];
/* header size */
frame_bits += 65;
// if (s->channel_mode == 2)
// frame_bits += 2;
frame_bits += frame_bits_inc[s->channel_mode];
/* audio blocks */
for(i=0;i<NB_BLOCKS;i++) {
frame_bits += s->nb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */
if (s->channel_mode == AC3_CHMODE_STEREO) {
frame_bits++; /* rematstr */
if(i==0) frame_bits += 4;
}
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);
/* auxdatae, crcrsv */
frame_bits += 2;
/* CRC */
frame_bits += 16;
/* calculate psd and masking curve before doing bit allocation */
bit_alloc_masking(s, encoded_exp, exp_strategy, psd, mask);
/* now the big work begins : do the bit allocation. Modify the snr
offset until we can pack everything in the requested frame size */
coarse_snr_offset = s->coarse_snr_offset;
while (coarse_snr_offset >= 0 &&
bit_alloc(s, mask, psd, bap, frame_bits, coarse_snr_offset, 0) < 0)
coarse_snr_offset -= SNR_INC1;
if (coarse_snr_offset < 0) {
av_log(NULL, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n");
return -1;
}
while ((coarse_snr_offset + SNR_INC1) <= 63 &&
bit_alloc(s, mask, psd, bap1, frame_bits,
coarse_snr_offset + SNR_INC1, 0) >= 0) {
coarse_snr_offset += SNR_INC1;
memcpy(bap, bap1, sizeof(bap1));
}
while ((coarse_snr_offset + 1) <= 63 &&
bit_alloc(s, mask, psd, bap1, frame_bits, coarse_snr_offset + 1, 0) >= 0) {
coarse_snr_offset++;
memcpy(bap, bap1, sizeof(bap1));
}
fine_snr_offset = 0;
while ((fine_snr_offset + SNR_INC1) <= 15 &&
bit_alloc(s, mask, psd, bap1, frame_bits,
coarse_snr_offset, fine_snr_offset + SNR_INC1) >= 0) {
fine_snr_offset += SNR_INC1;
memcpy(bap, bap1, sizeof(bap1));
}
while ((fine_snr_offset + 1) <= 15 &&
bit_alloc(s, mask, psd, bap1, frame_bits,
coarse_snr_offset, fine_snr_offset + 1) >= 0) {
fine_snr_offset++;
memcpy(bap, bap1, sizeof(bap1));
}
s->coarse_snr_offset = coarse_snr_offset;
for(ch=0;ch<s->nb_all_channels;ch++)
s->fine_snr_offset[ch] = fine_snr_offset;
#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;
}
static av_cold int set_channel_info(AC3EncodeContext *s, int channels,
int64_t *channel_layout)
{
int ch_layout;
if (channels < 1 || channels > AC3_MAX_CHANNELS)
return -1;
if ((uint64_t)*channel_layout > 0x7FF)
return -1;
ch_layout = *channel_layout;
if (!ch_layout)
ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL);
if (avcodec_channel_layout_num_channels(ch_layout) != channels)
return -1;
s->lfe = !!(ch_layout & CH_LOW_FREQUENCY);
s->nb_all_channels = channels;
s->nb_channels = channels - s->lfe;
s->lfe_channel = s->lfe ? s->nb_channels : -1;
if (s->lfe)
ch_layout -= CH_LOW_FREQUENCY;
switch (ch_layout) {
case CH_LAYOUT_MONO: s->channel_mode = AC3_CHMODE_MONO; break;
case CH_LAYOUT_STEREO: s->channel_mode = AC3_CHMODE_STEREO; break;
case CH_LAYOUT_SURROUND: s->channel_mode = AC3_CHMODE_3F; break;
case CH_LAYOUT_2_1: s->channel_mode = AC3_CHMODE_2F1R; break;
case CH_LAYOUT_4POINT0: s->channel_mode = AC3_CHMODE_3F1R; break;
case CH_LAYOUT_QUAD:
case CH_LAYOUT_2_2: s->channel_mode = AC3_CHMODE_2F2R; break;
case CH_LAYOUT_5POINT0:
case CH_LAYOUT_5POINT0_BACK: s->channel_mode = AC3_CHMODE_3F2R; break;
default:
return -1;
}
s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe];
*channel_layout = ch_layout;
if (s->lfe)
*channel_layout |= CH_LOW_FREQUENCY;
return 0;
}
static av_cold int AC3_encode_init(AVCodecContext *avctx)
{
int freq = avctx->sample_rate;
int bitrate = avctx->bit_rate;
AC3EncodeContext *s = avctx->priv_data;
int i, j, ch;
float alpha;
int bw_code;
avctx->frame_size = AC3_FRAME_SIZE;
ac3_common_init();
if (!avctx->channel_layout) {
av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
"encoder will guess the layout, but it "
"might be incorrect.\n");
}
if (set_channel_info(s, avctx->channels, &avctx->channel_layout)) {
av_log(avctx, AV_LOG_ERROR, "invalid channel layout\n");
return -1;
}
/* frequency */
for(i=0;i<3;i++) {
for(j=0;j<3;j++)
if ((ff_ac3_sample_rate_tab[j] >> i) == freq)
goto found;
}
return -1;
found:
s->sample_rate = freq;
s->sr_shift = i;
s->sr_code = j;
s->bitstream_id = 8 + s->sr_shift;
s->bitstream_mode = 0; /* complete main audio service */
/* bitrate & frame size */
for(i=0;i<19;i++) {
if ((ff_ac3_bitrate_tab[i] >> s->sr_shift)*1000 == bitrate)
break;
}
if (i == 19)
return -1;
s->bit_rate = bitrate;
s->frame_size_code = i << 1;
s->frame_size_min = ff_ac3_frame_size_tab[s->frame_size_code][s->sr_code];
s->bits_written = 0;
s->samples_written = 0;
s->frame_size = s->frame_size_min;
/* bit allocation init */
if(avctx->cutoff) {
/* calculate bandwidth based on user-specified cutoff frequency */
int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1);
int fbw_coeffs = cutoff * 512 / s->sample_rate;
bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60);
} else {
/* use default bandwidth setting */
/* XXX: should compute the bandwidth according to the frame
size, so that we avoid annoying high frequency artifacts */
bw_code = 50;
}
for(ch=0;ch<s->nb_channels;ch++) {
/* bandwidth for each channel */
s->chbwcod[ch] = bw_code;
s->nb_coefs[ch] = bw_code * 3 + 73;
}
if (s->lfe) {
s->nb_coefs[s->lfe_channel] = 7; /* fixed */
}
/* initial snr offset */
s->coarse_snr_offset = 40;
/* 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));
}
avctx->coded_frame= avcodec_alloc_frame();
avctx->coded_frame->key_frame= 1;
return 0;
}
/* output the AC-3 frame header */
static void output_frame_header(AC3EncodeContext *s, unsigned char *frame)
{
init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE);
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->sr_code);
put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min));
put_bits(&s->pb, 5, s->bitstream_id);
put_bits(&s->pb, 3, s->bitstream_mode);
put_bits(&s->pb, 3, s->channel_mode);
if ((s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO)
put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */
if (s->channel_mode & 0x04)
put_bits(&s->pb, 2, 1); /* XXX -6 dB */
if (s->channel_mode == AC3_CHMODE_STEREO)
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 additional 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 AC-3
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->channel_mode == AC3_CHMODE_STEREO)
{
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;
av_log(NULL, AV_LOG_DEBUG, "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->slow_decay_code);
put_bits(&s->pb, 2, s->fast_decay_code);
put_bits(&s->pb, 2, s->slow_gain_code);
put_bits(&s->pb, 2, s->db_per_bit_code);
put_bits(&s->pb, 3, s->floor_code);
}
/* snr offset */
put_bits(&s->pb, 1, baie); /* always present with bai */
if (baie) {
put_bits(&s->pb, 6, s->coarse_snr_offset);
for(ch=0;ch<s->nb_all_channels;ch++) {
put_bits(&s->pb, 4, s->fine_snr_offset[ch]);
put_bits(&s->pb, 3, s->fast_gain_code[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;
}
}
}
}
#define CRC16_POLY ((1 << 0) | (1 << 2) | (1 << 15) | (1 << 16))
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 - (put_bits_ptr(&s->pb) - frame) - 2;
assert(n >= 0);
if(n>0)
memset(put_bits_ptr(&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 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
frame + 4, 2 * frame_size_58 - 4));
/* 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);
AV_WB16(frame+2,crc1);
crc2 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
frame + 2 * frame_size_58,
(frame_size - frame_size_58) * 2 - 2));
AV_WB16(frame+2*frame_size-2,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;
int16_t *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++) {
int ich = s->channel_map[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[ich], N/2 * sizeof(int16_t));
sinc = s->nb_all_channels;
sptr = samples + (sinc * (N/2) * i) + ich;
for(j=0;j<N/2;j++) {
v = *sptr;
input_samples[j + N/2] = v;
s->last_samples[ich][j] = v;
sptr += sinc;
}
/* apply the MDCT window */
for(j=0;j<N/2;j++) {
input_samples[j] = MUL16(input_samples[j],
ff_ac3_window[j]) >> 15;
input_samples[N-j-1] = MUL16(input_samples[N-j-1],
ff_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 - 9;
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;
}
}
/* adjust for fractional frame sizes */
while(s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) {
s->bits_written -= s->bit_rate;
s->samples_written -= s->sample_rate;
}
s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate);
s->bits_written += s->frame_size * 16;
s->samples_written += AC3_FRAME_SIZE;
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 av_cold int AC3_encode_close(AVCodecContext *avctx)
{
av_freep(&avctx->coded_frame);
return 0;
}
#if 0
/*************************************************************************/
/* TEST */
#undef random
#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",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_AC3,
sizeof(AC3EncodeContext),
AC3_encode_init,
AC3_encode_frame,
AC3_encode_close,
NULL,
.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.channel_layouts = (const int64_t[]){
CH_LAYOUT_MONO,
CH_LAYOUT_STEREO,
CH_LAYOUT_2_1,
CH_LAYOUT_SURROUND,
CH_LAYOUT_2_2,
CH_LAYOUT_QUAD,
CH_LAYOUT_4POINT0,
CH_LAYOUT_5POINT0,
CH_LAYOUT_5POINT0_BACK,
(CH_LAYOUT_MONO | CH_LOW_FREQUENCY),
(CH_LAYOUT_STEREO | CH_LOW_FREQUENCY),
(CH_LAYOUT_2_1 | CH_LOW_FREQUENCY),
(CH_LAYOUT_SURROUND | CH_LOW_FREQUENCY),
(CH_LAYOUT_2_2 | CH_LOW_FREQUENCY),
(CH_LAYOUT_QUAD | CH_LOW_FREQUENCY),
(CH_LAYOUT_4POINT0 | CH_LOW_FREQUENCY),
CH_LAYOUT_5POINT1,
CH_LAYOUT_5POINT1_BACK,
0 },
};
| 123linslouis-android-video-cutter | jni/libavcodec/ac3enc.c | C | asf20 | 42,466 |
/*
* Intel Indeo 2 codec
* copyright (c) 2005 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_INDEO2DATA_H
#define AVCODEC_INDEO2DATA_H
#include <stdint.h>
#define IR2_CODES 143
static const uint16_t ir2_codes[IR2_CODES][2] = {
#ifdef ALT_BITSTREAM_READER_LE
{0x0000, 3}, {0x0004, 3}, {0x0006, 3}, {0x0001, 5},
{0x0009, 5}, {0x0019, 5}, {0x000D, 5}, {0x001D, 5},
{0x0023, 6}, {0x0013, 6}, {0x0033, 6}, {0x000B, 6},
{0x002B, 6}, {0x001B, 6}, {0x0007, 8}, {0x0087, 8},
{0x0027, 8}, {0x00A7, 8}, {0x0067, 8}, {0x00E7, 8},
{0x0097, 8}, {0x0057, 8}, {0x0037, 8}, {0x00B7, 8},
{0x00F7, 8}, {0x000F, 9}, {0x008F, 9}, {0x018F, 9},
{0x014F, 9}, {0x00CF, 9}, {0x002F, 9}, {0x012F, 9},
{0x01AF, 9}, {0x006F, 9}, {0x00EF, 9}, {0x01EF, 9},
{0x001F, 10}, {0x021F, 10}, {0x011F, 10}, {0x031F, 10},
{0x009F, 10}, {0x029F, 10}, {0x019F, 10}, {0x039F, 10},
{0x005F, 10}, {0x025F, 10}, {0x015F, 10}, {0x035F, 10},
{0x00DF, 10}, {0x02DF, 10}, {0x01DF, 10}, {0x03DF, 10},
{0x003F, 13}, {0x103F, 13}, {0x083F, 13}, {0x183F, 13},
{0x043F, 13}, {0x143F, 13}, {0x0C3F, 13}, {0x1C3F, 13},
{0x023F, 13}, {0x123F, 13}, {0x0A3F, 13}, {0x1A3F, 13},
{0x063F, 13}, {0x163F, 13}, {0x0E3F, 13}, {0x1E3F, 13},
{0x013F, 13}, {0x113F, 13}, {0x093F, 13}, {0x193F, 13},
{0x053F, 13}, {0x153F, 13}, {0x0D3F, 13}, {0x1D3F, 13},
{0x033F, 13}, {0x133F, 13}, {0x0B3F, 13}, {0x1B3F, 13},
{0x073F, 13}, {0x173F, 13}, {0x0F3F, 13}, {0x1F3F, 13},
{0x00BF, 13}, {0x10BF, 13}, {0x08BF, 13}, {0x18BF, 13},
{0x04BF, 13}, {0x14BF, 13}, {0x0CBF, 13}, {0x1CBF, 13},
{0x02BF, 13}, {0x12BF, 13}, {0x0ABF, 13}, {0x1ABF, 13},
{0x06BF, 13}, {0x16BF, 13}, {0x0EBF, 13}, {0x1EBF, 13},
{0x01BF, 13}, {0x11BF, 13}, {0x09BF, 13}, {0x19BF, 13},
{0x05BF, 13}, {0x15BF, 13}, {0x0DBF, 13}, {0x1DBF, 13},
{0x03BF, 13}, {0x13BF, 13}, {0x0BBF, 13}, {0x1BBF, 13},
{0x07BF, 13}, {0x17BF, 13}, {0x0FBF, 13}, {0x1FBF, 13},
{0x007F, 14}, {0x207F, 14}, {0x107F, 14}, {0x307F, 14},
{0x087F, 14}, {0x287F, 14}, {0x187F, 14}, {0x387F, 14},
{0x047F, 14}, {0x247F, 14}, {0x147F, 14}, {0x0002, 3},
{0x0011, 5}, {0x0005, 5}, {0x0015, 5}, {0x0003, 6},
{0x003B, 6}, {0x0047, 8}, {0x00C7, 8}, {0x0017, 8},
{0x00D7, 8}, {0x0077, 8}, {0x010F, 9}, {0x004F, 9},
{0x01CF, 9}, {0x00AF, 9}, {0x016F, 9},
#else
{0x0000, 3}, {0x0001, 3}, {0x0003, 3}, {0x0010, 5},
{0x0012, 5}, {0x0013, 5}, {0x0016, 5}, {0x0017, 5},
{0x0031, 6}, {0x0032, 6}, {0x0033, 6}, {0x0034, 6},
{0x0035, 6}, {0x0036, 6}, {0x00E0, 8}, {0x00E1, 8},
{0x00E4, 8}, {0x00E5, 8}, {0x00E6, 8}, {0x00E7, 8},
{0x00E9, 8}, {0x00EA, 8}, {0x00EC, 8}, {0x00ED, 8},
{0x00EF, 8}, {0x01E0, 9}, {0x01E2, 9}, {0x01E3, 9},
{0x01E5, 9}, {0x01E6, 9}, {0x01E8, 9}, {0x01E9, 9},
{0x01EB, 9}, {0x01EC, 9}, {0x01EE, 9}, {0x01EF, 9},
{0x03E0, 10}, {0x03E1, 10}, {0x03E2, 10}, {0x03E3, 10},
{0x03E4, 10}, {0x03E5, 10}, {0x03E6, 10}, {0x03E7, 10},
{0x03E8, 10}, {0x03E9, 10}, {0x03EA, 10}, {0x03EB, 10},
{0x03EC, 10}, {0x03ED, 10}, {0x03EE, 10}, {0x03EF, 10},
{0x1F80, 13}, {0x1F81, 13}, {0x1F82, 13}, {0x1F83, 13},
{0x1F84, 13}, {0x1F85, 13}, {0x1F86, 13}, {0x1F87, 13},
{0x1F88, 13}, {0x1F89, 13}, {0x1F8A, 13}, {0x1F8B, 13},
{0x1F8C, 13}, {0x1F8D, 13}, {0x1F8E, 13}, {0x1F8F, 13},
{0x1F90, 13}, {0x1F91, 13}, {0x1F92, 13}, {0x1F93, 13},
{0x1F94, 13}, {0x1F95, 13}, {0x1F96, 13}, {0x1F97, 13},
{0x1F98, 13}, {0x1F99, 13}, {0x1F9A, 13}, {0x1F9B, 13},
{0x1F9C, 13}, {0x1F9D, 13}, {0x1F9E, 13}, {0x1F9F, 13},
{0x1FA0, 13}, {0x1FA1, 13}, {0x1FA2, 13}, {0x1FA3, 13},
{0x1FA4, 13}, {0x1FA5, 13}, {0x1FA6, 13}, {0x1FA7, 13},
{0x1FA8, 13}, {0x1FA9, 13}, {0x1FAA, 13}, {0x1FAB, 13},
{0x1FAC, 13}, {0x1FAD, 13}, {0x1FAE, 13}, {0x1FAF, 13},
{0x1FB0, 13}, {0x1FB1, 13}, {0x1FB2, 13}, {0x1FB3, 13},
{0x1FB4, 13}, {0x1FB5, 13}, {0x1FB6, 13}, {0x1FB7, 13},
{0x1FB8, 13}, {0x1FB9, 13}, {0x1FBA, 13}, {0x1FBB, 13},
{0x1FBC, 13}, {0x1FBD, 13}, {0x1FBE, 13}, {0x1FBF, 13},
{0x3F80, 14}, {0x3F81, 14}, {0x3F82, 14}, {0x3F83, 14},
{0x3F84, 14}, {0x3F85, 14}, {0x3F86, 14}, {0x3F87, 14},
{0x3F88, 14}, {0x3F89, 14}, {0x3F8A, 14}, {0x0002, 3},
{0x0011, 5}, {0x0014, 5}, {0x0015, 5}, {0x0030, 6},
{0x0037, 6}, {0x00E2, 8}, {0x00E3, 8}, {0x00E8, 8},
{0x00EB, 8}, {0x00EE, 8}, {0x01E1, 9}, {0x01E4, 9},
{0x01E7, 9}, {0x01EA, 9}, {0x01ED, 9}
#endif
};
static const uint8_t ir2_luma_table[256] = {
0x80, 0x80, 0x84, 0x84, 0x7C, 0x7C, 0x7F, 0x85,
0x81, 0x7B, 0x85, 0x7F, 0x7B, 0x81, 0x8C, 0x8C,
0x74, 0x74, 0x83, 0x8D, 0x7D, 0x73, 0x8D, 0x83,
0x73, 0x7D, 0x77, 0x89, 0x89, 0x77, 0x89, 0x77,
0x77, 0x89, 0x8C, 0x95, 0x74, 0x6B, 0x95, 0x8C,
0x6B, 0x74, 0x7C, 0x90, 0x84, 0x70, 0x90, 0x7C,
0x70, 0x84, 0x96, 0x96, 0x6A, 0x6A, 0x82, 0x98,
0x7E, 0x68, 0x98, 0x82, 0x68, 0x7E, 0x97, 0xA2,
0x69, 0x5E, 0xA2, 0x97, 0x5E, 0x69, 0xA2, 0xA2,
0x5E, 0x5E, 0x8B, 0xA3, 0x75, 0x5D, 0xA3, 0x8B,
0x5D, 0x75, 0x71, 0x95, 0x8F, 0x6B, 0x95, 0x71,
0x6B, 0x8F, 0x78, 0x9D, 0x88, 0x63, 0x9D, 0x78,
0x63, 0x88, 0x7F, 0xA7, 0x81, 0x59, 0xA7, 0x7F,
0x59, 0x81, 0xA4, 0xB1, 0x5C, 0x4F, 0xB1, 0xA4,
0x4F, 0x5C, 0x96, 0xB1, 0x6A, 0x4F, 0xB1, 0x96,
0x4F, 0x6A, 0xB2, 0xB2, 0x4E, 0x4E, 0x65, 0x9B,
0x9B, 0x65, 0x9B, 0x65, 0x65, 0x9B, 0x89, 0xB4,
0x77, 0x4C, 0xB4, 0x89, 0x4C, 0x77, 0x6A, 0xA3,
0x96, 0x5D, 0xA3, 0x6A, 0x5D, 0x96, 0x73, 0xAC,
0x8D, 0x54, 0xAC, 0x73, 0x54, 0x8D, 0xB4, 0xC3,
0x4C, 0x3D, 0xC3, 0xB4, 0x3D, 0x4C, 0xA4, 0xC3,
0x5C, 0x3D, 0xC3, 0xA4, 0x3D, 0x5C, 0xC4, 0xC4,
0x3C, 0x3C, 0x96, 0xC6, 0x6A, 0x3A, 0xC6, 0x96,
0x3A, 0x6A, 0x7C, 0xBA, 0x84, 0x46, 0xBA, 0x7C,
0x46, 0x84, 0x5B, 0xAB, 0xA5, 0x55, 0xAB, 0x5B,
0x55, 0xA5, 0x63, 0xB4, 0x9D, 0x4C, 0xB4, 0x63,
0x4C, 0x9D, 0x86, 0xCA, 0x7A, 0x36, 0xCA, 0x86,
0x36, 0x7A, 0xB6, 0xD7, 0x4A, 0x29, 0xD7, 0xB6,
0x29, 0x4A, 0xC8, 0xD7, 0x38, 0x29, 0xD7, 0xC8,
0x29, 0x38, 0xA4, 0xD8, 0x5C, 0x28, 0xD8, 0xA4,
0x28, 0x5C, 0x6C, 0xC1, 0x94, 0x3F, 0xC1, 0x6C,
0x3F, 0x94, 0xD9, 0xD9, 0x27, 0x27, 0x80, 0x80
};
#endif /* AVCODEC_INDEO2DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/indeo2data.h | C | asf20 | 6,829 |
/*
* Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg
* written, produced, and directed by Alan Smithee
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "avcodec.h"
#include "dsputil.h"
#include "bytestream.h"
#include "indeo3data.h"
typedef struct
{
uint8_t *Ybuf;
uint8_t *Ubuf;
uint8_t *Vbuf;
unsigned short y_w, y_h;
unsigned short uv_w, uv_h;
} YUVBufs;
typedef struct Indeo3DecodeContext {
AVCodecContext *avctx;
int width, height;
AVFrame frame;
uint8_t *buf;
YUVBufs iv_frame[2];
YUVBufs *cur_frame;
YUVBufs *ref_frame;
uint8_t *ModPred;
uint8_t *corrector_type;
} Indeo3DecodeContext;
static const uint8_t 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 const uint8_t corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 };
static av_cold int build_modpred(Indeo3DecodeContext *s)
{
int i, j;
if (!(s->ModPred = av_malloc(8 * 128)))
return AVERROR(ENOMEM);
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));
}
if (!(s->corrector_type = av_malloc(24 * 256)))
return AVERROR(ENOMEM);
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];
}
}
return 0;
}
static av_cold int iv_alloc_frames(Indeo3DecodeContext *s)
{
int luma_width = (s->width + 3) & ~3,
luma_height = (s->height + 3) & ~3,
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,
i;
unsigned int bufsize = luma_pixels * 2 + luma_width * 3 +
(chroma_pixels + chroma_width) * 4;
av_freep(&s->buf);
if(!(s->buf = av_malloc(bufsize)))
return AVERROR(ENOMEM);
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].Ybuf = s->buf + luma_width;
i = luma_pixels + luma_width * 2;
s->iv_frame[1].Ybuf = s->buf + i;
i += (luma_pixels + luma_width);
s->iv_frame[0].Ubuf = s->buf + i;
i += (chroma_pixels + chroma_width);
s->iv_frame[1].Ubuf = s->buf + i;
i += (chroma_pixels + chroma_width);
s->iv_frame[0].Vbuf = s->buf + i;
i += (chroma_pixels + chroma_width);
s->iv_frame[1].Vbuf = s->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;
}
return 0;
}
static av_cold void iv_free_func(Indeo3DecodeContext *s)
{
av_freep(&s->buf);
av_freep(&s->ModPred);
av_freep(&s->corrector_type);
}
struct ustr {
long xpos;
long ypos;
long width;
long height;
long split_flag;
long split_direction;
long usl7;
};
#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,
uint8_t *cur, uint8_t *ref, int width, int height,
const uint8_t *buf1, long cb_offset, const uint8_t *hdr,
const uint8_t *buf2, int min_width_160)
{
uint8_t bit_buf;
unsigned long bit_pos, lv, lv1, lv2;
long *width_tbl, width_tbl_arr[10];
const signed char *ref_vectors;
uint8_t *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];
uint8_t *correction_type_sp[2];
struct ustr 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;
unsigned short res;
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++;
if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
break;
}
memcpy(strip, strip-1, sizeof(*strip));
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++;
if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) {
av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n");
break;
}
memcpy(strip, strip-1, sizeof(*strip));
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 = (const signed char*)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 + cb_offset;
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) + cb_offset;
correction_type_sp[0] = s->corrector_type + (lv << 8);
correction_lp[0] = correction + (lv << 8);
lv = (hdr[j] >> 4) + cb_offset;
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 = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
lp2++;
break;
case 1:
res = ((le2me_16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
((unsigned short *)cur_lp)[0] = le2me_16(res);
res = ((le2me_16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
((unsigned short *)cur_lp)[1] = le2me_16(res);
buf1++;
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]] = le2me_32(((le2me_32(*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] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
lp2++;
break;
case 1:
res = ((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1;
((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
res = ((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1;
((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
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]];
buf1++;
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:
av_log(s->avctx, AV_LOG_ERROR, "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) {
#if HAVE_BIGENDIAN
lv1 = lv1 & 0xFF00FF00;
lv1 = (lv1 >> 8) | lv1;
lv2 = lv2 & 0xFF00FF00;
lv2 = (lv2 >> 8) | lv2;
#else
lv1 = lv1 & 0x00FF00FF;
lv1 = (lv1 << 8) | lv1;
lv2 = lv2 & 0x00FF00FF;
lv2 = (lv2 << 8) | lv2;
#endif
}
switch(correction_type_sp[lp2 & 0x01][k]) {
case 0:
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(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]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(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];
}
buf1++;
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:
av_log(s->avctx, AV_LOG_ERROR, "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] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(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] = le2me_32(((le2me_32(ref_lp[0]) >> 1) + lv1) << 1);
cur_lp[1] = le2me_32(((le2me_32(ref_lp[1]) >> 1) + lv2) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1);
cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(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:
av_log(s->avctx, AV_LOG_ERROR, "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] = le2me_32(((le2me_32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1);
cur_lp[width_tbl[1]] = le2me_32(((le2me_32(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]);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1);
((unsigned short *)cur_lp)[0] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1);
((unsigned short *)cur_lp)[1] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1);
((unsigned short *)cur_lp)[width_tbl[2]] = le2me_16(res);
res = (unsigned short)(((le2me_16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1);
((unsigned short *)cur_lp)[width_tbl[2]+1] = le2me_16(res);
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:
av_log(s->avctx, AV_LOG_ERROR, "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;
}
}
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 av_cold int indeo3_decode_init(AVCodecContext *avctx)
{
Indeo3DecodeContext *s = avctx->priv_data;
int ret = 0;
s->avctx = avctx;
s->width = avctx->width;
s->height = avctx->height;
avctx->pix_fmt = PIX_FMT_YUV410P;
if (!(ret = build_modpred(s)))
ret = iv_alloc_frames(s);
if (ret)
iv_free_func(s);
return ret;
}
static int iv_decode_frame(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
Indeo3DecodeContext *s = avctx->priv_data;
unsigned int image_width, image_height,
chroma_width, chroma_height;
unsigned long flags, cb_offset, data_size,
y_offset, v_offset, u_offset, mc_vector_count;
const uint8_t *hdr_pos, *buf_pos;
buf_pos = buf;
buf_pos += 18; /* skip OS header (16 bytes) and version number */
flags = bytestream_get_le16(&buf_pos);
data_size = bytestream_get_le32(&buf_pos);
cb_offset = *buf_pos++;
buf_pos += 3; /* skip reserved byte and checksum */
image_height = bytestream_get_le16(&buf_pos);
image_width = bytestream_get_le16(&buf_pos);
if(avcodec_check_dimensions(avctx, image_width, image_height))
return -1;
if (image_width != avctx->width || image_height != avctx->height) {
int ret;
avcodec_set_dimensions(avctx, image_width, image_height);
s->width = avctx->width;
s->height = avctx->height;
ret = iv_alloc_frames(s);
if (ret < 0) {
s->width = s->height = 0;
return ret;
}
}
chroma_height = ((image_height >> 2) + 3) & 0x7ffc;
chroma_width = ((image_width >> 2) + 3) & 0x7ffc;
y_offset = bytestream_get_le32(&buf_pos);
v_offset = bytestream_get_le32(&buf_pos);
u_offset = bytestream_get_le32(&buf_pos);
buf_pos += 4; /* reserved */
hdr_pos = buf_pos;
if(data_size == 0x80) return 4;
if(FFMAX3(y_offset, v_offset, u_offset) >= buf_size-16) {
av_log(s->avctx, AV_LOG_ERROR, "y/u/v offset outside buffer\n");
return -1;
}
if(flags & 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 + y_offset;
mc_vector_count = bytestream_get_le32(&buf_pos);
if(2LL*mc_vector_count >= buf_size-16-y_offset) {
av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
return -1;
}
iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, image_width,
image_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
FFMIN(image_width, 160));
if (!(s->avctx->flags & CODEC_FLAG_GRAY))
{
buf_pos = buf + 16 + v_offset;
mc_vector_count = bytestream_get_le32(&buf_pos);
if(2LL*mc_vector_count >= buf_size-16-v_offset) {
av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
return -1;
}
iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width,
chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
FFMIN(chroma_width, 40));
buf_pos = buf + 16 + u_offset;
mc_vector_count = bytestream_get_le32(&buf_pos);
if(2LL*mc_vector_count >= buf_size-16-u_offset) {
av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n");
return -1;
}
iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width,
chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos,
FFMIN(chroma_width, 40));
}
return 8;
}
static int indeo3_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
Indeo3DecodeContext *s=avctx->priv_data;
uint8_t *src, *dest;
int y;
if (iv_decode_frame(avctx, buf, buf_size) < 0)
return -1;
if(s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
s->frame.reference = 0;
if(avctx->get_buffer(avctx, &s->frame) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "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];
}
if (!(s->avctx->flags & CODEC_FLAG_GRAY))
{
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 av_cold int indeo3_decode_end(AVCodecContext *avctx)
{
Indeo3DecodeContext *s = avctx->priv_data;
iv_free_func(s);
return 0;
}
AVCodec indeo3_decoder = {
"indeo3",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_INDEO3,
sizeof(Indeo3DecodeContext),
indeo3_decode_init,
NULL,
indeo3_decode_end,
indeo3_decode_frame,
CODEC_CAP_DR1,
NULL,
.long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/indeo3.c | C | asf20 | 48,559 |
/**
* FLAC audio encoder
* Copyright (c) 2006 Justin Ruggles <justin.ruggles@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/crc.h"
#include "libavutil/md5.h"
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#include "golomb.h"
#include "lpc.h"
#include "flac.h"
#include "flacdata.h"
#define FLAC_SUBFRAME_CONSTANT 0
#define FLAC_SUBFRAME_VERBATIM 1
#define FLAC_SUBFRAME_FIXED 8
#define FLAC_SUBFRAME_LPC 32
#define MAX_FIXED_ORDER 4
#define MAX_PARTITION_ORDER 8
#define MAX_PARTITIONS (1 << MAX_PARTITION_ORDER)
#define MAX_LPC_PRECISION 15
#define MAX_LPC_SHIFT 15
#define MAX_RICE_PARAM 14
typedef struct CompressionOptions {
int compression_level;
int block_time_ms;
int use_lpc;
int lpc_coeff_precision;
int min_prediction_order;
int max_prediction_order;
int prediction_order_method;
int min_partition_order;
int max_partition_order;
} CompressionOptions;
typedef struct RiceContext {
int porder;
int params[MAX_PARTITIONS];
} RiceContext;
typedef struct FlacSubframe {
int type;
int type_code;
int obits;
int order;
int32_t coefs[MAX_LPC_ORDER];
int shift;
RiceContext rc;
int32_t samples[FLAC_MAX_BLOCKSIZE];
int32_t residual[FLAC_MAX_BLOCKSIZE+1];
} FlacSubframe;
typedef struct FlacFrame {
FlacSubframe subframes[FLAC_MAX_CHANNELS];
int blocksize;
int bs_code[2];
uint8_t crc8;
int ch_mode;
} FlacFrame;
typedef struct FlacEncodeContext {
PutBitContext pb;
int channels;
int samplerate;
int sr_code[2];
int max_blocksize;
int min_framesize;
int max_framesize;
int max_encoded_framesize;
uint32_t frame_count;
uint64_t sample_count;
uint8_t md5sum[16];
FlacFrame frame;
CompressionOptions options;
AVCodecContext *avctx;
DSPContext dsp;
struct AVMD5 *md5ctx;
} FlacEncodeContext;
/**
* Writes streaminfo metadata block to byte array
*/
static void write_streaminfo(FlacEncodeContext *s, uint8_t *header)
{
PutBitContext pb;
memset(header, 0, FLAC_STREAMINFO_SIZE);
init_put_bits(&pb, header, FLAC_STREAMINFO_SIZE);
/* streaminfo metadata block */
put_bits(&pb, 16, s->max_blocksize);
put_bits(&pb, 16, s->max_blocksize);
put_bits(&pb, 24, s->min_framesize);
put_bits(&pb, 24, s->max_framesize);
put_bits(&pb, 20, s->samplerate);
put_bits(&pb, 3, s->channels-1);
put_bits(&pb, 5, 15); /* bits per sample - 1 */
/* write 36-bit sample count in 2 put_bits() calls */
put_bits(&pb, 24, (s->sample_count & 0xFFFFFF000LL) >> 12);
put_bits(&pb, 12, s->sample_count & 0x000000FFFLL);
flush_put_bits(&pb);
memcpy(&header[18], s->md5sum, 16);
}
/**
* Sets blocksize based on samplerate
* Chooses the closest predefined blocksize >= BLOCK_TIME_MS milliseconds
*/
static int select_blocksize(int samplerate, int block_time_ms)
{
int i;
int target;
int blocksize;
assert(samplerate > 0);
blocksize = ff_flac_blocksize_table[1];
target = (samplerate * block_time_ms) / 1000;
for(i=0; i<16; i++) {
if(target >= ff_flac_blocksize_table[i] && ff_flac_blocksize_table[i] > blocksize) {
blocksize = ff_flac_blocksize_table[i];
}
}
return blocksize;
}
static av_cold int flac_encode_init(AVCodecContext *avctx)
{
int freq = avctx->sample_rate;
int channels = avctx->channels;
FlacEncodeContext *s = avctx->priv_data;
int i, level;
uint8_t *streaminfo;
s->avctx = avctx;
dsputil_init(&s->dsp, avctx);
if(avctx->sample_fmt != SAMPLE_FMT_S16) {
return -1;
}
if(channels < 1 || channels > FLAC_MAX_CHANNELS) {
return -1;
}
s->channels = channels;
/* find samplerate in table */
if(freq < 1)
return -1;
for(i=4; i<12; i++) {
if(freq == ff_flac_sample_rate_table[i]) {
s->samplerate = ff_flac_sample_rate_table[i];
s->sr_code[0] = i;
s->sr_code[1] = 0;
break;
}
}
/* if not in table, samplerate is non-standard */
if(i == 12) {
if(freq % 1000 == 0 && freq < 255000) {
s->sr_code[0] = 12;
s->sr_code[1] = freq / 1000;
} else if(freq % 10 == 0 && freq < 655350) {
s->sr_code[0] = 14;
s->sr_code[1] = freq / 10;
} else if(freq < 65535) {
s->sr_code[0] = 13;
s->sr_code[1] = freq;
} else {
return -1;
}
s->samplerate = freq;
}
/* set compression option defaults based on avctx->compression_level */
if(avctx->compression_level < 0) {
s->options.compression_level = 5;
} else {
s->options.compression_level = avctx->compression_level;
}
av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", s->options.compression_level);
level= s->options.compression_level;
if(level > 12) {
av_log(avctx, AV_LOG_ERROR, "invalid compression level: %d\n",
s->options.compression_level);
return -1;
}
s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level];
s->options.use_lpc = ((int[]){ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
s->options.min_prediction_order= ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level];
s->options.max_prediction_order= ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level];
s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST,
ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST,
ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL,
ORDER_METHOD_LOG, ORDER_METHOD_SEARCH, ORDER_METHOD_LOG,
ORDER_METHOD_SEARCH})[level];
s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level];
s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level];
/* set compression option overrides from AVCodecContext */
if(avctx->use_lpc >= 0) {
s->options.use_lpc = av_clip(avctx->use_lpc, 0, 11);
}
if(s->options.use_lpc == 1)
av_log(avctx, AV_LOG_DEBUG, " use lpc: Levinson-Durbin recursion with Welch window\n");
else if(s->options.use_lpc > 1)
av_log(avctx, AV_LOG_DEBUG, " use lpc: Cholesky factorization\n");
if(avctx->min_prediction_order >= 0) {
if(s->options.use_lpc) {
if(avctx->min_prediction_order < MIN_LPC_ORDER ||
avctx->min_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order);
return -1;
}
} else {
if(avctx->min_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n",
avctx->min_prediction_order);
return -1;
}
}
s->options.min_prediction_order = avctx->min_prediction_order;
}
if(avctx->max_prediction_order >= 0) {
if(s->options.use_lpc) {
if(avctx->max_prediction_order < MIN_LPC_ORDER ||
avctx->max_prediction_order > MAX_LPC_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order);
return -1;
}
} else {
if(avctx->max_prediction_order > MAX_FIXED_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n",
avctx->max_prediction_order);
return -1;
}
}
s->options.max_prediction_order = avctx->max_prediction_order;
}
if(s->options.max_prediction_order < s->options.min_prediction_order) {
av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n",
s->options.min_prediction_order, s->options.max_prediction_order);
return -1;
}
av_log(avctx, AV_LOG_DEBUG, " prediction order: %d, %d\n",
s->options.min_prediction_order, s->options.max_prediction_order);
if(avctx->prediction_order_method >= 0) {
if(avctx->prediction_order_method > ORDER_METHOD_LOG) {
av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n",
avctx->prediction_order_method);
return -1;
}
s->options.prediction_order_method = avctx->prediction_order_method;
}
switch(s->options.prediction_order_method) {
case ORDER_METHOD_EST: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"estimate"); break;
case ORDER_METHOD_2LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"2-level"); break;
case ORDER_METHOD_4LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"4-level"); break;
case ORDER_METHOD_8LEVEL: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"8-level"); break;
case ORDER_METHOD_SEARCH: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"full search"); break;
case ORDER_METHOD_LOG: av_log(avctx, AV_LOG_DEBUG, " order method: %s\n",
"log search"); break;
}
if(avctx->min_partition_order >= 0) {
if(avctx->min_partition_order > MAX_PARTITION_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid min partition order: %d\n",
avctx->min_partition_order);
return -1;
}
s->options.min_partition_order = avctx->min_partition_order;
}
if(avctx->max_partition_order >= 0) {
if(avctx->max_partition_order > MAX_PARTITION_ORDER) {
av_log(avctx, AV_LOG_ERROR, "invalid max partition order: %d\n",
avctx->max_partition_order);
return -1;
}
s->options.max_partition_order = avctx->max_partition_order;
}
if(s->options.max_partition_order < s->options.min_partition_order) {
av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n",
s->options.min_partition_order, s->options.max_partition_order);
return -1;
}
av_log(avctx, AV_LOG_DEBUG, " partition order: %d, %d\n",
s->options.min_partition_order, s->options.max_partition_order);
if(avctx->frame_size > 0) {
if(avctx->frame_size < FLAC_MIN_BLOCKSIZE ||
avctx->frame_size > FLAC_MAX_BLOCKSIZE) {
av_log(avctx, AV_LOG_ERROR, "invalid block size: %d\n",
avctx->frame_size);
return -1;
}
} else {
s->avctx->frame_size = select_blocksize(s->samplerate, s->options.block_time_ms);
}
s->max_blocksize = s->avctx->frame_size;
av_log(avctx, AV_LOG_DEBUG, " block size: %d\n", s->avctx->frame_size);
/* set LPC precision */
if(avctx->lpc_coeff_precision > 0) {
if(avctx->lpc_coeff_precision > MAX_LPC_PRECISION) {
av_log(avctx, AV_LOG_ERROR, "invalid lpc coeff precision: %d\n",
avctx->lpc_coeff_precision);
return -1;
}
s->options.lpc_coeff_precision = avctx->lpc_coeff_precision;
} else {
/* default LPC precision */
s->options.lpc_coeff_precision = 15;
}
av_log(avctx, AV_LOG_DEBUG, " lpc precision: %d\n",
s->options.lpc_coeff_precision);
/* set maximum encoded frame size in verbatim mode */
s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size,
s->channels, 16);
/* initialize MD5 context */
s->md5ctx = av_malloc(av_md5_size);
if(!s->md5ctx)
return AVERROR(ENOMEM);
av_md5_init(s->md5ctx);
streaminfo = av_malloc(FLAC_STREAMINFO_SIZE);
write_streaminfo(s, streaminfo);
avctx->extradata = streaminfo;
avctx->extradata_size = FLAC_STREAMINFO_SIZE;
s->frame_count = 0;
s->min_framesize = s->max_framesize;
avctx->coded_frame = avcodec_alloc_frame();
avctx->coded_frame->key_frame = 1;
return 0;
}
static void init_frame(FlacEncodeContext *s)
{
int i, ch;
FlacFrame *frame;
frame = &s->frame;
for(i=0; i<16; i++) {
if(s->avctx->frame_size == ff_flac_blocksize_table[i]) {
frame->blocksize = ff_flac_blocksize_table[i];
frame->bs_code[0] = i;
frame->bs_code[1] = 0;
break;
}
}
if(i == 16) {
frame->blocksize = s->avctx->frame_size;
if(frame->blocksize <= 256) {
frame->bs_code[0] = 6;
frame->bs_code[1] = frame->blocksize-1;
} else {
frame->bs_code[0] = 7;
frame->bs_code[1] = frame->blocksize-1;
}
}
for(ch=0; ch<s->channels; ch++) {
frame->subframes[ch].obits = 16;
}
}
/**
* Copy channel-interleaved input samples into separate subframes
*/
static void copy_samples(FlacEncodeContext *s, int16_t *samples)
{
int i, j, ch;
FlacFrame *frame;
frame = &s->frame;
for(i=0,j=0; i<frame->blocksize; i++) {
for(ch=0; ch<s->channels; ch++,j++) {
frame->subframes[ch].samples[i] = samples[j];
}
}
}
#define rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k)))
/**
* Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0
*/
static int find_optimal_param(uint32_t sum, int n)
{
int k;
uint32_t sum2;
if(sum <= n>>1)
return 0;
sum2 = sum-(n>>1);
k = av_log2(n<256 ? FASTDIV(sum2,n) : sum2/n);
return FFMIN(k, MAX_RICE_PARAM);
}
static uint32_t calc_optimal_rice_params(RiceContext *rc, int porder,
uint32_t *sums, int n, int pred_order)
{
int i;
int k, cnt, part;
uint32_t all_bits;
part = (1 << porder);
all_bits = 4 * part;
cnt = (n >> porder) - pred_order;
for(i=0; i<part; i++) {
k = find_optimal_param(sums[i], cnt);
rc->params[i] = k;
all_bits += rice_encode_count(sums[i], cnt, k);
cnt = n >> porder;
}
rc->porder = porder;
return all_bits;
}
static void calc_sums(int pmin, int pmax, uint32_t *data, int n, int pred_order,
uint32_t sums[][MAX_PARTITIONS])
{
int i, j;
int parts;
uint32_t *res, *res_end;
/* sums for highest level */
parts = (1 << pmax);
res = &data[pred_order];
res_end = &data[n >> pmax];
for(i=0; i<parts; i++) {
uint32_t sum = 0;
while(res < res_end){
sum += *(res++);
}
sums[pmax][i] = sum;
res_end+= n >> pmax;
}
/* sums for lower levels */
for(i=pmax-1; i>=pmin; i--) {
parts = (1 << i);
for(j=0; j<parts; j++) {
sums[i][j] = sums[i+1][2*j] + sums[i+1][2*j+1];
}
}
}
static uint32_t calc_rice_params(RiceContext *rc, int pmin, int pmax,
int32_t *data, int n, int pred_order)
{
int i;
uint32_t bits[MAX_PARTITION_ORDER+1];
int opt_porder;
RiceContext tmp_rc;
uint32_t *udata;
uint32_t sums[MAX_PARTITION_ORDER+1][MAX_PARTITIONS];
assert(pmin >= 0 && pmin <= MAX_PARTITION_ORDER);
assert(pmax >= 0 && pmax <= MAX_PARTITION_ORDER);
assert(pmin <= pmax);
udata = av_malloc(n * sizeof(uint32_t));
for(i=0; i<n; i++) {
udata[i] = (2*data[i]) ^ (data[i]>>31);
}
calc_sums(pmin, pmax, udata, n, pred_order, sums);
opt_porder = pmin;
bits[pmin] = UINT32_MAX;
for(i=pmin; i<=pmax; i++) {
bits[i] = calc_optimal_rice_params(&tmp_rc, i, sums[i], n, pred_order);
if(bits[i] <= bits[opt_porder]) {
opt_porder = i;
*rc= tmp_rc;
}
}
av_freep(&udata);
return bits[opt_porder];
}
static int get_max_p_order(int max_porder, int n, int order)
{
int porder = FFMIN(max_porder, av_log2(n^(n-1)));
if(order > 0)
porder = FFMIN(porder, av_log2(n/order));
return porder;
}
static uint32_t calc_rice_params_fixed(RiceContext *rc, int pmin, int pmax,
int32_t *data, int n, int pred_order,
int bps)
{
uint32_t bits;
pmin = get_max_p_order(pmin, n, pred_order);
pmax = get_max_p_order(pmax, n, pred_order);
bits = pred_order*bps + 6;
bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
return bits;
}
static uint32_t calc_rice_params_lpc(RiceContext *rc, int pmin, int pmax,
int32_t *data, int n, int pred_order,
int bps, int precision)
{
uint32_t bits;
pmin = get_max_p_order(pmin, n, pred_order);
pmax = get_max_p_order(pmax, n, pred_order);
bits = pred_order*bps + 4 + 5 + pred_order*precision + 6;
bits += calc_rice_params(rc, pmin, pmax, data, n, pred_order);
return bits;
}
static void encode_residual_verbatim(int32_t *res, int32_t *smp, int n)
{
assert(n > 0);
memcpy(res, smp, n * sizeof(int32_t));
}
static void encode_residual_fixed(int32_t *res, const int32_t *smp, int n,
int order)
{
int i;
for(i=0; i<order; i++) {
res[i] = smp[i];
}
if(order==0){
for(i=order; i<n; i++)
res[i]= smp[i];
}else if(order==1){
for(i=order; i<n; i++)
res[i]= smp[i] - smp[i-1];
}else if(order==2){
int a = smp[order-1] - smp[order-2];
for(i=order; i<n; i+=2) {
int b = smp[i] - smp[i-1];
res[i]= b - a;
a = smp[i+1] - smp[i];
res[i+1]= a - b;
}
}else if(order==3){
int a = smp[order-1] - smp[order-2];
int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
for(i=order; i<n; i+=2) {
int b = smp[i] - smp[i-1];
int d = b - a;
res[i]= d - c;
a = smp[i+1] - smp[i];
c = a - b;
res[i+1]= c - d;
}
}else{
int a = smp[order-1] - smp[order-2];
int c = smp[order-1] - 2*smp[order-2] + smp[order-3];
int e = smp[order-1] - 3*smp[order-2] + 3*smp[order-3] - smp[order-4];
for(i=order; i<n; i+=2) {
int b = smp[i] - smp[i-1];
int d = b - a;
int f = d - c;
res[i]= f - e;
a = smp[i+1] - smp[i];
c = a - b;
e = c - d;
res[i+1]= e - f;
}
}
}
#define LPC1(x) {\
int c = coefs[(x)-1];\
p0 += c*s;\
s = smp[i-(x)+1];\
p1 += c*s;\
}
static av_always_inline void encode_residual_lpc_unrolled(
int32_t *res, const int32_t *smp, int n,
int order, const int32_t *coefs, int shift, int big)
{
int i;
for(i=order; i<n; i+=2) {
int s = smp[i-order];
int p0 = 0, p1 = 0;
if(big) {
switch(order) {
case 32: LPC1(32)
case 31: LPC1(31)
case 30: LPC1(30)
case 29: LPC1(29)
case 28: LPC1(28)
case 27: LPC1(27)
case 26: LPC1(26)
case 25: LPC1(25)
case 24: LPC1(24)
case 23: LPC1(23)
case 22: LPC1(22)
case 21: LPC1(21)
case 20: LPC1(20)
case 19: LPC1(19)
case 18: LPC1(18)
case 17: LPC1(17)
case 16: LPC1(16)
case 15: LPC1(15)
case 14: LPC1(14)
case 13: LPC1(13)
case 12: LPC1(12)
case 11: LPC1(11)
case 10: LPC1(10)
case 9: LPC1( 9)
LPC1( 8)
LPC1( 7)
LPC1( 6)
LPC1( 5)
LPC1( 4)
LPC1( 3)
LPC1( 2)
LPC1( 1)
}
} else {
switch(order) {
case 8: LPC1( 8)
case 7: LPC1( 7)
case 6: LPC1( 6)
case 5: LPC1( 5)
case 4: LPC1( 4)
case 3: LPC1( 3)
case 2: LPC1( 2)
case 1: LPC1( 1)
}
}
res[i ] = smp[i ] - (p0 >> shift);
res[i+1] = smp[i+1] - (p1 >> shift);
}
}
static void encode_residual_lpc(int32_t *res, const int32_t *smp, int n,
int order, const int32_t *coefs, int shift)
{
int i;
for(i=0; i<order; i++) {
res[i] = smp[i];
}
#if CONFIG_SMALL
for(i=order; i<n; i+=2) {
int j;
int s = smp[i];
int p0 = 0, p1 = 0;
for(j=0; j<order; j++) {
int c = coefs[j];
p1 += c*s;
s = smp[i-j-1];
p0 += c*s;
}
res[i ] = smp[i ] - (p0 >> shift);
res[i+1] = smp[i+1] - (p1 >> shift);
}
#else
switch(order) {
case 1: encode_residual_lpc_unrolled(res, smp, n, 1, coefs, shift, 0); break;
case 2: encode_residual_lpc_unrolled(res, smp, n, 2, coefs, shift, 0); break;
case 3: encode_residual_lpc_unrolled(res, smp, n, 3, coefs, shift, 0); break;
case 4: encode_residual_lpc_unrolled(res, smp, n, 4, coefs, shift, 0); break;
case 5: encode_residual_lpc_unrolled(res, smp, n, 5, coefs, shift, 0); break;
case 6: encode_residual_lpc_unrolled(res, smp, n, 6, coefs, shift, 0); break;
case 7: encode_residual_lpc_unrolled(res, smp, n, 7, coefs, shift, 0); break;
case 8: encode_residual_lpc_unrolled(res, smp, n, 8, coefs, shift, 0); break;
default: encode_residual_lpc_unrolled(res, smp, n, order, coefs, shift, 1); break;
}
#endif
}
static int encode_residual(FlacEncodeContext *ctx, int ch)
{
int i, n;
int min_order, max_order, opt_order, precision, omethod;
int min_porder, max_porder;
FlacFrame *frame;
FlacSubframe *sub;
int32_t coefs[MAX_LPC_ORDER][MAX_LPC_ORDER];
int shift[MAX_LPC_ORDER];
int32_t *res, *smp;
frame = &ctx->frame;
sub = &frame->subframes[ch];
res = sub->residual;
smp = sub->samples;
n = frame->blocksize;
/* CONSTANT */
for(i=1; i<n; i++) {
if(smp[i] != smp[0]) break;
}
if(i == n) {
sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT;
res[0] = smp[0];
return sub->obits;
}
/* VERBATIM */
if(n < 5) {
sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
encode_residual_verbatim(res, smp, n);
return sub->obits * n;
}
min_order = ctx->options.min_prediction_order;
max_order = ctx->options.max_prediction_order;
min_porder = ctx->options.min_partition_order;
max_porder = ctx->options.max_partition_order;
precision = ctx->options.lpc_coeff_precision;
omethod = ctx->options.prediction_order_method;
/* FIXED */
if(!ctx->options.use_lpc || max_order == 0 || (n <= max_order)) {
uint32_t bits[MAX_FIXED_ORDER+1];
if(max_order > MAX_FIXED_ORDER) max_order = MAX_FIXED_ORDER;
opt_order = 0;
bits[0] = UINT32_MAX;
for(i=min_order; i<=max_order; i++) {
encode_residual_fixed(res, smp, n, i);
bits[i] = calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res,
n, i, sub->obits);
if(bits[i] < bits[opt_order]) {
opt_order = i;
}
}
sub->order = opt_order;
sub->type = FLAC_SUBFRAME_FIXED;
sub->type_code = sub->type | sub->order;
if(sub->order != max_order) {
encode_residual_fixed(res, smp, n, sub->order);
return calc_rice_params_fixed(&sub->rc, min_porder, max_porder, res, n,
sub->order, sub->obits);
}
return bits[sub->order];
}
/* LPC */
opt_order = ff_lpc_calc_coefs(&ctx->dsp, smp, n, min_order, max_order,
precision, coefs, shift, ctx->options.use_lpc,
omethod, MAX_LPC_SHIFT, 0);
if(omethod == ORDER_METHOD_2LEVEL ||
omethod == ORDER_METHOD_4LEVEL ||
omethod == ORDER_METHOD_8LEVEL) {
int levels = 1 << omethod;
uint32_t bits[levels];
int order;
int opt_index = levels-1;
opt_order = max_order-1;
bits[opt_index] = UINT32_MAX;
for(i=levels-1; i>=0; i--) {
order = min_order + (((max_order-min_order+1) * (i+1)) / levels)-1;
if(order < 0) order = 0;
encode_residual_lpc(res, smp, n, order+1, coefs[order], shift[order]);
bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
res, n, order+1, sub->obits, precision);
if(bits[i] < bits[opt_index]) {
opt_index = i;
opt_order = order;
}
}
opt_order++;
} else if(omethod == ORDER_METHOD_SEARCH) {
// brute-force optimal order search
uint32_t bits[MAX_LPC_ORDER];
opt_order = 0;
bits[0] = UINT32_MAX;
for(i=min_order-1; i<max_order; i++) {
encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
res, n, i+1, sub->obits, precision);
if(bits[i] < bits[opt_order]) {
opt_order = i;
}
}
opt_order++;
} else if(omethod == ORDER_METHOD_LOG) {
uint32_t bits[MAX_LPC_ORDER];
int step;
opt_order= min_order - 1 + (max_order-min_order)/3;
memset(bits, -1, sizeof(bits));
for(step=16 ;step; step>>=1){
int last= opt_order;
for(i=last-step; i<=last+step; i+= step){
if(i<min_order-1 || i>=max_order || bits[i] < UINT32_MAX)
continue;
encode_residual_lpc(res, smp, n, i+1, coefs[i], shift[i]);
bits[i] = calc_rice_params_lpc(&sub->rc, min_porder, max_porder,
res, n, i+1, sub->obits, precision);
if(bits[i] < bits[opt_order])
opt_order= i;
}
}
opt_order++;
}
sub->order = opt_order;
sub->type = FLAC_SUBFRAME_LPC;
sub->type_code = sub->type | (sub->order-1);
sub->shift = shift[sub->order-1];
for(i=0; i<sub->order; i++) {
sub->coefs[i] = coefs[sub->order-1][i];
}
encode_residual_lpc(res, smp, n, sub->order, sub->coefs, sub->shift);
return calc_rice_params_lpc(&sub->rc, min_porder, max_porder, res, n, sub->order,
sub->obits, precision);
}
static int encode_residual_v(FlacEncodeContext *ctx, int ch)
{
int i, n;
FlacFrame *frame;
FlacSubframe *sub;
int32_t *res, *smp;
frame = &ctx->frame;
sub = &frame->subframes[ch];
res = sub->residual;
smp = sub->samples;
n = frame->blocksize;
/* CONSTANT */
for(i=1; i<n; i++) {
if(smp[i] != smp[0]) break;
}
if(i == n) {
sub->type = sub->type_code = FLAC_SUBFRAME_CONSTANT;
res[0] = smp[0];
return sub->obits;
}
/* VERBATIM */
sub->type = sub->type_code = FLAC_SUBFRAME_VERBATIM;
encode_residual_verbatim(res, smp, n);
return sub->obits * n;
}
static int estimate_stereo_mode(int32_t *left_ch, int32_t *right_ch, int n)
{
int i, best;
int32_t lt, rt;
uint64_t sum[4];
uint64_t score[4];
int k;
/* calculate sum of 2nd order residual for each channel */
sum[0] = sum[1] = sum[2] = sum[3] = 0;
for(i=2; i<n; i++) {
lt = left_ch[i] - 2*left_ch[i-1] + left_ch[i-2];
rt = right_ch[i] - 2*right_ch[i-1] + right_ch[i-2];
sum[2] += FFABS((lt + rt) >> 1);
sum[3] += FFABS(lt - rt);
sum[0] += FFABS(lt);
sum[1] += FFABS(rt);
}
/* estimate bit counts */
for(i=0; i<4; i++) {
k = find_optimal_param(2*sum[i], n);
sum[i] = rice_encode_count(2*sum[i], n, k);
}
/* calculate score for each mode */
score[0] = sum[0] + sum[1];
score[1] = sum[0] + sum[3];
score[2] = sum[1] + sum[3];
score[3] = sum[2] + sum[3];
/* return mode with lowest score */
best = 0;
for(i=1; i<4; i++) {
if(score[i] < score[best]) {
best = i;
}
}
if(best == 0) {
return FLAC_CHMODE_INDEPENDENT;
} else if(best == 1) {
return FLAC_CHMODE_LEFT_SIDE;
} else if(best == 2) {
return FLAC_CHMODE_RIGHT_SIDE;
} else {
return FLAC_CHMODE_MID_SIDE;
}
}
/**
* Perform stereo channel decorrelation
*/
static void channel_decorrelation(FlacEncodeContext *ctx)
{
FlacFrame *frame;
int32_t *left, *right;
int i, n;
frame = &ctx->frame;
n = frame->blocksize;
left = frame->subframes[0].samples;
right = frame->subframes[1].samples;
if(ctx->channels != 2) {
frame->ch_mode = FLAC_CHMODE_INDEPENDENT;
return;
}
frame->ch_mode = estimate_stereo_mode(left, right, n);
/* perform decorrelation and adjust bits-per-sample */
if(frame->ch_mode == FLAC_CHMODE_INDEPENDENT) {
return;
}
if(frame->ch_mode == FLAC_CHMODE_MID_SIDE) {
int32_t tmp;
for(i=0; i<n; i++) {
tmp = left[i];
left[i] = (tmp + right[i]) >> 1;
right[i] = tmp - right[i];
}
frame->subframes[1].obits++;
} else if(frame->ch_mode == FLAC_CHMODE_LEFT_SIDE) {
for(i=0; i<n; i++) {
right[i] = left[i] - right[i];
}
frame->subframes[1].obits++;
} else {
for(i=0; i<n; i++) {
left[i] -= right[i];
}
frame->subframes[0].obits++;
}
}
static void write_utf8(PutBitContext *pb, uint32_t val)
{
uint8_t tmp;
PUT_UTF8(val, tmp, put_bits(pb, 8, tmp);)
}
static void output_frame_header(FlacEncodeContext *s)
{
FlacFrame *frame;
int crc;
frame = &s->frame;
put_bits(&s->pb, 16, 0xFFF8);
put_bits(&s->pb, 4, frame->bs_code[0]);
put_bits(&s->pb, 4, s->sr_code[0]);
if(frame->ch_mode == FLAC_CHMODE_INDEPENDENT) {
put_bits(&s->pb, 4, s->channels-1);
} else {
put_bits(&s->pb, 4, frame->ch_mode);
}
put_bits(&s->pb, 3, 4); /* bits-per-sample code */
put_bits(&s->pb, 1, 0);
write_utf8(&s->pb, s->frame_count);
if(frame->bs_code[0] == 6) {
put_bits(&s->pb, 8, frame->bs_code[1]);
} else if(frame->bs_code[0] == 7) {
put_bits(&s->pb, 16, frame->bs_code[1]);
}
if(s->sr_code[0] == 12) {
put_bits(&s->pb, 8, s->sr_code[1]);
} else if(s->sr_code[0] > 12) {
put_bits(&s->pb, 16, s->sr_code[1]);
}
flush_put_bits(&s->pb);
crc = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
s->pb.buf, put_bits_count(&s->pb)>>3);
put_bits(&s->pb, 8, crc);
}
static void output_subframe_constant(FlacEncodeContext *s, int ch)
{
FlacSubframe *sub;
int32_t res;
sub = &s->frame.subframes[ch];
res = sub->residual[0];
put_sbits(&s->pb, sub->obits, res);
}
static void output_subframe_verbatim(FlacEncodeContext *s, int ch)
{
int i;
FlacFrame *frame;
FlacSubframe *sub;
int32_t res;
frame = &s->frame;
sub = &frame->subframes[ch];
for(i=0; i<frame->blocksize; i++) {
res = sub->residual[i];
put_sbits(&s->pb, sub->obits, res);
}
}
static void output_residual(FlacEncodeContext *ctx, int ch)
{
int i, j, p, n, parts;
int k, porder, psize, res_cnt;
FlacFrame *frame;
FlacSubframe *sub;
int32_t *res;
frame = &ctx->frame;
sub = &frame->subframes[ch];
res = sub->residual;
n = frame->blocksize;
/* rice-encoded block */
put_bits(&ctx->pb, 2, 0);
/* partition order */
porder = sub->rc.porder;
psize = n >> porder;
parts = (1 << porder);
put_bits(&ctx->pb, 4, porder);
res_cnt = psize - sub->order;
/* residual */
j = sub->order;
for(p=0; p<parts; p++) {
k = sub->rc.params[p];
put_bits(&ctx->pb, 4, k);
if(p == 1) res_cnt = psize;
for(i=0; i<res_cnt && j<n; i++, j++) {
set_sr_golomb_flac(&ctx->pb, res[j], k, INT32_MAX, 0);
}
}
}
static void output_subframe_fixed(FlacEncodeContext *ctx, int ch)
{
int i;
FlacFrame *frame;
FlacSubframe *sub;
frame = &ctx->frame;
sub = &frame->subframes[ch];
/* warm-up samples */
for(i=0; i<sub->order; i++) {
put_sbits(&ctx->pb, sub->obits, sub->residual[i]);
}
/* residual */
output_residual(ctx, ch);
}
static void output_subframe_lpc(FlacEncodeContext *ctx, int ch)
{
int i, cbits;
FlacFrame *frame;
FlacSubframe *sub;
frame = &ctx->frame;
sub = &frame->subframes[ch];
/* warm-up samples */
for(i=0; i<sub->order; i++) {
put_sbits(&ctx->pb, sub->obits, sub->residual[i]);
}
/* LPC coefficients */
cbits = ctx->options.lpc_coeff_precision;
put_bits(&ctx->pb, 4, cbits-1);
put_sbits(&ctx->pb, 5, sub->shift);
for(i=0; i<sub->order; i++) {
put_sbits(&ctx->pb, cbits, sub->coefs[i]);
}
/* residual */
output_residual(ctx, ch);
}
static void output_subframes(FlacEncodeContext *s)
{
FlacFrame *frame;
FlacSubframe *sub;
int ch;
frame = &s->frame;
for(ch=0; ch<s->channels; ch++) {
sub = &frame->subframes[ch];
/* subframe header */
put_bits(&s->pb, 1, 0);
put_bits(&s->pb, 6, sub->type_code);
put_bits(&s->pb, 1, 0); /* no wasted bits */
/* subframe */
if(sub->type == FLAC_SUBFRAME_CONSTANT) {
output_subframe_constant(s, ch);
} else if(sub->type == FLAC_SUBFRAME_VERBATIM) {
output_subframe_verbatim(s, ch);
} else if(sub->type == FLAC_SUBFRAME_FIXED) {
output_subframe_fixed(s, ch);
} else if(sub->type == FLAC_SUBFRAME_LPC) {
output_subframe_lpc(s, ch);
}
}
}
static void output_frame_footer(FlacEncodeContext *s)
{
int crc;
flush_put_bits(&s->pb);
crc = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
s->pb.buf, put_bits_count(&s->pb)>>3));
put_bits(&s->pb, 16, crc);
flush_put_bits(&s->pb);
}
static void update_md5_sum(FlacEncodeContext *s, int16_t *samples)
{
#if HAVE_BIGENDIAN
int i;
for(i = 0; i < s->frame.blocksize*s->channels; i++) {
int16_t smp = le2me_16(samples[i]);
av_md5_update(s->md5ctx, (uint8_t *)&smp, 2);
}
#else
av_md5_update(s->md5ctx, (uint8_t *)samples, s->frame.blocksize*s->channels*2);
#endif
}
static int flac_encode_frame(AVCodecContext *avctx, uint8_t *frame,
int buf_size, void *data)
{
int ch;
FlacEncodeContext *s;
int16_t *samples = data;
int out_bytes;
int reencoded=0;
s = avctx->priv_data;
if(buf_size < s->max_framesize*2) {
av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
return 0;
}
/* when the last block is reached, update the header in extradata */
if (!data) {
s->max_framesize = s->max_encoded_framesize;
av_md5_final(s->md5ctx, s->md5sum);
write_streaminfo(s, avctx->extradata);
return 0;
}
init_frame(s);
copy_samples(s, samples);
channel_decorrelation(s);
for(ch=0; ch<s->channels; ch++) {
encode_residual(s, ch);
}
write_frame:
init_put_bits(&s->pb, frame, buf_size);
output_frame_header(s);
output_subframes(s);
output_frame_footer(s);
out_bytes = put_bits_count(&s->pb) >> 3;
if(out_bytes > s->max_framesize) {
if(reencoded) {
/* still too large. must be an error. */
av_log(avctx, AV_LOG_ERROR, "error encoding frame\n");
return -1;
}
/* frame too large. use verbatim mode */
for(ch=0; ch<s->channels; ch++) {
encode_residual_v(s, ch);
}
reencoded = 1;
goto write_frame;
}
s->frame_count++;
s->sample_count += avctx->frame_size;
update_md5_sum(s, samples);
if (out_bytes > s->max_encoded_framesize)
s->max_encoded_framesize = out_bytes;
if (out_bytes < s->min_framesize)
s->min_framesize = out_bytes;
return out_bytes;
}
static av_cold int flac_encode_close(AVCodecContext *avctx)
{
if (avctx->priv_data) {
FlacEncodeContext *s = avctx->priv_data;
av_freep(&s->md5ctx);
}
av_freep(&avctx->extradata);
avctx->extradata_size = 0;
av_freep(&avctx->coded_frame);
return 0;
}
AVCodec flac_encoder = {
"flac",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_FLAC,
sizeof(FlacEncodeContext),
flac_encode_init,
flac_encode_frame,
flac_encode_close,
NULL,
.capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY,
.sample_fmts = (const enum SampleFormat[]){SAMPLE_FMT_S16,SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/flacenc.c | C | asf20 | 38,791 |
/*
* Generate a header file for hardcoded AAC tables
*
* Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdlib.h>
#define CONFIG_HARDCODED_TABLES 0
#include "aac_tablegen.h"
#include "tableprint.h"
int main(void)
{
ff_aac_tableinit();
write_fileheader();
printf("const float ff_aac_pow2sf_tab[428] = {\n");
write_float_array(ff_aac_pow2sf_tab, 428);
printf("};\n");
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/aac_tablegen.c | C | asf20 | 1,195 |
/*
* Westwood Studios VQA Video Decoder
* Copyright (C) 2003 the ffmpeg project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VQA Video Decoder by Mike Melanson (melanson@pcisys.net)
* For more information about the VQA format, visit:
* http://wiki.multimedia.cx/index.php?title=VQA
*
* The VQA video decoder outputs PAL8 or RGB555 colorspace data, depending
* on the type of data in the file.
*
* This decoder needs the 42-byte VQHD header from the beginning
* of the VQA file passed through the extradata field. The VQHD header
* is laid out as:
*
* bytes 0-3 chunk fourcc: 'VQHD'
* bytes 4-7 chunk size in big-endian format, should be 0x0000002A
* bytes 8-49 VQHD chunk data
*
* Bytes 8-49 are what this decoder expects to see.
*
* Briefly, VQA is a vector quantized animation format that operates in a
* VGA palettized colorspace. It operates on pixel vectors (blocks)
* of either 4x2 or 4x4 in size. Compressed VQA chunks can contain vector
* codebooks, palette information, and code maps for rendering vectors onto
* frames. Any of these components can also be compressed with a run-length
* encoding (RLE) algorithm commonly referred to as "format80".
*
* VQA takes a novel approach to rate control. Each group of n frames
* (usually, n = 8) relies on a different vector codebook. Rather than
* transporting an entire codebook every 8th frame, the new codebook is
* broken up into 8 pieces and sent along with the compressed video chunks
* for each of the 8 frames preceding the 8 frames which require the
* codebook. A full codebook is also sent on the very first frame of a
* file. This is an interesting technique, although it makes random file
* seeking difficult despite the fact that the frames are all intracoded.
*
* V1,2 VQA uses 12-bit codebook indexes. If the 12-bit indexes were
* packed into bytes and then RLE compressed, bytewise, the results would
* be poor. That is why the coding method divides each index into 2 parts,
* the top 4 bits and the bottom 8 bits, then RL encodes the 4-bit pieces
* together and the 8-bit pieces together. If most of the vectors are
* clustered into one group of 256 vectors, most of the 4-bit index pieces
* should be the same.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#define PALETTE_COUNT 256
#define VQA_HEADER_SIZE 0x2A
#define CHUNK_PREAMBLE_SIZE 8
/* allocate the maximum vector space, regardless of the file version:
* (0xFF00 codebook vectors + 0x100 solid pixel vectors) * (4x4 pixels/block) */
#define MAX_CODEBOOK_VECTORS 0xFF00
#define SOLID_PIXEL_VECTORS 0x100
#define MAX_VECTORS (MAX_CODEBOOK_VECTORS + SOLID_PIXEL_VECTORS)
#define MAX_CODEBOOK_SIZE (MAX_VECTORS * 4 * 4)
#define CBF0_TAG MKBETAG('C', 'B', 'F', '0')
#define CBFZ_TAG MKBETAG('C', 'B', 'F', 'Z')
#define CBP0_TAG MKBETAG('C', 'B', 'P', '0')
#define CBPZ_TAG MKBETAG('C', 'B', 'P', 'Z')
#define CPL0_TAG MKBETAG('C', 'P', 'L', '0')
#define CPLZ_TAG MKBETAG('C', 'P', 'L', 'Z')
#define VPTZ_TAG MKBETAG('V', 'P', 'T', 'Z')
#define VQA_DEBUG 0
#if VQA_DEBUG
#define vqa_debug printf
#else
static inline void vqa_debug(const char *format, ...) { }
#endif
typedef struct VqaContext {
AVCodecContext *avctx;
AVFrame frame;
const unsigned char *buf;
int size;
uint32_t palette[PALETTE_COUNT];
int width; /* width of a frame */
int height; /* height of a frame */
int vector_width; /* width of individual vector */
int vector_height; /* height of individual vector */
int vqa_version; /* this should be either 1, 2 or 3 */
unsigned char *codebook; /* the current codebook */
int codebook_size;
unsigned char *next_codebook_buffer; /* accumulator for next codebook */
int next_codebook_buffer_index;
unsigned char *decode_buffer;
int decode_buffer_size;
/* number of frames to go before replacing codebook */
int partial_countdown;
int partial_count;
} VqaContext;
static av_cold int vqa_decode_init(AVCodecContext *avctx)
{
VqaContext *s = avctx->priv_data;
unsigned char *vqa_header;
int i, j, codebook_index;
s->avctx = avctx;
avctx->pix_fmt = PIX_FMT_PAL8;
/* make sure the extradata made it */
if (s->avctx->extradata_size != VQA_HEADER_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, " VQA video: expected extradata size of %d\n", VQA_HEADER_SIZE);
return -1;
}
/* load up the VQA parameters from the header */
vqa_header = (unsigned char *)s->avctx->extradata;
s->vqa_version = vqa_header[0];
s->width = AV_RL16(&vqa_header[6]);
s->height = AV_RL16(&vqa_header[8]);
if(avcodec_check_dimensions(avctx, s->width, s->height)){
s->width= s->height= 0;
return -1;
}
s->vector_width = vqa_header[10];
s->vector_height = vqa_header[11];
s->partial_count = s->partial_countdown = vqa_header[13];
/* the vector dimensions have to meet very stringent requirements */
if ((s->vector_width != 4) ||
((s->vector_height != 2) && (s->vector_height != 4))) {
/* return without further initialization */
return -1;
}
/* allocate codebooks */
s->codebook_size = MAX_CODEBOOK_SIZE;
s->codebook = av_malloc(s->codebook_size);
s->next_codebook_buffer = av_malloc(s->codebook_size);
/* initialize the solid-color vectors */
if (s->vector_height == 4) {
codebook_index = 0xFF00 * 16;
for (i = 0; i < 256; i++)
for (j = 0; j < 16; j++)
s->codebook[codebook_index++] = i;
} else {
codebook_index = 0xF00 * 8;
for (i = 0; i < 256; i++)
for (j = 0; j < 8; j++)
s->codebook[codebook_index++] = i;
}
s->next_codebook_buffer_index = 0;
/* allocate decode buffer */
s->decode_buffer_size = (s->width / s->vector_width) *
(s->height / s->vector_height) * 2;
s->decode_buffer = av_malloc(s->decode_buffer_size);
s->frame.data[0] = NULL;
return 0;
}
#define CHECK_COUNT() \
if (dest_index + count > dest_size) { \
av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
av_log(NULL, AV_LOG_ERROR, " VQA video: current dest_index = %d, count = %d, dest_size = %d\n", \
dest_index, count, dest_size); \
return; \
}
static void decode_format80(const unsigned char *src, int src_size,
unsigned char *dest, int dest_size, int check_size) {
int src_index = 0;
int dest_index = 0;
int count;
int src_pos;
unsigned char color;
int i;
while (src_index < src_size) {
vqa_debug(" opcode %02X: ", src[src_index]);
/* 0x80 means that frame is finished */
if (src[src_index] == 0x80)
return;
if (dest_index >= dest_size) {
av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",
dest_index, dest_size);
return;
}
if (src[src_index] == 0xFF) {
src_index++;
count = AV_RL16(&src[src_index]);
src_index += 2;
src_pos = AV_RL16(&src[src_index]);
src_index += 2;
vqa_debug("(1) copy %X bytes from absolute pos %X\n", count, src_pos);
CHECK_COUNT();
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[src_pos + i];
dest_index += count;
} else if (src[src_index] == 0xFE) {
src_index++;
count = AV_RL16(&src[src_index]);
src_index += 2;
color = src[src_index++];
vqa_debug("(2) set %X bytes to %02X\n", count, color);
CHECK_COUNT();
memset(&dest[dest_index], color, count);
dest_index += count;
} else if ((src[src_index] & 0xC0) == 0xC0) {
count = (src[src_index++] & 0x3F) + 3;
src_pos = AV_RL16(&src[src_index]);
src_index += 2;
vqa_debug("(3) copy %X bytes from absolute pos %X\n", count, src_pos);
CHECK_COUNT();
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[src_pos + i];
dest_index += count;
} else if (src[src_index] > 0x80) {
count = src[src_index++] & 0x3F;
vqa_debug("(4) copy %X bytes from source to dest\n", count);
CHECK_COUNT();
memcpy(&dest[dest_index], &src[src_index], count);
src_index += count;
dest_index += count;
} else {
count = ((src[src_index] & 0x70) >> 4) + 3;
src_pos = AV_RB16(&src[src_index]) & 0x0FFF;
src_index += 2;
vqa_debug("(5) copy %X bytes from relpos %X\n", count, src_pos);
CHECK_COUNT();
for (i = 0; i < count; i++)
dest[dest_index + i] = dest[dest_index - src_pos + i];
dest_index += count;
}
}
/* validate that the entire destination buffer was filled; this is
* important for decoding frame maps since each vector needs to have a
* codebook entry; it is not important for compressed codebooks because
* not every entry needs to be filled */
if (check_size)
if (dest_index < dest_size)
av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
dest_index, dest_size);
}
static void vqa_decode_chunk(VqaContext *s)
{
unsigned int chunk_type;
unsigned int chunk_size;
int byte_skip;
unsigned int index = 0;
int i;
unsigned char r, g, b;
int index_shift;
int cbf0_chunk = -1;
int cbfz_chunk = -1;
int cbp0_chunk = -1;
int cbpz_chunk = -1;
int cpl0_chunk = -1;
int cplz_chunk = -1;
int vptz_chunk = -1;
int x, y;
int lines = 0;
int pixel_ptr;
int vector_index = 0;
int lobyte = 0;
int hibyte = 0;
int lobytes = 0;
int hibytes = s->decode_buffer_size / 2;
/* first, traverse through the frame and find the subchunks */
while (index < s->size) {
chunk_type = AV_RB32(&s->buf[index]);
chunk_size = AV_RB32(&s->buf[index + 4]);
switch (chunk_type) {
case CBF0_TAG:
cbf0_chunk = index;
break;
case CBFZ_TAG:
cbfz_chunk = index;
break;
case CBP0_TAG:
cbp0_chunk = index;
break;
case CBPZ_TAG:
cbpz_chunk = index;
break;
case CPL0_TAG:
cpl0_chunk = index;
break;
case CPLZ_TAG:
cplz_chunk = index;
break;
case VPTZ_TAG:
vptz_chunk = index;
break;
default:
av_log(s->avctx, AV_LOG_ERROR, " VQA video: Found unknown chunk type: %c%c%c%c (%08X)\n",
(chunk_type >> 24) & 0xFF,
(chunk_type >> 16) & 0xFF,
(chunk_type >> 8) & 0xFF,
(chunk_type >> 0) & 0xFF,
chunk_type);
break;
}
byte_skip = chunk_size & 0x01;
index += (CHUNK_PREAMBLE_SIZE + chunk_size + byte_skip);
}
/* next, deal with the palette */
if ((cpl0_chunk != -1) && (cplz_chunk != -1)) {
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CPL0 and CPLZ chunks\n");
return;
}
/* decompress the palette chunk */
if (cplz_chunk != -1) {
/* yet to be handled */
}
/* convert the RGB palette into the machine's endian format */
if (cpl0_chunk != -1) {
chunk_size = AV_RB32(&s->buf[cpl0_chunk + 4]);
/* sanity check the palette size */
if (chunk_size / 3 > 256) {
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found a palette chunk with %d colors\n",
chunk_size / 3);
return;
}
cpl0_chunk += CHUNK_PREAMBLE_SIZE;
for (i = 0; i < chunk_size / 3; i++) {
/* scale by 4 to transform 6-bit palette -> 8-bit */
r = s->buf[cpl0_chunk++] * 4;
g = s->buf[cpl0_chunk++] * 4;
b = s->buf[cpl0_chunk++] * 4;
s->palette[i] = (r << 16) | (g << 8) | (b);
}
}
/* next, look for a full codebook */
if ((cbf0_chunk != -1) && (cbfz_chunk != -1)) {
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CBF0 and CBFZ chunks\n");
return;
}
/* decompress the full codebook chunk */
if (cbfz_chunk != -1) {
chunk_size = AV_RB32(&s->buf[cbfz_chunk + 4]);
cbfz_chunk += CHUNK_PREAMBLE_SIZE;
decode_format80(&s->buf[cbfz_chunk], chunk_size,
s->codebook, s->codebook_size, 0);
}
/* copy a full codebook */
if (cbf0_chunk != -1) {
chunk_size = AV_RB32(&s->buf[cbf0_chunk + 4]);
/* sanity check the full codebook size */
if (chunk_size > MAX_CODEBOOK_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: CBF0 chunk too large (0x%X bytes)\n",
chunk_size);
return;
}
cbf0_chunk += CHUNK_PREAMBLE_SIZE;
memcpy(s->codebook, &s->buf[cbf0_chunk], chunk_size);
}
/* decode the frame */
if (vptz_chunk == -1) {
/* something is wrong if there is no VPTZ chunk */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: no VPTZ chunk found\n");
return;
}
chunk_size = AV_RB32(&s->buf[vptz_chunk + 4]);
vptz_chunk += CHUNK_PREAMBLE_SIZE;
decode_format80(&s->buf[vptz_chunk], chunk_size,
s->decode_buffer, s->decode_buffer_size, 1);
/* render the final PAL8 frame */
if (s->vector_height == 4)
index_shift = 4;
else
index_shift = 3;
for (y = 0; y < s->frame.linesize[0] * s->height;
y += s->frame.linesize[0] * s->vector_height) {
for (x = y; x < y + s->width; x += 4, lobytes++, hibytes++) {
pixel_ptr = x;
/* get the vector index, the method for which varies according to
* VQA file version */
switch (s->vqa_version) {
case 1:
/* still need sample media for this case (only one game, "Legend of
* Kyrandia III : Malcolm's Revenge", is known to use this version) */
lobyte = s->decode_buffer[lobytes * 2];
hibyte = s->decode_buffer[(lobytes * 2) + 1];
vector_index = ((hibyte << 8) | lobyte) >> 3;
vector_index <<= index_shift;
lines = s->vector_height;
/* uniform color fill - a quick hack */
if (hibyte == 0xFF) {
while (lines--) {
s->frame.data[0][pixel_ptr + 0] = 255 - lobyte;
s->frame.data[0][pixel_ptr + 1] = 255 - lobyte;
s->frame.data[0][pixel_ptr + 2] = 255 - lobyte;
s->frame.data[0][pixel_ptr + 3] = 255 - lobyte;
pixel_ptr += s->frame.linesize[0];
}
lines=0;
}
break;
case 2:
lobyte = s->decode_buffer[lobytes];
hibyte = s->decode_buffer[hibytes];
vector_index = (hibyte << 8) | lobyte;
vector_index <<= index_shift;
lines = s->vector_height;
break;
case 3:
/* not implemented yet */
lines = 0;
break;
}
while (lines--) {
s->frame.data[0][pixel_ptr + 0] = s->codebook[vector_index++];
s->frame.data[0][pixel_ptr + 1] = s->codebook[vector_index++];
s->frame.data[0][pixel_ptr + 2] = s->codebook[vector_index++];
s->frame.data[0][pixel_ptr + 3] = s->codebook[vector_index++];
pixel_ptr += s->frame.linesize[0];
}
}
}
/* handle partial codebook */
if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CBP0 and CBPZ chunks\n");
return;
}
if (cbp0_chunk != -1) {
chunk_size = AV_RB32(&s->buf[cbp0_chunk + 4]);
cbp0_chunk += CHUNK_PREAMBLE_SIZE;
/* accumulate partial codebook */
memcpy(&s->next_codebook_buffer[s->next_codebook_buffer_index],
&s->buf[cbp0_chunk], chunk_size);
s->next_codebook_buffer_index += chunk_size;
s->partial_countdown--;
if (s->partial_countdown == 0) {
/* time to replace codebook */
memcpy(s->codebook, s->next_codebook_buffer,
s->next_codebook_buffer_index);
/* reset accounting */
s->next_codebook_buffer_index = 0;
s->partial_countdown = s->partial_count;
}
}
if (cbpz_chunk != -1) {
chunk_size = AV_RB32(&s->buf[cbpz_chunk + 4]);
cbpz_chunk += CHUNK_PREAMBLE_SIZE;
/* accumulate partial codebook */
memcpy(&s->next_codebook_buffer[s->next_codebook_buffer_index],
&s->buf[cbpz_chunk], chunk_size);
s->next_codebook_buffer_index += chunk_size;
s->partial_countdown--;
if (s->partial_countdown == 0) {
/* decompress codebook */
decode_format80(s->next_codebook_buffer,
s->next_codebook_buffer_index,
s->codebook, s->codebook_size, 0);
/* reset accounting */
s->next_codebook_buffer_index = 0;
s->partial_countdown = s->partial_count;
}
}
}
static int vqa_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VqaContext *s = avctx->priv_data;
s->buf = buf;
s->size = buf_size;
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
if (avctx->get_buffer(avctx, &s->frame)) {
av_log(s->avctx, AV_LOG_ERROR, " VQA Video: get_buffer() failed\n");
return -1;
}
vqa_decode_chunk(s);
/* make the palette available on the way out */
memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
s->frame.palette_has_changed = 1;
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
/* report that the buffer was completely consumed */
return buf_size;
}
static av_cold int vqa_decode_end(AVCodecContext *avctx)
{
VqaContext *s = avctx->priv_data;
av_free(s->codebook);
av_free(s->next_codebook_buffer);
av_free(s->decode_buffer);
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
return 0;
}
AVCodec vqa_decoder = {
"vqavideo",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_WS_VQA,
sizeof(VqaContext),
vqa_decode_init,
NULL,
vqa_decode_end,
vqa_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA (Vector Quantized Animation) video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/vqavideo.c | C | asf20 | 20,202 |
/**
* @file
* Psygnosis YOP decoder
*
* Copyright (C) 2010 Mohamed Naufal Basheer <naufal11@gmail.com>
* derived from the code by
* Copyright (C) 2009 Thomas P. Higdon <thomas.p.higdon@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
#include "get_bits.h"
typedef struct YopDecContext {
AVFrame frame;
AVCodecContext *avctx;
int num_pal_colors;
int first_color[2];
int frame_data_length;
int row_pos;
uint8_t *low_nibble;
uint8_t *srcptr;
uint8_t *dstptr;
uint8_t *dstbuf;
} YopDecContext;
// These tables are taken directly from:
// http://wiki.multimedia.cx/index.php?title=Psygnosis_YOP
/**
* Lookup table for painting macroblocks. Bytes 0-2 of each entry contain
* the macroblock positions to be painted (taken as (0, B0, B1, B2)).
* Byte 3 contains the number of bytes consumed on the input,
* equal to max(bytes 0-2) + 1.
*/
static const uint8_t paint_lut[15][4] =
{{1, 2, 3, 4}, {1, 2, 0, 3},
{1, 2, 1, 3}, {1, 2, 2, 3},
{1, 0, 2, 3}, {1, 0, 0, 2},
{1, 0, 1, 2}, {1, 1, 2, 3},
{0, 1, 2, 3}, {0, 1, 0, 2},
{1, 1, 0, 2}, {0, 1, 1, 2},
{0, 0, 1, 2}, {0, 0, 0, 1},
{1, 1, 1, 2},
};
/**
* Lookup table for copying macroblocks. Each entry contains the respective
* x and y pixel offset for the copy source.
*/
static const int8_t motion_vector[16][2] =
{{-4, -4}, {-2, -4},
{ 0, -4}, { 2, -4},
{-4, -2}, {-4, 0},
{-3, -3}, {-1, -3},
{ 1, -3}, { 3, -3},
{-3, -1}, {-2, -2},
{ 0, -2}, { 2, -2},
{ 4, -2}, {-2, 0},
};
static av_cold int yop_decode_init(AVCodecContext *avctx)
{
YopDecContext *s = avctx->priv_data;
s->avctx = avctx;
if (avctx->width & 1 || avctx->height & 1 ||
avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
av_log(avctx, AV_LOG_ERROR, "YOP has invalid dimensions\n");
return -1;
}
avctx->pix_fmt = PIX_FMT_PAL8;
s->num_pal_colors = avctx->extradata[0];
s->first_color[0] = avctx->extradata[1];
s->first_color[1] = avctx->extradata[2];
if (s->num_pal_colors + s->first_color[0] > 256 ||
s->num_pal_colors + s->first_color[1] > 256) {
av_log(avctx, AV_LOG_ERROR,
"YOP: palette parameters invalid, header probably corrupt\n");
return AVERROR_INVALIDDATA;
}
return 0;
}
static av_cold int yop_decode_close(AVCodecContext *avctx)
{
YopDecContext *s = avctx->priv_data;
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
return 0;
}
/**
* Paints a macroblock using the pattern in paint_lut.
* @param s codec context
* @param tag the tag that was in the nibble
*/
static void yop_paint_block(YopDecContext *s, int tag)
{
s->dstptr[0] = s->srcptr[0];
s->dstptr[1] = s->srcptr[paint_lut[tag][0]];
s->dstptr[s->frame.linesize[0]] = s->srcptr[paint_lut[tag][1]];
s->dstptr[s->frame.linesize[0] + 1] = s->srcptr[paint_lut[tag][2]];
// The number of src bytes consumed is in the last part of the lut entry.
s->srcptr += paint_lut[tag][3];
}
/**
* Copies a previously painted macroblock to the current_block.
* @param copy_tag the tag that was in the nibble
*/
static int yop_copy_previous_block(YopDecContext *s, int copy_tag)
{
uint8_t *bufptr;
// Calculate position for the copy source
bufptr = s->dstptr + motion_vector[copy_tag][0] +
s->frame.linesize[0] * motion_vector[copy_tag][1];
if (bufptr < s->dstbuf) {
av_log(s->avctx, AV_LOG_ERROR,
"YOP: cannot decode, file probably corrupt\n");
return AVERROR_INVALIDDATA;
}
s->dstptr[0] = bufptr[0];
s->dstptr[1] = bufptr[1];
s->dstptr[s->frame.linesize[0]] = bufptr[s->frame.linesize[0]];
s->dstptr[s->frame.linesize[0] + 1] = bufptr[s->frame.linesize[0] + 1];
return 0;
}
/**
* Returns the next nibble in sequence, consuming a new byte on the input
* only if necessary.
*/
static uint8_t yop_get_next_nibble(YopDecContext *s)
{
int ret;
if (s->low_nibble) {
ret = *s->low_nibble & 0xf;
s->low_nibble = NULL;
}else {
s->low_nibble = s->srcptr++;
ret = *s->low_nibble >> 4;
}
return ret;
}
/**
* Takes s->dstptr to the next macroblock in sequence.
*/
static void yop_next_macroblock(YopDecContext *s)
{
// If we are advancing to the next row of macroblocks
if (s->row_pos == s->frame.linesize[0] - 2) {
s->dstptr += s->frame.linesize[0];
s->row_pos = 0;
}else {
s->row_pos += 2;
}
s->dstptr += 2;
}
static int yop_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
YopDecContext *s = avctx->priv_data;
int tag, firstcolor, is_odd_frame;
int ret, i;
uint32_t *palette;
if (s->frame.data[0])
avctx->release_buffer(avctx, &s->frame);
ret = avctx->get_buffer(avctx, &s->frame);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
s->frame.linesize[0] = avctx->width;
s->dstbuf = s->frame.data[0];
s->dstptr = s->frame.data[0];
s->srcptr = avpkt->data + 4;
s->row_pos = 0;
s->low_nibble = NULL;
is_odd_frame = avpkt->data[0];
firstcolor = s->first_color[is_odd_frame];
palette = (uint32_t *)s->frame.data[1];
for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3)
palette[i + firstcolor] = (s->srcptr[0] << 18) |
(s->srcptr[1] << 10) |
(s->srcptr[2] << 2);
s->frame.palette_has_changed = 1;
while (s->dstptr - s->dstbuf <
avctx->width * avctx->height &&
s->srcptr - avpkt->data < avpkt->size) {
tag = yop_get_next_nibble(s);
if (tag != 0xf) {
yop_paint_block(s, tag);
}else {
tag = yop_get_next_nibble(s);
ret = yop_copy_previous_block(s, tag);
if (ret < 0) {
avctx->release_buffer(avctx, &s->frame);
return ret;
}
}
yop_next_macroblock(s);
}
*data_size = sizeof(AVFrame);
*(AVFrame *) data = s->frame;
return avpkt->size;
}
AVCodec yop_decoder = {
"yop",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_YOP,
sizeof(YopDecContext),
yop_decode_init,
NULL,
yop_decode_close,
yop_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/yop.c | C | asf20 | 7,447 |
/*
* AMR narrowband decoder
* Copyright (c) 2006-2007 Robert Swain
* Copyright (c) 2009 Colin McQuillan
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* AMR narrowband decoder
*
* This decoder uses floats for simplicity and so is not bit-exact. One
* difference is that differences in phase can accumulate. The test sequences
* in 3GPP TS 26.074 can still be useful.
*
* - Comparing this file's output to the output of the ref decoder gives a
* PSNR of 30 to 80. Plotting the output samples shows a difference in
* phase in some areas.
*
* - Comparing both decoders against their input, this decoder gives a similar
* PSNR. If the test sequence homing frames are removed (this decoder does
* not detect them), the PSNR is at least as good as the reference on 140
* out of 169 tests.
*/
#include <string.h>
#include <math.h>
#include "avcodec.h"
#include "get_bits.h"
#include "libavutil/common.h"
#include "celp_math.h"
#include "celp_filters.h"
#include "acelp_filters.h"
#include "acelp_vectors.h"
#include "acelp_pitch_delay.h"
#include "lsp.h"
#include "amrnbdata.h"
#define AMR_BLOCK_SIZE 160 ///< samples per frame
#define AMR_SAMPLE_BOUND 32768.0 ///< threshold for synthesis overflow
/**
* Scale from constructed speech to [-1,1]
*
* AMR is designed to produce 16-bit PCM samples (3GPP TS 26.090 4.2) but
* upscales by two (section 6.2.2).
*
* Fundamentally, this scale is determined by energy_mean through
* the fixed vector contribution to the excitation vector.
*/
#define AMR_SAMPLE_SCALE (2.0 / 32768.0)
/** Prediction factor for 12.2kbit/s mode */
#define PRED_FAC_MODE_12k2 0.65
#define LSF_R_FAC (8000.0 / 32768.0) ///< LSF residual tables to Hertz
#define MIN_LSF_SPACING (50.0488 / 8000.0) ///< Ensures stability of LPC filter
#define PITCH_LAG_MIN_MODE_12k2 18 ///< Lower bound on decoded lag search in 12.2kbit/s mode
/** Initial energy in dB. Also used for bad frames (unimplemented). */
#define MIN_ENERGY -14.0
/** Maximum sharpening factor
*
* The specification says 0.8, which should be 13107, but the reference C code
* uses 13017 instead. (Amusingly the same applies to SHARP_MAX in g729dec.c.)
*/
#define SHARP_MAX 0.79449462890625
/** Number of impulse response coefficients used for tilt factor */
#define AMR_TILT_RESPONSE 22
/** Tilt factor = 1st reflection coefficient * gamma_t */
#define AMR_TILT_GAMMA_T 0.8
/** Adaptive gain control factor used in post-filter */
#define AMR_AGC_ALPHA 0.9
typedef struct AMRContext {
AMRNBFrame frame; ///< decoded AMR parameters (lsf coefficients, codebook indexes, etc)
uint8_t bad_frame_indicator; ///< bad frame ? 1 : 0
enum Mode cur_frame_mode;
int16_t prev_lsf_r[LP_FILTER_ORDER]; ///< residual LSF vector from previous subframe
double lsp[4][LP_FILTER_ORDER]; ///< lsp vectors from current frame
double prev_lsp_sub4[LP_FILTER_ORDER]; ///< lsp vector for the 4th subframe of the previous frame
float lsf_q[4][LP_FILTER_ORDER]; ///< Interpolated LSF vector for fixed gain smoothing
float lsf_avg[LP_FILTER_ORDER]; ///< vector of averaged lsf vector
float lpc[4][LP_FILTER_ORDER]; ///< lpc coefficient vectors for 4 subframes
uint8_t pitch_lag_int; ///< integer part of pitch lag from current subframe
float excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1 + AMR_SUBFRAME_SIZE]; ///< current excitation and all necessary excitation history
float *excitation; ///< pointer to the current excitation vector in excitation_buf
float pitch_vector[AMR_SUBFRAME_SIZE]; ///< adaptive code book (pitch) vector
float fixed_vector[AMR_SUBFRAME_SIZE]; ///< algebraic codebook (fixed) vector (must be kept zero between frames)
float prediction_error[4]; ///< quantified prediction errors {20log10(^gamma_gc)} for previous four subframes
float pitch_gain[5]; ///< quantified pitch gains for the current and previous four subframes
float fixed_gain[5]; ///< quantified fixed gains for the current and previous four subframes
float beta; ///< previous pitch_gain, bounded by [0.0,SHARP_MAX]
uint8_t diff_count; ///< the number of subframes for which diff has been above 0.65
uint8_t hang_count; ///< the number of subframes since a hangover period started
float prev_sparse_fixed_gain; ///< previous fixed gain; used by anti-sparseness processing to determine "onset"
uint8_t prev_ir_filter_nr; ///< previous impulse response filter "impNr": 0 - strong, 1 - medium, 2 - none
uint8_t ir_filter_onset; ///< flag for impulse response filter strength
float postfilter_mem[10]; ///< previous intermediate values in the formant filter
float tilt_mem; ///< previous input to tilt compensation filter
float postfilter_agc; ///< previous factor used for adaptive gain control
float high_pass_mem[2]; ///< previous intermediate values in the high-pass filter
float samples_in[LP_FILTER_ORDER + AMR_SUBFRAME_SIZE]; ///< floating point samples
} AMRContext;
/** Double version of ff_weighted_vector_sumf() */
static void weighted_vector_sumd(double *out, const double *in_a,
const double *in_b, double weight_coeff_a,
double weight_coeff_b, int length)
{
int i;
for (i = 0; i < length; i++)
out[i] = weight_coeff_a * in_a[i]
+ weight_coeff_b * in_b[i];
}
static av_cold int amrnb_decode_init(AVCodecContext *avctx)
{
AMRContext *p = avctx->priv_data;
int i;
avctx->sample_fmt = SAMPLE_FMT_FLT;
// p->excitation always points to the same position in p->excitation_buf
p->excitation = &p->excitation_buf[PITCH_DELAY_MAX + LP_FILTER_ORDER + 1];
for (i = 0; i < LP_FILTER_ORDER; i++) {
p->prev_lsp_sub4[i] = lsp_sub4_init[i] * 1000 / (float)(1 << 15);
p->lsf_avg[i] = p->lsf_q[3][i] = lsp_avg_init[i] / (float)(1 << 15);
}
for (i = 0; i < 4; i++)
p->prediction_error[i] = MIN_ENERGY;
return 0;
}
/**
* Unpack an RFC4867 speech frame into the AMR frame mode and parameters.
*
* The order of speech bits is specified by 3GPP TS 26.101.
*
* @param p the context
* @param buf pointer to the input buffer
* @param buf_size size of the input buffer
*
* @return the frame mode
*/
static enum Mode unpack_bitstream(AMRContext *p, const uint8_t *buf,
int buf_size)
{
GetBitContext gb;
enum Mode mode;
init_get_bits(&gb, buf, buf_size * 8);
// Decode the first octet.
skip_bits(&gb, 1); // padding bit
mode = get_bits(&gb, 4); // frame type
p->bad_frame_indicator = !get_bits1(&gb); // quality bit
skip_bits(&gb, 2); // two padding bits
if (mode < MODE_DTX) {
uint16_t *data = (uint16_t *)&p->frame;
const uint8_t *order = amr_unpacking_bitmaps_per_mode[mode];
int field_size;
memset(&p->frame, 0, sizeof(AMRNBFrame));
buf++;
while ((field_size = *order++)) {
int field = 0;
int field_offset = *order++;
while (field_size--) {
int bit = *order++;
field <<= 1;
field |= buf[bit >> 3] >> (bit & 7) & 1;
}
data[field_offset] = field;
}
}
return mode;
}
/// @defgroup amr_lpc_decoding AMR pitch LPC coefficient decoding functions
/// @{
/**
* Convert an lsf vector into an lsp vector.
*
* @param lsf input lsf vector
* @param lsp output lsp vector
*/
static void lsf2lsp(const float *lsf, double *lsp)
{
int i;
for (i = 0; i < LP_FILTER_ORDER; i++)
lsp[i] = cos(2.0 * M_PI * lsf[i]);
}
/**
* Interpolate the LSF vector (used for fixed gain smoothing).
* The interpolation is done over all four subframes even in MODE_12k2.
*
* @param[in,out] lsf_q LSFs in [0,1] for each subframe
* @param[in] lsf_new New LSFs in [0,1] for subframe 4
*/
static void interpolate_lsf(float lsf_q[4][LP_FILTER_ORDER], float *lsf_new)
{
int i;
for (i = 0; i < 4; i++)
ff_weighted_vector_sumf(lsf_q[i], lsf_q[3], lsf_new,
0.25 * (3 - i), 0.25 * (i + 1),
LP_FILTER_ORDER);
}
/**
* Decode a set of 5 split-matrix quantized lsf indexes into an lsp vector.
*
* @param p the context
* @param lsp output LSP vector
* @param lsf_no_r LSF vector without the residual vector added
* @param lsf_quantizer pointers to LSF dictionary tables
* @param quantizer_offset offset in tables
* @param sign for the 3 dictionary table
* @param update store data for computing the next frame's LSFs
*/
static void lsf2lsp_for_mode12k2(AMRContext *p, double lsp[LP_FILTER_ORDER],
const float lsf_no_r[LP_FILTER_ORDER],
const int16_t *lsf_quantizer[5],
const int quantizer_offset,
const int sign, const int update)
{
int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector
float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector
int i;
for (i = 0; i < LP_FILTER_ORDER >> 1; i++)
memcpy(&lsf_r[i << 1], &lsf_quantizer[i][quantizer_offset],
2 * sizeof(*lsf_r));
if (sign) {
lsf_r[4] *= -1;
lsf_r[5] *= -1;
}
if (update)
memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(float));
for (i = 0; i < LP_FILTER_ORDER; i++)
lsf_q[i] = lsf_r[i] * (LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0);
ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER);
if (update)
interpolate_lsf(p->lsf_q, lsf_q);
lsf2lsp(lsf_q, lsp);
}
/**
* Decode a set of 5 split-matrix quantized lsf indexes into 2 lsp vectors.
*
* @param p pointer to the AMRContext
*/
static void lsf2lsp_5(AMRContext *p)
{
const uint16_t *lsf_param = p->frame.lsf;
float lsf_no_r[LP_FILTER_ORDER]; // LSFs without the residual vector
const int16_t *lsf_quantizer[5];
int i;
lsf_quantizer[0] = lsf_5_1[lsf_param[0]];
lsf_quantizer[1] = lsf_5_2[lsf_param[1]];
lsf_quantizer[2] = lsf_5_3[lsf_param[2] >> 1];
lsf_quantizer[3] = lsf_5_4[lsf_param[3]];
lsf_quantizer[4] = lsf_5_5[lsf_param[4]];
for (i = 0; i < LP_FILTER_ORDER; i++)
lsf_no_r[i] = p->prev_lsf_r[i] * LSF_R_FAC * PRED_FAC_MODE_12k2 + lsf_5_mean[i];
lsf2lsp_for_mode12k2(p, p->lsp[1], lsf_no_r, lsf_quantizer, 0, lsf_param[2] & 1, 0);
lsf2lsp_for_mode12k2(p, p->lsp[3], lsf_no_r, lsf_quantizer, 2, lsf_param[2] & 1, 1);
// interpolate LSP vectors at subframes 1 and 3
weighted_vector_sumd(p->lsp[0], p->prev_lsp_sub4, p->lsp[1], 0.5, 0.5, LP_FILTER_ORDER);
weighted_vector_sumd(p->lsp[2], p->lsp[1] , p->lsp[3], 0.5, 0.5, LP_FILTER_ORDER);
}
/**
* Decode a set of 3 split-matrix quantized lsf indexes into an lsp vector.
*
* @param p pointer to the AMRContext
*/
static void lsf2lsp_3(AMRContext *p)
{
const uint16_t *lsf_param = p->frame.lsf;
int16_t lsf_r[LP_FILTER_ORDER]; // residual LSF vector
float lsf_q[LP_FILTER_ORDER]; // quantified LSF vector
const int16_t *lsf_quantizer;
int i, j;
lsf_quantizer = (p->cur_frame_mode == MODE_7k95 ? lsf_3_1_MODE_7k95 : lsf_3_1)[lsf_param[0]];
memcpy(lsf_r, lsf_quantizer, 3 * sizeof(*lsf_r));
lsf_quantizer = lsf_3_2[lsf_param[1] << (p->cur_frame_mode <= MODE_5k15)];
memcpy(lsf_r + 3, lsf_quantizer, 3 * sizeof(*lsf_r));
lsf_quantizer = (p->cur_frame_mode <= MODE_5k15 ? lsf_3_3_MODE_5k15 : lsf_3_3)[lsf_param[2]];
memcpy(lsf_r + 6, lsf_quantizer, 4 * sizeof(*lsf_r));
// calculate mean-removed LSF vector and add mean
for (i = 0; i < LP_FILTER_ORDER; i++)
lsf_q[i] = (lsf_r[i] + p->prev_lsf_r[i] * pred_fac[i]) * (LSF_R_FAC / 8000.0) + lsf_3_mean[i] * (1.0 / 8000.0);
ff_set_min_dist_lsf(lsf_q, MIN_LSF_SPACING, LP_FILTER_ORDER);
// store data for computing the next frame's LSFs
interpolate_lsf(p->lsf_q, lsf_q);
memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r));
lsf2lsp(lsf_q, p->lsp[3]);
// interpolate LSP vectors at subframes 1, 2 and 3
for (i = 1; i <= 3; i++)
for(j = 0; j < LP_FILTER_ORDER; j++)
p->lsp[i-1][j] = p->prev_lsp_sub4[j] +
(p->lsp[3][j] - p->prev_lsp_sub4[j]) * 0.25 * i;
}
/// @}
/// @defgroup amr_pitch_vector_decoding AMR pitch vector decoding functions
/// @{
/**
* Like ff_decode_pitch_lag(), but with 1/6 resolution
*/
static void decode_pitch_lag_1_6(int *lag_int, int *lag_frac, int pitch_index,
const int prev_lag_int, const int subframe)
{
if (subframe == 0 || subframe == 2) {
if (pitch_index < 463) {
*lag_int = (pitch_index + 107) * 10923 >> 16;
*lag_frac = pitch_index - *lag_int * 6 + 105;
} else {
*lag_int = pitch_index - 368;
*lag_frac = 0;
}
} else {
*lag_int = ((pitch_index + 5) * 10923 >> 16) - 1;
*lag_frac = pitch_index - *lag_int * 6 - 3;
*lag_int += av_clip(prev_lag_int - 5, PITCH_LAG_MIN_MODE_12k2,
PITCH_DELAY_MAX - 9);
}
}
static void decode_pitch_vector(AMRContext *p,
const AMRNBSubframe *amr_subframe,
const int subframe)
{
int pitch_lag_int, pitch_lag_frac;
enum Mode mode = p->cur_frame_mode;
if (p->cur_frame_mode == MODE_12k2) {
decode_pitch_lag_1_6(&pitch_lag_int, &pitch_lag_frac,
amr_subframe->p_lag, p->pitch_lag_int,
subframe);
} else
ff_decode_pitch_lag(&pitch_lag_int, &pitch_lag_frac,
amr_subframe->p_lag,
p->pitch_lag_int, subframe,
mode != MODE_4k75 && mode != MODE_5k15,
mode <= MODE_6k7 ? 4 : (mode == MODE_7k95 ? 5 : 6));
p->pitch_lag_int = pitch_lag_int; // store previous lag in a uint8_t
pitch_lag_frac <<= (p->cur_frame_mode != MODE_12k2);
pitch_lag_int += pitch_lag_frac > 0;
/* Calculate the pitch vector by interpolating the past excitation at the
pitch lag using a b60 hamming windowed sinc function. */
ff_acelp_interpolatef(p->excitation, p->excitation + 1 - pitch_lag_int,
ff_b60_sinc, 6,
pitch_lag_frac + 6 - 6*(pitch_lag_frac > 0),
10, AMR_SUBFRAME_SIZE);
memcpy(p->pitch_vector, p->excitation, AMR_SUBFRAME_SIZE * sizeof(float));
}
/// @}
/// @defgroup amr_algebraic_code_book AMR algebraic code book (fixed) vector decoding functions
/// @{
/**
* Decode a 10-bit algebraic codebook index from a 10.2 kbit/s frame.
*/
static void decode_10bit_pulse(int code, int pulse_position[8],
int i1, int i2, int i3)
{
// coded using 7+3 bits with the 3 LSBs being, individually, the LSB of 1 of
// the 3 pulses and the upper 7 bits being coded in base 5
const uint8_t *positions = base_five_table[code >> 3];
pulse_position[i1] = (positions[2] << 1) + ( code & 1);
pulse_position[i2] = (positions[1] << 1) + ((code >> 1) & 1);
pulse_position[i3] = (positions[0] << 1) + ((code >> 2) & 1);
}
/**
* Decode the algebraic codebook index to pulse positions and signs and
* construct the algebraic codebook vector for MODE_10k2.
*
* @param fixed_index positions of the eight pulses
* @param fixed_sparse pointer to the algebraic codebook vector
*/
static void decode_8_pulses_31bits(const int16_t *fixed_index,
AMRFixed *fixed_sparse)
{
int pulse_position[8];
int i, temp;
decode_10bit_pulse(fixed_index[4], pulse_position, 0, 4, 1);
decode_10bit_pulse(fixed_index[5], pulse_position, 2, 6, 5);
// coded using 5+2 bits with the 2 LSBs being, individually, the LSB of 1 of
// the 2 pulses and the upper 5 bits being coded in base 5
temp = ((fixed_index[6] >> 2) * 25 + 12) >> 5;
pulse_position[3] = temp % 5;
pulse_position[7] = temp / 5;
if (pulse_position[7] & 1)
pulse_position[3] = 4 - pulse_position[3];
pulse_position[3] = (pulse_position[3] << 1) + ( fixed_index[6] & 1);
pulse_position[7] = (pulse_position[7] << 1) + ((fixed_index[6] >> 1) & 1);
fixed_sparse->n = 8;
for (i = 0; i < 4; i++) {
const int pos1 = (pulse_position[i] << 2) + i;
const int pos2 = (pulse_position[i + 4] << 2) + i;
const float sign = fixed_index[i] ? -1.0 : 1.0;
fixed_sparse->x[i ] = pos1;
fixed_sparse->x[i + 4] = pos2;
fixed_sparse->y[i ] = sign;
fixed_sparse->y[i + 4] = pos2 < pos1 ? -sign : sign;
}
}
/**
* Decode the algebraic codebook index to pulse positions and signs,
* then construct the algebraic codebook vector.
*
* nb of pulses | bits encoding pulses
* For MODE_4k75 or MODE_5k15, 2 | 1-3, 4-6, 7
* MODE_5k9, 2 | 1, 2-4, 5-6, 7-9
* MODE_6k7, 3 | 1-3, 4, 5-7, 8, 9-11
* MODE_7k4 or MODE_7k95, 4 | 1-3, 4-6, 7-9, 10, 11-13
*
* @param fixed_sparse pointer to the algebraic codebook vector
* @param pulses algebraic codebook indexes
* @param mode mode of the current frame
* @param subframe current subframe number
*/
static void decode_fixed_sparse(AMRFixed *fixed_sparse, const uint16_t *pulses,
const enum Mode mode, const int subframe)
{
assert(MODE_4k75 <= mode && mode <= MODE_12k2);
if (mode == MODE_12k2) {
ff_decode_10_pulses_35bits(pulses, fixed_sparse, gray_decode, 5, 3);
} else if (mode == MODE_10k2) {
decode_8_pulses_31bits(pulses, fixed_sparse);
} else {
int *pulse_position = fixed_sparse->x;
int i, pulse_subset;
const int fixed_index = pulses[0];
if (mode <= MODE_5k15) {
pulse_subset = ((fixed_index >> 3) & 8) + (subframe << 1);
pulse_position[0] = ( fixed_index & 7) * 5 + track_position[pulse_subset];
pulse_position[1] = ((fixed_index >> 3) & 7) * 5 + track_position[pulse_subset + 1];
fixed_sparse->n = 2;
} else if (mode == MODE_5k9) {
pulse_subset = ((fixed_index & 1) << 1) + 1;
pulse_position[0] = ((fixed_index >> 1) & 7) * 5 + pulse_subset;
pulse_subset = (fixed_index >> 4) & 3;
pulse_position[1] = ((fixed_index >> 6) & 7) * 5 + pulse_subset + (pulse_subset == 3 ? 1 : 0);
fixed_sparse->n = pulse_position[0] == pulse_position[1] ? 1 : 2;
} else if (mode == MODE_6k7) {
pulse_position[0] = (fixed_index & 7) * 5;
pulse_subset = (fixed_index >> 2) & 2;
pulse_position[1] = ((fixed_index >> 4) & 7) * 5 + pulse_subset + 1;
pulse_subset = (fixed_index >> 6) & 2;
pulse_position[2] = ((fixed_index >> 8) & 7) * 5 + pulse_subset + 2;
fixed_sparse->n = 3;
} else { // mode <= MODE_7k95
pulse_position[0] = gray_decode[ fixed_index & 7];
pulse_position[1] = gray_decode[(fixed_index >> 3) & 7] + 1;
pulse_position[2] = gray_decode[(fixed_index >> 6) & 7] + 2;
pulse_subset = (fixed_index >> 9) & 1;
pulse_position[3] = gray_decode[(fixed_index >> 10) & 7] + pulse_subset + 3;
fixed_sparse->n = 4;
}
for (i = 0; i < fixed_sparse->n; i++)
fixed_sparse->y[i] = (pulses[1] >> i) & 1 ? 1.0 : -1.0;
}
}
/**
* Apply pitch lag to obtain the sharpened fixed vector (section 6.1.2)
*
* @param p the context
* @param subframe unpacked amr subframe
* @param mode mode of the current frame
* @param fixed_sparse sparse respresentation of the fixed vector
*/
static void pitch_sharpening(AMRContext *p, int subframe, enum Mode mode,
AMRFixed *fixed_sparse)
{
// The spec suggests the current pitch gain is always used, but in other
// modes the pitch and codebook gains are joinly quantized (sec 5.8.2)
// so the codebook gain cannot depend on the quantized pitch gain.
if (mode == MODE_12k2)
p->beta = FFMIN(p->pitch_gain[4], 1.0);
fixed_sparse->pitch_lag = p->pitch_lag_int;
fixed_sparse->pitch_fac = p->beta;
// Save pitch sharpening factor for the next subframe
// MODE_4k75 only updates on the 2nd and 4th subframes - this follows from
// the fact that the gains for two subframes are jointly quantized.
if (mode != MODE_4k75 || subframe & 1)
p->beta = av_clipf(p->pitch_gain[4], 0.0, SHARP_MAX);
}
/// @}
/// @defgroup amr_gain_decoding AMR gain decoding functions
/// @{
/**
* fixed gain smoothing
* Note that where the spec specifies the "spectrum in the q domain"
* in section 6.1.4, in fact frequencies should be used.
*
* @param p the context
* @param lsf LSFs for the current subframe, in the range [0,1]
* @param lsf_avg averaged LSFs
* @param mode mode of the current frame
*
* @return fixed gain smoothed
*/
static float fixed_gain_smooth(AMRContext *p , const float *lsf,
const float *lsf_avg, const enum Mode mode)
{
float diff = 0.0;
int i;
for (i = 0; i < LP_FILTER_ORDER; i++)
diff += fabs(lsf_avg[i] - lsf[i]) / lsf_avg[i];
// If diff is large for ten subframes, disable smoothing for a 40-subframe
// hangover period.
p->diff_count++;
if (diff <= 0.65)
p->diff_count = 0;
if (p->diff_count > 10) {
p->hang_count = 0;
p->diff_count--; // don't let diff_count overflow
}
if (p->hang_count < 40) {
p->hang_count++;
} else if (mode < MODE_7k4 || mode == MODE_10k2) {
const float smoothing_factor = av_clipf(4.0 * diff - 1.6, 0.0, 1.0);
const float fixed_gain_mean = (p->fixed_gain[0] + p->fixed_gain[1] +
p->fixed_gain[2] + p->fixed_gain[3] +
p->fixed_gain[4]) * 0.2;
return smoothing_factor * p->fixed_gain[4] +
(1.0 - smoothing_factor) * fixed_gain_mean;
}
return p->fixed_gain[4];
}
/**
* Decode pitch gain and fixed gain factor (part of section 6.1.3).
*
* @param p the context
* @param amr_subframe unpacked amr subframe
* @param mode mode of the current frame
* @param subframe current subframe number
* @param fixed_gain_factor decoded gain correction factor
*/
static void decode_gains(AMRContext *p, const AMRNBSubframe *amr_subframe,
const enum Mode mode, const int subframe,
float *fixed_gain_factor)
{
if (mode == MODE_12k2 || mode == MODE_7k95) {
p->pitch_gain[4] = qua_gain_pit [amr_subframe->p_gain ]
* (1.0 / 16384.0);
*fixed_gain_factor = qua_gain_code[amr_subframe->fixed_gain]
* (1.0 / 2048.0);
} else {
const uint16_t *gains;
if (mode >= MODE_6k7) {
gains = gains_high[amr_subframe->p_gain];
} else if (mode >= MODE_5k15) {
gains = gains_low [amr_subframe->p_gain];
} else {
// gain index is only coded in subframes 0,2 for MODE_4k75
gains = gains_MODE_4k75[(p->frame.subframe[subframe & 2].p_gain << 1) + (subframe & 1)];
}
p->pitch_gain[4] = gains[0] * (1.0 / 16384.0);
*fixed_gain_factor = gains[1] * (1.0 / 4096.0);
}
}
/// @}
/// @defgroup amr_pre_processing AMR pre-processing functions
/// @{
/**
* Circularly convolve a sparse fixed vector with a phase dispersion impulse
* response filter (D.6.2 of G.729 and 6.1.5 of AMR).
*
* @param out vector with filter applied
* @param in source vector
* @param filter phase filter coefficients
*
* out[n] = sum(i,0,len-1){ in[i] * filter[(len + n - i)%len] }
*/
static void apply_ir_filter(float *out, const AMRFixed *in,
const float *filter)
{
float filter1[AMR_SUBFRAME_SIZE], //!< filters at pitch lag*1 and *2
filter2[AMR_SUBFRAME_SIZE];
int lag = in->pitch_lag;
float fac = in->pitch_fac;
int i;
if (lag < AMR_SUBFRAME_SIZE) {
ff_celp_circ_addf(filter1, filter, filter, lag, fac,
AMR_SUBFRAME_SIZE);
if (lag < AMR_SUBFRAME_SIZE >> 1)
ff_celp_circ_addf(filter2, filter, filter1, lag, fac,
AMR_SUBFRAME_SIZE);
}
memset(out, 0, sizeof(float) * AMR_SUBFRAME_SIZE);
for (i = 0; i < in->n; i++) {
int x = in->x[i];
float y = in->y[i];
const float *filterp;
if (x >= AMR_SUBFRAME_SIZE - lag) {
filterp = filter;
} else if (x >= AMR_SUBFRAME_SIZE - (lag << 1)) {
filterp = filter1;
} else
filterp = filter2;
ff_celp_circ_addf(out, out, filterp, x, y, AMR_SUBFRAME_SIZE);
}
}
/**
* Reduce fixed vector sparseness by smoothing with one of three IR filters.
* Also know as "adaptive phase dispersion".
*
* This implements 3GPP TS 26.090 section 6.1(5).
*
* @param p the context
* @param fixed_sparse algebraic codebook vector
* @param fixed_vector unfiltered fixed vector
* @param fixed_gain smoothed gain
* @param out space for modified vector if necessary
*/
static const float *anti_sparseness(AMRContext *p, AMRFixed *fixed_sparse,
const float *fixed_vector,
float fixed_gain, float *out)
{
int ir_filter_nr;
if (p->pitch_gain[4] < 0.6) {
ir_filter_nr = 0; // strong filtering
} else if (p->pitch_gain[4] < 0.9) {
ir_filter_nr = 1; // medium filtering
} else
ir_filter_nr = 2; // no filtering
// detect 'onset'
if (fixed_gain > 2.0 * p->prev_sparse_fixed_gain) {
p->ir_filter_onset = 2;
} else if (p->ir_filter_onset)
p->ir_filter_onset--;
if (!p->ir_filter_onset) {
int i, count = 0;
for (i = 0; i < 5; i++)
if (p->pitch_gain[i] < 0.6)
count++;
if (count > 2)
ir_filter_nr = 0;
if (ir_filter_nr > p->prev_ir_filter_nr + 1)
ir_filter_nr--;
} else if (ir_filter_nr < 2)
ir_filter_nr++;
// Disable filtering for very low level of fixed_gain.
// Note this step is not specified in the technical description but is in
// the reference source in the function Ph_disp.
if (fixed_gain < 5.0)
ir_filter_nr = 2;
if (p->cur_frame_mode != MODE_7k4 && p->cur_frame_mode < MODE_10k2
&& ir_filter_nr < 2) {
apply_ir_filter(out, fixed_sparse,
(p->cur_frame_mode == MODE_7k95 ?
ir_filters_lookup_MODE_7k95 :
ir_filters_lookup)[ir_filter_nr]);
fixed_vector = out;
}
// update ir filter strength history
p->prev_ir_filter_nr = ir_filter_nr;
p->prev_sparse_fixed_gain = fixed_gain;
return fixed_vector;
}
/// @}
/// @defgroup amr_synthesis AMR synthesis functions
/// @{
/**
* Conduct 10th order linear predictive coding synthesis.
*
* @param p pointer to the AMRContext
* @param lpc pointer to the LPC coefficients
* @param fixed_gain fixed codebook gain for synthesis
* @param fixed_vector algebraic codebook vector
* @param samples pointer to the output speech samples
* @param overflow 16-bit overflow flag
*/
static int synthesis(AMRContext *p, float *lpc,
float fixed_gain, const float *fixed_vector,
float *samples, uint8_t overflow)
{
int i;
float excitation[AMR_SUBFRAME_SIZE];
// if an overflow has been detected, the pitch vector is scaled down by a
// factor of 4
if (overflow)
for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
p->pitch_vector[i] *= 0.25;
ff_weighted_vector_sumf(excitation, p->pitch_vector, fixed_vector,
p->pitch_gain[4], fixed_gain, AMR_SUBFRAME_SIZE);
// emphasize pitch vector contribution
if (p->pitch_gain[4] > 0.5 && !overflow) {
float energy = ff_dot_productf(excitation, excitation,
AMR_SUBFRAME_SIZE);
float pitch_factor =
p->pitch_gain[4] *
(p->cur_frame_mode == MODE_12k2 ?
0.25 * FFMIN(p->pitch_gain[4], 1.0) :
0.5 * FFMIN(p->pitch_gain[4], SHARP_MAX));
for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
excitation[i] += pitch_factor * p->pitch_vector[i];
ff_scale_vector_to_given_sum_of_squares(excitation, excitation, energy,
AMR_SUBFRAME_SIZE);
}
ff_celp_lp_synthesis_filterf(samples, lpc, excitation, AMR_SUBFRAME_SIZE,
LP_FILTER_ORDER);
// detect overflow
for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) {
return 1;
}
return 0;
}
/// @}
/// @defgroup amr_update AMR update functions
/// @{
/**
* Update buffers and history at the end of decoding a subframe.
*
* @param p pointer to the AMRContext
*/
static void update_state(AMRContext *p)
{
memcpy(p->prev_lsp_sub4, p->lsp[3], LP_FILTER_ORDER * sizeof(p->lsp[3][0]));
memmove(&p->excitation_buf[0], &p->excitation_buf[AMR_SUBFRAME_SIZE],
(PITCH_DELAY_MAX + LP_FILTER_ORDER + 1) * sizeof(float));
memmove(&p->pitch_gain[0], &p->pitch_gain[1], 4 * sizeof(float));
memmove(&p->fixed_gain[0], &p->fixed_gain[1], 4 * sizeof(float));
memmove(&p->samples_in[0], &p->samples_in[AMR_SUBFRAME_SIZE],
LP_FILTER_ORDER * sizeof(float));
}
/// @}
/// @defgroup amr_postproc AMR Post processing functions
/// @{
/**
* Get the tilt factor of a formant filter from its transfer function
*
* @param lpc_n LP_FILTER_ORDER coefficients of the numerator
* @param lpc_d LP_FILTER_ORDER coefficients of the denominator
*/
static float tilt_factor(float *lpc_n, float *lpc_d)
{
float rh0, rh1; // autocorrelation at lag 0 and 1
// LP_FILTER_ORDER prior zeros are needed for ff_celp_lp_synthesis_filterf
float impulse_buffer[LP_FILTER_ORDER + AMR_TILT_RESPONSE] = { 0 };
float *hf = impulse_buffer + LP_FILTER_ORDER; // start of impulse response
hf[0] = 1.0;
memcpy(hf + 1, lpc_n, sizeof(float) * LP_FILTER_ORDER);
ff_celp_lp_synthesis_filterf(hf, lpc_d, hf, AMR_TILT_RESPONSE,
LP_FILTER_ORDER);
rh0 = ff_dot_productf(hf, hf, AMR_TILT_RESPONSE);
rh1 = ff_dot_productf(hf, hf + 1, AMR_TILT_RESPONSE - 1);
// The spec only specifies this check for 12.2 and 10.2 kbit/s
// modes. But in the ref source the tilt is always non-negative.
return rh1 >= 0.0 ? rh1 / rh0 * AMR_TILT_GAMMA_T : 0.0;
}
/**
* Perform adaptive post-filtering to enhance the quality of the speech.
* See section 6.2.1.
*
* @param p pointer to the AMRContext
* @param lpc interpolated LP coefficients for this subframe
* @param buf_out output of the filter
*/
static void postfilter(AMRContext *p, float *lpc, float *buf_out)
{
int i;
float *samples = p->samples_in + LP_FILTER_ORDER; // Start of input
float speech_gain = ff_dot_productf(samples, samples,
AMR_SUBFRAME_SIZE);
float pole_out[AMR_SUBFRAME_SIZE + LP_FILTER_ORDER]; // Output of pole filter
const float *gamma_n, *gamma_d; // Formant filter factor table
float lpc_n[LP_FILTER_ORDER], lpc_d[LP_FILTER_ORDER]; // Transfer function coefficients
if (p->cur_frame_mode == MODE_12k2 || p->cur_frame_mode == MODE_10k2) {
gamma_n = ff_pow_0_7;
gamma_d = ff_pow_0_75;
} else {
gamma_n = ff_pow_0_55;
gamma_d = ff_pow_0_7;
}
for (i = 0; i < LP_FILTER_ORDER; i++) {
lpc_n[i] = lpc[i] * gamma_n[i];
lpc_d[i] = lpc[i] * gamma_d[i];
}
memcpy(pole_out, p->postfilter_mem, sizeof(float) * LP_FILTER_ORDER);
ff_celp_lp_synthesis_filterf(pole_out + LP_FILTER_ORDER, lpc_d, samples,
AMR_SUBFRAME_SIZE, LP_FILTER_ORDER);
memcpy(p->postfilter_mem, pole_out + AMR_SUBFRAME_SIZE,
sizeof(float) * LP_FILTER_ORDER);
ff_celp_lp_zero_synthesis_filterf(buf_out, lpc_n,
pole_out + LP_FILTER_ORDER,
AMR_SUBFRAME_SIZE, LP_FILTER_ORDER);
ff_tilt_compensation(&p->tilt_mem, tilt_factor(lpc_n, lpc_d), buf_out,
AMR_SUBFRAME_SIZE);
ff_adaptive_gain_control(buf_out, buf_out, speech_gain, AMR_SUBFRAME_SIZE,
AMR_AGC_ALPHA, &p->postfilter_agc);
}
/// @}
static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
AMRContext *p = avctx->priv_data; // pointer to private data
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
float *buf_out = data; // pointer to the output data buffer
int i, subframe;
float fixed_gain_factor;
AMRFixed fixed_sparse = {0}; // fixed vector up to anti-sparseness processing
float spare_vector[AMR_SUBFRAME_SIZE]; // extra stack space to hold result from anti-sparseness processing
float synth_fixed_gain; // the fixed gain that synthesis should use
const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use
p->cur_frame_mode = unpack_bitstream(p, buf, buf_size);
if (p->cur_frame_mode == MODE_DTX) {
av_log_missing_feature(avctx, "dtx mode", 1);
return -1;
}
if (p->cur_frame_mode == MODE_12k2) {
lsf2lsp_5(p);
} else
lsf2lsp_3(p);
for (i = 0; i < 4; i++)
ff_acelp_lspd2lpc(p->lsp[i], p->lpc[i], 5);
for (subframe = 0; subframe < 4; subframe++) {
const AMRNBSubframe *amr_subframe = &p->frame.subframe[subframe];
decode_pitch_vector(p, amr_subframe, subframe);
decode_fixed_sparse(&fixed_sparse, amr_subframe->pulses,
p->cur_frame_mode, subframe);
// The fixed gain (section 6.1.3) depends on the fixed vector
// (section 6.1.2), but the fixed vector calculation uses
// pitch sharpening based on the on the pitch gain (section 6.1.3).
// So the correct order is: pitch gain, pitch sharpening, fixed gain.
decode_gains(p, amr_subframe, p->cur_frame_mode, subframe,
&fixed_gain_factor);
pitch_sharpening(p, subframe, p->cur_frame_mode, &fixed_sparse);
ff_set_fixed_vector(p->fixed_vector, &fixed_sparse, 1.0,
AMR_SUBFRAME_SIZE);
p->fixed_gain[4] =
ff_amr_set_fixed_gain(fixed_gain_factor,
ff_dot_productf(p->fixed_vector, p->fixed_vector,
AMR_SUBFRAME_SIZE)/AMR_SUBFRAME_SIZE,
p->prediction_error,
energy_mean[p->cur_frame_mode], energy_pred_fac);
// The excitation feedback is calculated without any processing such
// as fixed gain smoothing. This isn't mentioned in the specification.
for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
p->excitation[i] *= p->pitch_gain[4];
ff_set_fixed_vector(p->excitation, &fixed_sparse, p->fixed_gain[4],
AMR_SUBFRAME_SIZE);
// In the ref decoder, excitation is stored with no fractional bits.
// This step prevents buzz in silent periods. The ref encoder can
// emit long sequences with pitch factor greater than one. This
// creates unwanted feedback if the excitation vector is nonzero.
// (e.g. test sequence T19_795.COD in 3GPP TS 26.074)
for (i = 0; i < AMR_SUBFRAME_SIZE; i++)
p->excitation[i] = truncf(p->excitation[i]);
// Smooth fixed gain.
// The specification is ambiguous, but in the reference source, the
// smoothed value is NOT fed back into later fixed gain smoothing.
synth_fixed_gain = fixed_gain_smooth(p, p->lsf_q[subframe],
p->lsf_avg, p->cur_frame_mode);
synth_fixed_vector = anti_sparseness(p, &fixed_sparse, p->fixed_vector,
synth_fixed_gain, spare_vector);
if (synthesis(p, p->lpc[subframe], synth_fixed_gain,
synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 0))
// overflow detected -> rerun synthesis scaling pitch vector down
// by a factor of 4, skipping pitch vector contribution emphasis
// and adaptive gain control
synthesis(p, p->lpc[subframe], synth_fixed_gain,
synth_fixed_vector, &p->samples_in[LP_FILTER_ORDER], 1);
postfilter(p, p->lpc[subframe], buf_out + subframe * AMR_SUBFRAME_SIZE);
// update buffers and history
ff_clear_fixed_vector(p->fixed_vector, &fixed_sparse, AMR_SUBFRAME_SIZE);
update_state(p);
}
ff_acelp_apply_order_2_transfer_function(buf_out, buf_out, highpass_zeros,
highpass_poles,
highpass_gain * AMR_SAMPLE_SCALE,
p->high_pass_mem, AMR_BLOCK_SIZE);
/* Update averaged lsf vector (used for fixed gain smoothing).
*
* Note that lsf_avg should not incorporate the current frame's LSFs
* for fixed_gain_smooth.
* The specification has an incorrect formula: the reference decoder uses
* qbar(n-1) rather than qbar(n) in section 6.1(4) equation 71. */
ff_weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3],
0.84, 0.16, LP_FILTER_ORDER);
/* report how many samples we got */
*data_size = AMR_BLOCK_SIZE * sizeof(float);
/* return the amount of bytes consumed if everything was OK */
return frame_sizes_nb[p->cur_frame_mode] + 1; // +7 for rounding and +8 for TOC
}
AVCodec amrnb_decoder = {
.name = "amrnb",
.type = AVMEDIA_TYPE_AUDIO,
.id = CODEC_ID_AMR_NB,
.priv_data_size = sizeof(AMRContext),
.init = amrnb_decode_init,
.decode = amrnb_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate NarrowBand"),
.sample_fmts = (enum SampleFormat[]){SAMPLE_FMT_FLT,SAMPLE_FMT_NONE},
};
| 123linslouis-android-video-cutter | jni/libavcodec/amrnbdec.c | C | asf20 | 40,426 |
/*
* AVS video decoder.
* Copyright (c) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "get_bits.h"
typedef struct {
AVFrame picture;
} AvsContext;
typedef enum {
AVS_VIDEO = 0x01,
AVS_AUDIO = 0x02,
AVS_PALETTE = 0x03,
AVS_GAME_DATA = 0x04,
} AvsBlockType;
typedef enum {
AVS_I_FRAME = 0x00,
AVS_P_FRAME_3X3 = 0x01,
AVS_P_FRAME_2X2 = 0x02,
AVS_P_FRAME_2X3 = 0x03,
} AvsVideoSubType;
static int
avs_decode_frame(AVCodecContext * avctx,
void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AvsContext *const avs = avctx->priv_data;
AVFrame *picture = data;
AVFrame *const p = (AVFrame *) & avs->picture;
const uint8_t *table, *vect;
uint8_t *out;
int i, j, x, y, stride, vect_w = 3, vect_h = 3;
AvsVideoSubType sub_type;
AvsBlockType type;
GetBitContext change_map;
if (avctx->reget_buffer(avctx, p)) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return -1;
}
p->reference = 1;
p->pict_type = FF_P_TYPE;
p->key_frame = 0;
out = avs->picture.data[0];
stride = avs->picture.linesize[0];
sub_type = buf[0];
type = buf[1];
buf += 4;
if (type == AVS_PALETTE) {
int first, last;
uint32_t *pal = (uint32_t *) avs->picture.data[1];
first = AV_RL16(buf);
last = first + AV_RL16(buf + 2);
buf += 4;
for (i=first; i<last; i++, buf+=3)
pal[i] = (buf[0] << 18) | (buf[1] << 10) | (buf[2] << 2);
sub_type = buf[0];
type = buf[1];
buf += 4;
}
if (type != AVS_VIDEO)
return -1;
switch (sub_type) {
case AVS_I_FRAME:
p->pict_type = FF_I_TYPE;
p->key_frame = 1;
case AVS_P_FRAME_3X3:
vect_w = 3;
vect_h = 3;
break;
case AVS_P_FRAME_2X2:
vect_w = 2;
vect_h = 2;
break;
case AVS_P_FRAME_2X3:
vect_w = 2;
vect_h = 3;
break;
default:
return -1;
}
table = buf + (256 * vect_w * vect_h);
if (sub_type != AVS_I_FRAME) {
int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h);
init_get_bits(&change_map, table, map_size);
table += map_size;
}
for (y=0; y<198; y+=vect_h) {
for (x=0; x<318; x+=vect_w) {
if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) {
vect = &buf[*table++ * (vect_w * vect_h)];
for (j=0; j<vect_w; j++) {
out[(y + 0) * stride + x + j] = vect[(0 * vect_w) + j];
out[(y + 1) * stride + x + j] = vect[(1 * vect_w) + j];
if (vect_h == 3)
out[(y + 2) * stride + x + j] =
vect[(2 * vect_w) + j];
}
}
}
if (sub_type != AVS_I_FRAME)
align_get_bits(&change_map);
}
*picture = *(AVFrame *) & avs->picture;
*data_size = sizeof(AVPicture);
return buf_size;
}
static av_cold int avs_decode_init(AVCodecContext * avctx)
{
avctx->pix_fmt = PIX_FMT_PAL8;
return 0;
}
AVCodec avs_decoder = {
"avs",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_AVS,
sizeof(AvsContext),
avs_decode_init,
NULL,
NULL,
avs_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/avs.c | C | asf20 | 4,269 |
/*
* Floating point AAN DCT
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* @brief
* Floating point AAN DCT
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#ifndef AVCODEC_FAANDCT_H
#define AVCODEC_FAANDCT_H
#include "dsputil.h"
#define FAAN_POSTSCALE
void ff_faandct(DCTELEM * data);
void ff_faandct248(DCTELEM * data);
#endif /* AVCODEC_FAANDCT_H */
| 123linslouis-android-video-cutter | jni/libavcodec/faandct.h | C | asf20 | 1,162 |
/*
* Raw Video Codec
* Copyright (c) 2001 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Raw Video Codec
*/
#include "avcodec.h"
#include "raw.h"
const PixelFormatTag ff_raw_pixelFormatTags[] = {
{ PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */
{ PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') },
{ PIX_FMT_YUV420P, MKTAG('Y', 'V', '1', '2') },
{ PIX_FMT_YUV410P, MKTAG('Y', 'U', 'V', '9') },
{ PIX_FMT_YUV410P, MKTAG('Y', 'V', 'U', '9') },
{ PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') },
{ PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') },
{ PIX_FMT_YUV422P, MKTAG('P', '4', '2', '2') },
{ PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') },
{ PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') },
{ PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */
{ PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') },
{ PIX_FMT_YUYV422, MKTAG('V', '4', '2', '2') },
{ PIX_FMT_YUYV422, MKTAG('V', 'Y', 'U', 'Y') },
{ PIX_FMT_YUYV422, MKTAG('Y', 'U', 'N', 'V') },
{ PIX_FMT_UYVY422, MKTAG('U', 'Y', 'V', 'Y') },
{ PIX_FMT_UYVY422, MKTAG('H', 'D', 'Y', 'C') },
{ PIX_FMT_UYVY422, MKTAG('U', 'Y', 'N', 'V') },
{ PIX_FMT_UYVY422, MKTAG('U', 'Y', 'N', 'Y') },
{ PIX_FMT_UYVY422, MKTAG('u', 'y', 'v', '1') },
{ PIX_FMT_UYVY422, MKTAG('2', 'V', 'u', '1') },
{ PIX_FMT_UYVY422, MKTAG('A', 'V', 'R', 'n') }, /* Avid AVI Codec 1:1 */
{ PIX_FMT_UYVY422, MKTAG('A', 'V', '1', 'x') }, /* Avid 1:1x */
{ PIX_FMT_UYVY422, MKTAG('A', 'V', 'u', 'p') },
{ PIX_FMT_UYVY422, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */
{ PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') },
{ PIX_FMT_RGB555LE, MKTAG('R', 'G', 'B', 15) },
{ PIX_FMT_BGR555LE, MKTAG('B', 'G', 'R', 15) },
{ PIX_FMT_RGB565LE, MKTAG('R', 'G', 'B', 16) },
{ PIX_FMT_BGR565LE, MKTAG('B', 'G', 'R', 16) },
{ PIX_FMT_RGB565LE, MKTAG( 3 , 0 , 0 , 0) },
/* quicktime */
{ PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') },
{ PIX_FMT_UYVY422, MKTAG('2', 'V', 'u', 'y') },
{ PIX_FMT_UYVY422, MKTAG('A', 'V', 'U', 'I') }, /* FIXME merge both fields */
{ PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', '2') },
{ PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', 's') },
{ PIX_FMT_PAL8, MKTAG('W', 'R', 'A', 'W') },
{ PIX_FMT_NONE, 0 },
};
unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt)
{
const PixelFormatTag * tags = ff_raw_pixelFormatTags;
while (tags->pix_fmt >= 0) {
if (tags->pix_fmt == fmt)
return tags->fourcc;
tags++;
}
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/raw.c | C | asf20 | 3,331 |
/*
* BMP image format decoder
* Copyright (c) 2005 Mans Rullgard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
#include "bmp.h"
#include "msrledec.h"
static av_cold int bmp_decode_init(AVCodecContext *avctx){
BMPContext *s = avctx->priv_data;
avcodec_get_frame_defaults((AVFrame*)&s->picture);
avctx->coded_frame = (AVFrame*)&s->picture;
return 0;
}
static int bmp_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
BMPContext *s = avctx->priv_data;
AVFrame *picture = data;
AVFrame *p = &s->picture;
unsigned int fsize, hsize;
int width, height;
unsigned int depth;
BiCompression comp;
unsigned int ihsize;
int i, j, n, linesize;
uint32_t rgb[3];
uint8_t *ptr;
int dsize;
const uint8_t *buf0 = buf;
if(buf_size < 14){
av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size);
return -1;
}
if(bytestream_get_byte(&buf) != 'B' ||
bytestream_get_byte(&buf) != 'M') {
av_log(avctx, AV_LOG_ERROR, "bad magic number\n");
return -1;
}
fsize = bytestream_get_le32(&buf);
if(buf_size < fsize){
av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d), trying to decode anyway\n",
buf_size, fsize);
fsize = buf_size;
}
buf += 2; /* reserved1 */
buf += 2; /* reserved2 */
hsize = bytestream_get_le32(&buf); /* header size */
ihsize = bytestream_get_le32(&buf); /* more header size */
if(ihsize + 14 > hsize){
av_log(avctx, AV_LOG_ERROR, "invalid header size %d\n", hsize);
return -1;
}
/* sometimes file size is set to some headers size, set a real size in that case */
if(fsize == 14 || fsize == ihsize + 14)
fsize = buf_size - 2;
if(fsize <= hsize){
av_log(avctx, AV_LOG_ERROR, "declared file size is less than header size (%d < %d)\n",
fsize, hsize);
return -1;
}
switch(ihsize){
case 40: // windib v3
case 64: // OS/2 v2
case 108: // windib v4
case 124: // windib v5
width = bytestream_get_le32(&buf);
height = bytestream_get_le32(&buf);
break;
case 12: // OS/2 v1
width = bytestream_get_le16(&buf);
height = bytestream_get_le16(&buf);
break;
default:
av_log(avctx, AV_LOG_ERROR, "unsupported BMP file, patch welcome\n");
return -1;
}
if(bytestream_get_le16(&buf) != 1){ /* planes */
av_log(avctx, AV_LOG_ERROR, "invalid BMP header\n");
return -1;
}
depth = bytestream_get_le16(&buf);
if(ihsize == 40)
comp = bytestream_get_le32(&buf);
else
comp = BMP_RGB;
if(comp != BMP_RGB && comp != BMP_BITFIELDS && comp != BMP_RLE4 && comp != BMP_RLE8){
av_log(avctx, AV_LOG_ERROR, "BMP coding %d not supported\n", comp);
return -1;
}
if(comp == BMP_BITFIELDS){
buf += 20;
rgb[0] = bytestream_get_le32(&buf);
rgb[1] = bytestream_get_le32(&buf);
rgb[2] = bytestream_get_le32(&buf);
}
avctx->width = width;
avctx->height = height > 0? height: -height;
avctx->pix_fmt = PIX_FMT_NONE;
switch(depth){
case 32:
if(comp == BMP_BITFIELDS){
rgb[0] = (rgb[0] >> 15) & 3;
rgb[1] = (rgb[1] >> 15) & 3;
rgb[2] = (rgb[2] >> 15) & 3;
if(rgb[0] + rgb[1] + rgb[2] != 3 ||
rgb[0] == rgb[1] || rgb[0] == rgb[2] || rgb[1] == rgb[2]){
break;
}
} else {
rgb[0] = 2;
rgb[1] = 1;
rgb[2] = 0;
}
avctx->pix_fmt = PIX_FMT_BGR24;
break;
case 24:
avctx->pix_fmt = PIX_FMT_BGR24;
break;
case 16:
if(comp == BMP_RGB)
avctx->pix_fmt = PIX_FMT_RGB555;
if(comp == BMP_BITFIELDS)
avctx->pix_fmt = rgb[1] == 0x07E0 ? PIX_FMT_RGB565 : PIX_FMT_RGB555;
break;
case 8:
if(hsize - ihsize - 14 > 0)
avctx->pix_fmt = PIX_FMT_PAL8;
else
avctx->pix_fmt = PIX_FMT_GRAY8;
break;
case 4:
if(hsize - ihsize - 14 > 0){
avctx->pix_fmt = PIX_FMT_PAL8;
}else{
av_log(avctx, AV_LOG_ERROR, "Unknown palette for 16-colour BMP\n");
return -1;
}
break;
case 1:
avctx->pix_fmt = PIX_FMT_MONOBLACK;
break;
default:
av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth);
return -1;
}
if(avctx->pix_fmt == PIX_FMT_NONE){
av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n");
return -1;
}
if(p->data[0])
avctx->release_buffer(avctx, p);
p->reference = 0;
if(avctx->get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
p->pict_type = FF_I_TYPE;
p->key_frame = 1;
buf = buf0 + hsize;
dsize = buf_size - hsize;
/* Line size in file multiple of 4 */
n = ((avctx->width * depth) / 8 + 3) & ~3;
if(n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8){
av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n",
dsize, n * avctx->height);
return -1;
}
// RLE may skip decoding some picture areas, so blank picture before decoding
if(comp == BMP_RLE4 || comp == BMP_RLE8)
memset(p->data[0], 0, avctx->height * p->linesize[0]);
if(depth == 4 || depth == 8)
memset(p->data[1], 0, 1024);
if(height > 0){
ptr = p->data[0] + (avctx->height - 1) * p->linesize[0];
linesize = -p->linesize[0];
} else {
ptr = p->data[0];
linesize = p->linesize[0];
}
if(avctx->pix_fmt == PIX_FMT_PAL8){
int colors = 1 << depth;
if(ihsize >= 36){
int t;
buf = buf0 + 46;
t = bytestream_get_le32(&buf);
if(t < 0 || t > (1 << depth)){
av_log(avctx, AV_LOG_ERROR, "Incorrect number of colors - %X for bitdepth %d\n", t, depth);
}else if(t){
colors = t;
}
}
buf = buf0 + 14 + ihsize; //palette location
if((hsize-ihsize-14) < (colors << 2)){ // OS/2 bitmap, 3 bytes per palette entry
for(i = 0; i < colors; i++)
((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf);
}else{
for(i = 0; i < colors; i++)
((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf);
}
buf = buf0 + hsize;
}
if(comp == BMP_RLE4 || comp == BMP_RLE8){
if(height < 0){
p->data[0] += p->linesize[0] * (avctx->height - 1);
p->linesize[0] = -p->linesize[0];
}
ff_msrle_decode(avctx, (AVPicture*)p, depth, buf, dsize);
if(height < 0){
p->data[0] += p->linesize[0] * (avctx->height - 1);
p->linesize[0] = -p->linesize[0];
}
}else{
switch(depth){
case 1:
case 8:
case 24:
for(i = 0; i < avctx->height; i++){
memcpy(ptr, buf, n);
buf += n;
ptr += linesize;
}
break;
case 4:
for(i = 0; i < avctx->height; i++){
int j;
for(j = 0; j < n; j++){
ptr[j*2+0] = (buf[j] >> 4) & 0xF;
ptr[j*2+1] = buf[j] & 0xF;
}
buf += n;
ptr += linesize;
}
break;
case 16:
for(i = 0; i < avctx->height; i++){
const uint16_t *src = (const uint16_t *) buf;
uint16_t *dst = (uint16_t *) ptr;
for(j = 0; j < avctx->width; j++)
*dst++ = le2me_16(*src++);
buf += n;
ptr += linesize;
}
break;
case 32:
for(i = 0; i < avctx->height; i++){
const uint8_t *src = buf;
uint8_t *dst = ptr;
for(j = 0; j < avctx->width; j++){
dst[0] = src[rgb[2]];
dst[1] = src[rgb[1]];
dst[2] = src[rgb[0]];
dst += 3;
src += 4;
}
buf += n;
ptr += linesize;
}
break;
default:
av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n");
return -1;
}
}
*picture = s->picture;
*data_size = sizeof(AVPicture);
return buf_size;
}
static av_cold int bmp_decode_end(AVCodecContext *avctx)
{
BMPContext* c = avctx->priv_data;
if (c->picture.data[0])
avctx->release_buffer(avctx, &c->picture);
return 0;
}
AVCodec bmp_decoder = {
"bmp",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_BMP,
sizeof(BMPContext),
bmp_decode_init,
NULL,
bmp_decode_end,
bmp_decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("BMP image"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/bmp.c | C | asf20 | 10,052 |
/*
* copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
* copyright (c) 2004 Maarten Daniels
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* H.261 tables.
*/
#ifndef AVCODEC_H261DATA_H
#define AVCODEC_H261DATA_H
#include <stdint.h>
#include "h261.h"
// H.261 VLC table for macroblock addressing
static const uint8_t h261_mba_code[35] = {
1, 3, 2, 3,
2, 3, 2, 7,
6, 11, 10, 9,
8, 7, 6, 23,
22, 21, 20, 19,
18, 35, 34, 33,
32, 31, 30, 29,
28, 27, 26, 25,
24,
15, //(MBA stuffing)
1 //(start code)
};
static const uint8_t h261_mba_bits[35] = {
1, 3, 3, 4,
4, 5, 5, 7,
7, 8, 8, 8,
8, 8, 8, 10,
10, 10, 10, 10,
10, 11, 11, 11,
11, 11, 11, 11,
11, 11, 11, 11,
11,
11, //(MBA stuffing)
16 //(start code)
};
//H.261 VLC table for macroblock type
static const uint8_t h261_mtype_code[10] = {
1, 1, 1, 1,
1, 1, 1, 1,
1, 1
};
static const uint8_t h261_mtype_bits[10] = {
4, 7, 1, 5,
9, 8, 10, 3,
2, 6
};
static const int h261_mtype_map[10]= {
MB_TYPE_INTRA4x4,
MB_TYPE_INTRA4x4 | MB_TYPE_QUANT,
MB_TYPE_CBP,
MB_TYPE_QUANT | MB_TYPE_CBP,
MB_TYPE_16x16,
MB_TYPE_CBP | MB_TYPE_16x16,
MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16,
MB_TYPE_16x16 | MB_TYPE_H261_FIL,
MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL,
MB_TYPE_QUANT | MB_TYPE_CBP | MB_TYPE_16x16 | MB_TYPE_H261_FIL
};
//H.261 VLC table for motion vectors
static const uint8_t h261_mv_tab[17][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}
};
static const int mvmap[17] =
{
0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
};
//H.261 VLC table for coded block pattern
static const uint8_t h261_cbp_tab[63][2] =
{
{11,5}, {9,5}, {13,6}, {13,4}, {23,7}, {19,7}, {31,8}, {12,4},
{22,7}, {18,7}, {30,8}, {19,5}, {27,8}, {23,8}, {19,8}, {11,4},
{21,7}, {17,7}, {29,8}, {17,5}, {25,8}, {21,8}, {17,8}, {15,6},
{15,8}, {13,8}, {3,9}, {15,5}, {11,8}, {7,8}, {7,9}, {10,4},
{20,7}, {16,7}, {28,8}, {14,6}, {14,8}, {12,8}, {2,9}, {16,5},
{24,8}, {20,8}, {16,8}, {14,5}, {10,8}, {6,8}, {6,9}, {18,5},
{26,8}, {22,8}, {18,8}, {13,5}, {9,8}, {5,8}, {5,9}, {12,5},
{8,8}, {4,8}, {4,9}, {7,3}, {10,5}, {8,5}, {12,6}
};
//H.261 VLC table for transform coefficients
static const uint16_t h261_tcoeff_vlc[65][2] = {
{ 0x2, 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 },
{ 0x3, 3 }, { 0x6, 6 }, { 0x25 , 8 }, { 0xc, 10 },
{ 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 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 },
{ 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12},
{ 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 },
{ 0x23, 8 }, { 0x22, 8 }, { 0x20, 8 }, { 0xe , 10 },
{ 0xd, 10 }, { 0x8, 10 },{ 0x1f, 12 }, { 0x1a, 12 },
{ 0x19, 12 }, { 0x17, 12 }, { 0x16, 12}, { 0x1f, 13},
{ 0x1e, 13 }, { 0x1d, 13 }, { 0x1c, 13}, { 0x1b, 13},
{ 0x1, 6 } //escape
};
static const int8_t h261_tcoeff_level[64] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
1, 2, 3, 4, 5, 6, 7, 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, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
};
static const int8_t h261_tcoeff_run[64] = {
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, 2, 3, 3, 3, 3, 4,
4, 4, 5, 5, 5, 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
};
static RLTable h261_rl_tcoeff = {
64,
64,
h261_tcoeff_vlc,
h261_tcoeff_run,
h261_tcoeff_level,
};
#endif /* AVCODEC_H261DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/h261data.h | C | asf20 | 5,358 |
/*
* RV20 encoder
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* RV20 encoder
*/
#include "mpegvideo.h"
#include "h263.h"
#include "put_bits.h"
void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
put_bits(&s->pb, 1, 0); /* unknown bit */
put_bits(&s->pb, 5, s->qscale);
put_sbits(&s->pb, 8, picture_number); //FIXME wrong, but correct is not known
s->mb_x= s->mb_y= 0;
ff_h263_encode_mba(s);
put_bits(&s->pb, 1, s->no_rounding);
assert(s->f_code == 1);
assert(s->unrestricted_mv == 1);
assert(s->alt_inter_vlc == 0);
assert(s->umvplus == 0);
assert(s->modified_quant==1);
assert(s->loop_filter==1);
s->h263_aic= s->pict_type == FF_I_TYPE;
if(s->h263_aic){
s->y_dc_scale_table=
s->c_dc_scale_table= ff_aic_dc_scale_table;
}else{
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
}
}
AVCodec rv20_encoder = {
"rv20",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_RV20,
sizeof(MpegEncContext),
MPV_encode_init,
MPV_encode_picture,
MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/rv20enc.c | C | asf20 | 2,109 |
/*
* MJPEG decoder
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2003 Alex Beregszaszi
* Copyright (c) 2003-2004 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MJPEG decoder.
*/
#ifndef AVCODEC_MJPEGDEC_H
#define AVCODEC_MJPEGDEC_H
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
#define MAX_COMPONENTS 4
typedef struct MJpegDecodeContext {
AVCodecContext *avctx;
GetBitContext gb;
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_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 ls;
int progressive;
int rgb;
int rct; /* standard rct */
int pegasus_rct; /* pegasus reversible colorspace transform */
int bits; /* bits per component */
int maxval;
int near; ///< near lossless bound (si 0 for lossless)
int t1,t2,t3;
int reset; ///< context halfing intervall ?rename
int width, height;
int mb_width, mb_height;
int nb_components;
int block_stride[MAX_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 ?) */
AVFrame picture; /* picture structure */
int got_picture; ///< we found a SOF and picture is valid, too.
int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
int8_t *qscale_table;
DECLARE_ALIGNED(16, DCTELEM, block)[64];
DCTELEM (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode)
uint8_t *last_nnz[MAX_COMPONENTS];
uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode)
ScanTable scantable;
DSPContext dsp;
int restart_interval;
int restart_count;
int buggy_avid;
int cs_itu601;
int interlace_polarity;
int mjpb_skiptosod;
int cur_scan; /* current scan, used by JPEG-LS */
int flipped; /* true if picture is flipped */
uint16_t (*ljpeg_buffer)[4];
unsigned int ljpeg_buffer_size;
} MJpegDecodeContext;
int ff_mjpeg_decode_init(AVCodecContext *avctx);
int ff_mjpeg_decode_end(AVCodecContext *avctx);
int ff_mjpeg_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt);
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s);
int ff_mjpeg_decode_dht(MJpegDecodeContext *s);
int ff_mjpeg_decode_sof(MJpegDecodeContext *s);
int ff_mjpeg_decode_sos(MJpegDecodeContext *s);
#endif /* AVCODEC_MJPEGDEC_H */
| 123linslouis-android-video-cutter | jni/libavcodec/mjpegdec.h | C | asf20 | 4,091 |
/*
* Range coder
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Range coder.
* based upon
* "Range encoding: an algorithm for removing redundancy from a digitised
* message.
* G. N. N. Martin Presented in March 1979 to the Video &
* Data Recording Conference,
* IBM UK Scientific Center held in Southampton July 24-27 1979."
*
*/
#include <string.h>
#include "avcodec.h"
#include "rangecoder.h"
#include "bytestream.h"
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){
c->bytestream_start=
c->bytestream= buf;
c->bytestream_end= buf + buf_size;
c->low= 0;
c->range= 0xFF00;
c->outstanding_count= 0;
c->outstanding_byte= -1;
}
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){
/* cast to avoid compiler warning */
ff_init_range_encoder(c, (uint8_t *) buf, buf_size);
c->low = bytestream_get_be16(&c->bytestream);
}
void ff_build_rac_states(RangeCoder *c, int factor, int max_p){
const int64_t one= 1LL<<32;
int64_t p;
int last_p8, p8, i;
memset(c->zero_state, 0, sizeof(c->zero_state));
memset(c-> one_state, 0, sizeof(c-> one_state));
last_p8= 0;
p= one/2;
for(i=0; i<128; i++){
p8= (256*p + one/2) >> 32; //FIXME try without the one
if(p8 <= last_p8) p8= last_p8+1;
if(last_p8 && last_p8<256 && p8<=max_p)
c->one_state[last_p8]= p8;
p+= ((one-p)*factor + one/2) >> 32;
last_p8= p8;
}
for(i=256-max_p; i<=max_p; i++){
if(c->one_state[i])
continue;
p= (i*one + 128) >> 8;
p+= ((one-p)*factor + one/2) >> 32;
p8= (256*p + one/2) >> 32; //FIXME try without the one
if(p8 <= i) p8= i+1;
if(p8 > max_p) p8= max_p;
c->one_state[ i]= p8;
}
for(i=1; i<255; i++)
c->zero_state[i]= 256-c->one_state[256-i];
}
/**
*
* @return the number of bytes written
*/
int ff_rac_terminate(RangeCoder *c){
c->range=0xFF;
c->low +=0xFF;
renorm_encoder(c);
c->range=0xFF;
renorm_encoder(c);
assert(c->low == 0);
assert(c->range >= 0x100);
return c->bytestream - c->bytestream_start;
}
#ifdef TEST
#define SIZE 10240
#include "libavutil/lfg.h"
int main(void){
RangeCoder c;
uint8_t b[9*SIZE];
uint8_t r[9*SIZE];
int i;
uint8_t state[10]= {0};
AVLFG prng;
av_lfg_init(&prng, 1);
ff_init_range_encoder(&c, b, SIZE);
ff_build_rac_states(&c, 0.05*(1LL<<32), 128+64+32+16);
memset(state, 128, sizeof(state));
for(i=0; i<SIZE; i++){
r[i] = av_lfg_get(&prng) % 7;
}
for(i=0; i<SIZE; i++){
START_TIMER
put_rac(&c, state, r[i]&1);
STOP_TIMER("put_rac")
}
ff_rac_terminate(&c);
ff_init_range_decoder(&c, b, SIZE);
memset(state, 128, sizeof(state));
for(i=0; i<SIZE; i++){
START_TIMER
if( (r[i]&1) != get_rac(&c, state) )
av_log(NULL, AV_LOG_DEBUG, "rac failure at %d\n", i);
STOP_TIMER("get_rac")
}
return 0;
}
#endif /* TEST */
| 123linslouis-android-video-cutter | jni/libavcodec/rangecoder.c | C | asf20 | 3,943 |
/*
* copyright (C) 2003 the ffmpeg project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_VP3DATA_H
#define AVCODEC_VP3DATA_H
#include <stdint.h>
#include <stdlib.h>
/* these coefficients dequantize intraframe Y plane coefficients
* (note: same as JPEG) */
static const 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
* (note: same as JPEG) */
static const 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 const 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 const 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 const uint32_t vp31_ac_scale_factor[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
};
static const uint8_t vp31_filter_limit_values[64] =
{ 30, 25, 20, 20, 15, 15, 14, 14,
13, 13, 12, 12, 11, 11, 10, 10,
9, 9, 8, 8, 7, 7, 7, 7,
6, 6, 6, 6, 5, 5, 5, 5,
4, 4, 4, 4, 3, 3, 3, 3,
2, 2, 2, 2, 2, 2, 2, 2,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static const uint16_t superblock_run_length_vlc_table[34][2] = {
{ 0, 1 },
{ 4, 3 }, { 5, 3 },
{ 0xC, 4 }, { 0xD, 4 },
{ 0x38, 6 }, { 0x39, 6 }, { 0x3A, 6 }, { 0x3B, 6 },
{ 0xF0, 8 }, { 0xF1, 8 }, { 0xF2, 8 }, { 0xF3, 8 },
{ 0xF4, 8 }, { 0xF5, 8 }, { 0xF6, 8 }, { 0xF7, 8 },
{ 0x3E0, 10 }, { 0x3E1, 10 }, { 0x3E2, 10 }, { 0x3E3, 10 },
{ 0x3E4, 10 }, { 0x3E5, 10 }, { 0x3E6, 10 }, { 0x3E7, 10 },
{ 0x3E8, 10 }, { 0x3E9, 10 }, { 0x3EA, 10 }, { 0x3EB, 10 },
{ 0x3EC, 10 }, { 0x3ED, 10 }, { 0x3EE, 10 }, { 0x3EF, 10 },
{ 0x3F, 6 } /* this last VLC is a special case for reading 12 more
bits from stream and adding the value 34 */
};
static const uint16_t fragment_run_length_vlc_table[30][2] = {
/* 1 -> 2 */
{ 0x0, 2 }, { 0x1, 2 },
/* 3 -> 4 */
{ 0x4, 3 }, { 0x5, 3 },
/* 5 -> 6 */
{ 0xC, 4 }, { 0xD, 4 },
/* 7 -> 10 */
{ 0x38, 6 }, { 0x39, 6 },
{ 0x3A, 6 }, { 0x3B, 6 },
/* 11 -> 14 */
{ 0x78, 7 }, { 0x79, 7 },
{ 0x7A, 7 }, { 0x7B, 7 },
/* 15 -> 30 */
{ 0x1F0, 9 }, { 0x1F1, 9 }, { 0x1F2, 9 }, { 0x1F3, 9 },
{ 0x1F4, 9 }, { 0x1F5, 9 }, { 0x1F6, 9 }, { 0x1F7, 9 },
{ 0x1F8, 9 }, { 0x1F9, 9 }, { 0x1FA, 9 }, { 0x1FB, 9 },
{ 0x1FC, 9 }, { 0x1FD, 9 }, { 0x1FE, 9 }, { 0x1FF, 9 }
};
static const uint8_t mode_code_vlc_table[8][2] = {
{ 0, 1 }, { 2, 2 },
{ 6, 3 }, { 14, 4 },
{ 30, 5 }, { 62, 6 },
{ 126, 7 }, { 127, 7 }
};
static const uint8_t motion_vector_vlc_table[63][2] = {
{ 0, 3 },
{ 1, 3 },
{ 2, 3 },
{ 6, 4 }, { 7, 4 },
{ 8, 4 }, { 9, 4 },
{ 40, 6 }, { 41, 6 }, { 42, 6 }, { 43, 6 },
{ 44, 6 }, { 45, 6 }, { 46, 6 }, { 47, 6 },
{ 96, 7 }, { 97, 7 }, { 98, 7 }, { 99, 7 },
{ 100, 7 }, { 101, 7 }, { 102, 7 }, { 103, 7 },
{ 104, 7 }, { 105, 7 }, { 106, 7 }, { 107, 7 },
{ 108, 7 }, { 109, 7 }, { 110, 7 }, { 111, 7 },
{ 0xE0, 8 }, { 0xE1, 8 }, { 0xE2, 8 }, { 0xE3, 8 },
{ 0xE4, 8 }, { 0xE5, 8 }, { 0xE6, 8 }, { 0xE7, 8 },
{ 0xE8, 8 }, { 0xE9, 8 }, { 0xEA, 8 }, { 0xEB, 8 },
{ 0xEC, 8 }, { 0xED, 8 }, { 0xEE, 8 }, { 0xEF, 8 },
{ 0xF0, 8 }, { 0xF1, 8 }, { 0xF2, 8 }, { 0xF3, 8 },
{ 0xF4, 8 }, { 0xF5, 8 }, { 0xF6, 8 }, { 0xF7, 8 },
{ 0xF8, 8 }, { 0xF9, 8 }, { 0xFA, 8 }, { 0xFB, 8 },
{ 0xFC, 8 }, { 0xFD, 8 }, { 0xFE, 8 }, { 0xFF, 8 }
};
static const int motion_vector_table[63] = {
0, 1, -1,
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, -14, 15, -15,
16, -16, 17, -17, 18, -18, 19, -19, 20, -20, 21, -21, 22, -22, 23, -23,
24, -24, 25, -25, 26, -26, 27, -27, 28, -28, 29, -29, 30, -30, 31, -31
};
static const int8_t fixed_motion_vector_table[64] = {
0, 0, 1, -1, 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, -14, 15, -15,
16, -16, 17, -17, 18, -18, 19, -19,
20, -20, 21, -21, 22, -22, 23, -23,
24, -24, 25, -25, 26, -26, 27, -27,
28, -28, 29, -29, 30, -30, 31, -31
};
/* only tokens 0..6 indicate eob runs */
static const int eob_run_base[7] = {
1, 2, 3, 4, 8, 16, 0
};
static const int eob_run_get_bits[7] = {
0, 0, 0, 2, 3, 4, 12
};
static const int zero_run_base[32] = {
0, 0, 0, 0, 0, 0, 0, /* 0..6 are never used */
0, 0, /* 7..8 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9..22 */
1, 2, 3, 4, 5, /* 23..27 */
6, 10, 1, 2 /* 28..31 */
};
static const int zero_run_get_bits[32] = {
0, 0, 0, 0, 0, 0, 0, /* 0..6 are never used */
3, 6, /* 7..8 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 9..22 */
0, 0, 0, 0, 0, /* 23..27 */
2, 3, 0, 1 /* 28..31 */
};
static const int coeff_get_bits[32] = {
0, 0, 0, 0, 0, 0, 0, /* 0..6 are never used */
0, 0, 0, 0, 0, 0, /* 7..12 use constant coeffs */
1, 1, 1, 1, /* 13..16 are constants but still need sign bit */
2, 3, 4, 5, 6, 10, /* 17..22, for reading large coeffs */
1, 1, 1, 1, 1, 1, 1, /* 23..29 are constants but still need sign bit */
2, 2 /* 30..31 */
};
static const int16_t coeff_table_token_7_8[1] = { 0 };
static const int16_t coeff_table_token_9[1] = { 1 };
static const int16_t coeff_table_token_10[1] = { -1 };
static const int16_t coeff_table_token_11[1] = { 2 };
static const int16_t coeff_table_token_12[1] = { -2 };
static const int16_t coeff_table_token_13[2] = { 3, -3 };
static const int16_t coeff_table_token_14[2] = { 4, -4 };
static const int16_t coeff_table_token_15[2] = { 5, -5 };
static const int16_t coeff_table_token_16[2] = { 6, -6 };
static const int16_t coeff_table_token_23_24_25_26_27_28_29[2] = { 1, -1 };
static const int16_t coeff_table_token_30[4] = { 2, 3, -2, -3 };
static const int16_t coeff_table_token_31[4] = { 2, 3, -2, -3 };
static const int16_t coeff_table_token_17[4] = {
7, 8, -7, -8
};
static const int16_t coeff_table_token_18[8] = {
9, 10, 11, 12, -9, -10, -11, -12
};
static const int16_t coeff_table_token_19[16] = {
13, 14, 15, 16, 17, 18, 19, 20, -13, -14, -15, -16, -17, -18, -19, -20
};
static const int16_t coeff_table_token_20[32] = {
21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36,
-21, -22, -23, -24, -25, -26, -27, -28,
-29, -30, -31, -32, -33, -34, -35, -36
};
static const int16_t coeff_table_token_21[64] = {
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,
-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
};
static const int16_t coeff_table_token_22[1024] = {
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, 256, 257, 258, 259, 260,
261, 262, 263, 264, 265, 266, 267, 268,
269, 270, 271, 272, 273, 274, 275, 276,
277, 278, 279, 280, 281, 282, 283, 284,
285, 286, 287, 288, 289, 290, 291, 292,
293, 294, 295, 296, 297, 298, 299, 300,
301, 302, 303, 304, 305, 306, 307, 308,
309, 310, 311, 312, 313, 314, 315, 316,
317, 318, 319, 320, 321, 322, 323, 324,
325, 326, 327, 328, 329, 330, 331, 332,
333, 334, 335, 336, 337, 338, 339, 340,
341, 342, 343, 344, 345, 346, 347, 348,
349, 350, 351, 352, 353, 354, 355, 356,
357, 358, 359, 360, 361, 362, 363, 364,
365, 366, 367, 368, 369, 370, 371, 372,
373, 374, 375, 376, 377, 378, 379, 380,
381, 382, 383, 384, 385, 386, 387, 388,
389, 390, 391, 392, 393, 394, 395, 396,
397, 398, 399, 400, 401, 402, 403, 404,
405, 406, 407, 408, 409, 410, 411, 412,
413, 414, 415, 416, 417, 418, 419, 420,
421, 422, 423, 424, 425, 426, 427, 428,
429, 430, 431, 432, 433, 434, 435, 436,
437, 438, 439, 440, 441, 442, 443, 444,
445, 446, 447, 448, 449, 450, 451, 452,
453, 454, 455, 456, 457, 458, 459, 460,
461, 462, 463, 464, 465, 466, 467, 468,
469, 470, 471, 472, 473, 474, 475, 476,
477, 478, 479, 480, 481, 482, 483, 484,
485, 486, 487, 488, 489, 490, 491, 492,
493, 494, 495, 496, 497, 498, 499, 500,
501, 502, 503, 504, 505, 506, 507, 508,
509, 510, 511, 512, 513, 514, 515, 516,
517, 518, 519, 520, 521, 522, 523, 524,
525, 526, 527, 528, 529, 530, 531, 532,
533, 534, 535, 536, 537, 538, 539, 540,
541, 542, 543, 544, 545, 546, 547, 548,
549, 550, 551, 552, 553, 554, 555, 556,
557, 558, 559, 560, 561, 562, 563, 564,
565, 566, 567, 568, 569, 570, 571, 572,
573, 574, 575, 576, 577, 578, 579, 580,
-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, -256, -257, -258, -259, -260,
-261, -262, -263, -264, -265, -266, -267, -268,
-269, -270, -271, -272, -273, -274, -275, -276,
-277, -278, -279, -280, -281, -282, -283, -284,
-285, -286, -287, -288, -289, -290, -291, -292,
-293, -294, -295, -296, -297, -298, -299, -300,
-301, -302, -303, -304, -305, -306, -307, -308,
-309, -310, -311, -312, -313, -314, -315, -316,
-317, -318, -319, -320, -321, -322, -323, -324,
-325, -326, -327, -328, -329, -330, -331, -332,
-333, -334, -335, -336, -337, -338, -339, -340,
-341, -342, -343, -344, -345, -346, -347, -348,
-349, -350, -351, -352, -353, -354, -355, -356,
-357, -358, -359, -360, -361, -362, -363, -364,
-365, -366, -367, -368, -369, -370, -371, -372,
-373, -374, -375, -376, -377, -378, -379, -380,
-381, -382, -383, -384, -385, -386, -387, -388,
-389, -390, -391, -392, -393, -394, -395, -396,
-397, -398, -399, -400, -401, -402, -403, -404,
-405, -406, -407, -408, -409, -410, -411, -412,
-413, -414, -415, -416, -417, -418, -419, -420,
-421, -422, -423, -424, -425, -426, -427, -428,
-429, -430, -431, -432, -433, -434, -435, -436,
-437, -438, -439, -440, -441, -442, -443, -444,
-445, -446, -447, -448, -449, -450, -451, -452,
-453, -454, -455, -456, -457, -458, -459, -460,
-461, -462, -463, -464, -465, -466, -467, -468,
-469, -470, -471, -472, -473, -474, -475, -476,
-477, -478, -479, -480, -481, -482, -483, -484,
-485, -486, -487, -488, -489, -490, -491, -492,
-493, -494, -495, -496, -497, -498, -499, -500,
-501, -502, -503, -504, -505, -506, -507, -508,
-509, -510, -511, -512, -513, -514, -515, -516,
-517, -518, -519, -520, -521, -522, -523, -524,
-525, -526, -527, -528, -529, -530, -531, -532,
-533, -534, -535, -536, -537, -538, -539, -540,
-541, -542, -543, -544, -545, -546, -547, -548,
-549, -550, -551, -552, -553, -554, -555, -556,
-557, -558, -559, -560, -561, -562, -563, -564,
-565, -566, -567, -568, -569, -570, -571, -572,
-573, -574, -575, -576, -577, -578, -579, -580
};
static const int16_t *const coeff_tables[32] = {
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
coeff_table_token_7_8,
coeff_table_token_7_8,
coeff_table_token_9,
coeff_table_token_10,
coeff_table_token_11,
coeff_table_token_12,
coeff_table_token_13,
coeff_table_token_14,
coeff_table_token_15,
coeff_table_token_16,
coeff_table_token_17,
coeff_table_token_18,
coeff_table_token_19,
coeff_table_token_20,
coeff_table_token_21,
coeff_table_token_22,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_23_24_25_26_27_28_29,
coeff_table_token_30,
coeff_table_token_31
};
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 /* AVCODEC_VP3DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/vp3data.h | C | asf20 | 64,158 |
/*
* H.263 parser
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_H263_PARSER_H
#define AVCODEC_H263_PARSER_H
#include "parser.h"
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size);
#endif /* AVCODEC_H263_PARSER_H */
| 123linslouis-android-video-cutter | jni/libavcodec/h263_parser.h | C | asf20 | 1,047 |
/*
* samplerate conversion for both audio and video
* Copyright (c) 2000 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* samplerate conversion for both audio and video
*/
#include "avcodec.h"
#include "audioconvert.h"
#include "opt.h"
struct AVResampleContext;
static const char *context_to_name(void *ptr)
{
return "audioresample";
}
static const AVOption options[] = {{NULL}};
static const AVClass audioresample_context_class = { "ReSampleContext", context_to_name, options, LIBAVUTIL_VERSION_INT };
struct ReSampleContext {
struct AVResampleContext *resample_context;
short *temp[2];
int temp_len;
float ratio;
/* channel convert */
int input_channels, output_channels, filter_channels;
AVAudioConvert *convert_ctx[2];
enum SampleFormat sample_fmt[2]; ///< input and output sample format
unsigned sample_size[2]; ///< size of one sample in sample_fmt
short *buffer[2]; ///< buffers used for conversion to S16
unsigned buffer_size[2]; ///< sizes of allocated buffers
};
/* 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 */
}
}
ReSampleContext *av_audio_resample_init(int output_channels, int input_channels,
int output_rate, int input_rate,
enum SampleFormat sample_fmt_out,
enum SampleFormat sample_fmt_in,
int filter_length, int log2_phase_count,
int linear, double cutoff)
{
ReSampleContext *s;
if ( input_channels > 2)
{
av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.\n");
return NULL;
}
s = av_mallocz(sizeof(ReSampleContext));
if (!s)
{
av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context.\n");
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;
s->sample_fmt [0] = sample_fmt_in;
s->sample_fmt [1] = sample_fmt_out;
s->sample_size[0] = av_get_bits_per_sample_format(s->sample_fmt[0])>>3;
s->sample_size[1] = av_get_bits_per_sample_format(s->sample_fmt[1])>>3;
if (s->sample_fmt[0] != SAMPLE_FMT_S16) {
if (!(s->convert_ctx[0] = av_audio_convert_alloc(SAMPLE_FMT_S16, 1,
s->sample_fmt[0], 1, NULL, 0))) {
av_log(s, AV_LOG_ERROR,
"Cannot convert %s sample format to s16 sample format\n",
avcodec_get_sample_fmt_name(s->sample_fmt[0]));
av_free(s);
return NULL;
}
}
if (s->sample_fmt[1] != SAMPLE_FMT_S16) {
if (!(s->convert_ctx[1] = av_audio_convert_alloc(s->sample_fmt[1], 1,
SAMPLE_FMT_S16, 1, NULL, 0))) {
av_log(s, AV_LOG_ERROR,
"Cannot convert s16 sample format to %s sample format\n",
avcodec_get_sample_fmt_name(s->sample_fmt[1]));
av_audio_convert_free(s->convert_ctx[0]);
av_free(s);
return NULL;
}
}
/*
* AC-3 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;
#define TAPS 16
s->resample_context= av_resample_init(output_rate, input_rate,
filter_length, log2_phase_count, linear, cutoff);
*(const AVClass**)s->resample_context = &audioresample_context_class;
return s;
}
#if LIBAVCODEC_VERSION_MAJOR < 53
ReSampleContext *audio_resample_init(int output_channels, int input_channels,
int output_rate, int input_rate)
{
return av_audio_resample_init(output_channels, input_channels,
output_rate, input_rate,
SAMPLE_FMT_S16, SAMPLE_FMT_S16,
TAPS, 10, 0, 0.8);
}
#endif
/* resample audio. 'nb_samples' is the number of input samples */
/* XXX: optimize it ! */
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];
short *output_bak = NULL;
int lenout;
if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
/* nothing to do */
memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
return nb_samples;
}
if (s->sample_fmt[0] != SAMPLE_FMT_S16) {
int istride[1] = { s->sample_size[0] };
int ostride[1] = { 2 };
const void *ibuf[1] = { input };
void *obuf[1];
unsigned input_size = nb_samples*s->input_channels*2;
if (!s->buffer_size[0] || s->buffer_size[0] < input_size) {
av_free(s->buffer[0]);
s->buffer_size[0] = input_size;
s->buffer[0] = av_malloc(s->buffer_size[0]);
if (!s->buffer[0]) {
av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
return 0;
}
}
obuf[0] = s->buffer[0];
if (av_audio_convert(s->convert_ctx[0], obuf, ostride,
ibuf, istride, nb_samples*s->input_channels) < 0) {
av_log(s->resample_context, AV_LOG_ERROR, "Audio sample format conversion failed\n");
return 0;
}
input = s->buffer[0];
}
lenout= 4*nb_samples * s->ratio + 16;
if (s->sample_fmt[1] != SAMPLE_FMT_S16) {
output_bak = output;
if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {
av_free(s->buffer[1]);
s->buffer_size[1] = lenout;
s->buffer[1] = av_malloc(s->buffer_size[1]);
if (!s->buffer[1]) {
av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
return 0;
}
}
output = s->buffer[1];
}
/* XXX: move those malloc to resample init code */
for(i=0; i<s->filter_channels; i++){
bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
buftmp2[i] = bufin[i] + s->temp_len;
}
/* make some zoom to avoid round pb */
bufout[0]= av_malloc( lenout * sizeof(short) );
bufout[1]= av_malloc( lenout * sizeof(short) );
if (s->input_channels == 2 &&
s->output_channels == 1) {
buftmp3[0] = output;
stereo_to_mono(buftmp2[0], input, nb_samples);
} else if (s->output_channels >= 2 && s->input_channels == 1) {
buftmp3[0] = bufout[0];
memcpy(buftmp2[0], input, nb_samples*sizeof(short));
} else if (s->output_channels >= 2) {
buftmp3[0] = bufout[0];
buftmp3[1] = bufout[1];
stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
} else {
buftmp3[0] = output;
memcpy(buftmp2[0], input, nb_samples*sizeof(short));
}
nb_samples += s->temp_len;
/* resample each channel */
nb_samples1 = 0; /* avoid warning */
for(i=0;i<s->filter_channels;i++) {
int consumed;
int is_last= i+1 == s->filter_channels;
nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);
s->temp_len= nb_samples - consumed;
s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));
memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));
}
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);
}
if (s->sample_fmt[1] != SAMPLE_FMT_S16) {
int istride[1] = { 2 };
int ostride[1] = { s->sample_size[1] };
const void *ibuf[1] = { output };
void *obuf[1] = { output_bak };
if (av_audio_convert(s->convert_ctx[1], obuf, ostride,
ibuf, istride, nb_samples1*s->output_channels) < 0) {
av_log(s->resample_context, AV_LOG_ERROR, "Audio sample format convertion failed\n");
return 0;
}
}
for(i=0; i<s->filter_channels; i++)
av_free(bufin[i]);
av_free(bufout[0]);
av_free(bufout[1]);
return nb_samples1;
}
void audio_resample_close(ReSampleContext *s)
{
av_resample_close(s->resample_context);
av_freep(&s->temp[0]);
av_freep(&s->temp[1]);
av_freep(&s->buffer[0]);
av_freep(&s->buffer[1]);
av_audio_convert_free(s->convert_ctx[0]);
av_audio_convert_free(s->convert_ctx[1]);
av_free(s);
}
| 123linslouis-android-video-cutter | jni/libavcodec/resample.c | C | asf20 | 11,859 |
/*
* E-AC-3 decoder
* Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
* Copyright (c) 2008 Justin Ruggles
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* There are several features of E-AC-3 that this decoder does not yet support.
*
* Enhanced Coupling
* No known samples exist. If any ever surface, this feature should not be
* too difficult to implement.
*
* Reduced Sample Rates
* No known samples exist. The spec also does not give clear information
* on how this is to be implemented.
*
* Dependent Streams
* Only the independent stream is currently decoded. Any dependent
* streams are skipped. We have only come across two examples of this, and
* they are both just test streams, one for HD-DVD and the other for
* Blu-ray.
*
* Transient Pre-noise Processing
* This is side information which a decoder should use to reduce artifacts
* caused by transients. There are samples which are known to have this
* information, but this decoder currently ignores it.
*/
#include "avcodec.h"
#include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3.h"
#include "ac3_parser.h"
#include "ac3dec.h"
#include "ac3dec_data.h"
#include "eac3dec_data.h"
/** gain adaptive quantization mode */
typedef enum {
EAC3_GAQ_NO =0,
EAC3_GAQ_12,
EAC3_GAQ_14,
EAC3_GAQ_124
} EAC3GaqMode;
#define EAC3_SR_CODE_REDUCED 3
void ff_eac3_apply_spectral_extension(AC3DecodeContext *s)
{
int bin, bnd, ch, i;
uint8_t wrapflag[SPX_MAX_BANDS]={1,0,}, num_copy_sections, copy_sizes[SPX_MAX_BANDS];
float rms_energy[SPX_MAX_BANDS];
/* Set copy index mapping table. Set wrap flags to apply a notch filter at
wrap points later on. */
bin = s->spx_dst_start_freq;
num_copy_sections = 0;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
int copysize;
int bandsize = s->spx_band_sizes[bnd];
if (bin + bandsize > s->spx_src_start_freq) {
copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
bin = s->spx_dst_start_freq;
wrapflag[bnd] = 1;
}
for (i = 0; i < bandsize; i += copysize) {
if (bin == s->spx_src_start_freq) {
copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
bin = s->spx_dst_start_freq;
}
copysize = FFMIN(bandsize - i, s->spx_src_start_freq - bin);
bin += copysize;
}
}
copy_sizes[num_copy_sections++] = bin - s->spx_dst_start_freq;
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (!s->channel_uses_spx[ch])
continue;
/* Copy coeffs from normal bands to extension bands */
bin = s->spx_src_start_freq;
for (i = 0; i < num_copy_sections; i++) {
memcpy(&s->transform_coeffs[ch][bin],
&s->transform_coeffs[ch][s->spx_dst_start_freq],
copy_sizes[i]*sizeof(float));
bin += copy_sizes[i];
}
/* Calculate RMS energy for each SPX band. */
bin = s->spx_src_start_freq;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
int bandsize = s->spx_band_sizes[bnd];
float accum = 0.0f;
for (i = 0; i < bandsize; i++) {
float coeff = s->transform_coeffs[ch][bin++];
accum += coeff * coeff;
}
rms_energy[bnd] = sqrtf(accum / bandsize);
}
/* Apply a notch filter at transitions between normal and extension
bands and at all wrap points. */
if (s->spx_atten_code[ch] >= 0) {
const float *atten_tab = ff_eac3_spx_atten_tab[s->spx_atten_code[ch]];
bin = s->spx_src_start_freq - 2;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
if (wrapflag[bnd]) {
float *coeffs = &s->transform_coeffs[ch][bin];
coeffs[0] *= atten_tab[0];
coeffs[1] *= atten_tab[1];
coeffs[2] *= atten_tab[2];
coeffs[3] *= atten_tab[1];
coeffs[4] *= atten_tab[0];
}
bin += s->spx_band_sizes[bnd];
}
}
/* Apply noise-blended coefficient scaling based on previously
calculated RMS energy, blending factors, and SPX coordinates for
each band. */
bin = s->spx_src_start_freq;
for (bnd = 0; bnd < s->num_spx_bands; bnd++) {
float nscale = s->spx_noise_blend[ch][bnd] * rms_energy[bnd] * (1.0f/(1<<31));
float sscale = s->spx_signal_blend[ch][bnd];
for (i = 0; i < s->spx_band_sizes[bnd]; i++) {
float noise = nscale * (int32_t)av_lfg_get(&s->dith_state);
s->transform_coeffs[ch][bin] *= sscale;
s->transform_coeffs[ch][bin++] += noise;
}
}
}
}
/** lrint(M_SQRT2*cos(2*M_PI/12)*(1<<23)) */
#define COEFF_0 10273905LL
/** lrint(M_SQRT2*cos(0*M_PI/12)*(1<<23)) = lrint(M_SQRT2*(1<<23)) */
#define COEFF_1 11863283LL
/** lrint(M_SQRT2*cos(5*M_PI/12)*(1<<23)) */
#define COEFF_2 3070444LL
/**
* Calculate 6-point IDCT of the pre-mantissas.
* All calculations are 24-bit fixed-point.
*/
static void idct6(int pre_mant[6])
{
int tmp;
int even0, even1, even2, odd0, odd1, odd2;
odd1 = pre_mant[1] - pre_mant[3] - pre_mant[5];
even2 = ( pre_mant[2] * COEFF_0) >> 23;
tmp = ( pre_mant[4] * COEFF_1) >> 23;
odd0 = ((pre_mant[1] + pre_mant[5]) * COEFF_2) >> 23;
even0 = pre_mant[0] + (tmp >> 1);
even1 = pre_mant[0] - tmp;
tmp = even0;
even0 = tmp + even2;
even2 = tmp - even2;
tmp = odd0;
odd0 = tmp + pre_mant[1] + pre_mant[3];
odd2 = tmp + pre_mant[5] - pre_mant[3];
pre_mant[0] = even0 + odd0;
pre_mant[1] = even1 + odd1;
pre_mant[2] = even2 + odd2;
pre_mant[3] = even2 - odd2;
pre_mant[4] = even1 - odd1;
pre_mant[5] = even0 - odd0;
}
void ff_eac3_decode_transform_coeffs_aht_ch(AC3DecodeContext *s, int ch)
{
int bin, blk, gs;
int end_bap, gaq_mode;
GetBitContext *gbc = &s->gbc;
int gaq_gain[AC3_MAX_COEFS];
gaq_mode = get_bits(gbc, 2);
end_bap = (gaq_mode < 2) ? 12 : 17;
/* if GAQ gain is used, decode gain codes for bins with hebap between
8 and end_bap */
gs = 0;
if (gaq_mode == EAC3_GAQ_12 || gaq_mode == EAC3_GAQ_14) {
/* read 1-bit GAQ gain codes */
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < end_bap)
gaq_gain[gs++] = get_bits1(gbc) << (gaq_mode-1);
}
} else if (gaq_mode == EAC3_GAQ_124) {
/* read 1.67-bit GAQ gain codes (3 codes in 5 bits) */
int gc = 2;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
if (s->bap[ch][bin] > 7 && s->bap[ch][bin] < 17) {
if (gc++ == 2) {
int group_code = get_bits(gbc, 5);
if (group_code > 26) {
av_log(s->avctx, AV_LOG_WARNING, "GAQ gain group code out-of-range\n");
group_code = 26;
}
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][0];
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][1];
gaq_gain[gs++] = ff_ac3_ungroup_3_in_5_bits_tab[group_code][2];
gc = 0;
}
}
}
}
gs=0;
for (bin = s->start_freq[ch]; bin < s->end_freq[ch]; bin++) {
int hebap = s->bap[ch][bin];
int bits = ff_eac3_bits_vs_hebap[hebap];
if (!hebap) {
/* zero-mantissa dithering */
for (blk = 0; blk < 6; blk++) {
s->pre_mantissa[ch][bin][blk] = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000;
}
} else if (hebap < 8) {
/* Vector Quantization */
int v = get_bits(gbc, bits);
for (blk = 0; blk < 6; blk++) {
s->pre_mantissa[ch][bin][blk] = ff_eac3_mantissa_vq[hebap][v][blk] << 8;
}
} else {
/* Gain Adaptive Quantization */
int gbits, log_gain;
if (gaq_mode != EAC3_GAQ_NO && hebap < end_bap) {
log_gain = gaq_gain[gs++];
} else {
log_gain = 0;
}
gbits = bits - log_gain;
for (blk = 0; blk < 6; blk++) {
int mant = get_sbits(gbc, gbits);
if (log_gain && mant == -(1 << (gbits-1))) {
/* large mantissa */
int b;
int mbits = bits - (2 - log_gain);
mant = get_sbits(gbc, mbits);
mant <<= (23 - (mbits - 1));
/* remap mantissa value to correct for asymmetric quantization */
if (mant >= 0)
b = 1 << (23 - log_gain);
else
b = ff_eac3_gaq_remap_2_4_b[hebap-8][log_gain-1] << 8;
mant += ((ff_eac3_gaq_remap_2_4_a[hebap-8][log_gain-1] * (int64_t)mant) >> 15) + b;
} else {
/* small mantissa, no GAQ, or Gk=1 */
mant <<= 24 - bits;
if (!log_gain) {
/* remap mantissa value for no GAQ or Gk=1 */
mant += (ff_eac3_gaq_remap_1[hebap-8] * (int64_t)mant) >> 15;
}
}
s->pre_mantissa[ch][bin][blk] = mant;
}
}
idct6(s->pre_mantissa[ch][bin]);
}
}
int ff_eac3_parse_header(AC3DecodeContext *s)
{
int i, blk, ch;
int ac3_exponent_strategy, parse_aht_info, parse_spx_atten_data;
int parse_transient_proc_info;
int num_cpl_blocks;
GetBitContext *gbc = &s->gbc;
/* An E-AC-3 stream can have multiple independent streams which the
application can select from. each independent stream can also contain
dependent streams which are used to add or replace channels. */
if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
av_log_missing_feature(s->avctx, "Dependent substream decoding", 1);
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
} else if (s->frame_type == EAC3_FRAME_TYPE_RESERVED) {
av_log(s->avctx, AV_LOG_ERROR, "Reserved frame type\n");
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
}
/* The substream id indicates which substream this frame belongs to. each
independent stream has its own substream id, and the dependent streams
associated to an independent stream have matching substream id's. */
if (s->substreamid) {
/* only decode substream with id=0. skip any additional substreams. */
av_log_missing_feature(s->avctx, "Additional substreams", 1);
return AAC_AC3_PARSE_ERROR_FRAME_TYPE;
}
if (s->bit_alloc_params.sr_code == EAC3_SR_CODE_REDUCED) {
/* The E-AC-3 specification does not tell how to handle reduced sample
rates in bit allocation. The best assumption would be that it is
handled like AC-3 DolbyNet, but we cannot be sure until we have a
sample which utilizes this feature. */
av_log_missing_feature(s->avctx, "Reduced sampling rates", 1);
return -1;
}
skip_bits(gbc, 5); // skip bitstream id
/* volume control params */
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
skip_bits(gbc, 5); // skip dialog normalization
if (get_bits1(gbc)) {
skip_bits(gbc, 8); // skip compression gain word
}
}
/* dependent stream channel map */
if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT) {
if (get_bits1(gbc)) {
skip_bits(gbc, 16); // skip custom channel map
}
}
/* mixing metadata */
if (get_bits1(gbc)) {
/* center and surround mix levels */
if (s->channel_mode > AC3_CHMODE_STEREO) {
skip_bits(gbc, 2); // skip preferred stereo downmix mode
if (s->channel_mode & 1) {
/* if three front channels exist */
skip_bits(gbc, 3); //skip Lt/Rt center mix level
s->center_mix_level = get_bits(gbc, 3);
}
if (s->channel_mode & 4) {
/* if a surround channel exists */
skip_bits(gbc, 3); //skip Lt/Rt surround mix level
s->surround_mix_level = get_bits(gbc, 3);
}
}
/* lfe mix level */
if (s->lfe_on && get_bits1(gbc)) {
// TODO: use LFE mix level
skip_bits(gbc, 5); // skip LFE mix level code
}
/* info for mixing with other streams and substreams */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT) {
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
// TODO: apply program scale factor
if (get_bits1(gbc)) {
skip_bits(gbc, 6); // skip program scale factor
}
}
if (get_bits1(gbc)) {
skip_bits(gbc, 6); // skip external program scale factor
}
/* skip mixing parameter data */
switch(get_bits(gbc, 2)) {
case 1: skip_bits(gbc, 5); break;
case 2: skip_bits(gbc, 12); break;
case 3: {
int mix_data_size = (get_bits(gbc, 5) + 2) << 3;
skip_bits_long(gbc, mix_data_size);
break;
}
}
/* skip pan information for mono or dual mono source */
if (s->channel_mode < AC3_CHMODE_STEREO) {
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
if (get_bits1(gbc)) {
/* note: this is not in the ATSC A/52B specification
reference: ETSI TS 102 366 V1.1.1
section: E.1.3.1.25 */
skip_bits(gbc, 8); // skip pan mean direction index
skip_bits(gbc, 6); // skip reserved paninfo bits
}
}
}
/* skip mixing configuration information */
if (get_bits1(gbc)) {
for (blk = 0; blk < s->num_blocks; blk++) {
if (s->num_blocks == 1 || get_bits1(gbc)) {
skip_bits(gbc, 5);
}
}
}
}
}
/* informational metadata */
if (get_bits1(gbc)) {
skip_bits(gbc, 3); // skip bit stream mode
skip_bits(gbc, 2); // skip copyright bit and original bitstream bit
if (s->channel_mode == AC3_CHMODE_STEREO) {
skip_bits(gbc, 4); // skip Dolby surround and headphone mode
}
if (s->channel_mode >= AC3_CHMODE_2F2R) {
skip_bits(gbc, 2); // skip Dolby surround EX mode
}
for (i = 0; i < (s->channel_mode ? 1 : 2); i++) {
if (get_bits1(gbc)) {
skip_bits(gbc, 8); // skip mix level, room type, and A/D converter type
}
}
if (s->bit_alloc_params.sr_code != EAC3_SR_CODE_REDUCED) {
skip_bits1(gbc); // skip source sample rate code
}
}
/* converter synchronization flag
If frames are less than six blocks, this bit should be turned on
once every 6 blocks to indicate the start of a frame set.
reference: RFC 4598, Section 2.1.3 Frame Sets */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && s->num_blocks != 6) {
skip_bits1(gbc); // skip converter synchronization flag
}
/* original frame size code if this stream was converted from AC-3 */
if (s->frame_type == EAC3_FRAME_TYPE_AC3_CONVERT &&
(s->num_blocks == 6 || get_bits1(gbc))) {
skip_bits(gbc, 6); // skip frame size code
}
/* additional bitstream info */
if (get_bits1(gbc)) {
int addbsil = get_bits(gbc, 6);
for (i = 0; i < addbsil + 1; i++) {
skip_bits(gbc, 8); // skip additional bit stream info
}
}
/* audio frame syntax flags, strategy data, and per-frame data */
if (s->num_blocks == 6) {
ac3_exponent_strategy = get_bits1(gbc);
parse_aht_info = get_bits1(gbc);
} else {
/* less than 6 blocks, so use AC-3-style exponent strategy syntax, and
do not use AHT */
ac3_exponent_strategy = 1;
parse_aht_info = 0;
}
s->snr_offset_strategy = get_bits(gbc, 2);
parse_transient_proc_info = get_bits1(gbc);
s->block_switch_syntax = get_bits1(gbc);
if (!s->block_switch_syntax)
memset(s->block_switch, 0, sizeof(s->block_switch));
s->dither_flag_syntax = get_bits1(gbc);
if (!s->dither_flag_syntax) {
for (ch = 1; ch <= s->fbw_channels; ch++)
s->dither_flag[ch] = 1;
}
s->dither_flag[CPL_CH] = s->dither_flag[s->lfe_ch] = 0;
s->bit_allocation_syntax = get_bits1(gbc);
if (!s->bit_allocation_syntax) {
/* set default bit allocation parameters */
s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[2];
s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[1];
s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab [1];
s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[2];
s->bit_alloc_params.floor = ff_ac3_floor_tab [7];
}
s->fast_gain_syntax = get_bits1(gbc);
s->dba_syntax = get_bits1(gbc);
s->skip_syntax = get_bits1(gbc);
parse_spx_atten_data = get_bits1(gbc);
/* coupling strategy occurance and coupling use per block */
num_cpl_blocks = 0;
if (s->channel_mode > 1) {
for (blk = 0; blk < s->num_blocks; blk++) {
s->cpl_strategy_exists[blk] = (!blk || get_bits1(gbc));
if (s->cpl_strategy_exists[blk]) {
s->cpl_in_use[blk] = get_bits1(gbc);
} else {
s->cpl_in_use[blk] = s->cpl_in_use[blk-1];
}
num_cpl_blocks += s->cpl_in_use[blk];
}
} else {
memset(s->cpl_in_use, 0, sizeof(s->cpl_in_use));
}
/* exponent strategy data */
if (ac3_exponent_strategy) {
/* AC-3-style exponent strategy syntax */
for (blk = 0; blk < s->num_blocks; blk++) {
for (ch = !s->cpl_in_use[blk]; ch <= s->fbw_channels; ch++) {
s->exp_strategy[blk][ch] = get_bits(gbc, 2);
}
}
} else {
/* LUT-based exponent strategy syntax */
for (ch = !((s->channel_mode > 1) && num_cpl_blocks); ch <= s->fbw_channels; ch++) {
int frmchexpstr = get_bits(gbc, 5);
for (blk = 0; blk < 6; blk++) {
s->exp_strategy[blk][ch] = ff_eac3_frm_expstr[frmchexpstr][blk];
}
}
}
/* LFE exponent strategy */
if (s->lfe_on) {
for (blk = 0; blk < s->num_blocks; blk++) {
s->exp_strategy[blk][s->lfe_ch] = get_bits1(gbc);
}
}
/* original exponent strategies if this stream was converted from AC-3 */
if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT &&
(s->num_blocks == 6 || get_bits1(gbc))) {
skip_bits(gbc, 5 * s->fbw_channels); // skip converter channel exponent strategy
}
/* determine which channels use AHT */
if (parse_aht_info) {
/* For AHT to be used, all non-zero blocks must reuse exponents from
the first block. Furthermore, for AHT to be used in the coupling
channel, all blocks must use coupling and use the same coupling
strategy. */
s->channel_uses_aht[CPL_CH]=0;
for (ch = (num_cpl_blocks != 6); ch <= s->channels; ch++) {
int use_aht = 1;
for (blk = 1; blk < 6; blk++) {
if ((s->exp_strategy[blk][ch] != EXP_REUSE) ||
(!ch && s->cpl_strategy_exists[blk])) {
use_aht = 0;
break;
}
}
s->channel_uses_aht[ch] = use_aht && get_bits1(gbc);
}
} else {
memset(s->channel_uses_aht, 0, sizeof(s->channel_uses_aht));
}
/* per-frame SNR offset */
if (!s->snr_offset_strategy) {
int csnroffst = (get_bits(gbc, 6) - 15) << 4;
int snroffst = (csnroffst + get_bits(gbc, 4)) << 2;
for (ch = 0; ch <= s->channels; ch++)
s->snr_offset[ch] = snroffst;
}
/* transient pre-noise processing data */
if (parse_transient_proc_info) {
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (get_bits1(gbc)) { // channel in transient processing
skip_bits(gbc, 10); // skip transient processing location
skip_bits(gbc, 8); // skip transient processing length
}
}
}
/* spectral extension attenuation data */
for (ch = 1; ch <= s->fbw_channels; ch++) {
if (parse_spx_atten_data && get_bits1(gbc)) {
s->spx_atten_code[ch] = get_bits(gbc, 5);
} else {
s->spx_atten_code[ch] = -1;
}
}
/* block start information */
if (s->num_blocks > 1 && get_bits1(gbc)) {
/* reference: Section E2.3.2.27
nblkstrtbits = (numblks - 1) * (4 + ceiling(log2(words_per_frame)))
The spec does not say what this data is or what it's used for.
It is likely the offset of each block within the frame. */
int block_start_bits = (s->num_blocks-1) * (4 + av_log2(s->frame_size-2));
skip_bits_long(gbc, block_start_bits);
av_log_missing_feature(s->avctx, "Block start info", 1);
}
/* syntax state initialization */
for (ch = 1; ch <= s->fbw_channels; ch++) {
s->first_spx_coords[ch] = 1;
s->first_cpl_coords[ch] = 1;
}
s->first_cpl_leak = 1;
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/eac3dec.c | C | asf20 | 22,919 |
/*
* TechSmith Camtasia decoder
* Copyright (c) 2004 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* TechSmith Camtasia decoder
*
* Fourcc: TSCC
*
* Codec is very simple:
* it codes picture (picture difference, really)
* with algorithm almost identical to Windows RLE8,
* only without padding and with greater pixel sizes,
* then this coded picture is packed with ZLib
*
* Supports: BGR8,BGR555,BGR24 - only BGR8 and BGR555 tested
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "avcodec.h"
#include "msrledec.h"
#include <zlib.h>
/*
* Decoder context
*/
typedef struct TsccContext {
AVCodecContext *avctx;
AVFrame pic;
// Bits per pixel
int bpp;
// Decompressed data size
unsigned int decomp_size;
// Decompression buffer
unsigned char* decomp_buf;
int height;
z_stream zstream;
} CamtasiaContext;
/*
*
* Decode a frame
*
*/
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
CamtasiaContext * const c = avctx->priv_data;
const unsigned char *encoded = buf;
unsigned char *outptr;
int zret; // Zlib return code
int len = buf_size;
if(c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
c->pic.reference = 1;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
if(avctx->get_buffer(avctx, &c->pic) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
outptr = c->pic.data[0]; // Output image pointer
zret = inflateReset(&(c->zstream));
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
return -1;
}
c->zstream.next_in = encoded;
c->zstream.avail_in = len;
c->zstream.next_out = c->decomp_buf;
c->zstream.avail_out = c->decomp_size;
zret = inflate(&(c->zstream), Z_FINISH);
// Z_DATA_ERROR means empty picture
if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) {
av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
return -1;
}
if(zret != Z_DATA_ERROR)
ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, c->decomp_buf, c->decomp_size - c->zstream.avail_out);
/* make the palette available on the way out */
if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE);
if (c->avctx->palctrl->palette_changed) {
c->pic.palette_has_changed = 1;
c->avctx->palctrl->palette_changed = 0;
}
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = c->pic;
/* always report that the buffer was completely consumed */
return buf_size;
}
/*
*
* Init tscc decoder
*
*/
static av_cold int decode_init(AVCodecContext *avctx)
{
CamtasiaContext * const c = avctx->priv_data;
int zret; // Zlib return code
c->avctx = avctx;
c->height = avctx->height;
// Needed if zlib unused or init aborted before inflateInit
memset(&(c->zstream), 0, sizeof(z_stream));
switch(avctx->bits_per_coded_sample){
case 8: avctx->pix_fmt = PIX_FMT_PAL8; break;
case 16: avctx->pix_fmt = PIX_FMT_RGB555; break;
case 24:
avctx->pix_fmt = PIX_FMT_BGR24;
break;
case 32: avctx->pix_fmt = PIX_FMT_RGB32; break;
default: av_log(avctx, AV_LOG_ERROR, "Camtasia error: unknown depth %i bpp\n", avctx->bits_per_coded_sample);
return -1;
}
c->bpp = avctx->bits_per_coded_sample;
// buffer size for RLE 'best' case when 2-byte code preceeds each pixel and there may be padding after it too
c->decomp_size = (((avctx->width * c->bpp + 7) >> 3) + 3 * avctx->width + 2) * avctx->height + 2;
/* Allocate decompression buffer */
if (c->decomp_size) {
if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) {
av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
return 1;
}
}
c->zstream.zalloc = Z_NULL;
c->zstream.zfree = Z_NULL;
c->zstream.opaque = Z_NULL;
zret = inflateInit(&(c->zstream));
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
return 1;
}
return 0;
}
/*
*
* Uninit tscc decoder
*
*/
static av_cold int decode_end(AVCodecContext *avctx)
{
CamtasiaContext * const c = avctx->priv_data;
av_freep(&c->decomp_buf);
if (c->pic.data[0])
avctx->release_buffer(avctx, &c->pic);
inflateEnd(&(c->zstream));
return 0;
}
AVCodec tscc_decoder = {
"camtasia",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_TSCC,
sizeof(CamtasiaContext),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("TechSmith Screen Capture Codec"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/tscc.c | C | asf20 | 5,689 |
/*
* AAC parser prototypes
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_AAC_PARSER_H
#define AVCODEC_AAC_PARSER_H
#include <stdint.h>
#include "aac_ac3_parser.h"
#include "get_bits.h"
#define AAC_ADTS_HEADER_SIZE 7
typedef struct {
uint32_t sample_rate;
uint32_t samples;
uint32_t bit_rate;
uint8_t crc_absent;
uint8_t object_type;
uint8_t sampling_index;
uint8_t chan_config;
uint8_t num_aac_frames;
} AACADTSHeaderInfo;
/**
* Parses AAC frame header.
* Parses the ADTS frame header to the end of the variable header, which is
* the first 54 bits.
* @param gbc[in] BitContext containing the first 54 bits of the frame.
* @param hdr[out] Pointer to struct where header info is written.
* @return Returns 0 on success, -1 if there is a sync word mismatch,
* -2 if the version element is invalid, -3 if the sample rate
* element is invalid, or -4 if the bit rate element is invalid.
*/
int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
#endif /* AVCODEC_AAC_PARSER_H */
| 123linslouis-android-video-cutter | jni/libavcodec/aac_parser.h | C | asf20 | 1,854 |
/*
* RLE encoder
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_RLE_H
#define AVCODEC_RLE_H
#include <stdint.h>
/**
* RLE compress the row, with maximum size of out_size. Value before repeated bytes is (count ^ xor_rep) + add_rep.
* Value before raw bytes is (count ^ xor_raw) + add_raw.
* @param outbuf Output buffer
* @param out_size Maximum output size
* @param ptr Input buffer
* @param bpp Bytes per pixel
* @param w Image width
* @return Size of output in bytes, or -1 if larger than out_size
*/
int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *inbuf, int bpp, int w,
int add_rep, int xor_rep, int add_raw, int xor_raw);
#endif /* AVCODEC_RLE_H */
| 123linslouis-android-video-cutter | jni/libavcodec/rle.h | C | asf20 | 1,491 |
/*
* VC-1 and WMV3 decoder common code
* Copyright (c) 2006-2007 Konstantin Shishkov
* Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* VC-1 and WMV3 decoder common code
*
*/
#include "internal.h"
#include "dsputil.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "vc1.h"
#include "vc1data.h"
#include "msmpeg4data.h"
#include "unary.h"
#include "simple_idct.h"
#undef NDEBUG
#include <assert.h>
/***********************************************************************/
/**
* @defgroup vc1bitplane VC-1 Bitplane decoding
* @see 8.7, p56
* @{
*/
/**
* Imode types
* @{
*/
enum Imode {
IMODE_RAW,
IMODE_NORM2,
IMODE_DIFF2,
IMODE_NORM6,
IMODE_DIFF6,
IMODE_ROWSKIP,
IMODE_COLSKIP
};
/** @} */ //imode defines
/** Decode rows by checking if they are skipped
* @param plane Buffer to store decoded bits
* @param[in] width Width of this buffer
* @param[in] height Height of this buffer
* @param[in] stride of this buffer
*/
static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
int x, y;
for (y=0; y<height; y++){
if (!get_bits1(gb)) //rowskip
memset(plane, 0, width);
else
for (x=0; x<width; x++)
plane[x] = get_bits1(gb);
plane += stride;
}
}
/** Decode columns by checking if they are skipped
* @param plane Buffer to store decoded bits
* @param[in] width Width of this buffer
* @param[in] height Height of this buffer
* @param[in] stride of this buffer
* @todo FIXME: Optimize
*/
static void decode_colskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){
int x, y;
for (x=0; x<width; x++){
if (!get_bits1(gb)) //colskip
for (y=0; y<height; y++)
plane[y*stride] = 0;
else
for (y=0; y<height; y++)
plane[y*stride] = get_bits1(gb);
plane ++;
}
}
/** Decode a bitplane's bits
* @param data bitplane where to store the decode bits
* @param[out] raw_flag pointer to the flag indicating that this bitplane is not coded explicitly
* @param v VC-1 context for bit reading and logging
* @return Status
* @todo FIXME: Optimize
*/
static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
{
GetBitContext *gb = &v->s.gb;
int imode, x, y, code, offset;
uint8_t invert, *planep = data;
int width, height, stride;
width = v->s.mb_width;
height = v->s.mb_height;
stride = v->s.mb_stride;
invert = get_bits1(gb);
imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
*raw_flag = 0;
switch (imode)
{
case IMODE_RAW:
//Data is actually read in the MB layer (same for all tests == "raw")
*raw_flag = 1; //invert ignored
return invert;
case IMODE_DIFF2:
case IMODE_NORM2:
if ((height * width) & 1)
{
*planep++ = get_bits1(gb);
offset = 1;
}
else offset = 0;
// decode bitplane as one long line
for (y = offset; y < height * width; y += 2) {
code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
*planep++ = code & 1;
offset++;
if(offset == width) {
offset = 0;
planep += stride - width;
}
*planep++ = code >> 1;
offset++;
if(offset == width) {
offset = 0;
planep += stride - width;
}
}
break;
case IMODE_DIFF6:
case IMODE_NORM6:
if(!(height % 3) && (width % 3)) { // use 2x3 decoding
for(y = 0; y < height; y+= 3) {
for(x = width & 1; x < width; x += 2) {
code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
if(code < 0){
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
}
planep[x + 0] = (code >> 0) & 1;
planep[x + 1] = (code >> 1) & 1;
planep[x + 0 + stride] = (code >> 2) & 1;
planep[x + 1 + stride] = (code >> 3) & 1;
planep[x + 0 + stride * 2] = (code >> 4) & 1;
planep[x + 1 + stride * 2] = (code >> 5) & 1;
}
planep += stride * 3;
}
if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
} else { // 3x2
planep += (height & 1) * stride;
for(y = height & 1; y < height; y += 2) {
for(x = width % 3; x < width; x += 3) {
code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
if(code < 0){
av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
return -1;
}
planep[x + 0] = (code >> 0) & 1;
planep[x + 1] = (code >> 1) & 1;
planep[x + 2] = (code >> 2) & 1;
planep[x + 0 + stride] = (code >> 3) & 1;
planep[x + 1 + stride] = (code >> 4) & 1;
planep[x + 2 + stride] = (code >> 5) & 1;
}
planep += stride * 2;
}
x = width % 3;
if(x) decode_colskip(data , x, height , stride, &v->s.gb);
if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
}
break;
case IMODE_ROWSKIP:
decode_rowskip(data, width, height, stride, &v->s.gb);
break;
case IMODE_COLSKIP:
decode_colskip(data, width, height, stride, &v->s.gb);
break;
default: break;
}
/* Applying diff operator */
if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
{
planep = data;
planep[0] ^= invert;
for (x=1; x<width; x++)
planep[x] ^= planep[x-1];
for (y=1; y<height; y++)
{
planep += stride;
planep[0] ^= planep[-stride];
for (x=1; x<width; x++)
{
if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
else planep[x] ^= planep[x-1];
}
}
}
else if (invert)
{
planep = data;
for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
}
return (imode<<1) + invert;
}
/** @} */ //Bitplane group
/***********************************************************************/
/** VOP Dquant decoding
* @param v VC-1 Context
*/
static int vop_dquant_decoding(VC1Context *v)
{
GetBitContext *gb = &v->s.gb;
int pqdiff;
//variable size
if (v->dquant == 2)
{
pqdiff = get_bits(gb, 3);
if (pqdiff == 7) v->altpq = get_bits(gb, 5);
else v->altpq = v->pq + pqdiff + 1;
}
else
{
v->dquantfrm = get_bits1(gb);
if ( v->dquantfrm )
{
v->dqprofile = get_bits(gb, 2);
switch (v->dqprofile)
{
case DQPROFILE_SINGLE_EDGE:
case DQPROFILE_DOUBLE_EDGES:
v->dqsbedge = get_bits(gb, 2);
break;
case DQPROFILE_ALL_MBS:
v->dqbilevel = get_bits1(gb);
if(!v->dqbilevel)
v->halfpq = 0;
default: break; //Forbidden ?
}
if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS)
{
pqdiff = get_bits(gb, 3);
if (pqdiff == 7) v->altpq = get_bits(gb, 5);
else v->altpq = v->pq + pqdiff + 1;
}
}
}
return 0;
}
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb);
/**
* Decode Simple/Main Profiles sequence header
* @see Figure 7-8, p16-17
* @param avctx Codec context
* @param gb GetBit context initialized from Codec context extra_data
* @return Status
*/
int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
{
av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
v->profile = get_bits(gb, 2);
if (v->profile == PROFILE_COMPLEX)
{
av_log(avctx, AV_LOG_ERROR, "WMV3 Complex Profile is not fully supported\n");
}
if (v->profile == PROFILE_ADVANCED)
{
v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz;
v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz;
return decode_sequence_header_adv(v, gb);
}
else
{
v->zz_8x4 = wmv2_scantableA;
v->zz_4x8 = wmv2_scantableB;
v->res_sm = get_bits(gb, 2); //reserved
if (v->res_sm)
{
av_log(avctx, AV_LOG_ERROR,
"Reserved RES_SM=%i is forbidden\n", v->res_sm);
return -1;
}
}
// (fps-2)/4 (->30)
v->frmrtq_postproc = get_bits(gb, 3); //common
// (bitrate-32kbps)/64kbps
v->bitrtq_postproc = get_bits(gb, 5); //common
v->s.loop_filter = get_bits1(gb); //common
if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE)
{
av_log(avctx, AV_LOG_ERROR,
"LOOPFILTER shall not be enabled in Simple Profile\n");
}
if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
v->s.loop_filter = 0;
v->res_x8 = get_bits1(gb); //reserved
v->multires = get_bits1(gb);
v->res_fasttx = get_bits1(gb);
if (!v->res_fasttx)
{
v->s.dsp.vc1_inv_trans_8x8 = ff_simple_idct;
v->s.dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add;
v->s.dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add;
v->s.dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add;
v->s.dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add;
v->s.dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add;
v->s.dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add;
v->s.dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add;
}
v->fastuvmc = get_bits1(gb); //common
if (!v->profile && !v->fastuvmc)
{
av_log(avctx, AV_LOG_ERROR,
"FASTUVMC unavailable in Simple Profile\n");
return -1;
}
v->extended_mv = get_bits1(gb); //common
if (!v->profile && v->extended_mv)
{
av_log(avctx, AV_LOG_ERROR,
"Extended MVs unavailable in Simple Profile\n");
return -1;
}
v->dquant = get_bits(gb, 2); //common
v->vstransform = get_bits1(gb); //common
v->res_transtab = get_bits1(gb);
if (v->res_transtab)
{
av_log(avctx, AV_LOG_ERROR,
"1 for reserved RES_TRANSTAB is forbidden\n");
return -1;
}
v->overlap = get_bits1(gb); //common
v->s.resync_marker = get_bits1(gb);
v->rangered = get_bits1(gb);
if (v->rangered && v->profile == PROFILE_SIMPLE)
{
av_log(avctx, AV_LOG_INFO,
"RANGERED should be set to 0 in Simple Profile\n");
}
v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common
v->quantizer_mode = get_bits(gb, 2); //common
v->finterpflag = get_bits1(gb); //common
v->res_rtm_flag = get_bits1(gb); //reserved
if (!v->res_rtm_flag)
{
// av_log(avctx, AV_LOG_ERROR,
// "0 for reserved RES_RTM_FLAG is forbidden\n");
av_log(avctx, AV_LOG_ERROR,
"Old WMV3 version detected, only I-frames will be decoded\n");
//return -1;
}
//TODO: figure out what they mean (always 0x402F)
if(!v->res_fasttx) skip_bits(gb, 16);
av_log(avctx, AV_LOG_DEBUG,
"Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
"LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n"
"Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
"DQuant=%i, Quantizer mode=%i, Max B frames=%i\n",
v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
v->rangered, v->vstransform, v->overlap, v->s.resync_marker,
v->dquant, v->quantizer_mode, avctx->max_b_frames
);
return 0;
}
static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
{
v->res_rtm_flag = 1;
v->level = get_bits(gb, 3);
if(v->level >= 5)
{
av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level);
}
v->chromaformat = get_bits(gb, 2);
if (v->chromaformat != 1)
{
av_log(v->s.avctx, AV_LOG_ERROR,
"Only 4:2:0 chroma format supported\n");
return -1;
}
// (fps-2)/4 (->30)
v->frmrtq_postproc = get_bits(gb, 3); //common
// (bitrate-32kbps)/64kbps
v->bitrtq_postproc = get_bits(gb, 5); //common
v->postprocflag = get_bits1(gb); //common
v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1;
v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1;
v->s.avctx->width = v->s.avctx->coded_width;
v->s.avctx->height = v->s.avctx->coded_height;
v->broadcast = get_bits1(gb);
v->interlace = get_bits1(gb);
v->tfcntrflag = get_bits1(gb);
v->finterpflag = get_bits1(gb);
skip_bits1(gb); // reserved
v->s.h_edge_pos = v->s.avctx->coded_width;
v->s.v_edge_pos = v->s.avctx->coded_height;
av_log(v->s.avctx, AV_LOG_DEBUG,
"Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n"
"LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
"TFCTRflag=%i, FINTERPflag=%i\n",
v->level, v->frmrtq_postproc, v->bitrtq_postproc,
v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
v->tfcntrflag, v->finterpflag
);
v->psf = get_bits1(gb);
if(v->psf) { //PsF, 6.1.13
av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
return -1;
}
v->s.max_b_frames = v->s.avctx->max_b_frames = 7;
if(get_bits1(gb)) { //Display Info - decoding is not affected by it
int w, h, ar = 0;
av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n");
v->s.avctx->width = w = get_bits(gb, 14) + 1;
v->s.avctx->height = h = get_bits(gb, 14) + 1;
av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h);
if(get_bits1(gb))
ar = get_bits(gb, 4);
if(ar && ar < 14){
v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar];
}else if(ar == 15){
w = get_bits(gb, 8);
h = get_bits(gb, 8);
v->s.avctx->sample_aspect_ratio = (AVRational){w, h};
}
av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den);
if(get_bits1(gb)){ //framerate stuff
if(get_bits1(gb)) {
v->s.avctx->time_base.num = 32;
v->s.avctx->time_base.den = get_bits(gb, 16) + 1;
} else {
int nr, dr;
nr = get_bits(gb, 8);
dr = get_bits(gb, 4);
if(nr && nr < 8 && dr && dr < 3){
v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1];
v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000;
}
}
}
if(get_bits1(gb)){
v->color_prim = get_bits(gb, 8);
v->transfer_char = get_bits(gb, 8);
v->matrix_coef = get_bits(gb, 8);
}
}
v->hrd_param_flag = get_bits1(gb);
if(v->hrd_param_flag) {
int i;
v->hrd_num_leaky_buckets = get_bits(gb, 5);
skip_bits(gb, 4); //bitrate exponent
skip_bits(gb, 4); //buffer size exponent
for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
skip_bits(gb, 16); //hrd_rate[n]
skip_bits(gb, 16); //hrd_buffer[n]
}
}
return 0;
}
int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
{
int i;
av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
v->broken_link = get_bits1(gb);
v->closed_entry = get_bits1(gb);
v->panscanflag = get_bits1(gb);
v->refdist_flag = get_bits1(gb);
v->s.loop_filter = get_bits1(gb);
v->fastuvmc = get_bits1(gb);
v->extended_mv = get_bits1(gb);
v->dquant = get_bits(gb, 2);
v->vstransform = get_bits1(gb);
v->overlap = get_bits1(gb);
v->quantizer_mode = get_bits(gb, 2);
if(v->hrd_param_flag){
for(i = 0; i < v->hrd_num_leaky_buckets; i++) {
skip_bits(gb, 8); //hrd_full[n]
}
}
if(get_bits1(gb)){
avctx->coded_width = (get_bits(gb, 12)+1)<<1;
avctx->coded_height = (get_bits(gb, 12)+1)<<1;
}
if(v->extended_mv)
v->extended_dmv = get_bits1(gb);
if((v->range_mapy_flag = get_bits1(gb))) {
av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n");
v->range_mapy = get_bits(gb, 3);
}
if((v->range_mapuv_flag = get_bits1(gb))) {
av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n");
v->range_mapuv = get_bits(gb, 3);
}
av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n"
"BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
"RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
"DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
return 0;
}
int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
{
int pqindex, lowquant, status;
if(v->finterpflag) v->interpfrm = get_bits1(gb);
skip_bits(gb, 2); //framecnt unused
v->rangeredfrm = 0;
if (v->rangered) v->rangeredfrm = get_bits1(gb);
v->s.pict_type = get_bits1(gb);
if (v->s.avctx->max_b_frames) {
if (!v->s.pict_type) {
if (get_bits1(gb)) v->s.pict_type = FF_I_TYPE;
else v->s.pict_type = FF_B_TYPE;
} else v->s.pict_type = FF_P_TYPE;
} else v->s.pict_type = v->s.pict_type ? FF_P_TYPE : FF_I_TYPE;
v->bi_type = 0;
if(v->s.pict_type == FF_B_TYPE) {
v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
if(v->bfraction == 0) {
v->s.pict_type = FF_BI_TYPE;
}
}
if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
skip_bits(gb, 7); // skip buffer fullness
if(v->parse_only)
return 0;
/* calculate RND */
if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
v->rnd = 1;
if(v->s.pict_type == FF_P_TYPE)
v->rnd ^= 1;
/* Quantizer stuff */
pqindex = get_bits(gb, 5);
if(!pqindex) return -1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = ff_vc1_pquant_table[0][pqindex];
else
v->pq = ff_vc1_pquant_table[1][pqindex];
v->pquantizer = 1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pquantizer = pqindex < 9;
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex;
if (pqindex < 9) v->halfpq = get_bits1(gb);
else v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits1(gb);
v->dquantfrm = 0;
if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3);
v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
if (v->multires && v->s.pict_type != FF_B_TYPE) v->respic = get_bits(gb, 2);
if(v->res_x8 && (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)){
v->x8_type = get_bits1(gb);
}else v->x8_type = 0;
//av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n",
// (v->s.pict_type == FF_P_TYPE) ? 'P' : ((v->s.pict_type == FF_I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm);
if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0;
switch(v->s.pict_type) {
case FF_P_TYPE:
if (v->pq < 5) v->tt_index = 0;
else if(v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
lowquant = (v->pq > 12) ? 0 : 1;
v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
{
int scale, shift, i;
v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
v->lumscale = get_bits(gb, 6);
v->lumshift = get_bits(gb, 6);
v->use_ic = 1;
/* fill lookup tables for intensity compensation */
if(!v->lumscale) {
scale = -64;
shift = (255 - v->lumshift * 2) << 6;
if(v->lumshift > 31)
shift += 128 << 6;
} else {
scale = v->lumscale + 32;
if(v->lumshift > 31)
shift = (v->lumshift - 64) << 6;
else
shift = v->lumshift << 6;
}
for(i = 0; i < 256; i++) {
v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
}
}
if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
else
v->s.quarter_sample = 1;
} else
v->s.quarter_sample = 1;
v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV)
|| v->mv_mode == MV_PMODE_MIXED_MV)
{
status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
} else {
v->mv_type_is_raw = 0;
memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
}
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
/* Hopefully this is correct for P frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
if (v->dquant)
{
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0; //FIXME Is that so ?
if (v->vstransform)
{
v->ttmbf = get_bits1(gb);
if (v->ttmbf)
{
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
v->ttmbf = 1;
v->ttfrm = TT_8X8;
}
break;
case FF_B_TYPE:
if (v->pq < 5) v->tt_index = 0;
else if(v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
v->s.mspel = v->s.quarter_sample;
status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
if (v->dquant)
{
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0;
if (v->vstransform)
{
v->ttmbf = get_bits1(gb);
if (v->ttmbf)
{
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
v->ttmbf = 1;
v->ttfrm = TT_8X8;
}
break;
}
if(!v->x8_type)
{
/* AC Syntax */
v->c_ac_table_index = decode012(gb);
if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
{
v->y_ac_table_index = decode012(gb);
}
/* DC Syntax */
v->s.dc_table_index = get_bits1(gb);
}
if(v->s.pict_type == FF_BI_TYPE) {
v->s.pict_type = FF_B_TYPE;
v->bi_type = 1;
}
return 0;
}
int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
{
int pqindex, lowquant;
int status;
v->p_frame_skipped = 0;
if(v->interlace){
v->fcm = decode012(gb);
if(v->fcm){
if(!v->warn_interlaced++)
av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is not implemented\n");
return -1;
}
}
switch(get_unary(gb, 0, 4)) {
case 0:
v->s.pict_type = FF_P_TYPE;
break;
case 1:
v->s.pict_type = FF_B_TYPE;
break;
case 2:
v->s.pict_type = FF_I_TYPE;
break;
case 3:
v->s.pict_type = FF_BI_TYPE;
break;
case 4:
v->s.pict_type = FF_P_TYPE; // skipped pic
v->p_frame_skipped = 1;
return 0;
}
if(v->tfcntrflag)
skip_bits(gb, 8);
if(v->broadcast) {
if(!v->interlace || v->psf) {
v->rptfrm = get_bits(gb, 2);
} else {
v->tff = get_bits1(gb);
v->rptfrm = get_bits1(gb);
}
}
if(v->panscanflag) {
//...
}
v->rnd = get_bits1(gb);
if(v->interlace)
v->uvsamp = get_bits1(gb);
if(v->finterpflag) v->interpfrm = get_bits1(gb);
if(v->s.pict_type == FF_B_TYPE) {
v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1);
v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index];
if(v->bfraction == 0) {
v->s.pict_type = FF_BI_TYPE; /* XXX: should not happen here */
}
}
pqindex = get_bits(gb, 5);
if(!pqindex) return -1;
v->pqindex = pqindex;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pq = ff_vc1_pquant_table[0][pqindex];
else
v->pq = ff_vc1_pquant_table[1][pqindex];
v->pquantizer = 1;
if (v->quantizer_mode == QUANT_FRAME_IMPLICIT)
v->pquantizer = pqindex < 9;
if (v->quantizer_mode == QUANT_NON_UNIFORM)
v->pquantizer = 0;
v->pqindex = pqindex;
if (pqindex < 9) v->halfpq = get_bits1(gb);
else v->halfpq = 0;
if (v->quantizer_mode == QUANT_FRAME_EXPLICIT)
v->pquantizer = get_bits1(gb);
if(v->postprocflag)
v->postproc = get_bits(gb, 2);
if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0;
if(v->parse_only)
return 0;
switch(v->s.pict_type) {
case FF_I_TYPE:
case FF_BI_TYPE:
status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->condover = CONDOVER_NONE;
if(v->overlap && v->pq <= 8) {
v->condover = decode012(gb);
if(v->condover == CONDOVER_SELECT) {
status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
}
}
break;
case FF_P_TYPE:
if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
else v->mvrange = 0;
v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
if (v->pq < 5) v->tt_index = 0;
else if(v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
lowquant = (v->pq > 12) ? 0 : 1;
v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)];
if (v->mv_mode == MV_PMODE_INTENSITY_COMP)
{
int scale, shift, i;
v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)];
v->lumscale = get_bits(gb, 6);
v->lumshift = get_bits(gb, 6);
/* fill lookup tables for intensity compensation */
if(!v->lumscale) {
scale = -64;
shift = (255 - v->lumshift * 2) << 6;
if(v->lumshift > 31)
shift += 128 << 6;
} else {
scale = v->lumscale + 32;
if(v->lumshift > 31)
shift = (v->lumshift - 64) << 6;
else
shift = v->lumshift << 6;
}
for(i = 0; i < 256; i++) {
v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6);
v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6);
}
v->use_ic = 1;
}
if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)
v->s.quarter_sample = 0;
else
v->s.quarter_sample = 1;
} else
v->s.quarter_sample = 1;
v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN));
if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
v->mv_mode2 == MV_PMODE_MIXED_MV)
|| v->mv_mode == MV_PMODE_MIXED_MV)
{
status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
} else {
v->mv_type_is_raw = 0;
memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
}
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
/* Hopefully this is correct for P frames */
v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables
v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
if (v->dquant)
{
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0; //FIXME Is that so ?
if (v->vstransform)
{
v->ttmbf = get_bits1(gb);
if (v->ttmbf)
{
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
v->ttmbf = 1;
v->ttfrm = TT_8X8;
}
break;
case FF_B_TYPE:
if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3);
else v->mvrange = 0;
v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13
v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11
v->range_x = 1 << (v->k_x - 1);
v->range_y = 1 << (v->k_y - 1);
if (v->pq < 5) v->tt_index = 0;
else if(v->pq < 13) v->tt_index = 1;
else v->tt_index = 2;
v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN;
v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV);
v->s.mspel = v->s.quarter_sample;
status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v);
if (status < 0) return -1;
av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
"Imode: %i, Invert: %i\n", status>>1, status&1);
v->s.mv_table_index = get_bits(gb, 2);
v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)];
if (v->dquant)
{
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->ttfrm = 0;
if (v->vstransform)
{
v->ttmbf = get_bits1(gb);
if (v->ttmbf)
{
v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)];
}
} else {
v->ttmbf = 1;
v->ttfrm = TT_8X8;
}
break;
}
/* AC Syntax */
v->c_ac_table_index = decode012(gb);
if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
{
v->y_ac_table_index = decode012(gb);
}
/* DC Syntax */
v->s.dc_table_index = get_bits1(gb);
if ((v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) && v->dquant) {
av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n");
vop_dquant_decoding(v);
}
v->bi_type = 0;
if(v->s.pict_type == FF_BI_TYPE) {
v->s.pict_type = FF_B_TYPE;
v->bi_type = 1;
}
return 0;
}
| 123linslouis-android-video-cutter | jni/libavcodec/vc1.c | C | asf20 | 35,508 |
/*
* Copyright (C) 2008 David Conrad
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include <speex/speex.h>
#include <speex/speex_header.h>
#include <speex/speex_stereo.h>
#include <speex/speex_callbacks.h>
typedef struct {
SpeexBits bits;
SpeexStereoState stereo;
void *dec_state;
SpeexHeader *header;
int frame_size;
} LibSpeexContext;
static av_cold int libspeex_decode_init(AVCodecContext *avctx)
{
LibSpeexContext *s = avctx->priv_data;
const SpeexMode *mode;
// defaults in the case of a missing header
if (avctx->sample_rate <= 8000)
mode = &speex_nb_mode;
else if (avctx->sample_rate <= 16000)
mode = &speex_wb_mode;
else
mode = &speex_uwb_mode;
if (avctx->extradata_size >= 80)
s->header = speex_packet_to_header(avctx->extradata, avctx->extradata_size);
avctx->sample_fmt = SAMPLE_FMT_S16;
if (s->header) {
avctx->sample_rate = s->header->rate;
avctx->channels = s->header->nb_channels;
avctx->frame_size = s->frame_size = s->header->frame_size;
if (s->header->frames_per_packet)
avctx->frame_size *= s->header->frames_per_packet;
mode = speex_lib_get_mode(s->header->mode);
if (!mode) {
av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode);
return -1;
}
} else
av_log(avctx, AV_LOG_INFO, "Missing Speex header, assuming defaults.\n");
if (avctx->channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Only stereo and mono are supported.\n");
return -1;
}
speex_bits_init(&s->bits);
s->dec_state = speex_decoder_init(mode);
if (!s->dec_state) {
av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder.\n");
return -1;
}
if (!s->header) {
speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size);
}
if (avctx->channels == 2) {
SpeexCallback callback;
callback.callback_id = SPEEX_INBAND_STEREO;
callback.func = speex_std_stereo_request_handler;
callback.data = &s->stereo;
s->stereo = (SpeexStereoState)SPEEX_STEREO_STATE_INIT;
speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback);
}
return 0;
}
static int libspeex_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
LibSpeexContext *s = avctx->priv_data;
int16_t *output = data, *end;
int i, num_samples;
num_samples = s->frame_size * avctx->channels;
end = output + *data_size / sizeof(*output);
speex_bits_read_from(&s->bits, buf, buf_size);
for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) {
int ret = speex_decode_int(s->dec_state, &s->bits, output);
if (ret <= -2) {
av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n");
return -1;
} else if (ret == -1)
// end of stream
break;
if (avctx->channels == 2)
speex_decode_stereo_int(output, s->frame_size, &s->stereo);
output += num_samples;
}
avctx->frame_size = s->frame_size * i;
*data_size = avctx->channels * avctx->frame_size * sizeof(*output);
return buf_size;
}
static av_cold int libspeex_decode_close(AVCodecContext *avctx)
{
LibSpeexContext *s = avctx->priv_data;
speex_header_free(s->header);
speex_bits_destroy(&s->bits);
speex_decoder_destroy(s->dec_state);
return 0;
}
AVCodec libspeex_decoder = {
"libspeex",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_SPEEX,
sizeof(LibSpeexContext),
libspeex_decode_init,
NULL,
libspeex_decode_close,
libspeex_decode_frame,
.long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/libspeexdec.c | C | asf20 | 4,660 |
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* data structures common to libdiracenc.c and libdiracdec.c
*/
#ifndef AVCODEC_LIBDIRAC_H
#define AVCODEC_LIBDIRAC_H
#include "avcodec.h"
#include <libdirac_common/dirac_types.h>
/**
* Table providing a Dirac chroma format to FFmpeg pixel format mapping.
*/
static const struct {
enum PixelFormat ff_pix_fmt;
dirac_chroma_t dirac_pix_fmt;
} ffmpeg_dirac_pixel_format_map[] = {
{ PIX_FMT_YUV420P, format420 },
{ PIX_FMT_YUV422P, format422 },
{ PIX_FMT_YUV444P, format444 },
};
#endif /* AVCODEC_LIBDIRAC_H */
| 123linslouis-android-video-cutter | jni/libavcodec/libdirac.h | C | asf20 | 1,390 |
/*
* Winnov WNV1 codec
* Copyright (c) 2005 Konstantin Shishkov
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Winnov WNV1 codec.
*/
#include "avcodec.h"
#include "get_bits.h"
#include "libavutil/common.h"
typedef struct WNV1Context{
AVCodecContext *avctx;
AVFrame pic;
int shift;
GetBitContext gb;
} WNV1Context;
static const uint16_t code_tab[16][2]={
{0x1FD,9}, {0xFD,8}, {0x7D,7}, {0x3D,6}, {0x1D,5}, {0x0D,4}, {0x005,3},
{0x000,1},
{0x004,3}, {0x0C,4}, {0x1C,5}, {0x3C,6}, {0x7C,7}, {0xFC,8}, {0x1FC,9}, {0xFF,8}
};
#define CODE_VLC_BITS 9
static VLC code_vlc;
/* returns modified base_value */
static inline int wnv1_get_code(WNV1Context *w, int base_value)
{
int v = get_vlc2(&w->gb, code_vlc.table, CODE_VLC_BITS, 1);
if(v==15)
return av_reverse[ get_bits(&w->gb, 8 - w->shift) ];
else
return base_value + ((v - 7)<<w->shift);
}
static int decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
WNV1Context * const l = avctx->priv_data;
AVFrame * const p= (AVFrame*)&l->pic;
unsigned char *Y,*U,*V;
int i, j;
int prev_y = 0, prev_u = 0, prev_v = 0;
uint8_t *rbuf;
rbuf = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(!rbuf){
av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n");
return -1;
}
if(p->data[0])
avctx->release_buffer(avctx, p);
p->reference = 0;
if(avctx->get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
av_free(rbuf);
return -1;
}
p->key_frame = 1;
for(i=8; i<buf_size; i++)
rbuf[i]= av_reverse[ buf[i] ];
init_get_bits(&l->gb, rbuf+8, (buf_size-8)*8);
if (buf[2] >> 4 == 6)
l->shift = 2;
else {
l->shift = 8 - (buf[2] >> 4);
if (l->shift > 4) {
av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4);
l->shift = 4;
}
if (l->shift < 1) {
av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4);
l->shift = 1;
}
}
Y = p->data[0];
U = p->data[1];
V = p->data[2];
for (j = 0; j < avctx->height; j++) {
for (i = 0; i < avctx->width / 2; i++) {
Y[i * 2] = wnv1_get_code(l, prev_y);
prev_u = U[i] = wnv1_get_code(l, prev_u);
prev_y = Y[(i * 2) + 1] = wnv1_get_code(l, Y[i * 2]);
prev_v = V[i] = wnv1_get_code(l, prev_v);
}
Y += p->linesize[0];
U += p->linesize[1];
V += p->linesize[2];
}
*data_size = sizeof(AVFrame);
*(AVFrame*)data = l->pic;
av_free(rbuf);
return buf_size;
}
static av_cold int decode_init(AVCodecContext *avctx){
WNV1Context * const l = avctx->priv_data;
static VLC_TYPE code_table[1 << CODE_VLC_BITS][2];
l->avctx = avctx;
avctx->pix_fmt = PIX_FMT_YUV422P;
code_vlc.table = code_table;
code_vlc.table_allocated = 1 << CODE_VLC_BITS;
init_vlc(&code_vlc, CODE_VLC_BITS, 16,
&code_tab[0][1], 4, 2,
&code_tab[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
return 0;
}
static av_cold int decode_end(AVCodecContext *avctx){
WNV1Context * const l = avctx->priv_data;
AVFrame *pic = &l->pic;
if (pic->data[0])
avctx->release_buffer(avctx, pic);
return 0;
}
AVCodec wnv1_decoder = {
"wnv1",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_WNV1,
sizeof(WNV1Context),
decode_init,
NULL,
decode_end,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Winnov WNV1"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/wnv1.c | C | asf20 | 4,571 |
/*
* DSP utils
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* DSP utils
*/
#include "avcodec.h"
#include "dsputil.h"
#include "simple_idct.h"
#include "faandct.h"
#include "faanidct.h"
#include "mathops.h"
#include "mpegvideo.h"
#include "config.h"
#include "lpc.h"
#include "ac3dec.h"
#include "vorbis.h"
#include "png.h"
uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, };
uint32_t ff_squareTbl[512] = {0, };
// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size
#define pb_7f (~0UL/255 * 0x7f)
#define pb_80 (~0UL/255 * 0x80)
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
};
/* Specific zigzag scan for 248 idct. NOTE that unlike the
specification, we interleave the fields */
const uint8_t ff_zigzag248_direct[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,
};
/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
DECLARE_ALIGNED(16, uint16_t, 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<=16909558 && 2<=b<=256
* for a>16909558, is an overestimate by less than 1 part in 1<<24 */
const uint32_t ff_inverse[257]={
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,
16777216
};
/* 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 const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7};
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];
#if ARCH_PPC
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;
}
}
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 = ff_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, const 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 sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
{
int s, i;
uint32_t *sq = ff_squareTbl + 256;
s = 0;
for (i = 0; i < h; 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]];
pix1 += line_size;
pix2 += line_size;
}
return s;
}
static int sse8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h)
{
int s, i;
uint32_t *sq = ff_squareTbl + 256;
s = 0;
for (i = 0; i < h; 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 h)
{
int s, i;
uint32_t *sq = ff_squareTbl + 256;
s = 0;
for (i = 0; i < h; 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;
}
/* 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 */
}
}
/**
* 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];
}
}
}
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 = ff_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 put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
/* read the pixels */
for(i=0;i<4;i++) {
pixels[0] = cm[block[0]];
pixels[1] = cm[block[1]];
pixels[2] = cm[block[2]];
pixels[3] = cm[block[3]];
pixels += line_size;
block += 8;
}
}
static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
/* read the pixels */
for(i=0;i<2;i++) {
pixels[0] = cm[block[0]];
pixels[1] = cm[block[1]];
pixels += line_size;
block += 8;
}
}
static void put_signed_pixels_clamped_c(const DCTELEM *block,
uint8_t *restrict pixels,
int line_size)
{
int i, j;
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (*block < -128)
*pixels = 0;
else if (*block > 127)
*pixels = 255;
else
*pixels = (uint8_t)(*block + 128);
block++;
pixels++;
}
pixels += (line_size - 8);
}
}
static void put_pixels_nonclamped_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
/* read the pixels */
for(i=0;i<8;i++) {
pixels[0] = block[0];
pixels[1] = block[1];
pixels[2] = block[2];
pixels[3] = block[3];
pixels[4] = block[4];
pixels[5] = block[5];
pixels[6] = block[6];
pixels[7] = 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 = ff_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;
}
}
static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
/* read the pixels */
for(i=0;i<4;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 += line_size;
block += 8;
}
}
static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels,
int line_size)
{
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
/* read the pixels */
for(i=0;i<2;i++) {
pixels[0] = cm[pixels[0] + block[0]];
pixels[1] = cm[pixels[1] + block[1]];
pixels += line_size;
block += 8;
}
}
static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
{
int i;
for(i=0;i<8;i++) {
pixels[0] += block[0];
pixels[1] += block[1];
pixels[2] += block[2];
pixels[3] += block[3];
pixels[4] += block[4];
pixels[5] += block[5];
pixels[6] += block[6];
pixels[7] += block[7];
pixels += line_size;
block += 8;
}
}
static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size)
{
int i;
for(i=0;i<4;i++) {
pixels[0] += block[0];
pixels[1] += block[1];
pixels[2] += block[2];
pixels[3] += block[3];
pixels += line_size;
block += 4;
}
}
static int sum_abs_dctelem_c(DCTELEM *block)
{
int sum=0, i;
for(i=0; i<64; i++)
sum+= FFABS(block[i]);
return sum;
}
static void fill_block16_c(uint8_t *block, uint8_t value, int line_size, int h)
{
int i;
for (i = 0; i < h; i++) {
memset(block, value, 16);
block += line_size;
}
}
static void fill_block8_c(uint8_t *block, uint8_t value, int line_size, int h)
{
int i;
for (i = 0; i < h; i++) {
memset(block, value, 8);
block += line_size;
}
}
static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize)
{
int i, j;
uint16_t *dst1 = (uint16_t *) dst;
uint16_t *dst2 = (uint16_t *)(dst + linesize);
for (j = 0; j < 8; j++) {
for (i = 0; i < 8; i++) {
dst1[i] = dst2[i] = src[i] * 0x0101;
}
src += 8;
dst1 += linesize;
dst2 += linesize;
}
}
#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), AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
uint64_t b= AV_RN64(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= AV_RN64(pixels );\
b= AV_RN64(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= AV_RN64(pixels );\
const uint64_t b= AV_RN64(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= AV_RN64(pixels );\
uint64_t b= AV_RN64(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= AV_RN64(pixels );\
b= AV_RN64(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 )), AV_RN16(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 )), AV_RN32(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 )), AV_RN32(pixels ));\
OP(*((uint32_t*)(block+4)), AV_RN32(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= AV_RN32(&src1[i*src_stride1 ]);\
b= AV_RN32(&src2[i*src_stride2 ]);\
OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\
a= AV_RN32(&src1[i*src_stride1+4]);\
b= AV_RN32(&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= AV_RN32(&src1[i*src_stride1 ]);\
b= AV_RN32(&src2[i*src_stride2 ]);\
OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\
a= AV_RN32(&src1[i*src_stride1+4]);\
b= AV_RN32(&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= AV_RN32(&src1[i*src_stride1 ]);\
b= AV_RN32(&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= AV_RN16(&src1[i*src_stride1 ]);\
b= AV_RN16(&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= AV_RN32(&src1[i*src_stride1]);\
b= AV_RN32(&src2[i*src_stride2]);\
c= AV_RN32(&src3[i*src_stride3]);\
d= AV_RN32(&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= AV_RN32(&src1[i*src_stride1+4]);\
b= AV_RN32(&src2[i*src_stride2+4]);\
c= AV_RN32(&src3[i*src_stride3+4]);\
d= AV_RN32(&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= AV_RN32(&src1[i*src_stride1]);\
b= AV_RN32(&src2[i*src_stride2]);\
c= AV_RN32(&src3[i*src_stride3]);\
d= AV_RN32(&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= AV_RN32(&src1[i*src_stride1+4]);\
b= AV_RN32(&src2[i*src_stride2+4]);\
c= AV_RN32(&src3[i*src_stride3+4]);\
d= AV_RN32(&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= AV_RN32(pixels );\
const uint32_t b= AV_RN32(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= AV_RN32(pixels );\
uint32_t b= AV_RN32(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= AV_RN32(pixels );\
b= AV_RN32(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= AV_RN32(pixels );\
const uint32_t b= AV_RN32(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= AV_RN32(pixels );\
uint32_t b= AV_RN32(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= AV_RN32(pixels );\
b= AV_RN32(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= AV_RN32(pixels );\
const uint32_t b= AV_RN32(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= AV_RN32(pixels );\
uint32_t b= AV_RN32(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= AV_RN32(pixels );\
b= AV_RN32(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 put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h);
}
static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){
put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h);
}
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;
}
}
void ff_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 + av_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= av_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= av_clip(src_x, 0, width) + av_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);\
\
if(D){\
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;\
}\
}else{\
const int E= B+C;\
const int step= C ? stride : 1;\
for(i=0; i<h; i++){\
OP(dst[0], (A*src[0] + E*src[step+0]));\
OP(dst[1], (A*src[1] + E*src[step+1]));\
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);\
\
if(D){\
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;\
}\
}else{\
const int E= B+C;\
const int step= C ? stride : 1;\
for(i=0; i<h; i++){\
OP(dst[0], (A*src[0] + E*src[step+0]));\
OP(dst[1], (A*src[1] + E*src[step+1]));\
OP(dst[2], (A*src[2] + E*src[step+2]));\
OP(dst[3], (A*src[3] + E*src[step+3]));\
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);\
\
if(D){\
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;\
}\
}else{\
const int E= B+C;\
const int step= C ? stride : 1;\
for(i=0; i<h; i++){\
OP(dst[0], (A*src[0] + E*src[step+0]));\
OP(dst[1], (A*src[1] + E*src[step+1]));\
OP(dst[2], (A*src[2] + E*src[step+2]));\
OP(dst[3], (A*src[3] + E*src[step+3]));\
OP(dst[4], (A*src[4] + E*src[step+4]));\
OP(dst[5], (A*src[5] + E*src[step+5]));\
OP(dst[6], (A*src[6] + E*src[step+6]));\
OP(dst[7], (A*src[7] + E*src[step+7]));\
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 void put_no_rnd_vc1_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++)
{
dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6;
dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6;
dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6;
dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6;
dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6;
dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6;
dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6;
dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6;
dst+= stride;
src+= stride;
}
}
static void avg_no_rnd_vc1_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++)
{
dst[0] = avg2(dst[0], ((A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6));
dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6));
dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6));
dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6));
dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6));
dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6));
dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6));
dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6));
dst+= stride;
src+= stride;
}
}
#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 = ff_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 = ff_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 = ff_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 = ff_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 av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
const int h=2;\
uint8_t *cm = ff_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]));\
dst+=dstStride;\
src+=srcStride;\
}\
}\
\
static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
const int w=2;\
uint8_t *cm = ff_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];\
OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\
OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\
dst++;\
src++;\
}\
}\
\
static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\
const int h=2;\
const int w=2;\
uint8_t *cm = ff_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+=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];\
OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\
OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\
dst++;\
tmp++;\
}\
}\
static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\
const int h=4;\
uint8_t *cm = ff_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 = ff_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 = ff_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 = ff_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 = ff_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 = ff_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;\
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_, 2)
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 = ff_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;
}
}
#if CONFIG_CAVS_DECODER
/* AVS specific */
void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
put_pixels8_c(dst, src, stride, 8);
}
void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
avg_pixels8_c(dst, src, stride, 8);
}
void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
put_pixels16_c(dst, src, stride, 16);
}
void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) {
avg_pixels16_c(dst, src, stride, 16);
}
#endif /* CONFIG_CAVS_DECODER */
#if CONFIG_VC1_DECODER
/* VC-1 specific */
void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
put_pixels8_c(dst, src, stride, 8);
}
void ff_avg_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
avg_pixels8_c(dst, src, stride, 8);
}
#endif /* CONFIG_VC1_DECODER */
#if CONFIG_RV40_DECODER
static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
put_pixels16_xy2_c(dst, src, stride, 16);
}
static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){
avg_pixels16_xy2_c(dst, src, stride, 16);
}
static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
put_pixels8_xy2_c(dst, src, stride, 8);
}
static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){
avg_pixels8_xy2_c(dst, src, stride, 8);
}
#endif /* CONFIG_RV40_DECODER */
static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){
uint8_t *cm = ff_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 void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){
if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
int x;
const int strength= ff_h263_loop_filter_strength[qscale];
for(x=0; x<8; x++){
int d1, d2, ad1;
int p0= src[x-2*stride];
int p1= src[x-1*stride];
int p2= src[x+0*stride];
int p3= src[x+1*stride];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[x-1*stride] = p1;
src[x+0*stride] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[x-2*stride] = p0 - d2;
src[x+ stride] = p3 + d2;
}
}
}
static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){
if(CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
int y;
const int strength= ff_h263_loop_filter_strength[qscale];
for(y=0; y<8; y++){
int d1, d2, ad1;
int p0= src[y*stride-2];
int p1= src[y*stride-1];
int p2= src[y*stride+0];
int p3= src[y*stride+1];
int d = (p0 - p3 + 4*(p2 - p1)) / 8;
if (d<-2*strength) d1= 0;
else if(d<- strength) d1=-2*strength - d;
else if(d< strength) d1= d;
else if(d< 2*strength) d1= 2*strength - d;
else d1= 0;
p1 += d1;
p2 -= d1;
if(p1&256) p1= ~(p1>>31);
if(p2&256) p2= ~(p2>>31);
src[y*stride-1] = p1;
src[y*stride+0] = p2;
ad1= FFABS(d1)>>1;
d2= av_clip((p0-p3)/4, -ad1, ad1);
src[y*stride-2] = p0 - d2;
src[y*stride+1] = p3 + d2;
}
}
}
static void h261_loop_filter_c(uint8_t *src, int stride){
int x,y,xy,yz;
int temp[64];
for(x=0; x<8; x++){
temp[x ] = 4*src[x ];
temp[x + 7*8] = 4*src[x + 7*stride];
}
for(y=1; y<7; y++){
for(x=0; x<8; x++){
xy = y * stride + x;
yz = y * 8 + x;
temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride];
}
}
for(y=0; y<8; y++){
src[ y*stride] = (temp[ y*8] + 2)>>2;
src[7+y*stride] = (temp[7+y*8] + 2)>>2;
for(x=1; x<7; x++){
xy = y * stride + x;
yz = y * 8 + x;
src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4;
}
}
}
static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
s = 0;
for(i=0;i<h;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_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
s = 0;
for(i=0;i<h;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_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
uint8_t *pix3 = pix2 + line_size;
s = 0;
for(i=0;i<h;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_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
uint8_t *pix3 = pix2 + line_size;
s = 0;
for(i=0;i<h;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_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
s = 0;
for(i=0;i<h;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_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
s = 0;
for(i=0;i<h;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_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
uint8_t *pix3 = pix2 + line_size;
s = 0;
for(i=0;i<h;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_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
{
int s, i;
uint8_t *pix3 = pix2 + line_size;
s = 0;
for(i=0;i<h;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 nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
MpegEncContext *c = v;
int score1=0;
int score2=0;
int x,y;
for(y=0; y<h; y++){
for(x=0; x<16; x++){
score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
}
if(y+1<h){
for(x=0; x<15; x++){
score2+= FFABS( s1[x ] - s1[x +stride]
- s1[x+1] + s1[x+1+stride])
-FFABS( s2[x ] - s2[x +stride]
- s2[x+1] + s2[x+1+stride]);
}
}
s1+= stride;
s2+= stride;
}
if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
else return score1 + FFABS(score2)*8;
}
static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){
MpegEncContext *c = v;
int score1=0;
int score2=0;
int x,y;
for(y=0; y<h; y++){
for(x=0; x<8; x++){
score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]);
}
if(y+1<h){
for(x=0; x<7; x++){
score2+= FFABS( s1[x ] - s1[x +stride]
- s1[x+1] + s1[x+1+stride])
-FFABS( s2[x ] - s2[x +stride]
- s2[x+1] + s2[x+1+stride]);
}
}
s1+= stride;
s2+= stride;
}
if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
else return score1 + FFABS(score2)*8;
}
static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){
int i;
unsigned int sum=0;
for(i=0; i<8*8; i++){
int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT));
int w= weight[i];
b>>= RECON_SHIFT;
assert(-512<b && b<512);
sum += (w*b)*(w*b)>>4;
}
return sum>>2;
}
static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){
int i;
for(i=0; i<8*8; i++){
rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
}
}
/**
* 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 it is ok but not clean and might fail for some permutations
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];
}
}
static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){
return 0;
}
void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){
int i;
memset(cmp, 0, sizeof(void*)*6);
for(i=0; i<6; i++){
switch(type&0xFF){
case FF_CMP_SAD:
cmp[i]= c->sad[i];
break;
case FF_CMP_SATD:
cmp[i]= c->hadamard8_diff[i];
break;
case FF_CMP_SSE:
cmp[i]= c->sse[i];
break;
case FF_CMP_DCT:
cmp[i]= c->dct_sad[i];
break;
case FF_CMP_DCT264:
cmp[i]= c->dct264_sad[i];
break;
case FF_CMP_DCTMAX:
cmp[i]= c->dct_max[i];
break;
case FF_CMP_PSNR:
cmp[i]= c->quant_psnr[i];
break;
case FF_CMP_BIT:
cmp[i]= c->bit[i];
break;
case FF_CMP_RD:
cmp[i]= c->rd[i];
break;
case FF_CMP_VSAD:
cmp[i]= c->vsad[i];
break;
case FF_CMP_VSSE:
cmp[i]= c->vsse[i];
break;
case FF_CMP_ZERO:
cmp[i]= zero_cmp;
break;
case FF_CMP_NSSE:
cmp[i]= c->nsse[i];
break;
#if CONFIG_DWT
case FF_CMP_W53:
cmp[i]= c->w53[i];
break;
case FF_CMP_W97:
cmp[i]= c->w97[i];
break;
#endif
default:
av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n");
}
}
}
static void clear_block_c(DCTELEM *block)
{
memset(block, 0, sizeof(DCTELEM)*64);
}
/**
* 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){
long i;
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
long a = *(long*)(src+i);
long b = *(long*)(dst+i);
*(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
}
for(; i<w; i++)
dst[i+0] += src[i+0];
}
static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
long i;
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
long a = *(long*)(src1+i);
long b = *(long*)(src2+i);
*(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80);
}
for(; i<w; i++)
dst[i] = src1[i]+src2[i];
}
static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){
long i;
#if !HAVE_FAST_UNALIGNED
if((long)src2 & (sizeof(long)-1)){
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];
}
}else
#endif
for(i=0; i<=w-sizeof(long); i+=sizeof(long)){
long a = *(long*)(src1+i);
long b = *(long*)(src2+i);
*(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80);
}
for(; i<w; i++)
dst[i+0] = src1[i+0]-src2[i+0];
}
static void add_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const 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;
}
static void sub_hfyu_median_prediction_c(uint8_t *dst, const uint8_t *src1, const 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 int add_hfyu_left_prediction_c(uint8_t *dst, const 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;
}
#if HAVE_BIGENDIAN
#define B 3
#define G 2
#define R 1
#define A 0
#else
#define B 0
#define G 1
#define R 2
#define A 3
#endif
static void add_hfyu_left_prediction_bgr32_c(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){
int i;
int r,g,b,a;
r= *red;
g= *green;
b= *blue;
a= *alpha;
for(i=0; i<w; i++){
b+= src[4*i+B];
g+= src[4*i+G];
r+= src[4*i+R];
a+= src[4*i+A];
dst[4*i+B]= b;
dst[4*i+G]= g;
dst[4*i+R]= r;
dst[4*i+A]= a;
}
*red= r;
*green= g;
*blue= b;
*alpha= a;
}
#undef B
#undef G
#undef R
#undef A
#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) (FFABS((x)+(y)) + FFABS((x)-(y)))
static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
int i;
int temp[64];
int sum=0;
assert(h==8);
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_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){
int i;
int temp[64];
int sum=0;
assert(h==8);
for(i=0; i<8; i++){
//FIXME try pointer walks
BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]);
BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]);
BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]);
BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[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]);
}
sum -= FFABS(temp[8*0] + temp[8*4]); // -mean
return sum;
}
static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
MpegEncContext * const s= (MpegEncContext *)c;
LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
assert(h==8);
s->dsp.diff_pixels(temp, src1, src2, stride);
s->dsp.fdct(temp);
return s->dsp.sum_abs_dctelem(temp);
}
#if CONFIG_GPL
#define DCT8_1D {\
const int s07 = SRC(0) + SRC(7);\
const int s16 = SRC(1) + SRC(6);\
const int s25 = SRC(2) + SRC(5);\
const int s34 = SRC(3) + SRC(4);\
const int a0 = s07 + s34;\
const int a1 = s16 + s25;\
const int a2 = s07 - s34;\
const int a3 = s16 - s25;\
const int d07 = SRC(0) - SRC(7);\
const int d16 = SRC(1) - SRC(6);\
const int d25 = SRC(2) - SRC(5);\
const int d34 = SRC(3) - SRC(4);\
const int a4 = d16 + d25 + (d07 + (d07>>1));\
const int a5 = d07 - d34 - (d25 + (d25>>1));\
const int a6 = d07 + d34 - (d16 + (d16>>1));\
const int a7 = d16 - d25 + (d34 + (d34>>1));\
DST(0, a0 + a1 ) ;\
DST(1, a4 + (a7>>2)) ;\
DST(2, a2 + (a3>>1)) ;\
DST(3, a5 + (a6>>2)) ;\
DST(4, a0 - a1 ) ;\
DST(5, a6 - (a5>>2)) ;\
DST(6, (a2>>1) - a3 ) ;\
DST(7, (a4>>2) - a7 ) ;\
}
static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
MpegEncContext * const s= (MpegEncContext *)c;
DCTELEM dct[8][8];
int i;
int sum=0;
s->dsp.diff_pixels(dct[0], src1, src2, stride);
#define SRC(x) dct[i][x]
#define DST(x,v) dct[i][x]= v
for( i = 0; i < 8; i++ )
DCT8_1D
#undef SRC
#undef DST
#define SRC(x) dct[x][i]
#define DST(x,v) sum += FFABS(v)
for( i = 0; i < 8; i++ )
DCT8_1D
#undef SRC
#undef DST
return sum;
}
#endif
static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
MpegEncContext * const s= (MpegEncContext *)c;
LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
int sum=0, i;
assert(h==8);
s->dsp.diff_pixels(temp, src1, src2, stride);
s->dsp.fdct(temp);
for(i=0; i<64; i++)
sum= FFMAX(sum, FFABS(temp[i]));
return sum;
}
static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
MpegEncContext * const s= (MpegEncContext *)c;
LOCAL_ALIGNED_16(DCTELEM, temp, [64*2]);
DCTELEM * const bak = temp+64;
int sum=0, i;
assert(h==8);
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_inter(s, temp, 0, s->qscale);
ff_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, int h){
MpegEncContext * const s= (MpegEncContext *)c;
const uint8_t *scantable= s->intra_scantable.permutated;
LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
LOCAL_ALIGNED_16(uint8_t, lsrc1, [64]);
LOCAL_ALIGNED_16(uint8_t, lsrc2, [64]);
int i, last, run, bits, level, distortion, start_i;
const int esc_length= s->ac_esc_length;
uint8_t * length;
uint8_t * last_length;
assert(h==8);
copy_block8(lsrc1, src1, 8, stride, 8);
copy_block8(lsrc2, src2, 8, stride, 8);
s->dsp.diff_pixels(temp, lsrc1, lsrc2, 8);
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){
if(s->mb_intra)
s->dct_unquantize_intra(s, temp, 0, s->qscale);
else
s->dct_unquantize_inter(s, temp, 0, s->qscale);
}
s->dsp.idct_add(lsrc2, 8, temp);
distortion= s->dsp.sse[1](NULL, lsrc2, lsrc1, 8, 8);
return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7);
}
static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){
MpegEncContext * const s= (MpegEncContext *)c;
const uint8_t *scantable= s->intra_scantable.permutated;
LOCAL_ALIGNED_16(DCTELEM, temp, [64]);
int i, last, run, bits, level, start_i;
const int esc_length= s->ac_esc_length;
uint8_t * length;
uint8_t * last_length;
assert(h==8);
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;
}
#define VSAD_INTRA(size) \
static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
int score=0; \
int x,y; \
\
for(y=1; y<h; y++){ \
for(x=0; x<size; x+=4){ \
score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \
+FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \
} \
s+= stride; \
} \
\
return score; \
}
VSAD_INTRA(8)
VSAD_INTRA(16)
static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
int score=0;
int x,y;
for(y=1; y<h; y++){
for(x=0; x<16; x++){
score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]);
}
s1+= stride;
s2+= stride;
}
return score;
}
#define SQ(a) ((a)*(a))
#define VSSE_INTRA(size) \
static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \
int score=0; \
int x,y; \
\
for(y=1; y<h; y++){ \
for(x=0; x<size; 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; \
}
VSSE_INTRA(8)
VSSE_INTRA(16)
static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){
int score=0;
int x,y;
for(y=1; y<h; 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;
}
static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2,
int size){
int score=0;
int i;
for(i=0; i<size; i++)
score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
return score;
}
WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c)
WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c)
WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c)
#if CONFIG_GPL
WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c)
#endif
WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c)
WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c)
WRAPPER8_16_SQ(rd8x8_c, rd16_c)
WRAPPER8_16_SQ(bit8x8_c, bit16_c)
static void vector_fmul_c(float *dst, const float *src, int len){
int i;
for(i=0; i<len; i++)
dst[i] *= src[i];
}
static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){
int i;
src1 += len-1;
for(i=0; i<len; i++)
dst[i] = src0[i] * src1[-i];
}
static void vector_fmul_add_c(float *dst, const float *src0, const float *src1, const float *src2, int len){
int i;
for(i=0; i<len; i++)
dst[i] = src0[i] * src1[i] + src2[i];
}
void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){
int i,j;
dst += len;
win += len;
src0+= len;
for(i=-len, j=len-1; i<0; i++, j--) {
float s0 = src0[i];
float s1 = src1[j];
float wi = win[i];
float wj = win[j];
dst[i] = s0*wj - s1*wi + add_bias;
dst[j] = s0*wi + s1*wj + add_bias;
}
}
static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
int len)
{
int i;
for (i = 0; i < len; i++)
dst[i] = src[i] * mul;
}
static void vector_fmul_sv_scalar_2_c(float *dst, const float *src,
const float **sv, float mul, int len)
{
int i;
for (i = 0; i < len; i += 2, sv++) {
dst[i ] = src[i ] * sv[0][0] * mul;
dst[i+1] = src[i+1] * sv[0][1] * mul;
}
}
static void vector_fmul_sv_scalar_4_c(float *dst, const float *src,
const float **sv, float mul, int len)
{
int i;
for (i = 0; i < len; i += 4, sv++) {
dst[i ] = src[i ] * sv[0][0] * mul;
dst[i+1] = src[i+1] * sv[0][1] * mul;
dst[i+2] = src[i+2] * sv[0][2] * mul;
dst[i+3] = src[i+3] * sv[0][3] * mul;
}
}
static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul,
int len)
{
int i;
for (i = 0; i < len; i += 2, sv++) {
dst[i ] = sv[0][0] * mul;
dst[i+1] = sv[0][1] * mul;
}
}
static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul,
int len)
{
int i;
for (i = 0; i < len; i += 4, sv++) {
dst[i ] = sv[0][0] * mul;
dst[i+1] = sv[0][1] * mul;
dst[i+2] = sv[0][2] * mul;
dst[i+3] = sv[0][3] * mul;
}
}
static void butterflies_float_c(float *restrict v1, float *restrict v2,
int len)
{
int i;
for (i = 0; i < len; i++) {
float t = v1[i] - v2[i];
v1[i] += v2[i];
v2[i] = t;
}
}
static float scalarproduct_float_c(const float *v1, const float *v2, int len)
{
float p = 0.0;
int i;
for (i = 0; i < len; i++)
p += v1[i] * v2[i];
return p;
}
static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){
int i;
for(i=0; i<len; i++)
dst[i] = src[i] * mul;
}
static inline uint32_t clipf_c_one(uint32_t a, uint32_t mini,
uint32_t maxi, uint32_t maxisign)
{
if(a > mini) return mini;
else if((a^(1<<31)) > maxisign) return maxi;
else return a;
}
static void vector_clipf_c_opposite_sign(float *dst, const float *src, float *min, float *max, int len){
int i;
uint32_t mini = *(uint32_t*)min;
uint32_t maxi = *(uint32_t*)max;
uint32_t maxisign = maxi ^ (1<<31);
uint32_t *dsti = (uint32_t*)dst;
const uint32_t *srci = (const uint32_t*)src;
for(i=0; i<len; i+=8) {
dsti[i + 0] = clipf_c_one(srci[i + 0], mini, maxi, maxisign);
dsti[i + 1] = clipf_c_one(srci[i + 1], mini, maxi, maxisign);
dsti[i + 2] = clipf_c_one(srci[i + 2], mini, maxi, maxisign);
dsti[i + 3] = clipf_c_one(srci[i + 3], mini, maxi, maxisign);
dsti[i + 4] = clipf_c_one(srci[i + 4], mini, maxi, maxisign);
dsti[i + 5] = clipf_c_one(srci[i + 5], mini, maxi, maxisign);
dsti[i + 6] = clipf_c_one(srci[i + 6], mini, maxi, maxisign);
dsti[i + 7] = clipf_c_one(srci[i + 7], mini, maxi, maxisign);
}
}
static void vector_clipf_c(float *dst, const float *src, float min, float max, int len){
int i;
if(min < 0 && max > 0) {
vector_clipf_c_opposite_sign(dst, src, &min, &max, len);
} else {
for(i=0; i < len; i+=8) {
dst[i ] = av_clipf(src[i ], min, max);
dst[i + 1] = av_clipf(src[i + 1], min, max);
dst[i + 2] = av_clipf(src[i + 2], min, max);
dst[i + 3] = av_clipf(src[i + 3], min, max);
dst[i + 4] = av_clipf(src[i + 4], min, max);
dst[i + 5] = av_clipf(src[i + 5], min, max);
dst[i + 6] = av_clipf(src[i + 6], min, max);
dst[i + 7] = av_clipf(src[i + 7], min, max);
}
}
}
static av_always_inline int float_to_int16_one(const float *src){
int_fast32_t tmp = *(const int32_t*)src;
if(tmp & 0xf0000){
tmp = (0x43c0ffff - tmp)>>31;
// is this faster on some gcc/cpu combinations?
// if(tmp > 0x43c0ffff) tmp = 0xFFFF;
// else tmp = 0;
}
return tmp - 0x8000;
}
void ff_float_to_int16_c(int16_t *dst, const float *src, long len){
int i;
for(i=0; i<len; i++)
dst[i] = float_to_int16_one(src+i);
}
void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){
int i,j,c;
if(channels==2){
for(i=0; i<len; i++){
dst[2*i] = float_to_int16_one(src[0]+i);
dst[2*i+1] = float_to_int16_one(src[1]+i);
}
}else{
for(c=0; c<channels; c++)
for(i=0, j=c; i<len; i++, j+=channels)
dst[j] = float_to_int16_one(src[c]+i);
}
}
static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift)
{
int res = 0;
while (order--)
res += (*v1++ * *v2++) >> shift;
return res;
}
static int32_t scalarproduct_and_madd_int16_c(int16_t *v1, int16_t *v2, int16_t *v3, int order, int mul)
{
int res = 0;
while (order--) {
res += *v1 * *v2++;
*v1++ += mul * *v3++;
}
return res;
}
#define W0 2048
#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) */
static void wmv2_idct_row(short * b)
{
int s1,s2;
int a0,a1,a2,a3,a4,a5,a6,a7;
/*step 1*/
a1 = W1*b[1]+W7*b[7];
a7 = W7*b[1]-W1*b[7];
a5 = W5*b[5]+W3*b[3];
a3 = W3*b[5]-W5*b[3];
a2 = W2*b[2]+W6*b[6];
a6 = W6*b[2]-W2*b[6];
a0 = W0*b[0]+W0*b[4];
a4 = W0*b[0]-W0*b[4];
/*step 2*/
s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7,
s2 = (181*(a1-a5-a7+a3)+128)>>8;
/*step 3*/
b[0] = (a0+a2+a1+a5 + (1<<7))>>8;
b[1] = (a4+a6 +s1 + (1<<7))>>8;
b[2] = (a4-a6 +s2 + (1<<7))>>8;
b[3] = (a0-a2+a7+a3 + (1<<7))>>8;
b[4] = (a0-a2-a7-a3 + (1<<7))>>8;
b[5] = (a4-a6 -s2 + (1<<7))>>8;
b[6] = (a4+a6 -s1 + (1<<7))>>8;
b[7] = (a0+a2-a1-a5 + (1<<7))>>8;
}
static void wmv2_idct_col(short * b)
{
int s1,s2;
int a0,a1,a2,a3,a4,a5,a6,a7;
/*step 1, with extended precision*/
a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3;
a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3;
a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3;
a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3;
a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3;
a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3;
a0 = (W0*b[8*0]+W0*b[8*4] )>>3;
a4 = (W0*b[8*0]-W0*b[8*4] )>>3;
/*step 2*/
s1 = (181*(a1-a5+a7-a3)+128)>>8;
s2 = (181*(a1-a5-a7+a3)+128)>>8;
/*step 3*/
b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14;
b[8*1] = (a4+a6 +s1 + (1<<13))>>14;
b[8*2] = (a4-a6 +s2 + (1<<13))>>14;
b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14;
b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14;
b[8*5] = (a4-a6 -s2 + (1<<13))>>14;
b[8*6] = (a4+a6 -s1 + (1<<13))>>14;
b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14;
}
void ff_wmv2_idct_c(short * block){
int i;
for(i=0;i<64;i+=8){
wmv2_idct_row(block+i);
}
for(i=0;i<8;i++){
wmv2_idct_col(block+i);
}
}
/* XXX: those functions should be suppressed ASAP when all IDCTs are
converted */
static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block)
{
ff_wmv2_idct_c(block);
put_pixels_clamped_c(block, dest, line_size);
}
static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block)
{
ff_wmv2_idct_c(block);
add_pixels_clamped_c(block, dest, line_size);
}
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);
}
static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block)
{
j_rev_dct4 (block);
put_pixels_clamped4_c(block, dest, line_size);
}
static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block)
{
j_rev_dct4 (block);
add_pixels_clamped4_c(block, dest, line_size);
}
static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block)
{
j_rev_dct2 (block);
put_pixels_clamped2_c(block, dest, line_size);
}
static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block)
{
j_rev_dct2 (block);
add_pixels_clamped2_c(block, dest, line_size);
}
static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block)
{
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
dest[0] = cm[(block[0] + 4)>>3];
}
static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block)
{
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
dest[0] = cm[dest[0] + ((block[0] + 4)>>3)];
}
static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; }
/* init static data */
av_cold void dsputil_static_init(void)
{
int i;
for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i;
for(i=0;i<MAX_NEG_CROP;i++) {
ff_cropTbl[i] = 0;
ff_cropTbl[i + MAX_NEG_CROP + 256] = 255;
}
for(i=0;i<512;i++) {
ff_squareTbl[i] = (i - 256) * (i - 256);
}
for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
}
int ff_check_alignment(void){
static int did_fail=0;
DECLARE_ALIGNED(16, int, aligned);
if((intptr_t)&aligned & 15){
if(!did_fail){
#if HAVE_MMX || HAVE_ALTIVEC
av_log(NULL, AV_LOG_ERROR,
"Compiler did not align stack variables. Libavcodec has been miscompiled\n"
"and may be very slow or crash. This is not a bug in libavcodec,\n"
"but in the compiler. You may try recompiling using gcc >= 4.2.\n"
"Do not report crashes to FFmpeg developers.\n");
#endif
did_fail=1;
}
return -1;
}
return 0;
}
av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
{
int i;
ff_check_alignment();
#if CONFIG_ENCODERS
if(avctx->dct_algo==FF_DCT_FASTINT) {
c->fdct = fdct_ifast;
c->fdct248 = fdct_ifast248;
}
else if(avctx->dct_algo==FF_DCT_FAAN) {
c->fdct = ff_faandct;
c->fdct248 = ff_faandct248;
}
else {
c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default
c->fdct248 = ff_fdct248_islow;
}
#endif //CONFIG_ENCODERS
if(avctx->lowres==1){
if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){
c->idct_put= ff_jref_idct4_put;
c->idct_add= ff_jref_idct4_add;
}else{
c->idct_put= ff_h264_lowres_idct_put_c;
c->idct_add= ff_h264_lowres_idct_add_c;
}
c->idct = j_rev_dct4;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->lowres==2){
c->idct_put= ff_jref_idct2_put;
c->idct_add= ff_jref_idct2_add;
c->idct = j_rev_dct2;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->lowres==3){
c->idct_put= ff_jref_idct1_put;
c->idct_add= ff_jref_idct1_add;
c->idct = j_rev_dct1;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else{
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 if((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER || CONFIG_VP6_DECODER ) &&
avctx->idct_algo==FF_IDCT_VP3){
c->idct_put= ff_vp3_idct_put_c;
c->idct_add= ff_vp3_idct_add_c;
c->idct = ff_vp3_idct_c;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->idct_algo==FF_IDCT_WMV2){
c->idct_put= ff_wmv2_idct_put_c;
c->idct_add= ff_wmv2_idct_add_c;
c->idct = ff_wmv2_idct_c;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->idct_algo==FF_IDCT_FAAN){
c->idct_put= ff_faanidct_put;
c->idct_add= ff_faanidct_add;
c->idct = ff_faanidct;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) {
c->idct_put= ff_ea_idct_put_c;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) {
c->idct = ff_bink_idct_c;
c->idct_add = ff_bink_idct_add_c;
c->idct_put = ff_bink_idct_put_c;
c->idct_permutation_type = FF_NO_IDCT_PERM;
}else{ //accurate/default
c->idct_put= ff_simple_idct_put;
c->idct_add= ff_simple_idct_add;
c->idct = ff_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->put_signed_pixels_clamped = put_signed_pixels_clamped_c;
c->put_pixels_nonclamped = put_pixels_nonclamped_c;
c->add_pixels_clamped = add_pixels_clamped_c;
c->add_pixels8 = add_pixels8_c;
c->add_pixels4 = add_pixels4_c;
c->sum_abs_dctelem = sum_abs_dctelem_c;
c->gmc1 = gmc1_c;
c->gmc = ff_gmc_c;
c->clear_block = clear_block_c;
c->clear_blocks = clear_blocks_c;
c->pix_sum = pix_sum_c;
c->pix_norm1 = pix_norm1_c;
c->fill_block_tab[0] = fill_block16_c;
c->fill_block_tab[1] = fill_block8_c;
c->scale_block = scale_block_c;
/* TODO [0] 16 [1] 8 */
c->pix_abs[0][0] = pix_abs16_c;
c->pix_abs[0][1] = pix_abs16_x2_c;
c->pix_abs[0][2] = pix_abs16_y2_c;
c->pix_abs[0][3] = pix_abs16_xy2_c;
c->pix_abs[1][0] = pix_abs8_c;
c->pix_abs[1][1] = pix_abs8_x2_c;
c->pix_abs[1][2] = pix_abs8_y2_c;
c->pix_abs[1][3] = pix_abs8_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_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;
c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;
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(put_h264_qpel, 3, 2);
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_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c;
c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c;
c->draw_edges = draw_edges_c;
#if CONFIG_CAVS_DECODER
ff_cavsdsp_init(c,avctx);
#endif
#if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER
ff_mlp_init(c, avctx);
#endif
#if CONFIG_VC1_DECODER
ff_vc1dsp_init(c,avctx);
#endif
#if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER
ff_intrax8dsp_init(c,avctx);
#endif
#if CONFIG_RV30_DECODER
ff_rv30dsp_init(c,avctx);
#endif
#if CONFIG_RV40_DECODER
ff_rv40dsp_init(c,avctx);
c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c;
c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c;
c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c;
c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c;
#endif
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;
#define SET_CMP_FUNC(name) \
c->name[0]= name ## 16_c;\
c->name[1]= name ## 8x8_c;
SET_CMP_FUNC(hadamard8_diff)
c->hadamard8_diff[4]= hadamard8_intra16_c;
c->hadamard8_diff[5]= hadamard8_intra8x8_c;
SET_CMP_FUNC(dct_sad)
SET_CMP_FUNC(dct_max)
#if CONFIG_GPL
SET_CMP_FUNC(dct264_sad)
#endif
c->sad[0]= pix_abs16_c;
c->sad[1]= pix_abs8_c;
c->sse[0]= sse16_c;
c->sse[1]= sse8_c;
c->sse[2]= sse4_c;
SET_CMP_FUNC(quant_psnr)
SET_CMP_FUNC(rd)
SET_CMP_FUNC(bit)
c->vsad[0]= vsad16_c;
c->vsad[4]= vsad_intra16_c;
c->vsad[5]= vsad_intra8_c;
c->vsse[0]= vsse16_c;
c->vsse[4]= vsse_intra16_c;
c->vsse[5]= vsse_intra8_c;
c->nsse[0]= nsse16_c;
c->nsse[1]= nsse8_c;
#if CONFIG_DWT
ff_dsputil_init_dwt(c);
#endif
c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;
c->add_bytes= add_bytes_c;
c->add_bytes_l2= add_bytes_l2_c;
c->diff_bytes= diff_bytes_c;
c->add_hfyu_median_prediction= add_hfyu_median_prediction_c;
c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;
c->add_hfyu_left_prediction = add_hfyu_left_prediction_c;
c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c;
c->bswap_buf= bswap_buf;
#if CONFIG_PNG_DECODER
c->add_png_paeth_prediction= ff_add_png_paeth_prediction;
#endif
if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) {
c->h263_h_loop_filter= h263_h_loop_filter_c;
c->h263_v_loop_filter= h263_v_loop_filter_c;
}
if (CONFIG_VP3_DECODER) {
c->vp3_h_loop_filter= ff_vp3_h_loop_filter_c;
c->vp3_v_loop_filter= ff_vp3_v_loop_filter_c;
c->vp3_idct_dc_add= ff_vp3_idct_dc_add_c;
}
if (CONFIG_VP6_DECODER) {
c->vp6_filter_diag4= ff_vp6_filter_diag4_c;
}
c->h261_loop_filter= h261_loop_filter_c;
c->try_8x8basis= try_8x8basis_c;
c->add_8x8basis= add_8x8basis_c;
#if CONFIG_VORBIS_DECODER
c->vorbis_inverse_coupling = vorbis_inverse_coupling;
#endif
#if CONFIG_AC3_DECODER
c->ac3_downmix = ff_ac3_downmix_c;
#endif
#if CONFIG_LPC
c->lpc_compute_autocorr = ff_lpc_compute_autocorr;
#endif
c->vector_fmul = vector_fmul_c;
c->vector_fmul_reverse = vector_fmul_reverse_c;
c->vector_fmul_add = vector_fmul_add_c;
c->vector_fmul_window = ff_vector_fmul_window_c;
c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c;
c->vector_clipf = vector_clipf_c;
c->float_to_int16 = ff_float_to_int16_c;
c->float_to_int16_interleave = ff_float_to_int16_interleave_c;
c->scalarproduct_int16 = scalarproduct_int16_c;
c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c;
c->scalarproduct_float = scalarproduct_float_c;
c->butterflies_float = butterflies_float_c;
c->vector_fmul_scalar = vector_fmul_scalar_c;
c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c;
c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c;
c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c;
c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c;
c->shrink[0]= ff_img_copy_plane;
c->shrink[1]= ff_shrink22;
c->shrink[2]= ff_shrink44;
c->shrink[3]= ff_shrink88;
c->prefetch= just_return;
memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));
memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));
if (HAVE_MMX) dsputil_init_mmx (c, avctx);
if (ARCH_ARM) dsputil_init_arm (c, avctx);
if (CONFIG_MLIB) dsputil_init_mlib (c, avctx);
if (HAVE_VIS) dsputil_init_vis (c, avctx);
if (ARCH_ALPHA) dsputil_init_alpha (c, avctx);
if (ARCH_PPC) dsputil_init_ppc (c, avctx);
if (HAVE_MMI) dsputil_init_mmi (c, avctx);
if (ARCH_SH4) dsputil_init_sh4 (c, avctx);
if (ARCH_BFIN) dsputil_init_bfin (c, avctx);
for(i=0; i<64; i++){
if(!c->put_2tap_qpel_pixels_tab[0][i])
c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];
if(!c->avg_2tap_qpel_pixels_tab[0][i])
c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];
}
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;
case FF_PARTTRANS_IDCT_PERM:
for(i=0; i<64; i++)
c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);
break;
case FF_SSE2_IDCT_PERM:
for(i=0; i<64; i++)
c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];
break;
default:
av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n");
}
}
| 123linslouis-android-video-cutter | jni/libavcodec/dsputil.c | C | asf20 | 164,357 |
/*
* H.26L/H.264/AVC/JVT/14496-10/... parameter set decoding
* Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* H.264 / AVC / MPEG4 part10 parameter set decoding.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "internal.h"
#include "dsputil.h"
#include "avcodec.h"
#include "h264.h"
#include "h264data.h" //FIXME FIXME FIXME (just for zigzag_scan)
#include "golomb.h"
//#undef NDEBUG
#include <assert.h>
static const AVRational pixel_aspect[17]={
{0, 1},
{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},
{4, 3},
{3, 2},
{2, 1},
};
const uint8_t ff_h264_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 default_scaling4[2][16]={
{ 6,13,20,28,
13,20,28,32,
20,28,32,37,
28,32,37,42
},{
10,14,20,24,
14,20,24,27,
20,24,27,30,
24,27,30,34
}};
static const uint8_t default_scaling8[2][64]={
{ 6,10,13,16,18,23,25,27,
10,11,16,18,23,25,27,29,
13,16,18,23,25,27,29,31,
16,18,23,25,27,29,31,33,
18,23,25,27,29,31,33,36,
23,25,27,29,31,33,36,38,
25,27,29,31,33,36,38,40,
27,29,31,33,36,38,40,42
},{
9,13,15,17,19,21,22,24,
13,13,17,19,21,22,24,25,
15,17,19,21,22,24,25,27,
17,19,21,22,24,25,27,28,
19,21,22,24,25,27,28,30,
21,22,24,25,27,28,30,32,
22,24,25,27,28,30,32,33,
24,25,27,28,30,32,33,35
}};
static inline int decode_hrd_parameters(H264Context *h, SPS *sps){
MpegEncContext * const s = &h->s;
int cpb_count, i;
cpb_count = get_ue_golomb_31(&s->gb) + 1;
if(cpb_count > 32U){
av_log(h->s.avctx, AV_LOG_ERROR, "cpb_count %d invalid\n", cpb_count);
return -1;
}
get_bits(&s->gb, 4); /* bit_rate_scale */
get_bits(&s->gb, 4); /* cpb_size_scale */
for(i=0; i<cpb_count; i++){
get_ue_golomb(&s->gb); /* bit_rate_value_minus1 */
get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */
get_bits1(&s->gb); /* cbr_flag */
}
sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;
sps->cpb_removal_delay_length = get_bits(&s->gb, 5) + 1;
sps->dpb_output_delay_length = get_bits(&s->gb, 5) + 1;
sps->time_offset_length = get_bits(&s->gb, 5);
sps->cpb_cnt = cpb_count;
return 0;
}
static inline int decode_vui_parameters(H264Context *h, SPS *sps){
MpegEncContext * const s = &h->s;
int aspect_ratio_info_present_flag;
unsigned int 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.num= get_bits(&s->gb, 16);
sps->sar.den= get_bits(&s->gb, 16);
}else if(aspect_ratio_idc < FF_ARRAY_ELEMS(pixel_aspect)){
sps->sar= pixel_aspect[aspect_ratio_idc];
}else{
av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n");
return -1;
}
}else{
sps->sar.num=
sps->sar.den= 0;
}
// s->avctx->aspect_ratio= sar_width*s->width / (float)(s->height*sar_height);
if(get_bits1(&s->gb)){ /* overscan_info_present_flag */
get_bits1(&s->gb); /* overscan_appropriate_flag */
}
sps->video_signal_type_present_flag = get_bits1(&s->gb);
if(sps->video_signal_type_present_flag){
get_bits(&s->gb, 3); /* video_format */
sps->full_range = get_bits1(&s->gb); /* video_full_range_flag */
sps->colour_description_present_flag = get_bits1(&s->gb);
if(sps->colour_description_present_flag){
sps->color_primaries = get_bits(&s->gb, 8); /* colour_primaries */
sps->color_trc = get_bits(&s->gb, 8); /* transfer_characteristics */
sps->colorspace = get_bits(&s->gb, 8); /* matrix_coefficients */
if (sps->color_primaries >= AVCOL_PRI_NB)
sps->color_primaries = AVCOL_PRI_UNSPECIFIED;
if (sps->color_trc >= AVCOL_TRC_NB)
sps->color_trc = AVCOL_TRC_UNSPECIFIED;
if (sps->colorspace >= AVCOL_SPC_NB)
sps->colorspace = AVCOL_SPC_UNSPECIFIED;
}
}
if(get_bits1(&s->gb)){ /* chroma_location_info_present_flag */
s->avctx->chroma_sample_location = get_ue_golomb(&s->gb)+1; /* chroma_sample_location_type_top_field */
get_ue_golomb(&s->gb); /* chroma_sample_location_type_bottom_field */
}
sps->timing_info_present_flag = get_bits1(&s->gb);
if(sps->timing_info_present_flag){
sps->num_units_in_tick = get_bits_long(&s->gb, 32);
sps->time_scale = get_bits_long(&s->gb, 32);
if(!sps->num_units_in_tick || !sps->time_scale){
av_log(h->s.avctx, AV_LOG_ERROR, "time_scale/num_units_in_tick invalid or unsupported (%d/%d)\n", sps->time_scale, sps->num_units_in_tick);
return -1;
}
sps->fixed_frame_rate_flag = get_bits1(&s->gb);
}
sps->nal_hrd_parameters_present_flag = get_bits1(&s->gb);
if(sps->nal_hrd_parameters_present_flag)
if(decode_hrd_parameters(h, sps) < 0)
return -1;
sps->vcl_hrd_parameters_present_flag = get_bits1(&s->gb);
if(sps->vcl_hrd_parameters_present_flag)
if(decode_hrd_parameters(h, sps) < 0)
return -1;
if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag)
get_bits1(&s->gb); /* low_delay_hrd_flag */
sps->pic_struct_present_flag = get_bits1(&s->gb);
sps->bitstream_restriction_flag = get_bits1(&s->gb);
if(sps->bitstream_restriction_flag){
get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */
get_ue_golomb(&s->gb); /* max_bytes_per_pic_denom */
get_ue_golomb(&s->gb); /* max_bits_per_mb_denom */
get_ue_golomb(&s->gb); /* log2_max_mv_length_horizontal */
get_ue_golomb(&s->gb); /* log2_max_mv_length_vertical */
sps->num_reorder_frames= get_ue_golomb(&s->gb);
get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/
if(s->gb.size_in_bits < get_bits_count(&s->gb)){
av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", get_bits_count(&s->gb) - s->gb.size_in_bits);
sps->num_reorder_frames=0;
sps->bitstream_restriction_flag= 0;
}
if(sps->num_reorder_frames > 16U /*max_dec_frame_buffering || max_dec_frame_buffering > 16*/){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal num_reorder_frames %d\n", sps->num_reorder_frames);
return -1;
}
}
return 0;
}
static void decode_scaling_list(H264Context *h, uint8_t *factors, int size,
const uint8_t *jvt_list, const uint8_t *fallback_list){
MpegEncContext * const s = &h->s;
int i, last = 8, next = 8;
const uint8_t *scan = size == 16 ? zigzag_scan : ff_zigzag_direct;
if(!get_bits1(&s->gb)) /* matrix not written, we use the predicted one */
memcpy(factors, fallback_list, size*sizeof(uint8_t));
else
for(i=0;i<size;i++){
if(next)
next = (last + get_se_golomb(&s->gb)) & 0xff;
if(!i && !next){ /* matrix not written, we use the preset one */
memcpy(factors, jvt_list, size*sizeof(uint8_t));
break;
}
last = factors[scan[i]] = next ? next : last;
}
}
static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_sps,
uint8_t (*scaling_matrix4)[16], uint8_t (*scaling_matrix8)[64]){
MpegEncContext * const s = &h->s;
int fallback_sps = !is_sps && sps->scaling_matrix_present;
const uint8_t *fallback[4] = {
fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0],
fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1],
fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0],
fallback_sps ? sps->scaling_matrix8[1] : default_scaling8[1]
};
if(get_bits1(&s->gb)){
sps->scaling_matrix_present |= is_sps;
decode_scaling_list(h,scaling_matrix4[0],16,default_scaling4[0],fallback[0]); // Intra, Y
decode_scaling_list(h,scaling_matrix4[1],16,default_scaling4[0],scaling_matrix4[0]); // Intra, Cr
decode_scaling_list(h,scaling_matrix4[2],16,default_scaling4[0],scaling_matrix4[1]); // Intra, Cb
decode_scaling_list(h,scaling_matrix4[3],16,default_scaling4[1],fallback[1]); // Inter, Y
decode_scaling_list(h,scaling_matrix4[4],16,default_scaling4[1],scaling_matrix4[3]); // Inter, Cr
decode_scaling_list(h,scaling_matrix4[5],16,default_scaling4[1],scaling_matrix4[4]); // Inter, Cb
if(is_sps || pps->transform_8x8_mode){
decode_scaling_list(h,scaling_matrix8[0],64,default_scaling8[0],fallback[2]); // Intra, Y
decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y
}
}
}
int ff_h264_decode_seq_parameter_set(H264Context *h){
MpegEncContext * const s = &h->s;
int profile_idc, level_idc;
unsigned int sps_id;
int 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_bits1(&s->gb); //constraint_set3_flag
get_bits(&s->gb, 4); // reserved
level_idc= get_bits(&s->gb, 8);
sps_id= get_ue_golomb_31(&s->gb);
if(sps_id >= MAX_SPS_COUNT) {
av_log(h->s.avctx, AV_LOG_ERROR, "sps_id (%d) out of range\n", sps_id);
return -1;
}
sps= av_mallocz(sizeof(SPS));
if(sps == NULL)
return -1;
sps->profile_idc= profile_idc;
sps->level_idc= level_idc;
memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
sps->scaling_matrix_present = 0;
if(sps->profile_idc >= 100){ //high profile
sps->chroma_format_idc= get_ue_golomb_31(&s->gb);
if(sps->chroma_format_idc == 3)
sps->residual_color_transform_flag = get_bits1(&s->gb);
sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8;
sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8;
sps->transform_bypass = get_bits1(&s->gb);
decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);
}else{
sps->chroma_format_idc= 1;
sps->bit_depth_luma = 8;
sps->bit_depth_chroma = 8;
}
sps->log2_max_frame_num= get_ue_golomb(&s->gb) + 4;
sps->poc_type= get_ue_golomb_31(&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);
if((unsigned)sps->poc_cycle_length >= FF_ARRAY_ELEMS(sps->offset_for_ref_frame)){
av_log(h->s.avctx, AV_LOG_ERROR, "poc_cycle_length overflow %u\n", sps->poc_cycle_length);
goto fail;
}
for(i=0; i<sps->poc_cycle_length; i++)
sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb);
}else if(sps->poc_type != 2){
av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type);
goto fail;
}
sps->ref_frame_count= get_ue_golomb_31(&s->gb);
if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){
av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n");
goto fail;
}
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;
if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 ||
avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)){
av_log(h->s.avctx, AV_LOG_ERROR, "mb_width/height overflow\n");
goto fail;
}
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);
if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){
av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
goto fail;
}
#ifndef ALLOW_INTERLACE
if(sps->mb_aff)
av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF support not included; enable it at compile-time.\n");
#endif
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){
av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n");
}
if(sps->crop_right >= 8 || sps->crop_bottom >= (8>> !sps->frame_mbs_only_flag)){
av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not 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 )
if (decode_vui_parameters(h, sps) < 0)
goto fail;
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\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" : "",
((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc],
sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
sps->timing_info_present_flag ? sps->time_scale : 0
);
}
av_free(h->sps_buffers[sps_id]);
h->sps_buffers[sps_id]= sps;
h->sps = *sps;
return 0;
fail:
av_free(sps);
return -1;
}
static void
build_qp_table(PPS *pps, int t, int index)
{
int i;
for(i = 0; i < 52; i++)
pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)];
}
int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){
MpegEncContext * const s = &h->s;
unsigned int pps_id= get_ue_golomb(&s->gb);
PPS *pps;
if(pps_id >= MAX_PPS_COUNT) {
av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id);
return -1;
}
pps= av_mallocz(sizeof(PPS));
if(pps == NULL)
return -1;
pps->sps_id= get_ue_golomb_31(&s->gb);
if((unsigned)pps->sps_id>=MAX_SPS_COUNT || h->sps_buffers[pps->sps_id] == NULL){
av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n");
goto fail;
}
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);
av_log(h->s.avctx, AV_LOG_ERROR, "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]-1 > 32-1 || pps->ref_count[1]-1 > 32-1){
av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n");
goto fail;
}
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[0]= 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);
pps->transform_8x8_mode= 0;
h->dequant_coeff_pps= -1; //contents of sps/pps can change even if id doesn't, so reinit
memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4));
memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8));
if(get_bits_count(&s->gb) < bit_length){
pps->transform_8x8_mode= get_bits1(&s->gb);
decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8);
pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset
} else {
pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0];
}
build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]);
build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]);
if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1])
pps->chroma_qp_diff= 1;
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %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[0], pps->chroma_qp_index_offset[1],
pps->deblocking_filter_parameters_present ? "LPAR" : "",
pps->constrained_intra_pred ? "CONSTR" : "",
pps->redundant_pic_cnt_present ? "REDU" : "",
pps->transform_8x8_mode ? "8x8DCT" : ""
);
}
av_free(h->pps_buffers[pps_id]);
h->pps_buffers[pps_id]= pps;
return 0;
fail:
av_free(pps);
return -1;
}
| 123linslouis-android-video-cutter | jni/libavcodec/h264_ps.c | C | asf20 | 20,520 |
/*
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "libavutil/bswap.h"
static av_cold int decode_init(AVCodecContext *avctx)
{
if(avctx->width & 1){
av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
return -1;
}
avctx->pix_fmt = PIX_FMT_YUV422P16;
avctx->bits_per_raw_sample= 10;
avctx->coded_frame= avcodec_alloc_frame();
return 0;
}
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
int y=0;
int width= avctx->width;
AVFrame *pic= avctx->coded_frame;
const uint32_t *src= (const uint32_t *)avpkt->data;
uint16_t *ydst, *udst, *vdst, *yend;
if(pic->data[0])
avctx->release_buffer(avctx, pic);
if(avpkt->size < avctx->width * avctx->height * 8 / 3){
av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
return -1;
}
if(avpkt->size > avctx->width * avctx->height * 8 / 3){
av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n");
}
pic->reference= 0;
if(avctx->get_buffer(avctx, pic) < 0)
return -1;
ydst= (uint16_t *)pic->data[0];
udst= (uint16_t *)pic->data[1];
vdst= (uint16_t *)pic->data[2];
yend= ydst + width;
pic->pict_type= FF_I_TYPE;
pic->key_frame= 1;
for(;;){
uint32_t v= be2me_32(*src++);
*udst++= (v>>16) & 0xFFC0;
*ydst++= (v>>6 ) & 0xFFC0;
*vdst++= (v<<4 ) & 0xFFC0;
v= be2me_32(*src++);
*ydst++= (v>>16) & 0xFFC0;
if(ydst >= yend){
ydst+= pic->linesize[0]/2 - width;
udst+= pic->linesize[1]/2 - width/2;
vdst+= pic->linesize[2]/2 - width/2;
yend= ydst + width;
if(++y >= avctx->height)
break;
}
*udst++= (v>>6 ) & 0xFFC0;
*ydst++= (v<<4 ) & 0xFFC0;
v= be2me_32(*src++);
*vdst++= (v>>16) & 0xFFC0;
*ydst++= (v>>6 ) & 0xFFC0;
if(ydst >= yend){
ydst+= pic->linesize[0]/2 - width;
udst+= pic->linesize[1]/2 - width/2;
vdst+= pic->linesize[2]/2 - width/2;
yend= ydst + width;
if(++y >= avctx->height)
break;
}
*udst++= (v<<4 ) & 0xFFC0;
v= be2me_32(*src++);
*ydst++= (v>>16) & 0xFFC0;
*vdst++= (v>>6 ) & 0xFFC0;
*ydst++= (v<<4 ) & 0xFFC0;
if(ydst >= yend){
ydst+= pic->linesize[0]/2 - width;
udst+= pic->linesize[1]/2 - width/2;
vdst+= pic->linesize[2]/2 - width/2;
yend= ydst + width;
if(++y >= avctx->height)
break;
}
}
*data_size=sizeof(AVFrame);
*(AVFrame*)data= *avctx->coded_frame;
return avpkt->size;
}
static av_cold int decode_close(AVCodecContext *avctx)
{
AVFrame *pic = avctx->coded_frame;
if (pic->data[0])
avctx->release_buffer(avctx, pic);
av_freep(&avctx->coded_frame);
return 0;
}
AVCodec v210x_decoder = {
"v210x",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_V210X,
0,
decode_init,
NULL,
decode_close,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/v210x.c | C | asf20 | 4,041 |
/*
* Windows Media Voice (WMAVoice) tables.
* Copyright (c) 2009 Ronald S. Bultje
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* @brief Windows Media Voice (WMAVoice) tables
* @author Ronald S. Bultje <rsbultje@gmail.com>
*/
#ifndef AVCODEC_WMAVOICE_DATA_H
#define AVCODEC_WMAVOICE_DATA_H
#include <stdint.h>
static const uint8_t wmavoice_dq_lsp10i[0xf00] = {
125, 109, 84, 55, 34, 51, 109, 112, 118, 132,
122, 102, 78, 80, 132, 119, 132, 132, 125, 131,
109, 91, 131, 131, 136, 136, 137, 137, 140, 145,
140, 143, 117, 136, 122, 106, 109, 91, 115, 119,
133, 117, 103, 80, 55, 117, 123, 102, 93, 80,
139, 116, 70, 39, 95, 89, 103, 113, 112, 122,
135, 244, 229, 215, 199, 181, 163, 150, 146, 144,
143, 173, 171, 154, 155, 154, 151, 148, 145, 143,
132, 138, 116, 85, 117, 94, 108, 117, 107, 116,
132, 118, 123, 119, 88, 67, 49, 95, 84, 95,
121, 103, 74, 70, 179, 164, 141, 126, 107, 112,
119, 95, 103, 149, 139, 148, 144, 147, 148, 141,
151, 133, 142, 129, 111, 131, 108, 128, 122, 108,
121, 96, 115, 138, 116, 93, 105, 115, 115, 123,
129, 106, 136, 180, 147, 130, 108, 141, 131, 118,
136, 155, 176, 156, 135, 129, 140, 146, 142, 134,
141, 130, 109, 80, 52, 38, 18, 47, 118, 134,
155, 141, 100, 78, 72, 89, 79, 96, 92, 98,
133, 111, 83, 91, 72, 58, 105, 115, 112, 120,
145, 127, 135, 113, 113, 105, 105, 85, 69, 61,
115, 96, 116, 145, 159, 170, 175, 175, 168, 155,
140, 120, 84, 52, 80, 145, 125, 127, 116, 126,
128, 108, 101, 198, 227, 200, 178, 159, 147, 148,
121, 88, 46, 109, 124, 126, 126, 137, 147, 147,
129, 107, 164, 148, 127, 117, 134, 120, 111, 116,
120, 103, 98, 73, 66, 61, 70, 115, 116, 125,
126, 100, 77, 188, 162, 140, 114, 128, 139, 123,
145, 165, 164, 134, 109, 100, 108, 118, 127, 130,
156, 182, 190, 173, 167, 165, 162, 157, 152, 147,
150, 164, 179, 183, 173, 155, 140, 136, 134, 135,
122, 92, 69, 140, 132, 118, 108, 128, 138, 132,
123, 127, 148, 137, 150, 149, 139, 127, 124, 130,
136, 138, 112, 70, 41, 37, 132, 140, 129, 125,
130, 111, 78, 33, 51, 161, 141, 136, 120, 122,
126, 110, 87, 106, 85, 68, 48, 81, 112, 113,
135, 125, 98, 85, 102, 80, 100, 87, 86, 116,
142, 133, 110, 66, 48, 152, 139, 135, 136, 123,
128, 116, 89, 102, 128, 99, 83, 61, 105, 124,
120, 94, 73, 83, 78, 100, 122, 124, 128, 132,
144, 137, 116, 102, 75, 144, 136, 127, 140, 127,
154, 144, 118, 99, 90, 90, 89, 75, 68, 83,
123, 103, 89, 198, 180, 154, 138, 122, 136, 120,
138, 118, 121, 136, 110, 105, 85, 111, 101, 104,
121, 126, 139, 115, 99, 101, 107, 110, 123, 126,
127, 115, 88, 109, 164, 134, 138, 138, 120, 121,
130, 202, 195, 202, 199, 201, 181, 164, 159, 148,
120, 116, 194, 199, 186, 171, 154, 142, 137, 133,
137, 129, 112, 149, 134, 112, 149, 138, 120, 134,
119, 102, 107, 83, 79, 114, 119, 127, 128, 128,
144, 148, 165, 155, 161, 150, 135, 122, 116, 115,
120, 99, 80, 120, 123, 124, 111, 89, 70, 108,
118, 95, 66, 53, 105, 126, 125, 105, 83, 111,
129, 197, 191, 197, 206, 213, 216, 208, 196, 169,
133, 109, 127, 164, 134, 121, 99, 92, 82, 71,
131, 121, 93, 91, 136, 105, 115, 140, 120, 110,
150, 164, 139, 108, 87, 81, 93, 92, 104, 116,
133, 114, 125, 126, 111, 136, 110, 156, 147, 133,
113, 94, 118, 120, 115, 125, 124, 126, 127, 134,
116, 131, 161, 158, 166, 157, 150, 150, 144, 141,
125, 185, 169, 142, 140, 143, 139, 131, 134, 138,
179, 188, 170, 150, 134, 140, 144, 133, 127, 127,
150, 177, 204, 184, 192, 194, 190, 193, 177, 158,
114, 113, 138, 116, 137, 135, 132, 131, 127, 134,
120, 147, 163, 135, 133, 137, 136, 136, 133, 135,
137, 120, 95, 73, 46, 48, 111, 97, 97, 123,
139, 130, 109, 76, 52, 72, 61, 61, 125, 127,
132, 119, 119, 90, 66, 41, 64, 156, 143, 129,
131, 106, 58, 25, 99, 115, 122, 136, 129, 132,
134, 123, 97, 53, 27, 114, 125, 114, 120, 123,
122, 107, 93, 57, 47, 133, 128, 138, 141, 131,
145, 132, 122, 110, 79, 57, 30, 73, 153, 144,
150, 132, 85, 59, 133, 125, 130, 115, 100, 96,
148, 127, 111, 86, 61, 38, 110, 121, 108, 99,
157, 143, 105, 77, 116, 118, 115, 131, 122, 122,
133, 119, 134, 108, 86, 61, 129, 165, 143, 127,
125, 105, 89, 111, 97, 85, 113, 99, 98, 117,
149, 131, 101, 106, 88, 95, 79, 119, 123, 120,
125, 109, 81, 100, 201, 183, 156, 138, 115, 116,
141, 119, 129, 105, 76, 60, 110, 99, 92, 82,
150, 156, 129, 95, 69, 115, 115, 113, 134, 125,
118, 97, 67, 96, 203, 197, 171, 151, 133, 125,
143, 131, 120, 134, 105, 80, 51, 60, 139, 134,
129, 160, 223, 219, 219, 212, 197, 173, 157, 146,
132, 112, 164, 144, 119, 102, 92, 76, 73, 94,
132, 112, 124, 114, 93, 92, 83, 73, 69, 99,
129, 103, 188, 163, 142, 132, 127, 101, 82, 59,
140, 141, 111, 74, 46, 105, 113, 99, 127, 122,
125, 94, 63, 112, 116, 101, 81, 120, 136, 134,
133, 190, 224, 193, 179, 158, 146, 143, 140, 136,
152, 161, 132, 120, 112, 94, 114, 102, 92, 116,
129, 194, 196, 202, 211, 212, 210, 190, 169, 152,
166, 166, 145, 111, 91, 132, 133, 128, 136, 130,
118, 94, 72, 74, 92, 86, 89, 92, 106, 123,
126, 100, 86, 137, 117, 92, 76, 104, 106, 114,
133, 109, 204, 192, 166, 148, 138, 128, 111, 81,
118, 99, 79, 146, 169, 141, 123, 102, 131, 120,
127, 105, 136, 204, 170, 154, 131, 145, 135, 119,
117, 95, 64, 83, 141, 136, 118, 96, 99, 126,
115, 93, 98, 102, 95, 105, 106, 114, 119, 128,
131, 121, 98, 139, 149, 119, 109, 86, 105, 129,
134, 119, 104, 169, 185, 155, 141, 122, 107, 127,
136, 115, 85, 108, 87, 126, 102, 128, 136, 129,
125, 99, 126, 158, 133, 139, 132, 113, 91, 107,
141, 122, 128, 161, 130, 127, 105, 120, 118, 106,
122, 140, 161, 168, 187, 184, 176, 158, 144, 140,
127, 111, 89, 130, 132, 105, 134, 121, 100, 122,
129, 110, 128, 115, 129, 116, 132, 118, 114, 119,
138, 133, 132, 188, 183, 159, 161, 147, 134, 140,
132, 113, 84, 167, 147, 132, 124, 109, 133, 121,
132, 128, 116, 121, 98, 101, 145, 129, 128, 129,
124, 112, 152, 158, 136, 161, 139, 165, 158, 142,
139, 138, 110, 127, 148, 117, 126, 118, 101, 116,
155, 168, 154, 128, 120, 152, 150, 141, 140, 135,
127, 111, 109, 134, 104, 133, 110, 112, 132, 114,
111, 87, 68, 89, 107, 121, 121, 126, 126, 129,
120, 148, 169, 163, 173, 178, 185, 188, 178, 163,
122, 97, 86, 117, 101, 138, 118, 142, 155, 139,
125, 114, 131, 138, 153, 149, 163, 150, 143, 141,
157, 161, 138, 152, 134, 121, 122, 109, 110, 124,
151, 171, 196, 168, 145, 139, 147, 151, 146, 139,
134, 169, 179, 170, 175, 178, 177, 173, 165, 154,
120, 151, 118, 107, 125, 129, 133, 133, 136, 139,
119, 141, 159, 151, 160, 165, 168, 169, 162, 152,
115, 111, 119, 94, 117, 121, 127, 127, 132, 136,
134, 153, 147, 142, 142, 147, 159, 159, 154, 147,
110, 106, 139, 135, 143, 142, 147, 146, 147, 147,
115, 133, 151, 133, 141, 142, 151, 152, 147, 144,
115, 132, 144, 131, 125, 126, 128, 130, 131, 136,
138, 118, 96, 71, 48, 26, 43, 130, 125, 125,
134, 122, 98, 54, 28, 84, 77, 73, 109, 125,
133, 112, 67, 48, 141, 129, 126, 113, 112, 118,
143, 123, 89, 54, 71, 73, 75, 131, 123, 123,
126, 109, 81, 31, 15, 94, 110, 109, 119, 128,
132, 122, 97, 92, 73, 50, 27, 22, 104, 133,
133, 119, 94, 48, 34, 168, 160, 154, 151, 130,
147, 133, 90, 54, 71, 123, 106, 105, 93, 117,
143, 132, 107, 69, 45, 78, 178, 169, 150, 139,
138, 123, 116, 96, 69, 49, 32, 113, 103, 112,
154, 151, 125, 79, 60, 152, 160, 154, 155, 137,
142, 151, 124, 88, 66, 59, 94, 87, 95, 119,
166, 154, 122, 92, 138, 132, 124, 114, 97, 97,
122, 99, 98, 219, 191, 176, 165, 159, 153, 131,
130, 119, 91, 51, 24, 41, 144, 156, 147, 139,
139, 122, 81, 65, 124, 111, 104, 90, 94, 98,
138, 120, 112, 91, 63, 65, 89, 75, 78, 106,
126, 107, 91, 85, 69, 95, 90, 84, 108, 120,
155, 139, 100, 78, 120, 110, 109, 91, 77, 73,
144, 130, 135, 112, 88, 65, 62, 142, 129, 126,
170, 154, 150, 131, 121, 116, 100, 92, 83, 86,
131, 122, 98, 107, 102, 75, 54, 38, 117, 130,
146, 139, 117, 107, 86, 66, 44, 30, 97, 128,
129, 116, 100, 59, 108, 127, 119, 139, 129, 129,
124, 106, 79, 49, 154, 190, 166, 152, 133, 123,
141, 149, 123, 89, 61, 70, 143, 132, 125, 126,
136, 113, 177, 166, 141, 123, 109, 108, 105, 93,
137, 117, 147, 123, 99, 85, 109, 98, 91, 75,
129, 121, 102, 78, 53, 90, 149, 136, 134, 135,
144, 136, 126, 90, 114, 152, 137, 152, 138, 128,
133, 115, 107, 129, 99, 78, 60, 129, 125, 118,
147, 141, 119, 124, 110, 91, 79, 64, 106, 117,
134, 111, 164, 143, 123, 113, 116, 95, 76, 56,
147, 159, 140, 109, 83, 84, 140, 135, 127, 129,
123, 104, 116, 99, 91, 87, 80, 110, 113, 121,
124, 106, 174, 174, 152, 141, 132, 134, 126, 124,
140, 190, 240, 215, 212, 189, 173, 158, 144, 137,
123, 97, 79, 102, 110, 111, 90, 75, 126, 124,
134, 121, 104, 145, 127, 100, 77, 65, 120, 118,
123, 106, 87, 41, 68, 119, 106, 115, 109, 119,
137, 232, 241, 225, 217, 202, 183, 169, 156, 145,
161, 146, 127, 110, 97, 107, 88, 114, 108, 106,
141, 244, 216, 192, 172, 163, 148, 143, 144, 144,
128, 127, 109, 89, 77, 68, 124, 120, 121, 125,
125, 94, 48, 71, 116, 113, 104, 120, 142, 137,
133, 129, 115, 82, 68, 120, 99, 133, 134, 124,
130, 106, 108, 160, 130, 111, 89, 129, 124, 119,
134, 120, 149, 143, 116, 95, 87, 142, 132, 122,
126, 114, 108, 107, 80, 141, 133, 123, 137, 124,
117, 95, 69, 43, 62, 98, 114, 116, 112, 120,
122, 99, 87, 164, 145, 123, 99, 95, 118, 105,
126, 101, 102, 120, 113, 110, 92, 139, 134, 126,
148, 194, 241, 219, 221, 215, 200, 193, 174, 151,
127, 104, 122, 136, 113, 106, 110, 95, 78, 106,
131, 163, 217, 199, 194, 175, 164, 155, 142, 138,
139, 124, 88, 57, 161, 161, 145, 139, 124, 116,
127, 110, 91, 98, 126, 104, 113, 98, 94, 94,
145, 138, 114, 90, 75, 130, 117, 107, 99, 90,
119, 98, 86, 101, 148, 133, 103, 83, 124, 131,
143, 168, 169, 133, 110, 117, 139, 149, 147, 137,
124, 106, 80, 138, 194, 163, 142, 119, 106, 130,
136, 125, 105, 114, 87, 113, 101, 89, 108, 102,
114, 90, 53, 46, 105, 116, 126, 122, 118, 122,
124, 102, 92, 195, 167, 160, 144, 154, 154, 132,
118, 97, 88, 72, 98, 120, 112, 98, 79, 117,
114, 107, 185, 191, 191, 188, 175, 165, 153, 143,
119, 97, 90, 89, 120, 151, 136, 113, 99, 112,
141, 121, 144, 122, 125, 113, 133, 111, 92, 69,
120, 98, 78, 109, 151, 145, 157, 157, 151, 143,
130, 110, 120, 188, 159, 141, 119, 112, 109, 98,
126, 112, 83, 110, 169, 139, 127, 105, 93, 123,
141, 145, 117, 106, 91, 78, 123, 107, 101, 125,
117, 95, 71, 147, 176, 153, 148, 133, 135, 127,
124, 106, 79, 64, 115, 96, 108, 115, 106, 105,
127, 115, 90, 98, 105, 81, 144, 135, 117, 125,
126, 104, 98, 165, 138, 136, 112, 149, 148, 131,
119, 144, 186, 185, 204, 202, 209, 200, 182, 161,
123, 153, 190, 189, 199, 194, 191, 176, 157, 147,
121, 103, 119, 98, 100, 120, 106, 97, 95, 126,
137, 130, 102, 117, 117, 92, 126, 114, 101, 118,
131, 219, 190, 167, 153, 151, 144, 140, 142, 143,
114, 102, 151, 152, 132, 120, 112, 120, 127, 131,
138, 122, 91, 143, 118, 120, 114, 104, 124, 117,
148, 142, 117, 126, 97, 125, 108, 116, 142, 125,
126, 106, 91, 169, 208, 178, 158, 138, 127, 135,
133, 126, 101, 83, 147, 130, 125, 117, 114, 117,
120, 103, 94, 149, 136, 129, 139, 118, 133, 133,
147, 152, 126, 132, 119, 97, 132, 129, 114, 126,
112, 107, 148, 125, 112, 114, 124, 125, 129, 135,
139, 121, 157, 151, 131, 140, 118, 147, 136, 121,
115, 105, 159, 167, 185, 191, 196, 190, 176, 160,
124, 106, 104, 122, 130, 114, 152, 144, 134, 136,
136, 152, 159, 153, 131, 114, 116, 126, 129, 129,
124, 109, 87, 131, 107, 115, 130, 107, 144, 131,
126, 162, 176, 175, 180, 176, 160, 141, 134, 134,
136, 127, 108, 161, 162, 133, 141, 124, 112, 128,
130, 115, 110, 140, 107, 155, 134, 131, 156, 137,
122, 106, 116, 127, 118, 161, 150, 170, 167, 152,
139, 177, 203, 176, 155, 139, 130, 128, 129, 132,
137, 119, 125, 103, 110, 123, 107, 120, 108, 101,
113, 107, 160, 154, 160, 166, 169, 176, 168, 156,
115, 90, 65, 115, 115, 104, 120, 112, 109, 124,
131, 123, 100, 109, 185, 158, 141, 132, 116, 119,
139, 130, 119, 156, 124, 138, 127, 116, 141, 128,
133, 118, 115, 180, 149, 151, 135, 130, 147, 129,
117, 90, 80, 119, 124, 128, 132, 130, 128, 135,
112, 97, 142, 161, 167, 165, 154, 142, 136, 135,
118, 141, 193, 172, 157, 152, 148, 145, 146, 141,
125, 147, 165, 166, 149, 133, 123, 122, 128, 131,
128, 193, 177, 174, 182, 186, 197, 193, 191, 173,
124, 144, 162, 133, 113, 113, 123, 128, 129, 130,
117, 98, 121, 122, 137, 132, 110, 97, 111, 130,
128, 176, 151, 125, 126, 134, 130, 121, 127, 130,
122, 151, 142, 111, 106, 121, 126, 126, 130, 134,
148, 167, 186, 153, 129, 122, 124, 128, 130, 128,
148, 172, 206, 178, 171, 182, 169, 180, 172, 156,
133, 164, 174, 160, 155, 163, 163, 172, 169, 158,
132, 150, 147, 142, 152, 140, 140, 140, 134, 135,
137, 158, 167, 172, 163, 153, 169, 158, 146, 147,
150, 161, 162, 172, 153, 133, 140, 144, 136, 135,
109, 84, 101, 120, 129, 134, 133, 136, 137, 143,
112, 114, 157, 147, 141, 136, 135, 133, 135, 138,
121, 154, 161, 150, 149, 154, 151, 144, 146, 144,
111, 117, 125, 125, 130, 131, 135, 137, 143, 148,
121, 141, 146, 131, 138, 126, 118, 111, 119, 130,
120, 135, 145, 121, 140, 134, 138, 137, 131, 134,
115, 137, 132, 137, 139, 138, 138, 139, 145, 149,
131, 149, 147, 133, 132, 126, 131, 134, 130, 133,
110, 98, 84, 141, 107, 169, 169, 123, 125, 126,
118, 210, 98, 126, 132, 138, 128, 139, 156, 157,
140, 142, 129, 95, 192, 178, 182, 186, 183, 159,
135, 134, 144, 124, 100, 228, 203, 161, 122, 104,
139, 159, 134, 161, 121, 126, 192, 152, 218, 180,
132, 132, 119, 99, 96, 97, 80, 53, 134, 143,
102, 114, 133, 114, 127, 83, 77, 126, 85, 107,
110, 114, 194, 186, 139, 116, 147, 104, 129, 138,
126, 133, 109, 144, 115, 45, 130, 97, 159, 155,
157, 162, 189, 185, 168, 163, 151, 151, 142, 135,
144, 147, 120, 74, 192, 186, 149, 118, 71, 84,
143, 156, 133, 178, 168, 107, 119, 149, 105, 112,
182, 184, 158, 118, 118, 148, 128, 177, 171, 152,
139, 135, 126, 209, 171, 150, 123, 100, 190, 158,
166, 97, 136, 123, 136, 139, 128, 138, 126, 121,
132, 131, 128, 95, 60, 168, 127, 140, 208, 161,
109, 102, 119, 162, 150, 137, 107, 200, 156, 136,
136, 128, 103, 95, 74, 91, 220, 173, 152, 138,
139, 129, 140, 136, 122, 82, 180, 115, 53, 90,
121, 107, 99, 148, 116, 139, 100, 63, 191, 155,
130, 129, 163, 155, 98, 175, 95, 151, 127, 107,
124, 124, 116, 88, 71, 164, 148, 96, 57, 89,
125, 117, 77, 63, 162, 144, 113, 109, 137, 134,
134, 130, 149, 174, 158, 158, 130, 81, 28, 67,
142, 139, 129, 100, 194, 134, 68, 175, 131, 103,
136, 132, 122, 96, 119, 82, 115, 249, 215, 168,
125, 139, 199, 96, 146, 123, 136, 179, 142, 137,
181, 166, 106, 86, 122, 106, 123, 131, 106, 119,
129, 189, 188, 147, 126, 110, 101, 114, 147, 136,
132, 106, 72, 175, 148, 99, 130, 153, 125, 136,
123, 119, 147, 170, 157, 126, 209, 188, 158, 152,
101, 89, 142, 131, 161, 150, 148, 124, 89, 119,
141, 137, 131, 103, 81, 85, 64, 175, 129, 121,
137, 144, 142, 145, 119, 205, 148, 80, 165, 138,
143, 137, 167, 165, 148, 149, 110, 234, 217, 170,
167, 152, 75, 140, 155, 155, 175, 129, 136, 134,
136, 152, 161, 131, 140, 121, 91, 79, 255, 209,
132, 147, 120, 114, 177, 128, 110, 61, 89, 131,
125, 127, 93, 87, 167, 115, 186, 162, 107, 106,
134, 162, 151, 100, 79, 67, 151, 116, 130, 142,
162, 153, 155, 143, 122, 85, 202, 187, 135, 125,
158, 155, 103, 129, 74, 149, 130, 98, 129, 126,
148, 152, 153, 133, 118, 94, 80, 70, 47, 90,
124, 118, 143, 184, 158, 126, 70, 82, 111, 113,
126, 135, 175, 141, 203, 166, 123, 123, 134, 133,
113, 111, 128, 76, 128, 177, 151, 178, 134, 125,
120, 120, 193, 106, 98, 134, 101, 86, 101, 114,
136, 127, 134, 196, 86, 105, 145, 128, 119, 137,
138, 126, 230, 161, 141, 128, 129, 136, 88, 83,
103, 118, 178, 123, 89, 101, 161, 173, 165, 147,
130, 123, 171, 158, 131, 81, 50, 177, 162, 136,
125, 115, 82, 173, 195, 168, 130, 112, 112, 121,
152, 148, 167, 87, 82, 161, 142, 147, 98, 89,
168, 138, 97, 157, 132, 114, 74, 126, 161, 141,
135, 123, 68, 137, 124, 118, 112, 92, 65, 96,
191, 181, 161, 151, 141, 145, 129, 102, 97, 111,
144, 128, 55, 128, 115, 155, 129, 184, 167, 147,
131, 141, 125, 33, 127, 111, 127, 131, 125, 130,
137, 130, 121, 195, 172, 177, 176, 149, 98, 97,
126, 106, 168, 159, 144, 185, 156, 151, 182, 158,
123, 93, 110, 116, 98, 99, 125, 136, 139, 148,
79, 112, 149, 128, 147, 136, 118, 105, 166, 152,
117, 115, 92, 128, 148, 132, 170, 143, 226, 190,
122, 192, 165, 121, 143, 144, 174, 124, 113, 124,
122, 135, 34, 93, 118, 111, 111, 136, 123, 116,
99, 195, 139, 99, 114, 102, 96, 108, 111, 112,
113, 129, 172, 137, 105, 139, 154, 86, 113, 108,
132, 79, 63, 120, 93, 162, 90, 103, 94, 95,
117, 127, 104, 100, 142, 129, 93, 27, 196, 153,
113, 91, 101, 90, 84, 68, 138, 38, 118, 148,
87, 103, 125, 109, 96, 152, 100, 56, 31, 62,
176, 129, 124, 115, 103, 92, 100, 121, 130, 125,
128, 71, 82, 71, 152, 85, 107, 116, 138, 133,
103, 116, 139, 144, 72, 37, 118, 141, 109, 95,
86, 92, 121, 167, 156, 104, 92, 91, 122, 114,
89, 61, 172, 128, 95, 103, 84, 101, 88, 84,
116, 125, 108, 62, 74, 108, 160, 143, 189, 164,
91, 115, 144, 43, 116, 79, 106, 108, 74, 83,
87, 90, 61, 71, 76, 76, 95, 130, 89, 94,
114, 107, 101, 145, 161, 147, 143, 163, 147, 129,
101, 73, 111, 108, 93, 104, 186, 141, 99, 89,
112, 126, 111, 113, 152, 41, 159, 115, 131, 124,
117, 101, 115, 130, 124, 87, 59, 177, 63, 85,
109, 116, 103, 68, 145, 132, 29, 119, 96, 89,
117, 90, 181, 103, 101, 111, 97, 96, 199, 171,
113, 120, 93, 119, 101, 64, 56, 55, 63, 90,
105, 101, 86, 45, 136, 179, 142, 102, 115, 114,
113, 108, 121, 84, 23, 125, 76, 102, 119, 107,
120, 104, 73, 177, 83, 114, 128, 85, 152, 126,
137, 115, 149, 109, 163, 133, 110, 98, 54, 61,
95, 111, 135, 103, 88, 164, 115, 187, 122, 98,
129, 132, 95, 86, 71, 119, 146, 111, 38, 67,
102, 100, 66, 148, 137, 103, 145, 95, 35, 85,
44, 136, 102, 111, 108, 115, 136, 105, 120, 110,
108, 147, 112, 169, 116, 146, 81, 120, 94, 84,
93, 97, 90, 119, 102, 91, 48, 147, 204, 151,
148, 160, 144, 131, 144, 175, 158, 133, 212, 163,
172, 152, 151, 112, 148, 151, 145, 179, 160, 124,
164, 164, 167, 161, 141, 120, 131, 141, 198, 177,
169, 156, 146, 156, 124, 185, 164, 195, 181, 193,
201, 147, 148, 168, 165, 159, 162, 148, 150, 148,
146, 157, 158, 149, 164, 129, 160, 214, 174, 166,
154, 176, 146, 141, 155, 140, 140, 169, 106, 155,
166, 162, 134, 193, 157, 155, 146, 196, 171, 107,
177, 174, 163, 155, 147, 203, 162, 146, 150, 83,
157, 170, 180, 178, 159, 157, 151, 117, 115, 183,
170, 180, 174, 150, 177, 173, 136, 181, 196, 184,
164, 168, 165, 148, 175, 168, 209, 189, 159, 114,
157, 158, 141, 168, 170, 139, 175, 128, 151, 39,
128, 154, 159, 161, 148, 180, 131, 165, 159, 131,
163, 150, 174, 178, 178, 198, 172, 138, 184, 191,
143, 164, 161, 163, 210, 171, 155, 168, 150, 116,
182, 170, 145, 152, 141, 139, 191, 149, 160, 202,
145, 169, 145, 181, 148, 183, 197, 165, 146, 171,
161, 153, 157, 170, 164, 149, 183, 167, 246, 235,
162, 144, 170, 152, 173, 150, 113, 135, 156, 154,
158, 148, 178, 159, 161, 114, 180, 156, 116, 163,
164, 161, 122, 164, 164, 183, 135, 135, 144, 182,
160, 147, 163, 152, 169, 185, 159, 177, 99, 211,
168, 167, 215, 170, 150, 157, 154, 176, 154, 143,
163, 117, 178, 160, 163, 165, 164, 166, 174, 136,
159, 169, 152, 123, 199, 149, 169, 140, 159, 208,
155, 161, 186, 122, 134, 167, 171, 145, 148, 176,
148, 137, 114, 160, 166, 153, 162, 156, 164, 172,
155, 148, 155, 182, 114, 150, 157, 154, 140, 159,
166, 160, 169, 206, 182, 145, 157, 165, 147, 202,
131, 154, 193, 162, 162, 149, 167, 157, 191, 188,
149, 205, 147, 166, 150, 150, 159, 153, 171, 160
};
static const uint8_t wmavoice_dq_lsp16i1[0x640] = {
142, 121, 141, 112, 99, 119, 92, 122, 183, 155,
122, 98, 75, 78, 85, 101, 108, 134, 128, 123,
115, 90, 79, 58, 73, 127, 106, 60, 97, 107,
141, 163, 130, 123, 136, 156, 201, 189, 204, 206,
140, 116, 69, 60, 117, 123, 106, 124, 91, 63,
150, 144, 110, 80, 63, 112, 80, 70, 76, 63,
114, 86, 147, 165, 137, 125, 120, 140, 115, 101,
101, 99, 166, 158, 158, 104, 126, 131, 134, 143,
121, 102, 73, 36, 83, 132, 113, 76, 38, 20,
132, 111, 78, 73, 51, 131, 108, 131, 105, 80,
148, 138, 101, 65, 47, 115, 86, 50, 124, 129,
116, 89, 85, 87, 64, 111, 74, 39, 115, 113,
112, 83, 75, 122, 127, 114, 91, 106, 125, 130,
131, 108, 79, 136, 112, 110, 147, 164, 144, 124,
121, 236, 218, 190, 168, 106, 101, 160, 172, 191,
113, 138, 102, 91, 109, 100, 71, 85, 112, 119,
121, 96, 51, 64, 126, 135, 114, 76, 34, 104,
145, 127, 90, 56, 131, 142, 131, 92, 123, 102,
128, 105, 63, 24, 95, 115, 87, 49, 156, 174,
123, 105, 88, 58, 55, 141, 119, 99, 75, 81,
137, 117, 114, 80, 56, 119, 91, 106, 166, 135,
114, 84, 38, 93, 116, 129, 103, 97, 87, 97,
115, 184, 193, 173, 157, 117, 88, 114, 151, 121,
126, 111, 75, 129, 133, 130, 107, 71, 115, 92,
128, 108, 120, 100, 97, 111, 80, 119, 122, 91,
114, 94, 149, 129, 136, 114, 88, 132, 110, 85,
116, 99, 101, 71, 71, 110, 140, 142, 131, 110,
122, 98, 83, 127, 100, 106, 130, 123, 114, 103,
113, 87, 140, 116, 113, 140, 161, 171, 145, 129,
115, 178, 158, 161, 160, 118, 195, 209, 221, 228,
99, 83, 140, 134, 140, 127, 186, 168, 187, 187,
107, 114, 100, 111, 111, 104, 130, 131, 116, 128,
128, 104, 64, 18, 49, 126, 107, 69, 56, 153,
154, 142, 110, 113, 89, 120, 93, 73, 190, 172,
119, 96, 57, 21, 60, 126, 122, 81, 99, 117,
159, 141, 108, 88, 120, 144, 125, 89, 44, 94,
147, 131, 93, 81, 61, 133, 113, 85, 47, 62,
123, 121, 87, 53, 90, 120, 94, 76, 70, 48,
125, 103, 93, 64, 35, 140, 129, 88, 47, 30,
127, 104, 58, 51, 103, 124, 100, 102, 76, 47,
115, 87, 54, 46, 77, 182, 218, 174, 163, 145,
140, 126, 89, 105, 82, 125, 119, 101, 69, 58,
125, 107, 172, 145, 128, 138, 113, 109, 92, 90,
117, 93, 83, 93, 132, 125, 102, 67, 148, 161,
131, 110, 96, 99, 74, 119, 92, 54, 84, 81,
110, 152, 120, 106, 131, 108, 74, 68, 99, 107,
121, 97, 120, 101, 78, 132, 110, 127, 164, 134,
111, 159, 204, 189, 178, 158, 183, 146, 144, 137,
123, 106, 136, 108, 135, 117, 91, 163, 135, 113,
119, 177, 134, 122, 121, 132, 109, 157, 131, 113,
115, 87, 87, 100, 92, 120, 95, 59, 146, 139,
129, 101, 135, 122, 101, 119, 100, 112, 88, 99,
118, 90, 123, 125, 107, 121, 98, 73, 104, 80,
112, 79, 86, 122, 96, 104, 81, 107, 90, 93,
112, 150, 140, 109, 115, 113, 86, 73, 76, 112,
130, 111, 101, 112, 84, 123, 97, 63, 134, 115,
109, 77, 128, 141, 119, 125, 101, 108, 147, 119,
134, 149, 150, 127, 115, 136, 244, 220, 210, 189,
105, 138, 171, 156, 174, 117, 162, 133, 146, 141,
115, 93, 119, 98, 122, 114, 106, 154, 145, 162,
107, 131, 189, 165, 152, 101, 107, 129, 114, 139,
116, 186, 186, 161, 180, 100, 89, 137, 116, 116,
106, 130, 194, 196, 207, 110, 156, 157, 138, 149,
102, 93, 159, 138, 120, 109, 132, 105, 122, 135,
148, 128, 85, 76, 102, 168, 154, 141, 117, 100,
125, 106, 62, 101, 146, 124, 102, 65, 25, 15,
120, 94, 46, 21, 94, 149, 128, 115, 85, 92,
119, 93, 70, 52, 30, 162, 151, 123, 91, 80,
126, 112, 84, 47, 33, 138, 114, 73, 60, 87,
126, 211, 174, 158, 143, 129, 106, 65, 31, 133,
119, 95, 52, 99, 173, 123, 96, 119, 206, 178,
127, 104, 60, 61, 67, 152, 136, 104, 63, 83,
133, 130, 92, 64, 45, 120, 96, 53, 30, 130,
128, 103, 74, 59, 35, 135, 114, 77, 30, 57,
108, 130, 123, 90, 87, 143, 125, 93, 54, 60,
133, 118, 79, 87, 95, 115, 89, 111, 88, 65,
124, 102, 70, 40, 47, 148, 131, 123, 130, 104,
127, 109, 87, 56, 121, 147, 123, 121, 107, 85,
178, 237, 200, 193, 170, 139, 118, 100, 75, 110,
133, 121, 81, 73, 68, 120, 195, 157, 141, 131,
127, 102, 107, 88, 60, 136, 113, 100, 69, 45,
128, 105, 93, 77, 67, 131, 116, 149, 184, 156,
115, 85, 35, 45, 112, 128, 108, 68, 73, 111,
118, 93, 187, 162, 139, 136, 115, 84, 57, 37,
131, 133, 125, 98, 85, 138, 115, 92, 86, 61,
116, 96, 70, 52, 110, 115, 109, 135, 104, 88,
136, 159, 122, 109, 115, 122, 110, 98, 70, 95,
112, 81, 68, 85, 90, 124, 101, 87, 56, 89,
109, 82, 98, 100, 115, 124, 102, 76, 88, 63,
111, 78, 42, 78, 102, 110, 71, 64, 131, 111,
125, 104, 107, 87, 123, 129, 131, 99, 85, 68,
147, 137, 102, 99, 75, 120, 155, 142, 109, 91,
132, 109, 131, 141, 113, 136, 119, 94, 152, 128,
127, 102, 79, 159, 134, 111, 78, 98, 109, 80,
115, 86, 51, 63, 103, 116, 86, 170, 149, 123,
135, 178, 159, 125, 114, 113, 189, 226, 203, 202,
140, 117, 116, 94, 70, 128, 103, 94, 174, 149,
118, 98, 83, 84, 106, 115, 157, 120, 94, 95,
131, 112, 75, 96, 74, 121, 97, 144, 117, 95,
120, 90, 140, 138, 110, 119, 93, 55, 92, 114,
114, 87, 151, 125, 100, 111, 82, 83, 160, 139,
114, 86, 56, 90, 138, 104, 109, 101, 77, 118,
140, 142, 143, 148, 126, 121, 102, 129, 107, 111,
113, 79, 58, 111, 91, 120, 94, 63, 115, 98,
121, 94, 99, 97, 78, 120, 92, 68, 173, 148,
122, 114, 109, 87, 82, 132, 229, 192, 176, 155,
137, 116, 123, 97, 115, 132, 115, 86, 120, 95,
135, 116, 101, 136, 108, 109, 74, 100, 125, 115,
112, 158, 144, 124, 134, 114, 83, 73, 147, 120,
120, 104, 150, 122, 116, 110, 104, 192, 183, 174,
134, 112, 116, 120, 93, 121, 101, 93, 110, 90,
121, 93, 147, 152, 122, 115, 153, 171, 161, 142,
123, 95, 116, 114, 93, 113, 89, 96, 77, 93,
113, 174, 180, 143, 138, 116, 86, 100, 135, 106,
103, 121, 149, 115, 103, 121, 95, 82, 149, 121,
117, 92, 93, 111, 114, 123, 209, 196, 193, 183,
125, 102, 107, 130, 104, 115, 91, 113, 103, 99,
114, 86, 68, 108, 110, 111, 159, 162, 125, 113,
125, 235, 234, 225, 214, 99, 74, 118, 121, 127,
104, 123, 158, 128, 127, 113, 96, 116, 136, 158,
100, 80, 138, 155, 166, 118, 143, 115, 125, 114,
119, 137, 133, 136, 139, 151, 188, 172, 174, 173,
138, 161, 158, 158, 155, 121, 198, 194, 211, 202,
100, 90, 112, 110, 122, 100, 91, 122, 128, 135,
101, 109, 127, 101, 114, 105, 126, 160, 147, 143,
109, 138, 142, 158, 163, 113, 174, 185, 188, 206,
112, 154, 166, 176, 183, 101, 108, 140, 140, 143,
106, 135, 130, 137, 126, 103, 114, 115, 128, 126,
107, 86, 21, 115, 75, 117, 139, 97, 65, 105,
64, 191, 101, 106, 139, 107, 98, 218, 132, 104,
73, 136, 165, 84, 118, 150, 111, 58, 130, 107,
99, 136, 132, 56, 52, 102, 136, 69, 78, 163,
85, 173, 148, 138, 85, 69, 106, 128, 133, 155,
104, 91, 149, 56, 104, 103, 101, 172, 96, 57,
104, 97, 125, 197, 166, 107, 169, 47, 120, 103,
150, 89, 99, 139, 162, 101, 69, 137, 158, 126,
191, 173, 127, 79, 155, 51, 131, 112, 86, 74,
135, 61, 114, 81, 125, 117, 112, 72, 175, 72,
127, 123, 142, 132, 78, 116, 158, 111, 121, 143,
108, 102, 89, 20, 194, 81, 99, 107, 65, 150,
103, 78, 91, 69, 96, 104, 116, 116, 103, 105,
107, 117, 110, 130, 28, 88, 103, 62, 72, 85,
125, 126, 141, 126, 178, 121, 102, 57, 46, 124,
97, 91, 89, 138, 95, 98, 143, 99, 169, 123,
140, 119, 113, 82, 140, 118, 112, 91, 92, 241,
134, 89, 95, 112, 78, 167, 140, 145, 121, 100,
109, 205, 144, 91, 100, 113, 103, 142, 175, 95,
117, 121, 35, 121, 127, 159, 129, 85, 64, 75,
116, 98, 103, 127, 129, 66, 68, 110, 96, 86,
79, 100, 156, 133, 92, 135, 96, 164, 132, 121,
93, 163, 134, 91, 208, 104, 77, 126, 116, 58,
136, 118, 132, 81, 61, 73, 115, 66, 129, 123,
111, 85, 42, 178, 134, 108, 132, 159, 45, 157,
105, 164, 100, 94, 60, 96, 57, 154, 105, 102,
103, 114, 96, 12, 91, 119, 115, 67, 92, 64,
94, 61, 106, 106, 165, 105, 94, 98, 68, 30,
146, 130, 107, 173, 140, 102, 90, 163, 106, 184,
100, 53, 68, 131, 92, 105, 111, 68, 153, 186,
101, 82, 48, 99, 147, 122, 136, 176, 96, 96,
104, 132, 167, 149, 136, 138, 144, 97, 120, 92
};
static const uint8_t wmavoice_dq_lsp16i2[0x3c0] = {
23, 12, 107, 119, 110, 205, 214, 212, 208, 201,
102, 95, 69, 117, 107, 118, 123, 118, 123, 121,
82, 58, 83, 95, 84, 139, 145, 153, 161, 169,
102, 100, 138, 121, 101, 129, 130, 138, 150, 139,
76, 104, 86, 112, 133, 113, 91, 63, 73, 129,
199, 193, 182, 181, 172, 119, 101, 83, 94, 76,
161, 157, 152, 157, 158, 110, 90, 121, 96, 79,
124, 107, 114, 88, 73, 152, 137, 121, 107, 99,
57, 50, 100, 81, 74, 115, 96, 72, 49, 69,
83, 68, 40, 53, 103, 36, 131, 107, 84, 64,
236, 245, 242, 231, 213, 95, 109, 88, 69, 110,
228, 221, 204, 182, 170, 129, 110, 97, 118, 104,
98, 76, 98, 75, 61, 93, 77, 113, 91, 72,
116, 94, 106, 134, 118, 177, 188, 169, 162, 153,
163, 149, 131, 131, 132, 177, 163, 173, 168, 158,
113, 131, 107, 113, 100, 132, 143, 131, 134, 142,
45, 36, 121, 113, 102, 43, 95, 84, 67, 56,
76, 82, 68, 48, 33, 55, 58, 59, 43, 65,
66, 85, 66, 81, 94, 102, 82, 54, 33, 94,
113, 111, 89, 60, 34, 138, 120, 101, 101, 86,
88, 73, 55, 114, 115, 92, 74, 93, 77, 123,
90, 117, 99, 79, 59, 97, 75, 97, 122, 104,
233, 237, 227, 208, 190, 209, 230, 233, 240, 241,
195, 197, 188, 167, 147, 204, 185, 168, 162, 157,
142, 124, 119, 123, 106, 117, 110, 81, 121, 123,
74, 116, 124, 119, 120, 178, 168, 146, 132, 125,
102, 104, 105, 110, 114, 104, 82, 78, 100, 86,
120, 102, 105, 93, 143, 127, 108, 128, 106, 88,
177, 189, 203, 207, 215, 101, 131, 119, 95, 73,
149, 139, 135, 147, 153, 160, 167, 165, 174, 177,
120, 109, 134, 140, 145, 131, 130, 142, 139, 161,
143, 158, 148, 145, 145, 123, 142, 132, 116, 102,
40, 23, 79, 82, 84, 26, 83, 141, 130, 122,
65, 46, 43, 89, 86, 28, 75, 80, 79, 98,
84, 65, 47, 26, 44, 49, 112, 101, 100, 94,
88, 76, 75, 48, 82, 104, 100, 75, 45, 15,
99, 83, 63, 34, 30, 66, 55, 94, 118, 113,
122, 106, 91, 68, 60, 135, 122, 104, 77, 59,
82, 102, 84, 62, 46, 92, 74, 55, 82, 71,
145, 134, 118, 93, 75, 79, 62, 83, 65, 55,
91, 94, 64, 70, 98, 89, 117, 110, 87, 97,
210, 223, 225, 223, 213, 83, 103, 86, 101, 85,
126, 106, 81, 79, 105, 216, 219, 217, 199, 179,
86, 78, 115, 138, 135, 102, 84, 87, 59, 46,
219, 206, 184, 167, 158, 201, 188, 165, 145, 135,
87, 113, 142, 152, 155, 190, 170, 153, 149, 146,
205, 208, 201, 185, 167, 84, 73, 124, 104, 96,
76, 88, 99, 74, 80, 110, 125, 122, 99, 112,
108, 84, 70, 130, 137, 161, 152, 136, 119, 105,
110, 91, 101, 74, 96, 111, 101, 93, 153, 149,
133, 124, 102, 97, 120, 101, 93, 75, 81, 64,
111, 94, 107, 79, 58, 188, 206, 215, 221, 232,
163, 175, 165, 150, 136, 103, 106, 123, 133, 132,
168, 184, 191, 183, 170, 110, 117, 90, 98, 93,
104, 87, 122, 98, 127, 129, 110, 127, 113, 125,
134, 118, 102, 140, 132, 186, 199, 202, 198, 188,
149, 147, 175, 185, 186, 117, 93, 99, 112, 93,
107, 138, 138, 129, 128, 96, 129, 104, 118, 134,
145, 136, 115, 121, 129, 138, 155, 148, 134, 120,
170, 151, 150, 145, 138, 168, 173, 185, 194, 200,
144, 159, 172, 168, 156, 121, 121, 138, 173, 168,
126, 111, 140, 139, 117, 149, 133, 142, 137, 130,
143, 139, 158, 158, 146, 119, 128, 121, 132, 145,
122, 136, 159, 153, 141, 133, 133, 130, 129, 126,
120, 76, 50, 149, 109, 92, 155, 118, 90, 66,
132, 117, 87, 156, 117, 119, 102, 44, 83, 91,
109, 73, 106, 84, 29, 55, 130, 112, 81, 241,
75, 40, 91, 89, 67, 112, 90, 149, 81, 72,
128, 90, 71, 28, 160, 73, 157, 123, 143, 108,
63, 88, 70, 81, 97, 75, 111, 149, 113, 96,
78, 104, 83, 179, 95, 105, 106, 65, 130, 66,
51, 118, 92, 53, 68, 105, 75, 176, 151, 115,
94, 75, 68, 95, 220, 103, 125, 105, 43, 95,
39, 114, 65, 145, 135, 33, 142, 138, 103, 52,
82, 85, 117, 110, 67, 102, 74, 42, 62, 118,
144, 121, 82, 57, 102, 67, 75, 44, 129, 96,
75, 63, 88, 48, 116, 135, 94, 85, 102, 66,
122, 77, 105, 122, 152, 120, 56, 90, 83, 100,
90, 128, 63, 80, 103, 126, 117, 103, 80, 193,
42, 73, 117, 93, 91, 95, 128, 100, 128, 162,
70, 120, 126, 73, 123, 99, 99, 91, 75, 135,
81, 125, 111, 77, 13, 94, 78, 85, 187, 157,
11, 143, 109, 99, 119, 53, 141, 82, 122, 68,
132, 89, 136, 119, 88, 75, 49, 174, 119, 70,
138, 121, 108, 78, 52, 104, 90, 96, 93, 93,
114, 90, 78, 46, 58, 62, 114, 69, 44, 162,
103, 58, 98, 141, 83, 137, 95, 119, 73, 111,
81, 46, 126, 111, 123, 107, 117, 122, 121, 54,
106, 104, 59, 110, 148, 97, 155, 97, 83, 133,
97, 71, 57, 91, 58, 52, 79, 127, 152, 109,
96, 92, 145, 107, 149, 102, 61, 125, 61, 170,
56, 89, 77, 106, 38, 147, 96, 77, 105, 123,
85, 83, 117, 63, 69, 126, 133, 93, 107, 92,
77, 115, 95, 111, 103, 61, 87, 103, 98, 155,
94, 111, 80, 78, 54, 117, 128, 130, 99, 109,
106, 99, 113, 133, 115, 89, 65, 74, 112, 127
};
static const uint8_t wmavoice_dq_lsp16i3[0x300] = {
70, 100, 121, 129, 132, 132, 201, 188, 165, 145, 144, 136,
112, 127, 116, 125, 130, 129, 124, 135, 135, 146, 129, 128,
162, 158, 144, 151, 135, 129, 103, 86, 111, 113, 112, 122,
90, 139, 129, 117, 126, 129, 142, 145, 167, 147, 124, 124,
230, 209, 189, 175, 156, 141, 64, 80, 86, 108, 121, 129,
44, 79, 115, 113, 115, 128, 133, 106, 79, 109, 125, 127,
171, 156, 132, 109, 103, 115, 106, 70, 93, 145, 141, 128,
148, 125, 122, 107, 110, 117, 146, 145, 128, 110, 98, 111,
237, 212, 185, 156, 139, 133, 84, 55, 26, 77, 114, 127,
172, 170, 171, 168, 162, 143, 82, 82, 76, 70, 104, 126,
17, 95, 109, 111, 120, 132, 81, 74, 57, 126, 141, 131,
110, 127, 162, 148, 129, 123, 177, 172, 155, 151, 145, 134,
144, 123, 90, 66, 109, 130, 82, 127, 103, 123, 132, 131,
127, 97, 97, 142, 140, 128, 159, 134, 136, 123, 113, 117,
131, 140, 154, 169, 158, 134, 96, 109, 150, 122, 105, 120,
120, 150, 152, 122, 119, 125, 123, 126, 124, 107, 100, 113,
248, 233, 216, 189, 160, 142, 58, 24, 13, 77, 111, 127,
183, 189, 182, 157, 140, 131, 96, 83, 59, 43, 73, 119,
222, 196, 171, 146, 129, 128, 32, 13, 53, 101, 114, 127,
119, 101, 70, 70, 110, 127, 77, 86, 161, 148, 130, 118,
199, 183, 170, 167, 156, 141, 30, 115, 142, 133, 131, 130,
101, 103, 181, 176, 152, 126, 66, 44, 73, 94, 111, 128,
150, 122, 100, 101, 104, 118, 61, 110, 87, 76, 93, 125,
190, 170, 150, 134, 135, 129, 112, 89, 63, 123, 141, 132,
175, 154, 136, 142, 140, 132, 117, 143, 129, 128, 136, 132,
168, 142, 112, 113, 128, 128, 155, 169, 159, 144, 139, 131,
61, 136, 144, 124, 112, 123, 86, 81, 104, 121, 129, 130,
160, 127, 118, 150, 151, 134, 126, 115, 121, 132, 134, 131,
137, 148, 144, 139, 140, 134, 106, 102, 105, 90, 87, 113,
134, 129, 128, 121, 121, 123, 153, 151, 129, 139, 142, 134,
150, 142, 141, 148, 149, 141, 100, 121, 133, 147, 150, 134,
163, 158, 147, 132, 141, 132, 142, 127, 141, 136, 136, 132,
232, 218, 205, 189, 169, 146, 243, 224, 201, 171, 147, 138,
224, 196, 169, 162, 154, 140, 51, 20, 59, 111, 121, 128,
203, 197, 193, 177, 162, 145, 75, 40, 47, 122, 130, 129,
102, 77, 47, 83, 121, 129, 111, 108, 84, 56, 63, 114,
211, 181, 154, 137, 126, 125, 213, 198, 186, 162, 144, 138,
41, 45, 90, 110, 118, 130, 83, 63, 130, 164, 153, 128,
195, 167, 142, 123, 113, 119, 19, 42, 105, 113, 120, 132,
50, 63, 49, 64, 112, 128, 114, 90, 132, 171, 162, 134,
129, 128, 107, 83, 74, 110, 50, 116, 109, 120, 128, 132,
94, 59, 73, 111, 117, 126, 197, 170, 166, 153, 138, 132,
65, 48, 109, 133, 131, 128, 170, 163, 172, 158, 138, 130,
66, 126, 147, 160, 151, 132, 42, 129, 117, 95, 91, 120,
97, 165, 164, 142, 133, 125, 163, 142, 114, 88, 97, 122,
104, 77, 142, 143, 128, 120, 136, 160, 188, 169, 149, 130,
113, 83, 85, 102, 114, 125, 164, 169, 142, 120, 122, 124,
98, 152, 132, 105, 92, 117, 42, 71, 125, 155, 151, 137,
94, 105, 81, 107, 118, 126, 84, 56, 123, 117, 108, 122,
174, 179, 166, 137, 118, 121, 130, 103, 147, 152, 134, 124,
148, 127, 94, 117, 144, 134, 129, 106, 102, 95, 106, 118,
147, 157, 153, 125, 103, 117, 155, 128, 113, 132, 120, 122,
181, 151, 136, 126, 122, 122, 110, 111, 109, 108, 120, 124,
97, 130, 103, 89, 107, 124, 179, 158, 158, 142, 131, 128,
142, 111, 115, 122, 126, 125, 145, 145, 134, 115, 129, 128,
130, 139, 112, 99, 121, 125, 79, 104, 119, 102, 105, 123,
116, 121, 136, 125, 126, 127, 124, 100, 122, 119, 111, 119,
159, 140, 139, 128, 138, 131, 105, 100, 116, 128, 135, 132,
159, 142, 156, 147, 140, 134, 130, 150, 129, 126, 114, 120,
138, 124, 146, 131, 109, 119, 93, 115, 125, 131, 125, 129,
125, 121, 101, 119, 114, 120, 163, 154, 151, 153, 153, 139,
166, 153, 150, 133, 119, 121, 159, 151, 128, 130, 122, 123,
147, 154, 144, 133, 128, 127, 129, 131, 134, 140, 148, 138,
138, 136, 120, 131, 135, 131, 150, 140, 137, 144, 129, 129
};
static const uint8_t wmavoice_dq_lsp10r[0x1400] = {
128, 128, 129, 129, 130, 130, 131, 130, 129, 129,
134, 133, 127, 125, 136, 135, 135, 134, 173, 172,
133, 139, 136, 165, 133, 176, 137, 159, 135, 152,
147, 161, 147, 152, 149, 156, 146, 146, 140, 136,
134, 135, 136, 140, 139, 155, 123, 133, 132, 142,
132, 148, 143, 177, 124, 143, 123, 136, 126, 134,
126, 125, 125, 124, 129, 128, 123, 123, 133, 133,
116, 116, 121, 121, 121, 120, 129, 128, 131, 131,
132, 133, 132, 129, 138, 124, 138, 124, 132, 100,
135, 94, 149, 111, 152, 115, 150, 128, 141, 133,
129, 129, 130, 129, 147, 145, 136, 137, 120, 122,
120, 122, 127, 129, 104, 108, 113, 115, 124, 124,
140, 139, 147, 145, 132, 130, 184, 177, 201, 196,
170, 171, 160, 161, 145, 147, 137, 145, 131, 131,
130, 130, 130, 130, 130, 130, 132, 134, 131, 132,
131, 133, 141, 144, 142, 149, 84, 93, 103, 104,
139, 139, 142, 140, 147, 147, 172, 165, 122, 121,
98, 100, 101, 106, 112, 117, 122, 124, 124, 124,
134, 133, 133, 133, 146, 142, 147, 145, 156, 156,
143, 146, 119, 124, 129, 132, 151, 149, 136, 135,
147, 148, 181, 180, 199, 188, 190, 173, 166, 161,
147, 142, 153, 149, 154, 146, 150, 146, 138, 134,
131, 135, 96, 136, 48, 138, 56, 131, 63, 124,
85, 128, 103, 132, 117, 134, 120, 132, 125, 129,
131, 130, 129, 128, 129, 128, 163, 168, 117, 120,
121, 121, 136, 138, 131, 132, 135, 136, 131, 133,
133, 133, 133, 134, 117, 118, 105, 109, 142, 151,
144, 159, 131, 138, 121, 126, 123, 123, 121, 124,
131, 131, 129, 129, 141, 140, 142, 134, 87, 90,
109, 109, 130, 127, 139, 143, 133, 131, 127, 126,
134, 135, 134, 136, 97, 98, 130, 132, 134, 137,
115, 119, 125, 130, 107, 109, 119, 118, 126, 127,
134, 135, 127, 132, 172, 203, 160, 196, 152, 179,
152, 172, 148, 168, 153, 172, 145, 156, 137, 140,
102, 116, 42, 56, 74, 61, 82, 70, 86, 78,
101, 97, 104, 100, 115, 108, 116, 108, 123, 118,
149, 143, 166, 129, 168, 96, 142, 95, 135, 98,
117, 86, 116, 93, 121, 108, 119, 107, 121, 117,
135, 135, 127, 138, 72, 132, 99, 136, 112, 147,
120, 152, 136, 155, 138, 146, 140, 142, 134, 139,
163, 145, 192, 130, 147, 124, 147, 125, 133, 125,
127, 124, 128, 123, 129, 122, 130, 122, 130, 125,
130, 137, 135, 180, 124, 133, 130, 129, 132, 133,
124, 124, 131, 130, 132, 136, 126, 124, 127, 125,
132, 132, 133, 133, 144, 140, 143, 142, 137, 135,
143, 138, 152, 149, 221, 219, 158, 161, 143, 141,
130, 129, 140, 135, 170, 145, 193, 156, 186, 152,
167, 139, 151, 131, 142, 127, 134, 120, 131, 125,
135, 133, 141, 125, 199, 109, 137, 126, 134, 123,
130, 129, 132, 123, 128, 125, 122, 126, 125, 125,
130, 128, 91, 89, 138, 135, 139, 134, 133, 129,
132, 130, 125, 128, 136, 135, 129, 127, 126, 126,
132, 131, 133, 131, 128, 120, 132, 126, 126, 119,
134, 130, 131, 123, 104, 95, 140, 141, 136, 137,
133, 133, 133, 134, 117, 98, 74, 49, 112, 111,
123, 122, 126, 127, 131, 131, 127, 126, 128, 129,
130, 131, 124, 127, 101, 107, 108, 109, 115, 115,
100, 99, 130, 128, 134, 136, 125, 127, 128, 130,
136, 137, 145, 150, 149, 164, 136, 151, 114, 111,
124, 125, 143, 150, 162, 174, 158, 169, 136, 137,
131, 131, 131, 131, 132, 133, 111, 110, 122, 121,
136, 136, 134, 133, 131, 132, 127, 127, 125, 125,
128, 129, 129, 130, 125, 127, 140, 140, 148, 149,
133, 136, 146, 153, 110, 118, 127, 129, 128, 129,
131, 133, 127, 131, 140, 161, 167, 224, 131, 139,
136, 143, 135, 139, 138, 143, 149, 155, 141, 143,
134, 132, 120, 111, 83, 83, 121, 126, 102, 107,
112, 115, 97, 104, 120, 115, 129, 123, 122, 122,
134, 135, 122, 131, 102, 124, 114, 119, 93, 103,
78, 79, 67, 72, 66, 73, 78, 82, 103, 102,
144, 135, 165, 139, 165, 129, 160, 126, 153, 127,
161, 134, 160, 142, 160, 143, 148, 140, 138, 135,
138, 95, 147, 54, 143, 78, 140, 112, 142, 113,
140, 121, 135, 117, 135, 122, 136, 131, 131, 132,
147, 159, 140, 156, 127, 81, 142, 128, 146, 127,
144, 125, 146, 128, 149, 130, 144, 135, 133, 128,
130, 131, 131, 131, 134, 139, 126, 134, 141, 154,
168, 205, 153, 176, 148, 163, 147, 158, 141, 143,
131, 135, 126, 146, 108, 157, 107, 156, 119, 146,
100, 138, 104, 125, 119, 134, 101, 122, 113, 122,
95, 133, 52, 140, 83, 136, 110, 133, 114, 131,
123, 131, 133, 131, 138, 135, 132, 132, 127, 127,
129, 128, 124, 122, 128, 126, 145, 170, 143, 172,
141, 163, 143, 176, 138, 164, 139, 155, 135, 145,
135, 136, 136, 127, 132, 76, 128, 76, 127, 63,
125, 66, 123, 67, 120, 71, 124, 92, 122, 111,
133, 133, 135, 136, 139, 140, 147, 147, 150, 144,
156, 147, 150, 145, 154, 146, 120, 123, 123, 124,
137, 133, 170, 141, 124, 124, 135, 134, 134, 135,
132, 132, 129, 129, 130, 130, 136, 136, 130, 132,
147, 159, 135, 158, 115, 146, 120, 148, 117, 136,
115, 137, 113, 132, 133, 142, 140, 144, 132, 134,
134, 135, 134, 137, 137, 147, 162, 178, 136, 147,
134, 144, 123, 132, 111, 113, 113, 113, 124, 124,
132, 131, 126, 126, 117, 114, 100, 95, 130, 125,
157, 145, 164, 156, 163, 158, 145, 145, 133, 134,
134, 134, 127, 126, 113, 102, 136, 130, 124, 122,
143, 145, 127, 131, 135, 143, 133, 137, 132, 132,
92, 94, 122, 125, 128, 129, 131, 130, 134, 135,
132, 128, 129, 127, 132, 132, 131, 129, 127, 127,
129, 129, 132, 131, 139, 131, 137, 132, 216, 178,
146, 134, 147, 137, 151, 142, 148, 139, 144, 138,
128, 127, 129, 129, 123, 131, 71, 91, 126, 128,
130, 134, 117, 123, 125, 125, 135, 140, 129, 132,
132, 132, 133, 134, 124, 130, 127, 133, 133, 138,
142, 149, 135, 141, 145, 149, 154, 164, 135, 138,
135, 135, 141, 142, 138, 137, 116, 96, 105, 86,
127, 118, 128, 120, 124, 117, 125, 117, 125, 121,
131, 131, 132, 134, 144, 145, 112, 112, 121, 123,
113, 116, 121, 123, 139, 138, 128, 128, 131, 131,
134, 132, 132, 132, 125, 128, 127, 130, 125, 131,
120, 128, 90, 119, 68, 98, 99, 112, 115, 124,
135, 135, 134, 134, 128, 129, 137, 137, 137, 138,
110, 114, 129, 130, 144, 145, 123, 125, 129, 129,
132, 133, 129, 130, 168, 187, 140, 149, 137, 144,
129, 130, 129, 134, 133, 138, 118, 118, 122, 120,
131, 130, 129, 128, 133, 133, 125, 125, 124, 123,
181, 179, 129, 129, 131, 127, 139, 136, 130, 128,
133, 133, 132, 132, 121, 120, 122, 119, 132, 129,
129, 125, 107, 96, 136, 137, 150, 146, 135, 134,
131, 131, 130, 130, 126, 123, 126, 123, 128, 125,
130, 123, 134, 127, 183, 159, 143, 135, 137, 134,
129, 129, 128, 128, 134, 133, 139, 138, 133, 132,
129, 127, 154, 151, 150, 144, 146, 146, 141, 142,
132, 132, 131, 131, 130, 130, 132, 133, 114, 115,
132, 132, 122, 122, 132, 131, 115, 117, 120, 120,
129, 129, 130, 130, 130, 129, 130, 131, 129, 131,
130, 130, 129, 129, 133, 132, 143, 144, 91, 91,
137, 136, 118, 107, 60, 45, 56, 49, 57, 52,
60, 56, 71, 75, 77, 80, 92, 97, 106, 106,
112, 131, 58, 121, 19, 65, 84, 101, 108, 122,
121, 127, 112, 117, 106, 112, 117, 124, 126, 127,
130, 129, 138, 133, 166, 155, 192, 179, 192, 177,
208, 191, 204, 192, 186, 179, 163, 163, 138, 142,
134, 134, 144, 142, 243, 236, 148, 146, 141, 137,
145, 141, 151, 144, 147, 143, 135, 139, 134, 133,
134, 128, 138, 88, 142, 10, 127, 76, 130, 96,
129, 102, 128, 108, 123, 111, 127, 119, 127, 124,
136, 136, 139, 139, 142, 140, 246, 241, 158, 167,
143, 145, 146, 149, 143, 145, 148, 152, 133, 134,
139, 135, 135, 136, 99, 137, 95, 133, 75, 138,
67, 135, 73, 128, 83, 132, 96, 126, 115, 127,
130, 132, 137, 136, 140, 135, 134, 130, 137, 131,
159, 151, 215, 197, 181, 170, 160, 149, 150, 143,
145, 148, 186, 207, 141, 147, 135, 137, 122, 122,
126, 125, 128, 126, 127, 127, 134, 126, 131, 123,
133, 133, 126, 122, 128, 122, 99, 93, 59, 60,
82, 82, 106, 107, 119, 123, 124, 128, 128, 129,
134, 137, 133, 139, 133, 136, 141, 132, 139, 122,
142, 97, 130, 81, 128, 89, 129, 101, 125, 112,
137, 140, 129, 148, 101, 159, 118, 180, 122, 178,
120, 178, 116, 168, 118, 153, 127, 151, 126, 136,
132, 134, 125, 126, 118, 105, 156, 124, 180, 132,
163, 124, 148, 121, 131, 112, 127, 115, 125, 122,
129, 131, 128, 129, 136, 134, 142, 141, 165, 158,
203, 182, 141, 136, 132, 130, 135, 135, 130, 130,
133, 133, 132, 132, 127, 126, 106, 105, 112, 110,
106, 105, 80, 84, 100, 101, 122, 125, 126, 128,
101, 109, 46, 59, 114, 112, 119, 119, 126, 121,
129, 124, 128, 125, 125, 122, 123, 120, 125, 122,
135, 134, 121, 134, 56, 139, 131, 145, 135, 138,
136, 139, 126, 130, 122, 132, 126, 129, 124, 129,
153, 169, 146, 179, 138, 139, 151, 143, 148, 138,
153, 137, 142, 129, 144, 126, 140, 128, 133, 126,
136, 134, 154, 149, 173, 157, 152, 144, 149, 141,
137, 136, 127, 121, 123, 121, 121, 126, 120, 123,
157, 143, 166, 135, 120, 122, 112, 118, 102, 118,
111, 124, 134, 131, 141, 138, 135, 134, 126, 129,
140, 123, 152, 76, 131, 116, 138, 136, 126, 134,
130, 142, 126, 136, 120, 132, 126, 128, 124, 127,
131, 138, 80, 147, 126, 138, 130, 140, 129, 134,
133, 135, 131, 132, 126, 127, 127, 125, 125, 123,
132, 132, 130, 132, 123, 130, 102, 102, 107, 110,
116, 127, 132, 152, 142, 160, 143, 151, 142, 146,
132, 132, 132, 132, 125, 126, 132, 140, 158, 199,
135, 149, 134, 140, 135, 131, 129, 120, 127, 121,
129, 130, 122, 123, 125, 124, 138, 138, 138, 135,
140, 141, 101, 94, 105, 98, 121, 122, 127, 128,
126, 127, 119, 121, 133, 156, 132, 159, 130, 148,
137, 164, 127, 138, 130, 137, 135, 140, 126, 126,
128, 129, 129, 129, 126, 124, 130, 128, 143, 138,
149, 143, 185, 170, 129, 127, 138, 133, 138, 135,
132, 134, 137, 144, 139, 183, 131, 145, 127, 128,
128, 127, 128, 122, 129, 125, 145, 139, 135, 131,
132, 133, 132, 130, 152, 96, 159, 85, 150, 105,
154, 115, 143, 120, 138, 126, 134, 124, 130, 126,
128, 127, 121, 123, 122, 123, 116, 125, 84, 87,
133, 135, 129, 131, 123, 126, 133, 135, 131, 130,
136, 134, 129, 119, 79, 63, 116, 116, 136, 133,
133, 130, 140, 143, 127, 127, 124, 125, 127, 128,
128, 126, 124, 120, 139, 128, 153, 134, 151, 134,
174, 145, 159, 136, 165, 144, 171, 149, 143, 135,
134, 134, 133, 133, 121, 119, 177, 162, 166, 154,
127, 130, 132, 132, 136, 137, 142, 143, 138, 137,
167, 151, 162, 142, 128, 136, 142, 148, 128, 143,
145, 153, 140, 149, 132, 141, 128, 139, 127, 133,
156, 169, 131, 129, 126, 120, 127, 125, 129, 120,
131, 126, 126, 123, 124, 121, 122, 121, 123, 123,
138, 140, 149, 156, 145, 152, 105, 102, 131, 126,
151, 146, 147, 139, 144, 137, 143, 133, 135, 130,
132, 130, 131, 129, 126, 130, 126, 129, 110, 135,
115, 139, 108, 146, 105, 147, 121, 134, 124, 133,
137, 137, 135, 134, 143, 142, 146, 146, 120, 121,
139, 137, 133, 129, 149, 145, 139, 133, 130, 127,
134, 134, 134, 134, 125, 124, 117, 119, 120, 113,
84, 80, 122, 125, 108, 112, 97, 102, 118, 120,
124, 123, 115, 116, 110, 111, 98, 97, 127, 124,
129, 127, 120, 117, 114, 109, 106, 104, 116, 116,
138, 138, 139, 141, 142, 146, 127, 125, 133, 130,
134, 128, 134, 127, 116, 91, 105, 84, 114, 106,
128, 128, 126, 126, 131, 137, 126, 129, 133, 139,
134, 145, 132, 143, 150, 192, 131, 142, 138, 141,
132, 130, 132, 130, 149, 138, 196, 152, 137, 125,
134, 125, 139, 128, 133, 125, 141, 134, 134, 135,
134, 135, 134, 135, 131, 130, 136, 133, 110, 106,
142, 144, 153, 162, 131, 129, 134, 132, 131, 130,
126, 125, 132, 130, 168, 153, 126, 124, 130, 126,
140, 135, 140, 134, 138, 133, 145, 137, 135, 134,
130, 130, 132, 131, 133, 132, 129, 129, 125, 128,
128, 130, 133, 139, 143, 152, 193, 215, 152, 160,
130, 131, 129, 131, 130, 131, 135, 136, 136, 141,
83, 81, 121, 120, 136, 130, 150, 145, 147, 145,
134, 133, 135, 133, 146, 142, 135, 131, 127, 128,
134, 135, 93, 102, 126, 132, 131, 133, 127, 129,
124, 125, 120, 122, 103, 106, 128, 129, 139, 138,
127, 128, 134, 134, 143, 138, 139, 134, 135, 133,
131, 130, 133, 131, 139, 134, 138, 136, 166, 156,
119, 116, 121, 122, 126, 124, 116, 117, 123, 124,
131, 131, 129, 129, 130, 128, 141, 138, 135, 132,
154, 145, 137, 129, 131, 125, 146, 137, 138, 135,
131, 131, 131, 132, 129, 130, 134, 138, 111, 116,
113, 118, 123, 125, 122, 124, 143, 147, 138, 140,
116, 113, 114, 112, 130, 126, 117, 115, 127, 126,
139, 137, 141, 139, 131, 132, 143, 144, 139, 140,
130, 130, 129, 128, 136, 134, 119, 117, 152, 143,
155, 143, 120, 119, 142, 139, 124, 130, 126, 128,
112, 110, 112, 109, 136, 132, 125, 118, 121, 115,
103, 101, 109, 100, 125, 120, 121, 117, 122, 121,
128, 128, 127, 127, 124, 124, 128, 127, 131, 129,
142, 138, 147, 141, 115, 108, 113, 109, 122, 119,
136, 133, 150, 139, 142, 131, 119, 111, 151, 137,
121, 116, 146, 134, 137, 129, 121, 123, 127, 129,
130, 130, 130, 130, 136, 137, 126, 126, 136, 136,
133, 133, 139, 139, 142, 143, 119, 120, 134, 134,
132, 132, 133, 133, 135, 138, 129, 131, 133, 134,
135, 138, 126, 130, 117, 118, 131, 132, 135, 135,
129, 129, 128, 128, 126, 129, 127, 129, 123, 125,
115, 117, 156, 157, 127, 131, 129, 129, 128, 129,
129, 130, 131, 131, 126, 127, 135, 134, 136, 135,
140, 136, 117, 113, 132, 128, 104, 97, 109, 106,
131, 131, 131, 131, 121, 123, 124, 125, 126, 127,
127, 127, 135, 135, 128, 128, 130, 130, 141, 140,
129, 129, 129, 129, 129, 127, 127, 125, 149, 146,
125, 123, 134, 133, 134, 132, 152, 150, 138, 138,
128, 128, 126, 125, 132, 133, 141, 143, 136, 136,
126, 127, 126, 127, 129, 131, 128, 129, 135, 134,
176, 139, 192, 135, 145, 122, 149, 117, 155, 134,
169, 133, 157, 139, 142, 136, 151, 152, 142, 147,
166, 174, 103, 107, 141, 134, 140, 136, 144, 135,
147, 135, 156, 131, 153, 127, 133, 126, 130, 124,
127, 130, 123, 124, 114, 105, 195, 193, 156, 157,
165, 158, 126, 122, 149, 141, 174, 173, 152, 147,
136, 139, 131, 138, 163, 169, 103, 124, 80, 102,
153, 186, 121, 151, 134, 161, 156, 190, 141, 151,
121, 123, 124, 127, 119, 127, 133, 134, 157, 156,
81, 69, 136, 134, 160, 169, 118, 114, 135, 128,
114, 116, 97, 97, 117, 122, 152, 161, 115, 121,
106, 122, 135, 137, 111, 113, 125, 135, 141, 145,
143, 146, 143, 150, 132, 136, 142, 150, 151, 167,
101, 107, 155, 173, 112, 124, 105, 100, 128, 126,
127, 130, 133, 134, 142, 121, 131, 116, 176, 145,
161, 120, 209, 150, 196, 133, 147, 115, 149, 130,
144, 145, 144, 145, 120, 119, 163, 160, 117, 118,
123, 117, 154, 119, 193, 98, 149, 101, 137, 116,
133, 135, 140, 143, 144, 156, 131, 146, 186, 201,
140, 139, 123, 125, 158, 169, 157, 166, 142, 143,
130, 131, 132, 132, 128, 128, 141, 142, 147, 149,
145, 148, 137, 139, 129, 129, 107, 108, 157, 157,
120, 121, 119, 119, 140, 132, 137, 131, 118, 113,
143, 136, 134, 135, 164, 158, 133, 125, 127, 124,
148, 122, 197, 130, 173, 145, 110, 139, 123, 165,
83, 158, 90, 167, 93, 142, 136, 169, 134, 152,
130, 126, 154, 138, 227, 150, 156, 114, 147, 114,
142, 109, 135, 110, 166, 135, 176, 150, 152, 142,
132, 132, 136, 136, 130, 135, 143, 152, 136, 144,
152, 160, 177, 185, 112, 112, 165, 166, 160, 161,
145, 145, 138, 139, 116, 118, 127, 131, 66, 80,
132, 142, 119, 127, 101, 108, 120, 130, 126, 130,
135, 135, 142, 139, 153, 137, 55, 30, 142, 139,
139, 143, 135, 133, 129, 133, 109, 108, 129, 129,
136, 135, 134, 131, 129, 132, 132, 134, 135, 149,
79, 206, 123, 137, 135, 143, 130, 140, 131, 134,
100, 99, 165, 164, 142, 123, 148, 133, 133, 122,
142, 133, 138, 125, 119, 111, 129, 123, 137, 130,
131, 132, 123, 129, 174, 185, 196, 181, 127, 111,
156, 141, 132, 114, 129, 106, 132, 107, 126, 117,
134, 140, 131, 136, 119, 146, 92, 246, 128, 132,
125, 129, 132, 140, 128, 141, 126, 145, 137, 142,
130, 130, 110, 115, 124, 139, 127, 151, 118, 152,
98, 146, 36, 108, 126, 158, 112, 146, 112, 130,
138, 136, 145, 138, 153, 145, 116, 125, 90, 103,
137, 138, 189, 185, 141, 151, 86, 93, 111, 111,
133, 171, 125, 209, 140, 132, 130, 134, 129, 101,
142, 120, 142, 132, 135, 126, 141, 140, 140, 134,
128, 123, 131, 123, 138, 118, 163, 133, 240, 197,
176, 151, 126, 123, 81, 94, 109, 118, 124, 133,
135, 133, 137, 134, 154, 135, 140, 155, 69, 190,
119, 149, 141, 151, 142, 123, 135, 125, 129, 130,
127, 125, 132, 127, 107, 80, 123, 103, 145, 131,
133, 107, 140, 103, 135, 106, 170, 145, 159, 143,
136, 137, 127, 130, 105, 119, 129, 134, 141, 151,
116, 127, 119, 140, 75, 119, 152, 162, 149, 152,
72, 138, 9, 143, 118, 160, 126, 134, 141, 147,
135, 131, 129, 129, 135, 129, 136, 126, 133, 125,
137, 135, 146, 141, 145, 139, 141, 140, 133, 130,
213, 208, 139, 130, 139, 136, 117, 117, 126, 125,
133, 130, 138, 131, 141, 100, 145, 93, 159, 121,
144, 132, 117, 160, 102, 187, 99, 162, 117, 144,
132, 132, 134, 134, 140, 141, 127, 126, 128, 131,
116, 116, 121, 127, 119, 126, 114, 114, 99, 100,
141, 144, 148, 159, 179, 224, 95, 131, 100, 125,
87, 110, 112, 132, 134, 147, 111, 125, 122, 122,
137, 140, 141, 129, 169, 12, 144, 132, 133, 144,
141, 146, 137, 147, 136, 122, 133, 130, 131, 128,
141, 142, 128, 139, 15, 69, 160, 159, 142, 130,
137, 126, 159, 141, 145, 143, 128, 125, 134, 128,
131, 130, 127, 127, 114, 104, 119, 98, 83, 68,
139, 120, 173, 142, 199, 154, 191, 153, 158, 145,
128, 130, 127, 127, 148, 150, 110, 99, 119, 109,
120, 113, 163, 154, 110, 90, 138, 129, 149, 144,
131, 134, 124, 142, 76, 217, 130, 129, 140, 138,
133, 135, 145, 150, 136, 138, 127, 130, 130, 134,
144, 119, 178, 70, 143, 130, 115, 136, 139, 138,
129, 109, 136, 116, 147, 122, 126, 112, 126, 123,
132, 139, 128, 144, 107, 156, 75, 163, 120, 164,
151, 136, 151, 99, 160, 112, 159, 126, 143, 126,
140, 138, 137, 135, 152, 108, 251, 85, 138, 116,
137, 118, 141, 119, 136, 121, 150, 134, 138, 131,
137, 137, 143, 144, 150, 153, 148, 154, 152, 151,
117, 104, 124, 96, 93, 67, 146, 138, 149, 148,
149, 153, 172, 193, 108, 114, 125, 128, 145, 165,
149, 160, 121, 130, 115, 120, 110, 112, 121, 118,
145, 146, 141, 142, 127, 127, 103, 95, 138, 143,
114, 126, 109, 115, 143, 136, 153, 149, 144, 142,
140, 138, 150, 144, 128, 116, 142, 136, 135, 122,
93, 88, 164, 163, 141, 142, 171, 182, 154, 160,
124, 125, 122, 123, 158, 155, 111, 97, 138, 130,
157, 134, 101, 65, 129, 118, 121, 114, 124, 119,
131, 133, 125, 129, 136, 147, 135, 152, 131, 133,
110, 115, 118, 114, 161, 159, 233, 218, 172, 166,
140, 107, 125, 0, 140, 103, 140, 115, 125, 113,
132, 135, 128, 133, 138, 146, 131, 145, 127, 133,
131, 131, 122, 122, 135, 132, 126, 124, 132, 133,
164, 167, 121, 127, 117, 120, 167, 162, 145, 143,
135, 134, 136, 134, 156, 146, 195, 177, 127, 139,
108, 140, 141, 173, 141, 178, 131, 155, 129, 141,
134, 134, 119, 114, 184, 184, 127, 126, 147, 151,
130, 140, 146, 159, 134, 145, 131, 136, 137, 142,
135, 137, 128, 136, 83, 108, 97, 98, 152, 119,
207, 144, 142, 121, 144, 129, 131, 127, 130, 132,
124, 125, 108, 107, 94, 116, 81, 114, 139, 173,
131, 158, 145, 177, 141, 163, 136, 140, 143, 144,
135, 141, 132, 136, 134, 142, 142, 136, 173, 50,
143, 106, 142, 127, 134, 139, 127, 133, 125, 125,
129, 130, 131, 133, 132, 148, 110, 138, 113, 135,
138, 175, 108, 151, 55, 119, 51, 100, 93, 116,
121, 121, 146, 151, 99, 120, 127, 137, 107, 122,
125, 139, 110, 132, 135, 156, 141, 156, 148, 157,
137, 137, 141, 140, 139, 137, 130, 128, 138, 136,
132, 134, 115, 110, 177, 179, 81, 86, 100, 98,
84, 83, 121, 121, 148, 157, 127, 133, 146, 156,
127, 136, 143, 151, 135, 139, 138, 142, 136, 136,
201, 164, 151, 129, 123, 136, 147, 148, 127, 142,
128, 143, 101, 126, 119, 133, 114, 131, 116, 126,
132, 133, 140, 140, 126, 125, 156, 153, 142, 129,
140, 130, 77, 69, 134, 132, 146, 148, 135, 136,
133, 132, 123, 116, 116, 103, 150, 135, 144, 127,
130, 117, 136, 122, 122, 106, 48, 38, 81, 78,
145, 146, 135, 136, 123, 122, 126, 133, 133, 138,
145, 145, 144, 150, 160, 181, 142, 139, 150, 150,
136, 136, 139, 139, 133, 133, 139, 135, 134, 129,
140, 137, 153, 145, 132, 131, 151, 144, 68, 66,
137, 137, 139, 139, 146, 146, 142, 139, 129, 128,
131, 129, 133, 132, 135, 134, 135, 134, 201, 200,
137, 136, 146, 143, 155, 153, 157, 158, 131, 138,
140, 139, 143, 144, 128, 123, 216, 192, 159, 150,
137, 138, 136, 142, 145, 148, 126, 162, 140, 170,
186, 95, 131, 140, 143, 148, 133, 128, 130, 133,
141, 139, 153, 150, 122, 122, 134, 144, 124, 130,
159, 166, 133, 139, 151, 150, 138, 139, 131, 134,
121, 121, 131, 129, 148, 180, 121, 135, 118, 131,
124, 148, 119, 119, 129, 126, 150, 156, 155, 160,
40, 154, 115, 157, 133, 129, 140, 133, 143, 133,
143, 132, 144, 130, 141, 131, 134, 130, 137, 133,
134, 136, 141, 140, 145, 137, 152, 124, 183, 91,
118, 154, 123, 158, 136, 134, 140, 142, 138, 142,
138, 135, 131, 131, 138, 129, 121, 128, 146, 219,
124, 123, 125, 135, 120, 126, 127, 141, 133, 136,
127, 124, 120, 107, 152, 125, 149, 108, 158, 144,
196, 185, 174, 164, 151, 149, 138, 131, 140, 137,
149, 148, 144, 145, 143, 145, 140, 143, 141, 147,
112, 125, 113, 113, 149, 155, 143, 149, 146, 151,
138, 138, 141, 138, 144, 129, 134, 125, 143, 140,
153, 154, 142, 123, 162, 42, 154, 106, 153, 130,
153, 153, 137, 137, 144, 144, 142, 140, 165, 151,
161, 140, 144, 134, 156, 124, 167, 143, 166, 155,
132, 132, 137, 138, 137, 132, 124, 127, 140, 144,
134, 140, 162, 180, 127, 131, 152, 169, 145, 156,
133, 134, 131, 133, 130, 132, 147, 149, 125, 117,
127, 118, 159, 155, 147, 142, 122, 117, 145, 144,
138, 137, 130, 133, 113, 149, 168, 224, 166, 201,
129, 151, 147, 154, 136, 135, 140, 136, 152, 141,
120, 112, 140, 127, 161, 100, 132, 115, 118, 125,
115, 133, 115, 157, 144, 146, 114, 135, 127, 139,
138, 141, 135, 135, 137, 136, 147, 142, 143, 144,
139, 152, 142, 136, 147, 143, 177, 39, 125, 71,
147, 143, 66, 88, 132, 158, 123, 126, 116, 135,
119, 124, 128, 135, 133, 140, 137, 126, 137, 130,
155, 38, 149, 103, 130, 135, 139, 143, 127, 137,
135, 141, 138, 148, 131, 148, 136, 147, 132, 139,
136, 140, 115, 129, 115, 151, 136, 160, 87, 131,
157, 176, 150, 164, 140, 141, 135, 119, 137, 133,
141, 140, 140, 139, 134, 134, 142, 144, 131, 132,
131, 134, 131, 132, 116, 114, 129, 133, 205, 207,
130, 133, 160, 170, 137, 127, 124, 112, 158, 146,
155, 137, 134, 136, 137, 142, 177, 184, 149, 152,
135, 134, 133, 132, 135, 129, 144, 136, 139, 134,
161, 155, 126, 109, 215, 186, 177, 153, 160, 149,
139, 139, 136, 140, 140, 142, 186, 71, 129, 144,
131, 165, 142, 152, 140, 151, 141, 143, 137, 139,
144, 138, 150, 135, 133, 126, 136, 143, 99, 152,
139, 131, 190, 118, 122, 147, 134, 155, 136, 143,
138, 135, 137, 132, 147, 144, 150, 144, 138, 134,
129, 133, 130, 138, 56, 175, 129, 166, 147, 165,
140, 138, 144, 137, 141, 133, 150, 139, 129, 135,
40, 83, 126, 130, 110, 120, 100, 110, 126, 128,
141, 142, 217, 175, 172, 151, 146, 153, 125, 132,
128, 137, 141, 141, 145, 145, 140, 133, 132, 131,
129, 144, 128, 177, 133, 195, 147, 120, 138, 131,
161, 114, 166, 134, 162, 118, 161, 115, 155, 129,
137, 136, 141, 129, 141, 132, 55, 168, 121, 126,
136, 139, 120, 133, 149, 147, 132, 141, 131, 136,
147, 150, 151, 132, 101, 31, 117, 101, 129, 132,
122, 138, 128, 137, 140, 170, 131, 143, 131, 134,
149, 192, 122, 158, 136, 146, 133, 166, 143, 141,
141, 136, 141, 129, 125, 155, 140, 138, 137, 131,
111, 112, 131, 132, 120, 127, 149, 148, 151, 141,
156, 148, 133, 129, 127, 124, 144, 137, 142, 139,
134, 133, 141, 138, 133, 135, 124, 96, 226, 152,
116, 108, 128, 105, 155, 130, 153, 138, 144, 139,
142, 141, 137, 135, 142, 143, 156, 162, 136, 89,
188, 145, 181, 152, 138, 146, 146, 154, 145, 149,
152, 133, 158, 133, 42, 153, 117, 144, 149, 139,
125, 139, 134, 128, 150, 128, 143, 125, 135, 132,
143, 141, 143, 141, 164, 173, 141, 142, 156, 155,
154, 154, 169, 170, 77, 80, 112, 105, 135, 134,
126, 143, 120, 172, 111, 144, 120, 154, 107, 153,
95, 134, 104, 134, 128, 116, 163, 131, 151, 136,
135, 133, 142, 143, 152, 204, 149, 112, 156, 128,
150, 126, 127, 129, 139, 175, 143, 141, 138, 135,
168, 148, 152, 105, 164, 121, 134, 122, 119, 109,
122, 148, 136, 143, 153, 132, 158, 148, 149, 150,
133, 131, 142, 141, 150, 149, 156, 173, 138, 155,
129, 144, 111, 107, 130, 129, 96, 89, 106, 104,
135, 135, 144, 146, 131, 153, 134, 154, 146, 166,
117, 138, 163, 187, 190, 216, 149, 156, 149, 152,
142, 142, 153, 154, 109, 145, 40, 102, 116, 126,
137, 139, 149, 157, 108, 124, 139, 146, 142, 147,
130, 126, 120, 111, 172, 146, 169, 136, 150, 135,
126, 96, 159, 143, 150, 122, 162, 129, 156, 142,
135, 142, 144, 138, 222, 109, 137, 145, 144, 142,
141, 143, 138, 136, 124, 150, 133, 144, 137, 145,
141, 144, 139, 144, 134, 154, 114, 136, 145, 173,
151, 215, 110, 115, 127, 134, 145, 150, 145, 144,
144, 142, 139, 131, 147, 132, 141, 119, 143, 106,
165, 41, 147, 129, 129, 144, 138, 135, 138, 140,
128, 150, 89, 163, 154, 115, 141, 127, 132, 145,
135, 157, 143, 145, 140, 141, 127, 135, 127, 129,
142, 147, 116, 147, 104, 162, 153, 143, 146, 130,
144, 110, 133, 123, 130, 137, 118, 198, 126, 152,
154, 146, 139, 127, 147, 112, 207, 151, 156, 136,
162, 137, 108, 121, 130, 135, 125, 131, 131, 134,
134, 134, 141, 144, 107, 143, 137, 144, 124, 136,
115, 147, 130, 157, 119, 167, 71, 144, 97, 128,
134, 138, 132, 133, 138, 138, 146, 146, 147, 131,
141, 138, 185, 65, 145, 123, 139, 130, 142, 128,
139, 136, 157, 147, 124, 119, 164, 148, 170, 154,
133, 130, 157, 148, 140, 141, 130, 135, 134, 137,
136, 137, 143, 144, 144, 144, 178, 186, 71, 73,
120, 118, 127, 124, 152, 151, 155, 146, 141, 138,
142, 143, 139, 143, 133, 134, 139, 140, 138, 135,
146, 141, 78, 198, 129, 139, 141, 141, 134, 141,
137, 136, 120, 120, 124, 118, 143, 148, 148, 152,
131, 143, 129, 137, 152, 158, 157, 160, 175, 178,
137, 139, 131, 133, 146, 152, 121, 147, 142, 143,
129, 136, 149, 145, 197, 114, 103, 141, 124, 140,
141, 140, 129, 129, 127, 130, 131, 124, 123, 117,
150, 139, 120, 109, 119, 120, 163, 163, 117, 121,
139, 139, 136, 136, 94, 74, 150, 145, 126, 127,
147, 150, 158, 162, 84, 74, 136, 129, 140, 132,
136, 135, 146, 145, 124, 116, 129, 120, 130, 129,
130, 109, 122, 111, 160, 141, 135, 113, 131, 121,
136, 135, 135, 135, 147, 147, 140, 140, 144, 145,
139, 142, 131, 137, 145, 145, 143, 153, 48, 49,
145, 143, 151, 147, 158, 146, 135, 124, 124, 116,
159, 140, 131, 126, 123, 120, 103, 117, 113, 119,
148, 146, 128, 124, 123, 126, 123, 120, 158, 141,
148, 137, 146, 143, 125, 143, 89, 107, 116, 123,
149, 147, 141, 139, 149, 153, 118, 121, 139, 138,
105, 119, 168, 147, 139, 141, 143, 138, 133, 130,
126, 126, 143, 142, 146, 144, 124, 123, 143, 145,
149, 148, 147, 141, 151, 143, 118, 113, 175, 171
};
static const uint8_t wmavoice_dq_lsp16r1[0x500] = {
147, 145, 193, 168, 188, 156, 141, 145, 141, 139,
148, 149, 148, 149, 153, 157, 144, 144, 152, 152,
141, 145, 153, 143, 243, 134, 151, 133, 166, 135,
150, 149, 135, 132, 32, 39, 110, 111, 109, 114,
126, 127, 147, 146, 177, 169, 162, 156, 210, 187,
141, 147, 95, 150, 127, 155, 108, 133, 139, 148,
138, 138, 140, 140, 147, 146, 134, 130, 136, 134,
147, 146, 142, 150, 62, 174, 126, 151, 122, 156,
154, 156, 179, 184, 115, 107, 105, 99, 127, 124,
146, 131, 140, 44, 132, 125, 156, 146, 153, 153,
136, 137, 145, 144, 141, 139, 158, 152, 138, 132,
145, 145, 147, 145, 146, 141, 144, 140, 110, 97,
140, 141, 143, 142, 130, 123, 127, 117, 126, 120,
147, 146, 161, 155, 169, 135, 122, 117, 166, 155,
144, 144, 142, 142, 125, 122, 137, 128, 194, 172,
127, 85, 148, 143, 153, 141, 147, 147, 140, 143,
118, 140, 0, 69, 51, 60, 111, 123, 137, 135,
146, 146, 164, 165, 207, 214, 145, 143, 149, 147,
178, 168, 197, 170, 134, 154, 148, 159, 115, 140,
103, 118, 13, 38, 139, 138, 135, 138, 140, 141,
144, 144, 140, 140, 150, 150, 156, 157, 164, 171,
143, 143, 140, 142, 118, 120, 172, 172, 160, 163,
146, 147, 150, 151, 176, 176, 230, 237, 153, 153,
168, 156, 173, 149, 164, 148, 162, 146, 178, 158,
147, 145, 143, 145, 111, 126, 111, 130, 89, 118,
153, 158, 122, 120, 142, 125, 124, 105, 148, 138,
145, 144, 156, 151, 193, 154, 146, 147, 119, 135,
142, 141, 145, 145, 152, 147, 142, 141, 146, 146,
139, 138, 154, 154, 148, 150, 147, 149, 144, 145,
134, 134, 141, 140, 135, 134, 145, 147, 160, 163,
144, 145, 149, 146, 115, 67, 127, 119, 141, 135,
145, 141, 130, 124, 143, 144, 151, 165, 141, 144,
154, 152, 160, 136, 115, 82, 64, 71, 64, 65,
143, 143, 151, 149, 240, 251, 165, 173, 173, 179,
148, 134, 156, 55, 160, 105, 133, 91, 129, 96,
149, 149, 145, 144, 160, 154, 171, 159, 140, 142,
154, 163, 178, 244, 147, 140, 153, 150, 137, 121,
145, 144, 145, 146, 138, 139, 149, 152, 189, 198,
148, 148, 156, 158, 168, 182, 165, 182, 172, 201,
143, 142, 99, 92, 152, 152, 143, 143, 127, 127,
165, 148, 173, 124, 113, 122, 134, 142, 127, 142,
124, 126, 137, 137, 131, 132, 144, 142, 141, 138,
172, 176, 138, 111, 152, 136, 167, 154, 156, 137,
140, 150, 78, 145, 158, 157, 161, 154, 155, 147,
153, 164, 156, 191, 129, 109, 153, 146, 153, 141,
138, 137, 141, 138, 115, 94, 144, 141, 155, 147,
144, 142, 144, 137, 168, 113, 141, 134, 145, 137,
146, 144, 150, 148, 140, 155, 103, 178, 137, 149,
145, 147, 148, 153, 175, 201, 138, 146, 110, 108,
143, 146, 124, 134, 124, 127, 164, 158, 127, 135,
145, 146, 150, 150, 145, 147, 95, 80, 150, 151,
149, 149, 162, 162, 144, 152, 170, 169, 145, 154,
145, 149, 143, 146, 142, 145, 152, 146, 160, 98,
141, 141, 153, 153, 140, 137, 131, 131, 145, 146,
133, 132, 127, 124, 158, 150, 173, 164, 178, 167,
146, 146, 154, 155, 117, 127, 143, 147, 147, 156,
142, 143, 144, 145, 146, 152, 170, 199, 151, 165,
146, 147, 139, 140, 147, 149, 132, 134, 147, 149,
138, 139, 142, 143, 162, 188, 145, 149, 160, 164,
150, 150, 139, 139, 143, 142, 146, 146, 137, 138,
142, 142, 141, 140, 152, 153, 164, 171, 110, 112,
139, 139, 143, 143, 138, 138, 142, 142, 143, 143,
137, 140, 142, 142, 145, 141, 149, 141, 182, 135,
146, 146, 150, 150, 144, 145, 150, 151, 135, 137,
137, 145, 51, 62, 68, 54, 69, 57, 62, 41,
137, 139, 139, 144, 135, 150, 225, 232, 208, 197,
136, 135, 141, 143, 145, 150, 160, 169, 213, 247,
142, 137, 72, 54, 110, 107, 105, 107, 127, 130,
145, 143, 169, 155, 219, 174, 195, 164, 183, 157,
155, 157, 239, 232, 169, 164, 170, 172, 156, 159,
142, 143, 136, 144, 59, 100, 139, 142, 130, 138,
147, 146, 150, 161, 128, 235, 143, 155, 146, 167,
154, 149, 128, 151, 42, 149, 55, 136, 59, 127,
128, 126, 74, 92, 143, 153, 140, 150, 166, 176,
146, 152, 150, 145, 140, 100, 140, 105, 124, 59,
195, 191, 146, 148, 144, 136, 136, 133, 129, 122,
133, 148, 40, 147, 102, 140, 123, 148, 118, 136,
143, 143, 150, 148, 184, 153, 160, 147, 166, 149,
58, 68, 127, 135, 141, 145, 143, 147, 150, 151,
140, 143, 137, 137, 120, 114, 71, 65, 125, 123,
153, 148, 215, 159, 136, 135, 150, 146, 150, 150,
148, 138, 166, 94, 150, 145, 145, 139, 147, 145,
146, 147, 150, 139, 171, 63, 158, 142, 153, 133,
147, 148, 143, 143, 76, 72, 155, 159, 164, 176,
149, 149, 173, 195, 145, 165, 138, 144, 150, 167,
180, 169, 146, 151, 146, 166, 147, 166, 149, 171,
157, 156, 168, 166, 147, 149, 121, 122, 116, 124,
145, 145, 147, 148, 172, 189, 168, 180, 144, 146,
139, 145, 141, 150, 115, 172, 141, 146, 143, 148,
145, 145, 142, 143, 145, 147, 138, 143, 58, 73,
141, 142, 146, 145, 163, 149, 218, 161, 147, 132,
152, 147, 146, 147, 140, 150, 141, 152, 89, 150,
78, 134, 135, 137, 139, 142, 140, 137, 137, 130,
144, 144, 152, 151, 145, 140, 181, 170, 191, 168,
164, 166, 136, 148, 112, 124, 139, 144, 146, 149,
142, 151, 113, 182, 137, 150, 143, 156, 138, 147,
154, 156, 108, 102, 118, 119, 133, 139, 113, 111,
145, 144, 150, 147, 175, 151, 104, 106, 116, 114,
143, 144, 151, 157, 151, 191, 135, 113, 138, 123,
146, 146, 155, 157, 106, 145, 132, 127, 140, 125,
161, 165, 146, 150, 151, 154, 139, 140, 142, 143,
144, 148, 145, 149, 147, 138, 168, 104, 146, 136,
138, 140, 91, 108, 111, 110, 145, 140, 158, 154,
130, 112, 122, 118, 136, 135, 119, 118, 141, 140,
147, 146, 146, 145, 138, 138, 182, 188, 132, 132,
144, 144, 156, 155, 168, 172, 123, 128, 144, 151,
142, 140, 145, 145, 137, 144, 141, 152, 128, 188,
149, 149, 160, 161, 160, 160, 166, 163, 130, 107,
143, 143, 142, 142, 149, 149, 132, 132, 170, 174,
148, 148, 154, 153, 118, 111, 157, 155, 114, 109,
140, 139, 138, 137, 205, 187, 137, 133, 147, 144,
144, 145, 147, 149, 105, 125, 108, 117, 155, 162,
146, 146, 162, 157, 144, 122, 154, 143, 161, 139,
141, 142, 130, 131, 144, 144, 142, 141, 144, 142,
132, 132, 141, 141, 150, 151, 139, 141, 151, 153,
142, 142, 154, 154, 150, 150, 148, 148, 166, 165,
143, 142, 144, 144, 132, 132, 142, 144, 130, 128,
142, 142, 143, 143, 153, 153, 147, 142, 129, 125,
142, 141, 143, 142, 143, 147, 105, 122, 135, 140,
141, 140, 140, 140, 151, 151, 156, 155, 146, 146,
133, 134, 140, 142, 142, 145, 141, 146, 112, 133,
142, 142, 145, 145, 137, 138, 155, 157, 149, 150,
144, 144, 139, 138, 130, 128, 132, 131, 147, 147,
139, 140, 142, 143, 115, 121, 141, 143, 137, 141,
146, 146, 150, 150, 145, 144, 133, 133, 133, 135,
143, 144, 144, 144, 166, 167, 139, 142, 139, 140,
150, 149, 138, 138, 142, 140, 148, 147, 160, 155,
146, 146, 147, 147, 138, 137, 143, 142, 151, 150
};
static const uint8_t wmavoice_dq_lsp16r2[0x500] = {
98, 98, 119, 121, 109, 112, 128, 135, 115, 121,
159, 113, 113, 106, 127, 114, 101, 102, 105, 111,
161, 162, 137, 138, 161, 159, 152, 150, 150, 148,
128, 79, 131, 102, 142, 120, 133, 119, 130, 117,
121, 115, 142, 133, 186, 155, 179, 144, 169, 135,
107, 103, 106, 106, 122, 122, 111, 112, 112, 115,
127, 123, 118, 115, 128, 125, 123, 119, 115, 109,
124, 130, 117, 126, 121, 133, 84, 144, 99, 114,
122, 125, 123, 131, 124, 135, 176, 200, 158, 176,
68, 74, 86, 87, 117, 115, 119, 116, 135, 128,
115, 116, 102, 104, 119, 123, 133, 148, 102, 109,
71, 121, 106, 117, 107, 127, 106, 122, 100, 110,
117, 115, 129, 128, 87, 84, 116, 116, 151, 157,
116, 128, 110, 117, 119, 134, 100, 114, 120, 129,
142, 141, 146, 151, 94, 91, 114, 114, 118, 118,
114, 112, 112, 109, 115, 112, 123, 123, 147, 148,
110, 164, 106, 152, 110, 158, 106, 151, 105, 135,
85, 51, 71, 27, 71, 34, 74, 45, 85, 53,
145, 134, 140, 130, 136, 134, 118, 122, 118, 126,
117, 84, 121, 81, 106, 80, 109, 106, 121, 127,
95, 94, 112, 110, 90, 94, 109, 107, 114, 109,
117, 118, 118, 123, 107, 107, 86, 93, 29, 31,
125, 112, 104, 60, 121, 111, 127, 116, 133, 130,
118, 117, 148, 145, 122, 126, 124, 127, 90, 91,
113, 110, 119, 118, 152, 147, 115, 112, 132, 131,
129, 140, 98, 112, 73, 85, 109, 115, 122, 126,
123, 122, 122, 122, 126, 125, 137, 140, 203, 210,
164, 176, 114, 114, 125, 122, 119, 112, 125, 120,
124, 122, 118, 115, 95, 96, 141, 144, 132, 131,
127, 130, 132, 134, 116, 114, 122, 123, 137, 134,
111, 111, 112, 116, 106, 118, 77, 101, 104, 115,
111, 111, 125, 126, 118, 121, 113, 115, 113, 113,
171, 170, 202, 199, 221, 206, 199, 184, 177, 167,
73, 90, 61, 93, 43, 74, 51, 71, 51, 72,
130, 130, 140, 137, 134, 132, 164, 160, 118, 111,
123, 136, 133, 154, 130, 158, 106, 110, 110, 114,
97, 97, 91, 94, 70, 69, 125, 123, 141, 140,
119, 100, 116, 77, 111, 67, 105, 52, 95, 34,
100, 122, 90, 124, 68, 120, 43, 117, 50, 112,
130, 129, 192, 188, 123, 118, 124, 117, 121, 115,
122, 111, 129, 111, 157, 85, 125, 109, 125, 119,
143, 152, 119, 128, 114, 116, 129, 136, 148, 157,
119, 117, 115, 115, 150, 148, 163, 154, 109, 102,
120, 126, 73, 119, 106, 121, 102, 122, 96, 113,
84, 83, 117, 115, 122, 117, 154, 143, 159, 142,
118, 122, 114, 117, 115, 122, 114, 130, 99, 156,
123, 120, 122, 116, 100, 81, 99, 91, 121, 112,
139, 131, 164, 142, 132, 119, 145, 133, 157, 141,
112, 109, 118, 116, 142, 134, 108, 110, 96, 99,
111, 110, 113, 112, 111, 104, 98, 94, 131, 131,
115, 114, 121, 118, 120, 115, 173, 148, 123, 117,
121, 124, 122, 124, 140, 146, 78, 82, 96, 93,
86, 90, 124, 125, 121, 123, 105, 106, 134, 135,
107, 109, 132, 141, 100, 95, 113, 114, 102, 105,
113, 130, 98, 145, 116, 115, 124, 117, 115, 105,
120, 123, 89, 87, 109, 108, 102, 101, 117, 117,
113, 122, 132, 138, 77, 116, 86, 99, 118, 126,
123, 120, 117, 111, 124, 119, 129, 118, 63, 58,
141, 135, 108, 106, 109, 111, 108, 110, 135, 138,
117, 114, 134, 127, 139, 129, 138, 130, 126, 122,
121, 118, 124, 121, 133, 130, 98, 85, 130, 123,
147, 129, 118, 112, 148, 130, 136, 123, 148, 131,
113, 112, 123, 118, 123, 115, 147, 95, 117, 110,
118, 119, 112, 113, 112, 113, 119, 119, 120, 120,
158, 133, 198, 145, 188, 129, 197, 137, 195, 133,
132, 140, 140, 139, 158, 156, 223, 217, 233, 233,
48, 56, 34, 37, 82, 84, 102, 102, 108, 110,
120, 142, 136, 169, 146, 195, 136, 186, 140, 182,
196, 186, 158, 155, 142, 134, 132, 125, 120, 119,
97, 105, 72, 75, 82, 85, 81, 84, 107, 109,
67, 121, 43, 119, 69, 124, 87, 129, 88, 128,
53, 57, 93, 98, 91, 94, 93, 98, 104, 104,
124, 123, 133, 133, 182, 181, 119, 121, 114, 116,
128, 105, 134, 112, 131, 72, 119, 59, 111, 84,
132, 142, 145, 180, 124, 132, 131, 143, 122, 134,
88, 85, 103, 103, 136, 140, 131, 143, 114, 132,
116, 57, 113, 57, 121, 76, 126, 80, 118, 86,
127, 112, 127, 97, 131, 100, 149, 91, 163, 86,
122, 119, 128, 121, 128, 116, 142, 127, 173, 139,
162, 116, 166, 107, 149, 103, 152, 107, 141, 108,
114, 113, 118, 116, 56, 43, 90, 90, 105, 105,
132, 134, 110, 107, 106, 105, 82, 84, 84, 84,
102, 106, 79, 89, 99, 99, 127, 129, 114, 118,
139, 157, 116, 123, 116, 123, 87, 89, 110, 113,
119, 126, 97, 97, 155, 163, 142, 153, 143, 146,
117, 114, 66, 67, 125, 126, 127, 128, 114, 113,
111, 114, 127, 133, 123, 132, 143, 162, 133, 148,
105, 108, 114, 114, 110, 109, 57, 48, 109, 106,
113, 130, 104, 131, 88, 139, 102, 169, 100, 172,
129, 114, 150, 97, 114, 112, 117, 119, 109, 116,
92, 107, 96, 116, 90, 125, 101, 122, 125, 140,
125, 133, 122, 129, 136, 153, 125, 135, 131, 139,
84, 71, 129, 123, 135, 120, 114, 103, 112, 101,
108, 121, 115, 156, 106, 123, 116, 131, 127, 139,
137, 147, 109, 117, 119, 126, 135, 144, 117, 119,
120, 127, 76, 105, 111, 116, 120, 125, 141, 138,
107, 104, 162, 155, 135, 130, 127, 123, 127, 121,
102, 104, 84, 87, 112, 115, 97, 102, 78, 82,
119, 118, 120, 123, 91, 105, 114, 119, 119, 126,
130, 126, 134, 126, 158, 134, 133, 99, 116, 100,
125, 122, 145, 143, 126, 117, 98, 96, 121, 120,
152, 148, 131, 126, 130, 129, 126, 119, 87, 87,
131, 131, 139, 137, 101, 102, 104, 105, 86, 83,
92, 89, 111, 105, 121, 115, 137, 124, 96, 84,
100, 96, 122, 119, 107, 108, 93, 96, 79, 82,
128, 123, 108, 106, 123, 120, 150, 150, 143, 140,
121, 120, 97, 99, 79, 80, 116, 116, 88, 90,
128, 131, 101, 97, 140, 140, 117, 116, 116, 118,
137, 135, 100, 91, 115, 112, 134, 121, 107, 99,
120, 122, 122, 125, 124, 126, 136, 141, 89, 95,
103, 119, 103, 116, 122, 139, 125, 137, 152, 170,
121, 122, 124, 124, 98, 97, 137, 140, 96, 92,
115, 113, 136, 136, 128, 132, 122, 124, 151, 158,
100, 107, 121, 131, 131, 158, 119, 130, 113, 114,
114, 109, 148, 130, 103, 95, 127, 116, 137, 120,
103, 108, 97, 97, 133, 128, 113, 109, 136, 128,
125, 124, 118, 118, 122, 121, 101, 99, 157, 152,
138, 134, 124, 115, 113, 101, 123, 112, 124, 110,
116, 113, 128, 121, 119, 110, 124, 113, 128, 67,
114, 118, 114, 123, 109, 121, 102, 123, 56, 116,
117, 111, 112, 99, 124, 114, 112, 79, 114, 88,
112, 113, 115, 117, 126, 127, 130, 132, 123, 122,
111, 104, 111, 102, 112, 102, 129, 118, 129, 115,
123, 124, 130, 133, 114, 117, 125, 127, 112, 117,
124, 125, 119, 120, 117, 116, 105, 104, 110, 110,
125, 124, 118, 116, 124, 123, 124, 121, 133, 132,
111, 111, 124, 124, 120, 119, 116, 116, 134, 130,
114, 116, 112, 113, 109, 111, 116, 118, 95, 98
};
static const uint8_t wmavoice_dq_lsp16r3[0x600] = {
84, 82, 95, 94, 125, 131, 98, 102, 94, 93, 104, 104,
127, 113, 87, 77, 125, 114, 109, 94, 94, 91, 106, 105,
168, 125, 163, 120, 128, 100, 119, 99, 108, 97, 108, 106,
86, 85, 128, 125, 79, 73, 103, 102, 123, 123, 116, 117,
84, 76, 135, 131, 133, 133, 129, 130, 125, 123, 115, 114,
94, 97, 79, 81, 115, 115, 94, 93, 128, 127, 126, 125,
124, 111, 105, 114, 104, 117, 109, 110, 124, 125, 118, 117,
107, 110, 106, 110, 93, 93, 149, 148, 118, 119, 111, 110,
147, 157, 143, 156, 134, 136, 118, 121, 106, 107, 105, 105,
114, 83, 114, 46, 106, 53, 110, 83, 107, 94, 105, 103,
92, 90, 109, 106, 172, 160, 114, 110, 109, 110, 110, 109,
90, 98, 98, 109, 102, 98, 97, 92, 100, 100, 101, 102,
123, 117, 124, 98, 82, 80, 117, 115, 112, 110, 109, 108,
107, 111, 100, 115, 105, 120, 104, 105, 83, 82, 95, 96,
109, 120, 72, 71, 97, 104, 69, 74, 99, 102, 118, 117,
137, 133, 142, 135, 105, 110, 121, 121, 125, 122, 114, 112,
151, 186, 115, 132, 103, 111, 100, 104, 99, 101, 104, 105,
18, 38, 56, 65, 76, 83, 85, 91, 101, 103, 108, 110,
144, 135, 126, 121, 115, 113, 79, 80, 118, 117, 117, 117,
117, 124, 115, 115, 126, 113, 130, 116, 112, 106, 108, 105,
77, 76, 76, 80, 109, 109, 125, 129, 130, 133, 116, 118,
96, 86, 109, 99, 102, 69, 84, 69, 107, 103, 114, 113,
78, 118, 82, 114, 84, 129, 69, 112, 78, 98, 96, 103,
89, 137, 96, 111, 105, 97, 93, 93, 101, 105, 105, 105,
141, 123, 102, 93, 91, 79, 87, 81, 102, 99, 109, 108,
94, 92, 124, 123, 130, 134, 100, 107, 71, 75, 92, 91,
94, 104, 107, 83, 106, 101, 113, 114, 122, 122, 114, 114,
118, 124, 103, 106, 95, 116, 90, 93, 107, 104, 109, 107,
116, 118, 76, 72, 88, 88, 132, 132, 140, 141, 116, 116,
90, 81, 111, 95, 139, 97, 123, 96, 112, 100, 110, 108,
112, 116, 133, 140, 112, 120, 80, 85, 55, 55, 85, 84,
125, 94, 111, 104, 116, 103, 112, 86, 93, 84, 99, 98,
180, 179, 197, 197, 169, 163, 149, 146, 130, 124, 116, 115,
76, 47, 36, 11, 43, 28, 66, 53, 82, 80, 102, 99,
119, 123, 176, 201, 113, 120, 112, 111, 103, 105, 106, 110,
145, 114, 112, 89, 120, 93, 123, 104, 131, 123, 113, 111,
97, 109, 82, 106, 75, 104, 103, 115, 120, 124, 111, 114,
114, 111, 113, 105, 34, 33, 63, 63, 105, 106, 122, 122,
51, 41, 96, 92, 125, 125, 118, 118, 118, 119, 113, 113,
111, 180, 108, 178, 107, 171, 110, 160, 105, 136, 102, 117,
76, 79, 90, 92, 80, 88, 88, 93, 123, 124, 122, 122,
131, 128, 123, 122, 151, 158, 108, 107, 129, 128, 119, 119,
97, 99, 114, 120, 121, 125, 151, 157, 82, 89, 95, 96,
128, 94, 130, 95, 149, 113, 149, 120, 127, 115, 113, 109,
167, 171, 83, 80, 84, 79, 106, 106, 112, 110, 107, 108,
130, 139, 81, 88, 107, 106, 112, 112, 119, 118, 114, 112,
108, 105, 100, 98, 120, 116, 122, 117, 38, 37, 72, 73,
118, 125, 110, 120, 114, 126, 135, 142, 139, 142, 118, 119,
119, 119, 156, 145, 78, 75, 94, 94, 112, 110, 113, 113,
101, 108, 98, 104, 103, 109, 117, 118, 167, 167, 132, 132,
116, 108, 118, 111, 149, 136, 85, 74, 95, 92, 113, 112,
74, 69, 104, 107, 96, 100, 117, 121, 103, 105, 103, 103,
110, 106, 111, 101, 82, 72, 96, 92, 132, 130, 120, 121,
116, 113, 138, 139, 104, 103, 131, 131, 68, 69, 92, 92,
97, 97, 146, 151, 122, 132, 97, 95, 117, 116, 115, 116,
139, 134, 110, 110, 124, 129, 100, 110, 86, 91, 100, 102,
116, 136, 88, 90, 137, 139, 103, 114, 114, 117, 111, 110,
82, 83, 104, 102, 97, 99, 97, 97, 58, 56, 84, 84,
83, 122, 76, 105, 112, 126, 120, 134, 112, 120, 108, 110,
114, 128, 73, 90, 72, 76, 98, 100, 95, 96, 101, 102,
101, 108, 118, 126, 94, 102, 81, 83, 138, 140, 131, 130,
88, 100, 112, 124, 105, 106, 122, 123, 121, 121, 114, 114,
76, 108, 73, 83, 93, 95, 110, 111, 98, 99, 103, 103,
105, 112, 98, 108, 114, 95, 117, 98, 120, 116, 116, 115,
231, 238, 150, 146, 124, 126, 115, 122, 117, 121, 112, 112,
74, 73, 72, 74, 60, 61, 62, 61, 85, 85, 101, 101,
67, 69, 50, 51, 83, 83, 110, 110, 118, 113, 112, 111,
199, 124, 184, 115, 176, 117, 165, 120, 138, 115, 116, 114,
52, 116, 36, 107, 49, 99, 72, 106, 91, 107, 104, 105,
140, 138, 141, 135, 154, 147, 166, 159, 139, 136, 116, 115,
130, 119, 180, 157, 183, 149, 136, 121, 119, 114, 111, 110,
104, 129, 113, 154, 111, 148, 108, 132, 105, 117, 106, 111,
114, 35, 99, 65, 113, 94, 110, 98, 111, 107, 107, 106,
106, 110, 128, 135, 162, 175, 143, 155, 115, 116, 109, 109,
168, 155, 112, 109, 125, 125, 126, 122, 126, 124, 111, 112,
128, 96, 160, 77, 151, 77, 121, 80, 114, 94, 107, 103,
97, 104, 101, 116, 56, 79, 74, 83, 92, 95, 104, 106,
63, 68, 76, 77, 110, 107, 96, 90, 85, 83, 97, 96,
116, 110, 46, 42, 103, 100, 122, 120, 102, 101, 104, 104,
106, 101, 109, 98, 96, 61, 67, 35, 72, 61, 96, 93,
88, 80, 81, 76, 113, 110, 144, 143, 88, 89, 93, 94,
95, 96, 100, 101, 136, 132, 166, 160, 148, 147, 115, 116,
80, 78, 130, 129, 120, 108, 91, 85, 95, 91, 104, 102,
151, 147, 106, 109, 110, 110, 64, 69, 68, 67, 96, 96,
90, 166, 97, 128, 99, 120, 104, 121, 109, 118, 105, 109,
122, 138, 110, 143, 75, 97, 83, 94, 89, 94, 102, 103,
136, 142, 103, 110, 83, 89, 99, 101, 138, 138, 120, 122,
168, 88, 105, 90, 109, 107, 110, 111, 106, 105, 103, 102,
68, 72, 102, 104, 92, 102, 65, 75, 89, 94, 106, 106,
83, 74, 93, 85, 73, 66, 106, 102, 100, 92, 99, 97,
93, 99, 101, 96, 116, 112, 125, 120, 88, 88, 96, 96,
44, 98, 93, 115, 104, 116, 103, 107, 112, 113, 107, 107,
93, 83, 105, 99, 93, 84, 127, 125, 141, 143, 117, 118,
106, 103, 126, 121, 137, 123, 123, 114, 147, 142, 127, 123,
103, 110, 89, 91, 121, 124, 66, 71, 68, 69, 96, 97,
114, 105, 68, 65, 69, 67, 96, 94, 131, 130, 123, 121,
111, 104, 130, 121, 95, 95, 72, 74, 88, 88, 105, 104,
135, 124, 110, 98, 114, 111, 159, 158, 111, 113, 104, 106,
103, 108, 94, 107, 55, 57, 115, 118, 121, 122, 111, 111,
97, 99, 106, 111, 119, 126, 59, 62, 111, 112, 124, 125,
86, 93, 100, 110, 118, 145, 113, 132, 120, 125, 112, 112,
101, 115, 78, 149, 81, 114, 111, 121, 108, 112, 107, 108,
104, 104, 94, 96, 84, 83, 135, 132, 71, 69, 88, 86,
100, 98, 62, 60, 81, 80, 90, 89, 63, 66, 89, 90,
123, 116, 108, 99, 90, 86, 91, 92, 65, 65, 88, 88,
84, 79, 115, 109, 123, 111, 99, 99, 134, 136, 121, 123,
127, 137, 84, 88, 104, 107, 128, 130, 74, 69, 89, 89,
118, 112, 143, 132, 141, 131, 113, 113, 99, 102, 104, 105,
117, 115, 100, 99, 131, 126, 90, 88, 145, 144, 128, 127,
112, 114, 131, 133, 85, 84, 118, 119, 151, 152, 117, 117,
110, 105, 162, 140, 116, 107, 140, 134, 124, 122, 113, 113,
107, 110, 124, 133, 98, 103, 99, 107, 109, 113, 112, 112,
115, 105, 82, 77, 125, 122, 133, 132, 118, 120, 113, 113,
101, 88, 84, 80, 97, 99, 91, 91, 94, 94, 101, 100,
121, 86, 139, 108, 106, 93, 103, 99, 112, 108, 108, 107,
113, 83, 105, 102, 125, 125, 114, 115, 110, 112, 108, 109,
93, 112, 113, 121, 125, 131, 101, 101, 107, 109, 111, 111,
98, 102, 117, 126, 80, 84, 107, 109, 83, 84, 96, 97,
132, 136, 112, 118, 94, 93, 121, 118, 99, 98, 102, 103,
122, 127, 128, 133, 118, 104, 102, 88, 100, 94, 104, 102,
115, 116, 102, 105, 140, 142, 135, 130, 90, 88, 100, 101,
94, 86, 112, 112, 89, 121, 92, 101, 109, 108, 110, 112,
99, 93, 129, 114, 109, 99, 131, 119, 102, 97, 103, 103,
103, 116, 124, 101, 115, 95, 105, 101, 94, 91, 100, 100,
113, 90, 94, 86, 92, 92, 117, 111, 106, 103, 106, 105,
115, 99, 110, 91, 107, 104, 81, 90, 108, 113, 112, 113,
113, 114, 93, 101, 101, 102, 101, 126, 93, 103, 104, 105,
117, 106, 124, 107, 104, 119, 108, 133, 104, 111, 104, 106
};
static const float wmavoice_lsp10_intercoeff_a[32][2][10] = {
{ { 0.5108627081, 0.0480548441, -1.5099149644, 0.6736935377,
0.7536551058, 0.7651474178, 0.8510628343, 0.6667704582,
0.7576012611, 0.7091397047 },
{ 0.1351471841, -0.1965375543, -1.6313457787, 0.3218626380,
0.4132472873, 0.4663473070, 0.5805781186, 0.3962165117,
0.4818550050, 0.4907165468 } },
{ { 0.8556320667, 0.7774704993, -0.0175759494, -0.1882298589,
0.1892164350, 0.4850396216, 0.6270319819, 0.6327089071,
0.6513319910, 0.6075088978 },
{ 0.4374088347, 0.3505934179, -0.0762144327, -0.2830760479,
-0.0626451969, 0.1500318050, 0.2602472305, 0.2781780064,
0.3167395592, 0.3596626520 } },
{ { 0.1899779737, 0.0650856197, 0.1699010432, 0.9122628570,
0.9097705483, 0.7433397174, 0.6304935217, 0.5164704025,
0.4174703658, 0.5215242505 },
{ 0.0704856217, 0.0169009864, 0.0188394487, 0.5587704182,
0.5194473267, 0.3539164960, 0.2426626086, 0.1721164286,
0.1371548772, 0.2594856918 } },
{ { 0.8858859241, 0.9100474715, 0.8921859264, 0.9332397878,
1.0225475132, 1.0555013716, 1.0983552337, 1.1290244758,
1.0363244414, 0.9277705550 },
{ 0.4810934663, 0.5782935023, 0.6835935414, 0.7650781870,
0.9018090069, 0.9996321201, 1.0219936669, 1.0474705994,
0.9109474719, 0.7774704993 } },
{ { 0.4359549880, 0.2275702953, 0.0993548632, 0.1763395071,
0.1055856347, 0.1018471718, 0.1170087159, 0.1221317947,
0.1834010482, 0.2988780141 },
{ 0.1573702693, 0.1041317880, 0.0506856143, 0.0781702399,
0.0058932900, -0.0026913285, -0.0031067133, 0.0070702136,
0.0116394460, 0.0566394627 } },
{ { 0.8528628349, 0.8028782010, 0.4680088460, 0.9055474699,
1.3742399514, 1.1093629301, 0.4122780561, 0.4003703594,
0.6360319853, 0.6415704489 },
{ 0.4252934456, 0.3823703527, 0.1676856577, 0.5241550207,
1.1995706558, 0.9088013172, 0.1224087179, 0.0730471611,
0.3071857095, 0.3772472739 } },
{ { 0.5508781075, 0.2829549313, -0.0022067130, 0.1042702496,
1.0318244398, 1.3258476257, 1.3550630212, 0.9931936562,
0.7195243239, 0.6807550788 },
{ 0.2679318488, 0.0960317850, -0.1357529163, -0.1291759908,
0.6451012194, 0.9968628883, 0.9510321021, 0.6608166099,
0.3799472749, 0.3735780418 } },
{ { 0.9967244267, 1.0255244374, 0.9800398052, 0.7939474285,
0.8288397491, 0.8390166759, 0.8660166860, 0.9247936308,
0.9127474725, 0.8684397638 },
{ 0.7921474278, 0.9416859448, 0.8547320664, 0.5348165631,
0.6231550574, 0.6703012288, 0.6987550855, 0.8147858977,
0.7406397164, 0.6496012211 } },
{ { 0.1439394951, -0.3193529844, -0.2024914026, -0.1854606271,
0.0877240896, 0.1617318094, 0.3087087870, 0.3777318895,
0.3910242021, 0.4797780812 },
{ -0.0157067180, -0.1778452396, -0.1554836929, -0.1759760082,
-0.0607759655, -0.0161221027, 0.0393317640, 0.0758856237,
0.1163856387, 0.1947548985 } },
{ { 1.1021629274, 0.9958244264, 0.4658626914, 0.3089164793,
0.3740626574, 0.2962472439, 0.3170857131, 0.2420395315,
0.2649549246, 0.2936857045 },
{ 0.4700857699, 0.1809087396, 0.0311625302, 0.0106009841,
0.0311625302, 0.0266625285, 0.0221625268, 0.0156548321,
0.0551163852, 0.1010164022 } },
{ { 0.2925087810, 0.3418011069, 0.7339243293, 0.7322627902,
0.7288704813, 0.7924935818, 0.7724166512, 0.7819012702,
0.8325782120, 0.7954705060 },
{ 0.0559471548, -0.0456144214, -0.0462374985, -0.1005144417,
-0.0511528850, -0.0455451906, -0.0044220984, 0.0451471508,
0.1232394874, 0.2085318267 } },
{ { 0.2230702937, -0.9052532017, 1.2441552877, 1.0825706124,
0.9088705480, 0.8797243834, 0.8648397624, 0.8091089725,
0.7633474171, 0.7468704879 },
{ -0.2030452490, -1.4167303145, 1.3542322516, 0.8369397521,
0.6148473620, 0.5560704172, 0.5450627208, 0.4978473186,
0.4200319052, 0.4904396236 } },
{ { 0.6088242829, 0.5965704322, 0.6547242999, 0.8554936051,
-0.2989298999, 0.2404472232, 0.3573780358, 0.7499166429,
0.7691628039, 0.6824858487 },
{ 0.2582395375, 0.2721549273, 0.3462318778, 0.4820626974,
-0.4780299664, -0.0712990463, 0.0200163722, 0.4246703684,
0.4660011530, 0.4172626734 } },
{ { 1.1749937236, 1.0773090720, 1.0566782951, 1.0249013603,
0.9947167337, 0.9626628757, 0.9562244117, 0.9072782397,
0.7654243410, 0.6448935270 },
{ 1.1595552564, 0.9340013266, 0.3959395885, 0.3693549633,
0.3915780485, 0.3104395568, 0.3499011099, 0.2236933708,
0.1638087332, 0.1811856627 } },
{ { 0.9572628736, 0.9389859438, 0.6619243026, 0.6849089265,
0.7276935577, 0.7839781940, 0.7987243533, 0.7748397291,
0.7101089358, 0.7277627885 },
{ 0.5809935033, 0.5575934947, 0.3544703424, 0.3636780381,
0.3736472726, 0.4486242235, 0.4684934616, 0.4481396079,
0.3456780314, 0.4478626847 } },
{ { 0.1259394884, 1.3096476197, 1.0794552267, 1.0009475052,
0.9061013162, 0.9216782451, 0.8954397738, 0.9160013199,
0.8575012982, 0.7479089499 },
{ -0.3689222336, 1.5293861628, 0.7323320210, 0.4102703631,
0.3825780451, 0.2828164697, 0.2644010782, 0.2455010712,
0.2482010722, 0.2335241437 } },
{ { 0.5380704105, 0.1600702703, -0.0657605827, -0.2390452623,
-0.3885837793, -0.4150299430, -0.3001760542, -0.1451683044,
0.1312010288, 0.2798395455 },
{ 0.2074933648, 0.0560163856, -0.0956682861, -0.2893068194,
-0.3889991641, -0.3918376267, -0.3550068438, -0.2649375796,
-0.0554451942, 0.1167317927 } },
{ { 0.6092396677, 0.5101011693, 0.4012011290, 0.5416011810,
0.5715781152, 0.6476627588, 0.6988243163, 0.7306012511,
0.7531704903, 0.6534781456 },
{ 0.2060395181, 0.1409625709, 0.1024702489, 0.1834010482,
0.1946856678, 0.2547779977, 0.3134857118, 0.3283011019,
0.3837549686, 0.3501780331 } },
{ { 0.4516011477, 0.5351627171, 0.8068243563, 0.7049858570,
0.7165473998, 0.6005858183, 0.4870473146, 0.2500010729,
0.3132087886, 0.4462703764 },
{ 0.1053087115, 0.1348702610, 0.4457857609, 0.3499703407,
0.3537780344, 0.2628780007, 0.1665087342, 0.0200856030,
0.0329625309, 0.1525241137 } },
{ { 0.7058166265, 0.7305320203, 1.1684860289, 1.4524707496,
1.3212091625, 1.2613245249, 1.1712552607, 1.1154552400,
1.0487167537, 0.9153782427 },
{ 0.2286087573, 0.2851703167, 1.2016475797, 1.5154707730,
1.2726091444, 1.1459167898, 0.9801090360, 0.9296397865,
0.8490551412, 0.6772243083 } },
{ { 0.6686396897, 0.5728935003, 0.4734780788, 0.6970243156,
0.5852165818, -0.0762836635, -0.2054683268, -0.1380375326,
0.1282933354, 0.3467164934 },
{ 0.2925087810, 0.2344933748, 0.1677548885, 0.2747856975,
0.2097087502, -0.2795452774, -0.3761222363, -0.3183837533,
-0.0834836662, 0.1482318044 } },
{ { 0.6559704542, 0.7737320364, 0.9867551923, 0.9912551939,
0.9508936405, 0.9114320874, 0.8336859047, 0.7905551195,
0.7672935724, 0.7532397211 },
{ 0.1843702793, 0.2565087676, 0.7571858764, 0.7545551062,
0.6793704629, 0.5981627405, 0.5078165531, 0.4282011390,
0.3948318958, 0.4502165318 } },
{ { 0.4430857599, 0.6102781296, 0.8485012949, 0.8573628366,
0.9078320861, 0.9979705811, 1.0411013663, 1.0524552166,
1.0194321275, 0.9023628533 },
{ 0.0070009828, 0.0084548295, 0.1613856554, 0.3484472632,
0.4385857582, 0.5895088911, 0.6367935240, 0.6736935377,
0.7026320100, 0.5924165845 } },
{ { 1.0532859862, 1.1059706211, 1.1311013997, 1.1250783205,
1.0425552130, 0.9993551970, 0.9673013389, 0.9386397898,
0.8836013079, 0.8336859047 },
{ 0.9791398048, 1.1481321752, 1.1275706291, 1.0082167387,
0.8809705377, 0.8031551242, 0.7287320197, 0.6496704519,
0.5211088657, 0.4734088480 } },
{ { -0.0251221061, -0.0443682671, 0.1282241046, 0.3850703537,
0.4252934456, 0.4547857642, 0.4690473080, 0.4873242378,
0.6001012027, 0.5882627368 },
{ -0.0562759638, -0.0246374905, 0.0070009828, 0.0971394777,
0.1232394874, 0.1278779507, 0.1302317977, 0.1462241113,
0.2073549032, 0.2446010709 } },
{ { 1.1749244928, 1.1155937016, 0.9236167073, 0.6288319826,
0.6515396833, 0.5391781032, 0.5398011804, 0.4997165501,
0.4066703618, 0.3998857439 },
{ 0.9403013289, 0.7346166372, 0.1841625869, 0.1319625676,
0.1395087242, 0.0857856274, 0.0952702463, 0.0860625505,
0.0829471648, 0.1132010221 } },
{ { 0.9047167003, 0.9840551913, 0.9933321178, 0.9360090196,
0.9164859354, 0.9213320911, 0.8701705337, 0.8815936148,
0.8414397538, 0.8188012838 },
{ 0.0961010158, -0.0147374868, 0.0202240646, 0.1002548635,
0.1407548785, 0.1837472022, 0.1858241260, 0.2064549029,
0.2228626013, 0.2859318554 } },
{ { 0.4034165144, 0.1918472052, 2.1959402561, 0.4763165414,
0.6577012241, 0.7036704719, 0.6626858413, 0.7650089562,
0.7702704966, 0.6543781459 },
{ 0.0940933228, -0.1222529113, 2.3491480052, 0.1385394931,
0.3052472472, 0.3665857315, 0.3350857198, 0.4722319245,
0.4313857555, 0.3846549690 } },
{ { 0.8215012848, 0.8613782227, 1.0399936736, 1.4082322717,
0.4075011313, 0.4091626704, 0.5230473280, 0.6101396680,
0.7510243356, 0.7237474024 },
{ 0.4810934663, 0.5670088828, 0.9207782447, 1.3007860780,
0.0453548431, 0.0858548582, 0.1803548932, 0.2790087759,
0.3974626660, 0.4581780732 } },
{ { 1.5921784937, 1.4987169206, 1.1321398616, 0.8235089779,
0.6888550818, 0.6621319950, 0.6192089021, 0.6533396840,
0.7196627855, 0.6549319923 },
{ 1.5911400318, 1.4768399894, 0.9358705580, 0.4674549997,
0.3522549570, 0.3144549429, 0.2985318601, 0.3559241891,
0.4061857462, 0.3958703578 } },
{ { 0.7975474298, 0.8712782264, 0.8974474669, 0.3008164763,
0.5562088788, 0.6655935347, 0.8921166956, 1.0918475389,
0.9544936419, 0.8554936051 },
{ 0.3769703507, 0.4930703938, 0.6619243026, -0.0382759571,
0.1766856611, 0.3015780151, 0.5952550471, 0.8903859258,
0.7395320237, 0.6205935180 } },
{ { 0.2206472158, 2.4467634261, 1.2920629978, 1.0239321291,
0.9014628530, 0.8552166820, 0.8219859004, 0.9005628526,
0.7614781857, 0.7763628066 },
{ -0.2722068131, 2.8967635930, 1.3039706945, 0.7695089579,
0.6132550538, 0.5701242685, 0.5737935007, 0.6533396840,
0.5422934890, 0.5150857866 } },
};
static const float wmavoice_lsp10_intercoeff_b[32][2][10] = {
{ { 0.4881048799, -0.1998192370, -0.3872502148, 0.0109423101,
0.0406953394, 0.1788437665, 0.1673750877, 0.3409781158,
0.4061202109, 0.5221177042 },
{ 0.1492218077, -0.1372330189, -0.2683691680, -0.0621950924,
-0.0624572337, -0.0068177581, -0.0076041818, 0.0680235624,
0.1055752933, 0.1199930608 } },
{ { 0.7934338748, 0.0012430847, 0.4239458144, 0.5521328747,
0.6497149467, 0.6423749924, 0.7170197070, 0.7169541717,
0.7778364718, 0.8397018015 },
{ 0.2768190503, -0.0491535664, -0.0325731337, 0.0261465013,
0.0469867289, 0.0649434030, 0.0781815350, 0.1031504869,
0.1194687784, 0.2451654971 } },
{ { 0.7212139666, 0.1658677757, 0.0101558864, 0.5636015534,
1.3175852597, 1.1911676526, 1.1266809106, 0.8230558336,
0.8604109585, 0.8094900250 },
{ 0.3658815324, 0.0816549063, -0.2092563212, 0.1946377754,
1.0856558084, 0.9491457641, 0.8461242616, 0.5193652213,
0.5975488424, 0.5293265879 } },
{ { 0.9507186115, 0.9078585207, 0.8773190677, 0.8677509129,
0.8024122119, 0.8127667904, 0.8246286809, 0.8779088855,
0.9454102516, 0.9863698184 },
{ 0.6883807778, 0.6900191605, 0.7059442401, 0.6552854478,
0.5843107104, 0.5553441048, 0.5887671113, 0.6494528055,
0.7725936472, 0.7792782485 } },
{ { 0.2399882078, 0.1938513517, 0.4441962242, 0.4475385249,
0.3055235147, 0.1745184362, 0.1174371839, 0.0679580271,
0.0782470703, 0.1695377529 },
{ 0.0170370936, 0.0253600776, 0.2072205544, 0.1907711923,
0.1096384823, 0.0327000320, -0.0134368241, -0.0461389422,
-0.0372916758, -0.0243156850 } },
{ { 0.5457104146, 0.3774812818, 0.5235594809, 0.2994287312,
0.2394639254, 0.5731041729, 0.9971176088, 1.1646913886,
0.9028123021, 0.7777709365 },
{ 0.2288472056, 0.1181580722, 0.2074171603, 0.0355180502,
-0.0024924278, 0.2596487999, 0.7474936247, 0.9103488624,
0.5927647650, 0.4772915542 } },
{ { 0.6541713476, 0.6412608922, 0.7625012100, 0.7826205492,
0.4839106202, 0.3311478198, 0.4577620327, 0.8572652638,
0.9442306161, 0.8282986581 },
{ 0.2852075696, 0.2614837885, 0.4221763611, 0.4314823747,
0.1434547007, 0.0435788929, 0.1397191882, 0.5525916219,
0.6752081811, 0.5487250388 } },
{ { 0.6742251515, 1.0610800683, 1.0500701368, 0.9570100009,
0.9325653315, 0.9243078828, 0.9148707986, 0.8317720294,
0.7696445584, 0.6784849465 },
{ 0.2283884585, 0.9739181101, 0.5336519182, 0.4974764287,
0.3998288214, 0.3674543798, 0.2719694376, 0.2608939707,
0.2087934017, 0.1675716937 } },
{ { 0.3736146986, -1.5457833707, 0.9216864705, 0.7959242165,
0.7358283401, 0.7233110964, 0.7271121442, 0.6852350831,
0.6891672015, 0.6589554250 },
{ 0.1246460676, -1.7167649865, 0.7037160397, 0.4803061783,
0.4694928527, 0.4654951990, 0.5208069980, 0.5305717587,
0.5288023055, 0.5278192759 } },
{ { 1.0116009116, 0.9882703424, 0.8393741250, 0.8889843524,
0.8934407532, 0.8906227350, 0.9222107530, 0.8973073363,
0.9257496595, 0.9306648076 },
{ 0.5097970665, -0.0106843412, 0.1419473886, 0.2804890275,
0.3719763160, 0.3694859743, 0.4640534222, 0.5034401417,
0.5592106879, 0.6652468145 } },
{ { 0.9718209803, 0.7615181804, 0.2172474563, 0.4920369983,
0.4310891628, 0.5038333535, 0.4668059051, 0.5339140594,
0.4453758597, 0.4050061107 },
{ 0.6543679535, 0.1205173433, -0.0050483048, 0.1580035388,
0.1308719218, 0.1700620353, 0.1740596890, 0.2179683447,
0.1967349052, 0.1703897119 } },
{ { 0.7663022578, 0.4025157690, 1.3811545074, 1.1642981768,
1.0709758997, 0.9812580645, 1.0092416406, 0.9089070857,
0.7776398659, 0.8189926445 },
{ 0.3471384346, 0.0602248609, 1.3968829811, 1.0841484964,
0.8940305710, 0.7313719392, 0.7345176339, 0.5304406881,
0.4076275229, 0.4535677731 } },
{ { 0.1300854981, 0.1323136985, 0.7564064264, 0.7335346043,
0.7924508452, 0.6039057672, 0.6896914840, 0.3694859743,
0.2825861573, 0.3179096878 },
{ -0.0208423138, -0.0530856848, 0.3449102342, 0.3819376826,
0.4466865659, 0.2807511687, 0.3842969537, 0.1144880950,
0.0617321730, 0.0767397583 } },
{ { 0.7559476793, 0.8462553322, 0.6452585459, 1.1308751702,
1.0606868565, 0.9498666525, 0.7425129414, 0.6221901178,
0.6574481130, 0.6976212561 },
{ 0.3420922160, 0.4310236275, 0.2800958157, 0.9317133725,
0.8210897744, 0.6144569516, 0.3227593005, 0.2464762032,
0.2769501209, 0.3521846533 } },
{ { 0.7609938979, 0.6943444908, 1.1490939856, 0.4350868165,
0.6101971567, 0.6246149242, 0.7370079756, 0.6522052884,
0.6966382265, 0.7565374970 },
{ 0.3939306438, 0.3449102342, 0.9874839187, 0.0910919905,
0.2804234922, 0.2888775468, 0.4060546756, 0.3284608722,
0.3483836055, 0.4819445610 } },
{ { 0.7828826904, 1.1833034158, 1.9916158915, 0.8667678833,
0.9218830764, 0.8856420517, 0.9373494089, 0.7415299118,
0.7450032830, 0.7074515522 },
{ 0.4685098231, 1.1713104546, 1.9853245020, 0.6206828058,
0.6664264500, 0.6033814847, 0.6089519858, 0.3784643114,
0.4212588668, 0.3441893458 } },
{ { 0.4671335816, 0.4177199602, 0.0804097354, -0.1836975515,
-0.1802241802, -0.0775958896, -0.0250365734, 0.0884050429,
0.2136430144, 0.3472039700 },
{ 0.1187478900, 0.1122598946, -0.0381436348, -0.2284581661,
-0.2302276194, -0.1738672554, -0.1350048184, -0.0547896028,
0.0000634491, 0.0545888245 } },
{ { 0.5545576811, 0.4791920781, 0.8204999566, 0.8462553322,
0.9212277234, 0.8946203887, 0.9659883380, 0.9137566984,
0.9225384295, 0.9207034409 },
{ 0.1176993251, -0.0429277122, -0.0330318809, 0.0566859543,
0.0983008742, 0.1593797803, 0.1732077301, 0.2320584357,
0.2739354968, 0.3753186166 } },
{ { 0.7157745361, 0.6367389560, -1.2036890686, 0.7107283175,
0.6885118484, 0.7332724631, 0.7436270416, 0.7113181353,
0.5935511887, 0.6023984551 },
{ 0.3664058149, 0.3280676603, -1.3082178831, 0.3909815550,
0.3641776145, 0.3926854730, 0.3898674548, 0.4086760879,
0.3127979338, 0.3949792087 } },
{ { 1.0267395675, 1.0621941686, 1.0415505469, 0.9971176088,
0.9764739871, 0.9904330075, 0.9591071308, 0.9338760376,
0.9026156962, 0.9073997736 },
{ 0.9855833948, 1.0548542142, 0.9787021875, 0.8573307991,
0.8360973597, 0.8193203211, 0.7386463583, 0.7038471103,
0.6333966553, 0.6434235573 } },
{ { 0.6235008240, 0.7635497749, 0.8094900250, 0.7227212787,
-0.0610809922, -0.1357912421, -0.2359291911, 0.0800165236,
0.3972729445, 0.5078965425 },
{ 0.2983146310, 0.4983939230, 0.4145742655, 0.3284608722,
-0.3203386664, -0.3495018780, -0.4734291434, -0.1808139980,
0.1211071610, 0.2001427412 } },
{ { 0.8925887942, 0.8804647624, 0.6153089106, 0.6760601401,
0.7887153327, 1.0065546930, 1.0829033256, 1.0347348750,
0.9800128937, 0.9125770628 },
{ 0.5955827832, 0.6195687056, 0.2924164534, 0.3553958833,
0.5417127609, 0.8713553548, 0.9977729619, 0.8817754686,
0.7645328045, 0.6604627371 } },
{ { 1.1581378579, 1.0359145105, 0.7731179297, 0.6839243770,
0.6839899123, 0.6664264500, 0.6910677254, 0.6579068601,
0.6779606640, 0.6243527830 },
{ 1.1508634388, 0.8400294781, 0.2358594835, 0.2542749047,
0.2484422624, 0.2620736063, 0.2676441073, 0.2713796198,
0.3068997562, 0.3223005533 } },
{ { 0.1376220584, 1.2572927773, 0.8593623936, 0.6218624413,
0.5128116906, 0.5393534899, 0.4436064065, 0.4334484339,
0.4494390488, 0.4002220333 },
{ -0.1159995794, 1.2433337569, 0.4805027843, 0.2632532418,
0.1769432425, 0.1868390739, 0.1555131972, 0.1530228555,
0.1490252018, 0.1559064090 } },
{ { 0.1817273200, -0.0085216761, 0.0739872754, 0.1808098257,
0.2770811915, 0.3344901204, 0.4292541742, 0.5404020548,
0.5780193210, 0.5707449019 },
{ -0.0035409927, -0.0188107193, -0.0057691932, 0.0132360458,
0.0560961366, 0.0534747243, 0.1002013981, 0.1737320125,
0.1706518531, 0.1637706459 } },
{ { 0.9648087025, 1.0030813217, 0.9501943290, 0.8381944895,
0.7545059025, 0.7621735334, 0.7121700943, 0.7328792512,
0.7534573376, 0.7414643764 },
{ 0.1872322857, -0.0081939995, 0.0663851798, 0.0963348150,
0.0509188473, 0.0565548837, 0.0471833348, 0.0809340179,
0.1049199402, 0.1751082540 } },
{ { 0.6792713702, 0.9521603882, 0.5296542645, 0.3657504618,
0.3905883431, 0.3121425807, 0.2726903260, 0.3156159520,
0.2859284580, 0.3179096878 },
{ 0.2307477295, 0.3771536052, 0.0743804872, 0.0260154307,
0.0477731526, 0.0391880274, 0.0228042006, 0.0572757721,
0.0337485969, 0.0492149293 } },
{ { 0.8649328947, 0.9505875409, 1.0443030298, 1.1704584956,
1.2709241211, 1.3232212961, 1.2477901578, 1.1513877213,
1.0346038043, 0.9695272446 },
{ 0.4620873630, 0.5685822368, 0.8975039423, 1.0476453304,
1.2278674245, 1.2290470600, 1.1962138712, 1.0051129162,
0.8706344664, 0.7477557659 } },
{ { 0.4188340604, 0.6011532843, 0.4726385474, 0.6389671564,
0.6753392518, 0.7842589319, 0.6147846282, 0.6708828509,
0.6406055391, 0.5398777723 },
{ 0.1012499630, 0.2312064767, 0.1773364544, 0.2800302804,
0.3348177969, 0.4343003929, 0.2822584808, 0.3293128312,
0.3024433553, 0.2401848137 } },
{ { 0.5049474537, 0.7943513691, 0.9536021650, 0.9407572448,
0.9823721647, 0.9747045338, 1.0145500004, 0.9629737139,
0.9526191354, 0.9283710718 },
{ 0.0566204190, 0.0973178446, 0.5812305510, 0.5687133074,
0.6834000945, 0.6616423726, 0.7611905038, 0.6683925092,
0.6463071108, 0.6118355393 } },
{ { 0.8969141245, 0.9359731674, 0.8756151497, 0.8419300020,
0.8353109360, 0.6807131469, 0.3358008265, 0.3386188447,
0.3524467945, 0.4495045841 },
{ 0.5298508704, 0.4606455863, 0.4934132397, 0.4415748119,
0.4015327394, 0.2052544951, -0.0329663455, -0.0154684186,
0.0418094397, 0.1631152928 } },
{ { 0.6345762908, 2.5209445655, 1.0373562872, 0.9166402519,
0.8865595460, 0.8907538056, 0.8522190452, 0.7290782034,
0.7385808229, 0.6345107555 },
{ 0.2641707361, 2.5696372986, 0.8539884984, 0.6532538533,
0.6087553799, 0.5851626694, 0.5276226699, 0.4330552220,
0.3971418738, 0.3599833548 } },
};
static const float wmavoice_lsp16_intercoeff_a[32][2][16] = {
{ { 0.5337238312, 0.4810695648, -0.3766536713, -0.1204767227,
-0.0898437500, -0.0070896149, 0.1134738922, 0.1337728500,
0.3739156723, 0.3849058151, 0.4220180511, 0.5404901505,
0.5224876404, 0.5502910614, 0.5313453674, 0.4405946732 },
{ 0.1775283813, 0.1679325104, -0.2702789307, -0.1359367371,
-0.1452455521, -0.0888595581, -0.0256662369, -0.0023736954,
0.1074047089, 0.1431636810, 0.1357412338, 0.2045526505,
0.2686481476, 0.3404531479, 0.3209333420, 0.1493968964 } },
{ { 0.7402400970, 0.0838251114, 0.6486282349, 0.6145095825,
0.7331047058, 0.7183008194, 0.7436847687, 0.7627944946,
0.7653779984, 0.7795667648, 0.8399305344, 0.8393154144,
0.8219690323, 0.7474164963, 0.6681070328, 0.6490793228 },
{ 0.2850513458, -0.0544128418, -0.0300130844, 0.0204677582,
0.0328931808, 0.0589332581, 0.0796422958, 0.1187639236,
0.1320505142, 0.1539077759, 0.2189874649, 0.2865276337,
0.2973947525, 0.2614307404, 0.2416648865, 0.2428951263 } },
{ { 0.6129922867, 0.7300701141, 0.2073822021, 0.5005893707,
0.5713691711, 0.5374965668, 0.6293134689, 0.5639057159,
0.7402811050, 0.6982889175, 0.4668397903, 0.6698703766,
0.8758535385, 0.8678569794, 0.8678569794, 0.7810840607 },
{ 0.2986249924, 0.3269615173, 0.0096416473, 0.1800708771,
0.2474060059, 0.2203407288, 0.3007984161, 0.2674179077,
0.4424810410, 0.4046306610, 0.2063980103, 0.4230022430,
0.6222190857, 0.6574449539, 0.6776618958, 0.6604385376 } },
{ { 0.7258052826, 0.5073966980, -0.3947381973, 0.5254812241,
1.0561246872, 0.9706230164, 0.9727144241, 0.9185838699,
0.8184833527, 0.9093980789, 0.8645353317, 0.7870302200,
0.6347675323, 0.5123996735, 0.2846002579, 0.3252801895 },
{ 0.4306297302, 0.2182903290, -0.4902458191, 0.1783485413,
0.7783365250, 0.7152252197, 0.7404451370, 0.6012639999,
0.5421304703, 0.6619558334, 0.6316919327, 0.5596818924,
0.3952398300, 0.3567333221, 0.1505041122, 0.1290159225 } },
{ { 0.3077287674, 0.2543363571, 0.2834520340, 0.5282287598,
0.5350360870, 0.4943971634, 0.4521999359, 0.3086309433,
0.2372770309, 0.0819387436, -0.1385612488, -0.0848407745,
-0.0380916595, 0.1192150116, 0.3228197098, 0.3012905121 },
{ 0.0567188263, 0.0196886063, 0.0682420731, 0.2102527618,
0.2452325821, 0.2060699463, 0.1620273590, 0.0784120560,
0.0418329239, -0.0508041382, -0.2193880081, -0.1644783020,
-0.1361827850, -0.0307512283, 0.1486587524, 0.2356367111 } },
{ { 0.4387903214, 0.5723943710, 0.6147556305, 0.9973602295,
1.1645498276, 1.1898927689, 1.0326681137, 0.6939010620,
0.6064310074, 0.4686441422, 0.4646663666, 0.4895582199,
0.5654230118, 0.6004848480, 0.6179132462, 0.6439123154 },
{ 0.1324195862, 0.2426080704, 0.3132238388, 0.7359752655,
0.9749288559, 0.9535636902, 0.8105278015, 0.4118890762,
0.3013315201, 0.2006158829, 0.2331352234, 0.2535161972,
0.3375005722, 0.4103307724, 0.4102897644, 0.4529380798 } },
{ { 0.7335557938, 0.9203472137, 0.4852113724, 0.8646993637,
0.7304391861, 0.7503690720, 0.6289854050, 0.6900463104,
0.6421079636, 0.5184278488, 0.4444904327, 0.2660236359,
0.2143125534, 0.2406396866, 0.4836940765, 0.5597229004 },
{ 0.3689947128, 0.4967346191, 0.1176567078, 0.5127687454,
0.3235168457, 0.3426265717, 0.2417469025, 0.3310623169,
0.2629890442, 0.2130823135, 0.1329116821, 0.0468769073,
-0.0081968307, 0.0146446228, 0.2440433502, 0.3408632278 } },
{ { 0.9425325394, 0.9597969055, 0.6160678864, 0.7050962448,
0.8063859940, 0.9063224792, 0.9890356064, 1.0038805008,
1.0338163376, 0.9453620911, 0.9634056091, 0.8068370819,
0.6859455109, 0.8909034729, 0.9990415573, 1.0122871399 },
{ 0.6895952225, 0.6451835632, 0.3169965744, 0.4268569946,
0.5666122437, 0.7722673416, 0.8845882416, 0.9061584473,
0.9550399780, 0.8118810654, 0.8601064682, 0.6129922867,
0.5069866180, 0.7065315247, 0.7862920761, 0.7766551971 } },
{ { 0.5641517639, -0.0941905975, 0.0412998199, 0.1810550690,
0.3459482193, 0.4213209152, 0.4401025772, 0.5397109985,
0.5607891083, 0.6348905563, 0.6861915588, 0.7280607224,
0.7267074585, 0.6447324753, 0.5948257446, 0.5475025177 },
{ 0.1906919479, -0.0519113541, -0.0608100891, -0.0018815994,
0.0383062363, 0.0362558365, 0.0529870987, 0.0692672729,
0.0953073502, 0.1327886581, 0.1390628815, 0.1904459000,
0.2362518311, 0.2063980103, 0.2311668396, 0.2291574478 } },
{ { 0.9901428223, 0.9589767456, 0.9012374878, 0.8017930984,
0.8929538727, 0.8512077332, 0.8790111542, 0.8832759857,
0.8949632645, 0.9159183502, 0.9293279648, 0.9152622223,
0.9247350693, 0.8753614426, 0.8730239868, 0.8066730499 },
{ 0.4230432510, -0.0464572906, 0.0182533264, 0.1159753799,
0.2349395752, 0.2740612030, 0.2987070084, 0.3620643616,
0.3923282623, 0.4694643021, 0.5202322006, 0.5356512070,
0.5564012527, 0.5362663269, 0.4791831970, 0.5046901703 } },
{ { 0.9785375595, 0.8820457458, 0.3965110779, 0.4790191650,
0.3907699585, 0.4195575714, 0.2938270569, 0.4091415405,
0.3659191132, 0.4030723572, 0.4168510437, 0.5030908585,
0.5023117065, 0.5511522293, 0.5354051590, 0.5563192368 },
{ 0.6592903137, 0.2933759689, 0.0562677383, 0.1286878586,
0.0758285522, 0.1192560196, 0.0508956909, 0.1175336838,
0.0684061050, 0.0988750458, 0.0923957825, 0.1819572449,
0.1965150833, 0.2257537842, 0.3049812317, 0.2993221283 } },
{ { 0.7120265961, 0.7847747803, 0.6065950394, 0.7235908508,
0.6740531921, 0.6535081863, 0.3734235764, 0.4788551331,
0.4410867691, 0.6927528381, 1.0758495331, 1.1148891449,
1.0708875656, 0.8896322250, 0.6401805878, 0.5057153702 },
{ 0.4210338593, 0.4763126373, 0.3229017258, 0.4079113007,
0.3922462463, 0.3529195786, 0.1258993149, 0.2168960571,
0.2207508087, 0.4605655670, 0.8759355545, 0.9526205063,
0.8843832016, 0.7001342773, 0.4503545761, 0.3484086990 } },
{ { 0.5254402161, 0.5349540710, 0.7036199570, 0.6240234375,
0.6464548111, 0.7537727356, 0.8311548233, 0.7334327698,
0.3484907150, 0.1846637726, 0.0894021988, 0.3977823257,
0.7672233582, 0.9224796295, 0.8818407059, 0.7453250885 },
{ 0.2587652206, 0.2524499893, 0.4135704041, 0.3129367828,
0.3403711319, 0.4473199844, 0.5330266953, 0.4227561951,
0.1080198288, -0.0044651031, -0.0727024078, 0.1583776474,
0.5302381516, 0.7313823700, 0.6735610962, 0.5630855560 } },
{ { 0.7936325073, 0.8551034927, 0.9755849838, 0.8953323364,
0.9345769882, 0.7202281952, 0.8388233185, 0.7941656113,
0.7550849915, 0.7894906998, 0.8590402603, 0.7813711166,
0.8483371735, 0.8652324677, 0.8586711884, 0.9584846497 },
{ 0.4781579971, 0.4731960297, 0.8289403915, 0.6175031662,
0.7262973785, 0.3638277054, 0.5544328690, 0.4761896133,
0.4388723373, 0.5021476746, 0.5630445480, 0.4562187195,
0.5190429688, 0.5937595367, 0.6121721268, 0.6973457336 } },
{ { 1.0724458694, 1.0449705124, 0.8594503403, 0.7604160309,
0.7837905884, 0.8136444092, 0.7623023987, 0.6098756790,
0.6432561874, 0.6395244598, 0.6853713989, 0.7401580811,
0.7399530411, 0.7652549744, 0.7675104141, 0.7393789291 },
{ 0.9382266998, 0.8419809341, 0.3087539673, 0.3620233536,
0.3547649384, 0.4241094589, 0.2857894897, 0.2123851776,
0.2355957031, 0.2794332504, 0.3219995499, 0.3898267746,
0.3937635422, 0.4058198929, 0.4228382111, 0.4181222916 } },
{ { 1.0275421143, 1.0940570831, 1.0164289474, 0.9097671509,
0.9400720596, 0.8976287842, 0.9175586700, 0.8900833130,
0.9154262543, 0.9492578506, 1.0011329651, 1.0361537933,
1.0359487534, 0.9320344925, 0.8974237442, 0.8811845779 },
{ 1.0046186447, 1.0860195160, 0.9442958832, 0.7473344803,
0.7876043320, 0.7410602570, 0.7422084808, 0.6844692230,
0.7256412506, 0.8455486298, 0.8969316483, 0.9362173080,
0.9092340469, 0.8227071762, 0.7481546402, 0.7088689804 } },
{ { 0.2205047607, -0.0129537582, 0.0972347260, 0.1154832840,
0.0951843262, 0.1532516479, 0.1288108826, 0.1749858856,
0.1591157913, 0.2134923935, 0.2477340698, 0.2634811401,
0.3032999039, 0.3272485733, 0.3170785904, 0.3172016144 },
{ 0.0032854080, -0.0446119308, 0.0284643173, 0.0155467987,
-0.0063104630, 0.0226001740, 0.0086984634, 0.0262088776,
0.0173921585, 0.0360507965, 0.0366659164, 0.0215339661,
0.0412178040, 0.1047391891, 0.1258172989, 0.0609836578 } },
{ { 0.1495609283, 0.3275766373, 0.8598194122, 0.6847562790,
0.7550849915, 0.5662431717, 0.6930398941, 0.7526245117,
0.7300291061, 0.7284708023, 0.6608896255, 0.5224056244,
0.4273900986, 0.5757160187, 0.4625749588, 0.5123586655 },
{ -0.0352210999, -0.0428895950, 0.3110914230, 0.2699604034,
0.3307752609, 0.2059469223, 0.2332172394, 0.3204412460,
0.2846412659, 0.3354911804, 0.2448635101, 0.1514062881,
0.1062564850, 0.2613077164, 0.2123441696, 0.3000602722 } },
{ { 0.6218910217, 0.6033554077, 0.4551525116, 0.3161764145,
0.2864866257, 0.6195125580, 0.7577505112, 1.0062179565,
0.8485012054, 0.6777849197, 0.7455301285, 0.3630485535,
0.2327661514, 0.5563192368, 0.4448595047, 0.3806819916 },
{ 0.2624969482, 0.2679510117, 0.1839666367, 0.0335903168,
0.0294075012, 0.2902593613, 0.4959144592, 0.7905979156,
0.5748548508, 0.3753919601, 0.4855394363, 0.1089630127,
0.0362968445, 0.3632535934, 0.2681150436, 0.2735691071 } },
{ { 0.7064495087, 0.4431781769, 0.7628355026, 0.7271585464,
0.7812070847, 0.7806739807, 0.8909854889, 0.8958654404,
0.9126787186, 0.9038209915, 0.9246120453, 0.9624624252,
0.9732475281, 0.7420034409, 0.5060844421, 0.5189199448 },
{ 0.3457021713, -0.0149221420, 0.3174476624, 0.3580865860,
0.4243965149, 0.4275541306, 0.5887155533, 0.6478490829,
0.6320610046, 0.6627349854, 0.6868886948, 0.7396659851,
0.7551259995, 0.5275316238, 0.3075237274, 0.3806819916 } },
{ { 0.4376831055, 0.4904603958, 0.6262788773, 0.5901098251,
0.4176712036, 0.0221490860, -0.1612796783, -0.2236118317,
-0.1087894440, -0.0022506714, 0.1051902771, 0.3307752609,
0.4167690277, 0.4997692108, 0.4645843506, 0.5228567123 },
{ 0.1228237152, 0.1671123505, 0.2931299210, 0.2549924850,
0.1435737610, -0.1124801636, -0.2181987762, -0.2723293304,
-0.1573429108, -0.0837745667, -0.0325555801, 0.1024427414,
0.1938495636, 0.2825498581, 0.2247285843, 0.2879629135 } },
{ { 0.6100807190, 0.7900238037, 0.9581155777, 0.8999662399,
0.9277286530, 0.9720993042, 0.9966220856, 0.9630365372,
0.9571723938, 0.8992280960, 0.8370189667, 0.7417984009,
0.7174396515, 0.6122951508, 0.6746683121, 0.7030458450 },
{ 0.0859165192, 0.0914115906, 0.6077432632, 0.5471334457,
0.5943746567, 0.6805324554, 0.6680250168, 0.6033554077,
0.6302976608, 0.4874258041, 0.3647298813, 0.2770137787,
0.2544183731, 0.2608156204, 0.3331537247, 0.4950942993 } },
{ { 0.4051227570, 1.1022176743, 0.8262338638, 0.6573219299,
0.5948667526, 0.5426225662, 0.4987850189, 0.4370269775,
0.4421119690, 0.3837165833, 0.3728494644, 0.3706760406,
0.4169740677, 0.3559951782, 0.2994041443, 0.3896217346 },
{ 0.0716867447, 0.9253911972, 0.2780799866, 0.2460117340,
0.1675224304, 0.1527595520, 0.1278266907, 0.1226596832,
0.1165084839, 0.0982189178, 0.0952253342, 0.1113414764,
0.1498889923, 0.0940361023, 0.0802984238, 0.1560811996 } },
{ { 0.7024717331, 0.7363853455, 0.9629545212, 0.9635286331,
1.0819597244, 1.1529855728, 1.2984409332, 1.2693252563,
1.2848672867, 1.2877378464, 1.2133083344, 1.0696573257,
1.0864706039, 0.9851808548, 0.8312368393, 0.8047866821 },
{ 0.3001422882, 0.2273120880, 0.6279602051, 0.6936140060,
0.8097076416, 0.9440498352, 1.1028738022, 1.1766471863,
1.1199741364, 1.1608181000, 1.0665817261, 0.8872537613,
0.9082908630, 0.7602519989, 0.6542053223, 0.7317514420 } },
{ { 0.0643463135, -0.6808919907, 0.2889881134, 0.6142225266,
0.6356697083, 0.6825828552, 0.6259508133, 0.4945611954,
0.5866651535, 0.6357517242, 0.5208883286, 0.4207878113,
0.5125637054, 0.3758020401, 0.5424175262, 0.6172571182 },
{ -0.0636806488, -0.7585611343, 0.0850553513, 0.2996912003,
0.3620643616, 0.4444084167, 0.4597454071, 0.3120756149,
0.4016780853, 0.5026807785, 0.4111919403, 0.3183498383,
0.3666572571, 0.1829824448, 0.3269205093, 0.4095926285 } },
{ { 0.9277286530, 0.9651279449, 0.9602069855, 0.9327726364,
0.9208393097, 0.8868436813, 0.9011554718, 0.8569488525,
0.9015245438, 0.8969726562, 0.9367094040, 0.9445009232,
0.8617057800, 0.8215589523, 0.8333692551, 0.7939195633 },
{ 0.1719102859, 0.1142530441, 0.1245460510, 0.1646108627,
0.1408672333, 0.0949792862, 0.0271930695, 0.0265779495,
-0.0064334869, -0.0109033585, 0.0152187347, 0.0252656937,
0.0166950226, 0.0736141205, 0.1205682755, 0.1895437241 } },
{ { 0.5964250565, 0.6065130234, 0.7228116989, 0.7348270416,
0.0718097687, 0.2369899750, 0.2456426620, 0.4961194992,
0.6410417557, 0.6765956879, 0.6771287918, 0.7285938263,
0.6706905365, 0.5105543137, 0.5068635941, 0.5430326462 },
{ 0.2782440186, 0.2620048523, 0.4424400330, 0.4124631882,
-0.1158838272, 0.0186223984, 0.0059919357, 0.1853609085,
0.3568563461, 0.3791646957, 0.4100847244, 0.4654865265,
0.4614677429, 0.3209743500, 0.3199081421, 0.3836755753 } },
{ { 0.8051557541, 0.8506336212, 0.9544658661, 0.5584516525,
0.5874032974, 0.5727224350, 0.6177902222, 0.7659521103,
0.9526205063, 1.0424280167, 1.0705595016, 1.0042905807,
0.6005258560, 0.3886785507, 0.4739751816, 0.6542463303 },
{ 0.4775428772, 0.5541868210, 0.7128057480, 0.2146816254,
0.2502765656, 0.2488822937, 0.3009214401, 0.4667987823,
0.6929988861, 0.8599834442, 0.8784780502, 0.7463912964,
0.3217535019, 0.1274986267, 0.2767267227, 0.5119485855 } },
{ { 0.5978193283, 0.5092830658, 1.0738401413, 0.7688636780,
0.8214769363, 0.7682075500, 0.4970626831, 0.2783260345,
0.2652854919, 0.3625154495, 0.5700569153, 0.5044031143,
0.4003248215, 0.5162544250, 0.5727634430, 0.5538587570 },
{ 0.2752094269, 0.1747808456, 0.8557186127, 0.4280872345,
0.5143680573, 0.4139804840, 0.1810960770, 0.0109539032,
0.0317039490, 0.0842351913, 0.3129367828, 0.2614717484,
0.1564092636, 0.2352676392, 0.3249931335, 0.3505821228 } },
{ { 0.7093610764, 0.7587757111, 1.8517618179, 1.0092525482,
0.8078622818, 0.8792982101, 0.8210668564, 0.8600654602,
0.6913585663, 0.6436662674, 0.6216859818, 0.6123771667,
0.5940465927, 0.5910940170, 0.6505966187, 0.5801038742 },
{ 0.3370904922, 0.4681930542, 1.9236078262, 0.8053607941,
0.5321245193, 0.6342344284, 0.5054693222, 0.5788326263,
0.4400615692, 0.4086904526, 0.3924102783, 0.4220180511,
0.3835115433, 0.4230432510, 0.5190839767, 0.3990535736 } },
{ { 0.6277141571, 1.1122236252, 1.0259838104, 0.9486427307,
0.9184608459, 0.9059944153, 0.9080038071, 0.8282022476,
0.8440313339, 0.7887935638, 0.7468013763, 0.6746683121,
0.6319379807, 0.6246795654, 0.7263793945, 0.7349090576 },
{ 0.2427721024, 1.0851583481, 0.6180362701, 0.5837125778,
0.4324750900, 0.4684801102, 0.3745307922, 0.3027257919,
0.3646888733, 0.2409267426, 0.2158298492, 0.2052907944,
0.2100887299, 0.2276401520, 0.3409452438, 0.4045896530 } },
{ { 0.8391513824, 0.8713426590, 1.1366233826, 1.1440868378,
1.1443738937, 1.0877418518, 1.0516138077, 1.0099496841,
0.9216184616, 0.8990640640, 0.9001302719, 0.8993101120,
0.8055248260, 0.8150796890, 0.7272815704, 0.7196130753 },
{ 0.4634771347, 0.5807189941, 1.1287908554, 1.1066875458,
1.0765056610, 0.9287538528, 0.8956193924, 0.8026132584,
0.6725769043, 0.5856809616, 0.5527515411, 0.5183868408,
0.4529380798, 0.5074377060, 0.4632720947, 0.5554990768 } },
};
static const float wmavoice_lsp16_intercoeff_b[32][2][16] = {
{ { 0.5431776047, -0.1212130189, -0.2471650839, 0.0683670044,
0.1418520808, 0.2518971562, 0.3708084226, 0.4141484499,
0.5712364912, 0.5852659345, 0.5670641661, 0.6401320100,
0.6447737217, 0.6726239920, 0.4994724989, 0.5574678183 },
{ 0.2040718794, -0.1271064281, -0.2266163826, -0.0406349897,
-0.0145058036, 0.0283126831, 0.0851084590, 0.0913147926,
0.1307432652, 0.1926501393, 0.2310355306, 0.2828245163,
0.3171940446, 0.4424681067, 0.2960716486, 0.3510941863 } },
{ { 0.8073900938, 0.0403081179, 0.5392660499, 0.6928597689,
0.6499369740, 0.7328097820, 0.7755761147, 0.7766191959,
0.8820225596, 0.8423333168, 0.8898978233, 0.8488525748,
0.8654375672, 0.6728326082, 0.6169234514, 0.6755967736 },
{ 0.3653843999, -0.0846008658, -0.0224332213, 0.1120721102,
0.1020585299, 0.1741876006, 0.2129902244, 0.2160151601,
0.3619422317, 0.4185815454, 0.5455245376, 0.5363975763,
0.5429168344, 0.3505726457, 0.3296067119, 0.3620986938 } },
{ { 0.1843576431, 0.0179861784, 0.3122915626, 0.3600125313,
0.2466817498, 0.2172668576, 0.1975526214, 0.1177569032,
0.1196866035, 0.0849519968, 0.0962694287, 0.1591672301,
0.2300446033, 0.3082756996, 0.4047607183, 0.3925045133 },
{ -0.0275964737, -0.0794897676, 0.1168181300, 0.1591150761,
0.0915755630, 0.0460972190, 0.0562151074, 0.0084419847,
-0.0095511675, -0.0408957601, -0.0376100540, -0.0166962743,
0.0656028390, 0.1226072311, 0.2293144464, 0.2142419219 } },
{ { 0.4781936407, -1.2478972673, 0.4884679914, 0.7755239606,
0.6785174012, 0.6590117812, 0.6177057624, 0.6427918673,
0.5402048230, 0.5512614846, 0.6424267888, 0.4229103327,
0.5106334686, 0.5136062503, 0.4490395188, 0.4753251672 },
{ 0.2852236032, -1.3815159798, 0.1904075146, 0.4874770641,
0.4593138695, 0.4182686210, 0.4174863100, 0.4604612589,
0.4089330435, 0.3891666532, 0.4700576067, 0.2383370996,
0.2801646590, 0.3398289084, 0.2766703367, 0.3374298215 } },
{ { 0.5925153494, 0.3858809471, 1.0754098296, 0.5752002001,
0.5516265631, 0.4853909016, 0.4719351530, 0.5018194318,
0.3037382960, 0.5154316425, 0.8809794784, 0.7755761147,
0.5941321254, 0.3974069953, 0.5925675035, 0.6097261906 },
{ 0.3008176684, 0.0706617832, 0.8484353423, 0.2574254870,
0.2815728188, 0.1930673718, 0.2523665428, 0.2691601515,
0.1271967888, 0.2653007507, 0.6473292708, 0.5275835395,
0.3928174376, 0.2405275702, 0.4008491635, 0.4556109309 } },
{ { 0.7339050174, 0.4290645123, 0.6859754324, 0.6349166036,
0.8034263849, 0.8509387374, 0.8591269255, 1.1049811840,
1.3928194642, 1.3423343301, 1.0849018693, 0.8943830729,
0.8579795361, 0.6920774579, 0.5613272190, 0.4303162098 },
{ 0.4534726143, 0.0901674032, 0.3465046287, 0.3470261693,
0.5217422843, 0.5874564052, 0.6014336944, 0.9161834717,
1.2823571563, 1.2193550467, 0.8868207335, 0.6514494419,
0.6249030232, 0.4453887343, 0.3665317893, 0.2242033482 } },
{ { 0.4293252826, 0.3303368688, 0.6181751490, 0.9884168506,
0.9915460944, 0.7939864993, 0.3019129038, 0.2443348169,
0.4543070793, 0.5617444515, 0.4895110726, 0.6600027084,
0.6290231943, 0.5580936670, 0.5459417701, 0.4647378922 },
{ 0.1409133077, -0.0050137639, 0.2551307082, 0.6764833927,
0.7112701535, 0.4648943543, 0.0301380754, -0.0235806108,
0.1018499136, 0.2422486544, 0.2406318784, 0.4000146985,
0.3713299632, 0.3259559274, 0.3820737004, 0.2888743877 } },
{ { 0.7733334899, 0.8321111202, 1.3098945022, 1.0331128836,
1.0380675197, 0.9479974508, 0.9740223289, 0.9442945123,
0.8926619887, 0.8719046712, 0.8640815616, 0.8404036164,
0.8359183669, 0.7675965428, 0.6895219088, 0.7266034484 },
{ 0.3655408621, 0.4643206596, 1.2171645761, 0.8341451287,
0.8387868404, 0.6713201404, 0.6814901829, 0.6294404268,
0.5172048807, 0.5205948949, 0.5408828259, 0.5298783183,
0.5781729817, 0.5000983477, 0.4727174640, 0.4326109886 } },
{ { 0.8902629018, 0.4598354101, 0.6392975450, 0.4483093619,
0.6220867038, 0.6323089004, 0.7063676715, 0.3717993498,
0.6718416810, 0.7876758575, 0.2807383537, 0.3118221760,
0.6703813672, 0.7662405372, 0.7122610807, 0.7851724625 },
{ 0.6301705837, 0.1221378446, 0.3532846570, 0.1412783861,
0.3471826315, 0.3435318470, 0.4466925859, 0.1390357614,
0.4092981219, 0.5406742096, 0.0690450072, 0.0829179883,
0.4625995755, 0.5700891018, 0.5542864203, 0.6545265317 } },
{ { -0.1100520492, 0.3803526163, 0.8075987101, 0.6903563738,
0.8012359142, 0.7835035324, 0.8195941448, 0.8381088376,
0.8033220768, 0.7511680126, 0.6393496990, 0.6096218824,
0.6934856176, 0.6690253615, 0.6401841640, 0.5600233674 },
{ -0.1776958704, -0.0293175578, 0.1520742774, 0.1746048331,
0.2222214937, 0.3052507639, 0.2977927327, 0.3797789216,
0.3395681381, 0.2976884246, 0.2516885400, 0.2403711081,
0.3567789793, 0.3302847147, 0.3368039727, 0.3310148716 } },
{ { 0.5587195158, 0.4676063657, 0.1392965317, -0.0990996957,
-0.0816280842, -0.1146416068, -0.0116894841, 0.0521992445,
0.1626615524, 0.2923687100, 0.4029874802, 0.4528989196,
0.4694839120, 0.5058352947, 0.5369191170, 0.5105291605 },
{ 0.2193530202, 0.1211469173, 0.0179861784, -0.2022604346,
-0.1409794092, -0.2121175528, -0.1152674556, -0.0594626069,
-0.0122110248, 0.0274260640, 0.1414870024, 0.2044369578,
0.2167974710, 0.2615978122, 0.3348221183, 0.3707562685 } },
{ { 0.5948622823, 0.7065241337, 0.9414781928, 0.9340723157,
0.8835350275, 0.9730835557, 0.8503650427, 0.8902629018,
0.8746688366, 0.6910865307, 0.6404449344, 0.6976057887,
0.5916287303, 0.6022160053, 0.7729684114, 0.6096740365 },
{ 0.1262058616, 0.1300652623, 0.6594290137, 0.6535877585,
0.5639349222, 0.6982316375, 0.4828875065, 0.5577285886,
0.4591052532, 0.2964367270, 0.2695252299, 0.3324751854,
0.2860580683, 0.2902825475, 0.4623388052, 0.3369604349 } },
{ { 0.8821268678, 0.8539636731, 0.2898653150, 0.7478301525,
0.5109463930, 0.8577187657, 0.4884679914, 0.7846509218,
0.7684310079, 0.7032384276, 0.6691296697, 0.8593355417,
0.9383489490, 0.9808023572, 0.6804992557, 0.6403927803 },
{ 0.5590324402, 0.4209806323, 0.0259135962, 0.4318808317,
0.2104346752, 0.5453680754, 0.1783599257, 0.4467447400,
0.4352708459, 0.4089330435, 0.3994410038, 0.5984609127,
0.6872792840, 0.7321317792, 0.4408513308, 0.4542027712 } },
{ { 0.6371070743, 0.6311093569, 0.7152860165, 0.6929640770,
0.2292101383, 0.3234525323, 0.9644259810, 0.9881039262,
0.8722697496, 0.4370440841, 0.4051779509, 0.4944135547,
0.5392660499, 0.5969484448, 0.4268740416, 0.4990552664 },
{ 0.4233797193, 0.3647063971, 0.4345406890, 0.4180078506,
-0.0006328225, 0.0586141944, 0.7620160580, 0.8152132034,
0.6707985997, 0.2095480561, 0.2178405523, 0.2776612639,
0.3142212629, 0.3808741570, 0.2676998377, 0.2804775834 } },
{ { 0.4509170651, 0.9490405321, 0.8557890654, 0.8271043301,
0.6915559173, 0.7321839333, 0.6257896423, 0.6274064183,
0.5238284469, 0.5194996595, 0.4116972089, 0.3382642865,
0.3755022883, 0.4867990613, 0.5686287880, 0.5106856227 },
{ 0.0989292860, 0.6244857907, 0.4700576067, 0.3905226588,
0.2630059719, 0.3009741306, 0.2150763869, 0.2067838907,
0.1533781290, 0.1815934777, 0.1023714542, 0.0373874903,
0.0897501707, 0.1849313378, 0.2852757573, 0.2625887394 } },
{ { 0.9954054952, 0.9554033279, 0.8237664700, 0.9780903459,
0.7261862159, 0.7884581685, 0.7933084965, 0.7393290401,
0.8783196211, 1.0409359932, 1.0217954516, 0.9159227014,
0.8698185086, 0.7057939768, 0.7662926912, 0.7339571714 },
{ 0.7913266420, 0.6739278436, 0.5061482191, 0.7058982849,
0.3480692506, 0.4338105321, 0.4428853393, 0.3758152127,
0.5962182879, 0.7925261855, 0.7968549728, 0.6629754901,
0.6325175166, 0.4598354101, 0.5310778618, 0.5518873334 } },
{ { 0.4638512731, 0.0604917407, 0.1897295117, 0.3403504491,
0.4708399177, 0.5241413713, 0.6061275601, 0.6446694136,
0.7313494682, 0.7208143473, 0.6268848777, 0.6081094146,
0.4913364649, 0.3529717326, 0.4954566360, 0.5767126679 },
{ 0.1353849769, -0.0274400115, 0.0002537966, 0.0272174478,
0.0555371046, 0.0652899146, 0.1010676026, 0.1073260903,
0.1568724513, 0.2207611799, 0.1434167027, 0.2262373567,
0.1177047491, 0.0162650943, 0.2529402375, 0.4087765813 } },
{ { 0.9700064659, 0.9917025566, 0.9159227014, 0.9309430718,
0.8991290927, 0.9314124584, 0.9059612751, 0.9473194480,
0.9604622722, 0.9377752542, 0.9197821021, 0.8869771957,
0.8506779671, 0.8594920039, 0.8320589662, 0.8739908338 },
{ 0.2892394662, 0.0551198721, 0.0892807841, 0.1158793569,
0.0905846357, 0.0738953352, 0.0395258069, 0.0240360498,
0.0477139950, 0.0751470327, 0.1171310544, 0.1555164456,
0.1384620667, 0.1818542480, 0.2104868293, 0.1288135648 } },
{ { 0.4101847410, 0.3326316476, 0.4666675925, 0.5077128410,
0.5892296433, 0.4272912741, 0.0603352785, -0.8668596745,
-1.1103670001, -0.0900248885, 0.1626615524, 0.1487885714,
0.4130010605, 0.5119373202, 0.5820323825, 0.5486016273 },
{ 0.0383262634, 0.1300652623, 0.2295230627, 0.2706204653,
0.3722165823, 0.1698066592, -0.0934670568, -0.8677462935,
-1.0724509954, -0.2164463401, -0.0056917667, -0.0301520228,
0.1299088001, 0.2579991817, 0.3482257128, 0.2469425201 } },
{ { 0.6031547785, 0.5515222549, 0.4292209744, 0.5027582049,
0.8167778254, 1.0925685167, 0.9878953099, 0.7019345760,
0.2509583831, 0.2475162148, 0.5660732388, 0.5145971775,
0.4824181199, 0.5970005989, 0.5996604562, 0.5384315848 },
{ 0.3677313328, 0.2650399804, 0.1585935354, 0.2213348746,
0.5566333532, 0.8425940871, 0.7604514360, 0.4523773789,
0.0681062341, 0.0737388730, 0.3169854283, 0.2868403792,
0.2661873698, 0.3635068536, 0.4300554395, 0.3743027449 } },
{ { 0.5017672777, 0.6634970307, 0.6869142056, 0.7066284418,
0.5669598579, 0.0621085167, 0.0634645224, 0.2321307659,
0.8322675824, 0.9855483770, 0.8296598792, 0.6140028238,
0.5462546945, 0.6730412245, 0.6856103539, 0.5975221395 },
{ 0.2680649161, 0.3324230313, 0.3688787222, 0.3886451125,
0.2774004936, -0.1695076823, -0.1353467703, 0.0159000158,
0.5895425677, 0.7586781979, 0.5639870763, 0.3687744141,
0.3401418328, 0.4477356672, 0.4782979488, 0.4034568667 } },
{ { 0.8838479519, 0.9025712609, 0.7326533198, 0.8124490380,
0.8956347704, 1.1007045507, 1.2731780410, 1.2029786706,
1.0839109421, 0.9664078355, 0.7356782556, 0.6942157745,
0.6917645335, 0.6383587718, 0.6503020525, 0.5989302993 },
{ 0.5576764345, 0.4596789479, 0.3790487647, 0.5514179468,
0.7333834767, 0.9612445831, 1.1976589561, 1.1094664335,
0.8868207335, 0.6789346337, 0.4643206596, 0.4029353261,
0.4384522438, 0.3871847987, 0.4326109886, 0.3691916466 } },
{ { 0.8520861268, 0.8413423896, 0.7238392830, 0.9103943706,
0.7072542906, 0.6479029655, 0.4557673931, 0.1908247471,
-0.0569070578, -0.1013423204, 0.2517406940, 0.4854952097,
0.5820845366, 0.5886037946, 0.6177579165, 0.6226603985 },
{ 0.6160889864, 0.4592095613, 0.4752208591, 0.6685559750,
0.4326109886, 0.4077335000, 0.2314006090, 0.0173603296,
-0.2208272815, -0.3014574647, 0.0321199298, 0.2559130192,
0.3603254557, 0.3466089368, 0.4072119594, 0.4776199460 } },
{ { 0.7083495259, 0.9001721740, 0.6795083284, 1.2743254304,
1.3672639728, 1.2563322783, 0.8557369113, 0.8287732601,
0.7942472696, 0.8006622195, 0.7034991980, 0.5479236245,
0.6391932368, 0.6248508692, 0.5495925546, 0.4719351530 },
{ 0.4000146985, 0.6493632793, 0.4583229423, 1.1484255195,
1.2521599531, 1.1232351065, 0.6150459051, 0.5347808003,
0.4726653099, 0.5269576907, 0.4278128147, 0.2745841742,
0.3868718743, 0.4183729291, 0.3474434018, 0.3150035739 } },
{ { 0.9070043564, 0.7648323774, 0.4281778932, 0.5475063920,
0.4134704471, 0.4706834555, 0.4549329281, 0.4648422003,
0.4572798610, 0.4823138118, 0.4666154385, 0.4841913581,
0.4018922448, 0.4297946692, 0.4646857381, 0.6091003418 },
{ 0.4925360084, 0.2065231204, 0.0948612690, 0.1716842055,
0.0992422104, 0.1332988143, 0.1255800128, 0.1257364750,
0.0955392718, 0.1118634939, 0.1372103691, 0.1525958180,
0.0902717113, 0.1591672301, 0.2335910797, 0.3767018318 } },
{ { 0.3185500503, 0.8677845001, 0.7776622772, 0.8160476685,
0.8624126315, 0.8057211637, 0.8852561116, 0.8471314907,
0.9145145416, 0.8945916891, 0.8638729453, 0.8531292081,
0.7425104380, 0.6215651631, 0.6501455903, 0.6341864467 },
{ -0.0499705672, 0.0687842369, 0.3051464558, 0.3368039727,
0.4942049384, 0.3823344707, 0.5683158636, 0.5044271350,
0.6278236508, 0.5777035952, 0.5745221972, 0.5502184033,
0.4244228005, 0.3163595796, 0.3525545001, 0.3582914472 } },
{ { 0.3200625181, 0.9415303469, 0.6067534089, 0.3568832874,
0.1600538492, 0.2938811779, 0.2037589550, 0.3017564416,
0.2572168708, 0.4796018004, 0.6938506961, 0.6847758889,
0.7232134342, 0.6111343503, 0.5159531832, 0.4856516719 },
{ 0.0680540800, 0.6285016537, 0.2514277697, 0.0790064335,
-0.0687981844, 0.0521992445, -0.0055874586, 0.0537117124,
0.0188206434, 0.1883213520, 0.4493002892, 0.4300554395,
0.4750122428, 0.3658016324, 0.3119786382, 0.2818335891 } },
{ { 0.6864969730, 1.0815640092, 0.9838794470, 0.8845259547,
0.9438772798, 0.8888025880, 0.8178730607, 0.8581881523,
0.7128347754, 0.7120524645, 0.7345308661, 0.7945601940,
0.7854853868, 0.8261655569, 0.6941114664, 0.6646444201 },
{ 0.2847542167, 0.9535257816, 0.6691818237, 0.5026538968,
0.5945493579, 0.4125838280, 0.3886451125, 0.3740941286,
0.2453778982, 0.2928902507, 0.3219922185, 0.4065861106,
0.3838469386, 0.4289602041, 0.3910441995, 0.3821780086 } },
{ { 1.1335094571, 1.0390062928, 0.7019867301, 0.6203134656,
0.6951545477, 0.4863818288, 0.6171320677, 0.6247465611,
0.5907421112, 0.6711115241, 0.7322882414, 0.7042293549,
0.5635698438, 0.6174449921, 0.6727283001, 0.6431047916 },
{ 1.0146503448, 0.7762541175, 0.2200310230, 0.2459515929,
0.2703596950, 0.1376276016, 0.2522100806, 0.2622758150,
0.2389107943, 0.2956544161, 0.3799875379, 0.3653843999,
0.2561216354, 0.2842326760, 0.4034568667, 0.3700782657 } },
{ { 0.6342907548, 0.9627570510, 0.5214815140, -0.0226939917,
0.5616401434, 0.7231091261, 0.7417802811, 0.9092991352,
0.9739701748, 0.7804785967, 0.6771092415, 0.6352295280,
0.4660417438, 0.5869870186, 0.6692339778, 0.5986173749 },
{ 0.3988673091, 0.6997441053, 0.2316613793, -0.2566571236,
0.2685343027, 0.4484136701, 0.4490395188, 0.6886874437,
0.7703085542, 0.5847443938, 0.4539941549, 0.4098196626,
0.2579991817, 0.3376384377, 0.4754816294, 0.5095382333 } },
{ { 0.4443456531, 2.0296727419, 0.6569256186, 0.6439914107,
0.6436263323, 0.5507399440, 0.6095175743, 0.6066491008,
0.5347808003, 0.2529402375, 0.4443978071, 0.7000570297,
0.8259569407, 0.5927761197, 0.5078171492, 0.4418422580 },
{ 0.2430831194, 1.9133691788, 0.3723730445, 0.3764410615,
0.3874977231, 0.3212099075, 0.3832210898, 0.4474227428,
0.3644977808, 0.0814055204, 0.2752621770, 0.4647378922,
0.6619845629, 0.4304205179, 0.3143777251, 0.2705683112 } },
{ { 0.9740744829, 1.0730628967, 0.9743352532, 0.9098728299,
0.9453375936, 0.9661470652, 0.9270836711, 0.9643738270,
0.9989519715, 0.9627048969, 0.9348546267, 0.9865393043,
0.9399657249, 0.9752218723, 0.8440544009, 0.8819182515 },
{ 0.9258319736, 1.0357205868, 0.8463491797, 0.8108844161,
0.8391519189, 0.8566235304, 0.8305986524, 0.8880724311,
0.9181653261, 0.8670021892, 0.8305986524, 0.8995984793,
0.8300249577, 0.8711223602, 0.7195626497, 0.8138571978 } },
};
static const double wmavoice_mean_lsf10[2][10] = {
{ 0.2235394066, 0.4097484909, 0.7025292732, 1.1077160169,
1.3939179044, 1.6741291716, 1.9552949226, 2.2199793918,
2.5103400247, 2.7829212906 },
{ 0.1493683393, 0.3714357373, 0.7702730245, 1.0609411394,
1.3270362536, 1.5806033119, 1.8398507524, 2.1116740248,
2.3823505771, 2.6865718527 }
};
static const double wmavoice_mean_lsf16[2][16] = {
{ 0.0999206754, 0.2345933590, 0.4621011210, 0.6772546160,
0.8346396060, 1.0067495130, 1.1571691668, 1.3292508688,
1.4941465650, 1.6600755584, 1.8461284908, 2.0529487333,
2.2690810112, 2.4949894820, 2.7172752965, 2.9164840903 },
{ 0.0918298402, 0.2475621892, 0.4782937721, 0.6284774045,
0.7861951264, 0.9303736000, 1.0940441024, 1.2521029300,
1.4434732098, 1.6551410742, 1.8917962963, 2.0967280403,
2.2981430375, 2.4826173497, 2.6827972461, 2.8811350800 }
};
static const float wmavoice_std_codebook[1000] = {
-0.185013, -0.150405, -0.707267, -0.284100, 0.882898,
-0.788627, 0.061005, 0.374431, 0.053843, -0.909826,
0.543602, 0.219326, 0.285698, 0.154709, -0.455005,
0.426276, -0.868852, -0.952324, -0.550001, 0.813814,
-0.352815, 0.242122, 0.820495, -0.189574, -0.449538,
0.499132, -0.247783, 0.598159, 0.732040, -0.564406,
-0.631788, -0.452973, 0.285189, -0.339055, 0.262927,
0.168087, -0.127682, -0.676067, -0.457481, 0.926161,
-0.585893, -0.913880, 0.145487, 0.699804, 0.240829,
0.690482, 0.126081, 0.371977, 0.738158, 0.576080,
0.185791, -0.614657, -0.181799, 0.006285, 0.195768,
0.368663, -0.494583, 0.947985, -0.033178, -0.762543,
-0.616421, 0.335034, -0.215516, 0.668769, 0.995979,
-0.952588, -0.163144, -0.131704, -0.628655, 0.379374,
-0.205543, -0.214549, 0.465494, 0.939944, -0.514744,
-0.293676, 0.630426, 0.611336, -0.921699, 0.368584,
0.187416, 0.264092, 0.753927, -0.994382, -0.729623,
-0.050304, 0.374280, -0.224205, -0.102319, -0.658897,
0.013252, 0.281260, 0.676137, 0.797736, -0.049971,
0.672115, 0.845148, 0.786885, -0.459588, -0.783507,
0.166259, 0.334869, 0.001944, -0.368247, 0.274813,
0.487200, 0.338077, -0.094761, 0.098536, 0.416378,
-0.726176, -0.714048, -0.319530, -0.972249, -0.708430,
-0.049153, -0.022553, 0.665850, 0.726642, 0.875127,
-0.993047, -0.260106, 0.156387, 0.683090, -0.462370,
-0.893584, 0.355205, -0.617222, 0.893301, 0.895617,
-0.400729, 0.059559, 0.230486, 0.601215, 0.691313,
-0.494701, 0.088415, 0.029390, 0.410539, -0.813049,
-0.554232, 0.684362, -0.527097, 0.126238, 0.712113,
-0.235528, -0.922915, -0.310440, -0.569678, 0.803727,
-0.435313, -0.562725, -0.456380, 0.721075, -0.879635,
0.081250, 0.827491, 0.475570, 0.464029, 0.720792,
0.371187, -0.936700, -0.219649, -0.398327, 0.664515,
-0.528336, 0.106972, -0.247070, 0.501053, -0.482490,
-0.060119, 0.946821, -0.798127, 0.412784, 0.073058,
0.913986, -0.822744, 0.150143, -0.396453, -0.392421,
-0.046130, 0.168234, 0.044854, 0.497490, -0.110691,
0.165219, -0.421259, -0.283200, -0.359212, -0.957231,
-0.562409, -0.988025, -0.893931, 0.217942, -0.386352,
0.770585, 0.689606, 0.720620, -0.476485, 0.190659,
-0.761870, 0.463395, 0.137480, -0.559997, -0.123821,
-0.789461, -0.646011, 0.053435, 0.360682, -0.042464,
0.661014, -0.685448, -0.874230, -0.294133, 0.812042,
0.015078, 0.871086, -0.609218, 0.731878, -0.488126,
-0.566448, -0.830530, -0.476150, -0.460379, 0.387412,
0.137497, -0.689794, 0.077018, -0.141883, -0.166280,
-0.732322, 0.096247, -0.702884, 0.405158, 0.536250,
0.173295, 0.615696, 0.890239, -0.773270, -0.023622,
-0.152226, 0.887744, 0.290930, -0.026456, -0.406389,
0.102972, 0.988622, -0.535303, 0.493754, 0.720500,
-0.023428, 0.927306, 0.889970, 0.500421, -0.533073,
0.277382, -0.362081, -0.222867, -0.645599, 0.496035,
0.610853, -0.377922, -0.407718, 0.907969, -0.972764,
-0.871468, 0.081264, 0.642933, -0.981230, 0.307994,
-0.380689, -0.133456, 0.195738, 0.910241, 0.840088,
0.789349, 0.013213, 0.828710, -0.745954, -0.493033,
0.549210, 0.230618, -0.565727, 0.439180, -0.268961,
-0.098800, -0.283438, 0.368958, 0.678333, 0.070963,
-0.135007, 0.289186, 0.693041, 0.457275, 0.197155,
0.720277, 0.585807, -0.721581, 0.363210, 0.604577,
0.586413, 0.982521, -0.528878, -0.217849, 0.892762,
-0.688791, -0.428500, -0.094025, -0.860081, -0.174454,
0.412942, 0.689129, -0.943836, 0.847215, 0.128309,
-0.212797, -0.251585, 0.844871, -0.843839, -0.573252,
-0.084167, 0.021154, 0.715935, -0.391126, -0.521570,
-0.086910, -0.670848, -0.935763, 0.191509, 0.692361,
0.668814, -0.222078, 0.674882, -0.860064, 0.560073,
0.567644, -0.548855, -0.868427, -0.526382, -0.408936,
-0.042881, 0.886560, -0.719807, 0.013283, 0.733775,
0.408502, 0.800487, -0.517810, 0.253372, 0.956648,
-0.091062, -0.830794, -0.022198, -0.375127, -0.221920,
0.456232, 0.537963, 0.107232, 0.520469, -0.270529,
-0.200406, 0.189284, 0.507393, -0.525524, 0.329220,
0.067466, -0.957881, 0.780365, 0.199039, -0.484262,
-0.628570, -0.843843, -0.597703, -0.348377, 0.169441,
-0.863928, -0.939875, -0.030073, -0.381738, 0.313497,
-0.073425, 0.527200, 0.482703, 0.904377, -0.847927,
-0.739217, 0.360609, 0.690035, 0.368015, -0.118921,
-0.580493, -0.832391, -0.929638, 0.926900, -0.357915,
0.399582, -0.005634, -0.315796, 0.179947, -0.806596,
0.393360, 0.732931, -0.415833, -0.724526, 0.957347,
-0.892887, 0.475366, 0.173583, -0.418554, -0.302536,
0.627315, 0.782000, 0.497542, 0.139082, 0.570111,
0.732375, -0.454643, 0.302218, -0.019505, 0.881778,
-0.057606, 0.273041, 0.414170, -0.503501, -0.079602,
-0.083941, 0.007178, -0.171925, 0.506856, 0.520953,
0.631684, -0.099784, 0.253885, -0.784149, 0.175691,
0.211231, -0.677036, -0.348943, -0.615186, -0.095591,
0.348521, -0.987871, -0.313590, -0.153938, 0.151210,
-0.743479, -0.421562, 0.696567, 0.558739, 0.558933,
0.578346, -0.498867, -0.168026, -0.007485, -0.002368,
0.752372, 0.908575, -0.995190, -0.419553, 0.415430,
0.525763, -0.787869, -0.684353, -0.220353, -0.572018,
0.491337, 0.990879, -0.249054, -0.857606, -0.624307,
0.655355, 0.490915, -0.612178, -0.658235, -0.663023,
0.539032, -0.401714, -0.084585, 0.235599, -0.842975,
-0.525653, -0.186055, -0.341841, 0.306321, 0.806460,
0.655791, 0.058693, 0.715035, 0.660601, 0.639140,
0.130465, 0.186363, 0.851271, 0.446112, 0.966011,
-0.720746, -0.062551, 0.956890, 0.030200, 0.079843,
-0.667418, -0.314445, -0.429243, -0.279596, 0.027320,
-0.092266, -0.740564, 0.625606, 0.823149, 0.495035,
0.782632, -0.702504, -0.691020, -0.559209, 0.603818,
-0.884560, -0.903419, -0.337489, 0.830475, 0.757182,
-0.698349, -0.039060, -0.056455, -0.847078, -0.592948,
-0.090444, -0.567824, 0.344501, -0.133554, 0.462375,
-0.575656, 0.199028, -0.852070, -0.004899, 0.919432,
0.175251, 0.902835, -0.821132, -0.199143, 0.725984,
0.673903, -0.416511, -0.976519, 0.982883, 0.024279,
0.627298, -0.901677, 0.120861, -0.710191, 0.928798,
-0.121958, -0.408540, -0.110261, 0.821588, -0.255618,
0.296790, -0.268856, 0.176557, -0.358709, 0.597589,
-0.361067, 0.065635, -0.203382, -0.213137, -0.939264,
-0.283951, 0.962113, 0.963571, -0.105083, -0.237030,
0.689556, -0.431180, 0.346459, 0.713037, -0.448297,
-0.629262, 0.340335, -0.349973, 0.491599, 0.630144,
-0.421175, -0.630359, -0.778396, 0.468564, -0.808771,
-0.034014, -0.234646, -0.077627, -0.857457, 0.406645,
-0.480038, -0.218524, -0.527720, 0.316580, 0.568338,
-0.466984, -0.967371, 0.530452, -0.503413, -0.072454,
-0.706578, -0.813857, 0.496366, 0.639881, 0.899179,
-0.951931, -0.989381, 0.239514, -0.301904, 0.502218,
-0.130341, 0.276921, 0.871860, 0.091262, -0.254515,
-0.936911, -0.942752, 0.510839, -0.014539, -0.800209,
-0.082516, 0.505423, -0.018733, 0.389763, -0.177997,
-0.450395, 0.922779, -0.145368, -0.919943, -0.580634,
0.782178, -0.626521, -0.394491, 0.278545, -0.986640,
-0.495312, 0.326614, -0.976021, 0.744203, -0.975290,
0.526197, -0.386139, 0.301631, 0.398057, 0.705124,
-0.952884, 0.461146, 0.762372, 0.557954, -0.553393,
0.962163, -0.524562, 0.952030, -0.056570, 0.865202,
-0.225967, 0.493035, 0.787981, 0.628665, 0.573093,
-0.792653, 0.410844, 0.946571, -0.187144, -0.310612,
0.959931, 0.317544, -0.983998, 0.983911, 0.061747,
-0.959287, 0.510108, 0.675608, 0.342344, -0.091835,
0.380731, 0.389460, -0.630689, 0.143103, -0.052586,
-0.184083, 0.105266, 0.422852, -0.232052, -0.951303,
0.288054, 0.541981, 0.541732, 0.076035, 0.170646,
0.114825, 0.283382, -0.418510, 0.061396, -0.903763,
0.270879, 0.021327, 0.413782, 0.286881, 0.005238,
-0.524472, 0.327594, -0.484654, -0.848864, -0.330063,
0.423511, 0.531868, -0.940603, 0.792822, -0.325029,
0.006811, -0.391261, 0.780237, -0.570337, 0.376687,
0.828934, 0.717717, -0.081333, 0.370666, -0.206248,
-0.910686, -0.514510, -0.922867, -0.329196, 0.546886,
-0.826629, 0.941683, -0.431786, 0.587152, 0.228564,
0.573452, -0.937320, -0.443843, -0.911202, -0.786184,
0.226094, 0.512309, 0.745684, 0.285491, 0.305131,
-0.579345, -0.707698, 0.913870, -0.799108, -0.278035,
0.290556, -0.970174, -0.560318, -0.790776, 0.400492,
0.233434, -0.701462, 0.885982, 0.310567, -0.030658,
0.432868, 0.483938, -0.088976, -0.998918, 0.071090,
-0.860412, 0.574534, 0.133770, -0.304255, 0.663332,
0.347586, 0.921839, 0.175641, 0.093270, 0.207330,
-0.519228, 0.513925, 0.499633, -0.605358, 0.714817,
-0.778402, 0.685198, 0.744643, -0.338720, 0.894422,
0.145135, 0.894714, -0.807041, 0.031117, 0.205281,
0.162301, -0.536015, -0.310781, -0.926675, -0.534932,
0.760308, -0.787088, -0.960398, -0.105922, -0.091343,
0.702934, -0.758336, -0.169504, -0.121425, 0.334935,
-0.962173, 0.359347, -0.151140, 0.537460, 0.753989,
-0.436323, 0.759058, 0.439187, -0.691680, -0.579662,
0.333608, 0.453454, -0.684948, 0.526567, -0.515429,
0.520333, -0.311132, -0.051443, -0.790448, -0.237807,
0.413625, 0.969861, -0.024895, 0.453226, -0.136061,
0.883762, 0.156160, 0.105603, -0.285741, -0.965264,
-0.559462, -0.247914, 0.394083, 0.289398, -0.710455,
0.148072, 0.853074, -0.951397, -0.412742, -0.838606,
-0.531059, 0.920866, 0.614848, -0.216007, 0.447434,
-0.900580, -0.695673, -0.863698, 0.047977, -0.486121,
-0.101505, -0.538399, -0.516261, 0.873600, 0.914828,
0.347678, 0.757362, 0.070988, -0.546718, -0.528380,
0.105724, -0.106180, 0.223706, -0.500194, -0.816782,
0.513251, 0.647878, -0.963708, 0.561854, -0.764864,
-0.802314, -0.969205, -0.843997, 0.812534, -0.185212,
0.603436, 0.911954, 0.119114, 0.739738, -0.040069,
0.632993, -0.361767, 0.421532, -0.883268, -0.488168,
0.336360, 0.464411, -0.730806, -0.592652, 0.917693,
-0.259186, 0.513071, -0.188487, 0.964520, -0.987122,
-0.005270, 0.477771, 0.660756, 0.031023, 0.039625,
0.895892, 0.228709, 0.070419, -0.948105, 0.041243,
0.885207, 0.655331, -0.046803, 0.004321, 0.395069,
0.913128, -0.362686, -0.966698, 0.334661, -0.245954,
-0.454865, -0.328980, -0.781543, -0.185671, 0.078368,
-0.863850, 0.555143, -0.408560, -0.052338, 0.519663,
-0.395683, 0.942393, -0.002565, -0.734927, -0.026585,
-0.962941, -0.839035, -0.797876, 0.107479, -0.787140,
0.243367, -0.007314, 0.868191, -0.803435, 0.997007,
0.263261, -0.890307, -0.365679, 0.296563, 0.444354,
0.388367, 0.841698, -0.884626, 0.606824, -0.343973,
0.193743, 0.742974, -0.788830, 0.785182, -0.309364,
0.730833, -0.610500, -0.366971, -0.271732, -0.345427,
0.606444, -0.234673, -0.184462, 0.808568, 0.872806,
0.028398, 0.051936, -0.134508, -0.103410, 0.248500,
-0.137501, -0.840150, 0.358194, 0.496819, 0.456413,
-0.197453, -0.114814, 0.298111, -0.082078, -0.507990,
0.954138, -0.888336, -0.765016, -0.834692, 0.896847,
-0.074380, 0.896141, -0.713654, 0.558649, -0.375591,
-0.059081, 0.165093, 0.389736, 0.756458, -0.026339,
0.262542, -0.215144, -0.974403, -0.871966, 0.681446
};
static const float wmavoice_gain_silence[256] = {
0.0000188351, 0.0000249147, 0.0000294447, 0.0000365973,
0.0000423193, 0.0000464916, 0.0000498295, 0.0000525713,
0.0000550747, 0.0000574589, 0.0000596046, 0.0000615120,
0.0000634193, 0.0000649691, 0.0000665188, 0.0000679493,
0.0000692606, 0.0000704527, 0.0000716448, 0.0000728369,
0.0000737906, 0.0000747442, 0.0000755787, 0.0000762939,
0.0000770092, 0.0000778437, 0.0000785589, 0.0000792742,
0.0000799894, 0.0000807047, 0.0000814199, 0.0000822544,
0.0000829697, 0.0000838041, 0.0000845194, 0.0000854731,
0.0000865459, 0.0000876188, 0.0000889301, 0.0000904799,
0.0000923872, 0.0000950098, 0.0000988245, 0.0001032352,
0.0001088381, 0.0001147985, 0.0001225471, 0.0001319647,
0.0001431704, 0.0001568794, 0.0001744032, 0.0001952648,
0.0002206564, 0.0002535582, 0.0002965927, 0.0003464222,
0.0004109144, 0.0004891157, 0.0005909204, 0.0007261038,
0.0008867979, 0.0010721684, 0.0012696981, 0.0015079975,
0.0017461777, 0.0019979477, 0.0022052526, 0.0023679733,
0.0025173426, 0.0026556253, 0.0027927160, 0.0029264688,
0.0030447245, 0.0031807423, 0.0033060312, 0.0034313202,
0.0035454035, 0.0036598444, 0.0037686825, 0.0038731098,
0.0039769411, 0.0040702820, 0.0041661263, 0.0042562485,
0.0043400526, 0.0044249296, 0.0045082569, 0.0045900345,
0.0046693087, 0.0047430992, 0.0048171282, 0.0048881769,
0.0049589872, 0.0050252676, 0.0050880909, 0.0051497221,
0.0052082539, 0.0052671432, 0.0053246021, 0.0053800344,
0.0054348707, 0.0054861307, 0.0055367947, 0.0055862665,
0.0056355000, 0.0056805611, 0.0057252645, 0.0057705641,
0.0058110952, 0.0058538914, 0.0058966875, 0.0059366226,
0.0059723854, 0.0060091019, 0.0060437918, 0.0060794353,
0.0061159134, 0.0061485767, 0.0061824322, 0.0062153339,
0.0062497854, 0.0062820911, 0.0063197613, 0.0063550472,
0.0063927174, 0.0064336061, 0.0064769983, 0.0065194368,
0.0065603256, 0.0066006184, 0.0066410303, 0.0066826344,
0.0067234039, 0.0067654848, 0.0068060160, 0.0068466663,
0.0068866014, 0.0069231987, 0.0069609880, 0.0069983006,
0.0070366859, 0.0070750713, 0.0071122646, 0.0071535110,
0.0071973801, 0.0072410107, 0.0072846413, 0.0073343515,
0.0073832273, 0.0074360371, 0.0074878931, 0.0075426102,
0.0076007843, 0.0076560974, 0.0077134371, 0.0077683926,
0.0078265667, 0.0078855753, 0.0079488754, 0.0080170631,
0.0080827475, 0.0081528425, 0.0082212687, 0.0082877874,
0.0083510876, 0.0084129572, 0.0084775686, 0.0085455179,
0.0086110830, 0.0086781979, 0.0087503195, 0.0088242292,
0.0089002848, 0.0089734793, 0.0090423822, 0.0091133118,
0.0091816187, 0.0092473030, 0.0093164444, 0.0093911886,
0.0094678402, 0.0095427036, 0.0096175671, 0.0096931458,
0.0097666979, 0.0098397732, 0.0099166632, 0.0099946260,
0.0100749731, 0.0101612806, 0.0102528334, 0.0103493929,
0.0104434490, 0.0105448961, 0.0106583834, 0.0107737780,
0.0108981133, 0.0110142231, 0.0111318827, 0.0112472773,
0.0113576651, 0.0114786625, 0.0116028786, 0.0117331743,
0.0118676424, 0.0120122433, 0.0121580362, 0.0123010874,
0.0124633312, 0.0126402378, 0.0128232241, 0.0130140781,
0.0132108927, 0.0134289265, 0.0136625767, 0.0138912201,
0.0141364336, 0.0144006014, 0.0146615505, 0.0149335861,
0.0152134895, 0.0155050755, 0.0158376694, 0.0162067413,
0.0165973902, 0.0169926882, 0.0174319744, 0.0179271698,
0.0184448957, 0.0190744400, 0.0197248459, 0.0204203129,
0.0212460756, 0.0221523046, 0.0231562853, 0.0243031979,
0.0256397724, 0.0271918774, 0.0289602280, 0.0310072899,
0.0333702564, 0.0363805294, 0.0401413441, 0.0443998575,
0.0498176813, 0.0562580824, 0.0640066862, 0.0732775927,
0.0836604834, 0.0962959528, 0.1122496128, 0.1335854530,
0.1608980894, 0.1990102530, 0.2616490126, 0.3926030397
};
static const float wmavoice_gain_universal[64] = {
0.0000000000, 0.0000000000, 0.0000015497, 0.0000015497,
0.0000095367, 0.0000164509, 0.0000379086, 0.0000494719,
0.0000799894, 0.0001058578, 0.0001349449, 0.0001627207,
0.0001972914, 0.0002325773, 0.0002671480, 0.0003106594,
0.0003589392, 0.0004127026, 0.0004582405, 0.0005071163,
0.0005759001, 0.0006588697, 0.0007554293, 0.0008602142,
0.0009772778, 0.0011068583, 0.0012603998, 0.0013889074,
0.0015437603, 0.0016924143, 0.0018980503, 0.0021264553,
0.0023632050, 0.0025693178, 0.0028522015, 0.0031896830,
0.0034654140, 0.0037885904, 0.0041683912, 0.0046081543,
0.0050576925, 0.0055632591, 0.0061818361, 0.0068151951,
0.0073953867, 0.0081818104, 0.0091186762, 0.0102789402,
0.0119919777, 0.0134155750, 0.0154829025, 0.0173798800,
0.0199711323, 0.0229473114, 0.0268185139, 0.0319474936,
0.0393068790, 0.0460114479, 0.0523469448, 0.0637906790,
0.0845471621, 0.1105458736, 0.1499300003, 0.2219169140
};
static const float wmavoice_gain_codebook_acb[128] = {
0.05, 0.14, 0.16, 0.05, 0.17, 0.25, 0.07, 0.21,
0.12, 0.22, 0.23, 0.13, 0.24, 0.32, 0.14, 0.29,
0.31, 0.41, 0.43, 0.32, 0.43, 0.51, 0.34, 0.48,
0.38, 0.47, 0.49, 0.38, 0.49, 0.57, 0.40, 0.54,
0.49, 0.59, 0.61, 0.50, 0.61, 0.69, 0.52, 0.66,
0.56, 0.65, 0.67, 0.56, 0.67, 0.75, 0.58, 0.72,
0.65, 0.74, 0.76, 0.65, 0.76, 0.84, 0.67, 0.81,
0.71, 0.80, 0.82, 0.71, 0.82, 0.90, 0.73, 0.87,
0.81, 0.90, 0.92, 0.81, 0.93, 1.01, 0.83, 0.97,
0.87, 0.96, 0.98, 0.87, 0.98, 1.06, 0.89, 1.03,
0.92, 1.02, 1.04, 0.93, 1.04, 1.12, 0.95, 1.09,
0.93, 1.02, 1.04, 0.93, 1.04, 1.12, 0.95, 1.09,
0.94, 1.04, 1.05, 0.10, 1.06, 1.14, 0.96, 1.11,
0.98, 1.08, 1.10, 0.99, 1.10, 1.18, 1.01, 1.15,
1.06, 1.15, 1.17, 1.06, 1.17, 1.25, 1.08, 1.22,
1.16, 1.25, 1.27, 1.16, 1.28, 1.36, 1.18, 1.32
};
static const float wmavoice_gain_codebook_fcb[128] = {
-0.8439700703 /* log(0.430) */, -0.6143360001 /* log(0.541) */,
-0.1531511795 /* log(0.858) */, -0.0998203353 /* log(0.905) */,
0.3213585988 /* log(1.379) */, 0.3777512695 /* log(1.459) */,
0.7158866675 /* log(2.046) */, 1.2700414043 /* log(3.561) */,
-1.6873994539 /* log(0.185) */, -1.2173958247 /* log(0.296) */,
-0.4893903430 /* log(0.613) */, -0.4155154440 /* log(0.660) */,
0.1257512053 /* log(1.134) */, 0.1947440768 /* log(1.215) */,
0.5883420662 /* log(1.801) */, 1.1987592373 /* log(3.316) */,
-1.3586791941 /* log(0.257) */, -0.9996723408 /* log(0.368) */,
-0.3768776513 /* log(0.686) */, -0.3119747650 /* log(0.732) */,
0.1881379421 /* log(1.207) */, 0.2523139286 /* log(1.287) */,
0.6280751838 /* log(1.874) */, 1.2202397768 /* log(3.388) */,
-0.7381445465 /* log(0.478) */, -0.5310283311 /* log(0.588) */,
-0.0987159729 /* log(0.906) */, -0.0491902442 /* log(0.952) */,
0.3555743385 /* log(1.427) */, 0.4101209196 /* log(1.507) */,
0.7390761124 /* log(2.094) */, 1.2831536022 /* log(3.608) */,
-0.2497442331 /* log(0.779) */, -0.1165338163 /* log(0.890) */,
0.1881379421 /* log(1.207) */, 0.2255406759 /* log(1.253) */,
0.5469646704 /* log(1.728) */, 0.5922212620 /* log(1.808) */,
0.8733832309 /* log(2.395) */, 1.3632815868 /* log(3.909) */,
-1.3903023825 /* log(0.249) */, -1.0216512475 /* log(0.360) */,
-0.3900840061 /* log(0.677) */, -0.3229638866 /* log(0.724) */,
0.1806534997 /* log(1.198) */, 0.2460785226 /* log(1.279) */,
0.6232610531 /* log(1.865) */, 1.2178757095 /* log(3.380) */,
-0.6033064766 /* log(0.547) */, -0.4185503477 /* log(0.658) */,
-0.0253178080 /* log(0.975) */, 0.0217614918 /* log(1.022) */,
0.4027948796 /* log(1.496) */, 0.4555243080 /* log(1.577) */,
0.7714961470 /* log(2.163) */, 1.3023691262 /* log(3.678) */,
-1.1056369036 /* log(0.331) */, -0.8164453969 /* log(0.442) */,
-0.2757535016 /* log(0.759) */, -0.2156715365 /* log(0.806) */,
0.2468600779 /* log(1.280) */, 0.3082197237 /* log(1.361) */,
0.6662897264 /* log(1.947) */, 1.2418464568 /* log(3.462) */,
-0.5395680926 /* log(0.583) */, -0.3652833185 /* log(0.694) */,
0.0109399400 /* log(1.011) */, 0.0554347069 /* log(1.057) */,
0.4265740713 /* log(1.532) */, 0.4774756441 /* log(1.612) */,
0.7880027116 /* log(2.199) */, 1.3118401752 /* log(3.713) */,
-0.9571127264 /* log(0.384) */, -0.7031975164 /* log(0.495) */,
-0.2082549388 /* log(0.812) */, -0.1519863570 /* log(0.859) */,
0.2874320412 /* log(1.333) */, 0.3464225675 /* log(1.414) */,
0.6931471806 /* log(2.000) */, 1.2570395253 /* log(3.515) */,
-0.2420715612 /* log(0.785) */, -0.1098148660 /* log(0.896) */,
0.1930966300 /* log(1.213) */, 0.2311117210 /* log(1.260) */,
0.5504308784 /* log(1.734) */, 0.5960854677 /* log(1.815) */,
0.8758853172 /* log(2.401) */, 1.3650707247 /* log(3.916) */,
0.6564831962 /* log(1.928) */, 0.7124594916 /* log(2.039) */,
0.8569652658 /* log(2.356) */, 0.8767179568 /* log(2.403) */,
1.0567480846 /* log(2.877) */, 1.0841752409 /* log(2.957) */,
1.2652560327 /* log(3.544) */, 1.6211688353 /* log(5.059) */,
-1.5417792640 /* log(0.214) */, -1.1239300967 /* log(0.325) */,
-0.4431669753 /* log(0.642) */, -5.2983173665 /* log(0.005) */,
0.1510028735 /* log(1.163) */, 0.2183319943 /* log(1.244) */,
0.6043159669 /* log(1.830) */, 1.2074666936 /* log(3.345) */,
-0.5124936809 /* log(0.599) */, -0.3424903089 /* log(0.710) */,
0.0266419309 /* log(1.027) */, 0.0713899961 /* log(1.074) */,
0.4369637752 /* log(1.548) */, 0.4879663296 /* log(1.629) */,
0.7952524035 /* log(2.215) */, 1.3164082337 /* log(3.730) */,
-0.8867319296 /* log(0.412) */, -0.6481738149 /* log(0.523) */,
-0.1743533871 /* log(0.840) */, -0.1199102967 /* log(0.887) */,
0.3089542077 /* log(1.362) */, 0.3660310389 /* log(1.442) */,
0.7075430608 /* log(2.029) */, 1.2649738259 /* log(3.543) */,
-0.0943106795 /* log(0.910) */, 0.0207825392 /* log(1.021) */,
0.2911759617 /* log(1.338) */, 0.3249778572 /* log(1.384) */,
0.6200387087 /* log(1.859) */, 0.6621723763 /* log(1.939) */,
0.9266370239 /* log(2.526) */, 1.3962446920 /* log(4.040) */
};
static const float wmavoice_ipol1_coeffs[17*9] = {
0,
0.6308171151, 0.7613050340, 0.8632577061, 0.9280143976,
0.9499985575, 0.9273047447, 0.8618999123, 0.7594153284,
-0.1791058179, -0.1351341452, -0.0589959878, 0.0472882274,
0.1784339990, 0.3262237605, 0.4801855979, 0.6285545824,
0,
-0.1921342459, -0.1786532696, -0.1341681625, -0.0575229186,
0.0492091286, 0.1806929555, 0.3286687729, 0.4826357064,
0.0807464118, 0.0506337392, 0.0080115446, -0.0428523305,
-0.0958572026, -0.1436148431, -0.1782128509, -0.1921164688,
0,
0.0960653644, 0.0803771760, 0.0500416081, 0.0072485465,
-0.0437018941, -0.0966834794, -0.1442930843, -0.1786170151,
-0.0391932014, -0.0189622506, 0.0070230183, 0.0356589290,
0.0630142610, 0.0847979258, 0.0969368290, 0.0961942221,
0,
-0.0515680681, -0.0389267015, -0.0185848991, 0.0074699190,
0.0361179407, 0.0634181346, 0.0850781347, 0.0970333587,
0.0178811825, 0.0048708571, -0.0108041526, -0.0271167825,
-0.0416534986, -0.0519338618, -0.0557823736, -0.0517020743,
0,
0.0267091128, 0.0177022810, 0.0046363524, -0.0110662053,
-0.0273700613, -0.0418578978, -0.0520511451, -0.0557823028,
-0.0069270437, 0.0008217385, 0.0097293532, 0.0185749526,
0.0259542684, 0.0304777338, 0.0309953480, 0.0268154419,
0,
-0.0125539196, -0.0068173436, 0.0009580161, 0.0098749646,
0.0187084037, 0.0260526291, 0.0305201071, 0.0309665180,
0.0019149571, -0.0022503408, -0.0068592466, -0.0112465904,
-0.0146595868, -0.0163685936, -0.0157934162, -0.0126258885,
0,
0.0050976076, 0.0018546581, -0.0023221741, -0.0069331308,
-0.0113109085, -0.0147021576, -0.0163786146, -0.0157635096,
-0.0001162733, 0.0019313511, 0.0040823850, 0.0060192454,
0.0073876535, 0.0078486321, 0.0071403184, 0.0051400312,
0,
-0.0017920607, -0.0000857157, 0.0019657183, 0.0041159806,
0.0060465694, 0.0074030068, 0.0078470460, 0.0071185785,
-0.0004100171, -0.0015364708, -0.0025490071, -0.0033188616,
-0.0037196307, -0.0036417283, -0.0030119629, -0.0018155784,
0,
0.0006907531, -0.0004282868, -0.0015539061, -0.0025635813,
-0.0033285026, -0.0037224069, -0.0036361245, -0.0029972247,
0, 0, 0, 0, 0, 0, 0, 0
};
/**
* Hamming-window sinc function (num = 32, x = [ 0, 31 ]):
* (0.54 + 0.46 * cos(2 * M_PI * x / (num - 1))) *
* sin(x * M_PI / 4) / (x * M_PI / 4)
*/
static const float wmavoice_ipol2_coeffs[32] = {
1, 0.8563459515, 0.5888634918, 0.2648358640,
0, -0.1360490318, -0.1434589471, -0.0758505310,
0, 0.0410402636, 0.0412485781, 0.0200064587,
0, -0.0081391358, -0.0068223253, -0.0029313546,
0, 0.0025864919, 0.0053062555, 0.0055688801,
0, -0.0104795941, -0.0187493577, -0.0160592399,
0, 0.0212381664, 0.0331059131, 0.0251942366,
0, -0.0273968070, -0.0392575669, -0.0276240534
};
/**
* LUT for 1.071575641632 * pow(1.0331663, n - 127)
*/
static const float wmavoice_energy_table[128] = {
0.0169982178, 0.0175619858, 0.0181444519, 0.0187462362,
0.0193679795, 0.0200103437, 0.0206740128, 0.0213596933,
0.0220681153, 0.0228000330, 0.0235562258, 0.0243374986,
0.0251446834, 0.0259786395, 0.0268402549, 0.0277304468,
0.0286501631, 0.0296003830, 0.0305821182, 0.0315964139,
0.0326443501, 0.0337270424, 0.0348456436, 0.0360013446,
0.0371953760, 0.0384290090, 0.0397035571, 0.0410203772,
0.0423808713, 0.0437864880, 0.0452387238, 0.0467391249,
0.0482892887, 0.0498908657, 0.0515455612, 0.0532551367,
0.0550214125, 0.0568462692, 0.0587316496, 0.0606795611,
0.0626920777, 0.0647713419, 0.0669195677, 0.0691390421,
0.0714321284, 0.0738012678, 0.0762489827, 0.0787778794,
0.0813906502, 0.0840900769, 0.0868790336, 0.0897604897,
0.0927375130, 0.0958132732, 0.0989910450, 0.1022742117,
0.1056662688, 0.1091708280, 0.1127916204, 0.1165325012,
0.1203974531, 0.1243905911, 0.1285161668, 0.1327785725,
0.1371823465, 0.1417321773, 0.1464329093, 0.1512895470,
0.1563072616, 0.1614913951, 0.1668474671, 0.1723811803,
0.1780984262, 0.1840052921, 0.1901080668, 0.1964132480,
0.2029275487, 0.2096579046, 0.2166114816, 0.2237956830,
0.2312181577, 0.2388868085, 0.2468098001, 0.2549955679,
0.2634528274, 0.2721905830, 0.2812181375, 0.2905451026,
0.3001814086, 0.3101373153, 0.3204234225, 0.3310506819,
0.3420304081, 0.3533742912, 0.3650944090, 0.3772032397,
0.3897136755, 0.4026390362, 0.4159930832, 0.4297900346,
0.4440445799, 0.4587718956, 0.4739876619, 0.4897080789,
0.5059498840, 0.5227303696, 0.5400674019, 0.5579794393,
0.5764855528, 0.5956054456, 0.6153594745, 0.6357686714,
0.6568547659, 0.6786402082, 0.7011481929, 0.7244026842,
0.7484284410, 0.7732510432, 0.7988969192, 0.8253933741,
0.8527686184, 0.8810517982, 0.9102730265, 0.9404634147,
0.9716551065, 1.0038813113, 1.0371763400, 1.0715756416
};
/**
* LUT for f(x,y) = pow((y + 6.9) / 64, 0.025 * (x + 1)).
*/
static const float wmavoice_denoise_power_table[12][64] = {
{ 0.9458379339, 0.9490436287, 0.9518757236, 0.9544130754,
0.9567118717, 0.9588135761, 0.9607496688, 0.9625446194,
0.9642178285, 0.9657849396, 0.9672587526, 0.9686498743,
0.9699671937, 0.9712182343, 0.9724094211, 0.9735462842,
0.9746336187, 0.9756756090, 0.9766759291, 0.9776378218,
0.9785641645, 0.9794575217, 0.9803201890, 0.9811542296,
0.9819615045, 0.9827436985, 0.9835023412, 0.9842388263,
0.9849544265, 0.9856503078, 0.9863275406, 0.9869871101,
0.9876299254, 0.9882568267, 0.9888685922, 0.9894659445,
0.9900495551, 0.9906200497, 0.9911780119, 0.9917239872,
0.9922584859, 0.9927819864, 0.9932949377, 0.9937977618,
0.9942908555, 0.9947745929, 0.9952493267, 0.9957153901,
0.9961730980, 0.9966227482, 0.9970646231, 0.9974989903,
0.9979261037, 0.9983462046, 0.9987595223, 0.9991662752,
0.9995666709, 0.9999609077, 1.0003491745, 1.0007316515,
1.0011085110, 1.0014799178, 1.0018460292, 1.0022069960 },
{ 0.8946093973, 0.9006838092, 0.9060673931, 0.9109043185,
0.9152976055, 0.9193234737, 0.9230399260, 0.9264921443,
0.9297160207, 0.9327405496, 0.9355894944, 0.9382825789,
0.9408363568, 0.9432648587, 0.9455800822, 0.9477923675,
0.9499106907, 0.9519428941, 0.9538958704, 0.9557757107,
0.9575878241, 0.9593370368, 0.9610276730, 0.9626636222,
0.9642483964, 0.9657851769, 0.9672768552, 0.9687260672,
0.9701352224, 0.9715065293, 0.9728420173, 0.9741435556,
0.9754128696, 0.9766515555, 0.9778610927, 0.9790428553,
0.9801981216, 0.9813280829, 0.9824338513, 0.9835164667,
0.9845769028, 0.9856160726, 0.9866348334, 0.9876339913,
0.9886143053, 0.9895764906, 0.9905212223, 0.9914491381,
0.9923608411, 0.9932569022, 0.9941378627, 0.9950042356,
0.9958565084, 0.9966951442, 0.9975205834, 0.9983332454,
0.9991335296, 0.9999218170, 1.0006984708, 1.0014638383,
1.0022182509, 1.0029620257, 1.0036954662, 1.0044188628 },
{ 0.8461555040, 0.8547882305, 0.8624635555, 0.8693789920,
0.8756760853, 0.8814598273, 0.8868103032, 0.8917900284,
0.8964487626, 0.9008267754, 0.9049571273, 0.9088673021,
0.9125804007, 0.9161160306, 0.9194909803, 0.9227197376,
0.9258148939, 0.9287874629, 0.9316471355, 0.9344024839,
0.9370611291, 0.9396298766, 0.9421148300, 0.9445214846,
0.9468548060, 0.9491192967, 0.9513190517, 0.9534578074,
0.9555389816, 0.9575657096, 0.9595408742, 0.9614671327,
0.9633469396, 0.9651825670, 0.9669761222, 0.9687295635,
0.9704447142, 0.9721232742, 0.9737668316, 0.9753768718,
0.9769547868, 0.9785018824, 0.9800193854, 0.9815084500,
0.9829701633, 0.9844055505, 0.9858155796, 0.9872011653,
0.9885631734, 0.9899024236, 0.9912196934, 0.9925157203,
0.9937912053, 0.9950468143, 0.9962831814, 0.9975009102,
0.9987005760, 0.9998827277, 1.0010478892, 1.0021965608,
1.0033292209, 1.0044463270, 1.0055483173, 1.0066356112 },
{ 0.8003259737, 0.8112313241, 0.8209581209, 0.8297466775,
0.8377697066, 0.8451556492, 0.8520027051, 0.8583876935,
0.8643718792, 0.8700049328, 0.8753277020, 0.8803741979,
0.8851730502, 0.8897485937, 0.8941216918, 0.8983103719,
0.9023303202, 0.9061952736, 0.9099173316, 0.9135072091,
0.9169744409, 0.9203275502, 0.9235741882, 0.9267212496,
0.9297749699, 0.9327410079, 0.9356245146, 0.9384301933,
0.9411623497, 0.9438249364, 0.9464215906, 0.9489556668,
0.9514302661, 0.9538482608, 0.9562123167, 0.9585249126,
0.9607883576, 0.9630048062, 0.9651762722, 0.9673046403,
0.9693916775, 0.9714390425, 0.9734482944, 0.9754209007,
0.9773582446, 0.9792616307, 0.9811322918, 0.9829713934,
0.9847800389, 0.9865592739, 0.9883100900, 0.9900334289,
0.9917301853, 0.9934012104, 0.9950473143, 0.9966692689,
0.9982678100, 0.9998436400, 1.0013974295, 1.0029298194,
1.0044414224, 1.0059328250, 1.0074045889, 1.0088572520 },
{ 0.7569786654, 0.7698939195, 0.7814501054, 0.7919210783,
0.8015042240, 0.8103467104, 0.8185613167, 0.8262364557,
0.8334427763, 0.8402376615, 0.8466683811, 0.8527743561,
0.8585888194, 0.8641400582, 0.8694523567, 0.8745467247,
0.8794414652, 0.8841526254, 0.8886943552, 0.8930791981,
0.8973183276, 0.9014217415, 0.9053984227, 0.9092564737,
0.9130032283, 0.9166453478, 0.9201889007, 0.9236394320,
0.9270020224, 0.9302813390, 0.9334816797, 0.9366070112,
0.9396610028, 0.9426470554, 0.9455683275, 0.9484277579,
0.9512280860, 0.9539718690, 0.9566614986, 0.9592992147,
0.9618871182, 0.9644271823, 0.9669212630, 0.9693711079,
0.9717783651, 0.9741445900, 0.9764712529, 0.9787597445,
0.9810113822, 0.9832274148, 0.9854090274, 0.9875573457,
0.9896734398, 0.9917583281, 0.9938129803, 0.9958383209,
0.9978352315, 0.9998045539, 1.0017470919, 1.0036636145,
1.0055548568, 1.0074215229, 1.0092642871, 1.0110837959 },
{ 0.7159791370, 0.7306629191, 0.7438433845, 0.7558198318,
0.7668086064, 0.7769714272, 0.7864325139, 0.7952894548,
0.8036203840, 0.8114888792, 0.8189474022, 0.8260397728,
0.8328029877, 0.8392685815, 0.8454636629, 0.8514117142,
0.8571332177, 0.8626461513, 0.8679663850, 0.8731080020,
0.8780835596, 0.8829043049, 0.8875803529, 0.8921208349,
0.8965340237, 0.9008274393, 0.9050079382, 0.9090817905,
0.9130547454, 0.9169320882, 0.9207186893, 0.9244190474,
0.9280373261, 0.9315773876, 0.9350428208, 0.9384369673,
0.9417629433, 0.9450236603, 0.9482218422, 0.9513600421,
0.9544406555, 0.9574659338, 0.9604379957, 0.9633588374,
0.9662303420, 0.9690542879, 0.9718323569, 0.9745661408,
0.9772571477, 0.9799068082, 0.9825164805, 0.9850874551,
0.9876209597, 0.9901181627, 0.9925801775, 0.9950080658,
0.9974028405, 0.9997654692, 1.0020968764, 1.0043979464,
1.0066695255, 1.0089124239, 1.0111274185, 1.0133152537 },
{ 0.6772002277, 0.6934309881, 0.7080464599, 0.7213643301,
0.7336148970, 0.7449707526, 0.7555647772, 0.7655015856,
0.7748651015, 0.7837237382, 0.7921340426, 0.8001433220,
0.8077915768, 0.8151129499, 0.8221368310, 0.8288887107,
0.8353908496, 0.8416628090, 0.8477218755, 0.8535834053,
0.8592611049, 0.8647672624, 0.8701129393, 0.8753081305,
0.8803618988, 0.8852824894, 0.8900774261, 0.8947535945,
0.8993173131, 0.9037743949, 0.9081302004, 0.9123896841,
0.9165574352, 0.9206377129, 0.9246344779, 0.9285514202,
0.9323919830, 0.9361593853, 0.9398566405, 0.9434865742,
0.9470518396, 0.9505549317, 0.9539981992, 0.9573838564,
0.9607139933, 0.9639905847, 0.9672154989, 0.9703905051,
0.9735172803, 0.9765974162, 0.9796324243, 0.9826237418,
0.9855727362, 0.9884807098, 0.9913489039, 0.9941785028,
0.9969706369, 0.9997263861, 1.0024467831, 1.0051328157,
1.0077854297, 1.0104055314, 1.0129939892, 1.0155516364 },
{ 0.6405216642, 0.6580962612, 0.6739722363, 0.6884795488,
0.7018580813, 0.7142880714, 0.7259086094, 0.7368294324,
0.7471387455, 0.7569085832, 0.7661985859, 0.7750587283,
0.7835313288, 0.7916525600, 0.7994535998, 0.8069615243,
0.8142000068, 0.8211898738, 0.8279495504, 0.8344954211,
0.8408421252, 0.8470027997, 0.8529892811, 0.8588122744,
0.8644814947, 0.8700057878, 0.8753932324, 0.8806512276,
0.8857865684, 0.8908055105, 0.8957138271, 0.9005168576,
0.9052195513, 0.9098265046, 0.9143419945, 0.9187700080,
0.9231142680, 0.9273782568, 0.9315652364, 0.9356782672,
0.9397202245, 0.9436938133, 0.9476015819, 0.9514459336,
0.9552291382, 0.9589533414, 0.9626205741, 0.9662327603,
0.9697917251, 0.9732992008, 0.9767568340, 0.9801661903,
0.9835287605, 0.9868459649, 0.9901191578, 0.9933496315,
0.9965386205, 0.9996873045, 1.0027968119, 1.0058682226,
1.0089025710, 1.0119008485, 1.0148640056, 1.0177929548 },
{ 0.6058296875, 0.6245620637, 0.6415378101, 0.6570938835,
0.6714759586, 0.6848691001, 0.6974164561, 0.7092312055,
0.7204044988, 0.7310109103, 0.7411122884, 0.7507605397,
0.7599996842, 0.7688674015, 0.7773962122, 0.7856143935,
0.7935466990, 0.8012149303, 0.8086383963, 0.8158342858,
0.8228179717, 0.8296032631, 0.8362026133, 0.8426272954,
0.8488875492, 0.8549927056, 0.8609512936, 0.8667711307,
0.8724594015, 0.8780227256, 0.8834672161, 0.8887985309,
0.8940219180, 0.8991422543, 0.9041640810, 0.9090916337,
0.9139288704, 0.9186794948, 0.9233469789, 0.9279345818,
0.9324453671, 0.9368822185, 0.9412478543, 0.9455448393,
0.9497755970, 0.9539424198, 0.9580474782, 0.9620928299,
0.9660804271, 0.9700121244, 0.9738896845, 0.9777147851,
0.9814890239, 0.9852139236, 0.9888909370, 0.9925214512,
0.9961067913, 0.9996482244, 1.0031469629, 1.0066041676,
1.0100209506, 1.0133983785, 1.0167374742, 1.0200392198 },
{ 0.5730166999, 0.5927366473, 0.6106642672, 0.6271389942,
0.6424090212, 0.6566617910, 0.6700426292, 0.6826666808,
0.6946268614, 0.7059993279, 0.7168473476, 0.7272241023,
0.7371747608, 0.7467380401, 0.7559474006, 0.7648319736,
0.7734172908, 0.7817258650, 0.7897776570, 0.7975904541,
0.8051801811, 0.8125611560, 0.8197463039, 0.8267473349,
0.8335748949, 0.8402386937, 0.8467476129, 0.8531098003,
0.8593327495, 0.8654233698, 0.8713880464, 0.8772326935,
0.8829628002, 0.8885834710, 0.8940994619, 0.8995152120,
0.9048348715, 0.9100623268, 0.9152012229, 0.9202549833,
0.9252268281, 0.9301197899, 0.9349367288, 0.9396803449,
0.9443531909, 0.9489576823, 0.9534961076, 0.9579706374,
0.9623833320, 0.9667361492, 0.9710309512, 0.9752695109,
0.9794535174, 0.9835845813, 0.9876642399, 0.9916939614,
0.9956751493, 0.9996091459, 1.0034972362, 1.0073406510,
1.0111405700, 1.0148981248, 1.0186144013, 1.0222904422 },
{ 0.5419809316, 0.5625329386, 0.5812764912, 0.5985496562,
0.6146003370, 0.6296162401, 0.6437432340, 0.6570971404,
0.6697716039, 0.6818435182, 0.6933768712, 0.7044255353,
0.7150353340, 0.7252456009, 0.7350903742, 0.7445993259,
0.7537984929, 0.7627108595, 0.7713568269, 0.7797545943,
0.7879204712, 0.7958691361, 0.8036138516, 0.8111666444,
0.8185384580, 0.8257392814, 0.8327782597, 0.8396637886,
0.8464035955, 0.8530048108, 0.8594740287, 0.8658173611,
0.8720404845, 0.8781486812, 0.8841468762, 0.8900396688,
0.8958313620, 0.9015259874, 0.9071273286, 0.9126389413,
0.9180641715, 0.9234061727, 0.9286679198, 0.9338522236,
0.9389617420, 0.9439989920, 0.9489663591, 0.9538661069,
0.9587003852, 0.9634712378, 0.9681806094, 0.9728303524,
0.9774222323, 0.9819579336, 0.9864390644, 0.9908671615,
0.9952436943, 0.9995700689, 1.0038476318, 1.0080776733,
1.0122614305, 1.0164000906, 1.0204947932, 1.0245466331 },
{ 0.5126261246, 0.5338683013, 0.5533029807, 0.5712636181,
0.5879954388, 0.6036845987, 0.6184760989, 0.6324853169,
0.6458057215, 0.6585142011, 0.6706748475, 0.6823417062,
0.6935608163, 0.7043717519, 0.7148088052, 0.7249019070,
0.7346773529, 0.7441583823, 0.7533656456, 0.7623175831,
0.7710307376, 0.7795200117, 0.7877988829, 0.7958795841,
0.8037732557, 0.8114900754, 0.8190393682, 0.8264297018,
0.8336689680, 0.8407644543, 0.8477229049, 0.8545505751,
0.8612532786, 0.8678364291, 0.8743050768, 0.8806639416,
0.8869174414, 0.8930697184, 0.8991246621, 0.9050859297,
0.9109569648, 0.9167410144, 0.9224411436, 0.9280602496,
0.9336010737, 0.9390662129, 0.9444581300, 0.9497791628,
0.9550315328, 0.9602173528, 0.9653386345, 0.9703972943,
0.9753951600, 0.9803339761, 0.9852154088, 0.9900410510,
0.9948124263, 0.9995309934, 1.0041981497, 1.0088152348,
1.0133835335, 1.0179042791, 1.0223786564, 1.0268078035 },
};
#endif /* AVCODEC_WMAVOICE_DATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/wmavoice_data.h | C | asf20 | 188,004 |
/*
* MPEG-1/2 decoder
* Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* MPEG-1/2 decoder
*/
//#define DEBUG
#include "internal.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "mpeg12.h"
#include "mpeg12data.h"
#include "mpeg12decdata.h"
#include "bytestream.h"
#include "vdpau_internal.h"
#include "xvmc_internal.h"
//#undef NDEBUG
//#include <assert.h>
#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
static inline int mpeg1_decode_block_intra(MpegEncContext *s,
DCTELEM *block,
int n);
static inline int mpeg1_decode_block_inter(MpegEncContext *s,
DCTELEM *block,
int n);
static inline int mpeg1_fast_decode_block_inter(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 inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n);
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
static void exchange_uv(MpegEncContext *s);
static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
PIX_FMT_XVMC_MPEG2_IDCT,
PIX_FMT_XVMC_MPEG2_MC,
PIX_FMT_NONE};
uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
#define INIT_2D_VLC_RL(rl, static_size)\
{\
static RL_VLC_ELEM rl_vlc_table[static_size];\
INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\
&rl.table_vlc[0][1], 4, 2,\
&rl.table_vlc[0][0], 4, 2, static_size);\
\
rl.rl_vlc[0]= rl_vlc_table;\
init_2d_vlc_rl(&rl);\
}
static void init_2d_vlc_rl(RLTable *rl)
{
int i;
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;
}
}
void ff_mpeg12_common_init(MpegEncContext *s)
{
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision];
}
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));
}
/******************************************/
/* decoding */
static VLC mv_vlc;
static VLC mbincr_vlc;
static VLC mb_ptype_vlc;
static VLC mb_btype_vlc;
static VLC mb_pat_vlc;
av_cold void ff_mpeg12_init_vlcs(void)
{
static int done = 0;
if (!done) {
done = 1;
INIT_VLC_STATIC(&dc_lum_vlc, DC_VLC_BITS, 12,
ff_mpeg12_vlc_dc_lum_bits, 1, 1,
ff_mpeg12_vlc_dc_lum_code, 2, 2, 512);
INIT_VLC_STATIC(&dc_chroma_vlc, DC_VLC_BITS, 12,
ff_mpeg12_vlc_dc_chroma_bits, 1, 1,
ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514);
INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17,
&ff_mpeg12_mbMotionVectorTable[0][1], 2, 1,
&ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518);
INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36,
&ff_mpeg12_mbAddrIncrTable[0][1], 2, 1,
&ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538);
INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64,
&ff_mpeg12_mbPatTable[0][1], 2, 1,
&ff_mpeg12_mbPatTable[0][0], 2, 1, 512);
INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7,
&table_mb_ptype[0][1], 2, 1,
&table_mb_ptype[0][0], 2, 1, 64);
INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
&table_mb_btype[0][1], 2, 1,
&table_mb_btype[0][0], 2, 1, 64);
init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
INIT_2D_VLC_RL(ff_rl_mpeg1, 680);
INIT_2D_VLC_RL(ff_rl_mpeg2, 674);
}
}
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->q_scale_type) {
return non_linear_qscale[qscale];
} else {
return qscale << 1;
}
}
/* motion type (for MPEG-2) */
#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[12][64])
{
int i, j, k, cbp, val, mb_type, motion_type;
const int mb_block_count = 4 + (1<< s->chroma_format);
dprintf(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
assert(s->mb_skipped==0);
if (s->mb_skip_run-- != 0) {
if (s->pict_type == FF_P_TYPE) {
s->mb_skipped = 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 {
int mb_type;
if(s->mb_x)
mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1];
else
mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all
if(IS_INTRA(mb_type))
return -1;
s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]=
mb_type | 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_skipped = 1;
}
return 0;
}
switch(s->pict_type) {
default:
case FF_I_TYPE:
if (get_bits1(&s->gb) == 0) {
if (get_bits1(&s->gb) == 0){
av_log(s->avctx, AV_LOG_ERROR, "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 FF_P_TYPE:
mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
if (mb_type < 0){
av_log(s->avctx, AV_LOG_ERROR, "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 FF_B_TYPE:
mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
if (mb_type < 0){
av_log(s->avctx, AV_LOG_ERROR, "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(s->avctx, "mb_type=%x\n", mb_type);
// motion_type = 0; /* avoid warning */
if (IS_INTRA(mb_type)) {
s->dsp.clear_blocks(s->block[0]);
if(!s->chroma_y_shift){
s->dsp.clear_blocks(s->block[6]);
}
/* compute DCT type */
if (s->picture_structure == PICT_FRAME && //FIXME add an 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 1, we memcpy blocks in xvmcvideo
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){
ff_xvmc_pack_pblocks(s,-1);//inter are always full blocks
if(s->swap_uv){
exchange_uv(s);
}
}
if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
if(s->flags2 & CODEC_FLAG2_FAST){
for(i=0;i<6;i++) {
mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i);
}
}else{
for(i=0;i<mb_block_count;i++) {
if (mpeg2_decode_block_intra(s, *s->pblocks[i], i) < 0)
return -1;
}
}
} else {
for(i=0;i<6;i++) {
if (mpeg1_decode_block_intra(s, *s->pblocks[i], i) < 0)
return -1;
}
}
} else {
if (mb_type & MB_TYPE_ZERO_MV){
assert(mb_type & MB_TYPE_CBP);
s->mv_dir = MV_DIR_FORWARD;
if(s->picture_structure == PICT_FRAME){
if(!s->frame_pred_frame_dct)
s->interlaced_dct = get_bits1(&s->gb);
s->mv_type = MV_TYPE_16X16;
}else{
s->mv_type = MV_TYPE_FIELD;
mb_type |= MB_TYPE_INTERLACED;
s->field_select[0][0]= s->picture_structure - 1;
}
if (IS_QUANT(mb_type))
s->qscale = get_qscale(s);
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 additional motion vector type */
if (s->frame_pred_frame_dct)
motion_type = MT_FRAME;
else{
motion_type = get_bits(&s->gb, 2);
if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
s->interlaced_dct = get_bits1(&s->gb);
}
if (IS_QUANT(mb_type))
s->qscale = get_qscale(s);
/* motion vectors */
s->mv_dir= (mb_type>>13)&3;
dprintf(s->avctx, "motion_type=%d\n", motion_type);
switch(motion_type) {
case MT_FRAME: /* or MT_16X8 */
if (s->picture_structure == PICT_FRAME) {
mb_type |= MB_TYPE_16x16;
s->mv_type = MV_TYPE_16X16;
for(i=0;i<2;i++) {
if (USES_LIST(mb_type, i)) {
/* MT_FRAME */
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 MPEG-1 */
if (s->full_pel[i]){
s->mv[i][0][0] <<= 1;
s->mv[i][0][1] <<= 1;
}
}
}
} else {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
s->mv_type = MV_TYPE_16X8;
for(i=0;i<2;i++) {
if (USES_LIST(mb_type, i)) {
/* MT_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(i=0;i<2;i++) {
if (USES_LIST(mb_type, i)) {
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(s->avctx, "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(s->avctx, "fmy=%d\n", val);
}
}
}
} else {
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
for(i=0;i<2;i++) {
if (USES_LIST(mb_type, i)) {
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:
s->mv_type = MV_TYPE_DMV;
for(i=0;i<2;i++) {
if (USES_LIST(mb_type, i)) {
int dmx, dmy, mx, my, m;
const int my_shift= s->picture_structure == PICT_FRAME;
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] >> my_shift);
dmy = get_dmv(s);
s->last_mv[i][0][1] = my<<my_shift;
s->last_mv[i][1][1] = my<<my_shift;
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;
default:
av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
}
s->mb_intra = 0;
if (HAS_CBP(mb_type)) {
s->dsp.clear_blocks(s->block[0]);
cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
if(mb_block_count > 6){
cbp<<= mb_block_count-6;
cbp |= get_bits(&s->gb, mb_block_count-6);
s->dsp.clear_blocks(s->block[6]);
}
if (cbp <= 0){
av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
//if 1, we memcpy blocks in xvmcvideo
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){
ff_xvmc_pack_pblocks(s,cbp);
if(s->swap_uv){
exchange_uv(s);
}
}
if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
if(s->flags2 & CODEC_FLAG2_FAST){
for(i=0;i<6;i++) {
if(cbp & 32) {
mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i);
} else {
s->block_last_index[i] = -1;
}
cbp+=cbp;
}
}else{
cbp<<= 12-mb_block_count;
for(i=0;i<mb_block_count;i++) {
if ( cbp & (1<<11) ) {
if (mpeg2_decode_block_non_intra(s, *s->pblocks[i], i) < 0)
return -1;
} else {
s->block_last_index[i] = -1;
}
cbp+=cbp;
}
}
} else {
if(s->flags2 & CODEC_FLAG2_FAST){
for(i=0;i<6;i++) {
if (cbp & 32) {
mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i);
} 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, *s->pblocks[i], i) < 0)
return -1;
} else {
s->block_last_index[i] = -1;
}
cbp+=cbp;
}
}
}
}else{
for(i=0;i<12;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 H.263, 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= INT_BIT - 5 - shift;
val = (val<<l)>>l;
return val;
}
static inline int mpeg1_decode_block_intra(MpegEncContext *s,
DCTELEM *block,
int n)
{
int level, dc, diff, i, j, run;
int component;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable= s->intra_scantable.permutated;
const uint16_t *quant_matrix= s->intra_matrix;
const int qscale= s->qscale;
/* DC coefficient */
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*quant_matrix[0];
dprintf(s->avctx, "dc=%d diff=%d\n", dc, diff);
i = 0;
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
for(;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if(level == 127){
break;
} else if(level != 0) {
i += run;
j = scantable[i];
level= (level*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*qscale*quant_matrix[j])>>4;
level= (level-1)|1;
level= -level;
}else{
level= (level*qscale*quant_matrix[j])>>4;
level= (level-1)|1;
}
}
if (i > 63){
av_log(s->avctx, AV_LOG_ERROR, "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;
}
int ff_mpeg1_decode_block_intra(MpegEncContext *s,
DCTELEM *block,
int n)
{
return mpeg1_decode_block_intra(s, block, n);
}
static inline int mpeg1_decode_block_inter(MpegEncContext *s,
DCTELEM *block,
int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable= s->intra_scantable.permutated;
const uint16_t *quant_matrix= s->inter_matrix;
const int qscale= s->qscale;
{
OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
level= (3*qscale*quant_matrix[0])>>5;
level= (level-1)|1;
if(GET_CACHE(re, &s->gb)&0x40000000)
level= -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
/* now quantify & encode AC coefficients */
for(;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if(level != 0) {
i += run;
j = scantable[i];
level= ((level*2+1)*qscale*quant_matrix[j])>>5;
level= (level-1)|1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
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; SKIP_BITS(re, &s->gb, 8);
} else if (level == 0) {
level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
}
i += run;
j = scantable[i];
if(level<0){
level= -level;
level= ((level*2+1)*qscale*quant_matrix[j])>>5;
level= (level-1)|1;
level= -level;
}else{
level= ((level*2+1)*qscale*quant_matrix[j])>>5;
level= (level-1)|1;
}
}
if (i > 63){
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
block[j] = level;
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
#if MIN_CACHE_BITS >= 19
UPDATE_CACHE(re, &s->gb);
#endif
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
}
s->block_last_index[n] = i;
return 0;
}
static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable= s->intra_scantable.permutated;
const int qscale= s->qscale;
{
OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
level= (3*qscale)>>1;
level= (level-1)|1;
if(GET_CACHE(re, &s->gb)&0x40000000)
level= -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
/* now quantify & encode AC coefficients */
for(;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if(level != 0) {
i += run;
j = scantable[i];
level= ((level*2+1)*qscale)>>1;
level= (level-1)|1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
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; SKIP_BITS(re, &s->gb, 8);
} else if (level == 0) {
level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);
}
i += run;
j = scantable[i];
if(level<0){
level= -level;
level= ((level*2+1)*qscale)>>1;
level= (level-1)|1;
level= -level;
}else{
level= ((level*2+1)*qscale)>>1;
level= (level-1)|1;
}
}
block[j] = level;
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
#if MIN_CACHE_BITS >= 19
UPDATE_CACHE(re, &s->gb);
#endif
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
}
s->block_last_index[n] = i;
return 0;
}
static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
DCTELEM *block,
int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable= s->intra_scantable.permutated;
const uint16_t *quant_matrix;
const int qscale= s->qscale;
int mismatch;
mismatch = 1;
{
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 first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
level= (3*qscale*quant_matrix[0])>>5;
if(GET_CACHE(re, &s->gb)&0x40000000)
level= -level;
block[0] = level;
mismatch ^= level;
i++;
SKIP_BITS(re, &s->gb, 2);
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
/* now quantify & encode AC coefficients */
for(;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
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);
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){
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
mismatch ^= level;
block[j] = level;
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
#if MIN_CACHE_BITS >= 19
UPDATE_CACHE(re, &s->gb);
#endif
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
}
block[63] ^= (mismatch & 1);
s->block_last_index[n] = i;
return 0;
}
static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
DCTELEM *block,
int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t * const scantable= s->intra_scantable.permutated;
const int qscale= s->qscale;
OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
UPDATE_CACHE(re, &s->gb);
if (((int32_t)GET_CACHE(re, &s->gb)) < 0) {
level= (3*qscale)>>1;
if(GET_CACHE(re, &s->gb)&0x40000000)
level= -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
goto end;
}
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
/* now quantify & encode AC coefficients */
for(;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if(level != 0) {
i += run;
j = scantable[i];
level= ((level*2+1)*qscale)>>1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
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)>>1;
level= -level;
}else{
level= ((level*2+1)*qscale)>>1;
}
}
block[j] = level;
#if MIN_CACHE_BITS < 19
UPDATE_CACHE(re, &s->gb);
#endif
if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF)
break;
#if MIN_CACHE_BITS >=19
UPDATE_CACHE(re, &s->gb);
#endif
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
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 coefficient */
if (n < 4){
quant_matrix = s->intra_matrix;
component = 0;
}else{
quant_matrix = s->chroma_intra_matrix;
component = (n&1) + 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 - s->intra_dc_precision);
dprintf(s->avctx, "dc=%d\n", block[0]);
mismatch = block[0] ^ 1;
i = 0;
if (s->intra_vlc_format)
rl = &ff_rl_mpeg2;
else
rl = &ff_rl_mpeg1;
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
for(;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
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){
av_log(s->avctx, AV_LOG_ERROR, "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_fast_decode_block_intra(MpegEncContext *s,
DCTELEM *block,
int n)
{
int level, dc, diff, j, run;
int component;
RLTable *rl;
uint8_t * scantable= s->intra_scantable.permutated;
const uint16_t *quant_matrix;
const int qscale= s->qscale;
/* DC coefficient */
if (n < 4){
quant_matrix = s->intra_matrix;
component = 0;
}else{
quant_matrix = s->chroma_intra_matrix;
component = (n&1) + 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 - s->intra_dc_precision);
if (s->intra_vlc_format)
rl = &ff_rl_mpeg2;
else
rl = &ff_rl_mpeg1;
{
OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
for(;;) {
UPDATE_CACHE(re, &s->gb);
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if(level == 127){
break;
} else if(level != 0) {
scantable += run;
j = *scantable;
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);
scantable += run;
j = *scantable;
if(level<0){
level= (-level*qscale*quant_matrix[j])>>4;
level= -level;
}else{
level= (level*qscale*quant_matrix[j])>>4;
}
}
block[j] = level;
}
CLOSE_READER(re, &s->gb);
}
s->block_last_index[n] = scantable - s->intra_scantable.permutated;
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 */
AVPanScan pan_scan; /** some temporary storage for the panscan */
int slice_count;
int swap_uv;//indicate VCR2
int save_aspect_info;
int save_width, save_height, save_progressive_seq;
AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator
int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame?
} Mpeg1Context;
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
{
Mpeg1Context *s = avctx->priv_data;
MpegEncContext *s2 = &s->mpeg_enc_ctx;
int i;
/* we need some permutation to store matrices,
* until MPV_common_init() sets the real permutation. */
for(i=0;i<64;i++)
s2->dsp.idct_permutation[i]=i;
MPV_decode_defaults(s2);
s->mpeg_enc_ctx.avctx= avctx;
s->mpeg_enc_ctx.flags= avctx->flags;
s->mpeg_enc_ctx.flags2= avctx->flags2;
ff_mpeg12_common_init(&s->mpeg_enc_ctx);
ff_mpeg12_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;
avctx->color_range= AVCOL_RANGE_MPEG;
if (avctx->codec->id == CODEC_ID_MPEG1VIDEO)
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
else
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
return 0;
}
static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
const uint8_t *new_perm){
uint16_t temp_matrix[64];
int i;
memcpy(temp_matrix,matrix,64*sizeof(uint16_t));
for(i=0;i<64;i++){
matrix[new_perm[i]] = temp_matrix[old_perm[i]];
}
}
static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
if(avctx->xvmc_acceleration)
return avctx->get_format(avctx,pixfmt_xvmc_mpg2_420);
else if(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){
if(avctx->codec_id == CODEC_ID_MPEG1VIDEO)
return PIX_FMT_VDPAU_MPEG1;
else
return PIX_FMT_VDPAU_MPEG2;
}else{
if(s->chroma_format < 2)
return avctx->get_format(avctx,ff_hwaccel_pixfmt_list_420);
else if(s->chroma_format == 2)
return PIX_FMT_YUV422P;
else
return PIX_FMT_YUV444P;
}
}
/* Call this function when we know all parameters.
* It may be called in different places for MPEG-1 and MPEG-2. */
static int mpeg_decode_postinit(AVCodecContext *avctx){
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
uint8_t old_permutation[64];
if (
(s1->mpeg_enc_ctx_allocated == 0)||
avctx->coded_width != s->width ||
avctx->coded_height != s->height||
s1->save_width != s->width ||
s1->save_height != s->height ||
s1->save_aspect_info != s->aspect_ratio_info||
s1->save_progressive_seq != s->progressive_sequence ||
0)
{
if (s1->mpeg_enc_ctx_allocated) {
ParseContext pc= s->parse_context;
s->parse_context.buffer=0;
MPV_common_end(s);
s->parse_context= pc;
}
if( (s->width == 0 )||(s->height == 0))
return -2;
avcodec_set_dimensions(avctx, s->width, s->height);
avctx->bit_rate = s->bit_rate;
s1->save_aspect_info = s->aspect_ratio_info;
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
/* low_delay may be forced, in this case we will have B-frames
* that behave like P-frames. */
avctx->has_b_frames = !(s->low_delay);
assert((avctx->sub_id==1) == (avctx->codec_id==CODEC_ID_MPEG1VIDEO));
if(avctx->codec_id==CODEC_ID_MPEG1VIDEO){
//MPEG-1 fps
avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num;
avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den;
//MPEG-1 aspect
avctx->sample_aspect_ratio= av_d2q(
1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255);
avctx->ticks_per_frame=1;
}else{//MPEG-2
//MPEG-2 fps
av_reduce(
&s->avctx->time_base.den,
&s->avctx->time_base.num,
ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2,
ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den,
1<<30);
avctx->ticks_per_frame=2;
//MPEG-2 aspect
if(s->aspect_ratio_info > 1){
//we ignore the spec here as reality does not match the spec, see for example
// res_change_ffmpeg_aspect.ts and sequence-display-aspect.mpg
if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) || 1){
s->avctx->sample_aspect_ratio=
av_div_q(
ff_mpeg2_aspect[s->aspect_ratio_info],
(AVRational){s->width, s->height}
);
}else{
s->avctx->sample_aspect_ratio=
av_div_q(
ff_mpeg2_aspect[s->aspect_ratio_info],
(AVRational){s1->pan_scan.width, s1->pan_scan.height}
);
}
}else{
s->avctx->sample_aspect_ratio=
ff_mpeg2_aspect[s->aspect_ratio_info];
}
}//MPEG-2
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
//until then pix_fmt may be changed right after codec init
if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
avctx->hwaccel ||
s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
if( avctx->idct_algo == FF_IDCT_AUTO )
avctx->idct_algo = FF_IDCT_SIMPLE;
/* Quantization matrices may need reordering
* if DCT permutation is changed. */
memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t));
if (MPV_common_init(s) < 0)
return -2;
quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation);
quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation);
quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation);
quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation);
s1->mpeg_enc_ctx_allocated = 1;
}
return 0;
}
static int mpeg1_decode_picture(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
int ref, f_code, vbv_delay;
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);
if(s->pict_type == 0 || s->pict_type > 3)
return -1;
vbv_delay= get_bits(&s->gb, 16);
if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) {
s->full_pel[0] = get_bits1(&s->gb);
f_code = get_bits(&s->gb, 3);
if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT)
return -1;
s->mpeg_f_code[0][0] = f_code;
s->mpeg_f_code[0][1] = f_code;
}
if (s->pict_type == FF_B_TYPE) {
s->full_pel[1] = get_bits1(&s->gb);
f_code = get_bits(&s->gb, 3);
if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT)
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 == FF_I_TYPE;
if(avctx->debug & FF_DEBUG_PICT_INFO)
av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
s->y_dc_scale = 8;
s->c_dc_scale = 8;
return 0;
}
static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
{
MpegEncContext *s= &s1->mpeg_enc_ctx;
int horiz_size_ext, vert_size_ext;
int bit_rate_ext;
skip_bits(&s->gb, 1); /* profile and level esc*/
s->avctx->profile= get_bits(&s->gb, 3);
s->avctx->level= get_bits(&s->gb, 4);
s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
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 += (bit_rate_ext << 18) * 400;
skip_bits1(&s->gb); /* marker */
s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10;
s->low_delay = get_bits1(&s->gb);
if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1;
s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1;
dprintf(s->avctx, "sequence extension\n");
s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
s->avctx->sub_id = 2; /* indicates MPEG-2 found */
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate);
}
static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
{
MpegEncContext *s= &s1->mpeg_enc_ctx;
int color_description, w, h;
skip_bits(&s->gb, 3); /* video format */
color_description= get_bits1(&s->gb);
if(color_description){
s->avctx->color_primaries= get_bits(&s->gb, 8);
s->avctx->color_trc = get_bits(&s->gb, 8);
s->avctx->colorspace = get_bits(&s->gb, 8);
}
w= get_bits(&s->gb, 14);
skip_bits(&s->gb, 1); //marker
h= get_bits(&s->gb, 14);
skip_bits(&s->gb, 1); //marker
s1->pan_scan.width= 16*w;
s1->pan_scan.height=16*h;
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
}
static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
{
MpegEncContext *s= &s1->mpeg_enc_ctx;
int i,nofco;
nofco = 1;
if(s->progressive_sequence){
if(s->repeat_first_field){
nofco++;
if(s->top_field_first)
nofco++;
}
}else{
if(s->picture_structure == PICT_FRAME){
nofco++;
if(s->repeat_first_field)
nofco++;
}
}
for(i=0; i<nofco; i++){
s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16);
skip_bits(&s->gb, 1); //marker
s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16);
skip_bits(&s->gb, 1); //marker
}
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n",
s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
);
}
static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra){
int i;
for(i=0; i<64; i++) {
int j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
int v = get_bits(&s->gb, 8);
if(v==0){
av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n");
return -1;
}
if(intra && i==0 && v!=8){
av_log(s->avctx, AV_LOG_ERROR, "intra matrix invalid, ignoring\n");
v= 8; // needed by pink.mpg / issue1046
}
matrix0[j] = v;
if(matrix1)
matrix1[j] = v;
}
return 0;
}
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
{
dprintf(s->avctx, "matrix extension\n");
if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1);
if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0);
}
static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
{
MpegEncContext *s= &s1->mpeg_enc_ctx;
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);
if(!s->pict_type && s1->mpeg_enc_ctx_allocated){
av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code, guessing missing values\n");
if(s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1]==15){
if(s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
s->pict_type= FF_I_TYPE;
else
s->pict_type= FF_P_TYPE;
}else
s->pict_type= FF_B_TYPE;
s->current_picture.pict_type= s->pict_type;
s->current_picture.key_frame= s->pict_type == FF_I_TYPE;
}
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->progressive_sequence && !s->progressive_frame){
s->progressive_frame= 1;
av_log(s->avctx, AV_LOG_ERROR, "interlaced frame in progressive sequence, ignoring\n");
}
if(s->picture_structure==0 || (s->progressive_frame && s->picture_structure!=PICT_FRAME)){
av_log(s->avctx, AV_LOG_ERROR, "picture_structure %d invalid, ignoring\n", s->picture_structure);
s->picture_structure= PICT_FRAME;
}
if(s->progressive_sequence && !s->frame_pred_frame_dct){
av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n");
s->frame_pred_frame_dct= 1;
}
if(s->picture_structure == PICT_FRAME){
s->first_field=0;
s->v_edge_pos= 16*s->mb_height;
}else{
s->first_field ^= 1;
s->v_edge_pos= 8*s->mb_height;
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);
}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);
}
/* composite display not parsed */
dprintf(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
dprintf(s->avctx, "picture_structure=%d\n", s->picture_structure);
dprintf(s->avctx, "top field first=%d\n", s->top_field_first);
dprintf(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
dprintf(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
dprintf(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
dprintf(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
dprintf(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
dprintf(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
}
static void exchange_uv(MpegEncContext *s){
DCTELEM (*tmp)[64];
tmp = s->pblocks[4];
s->pblocks[4] = s->pblocks[5];
s->pblocks[5] = tmp;
}
static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size){
AVCodecContext *avctx= s->avctx;
Mpeg1Context *s1 = (Mpeg1Context*)s;
/* start frame decoding */
if(s->first_field || s->picture_structure==PICT_FRAME){
if(MPV_frame_start(s, avctx) < 0)
return -1;
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;
}
}
*s->current_picture_ptr->pan_scan= s1->pan_scan;
}else{ //second field
int i;
if(!s->current_picture_ptr){
av_log(s->avctx, AV_LOG_ERROR, "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];
}
}
}
if (avctx->hwaccel) {
if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0)
return -1;
}
// MPV_frame_start will call this function too,
// but we need to call it on every field
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
if(ff_xvmc_field_start(s,avctx) < 0)
return -1;
return 0;
}
#define DECODE_SLICE_ERROR -1
#define DECODE_SLICE_OK 0
/**
* decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
* @return DECODE_SLICE_ERROR if the slice is damaged<br>
* DECODE_SLICE_OK if this slice is ok<br>
*/
static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
const uint8_t **buf, int buf_size)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
AVCodecContext *avctx= s->avctx;
const int field_pic= s->picture_structure != PICT_FRAME;
const int lowres= s->avctx->lowres;
s->resync_mb_x=
s->resync_mb_y= -1;
assert(mb_y < s->mb_height);
init_get_bits(&s->gb, *buf, buf_size*8);
ff_mpeg1_clean_buffers(s);
s->interlaced_dct = 0;
s->qscale = get_qscale(s);
if(s->qscale == 0){
av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
return -1;
}
/* extra slice info */
while (get_bits1(&s->gb) != 0) {
skip_bits(&s->gb, 8);
}
s->mb_x=0;
if(mb_y==0 && s->codec_tag == AV_RL32("SLIF")){
skip_bits1(&s->gb);
}else{
for(;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "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;
}
}
}
if(s->mb_x >= (unsigned)s->mb_width){
av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
return -1;
}
if (avctx->hwaccel) {
const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */
int start_code = -1;
buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
if (buf_end < *buf + buf_size)
buf_end -= 4;
s->mb_y = mb_y;
if (avctx->hwaccel->decode_slice(avctx, buf_start, buf_end - buf_start) < 0)
return DECODE_SLICE_ERROR;
*buf = buf_end;
return DECODE_SLICE_OK;
}
s->resync_mb_x= s->mb_x;
s->resync_mb_y= s->mb_y= mb_y;
s->mb_skip_run= 0;
ff_init_block_index(s);
if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) {
if(s->avctx->debug&FF_DEBUG_PICT_INFO){
av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %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 == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")),
s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", 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" :"");
}
}
for(;;) {
//If 1, we memcpy blocks in xvmcvideo.
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1)
ff_xvmc_init_block(s);//set s->block
if(mpeg_decode_mb(s, s->block) < 0)
return -1;
if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs
const int wrap = s->b8_stride;
int xy = s->mb_x*2 + s->mb_y*2*wrap;
int b8_xy= 4*(s->mb_x + s->mb_y*s->mb_stride);
int motion_x, motion_y, dir, i;
for(i=0; i<2; i++){
for(dir=0; dir<2; dir++){
if (s->mb_intra || (dir==1 && s->pict_type != FF_B_TYPE)) {
motion_x = motion_y = 0;
}else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){
motion_x = s->mv[dir][0][0];
motion_y = s->mv[dir][0][1];
} else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ {
motion_x = s->mv[dir][i][0];
motion_y = s->mv[dir][i][1];
}
s->current_picture.motion_val[dir][xy ][0] = motion_x;
s->current_picture.motion_val[dir][xy ][1] = motion_y;
s->current_picture.motion_val[dir][xy + 1][0] = motion_x;
s->current_picture.motion_val[dir][xy + 1][1] = motion_y;
s->current_picture.ref_index [dir][b8_xy ]=
s->current_picture.ref_index [dir][b8_xy + 1]= s->field_select[dir][i];
assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1);
}
xy += wrap;
b8_xy +=2;
}
}
s->dest[0] += 16 >> lowres;
s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
MPV_decode_mb(s, s->block);
if (++s->mb_x >= s->mb_width) {
const int mb_size= 16>>s->avctx->lowres;
ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size);
s->mb_x = 0;
s->mb_y += 1<<field_pic;
if(s->mb_y >= s->mb_height){
int left= get_bits_left(&s->gb);
int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && avctx->profile==0 && avctx->level==5
&& s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0
&& s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/;
if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
|| (avctx->error_recognition >= FF_ER_AGGRESSIVE && left>8)){
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
return -1;
}else
goto eos;
}
ff_init_block_index(s);
}
/* skip mb handling */
if (s->mb_skip_run == -1) {
/* read increment again */
s->mb_skip_run = 0;
for(;;) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "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){
av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
return -1;
}
goto eos; /* end of slice */
}
/* otherwise, stuffing, nothing to do */
} else {
s->mb_skip_run += code;
break;
}
}
if(s->mb_skip_run){
int i;
if(s->pict_type == FF_I_TYPE){
av_log(s->avctx, AV_LOG_ERROR, "skipped 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<12;i++)
s->block_last_index[i] = -1;
if(s->picture_structure == PICT_FRAME)
s->mv_type = MV_TYPE_16X16;
else
s->mv_type = MV_TYPE_FIELD;
if (s->pict_type == FF_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->field_select[0][0]= (s->picture_structure - 1) & 1;
} 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];
}
}
}
}
eos: // end of slice
*buf += (get_bits_count(&s->gb)-1)/8;
//printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
return 0;
}
static int slice_decode_thread(AVCodecContext *c, void *arg){
MpegEncContext *s= *(void**)arg;
const uint8_t *buf= s->gb.buffer;
int mb_y= s->start_mb_y;
const int field_pic= s->picture_structure != PICT_FRAME;
s->error_count= (3*(s->end_mb_y - s->start_mb_y)*s->mb_width) >> field_pic;
for(;;){
uint32_t start_code;
int ret;
ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
emms_c();
//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
if(ret < 0){
if(s->resync_mb_x>=0 && s->resync_mb_y>=0)
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);
}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);
}
if(s->mb_y == s->end_mb_y)
return 0;
start_code= -1;
buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code);
mb_y= start_code - SLICE_MIN_START_CODE;
if(mb_y < 0 || mb_y >= s->end_mb_y)
return -1;
}
return 0; //not reached
}
/**
* Handles slice ends.
* @return 1 if it seems to be the last slice
*/
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;
if (s->avctx->hwaccel) {
if (s->avctx->hwaccel->end_frame(s->avctx) < 0)
av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\n");
}
if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)
ff_xvmc_field_end(s);
/* end of slice reached */
if (/*s->mb_y<<field_pic == s->mb_height &&*/ !s->first_field) {
/* end of image */
s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2;
ff_er_frame_end(s);
MPV_frame_end(s);
if (s->pict_type == FF_B_TYPE || s->low_delay) {
*pict= *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict);
} 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, pict);
}
}
return 1;
} else {
return 0;
}
}
static int mpeg1_decode_sequence(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
int width,height;
int i, v, j;
init_get_bits(&s->gb, buf, buf_size*8);
width = get_bits(&s->gb, 12);
height = get_bits(&s->gb, 12);
if (width <= 0 || height <= 0)
return -1;
s->aspect_ratio_info= get_bits(&s->gb, 4);
if (s->aspect_ratio_info == 0) {
av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
if (avctx->error_recognition >= FF_ER_COMPLIANT)
return -1;
}
s->frame_rate_index = get_bits(&s->gb, 4);
if (s->frame_rate_index == 0 || s->frame_rate_index > 13)
return -1;
s->bit_rate = get_bits(&s->gb, 18) * 400;
if (get_bits1(&s->gb) == 0) /* marker */
return -1;
s->width = width;
s->height = height;
s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16;
skip_bits(&s->gb, 1);
/* get matrix */
if (get_bits1(&s->gb)) {
load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
} else {
for(i=0;i<64;i++) {
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)) {
load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
} 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;
}
}
if(show_bits(&s->gb, 23) != 0){
av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
return -1;
}
/* we set MPEG-2 parameters so that it emulates MPEG-1 */
s->progressive_sequence = 1;
s->progressive_frame = 1;
s->picture_structure = PICT_FRAME;
s->frame_pred_frame_dct = 1;
s->chroma_format = 1;
s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO;
avctx->sub_id = 1; /* indicates MPEG-1 */
s->out_format = FMT_MPEG1;
s->swap_uv = 0;//AFAIK VCR2 does not have SEQ_HEADER
if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1;
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n",
s->avctx->rc_buffer_size, s->bit_rate);
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 MPEG-1 context decoding */
s->out_format = FMT_MPEG1;
if (s1->mpeg_enc_ctx_allocated) {
MPV_common_end(s);
}
s->width = avctx->coded_width;
s->height = avctx->coded_height;
avctx->has_b_frames= 0; //true?
s->low_delay= 1;
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU )
if( avctx->idct_algo == FF_IDCT_AUTO )
avctx->idct_algo = FF_IDCT_SIMPLE;
if (MPV_common_init(s) < 0)
return -1;
exchange_uv(s);//common init reset pblocks, so we swap them here
s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB
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->chroma_format = 1;
s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO;
avctx->sub_id = 2; /* indicates MPEG-2 */
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
return 0;
}
static void mpeg_decode_user_data(AVCodecContext *avctx,
const uint8_t *p, int buf_size)
{
const uint8_t *buf_end = p+buf_size;
/* we parse the DTG active format information */
if (buf_end - p >= 5 &&
p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
int flags = p[4];
p += 5;
if (flags & 0x80) {
/* skip event id */
p += 2;
}
if (flags & 0x40) {
if (buf_end - p < 1)
return;
avctx->dtg_active_format = p[0] & 0x0f;
}
}
}
static void mpeg_decode_gop(AVCodecContext *avctx,
const uint8_t *buf, int buf_size){
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
int drop_frame_flag;
int time_code_hours, time_code_minutes;
int time_code_seconds, time_code_pictures;
int broken_link;
init_get_bits(&s->gb, buf, buf_size*8);
drop_frame_flag = get_bits1(&s->gb);
time_code_hours=get_bits(&s->gb,5);
time_code_minutes = get_bits(&s->gb,6);
skip_bits1(&s->gb);//marker bit
time_code_seconds = get_bits(&s->gb,6);
time_code_pictures = get_bits(&s->gb,6);
s->closed_gop = get_bits1(&s->gb);
/*broken_link indicate that after editing the
reference frames of the first B-Frames after GOP I-Frame
are missing (open gop)*/
broken_link = get_bits1(&s->gb);
if(s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n",
time_code_hours, time_code_minutes, time_code_seconds,
time_code_pictures, s->closed_gop, broken_link);
}
/**
* Finds the end of the current frame in the bitstream.
* @return the position of the first byte of the next frame, or -1
*/
int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)
{
int i;
uint32_t state= pc->state;
/* EOF considered as end of frame */
if (buf_size == 0)
return 0;
/*
0 frame start -> 1/4
1 first_SEQEXT -> 0/2
2 first field start -> 3/0
3 second_SEQEXT -> 2/0
4 searching end
*/
for(i=0; i<buf_size; i++){
assert(pc->frame_start_found>=0 && pc->frame_start_found<=4);
if(pc->frame_start_found&1){
if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80)
pc->frame_start_found--;
else if(state == EXT_START_CODE+2){
if((buf[i]&3) == 3) pc->frame_start_found= 0;
else pc->frame_start_found= (pc->frame_start_found+1)&3;
}
state++;
}else{
i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1;
if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){
i++;
pc->frame_start_found=4;
}
if(state == SEQ_END_CODE){
pc->state=-1;
return i+1;
}
if(pc->frame_start_found==2 && state == SEQ_START_CODE)
pc->frame_start_found= 0;
if(pc->frame_start_found<4 && state == EXT_START_CODE)
pc->frame_start_found++;
if(pc->frame_start_found == 4 && (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;
}
}
if(pc->frame_start_found == 0 && s && state == PICTURE_START_CODE){
ff_fetch_timestamp(s, i-3, 1);
}
}
}
pc->state= state;
return END_NOT_FOUND;
}
static int decode_chunks(AVCodecContext *avctx,
AVFrame *picture, int *data_size,
const uint8_t *buf, int buf_size);
/* handle buffering and image synchronisation */
static int mpeg_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
Mpeg1Context *s = avctx->priv_data;
AVFrame *picture = data;
MpegEncContext *s2 = &s->mpeg_enc_ctx;
dprintf(avctx, "fill_buffer\n");
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
/* special case for last picture */
if (s2->low_delay==0 && s2->next_picture_ptr) {
*picture= *(AVFrame*)s2->next_picture_ptr;
s2->next_picture_ptr= NULL;
*data_size = sizeof(AVFrame);
}
return buf_size;
}
if(s2->flags&CODEC_FLAG_TRUNCATED){
int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL);
if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
return 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 == AV_RL32("VCR2"))
vcr2_init_sequence(avctx);
s->slice_count= 0;
if(avctx->extradata && !avctx->frame_number)
decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size);
return decode_chunks(avctx, picture, data_size, buf, buf_size);
}
static int decode_chunks(AVCodecContext *avctx,
AVFrame *picture, int *data_size,
const uint8_t *buf, int buf_size)
{
Mpeg1Context *s = avctx->priv_data;
MpegEncContext *s2 = &s->mpeg_enc_ctx;
const uint8_t *buf_ptr = buf;
const uint8_t *buf_end = buf + buf_size;
int ret, input_size;
int last_code= 0;
for(;;) {
/* find next start code */
uint32_t start_code = -1;
buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
if (start_code > 0x1ff){
if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
if(avctx->thread_count > 1){
int i;
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
for(i=0; i<s->slice_count; i++)
s2->error_count += s2->thread_context[i]->error_count;
}
if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)
ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count);
if (slice_end(avctx, picture)) {
if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
*data_size = sizeof(AVPicture);
}
}
s2->pict_type= 0;
return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index);
}
input_size = buf_end - buf_ptr;
if(avctx->debug & FF_DEBUG_STARTCODE){
av_log(avctx, AV_LOG_DEBUG, "%3X at %td left %d\n", start_code, buf_ptr-buf, input_size);
}
/* prepare data for next start code */
switch(start_code) {
case SEQ_START_CODE:
if(last_code == 0){
mpeg1_decode_sequence(avctx, buf_ptr,
input_size);
s->sync=1;
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code);
}
break;
case PICTURE_START_CODE:
if(last_code == 0 || last_code == SLICE_MIN_START_CODE){
if(mpeg_decode_postinit(avctx) < 0){
av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n");
return -1;
}
/* we have a complete image: we try to decompress it */
if(mpeg1_decode_picture(avctx,
buf_ptr, input_size) < 0)
s2->pict_type=0;
s2->first_slice = 1;
last_code= PICTURE_START_CODE;
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code);
}
break;
case EXT_START_CODE:
init_get_bits(&s2->gb, buf_ptr, input_size*8);
switch(get_bits(&s2->gb, 4)) {
case 0x1:
if(last_code == 0){
mpeg_decode_sequence_extension(s);
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code);
}
break;
case 0x2:
mpeg_decode_sequence_display_extension(s);
break;
case 0x3:
mpeg_decode_quant_matrix_extension(s2);
break;
case 0x7:
mpeg_decode_picture_display_extension(s);
break;
case 0x8:
if(last_code == PICTURE_START_CODE){
mpeg_decode_picture_coding_extension(s);
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring pic cod ext after %X\n", last_code);
}
break;
}
break;
case USER_START_CODE:
mpeg_decode_user_data(avctx,
buf_ptr, input_size);
break;
case GOP_START_CODE:
if(last_code == 0){
s2->first_field=0;
mpeg_decode_gop(avctx,
buf_ptr, input_size);
s->sync=1;
}else{
av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code);
}
break;
default:
if (start_code >= SLICE_MIN_START_CODE &&
start_code <= SLICE_MAX_START_CODE && last_code!=0) {
const int field_pic= s2->picture_structure != PICT_FRAME;
int mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic;
last_code= SLICE_MIN_START_CODE;
if(s2->picture_structure == PICT_BOTTOM_FIELD)
mb_y++;
if (mb_y >= s2->mb_height){
av_log(s2->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s2->mb_height);
return -1;
}
if(s2->last_picture_ptr==NULL){
/* Skip B-frames if we do not have reference frames and gop is not closed */
if(s2->pict_type==FF_B_TYPE){
if(!s2->closed_gop)
break;
}
}
if(s2->pict_type==FF_I_TYPE)
s->sync=1;
if(s2->next_picture_ptr==NULL){
/* Skip P-frames if we do not have a reference frame or we have an invalid header. */
if(s2->pict_type==FF_P_TYPE && !s->sync) break;
}
/* Skip B-frames if we are in a hurry. */
if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break;
if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE)
||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE)
|| avctx->skip_frame >= AVDISCARD_ALL)
break;
/* Skip everything if we are in a hurry>=5. */
if(avctx->hurry_up>=5) break;
if (!s->mpeg_enc_ctx_allocated) break;
if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
break;
}
if(!s2->pict_type){
av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n");
break;
}
if(s2->first_slice){
s2->first_slice=0;
if(mpeg_field_start(s2, buf, buf_size) < 0)
return -1;
}
if(!s2->current_picture_ptr){
av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
return -1;
}
if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) {
s->slice_count++;
break;
}
if(avctx->thread_count > 1){
int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
if(threshold <= mb_y){
MpegEncContext *thread_context= s2->thread_context[s->slice_count];
thread_context->start_mb_y= mb_y;
thread_context->end_mb_y = s2->mb_height;
if(s->slice_count){
s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
ff_update_duplicate_context(thread_context, s2);
}
init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
s->slice_count++;
}
buf_ptr += 2; //FIXME add minimum number of bytes per slice
}else{
ret = mpeg_decode_slice(s, mb_y, &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);
}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 void flush(AVCodecContext *avctx){
Mpeg1Context *s = avctx->priv_data;
s->sync=0;
ff_mpeg_flush(avctx);
}
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",
AVMEDIA_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 | CODEC_CAP_DELAY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
};
AVCodec mpeg2video_decoder = {
"mpeg2video",
AVMEDIA_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 | CODEC_CAP_DELAY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"),
};
//legacy decoder
AVCodec mpegvideo_decoder = {
"mpegvideo",
AVMEDIA_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 | CODEC_CAP_DELAY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
};
#if CONFIG_MPEG_XVMC_DECODER
static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
if( avctx->thread_count > 1)
return -1;
if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
return -1;
if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
dprintf(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
}
mpeg_decode_init(avctx);
avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT;
avctx->xvmc_acceleration = 2;//2 - the blocks are packed!
return 0;
}
AVCodec mpeg_xvmc_decoder = {
"mpegvideo_xvmc",
AVMEDIA_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| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
.flush= flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"),
};
#endif
#if CONFIG_MPEG_VDPAU_DECODER
AVCodec mpeg_vdpau_decoder = {
"mpegvideo_vdpau",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_MPEG2VIDEO,
sizeof(Mpeg1Context),
mpeg_decode_init,
NULL,
mpeg_decode_end,
mpeg_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
.flush= flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
};
#endif
#if CONFIG_MPEG1_VDPAU_DECODER
AVCodec mpeg1_vdpau_decoder = {
"mpeg1video_vdpau",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_MPEG1VIDEO,
sizeof(Mpeg1Context),
mpeg_decode_init,
NULL,
mpeg_decode_end,
mpeg_decode_frame,
CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
.flush= flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
};
#endif
| 123linslouis-android-video-cutter | jni/libavcodec/mpeg12.c | C | asf20 | 91,488 |
/*
* H.264 IDCT
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* H.264 IDCT.
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "dsputil.h"
static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
block[0] += 1<<(shift-1);
for(i=0; i<4; i++){
const int z0= block[0 + block_stride*i] + block[2 + block_stride*i];
const int z1= block[0 + block_stride*i] - block[2 + block_stride*i];
const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i];
const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1);
block[0 + block_stride*i]= z0 + z3;
block[1 + block_stride*i]= z1 + z2;
block[2 + block_stride*i]= z1 - z2;
block[3 + block_stride*i]= z0 - z3;
}
for(i=0; i<4; i++){
const int z0= block[i + block_stride*0] + block[i + block_stride*2];
const int z1= block[i + block_stride*0] - block[i + block_stride*2];
const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3];
const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1);
dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ];
dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ];
dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ];
dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ];
}
}
void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride){
idct_internal(dst, block, stride, 4, 6, 1);
}
void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){
idct_internal(dst, block, stride, 8, 3, 1);
}
void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block){
idct_internal(dst, block, stride, 8, 3, 0);
}
void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride){
int i;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
block[0] += 32;
for( i = 0; i < 8; i++ )
{
const int a0 = block[0+i*8] + block[4+i*8];
const int a2 = block[0+i*8] - block[4+i*8];
const int a4 = (block[2+i*8]>>1) - block[6+i*8];
const int a6 = (block[6+i*8]>>1) + block[2+i*8];
const int b0 = a0 + a6;
const int b2 = a2 + a4;
const int b4 = a2 - a4;
const int b6 = a0 - a6;
const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1);
const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1);
const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1);
const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1);
const int b1 = (a7>>2) + a1;
const int b3 = a3 + (a5>>2);
const int b5 = (a3>>2) - a5;
const int b7 = a7 - (a1>>2);
block[0+i*8] = b0 + b7;
block[7+i*8] = b0 - b7;
block[1+i*8] = b2 + b5;
block[6+i*8] = b2 - b5;
block[2+i*8] = b4 + b3;
block[5+i*8] = b4 - b3;
block[3+i*8] = b6 + b1;
block[4+i*8] = b6 - b1;
}
for( i = 0; i < 8; i++ )
{
const int a0 = block[i+0*8] + block[i+4*8];
const int a2 = block[i+0*8] - block[i+4*8];
const int a4 = (block[i+2*8]>>1) - block[i+6*8];
const int a6 = (block[i+6*8]>>1) + block[i+2*8];
const int b0 = a0 + a6;
const int b2 = a2 + a4;
const int b4 = a2 - a4;
const int b6 = a0 - a6;
const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1);
const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1);
const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1);
const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1);
const int b1 = (a7>>2) + a1;
const int b3 = a3 + (a5>>2);
const int b5 = (a3>>2) - a5;
const int b7 = a7 - (a1>>2);
dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b7) >> 6) ];
dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b2 + b5) >> 6) ];
dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b4 + b3) >> 6) ];
dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b6 + b1) >> 6) ];
dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b6 - b1) >> 6) ];
dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b4 - b3) >> 6) ];
dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b2 - b5) >> 6) ];
dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b7) >> 6) ];
}
}
// assumes all AC coefs are 0
void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){
int i, j;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int dc = (block[0] + 32) >> 6;
for( j = 0; j < 4; j++ )
{
for( i = 0; i < 4; i++ )
dst[i] = cm[ dst[i] + dc ];
dst += stride;
}
}
void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){
int i, j;
uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;
int dc = (block[0] + 32) >> 6;
for( j = 0; j < 8; j++ )
{
for( i = 0; i < 8; i++ )
dst[i] = cm[ dst[i] + dc ];
dst += stride;
}
}
//FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split
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,
};
void ff_h264_idct_add16_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
int i;
for(i=0; i<16; i++){
int nnz = nnzc[ scan8[i] ];
if(nnz){
if(nnz==1 && block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride);
else idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1);
}
}
}
void ff_h264_idct_add16intra_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
int i;
for(i=0; i<16; i++){
if(nnzc[ scan8[i] ]) idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1);
else if(block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride);
}
}
void ff_h264_idct8_add4_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
int i;
for(i=0; i<16; i+=4){
int nnz = nnzc[ scan8[i] ];
if(nnz){
if(nnz==1 && block[i*16]) ff_h264_idct8_dc_add_c(dst + block_offset[i], block + i*16, stride);
else ff_h264_idct8_add_c (dst + block_offset[i], block + i*16, stride);
}
}
}
void ff_h264_idct_add8_c(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){
int i;
for(i=16; i<16+8; i++){
if(nnzc[ scan8[i] ])
ff_h264_idct_add_c (dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
else if(block[i*16])
ff_h264_idct_dc_add_c(dest[(i&4)>>2] + block_offset[i], block + i*16, stride);
}
}
| 123linslouis-android-video-cutter | jni/libavcodec/h264idct.c | C | asf20 | 8,169 |
/*
* Monkey's Audio lossless audio decoder
* Copyright (c) 2007 Benjamin Zores <ben@geexbox.org>
* based upon libdemac from Dave Chapman.
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define ALT_BITSTREAM_READER_LE
#include "avcodec.h"
#include "dsputil.h"
#include "get_bits.h"
#include "bytestream.h"
/**
* @file
* Monkey's Audio lossless audio decoder
*/
#define BLOCKS_PER_LOOP 4608
#define MAX_CHANNELS 2
#define MAX_BYTESPERSAMPLE 3
#define APE_FRAMECODE_MONO_SILENCE 1
#define APE_FRAMECODE_STEREO_SILENCE 3
#define APE_FRAMECODE_PSEUDO_STEREO 4
#define HISTORY_SIZE 512
#define PREDICTOR_ORDER 8
/** Total size of all predictor histories */
#define PREDICTOR_SIZE 50
#define YDELAYA (18 + PREDICTOR_ORDER*4)
#define YDELAYB (18 + PREDICTOR_ORDER*3)
#define XDELAYA (18 + PREDICTOR_ORDER*2)
#define XDELAYB (18 + PREDICTOR_ORDER)
#define YADAPTCOEFFSA 18
#define XADAPTCOEFFSA 14
#define YADAPTCOEFFSB 10
#define XADAPTCOEFFSB 5
/**
* Possible compression levels
* @{
*/
enum APECompressionLevel {
COMPRESSION_LEVEL_FAST = 1000,
COMPRESSION_LEVEL_NORMAL = 2000,
COMPRESSION_LEVEL_HIGH = 3000,
COMPRESSION_LEVEL_EXTRA_HIGH = 4000,
COMPRESSION_LEVEL_INSANE = 5000
};
/** @} */
#define APE_FILTER_LEVELS 3
/** Filter orders depending on compression level */
static const uint16_t ape_filter_orders[5][APE_FILTER_LEVELS] = {
{ 0, 0, 0 },
{ 16, 0, 0 },
{ 64, 0, 0 },
{ 32, 256, 0 },
{ 16, 256, 1280 }
};
/** Filter fraction bits depending on compression level */
static const uint8_t ape_filter_fracbits[5][APE_FILTER_LEVELS] = {
{ 0, 0, 0 },
{ 11, 0, 0 },
{ 11, 0, 0 },
{ 10, 13, 0 },
{ 11, 13, 15 }
};
/** Filters applied to the decoded data */
typedef struct APEFilter {
int16_t *coeffs; ///< actual coefficients used in filtering
int16_t *adaptcoeffs; ///< adaptive filter coefficients used for correcting of actual filter coefficients
int16_t *historybuffer; ///< filter memory
int16_t *delay; ///< filtered values
int avg;
} APEFilter;
typedef struct APERice {
uint32_t k;
uint32_t ksum;
} APERice;
typedef struct APERangecoder {
uint32_t low; ///< low end of interval
uint32_t range; ///< length of interval
uint32_t help; ///< bytes_to_follow resp. intermediate value
unsigned int buffer; ///< buffer for input/output
} APERangecoder;
/** Filter histories */
typedef struct APEPredictor {
int32_t *buf;
int32_t lastA[2];
int32_t filterA[2];
int32_t filterB[2];
int32_t coeffsA[2][4]; ///< adaption coefficients
int32_t coeffsB[2][5]; ///< adaption coefficients
int32_t historybuffer[HISTORY_SIZE + PREDICTOR_SIZE];
} APEPredictor;
/** Decoder context */
typedef struct APEContext {
AVCodecContext *avctx;
DSPContext dsp;
int channels;
int samples; ///< samples left to decode in current frame
int fileversion; ///< codec version, very important in decoding process
int compression_level; ///< compression levels
int fset; ///< which filter set to use (calculated from compression level)
int flags; ///< global decoder flags
uint32_t CRC; ///< frame CRC
int frameflags; ///< frame flags
int currentframeblocks; ///< samples (per channel) in current frame
int blocksdecoded; ///< count of decoded samples in current frame
APEPredictor predictor; ///< predictor used for final reconstruction
int32_t decoded0[BLOCKS_PER_LOOP]; ///< decoded data for the first channel
int32_t decoded1[BLOCKS_PER_LOOP]; ///< decoded data for the second channel
int16_t* filterbuf[APE_FILTER_LEVELS]; ///< filter memory
APERangecoder rc; ///< rangecoder used to decode actual values
APERice riceX; ///< rice code parameters for the second channel
APERice riceY; ///< rice code parameters for the first channel
APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for reconstruction
uint8_t *data; ///< current frame data
uint8_t *data_end; ///< frame data end
const uint8_t *ptr; ///< current position in frame data
const uint8_t *last_ptr; ///< position where last 4608-sample block ended
int error;
} APEContext;
// TODO: dsputilize
static av_cold int ape_decode_init(AVCodecContext * avctx)
{
APEContext *s = avctx->priv_data;
int i;
if (avctx->extradata_size != 6) {
av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n");
return -1;
}
if (avctx->bits_per_coded_sample != 16) {
av_log(avctx, AV_LOG_ERROR, "Only 16-bit samples are supported\n");
return -1;
}
if (avctx->channels > 2) {
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo is supported\n");
return -1;
}
s->avctx = avctx;
s->channels = avctx->channels;
s->fileversion = AV_RL16(avctx->extradata);
s->compression_level = AV_RL16(avctx->extradata + 2);
s->flags = AV_RL16(avctx->extradata + 4);
av_log(avctx, AV_LOG_DEBUG, "Compression Level: %d - Flags: %d\n", s->compression_level, s->flags);
if (s->compression_level % 1000 || s->compression_level > COMPRESSION_LEVEL_INSANE) {
av_log(avctx, AV_LOG_ERROR, "Incorrect compression level %d\n", s->compression_level);
return -1;
}
s->fset = s->compression_level / 1000 - 1;
for (i = 0; i < APE_FILTER_LEVELS; i++) {
if (!ape_filter_orders[s->fset][i])
break;
s->filterbuf[i] = av_malloc((ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4);
}
dsputil_init(&s->dsp, avctx);
avctx->sample_fmt = SAMPLE_FMT_S16;
avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
return 0;
}
static av_cold int ape_decode_close(AVCodecContext * avctx)
{
APEContext *s = avctx->priv_data;
int i;
for (i = 0; i < APE_FILTER_LEVELS; i++)
av_freep(&s->filterbuf[i]);
av_freep(&s->data);
return 0;
}
/**
* @defgroup rangecoder APE range decoder
* @{
*/
#define CODE_BITS 32
#define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1))
#define SHIFT_BITS (CODE_BITS - 9)
#define EXTRA_BITS ((CODE_BITS-2) % 8 + 1)
#define BOTTOM_VALUE (TOP_VALUE >> 8)
/** Start the decoder */
static inline void range_start_decoding(APEContext * ctx)
{
ctx->rc.buffer = bytestream_get_byte(&ctx->ptr);
ctx->rc.low = ctx->rc.buffer >> (8 - EXTRA_BITS);
ctx->rc.range = (uint32_t) 1 << EXTRA_BITS;
}
/** Perform normalization */
static inline void range_dec_normalize(APEContext * ctx)
{
while (ctx->rc.range <= BOTTOM_VALUE) {
ctx->rc.buffer <<= 8;
if(ctx->ptr < ctx->data_end)
ctx->rc.buffer += *ctx->ptr;
ctx->ptr++;
ctx->rc.low = (ctx->rc.low << 8) | ((ctx->rc.buffer >> 1) & 0xFF);
ctx->rc.range <<= 8;
}
}
/**
* Calculate culmulative frequency for next symbol. Does NO update!
* @param ctx decoder context
* @param tot_f is the total frequency or (code_value)1<<shift
* @return the culmulative frequency
*/
static inline int range_decode_culfreq(APEContext * ctx, int tot_f)
{
range_dec_normalize(ctx);
ctx->rc.help = ctx->rc.range / tot_f;
return ctx->rc.low / ctx->rc.help;
}
/**
* Decode value with given size in bits
* @param ctx decoder context
* @param shift number of bits to decode
*/
static inline int range_decode_culshift(APEContext * ctx, int shift)
{
range_dec_normalize(ctx);
ctx->rc.help = ctx->rc.range >> shift;
return ctx->rc.low / ctx->rc.help;
}
/**
* Update decoding state
* @param ctx decoder context
* @param sy_f the interval length (frequency of the symbol)
* @param lt_f the lower end (frequency sum of < symbols)
*/
static inline void range_decode_update(APEContext * ctx, int sy_f, int lt_f)
{
ctx->rc.low -= ctx->rc.help * lt_f;
ctx->rc.range = ctx->rc.help * sy_f;
}
/** Decode n bits (n <= 16) without modelling */
static inline int range_decode_bits(APEContext * ctx, int n)
{
int sym = range_decode_culshift(ctx, n);
range_decode_update(ctx, 1, sym);
return sym;
}
#define MODEL_ELEMENTS 64
/**
* Fixed probabilities for symbols in Monkey Audio version 3.97
*/
static const uint16_t counts_3970[22] = {
0, 14824, 28224, 39348, 47855, 53994, 58171, 60926,
62682, 63786, 64463, 64878, 65126, 65276, 65365, 65419,
65450, 65469, 65480, 65487, 65491, 65493,
};
/**
* Probability ranges for symbols in Monkey Audio version 3.97
*/
static const uint16_t counts_diff_3970[21] = {
14824, 13400, 11124, 8507, 6139, 4177, 2755, 1756,
1104, 677, 415, 248, 150, 89, 54, 31,
19, 11, 7, 4, 2,
};
/**
* Fixed probabilities for symbols in Monkey Audio version 3.98
*/
static const uint16_t counts_3980[22] = {
0, 19578, 36160, 48417, 56323, 60899, 63265, 64435,
64971, 65232, 65351, 65416, 65447, 65466, 65476, 65482,
65485, 65488, 65490, 65491, 65492, 65493,
};
/**
* Probability ranges for symbols in Monkey Audio version 3.98
*/
static const uint16_t counts_diff_3980[21] = {
19578, 16582, 12257, 7906, 4576, 2366, 1170, 536,
261, 119, 65, 31, 19, 10, 6, 3,
3, 2, 1, 1, 1,
};
/**
* Decode symbol
* @param ctx decoder context
* @param counts probability range start position
* @param counts_diff probability range widths
*/
static inline int range_get_symbol(APEContext * ctx,
const uint16_t counts[],
const uint16_t counts_diff[])
{
int symbol, cf;
cf = range_decode_culshift(ctx, 16);
if(cf > 65492){
symbol= cf - 65535 + 63;
range_decode_update(ctx, 1, cf);
if(cf > 65535)
ctx->error=1;
return symbol;
}
/* figure out the symbol inefficiently; a binary search would be much better */
for (symbol = 0; counts[symbol + 1] <= cf; symbol++);
range_decode_update(ctx, counts_diff[symbol], counts[symbol]);
return symbol;
}
/** @} */ // group rangecoder
static inline void update_rice(APERice *rice, int x)
{
int lim = rice->k ? (1 << (rice->k + 4)) : 0;
rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5);
if (rice->ksum < lim)
rice->k--;
else if (rice->ksum >= (1 << (rice->k + 5)))
rice->k++;
}
static inline int ape_decode_value(APEContext * ctx, APERice *rice)
{
int x, overflow;
if (ctx->fileversion < 3990) {
int tmpk;
overflow = range_get_symbol(ctx, counts_3970, counts_diff_3970);
if (overflow == (MODEL_ELEMENTS - 1)) {
tmpk = range_decode_bits(ctx, 5);
overflow = 0;
} else
tmpk = (rice->k < 1) ? 0 : rice->k - 1;
if (tmpk <= 16)
x = range_decode_bits(ctx, tmpk);
else {
x = range_decode_bits(ctx, 16);
x |= (range_decode_bits(ctx, tmpk - 16) << 16);
}
x += overflow << tmpk;
} else {
int base, pivot;
pivot = rice->ksum >> 5;
if (pivot == 0)
pivot = 1;
overflow = range_get_symbol(ctx, counts_3980, counts_diff_3980);
if (overflow == (MODEL_ELEMENTS - 1)) {
overflow = range_decode_bits(ctx, 16) << 16;
overflow |= range_decode_bits(ctx, 16);
}
if (pivot < 0x10000) {
base = range_decode_culfreq(ctx, pivot);
range_decode_update(ctx, 1, base);
} else {
int base_hi = pivot, base_lo;
int bbits = 0;
while (base_hi & ~0xFFFF) {
base_hi >>= 1;
bbits++;
}
base_hi = range_decode_culfreq(ctx, base_hi + 1);
range_decode_update(ctx, 1, base_hi);
base_lo = range_decode_culfreq(ctx, 1 << bbits);
range_decode_update(ctx, 1, base_lo);
base = (base_hi << bbits) + base_lo;
}
x = base + overflow * pivot;
}
update_rice(rice, x);
/* Convert to signed */
if (x & 1)
return (x >> 1) + 1;
else
return -(x >> 1);
}
static void entropy_decode(APEContext * ctx, int blockstodecode, int stereo)
{
int32_t *decoded0 = ctx->decoded0;
int32_t *decoded1 = ctx->decoded1;
ctx->blocksdecoded = blockstodecode;
if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
/* We are pure silence, just memset the output buffer. */
memset(decoded0, 0, blockstodecode * sizeof(int32_t));
memset(decoded1, 0, blockstodecode * sizeof(int32_t));
} else {
while (blockstodecode--) {
*decoded0++ = ape_decode_value(ctx, &ctx->riceY);
if (stereo)
*decoded1++ = ape_decode_value(ctx, &ctx->riceX);
}
}
if (ctx->blocksdecoded == ctx->currentframeblocks)
range_dec_normalize(ctx); /* normalize to use up all bytes */
}
static void init_entropy_decoder(APEContext * ctx)
{
/* Read the CRC */
ctx->CRC = bytestream_get_be32(&ctx->ptr);
/* Read the frame flags if they exist */
ctx->frameflags = 0;
if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) {
ctx->CRC &= ~0x80000000;
ctx->frameflags = bytestream_get_be32(&ctx->ptr);
}
/* Keep a count of the blocks decoded in this frame */
ctx->blocksdecoded = 0;
/* Initialize the rice structs */
ctx->riceX.k = 10;
ctx->riceX.ksum = (1 << ctx->riceX.k) * 16;
ctx->riceY.k = 10;
ctx->riceY.ksum = (1 << ctx->riceY.k) * 16;
/* The first 8 bits of input are ignored. */
ctx->ptr++;
range_start_decoding(ctx);
}
static const int32_t initial_coeffs[4] = {
360, 317, -109, 98
};
static void init_predictor_decoder(APEContext * ctx)
{
APEPredictor *p = &ctx->predictor;
/* Zero the history buffers */
memset(p->historybuffer, 0, PREDICTOR_SIZE * sizeof(int32_t));
p->buf = p->historybuffer;
/* Initialize and zero the coefficients */
memcpy(p->coeffsA[0], initial_coeffs, sizeof(initial_coeffs));
memcpy(p->coeffsA[1], initial_coeffs, sizeof(initial_coeffs));
memset(p->coeffsB, 0, sizeof(p->coeffsB));
p->filterA[0] = p->filterA[1] = 0;
p->filterB[0] = p->filterB[1] = 0;
p->lastA[0] = p->lastA[1] = 0;
}
/** Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero) */
static inline int APESIGN(int32_t x) {
return (x < 0) - (x > 0);
}
static av_always_inline int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB)
{
int32_t predictionA, predictionB, sign;
p->buf[delayA] = p->lastA[filter];
p->buf[adaptA] = APESIGN(p->buf[delayA]);
p->buf[delayA - 1] = p->buf[delayA] - p->buf[delayA - 1];
p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]);
predictionA = p->buf[delayA ] * p->coeffsA[filter][0] +
p->buf[delayA - 1] * p->coeffsA[filter][1] +
p->buf[delayA - 2] * p->coeffsA[filter][2] +
p->buf[delayA - 3] * p->coeffsA[filter][3];
/* Apply a scaled first-order filter compression */
p->buf[delayB] = p->filterA[filter ^ 1] - ((p->filterB[filter] * 31) >> 5);
p->buf[adaptB] = APESIGN(p->buf[delayB]);
p->buf[delayB - 1] = p->buf[delayB] - p->buf[delayB - 1];
p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]);
p->filterB[filter] = p->filterA[filter ^ 1];
predictionB = p->buf[delayB ] * p->coeffsB[filter][0] +
p->buf[delayB - 1] * p->coeffsB[filter][1] +
p->buf[delayB - 2] * p->coeffsB[filter][2] +
p->buf[delayB - 3] * p->coeffsB[filter][3] +
p->buf[delayB - 4] * p->coeffsB[filter][4];
p->lastA[filter] = decoded + ((predictionA + (predictionB >> 1)) >> 10);
p->filterA[filter] = p->lastA[filter] + ((p->filterA[filter] * 31) >> 5);
sign = APESIGN(decoded);
p->coeffsA[filter][0] += p->buf[adaptA ] * sign;
p->coeffsA[filter][1] += p->buf[adaptA - 1] * sign;
p->coeffsA[filter][2] += p->buf[adaptA - 2] * sign;
p->coeffsA[filter][3] += p->buf[adaptA - 3] * sign;
p->coeffsB[filter][0] += p->buf[adaptB ] * sign;
p->coeffsB[filter][1] += p->buf[adaptB - 1] * sign;
p->coeffsB[filter][2] += p->buf[adaptB - 2] * sign;
p->coeffsB[filter][3] += p->buf[adaptB - 3] * sign;
p->coeffsB[filter][4] += p->buf[adaptB - 4] * sign;
return p->filterA[filter];
}
static void predictor_decode_stereo(APEContext * ctx, int count)
{
APEPredictor *p = &ctx->predictor;
int32_t *decoded0 = ctx->decoded0;
int32_t *decoded1 = ctx->decoded1;
while (count--) {
/* Predictor Y */
*decoded0 = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, YADAPTCOEFFSA, YADAPTCOEFFSB);
decoded0++;
*decoded1 = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, XADAPTCOEFFSA, XADAPTCOEFFSB);
decoded1++;
/* Combined */
p->buf++;
/* Have we filled the history buffer? */
if (p->buf == p->historybuffer + HISTORY_SIZE) {
memmove(p->historybuffer, p->buf, PREDICTOR_SIZE * sizeof(int32_t));
p->buf = p->historybuffer;
}
}
}
static void predictor_decode_mono(APEContext * ctx, int count)
{
APEPredictor *p = &ctx->predictor;
int32_t *decoded0 = ctx->decoded0;
int32_t predictionA, currentA, A, sign;
currentA = p->lastA[0];
while (count--) {
A = *decoded0;
p->buf[YDELAYA] = currentA;
p->buf[YDELAYA - 1] = p->buf[YDELAYA] - p->buf[YDELAYA - 1];
predictionA = p->buf[YDELAYA ] * p->coeffsA[0][0] +
p->buf[YDELAYA - 1] * p->coeffsA[0][1] +
p->buf[YDELAYA - 2] * p->coeffsA[0][2] +
p->buf[YDELAYA - 3] * p->coeffsA[0][3];
currentA = A + (predictionA >> 10);
p->buf[YADAPTCOEFFSA] = APESIGN(p->buf[YDELAYA ]);
p->buf[YADAPTCOEFFSA - 1] = APESIGN(p->buf[YDELAYA - 1]);
sign = APESIGN(A);
p->coeffsA[0][0] += p->buf[YADAPTCOEFFSA ] * sign;
p->coeffsA[0][1] += p->buf[YADAPTCOEFFSA - 1] * sign;
p->coeffsA[0][2] += p->buf[YADAPTCOEFFSA - 2] * sign;
p->coeffsA[0][3] += p->buf[YADAPTCOEFFSA - 3] * sign;
p->buf++;
/* Have we filled the history buffer? */
if (p->buf == p->historybuffer + HISTORY_SIZE) {
memmove(p->historybuffer, p->buf, PREDICTOR_SIZE * sizeof(int32_t));
p->buf = p->historybuffer;
}
p->filterA[0] = currentA + ((p->filterA[0] * 31) >> 5);
*(decoded0++) = p->filterA[0];
}
p->lastA[0] = currentA;
}
static void do_init_filter(APEFilter *f, int16_t * buf, int order)
{
f->coeffs = buf;
f->historybuffer = buf + order;
f->delay = f->historybuffer + order * 2;
f->adaptcoeffs = f->historybuffer + order;
memset(f->historybuffer, 0, (order * 2) * sizeof(int16_t));
memset(f->coeffs, 0, order * sizeof(int16_t));
f->avg = 0;
}
static void init_filter(APEContext * ctx, APEFilter *f, int16_t * buf, int order)
{
do_init_filter(&f[0], buf, order);
do_init_filter(&f[1], buf + order * 3 + HISTORY_SIZE, order);
}
static void do_apply_filter(APEContext * ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits)
{
int res;
int absres;
while (count--) {
/* round fixedpoint scalar product */
res = ctx->dsp.scalarproduct_and_madd_int16(f->coeffs, f->delay - order, f->adaptcoeffs - order, order, APESIGN(*data));
res = (res + (1 << (fracbits - 1))) >> fracbits;
res += *data;
*data++ = res;
/* Update the output history */
*f->delay++ = av_clip_int16(res);
if (version < 3980) {
/* Version ??? to < 3.98 files (untested) */
f->adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4;
f->adaptcoeffs[-4] >>= 1;
f->adaptcoeffs[-8] >>= 1;
} else {
/* Version 3.98 and later files */
/* Update the adaption coefficients */
absres = FFABS(res);
if (absres)
*f->adaptcoeffs = ((res & (1<<31)) - (1<<30)) >> (25 + (absres <= f->avg*3) + (absres <= f->avg*4/3));
else
*f->adaptcoeffs = 0;
f->avg += (absres - f->avg) / 16;
f->adaptcoeffs[-1] >>= 1;
f->adaptcoeffs[-2] >>= 1;
f->adaptcoeffs[-8] >>= 1;
}
f->adaptcoeffs++;
/* Have we filled the history buffer? */
if (f->delay == f->historybuffer + HISTORY_SIZE + (order * 2)) {
memmove(f->historybuffer, f->delay - (order * 2),
(order * 2) * sizeof(int16_t));
f->delay = f->historybuffer + order * 2;
f->adaptcoeffs = f->historybuffer + order;
}
}
}
static void apply_filter(APEContext * ctx, APEFilter *f,
int32_t * data0, int32_t * data1,
int count, int order, int fracbits)
{
do_apply_filter(ctx, ctx->fileversion, &f[0], data0, count, order, fracbits);
if (data1)
do_apply_filter(ctx, ctx->fileversion, &f[1], data1, count, order, fracbits);
}
static void ape_apply_filters(APEContext * ctx, int32_t * decoded0,
int32_t * decoded1, int count)
{
int i;
for (i = 0; i < APE_FILTER_LEVELS; i++) {
if (!ape_filter_orders[ctx->fset][i])
break;
apply_filter(ctx, ctx->filters[i], decoded0, decoded1, count, ape_filter_orders[ctx->fset][i], ape_filter_fracbits[ctx->fset][i]);
}
}
static void init_frame_decoder(APEContext * ctx)
{
int i;
init_entropy_decoder(ctx);
init_predictor_decoder(ctx);
for (i = 0; i < APE_FILTER_LEVELS; i++) {
if (!ape_filter_orders[ctx->fset][i])
break;
init_filter(ctx, ctx->filters[i], ctx->filterbuf[i], ape_filter_orders[ctx->fset][i]);
}
}
static void ape_unpack_mono(APEContext * ctx, int count)
{
int32_t left;
int32_t *decoded0 = ctx->decoded0;
int32_t *decoded1 = ctx->decoded1;
if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
entropy_decode(ctx, count, 0);
/* We are pure silence, so we're done. */
av_log(ctx->avctx, AV_LOG_DEBUG, "pure silence mono\n");
return;
}
entropy_decode(ctx, count, 0);
ape_apply_filters(ctx, decoded0, NULL, count);
/* Now apply the predictor decoding */
predictor_decode_mono(ctx, count);
/* Pseudo-stereo - just copy left channel to right channel */
if (ctx->channels == 2) {
while (count--) {
left = *decoded0;
*(decoded1++) = *(decoded0++) = left;
}
}
}
static void ape_unpack_stereo(APEContext * ctx, int count)
{
int32_t left, right;
int32_t *decoded0 = ctx->decoded0;
int32_t *decoded1 = ctx->decoded1;
if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
/* We are pure silence, so we're done. */
av_log(ctx->avctx, AV_LOG_DEBUG, "pure silence stereo\n");
return;
}
entropy_decode(ctx, count, 1);
ape_apply_filters(ctx, decoded0, decoded1, count);
/* Now apply the predictor decoding */
predictor_decode_stereo(ctx, count);
/* Decorrelate and scale to output depth */
while (count--) {
left = *decoded1 - (*decoded0 / 2);
right = left + *decoded0;
*(decoded0++) = left;
*(decoded1++) = right;
}
}
static int ape_decode_frame(AVCodecContext * avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
APEContext *s = avctx->priv_data;
int16_t *samples = data;
int nblocks;
int i, n;
int blockstodecode;
int bytes_used;
if (buf_size == 0 && !s->samples) {
*data_size = 0;
return 0;
}
/* should not happen but who knows */
if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {
av_log (avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc! (max is %d where you have %d)\n", *data_size, s->samples * 2 * avctx->channels);
return -1;
}
if(!s->samples){
s->data = av_realloc(s->data, (buf_size + 3) & ~3);
s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2);
s->ptr = s->last_ptr = s->data;
s->data_end = s->data + buf_size;
nblocks = s->samples = bytestream_get_be32(&s->ptr);
n = bytestream_get_be32(&s->ptr);
if(n < 0 || n > 3){
av_log(avctx, AV_LOG_ERROR, "Incorrect offset passed\n");
s->data = NULL;
return -1;
}
s->ptr += n;
s->currentframeblocks = nblocks;
buf += 4;
if (s->samples <= 0) {
*data_size = 0;
return buf_size;
}
memset(s->decoded0, 0, sizeof(s->decoded0));
memset(s->decoded1, 0, sizeof(s->decoded1));
/* Initialize the frame decoder */
init_frame_decoder(s);
}
if (!s->data) {
*data_size = 0;
return buf_size;
}
nblocks = s->samples;
blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks);
s->error=0;
if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO))
ape_unpack_mono(s, blockstodecode);
else
ape_unpack_stereo(s, blockstodecode);
emms_c();
if(s->error || s->ptr > s->data_end){
s->samples=0;
av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n");
return -1;
}
for (i = 0; i < blockstodecode; i++) {
*samples++ = s->decoded0[i];
if(s->channels == 2)
*samples++ = s->decoded1[i];
}
s->samples -= blockstodecode;
*data_size = blockstodecode * 2 * s->channels;
bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size;
s->last_ptr = s->ptr;
return bytes_used;
}
AVCodec ape_decoder = {
"ape",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_APE,
sizeof(APEContext),
ape_decode_init,
NULL,
ape_decode_close,
ape_decode_frame,
.capabilities = CODEC_CAP_SUBFRAMES,
.long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/apedec.c | C | asf20 | 27,637 |
/*
* Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju at gmail dot com >
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* data structures common to libdirac and libschroedinger
*/
#ifndef AVCODEC_LIBDIRAC_LIBSCHRO_H
#define AVCODEC_LIBDIRAC_LIBSCHRO_H
#include "avcodec.h"
typedef struct {
uint16_t width;
uint16_t height;
uint16_t frame_rate_num;
uint16_t frame_rate_denom;
} FfmpegDiracSchroVideoFormatInfo;
/**
* Returns the index into the Dirac Schro common video format info table
*/
unsigned int ff_dirac_schro_get_video_format_idx(AVCodecContext *avccontext);
/**
* contains a single encoded frame returned from Dirac or Schroedinger
*/
typedef struct FfmpegDiracSchroEncodedFrame {
/** encoded frame data */
uint8_t *p_encbuf;
/** encoded frame size */
uint32_t size;
/** encoded frame number. Will be used as pts */
uint32_t frame_num;
/** key frame flag. 1 : is key frame , 0 : in not key frame */
uint16_t key_frame;
} FfmpegDiracSchroEncodedFrame;
/**
* queue element
*/
typedef struct FfmpegDiracSchroQueueElement {
/** Data to be stored in queue*/
void *data;
/** Pointer to next element queue */
struct FfmpegDiracSchroQueueElement *next;
} FfmpegDiracSchroQueueElement;
/**
* A simple queue implementation used in libdirac and libschroedinger
*/
typedef struct FfmpegDiracSchroQueue {
/** Pointer to head of queue */
FfmpegDiracSchroQueueElement *p_head;
/** Pointer to tail of queue */
FfmpegDiracSchroQueueElement *p_tail;
/** Queue size*/
int size;
} FfmpegDiracSchroQueue;
/**
* Initialise the queue
*/
void ff_dirac_schro_queue_init(FfmpegDiracSchroQueue *queue);
/**
* Add an element to the end of the queue
*/
int ff_dirac_schro_queue_push_back(FfmpegDiracSchroQueue *queue, void *p_data);
/**
* Return the first element in the queue
*/
void *ff_dirac_schro_queue_pop(FfmpegDiracSchroQueue *queue);
/**
* Free the queue resources. free_func is a function supplied by the caller to
* free any resources allocated by the caller. The data field of the queue
* element is passed to it.
*/
void ff_dirac_schro_queue_free(FfmpegDiracSchroQueue *queue,
void (*free_func)(void *));
#endif /* AVCODEC_LIBDIRAC_LIBSCHRO_H */
| 123linslouis-android-video-cutter | jni/libavcodec/libdirac_libschro.h | C | asf20 | 3,010 |
/*
* Copyright (c) 2008 Reimar Döffinger
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/intreadwrite.h"
#include "avcodec.h"
static int text2movsub(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
if (buf_size > 0xffff) return 0;
*poutbuf_size = buf_size + 2;
*poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
AV_WB16(*poutbuf, buf_size);
memcpy(*poutbuf + 2, buf, buf_size);
return 1;
}
AVBitStreamFilter text2movsub_bsf={
"text2movsub",
0,
text2movsub,
};
static int mov2textsub(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
if (buf_size < 2) return 0;
*poutbuf_size = FFMIN(buf_size - 2, AV_RB16(buf));
*poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(*poutbuf, buf + 2, *poutbuf_size);
return 1;
}
AVBitStreamFilter mov2textsub_bsf={
"mov2textsub",
0,
mov2textsub,
};
| 123linslouis-android-video-cutter | jni/libavcodec/movsub_bsf.c | C | asf20 | 1,937 |
/*
* Cirrus Logic AccuPak (CLJR) codec
* Copyright (c) 2003 Alex Beregszaszi
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Cirrus Logic AccuPak codec.
*/
#include "avcodec.h"
#include "dsputil.h"
#include "get_bits.h"
/* Disable the encoder. */
#undef CONFIG_CLJR_ENCODER
#define CONFIG_CLJR_ENCODER 0
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,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
CLJRContext * const a = avctx->priv_data;
AVFrame *picture = data;
AVFrame * const p= (AVFrame*)&a->picture;
int x, y;
if(p->data[0])
avctx->release_buffer(avctx, p);
p->reference= 0;
if(avctx->get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1;
}
p->pict_type= FF_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 CONFIG_CLJR_ENCODER
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;
*p = *pict;
p->pict_type= FF_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 av_cold void common_init(AVCodecContext *avctx){
CLJRContext * const a = avctx->priv_data;
avctx->coded_frame= (AVFrame*)&a->picture;
a->avctx= avctx;
}
static av_cold int decode_init(AVCodecContext *avctx){
common_init(avctx);
avctx->pix_fmt= PIX_FMT_YUV411P;
return 0;
}
#if CONFIG_CLJR_ENCODER
static av_cold int encode_init(AVCodecContext *avctx){
common_init(avctx);
return 0;
}
#endif
AVCodec cljr_decoder = {
"cljr",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_CLJR,
sizeof(CLJRContext),
decode_init,
NULL,
NULL,
decode_frame,
CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
};
#if CONFIG_CLJR_ENCODER
AVCodec cljr_encoder = {
"cljr",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_CLJR,
sizeof(CLJRContext),
encode_init,
encode_frame,
//encode_end,
.long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"),
};
#endif
| 123linslouis-android-video-cutter | jni/libavcodec/cljr.c | C | asf20 | 4,015 |
/*
* PNM image format
* Copyright (c) 2002, 2003 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_PNM_H
#define AVCODEC_PNM_H
#include "avcodec.h"
typedef struct PNMContext {
uint8_t *bytestream;
uint8_t *bytestream_start;
uint8_t *bytestream_end;
AVFrame picture;
int maxval; ///< maximum value of a pixel
int type;
} PNMContext;
int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s);
av_cold int ff_pnm_end(AVCodecContext *avctx);
av_cold int ff_pnm_init(AVCodecContext *avctx);
#endif /* AVCODEC_PNM_H */
| 123linslouis-android-video-cutter | jni/libavcodec/pnm.h | C | asf20 | 1,317 |
/*
* Common AAC and AC-3 parser
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "parser.h"
#include "aac_ac3_parser.h"
int ff_aac_ac3_parse(AVCodecParserContext *s1,
AVCodecContext *avctx,
const uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size)
{
AACAC3ParseContext *s = s1->priv_data;
ParseContext *pc = &s->pc;
int len, i;
int new_frame_start;
get_next:
i=END_NOT_FOUND;
if(s->remaining_size <= buf_size){
if(s->remaining_size && !s->need_next_header){
i= s->remaining_size;
s->remaining_size = 0;
}else{ //we need a header first
len=0;
for(i=s->remaining_size; i<buf_size; i++){
s->state = (s->state<<8) + buf[i];
if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
break;
}
if(len<=0){
i=END_NOT_FOUND;
}else{
s->state=0;
i-= s->header_size -1;
s->remaining_size = len;
if(!new_frame_start || pc->index+i<=0){
s->remaining_size += i;
goto get_next;
}
}
}
}
if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
s->remaining_size -= FFMIN(s->remaining_size, buf_size);
*poutbuf = NULL;
*poutbuf_size = 0;
return buf_size;
}
*poutbuf = buf;
*poutbuf_size = buf_size;
/* update codec info */
if(s->codec_id)
avctx->codec_id = s->codec_id;
/* Due to backwards compatible HE-AAC the sample rate, channel count,
and total number of samples found in an AAC ADTS header are not
reliable. Bit rate is still accurate because the total frame duration in
seconds is still correct (as is the number of bits in the frame). */
if (avctx->codec_id != CODEC_ID_AAC) {
avctx->sample_rate = s->sample_rate;
/* allow downmixing to stereo (or mono for AC-3) */
if(avctx->request_channels > 0 &&
avctx->request_channels < s->channels &&
(avctx->request_channels <= 2 ||
(avctx->request_channels == 1 &&
(avctx->codec_id == CODEC_ID_AC3 ||
avctx->codec_id == CODEC_ID_EAC3)))) {
avctx->channels = avctx->request_channels;
} else {
avctx->channels = s->channels;
avctx->channel_layout = s->channel_layout;
}
avctx->frame_size = s->samples;
}
avctx->bit_rate = s->bit_rate;
return i;
}
| 123linslouis-android-video-cutter | jni/libavcodec/aac_ac3_parser.c | C | asf20 | 3,484 |
/*
* The Video Decode and Presentation API for UNIX (VDPAU) is used for
* hardware-accelerated decoding of MPEG-1/2, H.264 and VC-1.
*
* Copyright (C) 2008 NVIDIA
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_VDPAU_H
#define AVCODEC_VDPAU_H
/**
* \defgroup Decoder VDPAU Decoder and Renderer
*
* VDPAU hardware acceleration has two modules
* - VDPAU decoding
* - VDPAU presentation
*
* The VDPAU decoding module parses all headers using FFmpeg
* parsing mechanisms and uses VDPAU for the actual decoding.
*
* As per the current implementation, the actual decoding
* and rendering (API calls) are done as part of the VDPAU
* presentation (vo_vdpau.c) module.
*
* @{
* \defgroup VDPAU_Decoding VDPAU Decoding
* \ingroup Decoder
* @{
*/
#include <vdpau/vdpau.h>
#include <vdpau/vdpau_x11.h>
/** \brief The videoSurface is used for rendering. */
#define FF_VDPAU_STATE_USED_FOR_RENDER 1
/**
* \brief The videoSurface is needed for reference/prediction.
* The codec manipulates this.
*/
#define FF_VDPAU_STATE_USED_FOR_REFERENCE 2
/**
* \brief This structure is used as a callback between the FFmpeg
* decoder (vd_) and presentation (vo_) module.
* This is used for defining a video frame containing surface,
* picture parameter, bitstream information etc which are passed
* between the FFmpeg decoder and its clients.
*/
struct vdpau_render_state {
VdpVideoSurface surface; ///< Used as rendered surface, never changed.
int state; ///< Holds FF_VDPAU_STATE_* values.
/** picture parameter information for all supported codecs */
union VdpPictureInfo {
VdpPictureInfoH264 h264;
VdpPictureInfoMPEG1Or2 mpeg;
VdpPictureInfoVC1 vc1;
VdpPictureInfoMPEG4Part2 mpeg4;
} info;
/** Describe size/location of the compressed video data.
Set to 0 when freeing bitstream_buffers. */
int bitstream_buffers_allocated;
int bitstream_buffers_used;
/** The user is responsible for freeing this buffer using av_freep(). */
VdpBitstreamBuffer *bitstream_buffers;
};
/* @}*/
#endif /* AVCODEC_VDPAU_H */
| 123linslouis-android-video-cutter | jni/libavcodec/vdpau.h | C | asf20 | 2,854 |
/*
* WMA compatible decoder
* Copyright (c) 2002 The FFmpeg Project
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* WMA compatible decoder.
* This decoder handles Microsoft Windows Media Audio data, versions 1 & 2.
* WMA v1 is identified by audio format 0x160 in Microsoft media files
* (ASF/AVI/WAV). WMA v2 is identified by audio format 0x161.
*
* To use this decoder, a calling application must supply the extra data
* bytes provided with the WMA data. These are the extra, codec-specific
* bytes at the end of a WAVEFORMATEX data structure. Transmit these bytes
* to the decoder using the extradata[_size] fields in AVCodecContext. There
* should be 4 extra bytes for v1 data and 6 extra bytes for v2 data.
*/
#include "avcodec.h"
#include "wma.h"
#undef NDEBUG
#include <assert.h>
#define EXPVLCBITS 8
#define EXPMAX ((19+EXPVLCBITS-1)/EXPVLCBITS)
#define HGAINVLCBITS 9
#define HGAINMAX ((13+HGAINVLCBITS-1)/HGAINVLCBITS)
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
#ifdef TRACE
static void dump_shorts(WMACodecContext *s, const char *name, const short *tab, int n)
{
int i;
tprintf(s->avctx, "%s[%d]:\n", name, n);
for(i=0;i<n;i++) {
if ((i & 7) == 0)
tprintf(s->avctx, "%4d: ", i);
tprintf(s->avctx, " %5d.0", tab[i]);
if ((i & 7) == 7)
tprintf(s->avctx, "\n");
}
}
static void dump_floats(WMACodecContext *s, const char *name, int prec, const float *tab, int n)
{
int i;
tprintf(s->avctx, "%s[%d]:\n", name, n);
for(i=0;i<n;i++) {
if ((i & 7) == 0)
tprintf(s->avctx, "%4d: ", i);
tprintf(s->avctx, " %8.*f", prec, tab[i]);
if ((i & 7) == 7)
tprintf(s->avctx, "\n");
}
if ((i & 7) != 0)
tprintf(s->avctx, "\n");
}
#endif
static int wma_decode_init(AVCodecContext * avctx)
{
WMACodecContext *s = avctx->priv_data;
int i, flags2;
uint8_t *extradata;
s->avctx = avctx;
/* extract flag infos */
flags2 = 0;
extradata = avctx->extradata;
if (avctx->codec->id == CODEC_ID_WMAV1 && avctx->extradata_size >= 4) {
flags2 = AV_RL16(extradata+2);
} else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) {
flags2 = AV_RL16(extradata+4);
}
// for(i=0; i<avctx->extradata_size; i++)
// av_log(NULL, AV_LOG_ERROR, "%02X ", extradata[i]);
s->use_exp_vlc = flags2 & 0x0001;
s->use_bit_reservoir = flags2 & 0x0002;
s->use_variable_block_len = flags2 & 0x0004;
if(ff_wma_init(avctx, flags2)<0)
return -1;
/* 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, 1.0);
if (s->use_noise_coding) {
init_vlc(&s->hgain_vlc, HGAINVLCBITS, sizeof(ff_wma_hgain_huffbits),
ff_wma_hgain_huffbits, 1, 1,
ff_wma_hgain_huffcodes, 2, 2, 0);
}
if (s->use_exp_vlc) {
init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits), //FIXME move out of context
ff_aac_scalefactor_bits, 1, 1,
ff_aac_scalefactor_code, 4, 4, 0);
} else {
wma_lsp_to_curve_init(s, s->frame_len);
}
avctx->sample_fmt = SAMPLE_FMT_S16;
return 0;
}
/**
* 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(WMACodecContext *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(WMACodecContext *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
* @todo optimize it further with SSE/3Dnow
*/
static void wma_lsp_to_curve(WMACodecContext *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(WMACodecContext *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] = ff_wma_lsp_codebook[i][val];
}
wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
s->block_len, lsp_coefs);
}
/** pow(10, i / 16.0) for i in -60..95 */
static const float pow_tab[] = {
1.7782794100389e-04, 2.0535250264571e-04,
2.3713737056617e-04, 2.7384196342644e-04,
3.1622776601684e-04, 3.6517412725484e-04,
4.2169650342858e-04, 4.8696752516586e-04,
5.6234132519035e-04, 6.4938163157621e-04,
7.4989420933246e-04, 8.6596432336006e-04,
1.0000000000000e-03, 1.1547819846895e-03,
1.3335214321633e-03, 1.5399265260595e-03,
1.7782794100389e-03, 2.0535250264571e-03,
2.3713737056617e-03, 2.7384196342644e-03,
3.1622776601684e-03, 3.6517412725484e-03,
4.2169650342858e-03, 4.8696752516586e-03,
5.6234132519035e-03, 6.4938163157621e-03,
7.4989420933246e-03, 8.6596432336006e-03,
1.0000000000000e-02, 1.1547819846895e-02,
1.3335214321633e-02, 1.5399265260595e-02,
1.7782794100389e-02, 2.0535250264571e-02,
2.3713737056617e-02, 2.7384196342644e-02,
3.1622776601684e-02, 3.6517412725484e-02,
4.2169650342858e-02, 4.8696752516586e-02,
5.6234132519035e-02, 6.4938163157621e-02,
7.4989420933246e-02, 8.6596432336007e-02,
1.0000000000000e-01, 1.1547819846895e-01,
1.3335214321633e-01, 1.5399265260595e-01,
1.7782794100389e-01, 2.0535250264571e-01,
2.3713737056617e-01, 2.7384196342644e-01,
3.1622776601684e-01, 3.6517412725484e-01,
4.2169650342858e-01, 4.8696752516586e-01,
5.6234132519035e-01, 6.4938163157621e-01,
7.4989420933246e-01, 8.6596432336007e-01,
1.0000000000000e+00, 1.1547819846895e+00,
1.3335214321633e+00, 1.5399265260595e+00,
1.7782794100389e+00, 2.0535250264571e+00,
2.3713737056617e+00, 2.7384196342644e+00,
3.1622776601684e+00, 3.6517412725484e+00,
4.2169650342858e+00, 4.8696752516586e+00,
5.6234132519035e+00, 6.4938163157621e+00,
7.4989420933246e+00, 8.6596432336007e+00,
1.0000000000000e+01, 1.1547819846895e+01,
1.3335214321633e+01, 1.5399265260595e+01,
1.7782794100389e+01, 2.0535250264571e+01,
2.3713737056617e+01, 2.7384196342644e+01,
3.1622776601684e+01, 3.6517412725484e+01,
4.2169650342858e+01, 4.8696752516586e+01,
5.6234132519035e+01, 6.4938163157621e+01,
7.4989420933246e+01, 8.6596432336007e+01,
1.0000000000000e+02, 1.1547819846895e+02,
1.3335214321633e+02, 1.5399265260595e+02,
1.7782794100389e+02, 2.0535250264571e+02,
2.3713737056617e+02, 2.7384196342644e+02,
3.1622776601684e+02, 3.6517412725484e+02,
4.2169650342858e+02, 4.8696752516586e+02,
5.6234132519035e+02, 6.4938163157621e+02,
7.4989420933246e+02, 8.6596432336007e+02,
1.0000000000000e+03, 1.1547819846895e+03,
1.3335214321633e+03, 1.5399265260595e+03,
1.7782794100389e+03, 2.0535250264571e+03,
2.3713737056617e+03, 2.7384196342644e+03,
3.1622776601684e+03, 3.6517412725484e+03,
4.2169650342858e+03, 4.8696752516586e+03,
5.6234132519035e+03, 6.4938163157621e+03,
7.4989420933246e+03, 8.6596432336007e+03,
1.0000000000000e+04, 1.1547819846895e+04,
1.3335214321633e+04, 1.5399265260595e+04,
1.7782794100389e+04, 2.0535250264571e+04,
2.3713737056617e+04, 2.7384196342644e+04,
3.1622776601684e+04, 3.6517412725484e+04,
4.2169650342858e+04, 4.8696752516586e+04,
5.6234132519035e+04, 6.4938163157621e+04,
7.4989420933246e+04, 8.6596432336007e+04,
1.0000000000000e+05, 1.1547819846895e+05,
1.3335214321633e+05, 1.5399265260595e+05,
1.7782794100389e+05, 2.0535250264571e+05,
2.3713737056617e+05, 2.7384196342644e+05,
3.1622776601684e+05, 3.6517412725484e+05,
4.2169650342858e+05, 4.8696752516586e+05,
5.6234132519035e+05, 6.4938163157621e+05,
7.4989420933246e+05, 8.6596432336007e+05,
};
/**
* decode exponents coded with VLC codes
*/
static int decode_exp_vlc(WMACodecContext *s, int ch)
{
int last_exp, n, code;
const uint16_t *ptr;
float v, max_scale;
uint32_t *q, *q_end, iv;
const float *ptab = pow_tab + 60;
const uint32_t *iptab = (const uint32_t*)ptab;
ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
q = (uint32_t *)s->exponents[ch];
q_end = q + s->block_len;
max_scale = 0;
if (s->version == 1) {
last_exp = get_bits(&s->gb, 5) + 10;
v = ptab[last_exp];
iv = iptab[last_exp];
max_scale = v;
n = *ptr++;
switch (n & 3) do {
case 0: *q++ = iv;
case 3: *q++ = iv;
case 2: *q++ = iv;
case 1: *q++ = iv;
} while ((n -= 4) > 0);
}else
last_exp = 36;
while (q < q_end) {
code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "Exponent vlc invalid\n");
return -1;
}
/* NOTE: this offset is the same as MPEG4 AAC ! */
last_exp += code - 60;
if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab)) {
av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
last_exp);
return -1;
}
v = ptab[last_exp];
iv = iptab[last_exp];
if (v > max_scale)
max_scale = v;
n = *ptr++;
switch (n & 3) do {
case 0: *q++ = iv;
case 3: *q++ = iv;
case 2: *q++ = iv;
case 1: *q++ = iv;
} while ((n -= 4) > 0);
}
s->max_exponent[ch] = max_scale;
return 0;
}
/**
* Apply MDCT window and add into output.
*
* We ensure that when the windows overlap their squared sum
* is always 1 (MDCT reconstruction rule).
*/
static void wma_window(WMACodecContext *s, float *out)
{
float *in = s->output;
int block_len, bsize, n;
/* left part */
if (s->block_len_bits <= s->prev_block_len_bits) {
block_len = s->block_len;
bsize = s->frame_len_bits - s->block_len_bits;
s->dsp.vector_fmul_add(out, in, s->windows[bsize],
out, block_len);
} else {
block_len = 1 << s->prev_block_len_bits;
n = (s->block_len - block_len) / 2;
bsize = s->frame_len_bits - s->prev_block_len_bits;
s->dsp.vector_fmul_add(out+n, in+n, s->windows[bsize],
out+n, block_len);
memcpy(out+n+block_len, in+n+block_len, n*sizeof(float));
}
out += s->block_len;
in += s->block_len;
/* right part */
if (s->block_len_bits <= s->next_block_len_bits) {
block_len = s->block_len;
bsize = s->frame_len_bits - s->block_len_bits;
s->dsp.vector_fmul_reverse(out, in, s->windows[bsize], block_len);
} else {
block_len = 1 << s->next_block_len_bits;
n = (s->block_len - block_len) / 2;
bsize = s->frame_len_bits - s->next_block_len_bits;
memcpy(out, in, n*sizeof(float));
s->dsp.vector_fmul_reverse(out+n, in+n, s->windows[bsize], block_len);
memset(out+n+block_len, 0, n*sizeof(float));
}
}
/**
* @return 0 if OK. 1 if last block of frame. return -1 if
* unrecorrable error.
*/
static int wma_decode_block(WMACodecContext *s)
{
int n, v, a, ch, bsize;
int coef_nb_bits, total_gain;
int nb_coefs[MAX_CHANNELS];
float mdct_norm;
#ifdef TRACE
tprintf(s->avctx, "***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){
av_log(s->avctx, AV_LOG_ERROR, "prev_block_len_bits %d out of range\n", s->frame_len_bits - v);
return -1;
}
s->prev_block_len_bits = s->frame_len_bits - v;
v = get_bits(&s->gb, n);
if (v >= s->nb_block_sizes){
av_log(s->avctx, AV_LOG_ERROR, "block_len_bits %d out of range\n", s->frame_len_bits - v);
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){
av_log(s->avctx, AV_LOG_ERROR, "next_block_len_bits %d out of range\n", s->frame_len_bits - v);
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){
av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
return -1;
}
if (s->nb_channels == 2) {
s->ms_stereo = get_bits1(&s->gb);
}
v = 0;
for(ch = 0; ch < s->nb_channels; ch++) {
a = get_bits1(&s->gb);
s->channel_coded[ch] = a;
v |= a;
}
bsize = s->frame_len_bits - s->block_len_bits;
/* if no channel coded, no need to go further */
/* XXX: fix potential framing problems */
if (!v)
goto next;
/* 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;
}
coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);
/* 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_bits1(&s->gb);
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_vlc2(&s->gb, s->hgain_vlc.table, HGAINVLCBITS, HGAINMAX);
if (code < 0){
av_log(s->avctx, AV_LOG_ERROR, "hgain vlc invalid\n");
return -1;
}
val += code - 18;
}
s->high_band_values[ch][i] = val;
}
}
}
}
}
/* exponents can be reused in short blocks. */
if ((s->block_len_bits == s->frame_len_bits) ||
get_bits1(&s->gb)) {
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);
}
s->exponents_bsize[ch] = bsize;
}
}
}
/* parse spectral coefficients : just RLE encoding */
for(ch = 0; ch < s->nb_channels; ch++) {
if (s->channel_coded[ch]) {
int tindex;
WMACoef* ptr = &s->coefs1[ch][0];
/* special VLC tables are used for ms stereo because
there is potentially less energy there */
tindex = (ch == 1 && s->ms_stereo);
memset(ptr, 0, s->block_len * sizeof(WMACoef));
ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],
s->level_table[tindex], s->run_table[tindex],
0, ptr, 0, nb_coefs[ch],
s->block_len, s->frame_len_bits, coef_nb_bits);
}
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]) {
WMACoef *coefs1;
float *coefs, *exponents, mult, mult1, noise;
int i, j, n, n1, last_high_band, esize;
float exp_power[HIGH_BAND_MAX_SIZE];
coefs1 = s->coefs1[ch];
exponents = s->exponents[ch];
esize = s->exponents_bsize[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[i<<bsize>>esize] * mult1;
s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
}
n1 = s->exponent_high_sizes[bsize];
/* compute power of high bands */
exponents = s->exponents[ch] +
(s->high_band_start[bsize]<<bsize>>esize);
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 = exponents[i<<bsize>>esize];
e2 += v * v;
}
exp_power[j] = e2 / n;
last_high_band = j;
tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
}
exponents += n<<bsize>>esize;
}
/* main freqs and high freqs */
exponents = s->exponents[ch] + (s->coefs_start<<bsize>>esize);
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++ = noise *
exponents[i<<bsize>>esize] * mult1;
}
exponents += n<<bsize>>esize;
} 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[i<<bsize>>esize] * mult;
}
exponents += n<<bsize>>esize;
}
}
/* very high freqs : noise */
n = s->block_len - s->coefs_end[bsize];
mult1 = mult * exponents[((-1<<bsize))>>esize];
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<<bsize>>esize] * 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(s, "exponents", 3, s->exponents[ch], s->block_len);
dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
}
}
#endif
if (s->ms_stereo && s->channel_coded[1]) {
/* 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(s->avctx, "rare ms-stereo case happened\n");
memset(s->coefs[0], 0, sizeof(float) * s->block_len);
s->channel_coded[0] = 1;
}
s->dsp.butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
}
next:
for(ch = 0; ch < s->nb_channels; ch++) {
int n4, index;
n4 = s->block_len / 2;
if(s->channel_coded[ch]){
ff_imdct_calc(&s->mdct_ctx[bsize], s->output, s->coefs[ch]);
}else if(!(s->ms_stereo && ch==1))
memset(s->output, 0, sizeof(s->output));
/* multiply by the window and add in the frame */
index = (s->frame_len / 2) + s->block_pos - n4;
wma_window(s, &s->frame_out[ch][index]);
}
/* 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(WMACodecContext *s, int16_t *samples)
{
int ret, i, n, ch, incr;
int16_t *ptr;
float *iptr;
#ifdef TRACE
tprintf(s->avctx, "***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;
if (s->dsp.float_to_int16_interleave == ff_float_to_int16_interleave_c) {
for(ch = 0; ch < s->nb_channels; ch++) {
ptr = samples + ch;
iptr = s->frame_out[ch];
for(i=0;i<n;i++) {
*ptr = av_clip_int16(lrintf(*iptr++));
ptr += incr;
}
/* prepare for next block */
memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
s->frame_len * sizeof(float));
}
} else {
float *output[MAX_CHANNELS];
for (ch = 0; ch < MAX_CHANNELS; ch++)
output[ch] = s->frame_out[ch];
s->dsp.float_to_int16_interleave(samples, (const float **)output, n, incr);
for(ch = 0; ch < incr; ch++) {
/* prepare for next block */
memmove(&s->frame_out[ch][0], &s->frame_out[ch][n], n * sizeof(float));
}
}
#ifdef TRACE
dump_shorts(s, "samples", samples, n * s->nb_channels);
#endif
return 0;
}
static int wma_decode_superframe(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
WMACodecContext *s = avctx->priv_data;
int nb_frames, bit_offset, i, pos, len;
uint8_t *q;
int16_t *samples;
tprintf(avctx, "***decode_superframe:\n");
if(buf_size==0){
s->last_superframe_len = 0;
return 0;
}
if (buf_size < s->block_align)
return 0;
buf_size = s->block_align;
samples = data;
init_get_bits(&s->gb, buf, buf_size*8);
if (s->use_bit_reservoir) {
/* read super frame header */
skip_bits(&s->gb, 4); /* super frame index */
nb_frames = get_bits(&s->gb, 4) - 1;
if((nb_frames+1) * s->nb_channels * s->frame_len * sizeof(int16_t) > *data_size){
av_log(s->avctx, AV_LOG_ERROR, "Insufficient output space\n");
goto fail;
}
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 > 7) {
*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) {
av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
goto fail;
}
s->last_superframe_len = len;
memcpy(s->last_superframe, buf + pos, len);
} else {
if(s->nb_channels * s->frame_len * sizeof(int16_t) > *data_size){
av_log(s->avctx, AV_LOG_ERROR, "Insufficient output space\n");
goto fail;
}
/* single frame decode */
if (wma_decode_frame(s, samples) < 0)
goto fail;
samples += s->nb_channels * s->frame_len;
}
//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d outbytes:%d eaten:%d\n", s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len, (int8_t *)samples - (int8_t *)data, s->block_align);
*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 av_cold void flush(AVCodecContext *avctx)
{
WMACodecContext *s = avctx->priv_data;
s->last_bitoffset=
s->last_superframe_len= 0;
}
AVCodec wmav1_decoder =
{
"wmav1",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_WMAV1,
sizeof(WMACodecContext),
wma_decode_init,
NULL,
ff_wma_end,
wma_decode_superframe,
.flush=flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
};
AVCodec wmav2_decoder =
{
"wmav2",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_WMAV2,
sizeof(WMACodecContext),
wma_decode_init,
NULL,
ff_wma_end,
wma_decode_superframe,
.flush=flush,
.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/wmadec.c | C | asf20 | 32,135 |
/*
* SGI image encoder
* Todd Kirby <doubleshot@pacbell.net>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "avcodec.h"
#include "bytestream.h"
#include "sgi.h"
#include "rle.h"
#define SGI_SINGLE_CHAN 2
#define SGI_MULTI_CHAN 3
typedef struct SgiContext {
AVFrame picture;
} SgiContext;
static av_cold int encode_init(AVCodecContext *avctx)
{
SgiContext *s = avctx->priv_data;
avcodec_get_frame_defaults(&s->picture);
avctx->coded_frame = &s->picture;
return 0;
}
static int encode_frame(AVCodecContext *avctx, unsigned char *buf,
int buf_size, void *data)
{
SgiContext *s = avctx->priv_data;
AVFrame * const p = &s->picture;
uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf;
int x, y, z, length, tablesize;
unsigned int width, height, depth, dimension;
unsigned char *orig_buf = buf, *end_buf = buf + buf_size;
*p = *(AVFrame*)data;
p->pict_type = FF_I_TYPE;
p->key_frame = 1;
width = avctx->width;
height = avctx->height;
switch (avctx->pix_fmt) {
case PIX_FMT_GRAY8:
dimension = SGI_SINGLE_CHAN;
depth = SGI_GRAYSCALE;
break;
case PIX_FMT_RGB24:
dimension = SGI_MULTI_CHAN;
depth = SGI_RGB;
break;
case PIX_FMT_RGBA:
dimension = SGI_MULTI_CHAN;
depth = SGI_RGBA;
break;
default:
return AVERROR_INVALIDDATA;
}
tablesize = depth * height * 4;
length = tablesize * 2 + SGI_HEADER_SIZE;
if (buf_size < length) {
av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", length, buf_size);
return -1;
}
/* Encode header. */
bytestream_put_be16(&buf, SGI_MAGIC);
bytestream_put_byte(&buf, avctx->coder_type != FF_CODER_TYPE_RAW); /* RLE 1 - VERBATIM 0*/
bytestream_put_byte(&buf, 1); /* bytes_per_channel */
bytestream_put_be16(&buf, dimension);
bytestream_put_be16(&buf, width);
bytestream_put_be16(&buf, height);
bytestream_put_be16(&buf, depth);
/* The rest are constant in this implementation. */
bytestream_put_be32(&buf, 0L); /* pixmin */
bytestream_put_be32(&buf, 255L); /* pixmax */
bytestream_put_be32(&buf, 0L); /* dummy */
/* name */
memset(buf, 0, SGI_HEADER_SIZE);
buf += 80;
/* colormap */
bytestream_put_be32(&buf, 0L);
/* The rest of the 512 byte header is unused. */
buf += 404;
offsettab = buf;
if (avctx->coder_type != FF_CODER_TYPE_RAW) {
/* Skip RLE offset table. */
buf += tablesize;
lengthtab = buf;
/* Skip RLE length table. */
buf += tablesize;
/* Make an intermediate consecutive buffer. */
if (!(encode_buf = av_malloc(width)))
return -1;
for (z = 0; z < depth; z++) {
in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;
for (y = 0; y < height; y++) {
bytestream_put_be32(&offsettab, buf - orig_buf);
for (x = 0; x < width; x++)
encode_buf[x] = in_buf[depth * x];
if ((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) {
av_free(encode_buf);
return -1;
}
buf += length;
bytestream_put_byte(&buf, 0);
bytestream_put_be32(&lengthtab, length + 1);
in_buf -= p->linesize[0];
}
}
av_free(encode_buf);
} else {
for (z = 0; z < depth; z++) {
in_buf = p->data[0] + p->linesize[0] * (height - 1) + z;
for (y = 0; y < height; y++) {
for (x = 0; x < width * depth; x += depth)
bytestream_put_byte(&buf, in_buf[x]);
in_buf -= p->linesize[0];
}
}
}
/* total length */
return buf - orig_buf;
}
AVCodec sgi_encoder = {
"sgi",
AVMEDIA_TYPE_VIDEO,
CODEC_ID_SGI,
sizeof(SgiContext),
encode_init,
encode_frame,
NULL,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_GRAY8, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("SGI image"),
};
| 123linslouis-android-video-cutter | jni/libavcodec/sgienc.c | C | asf20 | 4,982 |
/*
* Simple IDCT
*
* Copyright (c) 2001 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* simple idct header.
*/
#ifndef AVCODEC_SIMPLE_IDCT_H
#define AVCODEC_SIMPLE_IDCT_H
#include <stdint.h>
#include "dsputil.h"
void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block);
void ff_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 ff_simple_idct(DCTELEM *block);
void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block);
void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block);
void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block);
void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block);
#endif /* AVCODEC_SIMPLE_IDCT_H */
| 123linslouis-android-video-cutter | jni/libavcodec/simple_idct.h | C | asf20 | 1,691 |
/*
* COOK compatible decoder data
* Copyright (c) 2003 Sascha Sommer
* Copyright (c) 2005 Benjamin Larsson
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Cook AKA RealAudio G2 compatible decoderdata
*/
#ifndef AVCODEC_COOKDATA_H
#define AVCODEC_COOKDATA_H
#include <stdint.h>
/* various data tables */
static const int expbits_tab[8] = {
52,47,43,37,29,22,16,0,
};
static const float dither_tab[8] = {
0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107,
};
static const float quant_centroid_tab[7][14] = {
{ 0.000, 0.392, 0.761, 1.120, 1.477, 1.832, 2.183, 2.541, 2.893, 3.245, 3.598, 3.942, 4.288, 4.724 },
{ 0.000, 0.544, 1.060, 1.563, 2.068, 2.571, 3.072, 3.562, 4.070, 4.620, 0.000, 0.000, 0.000, 0.000 },
{ 0.000, 0.746, 1.464, 2.180, 2.882, 3.584, 4.316, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
{ 0.000, 1.006, 2.000, 2.993, 3.985, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
{ 0.000, 1.321, 2.703, 3.983, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
{ 0.000, 1.657, 3.491, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 },
{ 0.000, 1.964, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 }
};
static const int invradix_tab[7] = {
74899, 104858, 149797, 209716, 262144, 349526, 524288,
};
static const int kmax_tab[7] = {
13, 9, 6, 4, 3, 2, 1,
};
static const int vd_tab[7] = {
2, 2, 2, 4, 4, 5, 5,
};
static const int vpr_tab[7] = {
10, 10, 10, 5, 5, 4, 4,
};
/* VLC data */
static const int vhsize_tab[7] = {
191, 97, 48, 607, 246, 230, 32,
};
static const int vhvlcsize_tab[7] = {
8, 7, 7, 10, 9, 9, 6,
};
static const uint8_t envelope_quant_index_huffbits[13][24] = {
{ 4, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 5, 7, 8, 9, 11, 11, 12, 12, 12, 12 },
{ 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 7, 9, 11, 12, 13, 15, 15, 15, 16, 16 },
{ 12, 10, 8, 6, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4, 5, 5, 7, 9, 11, 13, 14, 14 },
{ 13, 10, 9, 9, 7, 7, 5, 5, 4, 3, 3, 3, 3, 3, 4, 4, 4, 5, 7, 9, 11, 13, 13, 13 },
{ 12, 13, 10, 8, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 5, 5, 6, 7, 9, 11, 14, 14 },
{ 12, 11, 9, 8, 8, 7, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 5, 7, 8, 10, 13, 14, 14 },
{ 15, 16, 15, 12, 10, 8, 6, 5, 4, 3, 3, 3, 2, 3, 4, 5, 5, 7, 9, 11, 13, 16, 16, 16 },
{ 14, 14, 11, 10, 9, 7, 7, 5, 5, 4, 3, 3, 2, 3, 3, 4, 5, 7, 9, 9, 12, 14, 15, 15 },
{ 9, 9, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 13 },
{ 14, 12, 10, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 8, 8, 9, 11, 14, 14, 14 },
{ 13, 10, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 2, 3, 4, 5, 6, 8, 9, 9, 11, 12, 14, 14 },
{ 16, 13, 12, 11, 9, 6, 5, 5, 4, 4, 4, 3, 2, 3, 3, 4, 5, 7, 8, 10, 14, 16, 16, 16 },
{ 13, 14, 14, 14, 10, 8, 7, 7, 5, 4, 3, 3, 2, 3, 3, 4, 5, 5, 7, 9, 11, 14, 14, 14 },
};
static const uint16_t envelope_quant_index_huffcodes[13][24] = {
{0x0006, 0x003e, 0x001c, 0x001d, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x0000, 0x0001,
0x0002, 0x000d, 0x001e, 0x007e, 0x00fe, 0x01fe, 0x07fc, 0x07fd, 0x0ffc, 0x0ffd, 0x0ffe, 0x0fff},
{0x03fe, 0x00fe, 0x003e, 0x001c, 0x001d, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005,
0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x0ffe, 0x1ffe, 0x7ffc, 0x7ffd, 0x7ffe, 0xfffe, 0xffff},
{0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x0000,
0x0001, 0x0002, 0x000c, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0x3ffe, 0x3fff},
{0x1ffc, 0x03fe, 0x01fc, 0x01fd, 0x007c, 0x007d, 0x001c, 0x001d, 0x000a, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x000b, 0x000c, 0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffd, 0x1ffe, 0x1fff},
{0x0ffe, 0x1ffe, 0x03fe, 0x00fe, 0x003c, 0x003d, 0x001a, 0x001b, 0x000a, 0x000b, 0x0000, 0x0001,
0x0002, 0x0003, 0x0004, 0x000c, 0x001c, 0x001d, 0x003e, 0x007e, 0x01fe, 0x07fe, 0x3ffe, 0x3fff},
{0x0ffe, 0x07fe, 0x01fe, 0x00fc, 0x00fd, 0x007c, 0x001c, 0x000a, 0x000b, 0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x000c, 0x000d, 0x001d, 0x001e, 0x007d, 0x00fe, 0x03fe, 0x1ffe, 0x3ffe, 0x3fff},
{0x7ffc, 0xfffc, 0x7ffd, 0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x000c, 0x0002, 0x0003, 0x0004,
0x0000, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0xfffd, 0xfffe, 0xffff},
{0x3ffc, 0x3ffd, 0x07fe, 0x03fe, 0x01fc, 0x007c, 0x007d, 0x001c, 0x001d, 0x000c, 0x0002, 0x0003,
0x0000, 0x0004, 0x0005, 0x000d, 0x001e, 0x007e, 0x01fd, 0x01fe, 0x0ffe, 0x3ffe, 0x7ffe, 0x7fff},
{0x01fc, 0x01fd, 0x01fe, 0x00fc, 0x007c, 0x003c, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
0x0004, 0x0005, 0x000d, 0x001d, 0x003d, 0x007d, 0x00fd, 0x03fe, 0x07fe, 0x0ffe, 0x1ffe, 0x1fff},
{0x3ffc, 0x0ffe, 0x03fe, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
0x0004, 0x0005, 0x000d, 0x001d, 0x003e, 0x00fd, 0x00fe, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
{0x1ffe, 0x03fe, 0x01fc, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000a, 0x000b, 0x000c, 0x0002, 0x0003,
0x0000, 0x0004, 0x000d, 0x001d, 0x003e, 0x00fd, 0x01fd, 0x01fe, 0x07fe, 0x0ffe, 0x3ffe, 0x3fff},
{0xfffc, 0x1ffe, 0x0ffe, 0x07fe, 0x01fe, 0x003e, 0x001c, 0x001d, 0x000a, 0x000b, 0x000c, 0x0002,
0x0000, 0x0003, 0x0004, 0x000d, 0x001e, 0x007e, 0x00fe, 0x03fe, 0x3ffe, 0xfffd, 0xfffe, 0xffff},
{0x1ffc, 0x3ffa, 0x3ffb, 0x3ffc, 0x03fe, 0x00fe, 0x007c, 0x007d, 0x001c, 0x000c, 0x0002, 0x0003,
0x0000, 0x0004, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
};
static const uint8_t cvh_huffbits0[191] = {
1, 4, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10,
11, 11, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9,
9, 10, 11, 11, 5, 6, 7, 8, 8, 9, 9, 9,
9, 10, 10, 10, 11, 12, 6, 7, 8, 9, 9, 9,
9, 10, 10, 10, 10, 11, 12, 13, 7, 7, 8, 9,
9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 8, 8,
9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 14,
8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13,
13, 15, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12,
12, 13, 14, 15, 9, 9, 9, 10, 10, 10, 11, 11,
12, 13, 12, 14, 15, 16, 9, 9, 10, 10, 10, 10,
11, 12, 12, 14, 14, 16, 16, 0, 9, 9, 10, 10,
11, 11, 12, 13, 13, 14, 14, 15, 0, 0, 10, 10,
10, 11, 11, 12, 12, 13, 15, 15, 16, 0, 0, 0,
11, 11, 11, 12, 13, 13, 13, 15, 16, 16, 0, 0,
0, 0, 11, 11, 12, 13, 13, 14, 15, 16, 16,
};
static const uint16_t cvh_huffcodes0[191] = {
0x0000,0x0008,0x002c,0x002d,0x0062,0x0063,0x00d4,0x00d5,0x00d6,0x01c6,0x01c7,0x03ca,
0x07d6,0x07d7,0x0009,0x0014,0x002e,0x0064,0x0065,0x00d7,0x00d8,0x01c8,0x01c9,0x01ca,
0x01cb,0x03cb,0x07d8,0x07d9,0x0015,0x002f,0x0066,0x00d9,0x00da,0x01cc,0x01cd,0x01ce,
0x01cf,0x03cc,0x03cd,0x03ce,0x07da,0x0fe4,0x0030,0x0067,0x00db,0x01d0,0x01d1,0x01d2,
0x01d3,0x03cf,0x03d0,0x03d1,0x03d2,0x07db,0x0fe5,0x1fea,0x0068,0x0069,0x00dc,0x01d4,
0x01d5,0x01d6,0x03d3,0x03d4,0x03d5,0x03d6,0x07dc,0x07dd,0x0fe6,0x1feb,0x00dd,0x00de,
0x01d7,0x01d8,0x01d9,0x03d7,0x03d8,0x03d9,0x03da,0x07de,0x07df,0x0fe7,0x1fec,0x3ff2,
0x00df,0x00e0,0x01da,0x01db,0x03db,0x03dc,0x07e0,0x07e1,0x07e2,0x0fe8,0x0fe9,0x1fed,
0x1fee,0x7ff4,0x00e1,0x00e2,0x01dc,0x01dd,0x03dd,0x03de,0x07e3,0x07e4,0x07e5,0x0fea,
0x0feb,0x1fef,0x3ff3,0x7ff5,0x01de,0x01df,0x01e0,0x03df,0x03e0,0x03e1,0x07e6,0x07e7,
0x0fec,0x1ff0,0x0fed,0x3ff4,0x7ff6,0xfff8,0x01e1,0x01e2,0x03e2,0x03e3,0x03e4,0x03e5,
0x07e8,0x0fee,0x0fef,0x3ff5,0x3ff6,0xfff9,0xfffa,0xfffa,0x01e3,0x01e4,0x03e6,0x03e7,
0x07e9,0x07ea,0x0ff0,0x1ff1,0x1ff2,0x3ff7,0x3ff8,0x7ff7,0x7ff7,0xfffa,0x03e8,0x03e9,
0x03ea,0x07eb,0x07ec,0x0ff1,0x0ff2,0x1ff3,0x7ff8,0x7ff9,0xfffb,0x3ff8,0x7ff7,0x7ff7,
0x07ed,0x07ee,0x07ef,0x0ff3,0x1ff4,0x1ff5,0x1ff6,0x7ffa,0xfffc,0xfffd,0xfffb,0xfffb,
0x3ff8,0x7ff7,0x07f0,0x07f1,0x0ff4,0x1ff7,0x1ff8,0x3ff9,0x7ffb,0xfffe,0xffff,
};
static const uint8_t cvh_huffbits1[97] = {
1, 4, 5, 6, 7, 8, 8, 9, 10, 10, 4, 5,
6, 7, 7, 8, 8, 9, 9, 11, 5, 5, 6, 7,
8, 8, 9, 9, 10, 11, 6, 6, 7, 8, 8, 9,
9, 10, 11, 12, 7, 7, 8, 8, 9, 9, 10, 11,
11, 13, 8, 8, 8, 9, 9, 10, 10, 11, 12, 14,
8, 8, 8, 9, 10, 11, 11, 12, 13, 15, 9, 9,
9, 10, 11, 12, 12, 14, 14, 0, 9, 9, 9, 10,
11, 12, 14, 16, 0, 0, 10, 10, 11, 12, 13, 14,
16,
};
static const uint16_t cvh_huffcodes1[97] = {
0x0000,0x0008,0x0014,0x0030,0x006a,0x00e2,0x00e3,0x01e4,0x03ec,0x03ed,0x0009,0x0015,
0x0031,0x006b,0x006c,0x00e4,0x00e5,0x01e5,0x01e6,0x07f0,0x0016,0x0017,0x0032,0x006d,
0x00e6,0x00e7,0x01e7,0x01e8,0x03ee,0x07f1,0x0033,0x0034,0x006e,0x00e8,0x00e9,0x01e9,
0x01ea,0x03ef,0x07f2,0x0ff6,0x006f,0x0070,0x00ea,0x00eb,0x01eb,0x01ec,0x03f0,0x07f3,
0x07f4,0x1ffa,0x00ec,0x00ed,0x00ee,0x01ed,0x01ee,0x03f1,0x03f2,0x07f5,0x0ff7,0x3ffa,
0x00ef,0x00f0,0x00f1,0x01ef,0x03f3,0x07f6,0x07f7,0x0ff8,0x1ffb,0x7ffe,0x01f0,0x01f1,
0x01f2,0x03f4,0x07f8,0x0ff9,0x0ffa,0x3ffb,0x3ffc,0x0000,0x01f3,0x01f4,0x01f5,0x03f5,
0x07f9,0x0ffb,0x3ffd,0xfffe,0x0000,0x0000,0x03f6,0x03f7,0x07fa,0x0ffc,0x1ffc,0x3ffe,
0xffff,
};
static const uint8_t cvh_huffbits2[48] = {
1, 4, 5, 7, 8, 9, 10, 3, 4, 5, 7, 8,
9, 10, 5, 5, 6, 7, 8, 10, 10, 7, 6, 7,
8, 9, 10, 12, 8, 8, 8, 9, 10, 12, 14, 8,
9, 9, 10, 11, 15, 16, 9, 10, 11, 12, 13, 16,
};
static const uint16_t cvh_huffcodes2[48] = {
0x0000,0x000a,0x0018,0x0074,0x00f2,0x01f4,0x03f6,0x0004,0x000b,0x0019,0x0075,0x00f3,
0x01f5,0x03f7,0x001a,0x001b,0x0038,0x0076,0x00f4,0x03f8,0x03f9,0x0077,0x0039,0x0078,
0x00f5,0x01f6,0x03fa,0x0ffc,0x00f6,0x00f7,0x00f8,0x01f7,0x03fb,0x0ffd,0x3ffe,0x00f9,
0x01f8,0x01f9,0x03fc,0x07fc,0x7ffe,0xfffe,0x01fa,0x03fd,0x07fd,0x0ffe,0x1ffe,0xffff,
};
static const uint8_t cvh_huffbits3[607] = {
2, 4, 6, 8, 10, 5, 5, 6, 8, 10, 7, 8,
8, 10, 12, 9, 9, 10, 12, 15, 10, 11, 13, 16,
16, 5, 6, 8, 10, 11, 5, 6, 8, 10, 12, 7,
7, 8, 10, 13, 9, 9, 10, 12, 15, 12, 11, 13,
16, 16, 7, 9, 10, 12, 15, 7, 8, 10, 12, 13,
9, 9, 11, 13, 16, 11, 11, 12, 14, 16, 12, 12,
14, 16, 0, 9, 11, 12, 16, 16, 9, 10, 13, 15,
16, 10, 11, 12, 16, 16, 13, 13, 16, 16, 16, 16,
16, 15, 16, 0, 11, 13, 16, 16, 15, 11, 13, 15,
16, 16, 13, 13, 16, 16, 0, 14, 16, 16, 16, 0,
16, 16, 0, 0, 0, 4, 6, 8, 10, 13, 6, 6,
8, 10, 13, 9, 8, 10, 12, 16, 10, 10, 11, 15,
16, 13, 12, 14, 16, 16, 5, 6, 8, 11, 13, 6,
6, 8, 10, 13, 8, 8, 9, 11, 14, 10, 10, 12,
12, 16, 13, 12, 13, 15, 16, 7, 8, 9, 12, 16,
7, 8, 10, 12, 14, 9, 9, 10, 13, 16, 11, 10,
12, 15, 16, 13, 13, 16, 16, 0, 9, 11, 13, 16,
16, 9, 10, 12, 15, 16, 10, 11, 13, 16, 16, 13,
12, 16, 16, 16, 16, 16, 16, 16, 0, 11, 13, 16,
16, 16, 11, 13, 16, 16, 16, 12, 13, 15, 16, 0,
16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 6, 8,
11, 13, 16, 8, 8, 10, 12, 16, 11, 10, 11, 13,
16, 12, 13, 13, 15, 16, 16, 16, 14, 16, 0, 6,
8, 10, 13, 16, 8, 8, 10, 12, 16, 10, 10, 11,
13, 16, 13, 12, 13, 16, 16, 14, 14, 14, 16, 0,
8, 9, 11, 13, 16, 8, 9, 11, 16, 14, 10, 10,
12, 15, 16, 12, 12, 13, 16, 16, 15, 16, 16, 16,
0, 10, 12, 15, 16, 16, 10, 12, 12, 14, 16, 12,
12, 13, 16, 16, 14, 15, 16, 16, 0, 16, 16, 16,
0, 0, 12, 15, 15, 16, 0, 13, 13, 16, 16, 0,
14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 0, 0,
0, 0, 0, 8, 10, 13, 15, 16, 10, 11, 13, 16,
16, 13, 13, 14, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 0, 8, 10, 11, 15, 16, 9, 10, 12,
16, 16, 12, 12, 15, 16, 16, 16, 14, 16, 16, 16,
16, 16, 16, 16, 0, 9, 11, 14, 16, 16, 10, 11,
13, 16, 16, 14, 13, 14, 16, 16, 16, 15, 15, 16,
0, 16, 16, 16, 0, 0, 11, 13, 16, 16, 16, 11,
13, 15, 16, 16, 13, 16, 16, 16, 0, 16, 16, 16,
16, 0, 16, 16, 0, 0, 0, 15, 16, 16, 16, 0,
14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 16, 16,
0, 0, 0, 0, 0, 0, 0, 0, 9, 13, 16, 16,
16, 11, 13, 16, 16, 16, 14, 15, 16, 16, 0, 15,
16, 16, 16, 0, 16, 16, 0, 0, 0, 9, 13, 15,
15, 16, 12, 13, 14, 16, 16, 16, 15, 16, 16, 0,
16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 11, 13,
15, 16, 0, 12, 14, 16, 16, 0, 16, 16, 16, 16,
0, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 16,
16, 16, 16, 0, 16, 16, 16, 16, 0, 16, 16, 16,
0, 0, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0,
16, 16, 0, 0, 0, 16, 16,
};
static const uint16_t cvh_huffcodes3[607] = {
0x0000,0x0004,0x0022,0x00c6,0x03b0,0x000c,0x000d,0x0023,0x00c7,0x03b1,0x005c,0x00c8,
0x00c9,0x03b2,0x0fa4,0x01c2,0x01c3,0x03b3,0x0fa5,0x7f72,0x03b4,0x07b2,0x1f9a,0xff24,
0xff25,0x000e,0x0024,0x00ca,0x03b5,0x07b3,0x000f,0x0025,0x00cb,0x03b6,0x0fa6,0x005d,
0x005e,0x00cc,0x03b7,0x1f9b,0x01c4,0x01c5,0x03b8,0x0fa7,0x7f73,0x0fa8,0x07b4,0x1f9c,
0xff26,0xff27,0x005f,0x01c6,0x03b9,0x0fa9,0x7f74,0x0060,0x00cd,0x03ba,0x0faa,0x1f9d,
0x01c7,0x01c8,0x07b5,0x1f9e,0xff28,0x07b6,0x07b7,0x0fab,0x3fa2,0xff29,0x0fac,0x0fad,
0x3fa3,0xff2a,0x3fa2,0x01c9,0x07b8,0x0fae,0xff2b,0xff2c,0x01ca,0x03bb,0x1f9f,0x7f75,
0xff2d,0x03bc,0x07b9,0x0faf,0xff2e,0xff2f,0x1fa0,0x1fa1,0xff30,0xff31,0xff32,0xff33,
0xff34,0x7f76,0xff35,0xff31,0x07ba,0x1fa2,0xff36,0xff37,0x7f77,0x07bb,0x1fa3,0x7f78,
0xff38,0xff39,0x1fa4,0x1fa5,0xff3a,0xff3b,0xff2e,0x3fa4,0xff3c,0xff3d,0xff3e,0xff31,
0xff3f,0xff40,0xff30,0xff31,0xff31,0x0005,0x0026,0x00ce,0x03bd,0x1fa6,0x0027,0x0028,
0x00cf,0x03be,0x1fa7,0x01cb,0x00d0,0x03bf,0x0fb0,0xff41,0x03c0,0x03c1,0x07bc,0x7f79,
0xff42,0x1fa8,0x0fb1,0x3fa5,0xff43,0xff44,0x0010,0x0029,0x00d1,0x07bd,0x1fa9,0x002a,
0x002b,0x00d2,0x03c2,0x1faa,0x00d3,0x00d4,0x01cc,0x07be,0x3fa6,0x03c3,0x03c4,0x0fb2,
0x0fb3,0xff45,0x1fab,0x0fb4,0x1fac,0x7f7a,0xff46,0x0061,0x00d5,0x01cd,0x0fb5,0xff47,
0x0062,0x00d6,0x03c5,0x0fb6,0x3fa7,0x01ce,0x01cf,0x03c6,0x1fad,0xff48,0x07bf,0x03c7,
0x0fb7,0x7f7b,0xff49,0x1fae,0x1faf,0xff4a,0xff4b,0x7f7b,0x01d0,0x07c0,0x1fb0,0xff4c,
0xff4d,0x01d1,0x03c8,0x0fb8,0x7f7c,0xff4e,0x03c9,0x07c1,0x1fb1,0xff4f,0xff50,0x1fb2,
0x0fb9,0xff51,0xff52,0xff53,0xff54,0xff55,0xff56,0xff57,0xff52,0x07c2,0x1fb3,0xff58,
0xff59,0xff5a,0x07c3,0x1fb4,0xff5b,0xff5c,0xff5d,0x0fba,0x1fb5,0x7f7d,0xff5e,0xff4f,
0xff5f,0xff60,0xff61,0xff62,0xff52,0xff63,0xff64,0xff51,0xff52,0xff52,0x002c,0x00d7,
0x07c4,0x1fb6,0xff65,0x00d8,0x00d9,0x03ca,0x0fbb,0xff66,0x07c5,0x03cb,0x07c6,0x1fb7,
0xff67,0x0fbc,0x1fb8,0x1fb9,0x7f7e,0xff68,0xff69,0xff6a,0x3fa8,0xff6b,0x7f7e,0x002d,
0x00da,0x03cc,0x1fba,0xff6c,0x00db,0x00dc,0x03cd,0x0fbd,0xff6d,0x03ce,0x03cf,0x07c7,
0x1fbb,0xff6e,0x1fbc,0x0fbe,0x1fbd,0xff6f,0xff70,0x3fa9,0x3faa,0x3fab,0xff71,0xff6f,
0x00dd,0x01d2,0x07c8,0x1fbe,0xff72,0x00de,0x01d3,0x07c9,0xff73,0x3fac,0x03d0,0x03d1,
0x0fbf,0x7f7f,0xff74,0x0fc0,0x0fc1,0x1fbf,0xff75,0xff76,0x7f80,0xff77,0xff78,0xff79,
0xff75,0x03d2,0x0fc2,0x7f81,0xff7a,0xff7b,0x03d3,0x0fc3,0x0fc4,0x3fad,0xff7c,0x0fc5,
0x0fc6,0x1fc0,0xff7d,0xff7e,0x3fae,0x7f82,0xff7f,0xff80,0xff80,0xff81,0xff82,0xff83,
0xff80,0xff80,0x0fc7,0x7f83,0x7f84,0xff84,0xff7a,0x1fc1,0x1fc2,0xff85,0xff86,0x3fad,
0x3faf,0xff87,0xff88,0xff89,0xff7d,0xff8a,0xff8b,0xff8c,0xff80,0xff80,0x3fae,0x7f82,
0xff7f,0xff80,0xff80,0x00df,0x03d4,0x1fc3,0x7f85,0xff8d,0x03d5,0x07ca,0x1fc4,0xff8e,
0xff8f,0x1fc5,0x1fc6,0x3fb0,0xff90,0xff91,0xff92,0xff93,0xff94,0xff95,0xff96,0xff97,
0xff98,0xff99,0xff9a,0xff95,0x00e0,0x03d6,0x07cb,0x7f86,0xff9b,0x01d4,0x03d7,0x0fc8,
0xff9c,0xff9d,0x0fc9,0x0fca,0x7f87,0xff9e,0xff9f,0xffa0,0x3fb1,0xffa1,0xffa2,0xffa3,
0xffa4,0xffa5,0xffa6,0xffa7,0xffa2,0x01d5,0x07cc,0x3fb2,0xffa8,0xffa9,0x03d8,0x07cd,
0x1fc7,0xffaa,0xffab,0x3fb3,0x1fc8,0x3fb4,0xffac,0xffad,0xffae,0x7f88,0x7f89,0xffaf,
0xffaf,0xffb0,0xffb1,0xffb2,0xffaf,0xffaf,0x07ce,0x1fc9,0xffb3,0xffb4,0xffb5,0x07cf,
0x1fca,0x7f8a,0xffb6,0xffb7,0x1fcb,0xffb8,0xffb9,0xffba,0xffba,0xffbb,0xffbc,0xffbd,
0xffbe,0xffbe,0xffbf,0xffc0,0xffbd,0xffbe,0xffbe,0x7f8b,0xffc1,0xffc2,0xffc3,0xffb4,
0x3fb5,0xffc4,0xffc5,0xffc6,0xffb6,0xffc7,0xffc8,0xffc9,0xffba,0xffba,0xffca,0xffcb,
0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,0x01d6,0x1fcc,0xffcc,0xffcd,
0xffce,0x07d0,0x1fcd,0xffcf,0xffd0,0xffd1,0x3fb6,0x7f8c,0xffd2,0xffd3,0xff90,0x7f8d,
0xffd4,0xffd5,0xffd6,0xff95,0xffd7,0xffd8,0xff94,0xff95,0xff95,0x01d7,0x1fce,0x7f8e,
0x7f8f,0xffd9,0x0fcb,0x1fcf,0x3fb7,0xffda,0xffdb,0xffdc,0x7f90,0xffdd,0xffde,0xff9e,
0xffdf,0xffe0,0xffe1,0xffe2,0xffa2,0xffe3,0xffe4,0xffa1,0xffa2,0xffa2,0x07d1,0x1fd0,
0x7f91,0xffe5,0xffa8,0x0fcc,0x3fb8,0xffe6,0xffe7,0xffaa,0xffe8,0xffe9,0xffea,0xffeb,
0xffac,0xffec,0xffed,0xffee,0xffaf,0xffaf,0xffae,0x7f88,0x7f89,0xffaf,0xffaf,0xffef,
0xfff0,0xfff1,0xfff2,0xffb4,0xfff3,0xfff4,0xfff5,0xfff6,0xffb6,0xfff7,0xfff8,0xfff9,
0xffba,0xffba,0xfffa,0xfffb,0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,
0xfffc,0xfffd,0xffb3,0xffb4,0xffb4,0xfffe,0xffff,
};
static const uint8_t cvh_huffbits4[246] = {
2, 4, 7, 10, 4, 5, 7, 10, 7, 8, 10, 14,
11, 11, 15, 15, 4, 5, 9, 12, 5, 5, 8, 12,
8, 7, 10, 15, 11, 11, 15, 15, 7, 9, 12, 15,
8, 8, 12, 15, 10, 10, 13, 15, 14, 14, 15, 0,
11, 13, 15, 15, 11, 13, 15, 15, 14, 15, 15, 0,
15, 15, 0, 0, 4, 5, 9, 13, 5, 6, 9, 13,
9, 9, 11, 15, 14, 13, 15, 15, 4, 6, 9, 12,
5, 6, 9, 13, 9, 8, 11, 15, 13, 12, 15, 15,
7, 9, 12, 15, 7, 8, 11, 15, 10, 10, 14, 15,
14, 15, 15, 0, 10, 12, 15, 15, 11, 13, 15, 15,
15, 15, 15, 0, 15, 15, 0, 0, 6, 9, 13, 14,
8, 9, 12, 15, 12, 12, 15, 15, 15, 15, 15, 0,
7, 9, 13, 15, 8, 9, 12, 15, 11, 12, 15, 15,
15, 15, 15, 0, 9, 11, 15, 15, 9, 11, 15, 15,
14, 14, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
14, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
9, 12, 15, 15, 12, 13, 15, 15, 15, 15, 15, 0,
15, 15, 0, 0, 10, 12, 15, 15, 12, 14, 15, 15,
15, 15, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
15, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
15, 15, 0, 0, 15, 15,
};
static const uint16_t cvh_huffcodes4[246] = {
0x0000,0x0004,0x006c,0x03e6,0x0005,0x0012,0x006d,0x03e7,0x006e,0x00e8,0x03e8,0x3fc4,
0x07e0,0x07e1,0x7fa4,0x7fa5,0x0006,0x0013,0x01e2,0x0fda,0x0014,0x0015,0x00e9,0x0fdb,
0x00ea,0x006f,0x03e9,0x7fa6,0x07e2,0x07e3,0x7fa7,0x7fa8,0x0070,0x01e3,0x0fdc,0x7fa9,
0x00eb,0x00ec,0x0fdd,0x7faa,0x03ea,0x03eb,0x1fd6,0x7fab,0x3fc5,0x3fc6,0x7fac,0x1fd6,
0x07e4,0x1fd7,0x7fad,0x7fae,0x07e5,0x1fd8,0x7faf,0x7fb0,0x3fc7,0x7fb1,0x7fb2,0x1fd6,
0x7fb3,0x7fb4,0x1fd6,0x1fd6,0x0007,0x0016,0x01e4,0x1fd9,0x0017,0x0032,0x01e5,0x1fda,
0x01e6,0x01e7,0x07e6,0x7fb5,0x3fc8,0x1fdb,0x7fb6,0x7fb7,0x0008,0x0033,0x01e8,0x0fde,
0x0018,0x0034,0x01e9,0x1fdc,0x01ea,0x00ed,0x07e7,0x7fb8,0x1fdd,0x0fdf,0x7fb9,0x7fba,
0x0071,0x01eb,0x0fe0,0x7fbb,0x0072,0x00ee,0x07e8,0x7fbc,0x03ec,0x03ed,0x3fc9,0x7fbd,
0x3fca,0x7fbe,0x7fbf,0x3fc9,0x03ee,0x0fe1,0x7fc0,0x7fc1,0x07e9,0x1fde,0x7fc2,0x7fc3,
0x7fc4,0x7fc5,0x7fc6,0x3fc9,0x7fc7,0x7fc8,0x3fc9,0x3fc9,0x0035,0x01ec,0x1fdf,0x3fcb,
0x00ef,0x01ed,0x0fe2,0x7fc9,0x0fe3,0x0fe4,0x7fca,0x7fcb,0x7fcc,0x7fcd,0x7fce,0x7fca,
0x0073,0x01ee,0x1fe0,0x7fcf,0x00f0,0x01ef,0x0fe5,0x7fd0,0x07ea,0x0fe6,0x7fd1,0x7fd2,
0x7fd3,0x7fd4,0x7fd5,0x7fd1,0x01f0,0x07eb,0x7fd6,0x7fd7,0x01f1,0x07ec,0x7fd8,0x7fd9,
0x3fcc,0x3fcd,0x7fda,0x7fda,0x7fdb,0x7fdc,0x7fda,0x7fda,0x3fce,0x7fdd,0x7fde,0x7fd6,
0x3fcf,0x7fdf,0x7fe0,0x7fd8,0x7fe1,0x7fe2,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
0x01f2,0x0fe7,0x7fe3,0x7fe4,0x0fe8,0x1fe1,0x7fe5,0x7fe6,0x7fe7,0x7fe8,0x7fe9,0x7fca,
0x7fea,0x7feb,0x7fca,0x7fca,0x03ef,0x0fe9,0x7fec,0x7fed,0x0fea,0x3fd0,0x7fee,0x7fef,
0x7ff0,0x7ff1,0x7ff2,0x7fd1,0x7ff3,0x7ff4,0x7fd1,0x7fd1,0x3fd1,0x7ff5,0x7ff6,0x7fd6,
0x7ff7,0x7ff8,0x7ff9,0x7fd8,0x7ffa,0x7ffb,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
0x7ffc,0x7ffd,0x7fd6,0x7fd6,0x7ffe,0x7fff,
};
static const uint8_t cvh_huffbits5[230] = {
2, 4, 8, 4, 5, 9, 9, 10, 14, 4, 6, 11,
5, 6, 12, 10, 11, 15, 9, 11, 15, 10, 13, 15,
14, 15, 0, 4, 6, 12, 6, 7, 12, 12, 12, 15,
5, 7, 13, 6, 7, 13, 12, 13, 15, 10, 12, 15,
11, 13, 15, 15, 15, 0, 8, 13, 15, 11, 12, 15,
15, 15, 0, 10, 13, 15, 12, 15, 15, 15, 15, 0,
15, 15, 0, 15, 15, 0, 0, 0, 0, 4, 5, 11,
5, 7, 12, 11, 12, 15, 6, 7, 13, 7, 8, 14,
12, 14, 15, 11, 13, 15, 12, 13, 15, 15, 15, 0,
5, 6, 13, 7, 8, 15, 12, 14, 15, 6, 8, 14,
7, 8, 15, 14, 15, 15, 12, 12, 15, 12, 13, 15,
15, 15, 0, 9, 13, 15, 12, 13, 15, 15, 15, 0,
11, 13, 15, 13, 13, 15, 15, 15, 0, 14, 15, 0,
15, 15, 0, 0, 0, 0, 8, 10, 15, 11, 12, 15,
15, 15, 0, 10, 12, 15, 12, 13, 15, 15, 15, 0,
14, 15, 0, 15, 15, 0, 0, 0, 0, 8, 12, 15,
12, 13, 15, 15, 15, 0, 11, 13, 15, 13, 15, 15,
15, 15, 0, 15, 15, 0, 15, 15, 0, 0, 0, 0,
14, 15, 0, 15, 15, 0, 0, 0, 0, 15, 15, 0,
15, 15,
};
static const uint16_t cvh_huffcodes5[230] = {
0x0000,0x0004,0x00f0,0x0005,0x0012,0x01f0,0x01f1,0x03e8,0x3fce,0x0006,0x0030,0x07de,
0x0013,0x0031,0x0fd2,0x03e9,0x07df,0x7fb0,0x01f2,0x07e0,0x7fb1,0x03ea,0x1fd2,0x7fb2,
0x3fcf,0x7fb3,0x0031,0x0007,0x0032,0x0fd3,0x0033,0x0070,0x0fd4,0x0fd5,0x0fd6,0x7fb4,
0x0014,0x0071,0x1fd3,0x0034,0x0072,0x1fd4,0x0fd7,0x1fd5,0x7fb5,0x03eb,0x0fd8,0x7fb6,
0x07e1,0x1fd6,0x7fb7,0x7fb8,0x7fb9,0x0072,0x00f1,0x1fd7,0x7fba,0x07e2,0x0fd9,0x7fbb,
0x7fbc,0x7fbd,0x0070,0x03ec,0x1fd8,0x7fbe,0x0fda,0x7fbf,0x7fc0,0x7fc1,0x7fc2,0x0072,
0x7fc3,0x7fc4,0x0071,0x7fc5,0x7fc6,0x0072,0x0034,0x0072,0x0072,0x0008,0x0015,0x07e3,
0x0016,0x0073,0x0fdb,0x07e4,0x0fdc,0x7fc7,0x0035,0x0074,0x1fd9,0x0075,0x00f2,0x3fd0,
0x0fdd,0x3fd1,0x7fc8,0x07e5,0x1fda,0x7fc9,0x0fde,0x1fdb,0x7fca,0x7fcb,0x7fcc,0x00f2,
0x0017,0x0036,0x1fdc,0x0076,0x00f3,0x7fcd,0x0fdf,0x3fd2,0x7fce,0x0037,0x00f4,0x3fd3,
0x0077,0x00f5,0x7fcf,0x3fd4,0x7fd0,0x7fd1,0x0fe0,0x0fe1,0x7fd2,0x0fe2,0x1fdd,0x7fd3,
0x7fd4,0x7fd5,0x00f5,0x01f3,0x1fde,0x7fd6,0x0fe3,0x1fdf,0x7fd7,0x7fd8,0x7fd9,0x00f3,
0x07e6,0x1fe0,0x7fda,0x1fe1,0x1fe2,0x7fdb,0x7fdc,0x7fdd,0x00f5,0x3fd5,0x7fde,0x00f4,
0x7fdf,0x7fe0,0x00f5,0x0077,0x00f5,0x00f5,0x00f6,0x03ed,0x7fe1,0x07e7,0x0fe4,0x7fe2,
0x7fe3,0x7fe4,0x0073,0x03ee,0x0fe5,0x7fe5,0x0fe6,0x1fe3,0x7fe6,0x7fe7,0x7fe8,0x00f2,
0x3fd6,0x7fe9,0x0074,0x7fea,0x7feb,0x00f2,0x0075,0x00f2,0x00f2,0x00f7,0x0fe7,0x7fec,
0x0fe8,0x1fe4,0x7fed,0x7fee,0x7fef,0x00f3,0x07e8,0x1fe5,0x7ff0,0x1fe6,0x7ff1,0x7ff2,
0x7ff3,0x7ff4,0x00f5,0x7ff5,0x7ff6,0x00f4,0x7ff7,0x7ff8,0x00f5,0x0077,0x00f5,0x00f5,
0x3fd7,0x7ff9,0x0036,0x7ffa,0x7ffb,0x00f3,0x0076,0x00f3,0x00f3,0x7ffc,0x7ffd,0x0000,
0x7ffe,0x7fff,
};
static const uint8_t cvh_huffbits6[32] = {
1, 4, 4, 6, 4, 6, 6, 8, 4, 6, 6, 8,
6, 9, 8, 10, 4, 6, 7, 8, 6, 9, 8, 11,
6, 9, 8, 10, 8, 10, 9, 11,
};
static const uint16_t cvh_huffcodes6[32] = {
0x0000,0x0008,0x0009,0x0034,0x000a,0x0035,0x0036,0x00f6,0x000b,0x0037,0x0038,0x00f7,
0x0039,0x01fa,0x00f8,0x03fc,0x000c,0x003a,0x007a,0x00f9,0x003b,0x01fb,0x00fa,0x07fe,
0x003c,0x01fc,0x00fb,0x03fd,0x00fc,0x03fe,0x01fd,0x07ff,
};
static const uint16_t* const cvh_huffcodes[7] = {
cvh_huffcodes0, cvh_huffcodes1, cvh_huffcodes2, cvh_huffcodes3,
cvh_huffcodes4, cvh_huffcodes5, cvh_huffcodes6,
};
static const uint8_t* const cvh_huffbits[7] = {
cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3,
cvh_huffbits4, cvh_huffbits5, cvh_huffbits6,
};
static const uint16_t ccpl_huffcodes2[3] = {
0x02,0x00,0x03,
};
static const uint16_t ccpl_huffcodes3[7] = {
0x3e,0x1e,0x02,0x00,0x06,0x0e,0x3f,
};
static const uint16_t ccpl_huffcodes4[15] = {
0xfc,0xfd,0x7c,0x3c,0x1c,0x0c,0x04,0x00,0x05,0x0d,0x1d,0x3d,
0x7d,0xfe,0xff,
};
static const uint16_t ccpl_huffcodes5[31] = {
0x03f8,0x03f9,0x03fa,0x03fb,0x01f8,0x01f9,0x00f8,0x00f9,0x0078,0x0079,0x0038,0x0039,
0x0018,0x0019,0x0004,0x0000,0x0005,0x001a,0x001b,0x003a,0x003b,0x007a,0x007b,0x00fa,
0x00fb,0x01fa,0x01fb,0x03fc,0x03fd,0x03fe,0x03ff,
};
static const uint16_t ccpl_huffcodes6[63] = {
0x0004,0x0005,0x0005,0x0006,0x0006,0x0007,0x0007,0x0007,0x0007,0x0008,0x0008,0x0008,
0x0008,0x0009,0x0009,0x0009,0x0009,0x000a,0x000a,0x000a,0x000a,0x000a,0x000b,0x000b,
0x000b,0x000b,0x000c,0x000d,0x000e,0x000e,0x0010,0x0000,0x000a,0x0018,0x0019,0x0036,
0x0037,0x0074,0x0075,0x0076,0x0077,0x00f4,0x00f5,0x00f6,0x00f7,0x01f5,0x01f6,0x01f7,
0x01f8,0x03f6,0x03f7,0x03f8,0x03f9,0x03fa,0x07fa,0x07fb,0x07fc,0x07fd,0x0ffd,0x1ffd,
0x3ffd,0x3ffe,0xffff,
};
static const uint8_t ccpl_huffbits2[3] = {
2,1,2,
};
static const uint8_t ccpl_huffbits3[7] = {
6,5,2,1,3,4,6,
};
static const uint8_t ccpl_huffbits4[15] = {
8,8,7,6,5,4,3,1,3,4,5,6,7,8,8,
};
static const uint8_t ccpl_huffbits5[31] = {
10,10,10,10,9,9,8,8,7,7,6,6,
5,5,3,1,3,5,5,6,6,7,7,8,
8,9,9,10,10,10,10,
};
static const uint8_t ccpl_huffbits6[63] = {
16,15,14,13,12,11,11,11,11,10,10,10,
10,9,9,9,9,9,8,8,8,8,7,7,
7,7,6,6,5,5,3,1,4,5,5,6,
6,7,7,7,7,8,8,8,8,9,9,9,
9,10,10,10,10,10,11,11,11,11,12,13,
14,14,16,
};
static const uint16_t* const ccpl_huffcodes[5] = {
ccpl_huffcodes2,ccpl_huffcodes3,
ccpl_huffcodes4,ccpl_huffcodes5,ccpl_huffcodes6
};
static const uint8_t* const ccpl_huffbits[5] = {
ccpl_huffbits2,ccpl_huffbits3,
ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6
};
//Coupling tables
static const int cplband[51] = {
0,1,2,3,4,5,6,7,8,9,
10,11,11,12,12,13,13,14,14,14,
15,15,15,15,16,16,16,16,16,17,
17,17,17,17,17,18,18,18,18,18,
18,18,19,19,19,19,19,19,19,19,
19,
};
static const float cplscale2[3] = {
0.953020632266998,0.70710676908493,0.302905440330505,
};
static const float cplscale3[7] = {
0.981279790401459,0.936997592449188,0.875934481620789,0.70710676908493,
0.482430040836334,0.349335819482803,0.192587479948997,
};
static const float cplscale4[15] = {
0.991486728191376,0.973249018192291,0.953020632266998,0.930133521556854,
0.903453230857849,0.870746195316315,0.826180458068848,0.70710676908493,
0.563405573368073,0.491732746362686,0.428686618804932,0.367221474647522,
0.302905440330505,0.229752898216248,0.130207896232605,
};
static const float cplscale5[31] = {
0.995926380157471,0.987517595291138,0.978726446628571,0.969505727291107,
0.95979779958725,0.949531257152557,0.938616216182709,0.926936149597168,
0.914336204528809,0.900602877140045,0.885426938533783,0.868331849575043,
0.84851086139679,0.824381768703461,0.791833400726318,0.70710676908493,
0.610737144947052,0.566034197807312,0.529177963733673,0.495983630418777,
0.464778542518616,0.434642940759659,0.404955863952637,0.375219136476517,
0.344963222742081,0.313672333955765,0.280692428350449,0.245068684220314,
0.205169528722763,0.157508864998817,0.0901700109243393,
};
static const float cplscale6[63] = {
0.998005926609039,0.993956744670868,0.989822506904602,0.985598564147949,
0.981279790401459,0.976860702037811,0.972335040569305,0.967696130275726,
0.962936460971832,0.958047747612000,0.953020632266998,0.947844684123993,
0.942508161067963,0.936997592449188,0.931297719478607,0.925390899181366,
0.919256627559662,0.912870943546295,0.906205296516418,0.899225592613220,
0.891890347003937,0.884148240089417,0.875934481620789,0.867165684700012,
0.857730865478516,0.847477376461029,0.836184680461884,0.823513329029083,
0.808890223503113,0.791194140911102,0.767520070075989,0.707106769084930,
0.641024887561798,0.611565053462982,0.587959706783295,0.567296981811523,
0.548448026180267,0.530831515789032,0.514098942279816,0.498019754886627,
0.482430040836334,0.467206478118896,0.452251672744751,0.437485188245773,
0.422837972640991,0.408248275518417,0.393658757209778,0.379014074802399,
0.364258885383606,0.349335819482803,0.334183186292648,0.318732559680939,
0.302905440330505,0.286608695983887,0.269728302955627,0.252119421958923,
0.233590632677078,0.213876649737358,0.192587479948997,0.169101938605309,
0.142307326197624,0.109772264957428,0.0631198287010193,
};
static const float* const cplscales[5] = {
cplscale2, cplscale3, cplscale4, cplscale5, cplscale6,
};
#endif /* AVCODEC_COOKDATA_H */
| 123linslouis-android-video-cutter | jni/libavcodec/cookdata.h | C | asf20 | 28,723 |
/*
* Range coder
* Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Range coder.
*/
#ifndef AVCODEC_RANGECODER_H
#define AVCODEC_RANGECODER_H
#include <stdint.h>
#include <assert.h>
#include "libavutil/common.h"
typedef struct RangeCoder{
int low;
int range;
int outstanding_count;
int outstanding_byte;
uint8_t zero_state[256];
uint8_t one_state[256];
uint8_t *bytestream_start;
uint8_t *bytestream;
uint8_t *bytestream_end;
}RangeCoder;
void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size);
void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size);
int ff_rac_terminate(RangeCoder *c);
void ff_build_rac_states(RangeCoder *c, int factor, int max_p);
static inline void renorm_encoder(RangeCoder *c){
//FIXME optimize
while(c->range < 0x100){
if(c->outstanding_byte < 0){
c->outstanding_byte= c->low>>8;
}else if(c->low <= 0xFF00){
*c->bytestream++ = c->outstanding_byte;
for(;c->outstanding_count; c->outstanding_count--)
*c->bytestream++ = 0xFF;
c->outstanding_byte= c->low>>8;
}else if(c->low >= 0x10000){
*c->bytestream++ = c->outstanding_byte + 1;
for(;c->outstanding_count; c->outstanding_count--)
*c->bytestream++ = 0x00;
c->outstanding_byte= (c->low>>8) & 0xFF;
}else{
c->outstanding_count++;
}
c->low = (c->low & 0xFF)<<8;
c->range <<= 8;
}
}
static inline int get_rac_count(RangeCoder *c){
int x= c->bytestream - c->bytestream_start + c->outstanding_count;
if(c->outstanding_byte >= 0)
x++;
return 8*x - av_log2(c->range);
}
static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){
int range1= (c->range * (*state)) >> 8;
assert(*state);
assert(range1 < c->range);
assert(range1 > 0);
if(!bit){
c->range -= range1;
*state= c->zero_state[*state];
}else{
c->low += c->range - range1;
c->range = range1;
*state= c->one_state[*state];
}
renorm_encoder(c);
}
static inline void refill(RangeCoder *c){
if(c->range < 0x100){
c->range <<= 8;
c->low <<= 8;
if(c->bytestream < c->bytestream_end)
c->low+= c->bytestream[0];
c->bytestream++;
}
}
static inline int get_rac(RangeCoder *c, uint8_t * const state){
int range1= (c->range * (*state)) >> 8;
int av_unused one_mask;
c->range -= range1;
#if 1
if(c->low < c->range){
*state= c->zero_state[*state];
refill(c);
return 0;
}else{
c->low -= c->range;
*state= c->one_state[*state];
c->range = range1;
refill(c);
return 1;
}
#else
one_mask= (c->range - c->low-1)>>31;
c->low -= c->range & one_mask;
c->range += (range1 - c->range) & one_mask;
*state= c->zero_state[(*state) + (256&one_mask)];
refill(c);
return one_mask&1;
#endif
}
#endif /* AVCODEC_RANGECODER_H */
| 123linslouis-android-video-cutter | jni/libavcodec/rangecoder.h | C | asf20 | 3,868 |
/*
* Constants for DV codec
* Copyright (c) 2002 Fabrice Bellard
*
* This file is part of FFmpeg.
*
* FFmpeg 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.1 of the License, or (at your option) any later version.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Constants for DV codec.
*/
#include "libavutil/rational.h"
#include "avcodec.h"
#include "dvdata.h"
static DVwork_chunk work_chunks_dv25pal [1*12*27];
static DVwork_chunk work_chunks_dv25pal411[1*12*27];
static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
static DVwork_chunk work_chunks_dv50pal [2*12*27];
static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
static DVwork_chunk work_chunks_dv100palp [2*12*27];
static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
static DVwork_chunk work_chunks_dv100pali [4*12*27];
static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
static uint32_t dv_idct_factor_sd [2*2*22*64];
static uint32_t dv_idct_factor_hd1080[2*4*16*64];
static uint32_t dv_idct_factor_hd720 [2*4*16*64];
static const DVprofile dv_profiles[] = {
{ .dsf = 0,
.video_stype = 0x0,
.frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
.difseg_size = 10,
.n_difchan = 1,
.time_base = { 1001, 30000 },
.ltc_divisor = 30,
.height = 480,
.width = 720,
.sar = {{10, 11}, {40, 33}},
.work_chunks = &work_chunks_dv25ntsc[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV411P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525,
},
{ .dsf = 1,
.video_stype = 0x0,
.frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
.difseg_size = 12,
.n_difchan = 1,
.time_base = { 1, 25 },
.ltc_divisor = 25,
.height = 576,
.width = 720,
.sar = {{59, 54}, {118, 81}},
.work_chunks = &work_chunks_dv25pal[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV420P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.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_shuffle625,
},
{ .dsf = 1,
.video_stype = 0x0,
.frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
.difseg_size = 12,
.n_difchan = 1,
.time_base = { 1, 25 },
.ltc_divisor = 25,
.height = 576,
.width = 720,
.sar = {{59, 54}, {118, 81}},
.work_chunks = &work_chunks_dv25pal411[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV411P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.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_shuffle625,
},
{ .dsf = 0,
.video_stype = 0x4,
.frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
.difseg_size = 10, /* also known as "DVCPRO50" */
.n_difchan = 2,
.time_base = { 1001, 30000 },
.ltc_divisor = 30,
.height = 480,
.width = 720,
.sar = {{10, 11}, {40, 33}},
.work_chunks = &work_chunks_dv50ntsc[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525,
},
{ .dsf = 1,
.video_stype = 0x4,
.frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
.difseg_size = 12, /* also known as "DVCPRO50" */
.n_difchan = 2,
.time_base = { 1, 25 },
.ltc_divisor = 25,
.height = 576,
.width = 720,
.sar = {{59, 54}, {118, 81}},
.work_chunks = &work_chunks_dv50pal[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.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_shuffle625,
},
{ .dsf = 0,
.video_stype = 0x14,
.frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
.difseg_size = 10, /* also known as "DVCPRO HD" */
.n_difchan = 4,
.time_base = { 1001, 30000 },
.ltc_divisor = 30,
.height = 1080,
.width = 1280,
.sar = {{1, 1}, {3, 2}},
.work_chunks = &work_chunks_dv100ntsci[0],
.idct_factor = &dv_idct_factor_hd1080[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 8,
.block_sizes = block_sizes_dv100,
.audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525,
},
{ .dsf = 1,
.video_stype = 0x14,
.frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
.difseg_size = 12, /* also known as "DVCPRO HD" */
.n_difchan = 4,
.time_base = { 1, 25 },
.ltc_divisor = 25,
.height = 1080,
.width = 1440,
.sar = {{1, 1}, {4, 3}},
.work_chunks = &work_chunks_dv100pali[0],
.idct_factor = &dv_idct_factor_hd1080[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 8,
.block_sizes = block_sizes_dv100,
.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_shuffle625,
},
{ .dsf = 0,
.video_stype = 0x18,
.frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
.difseg_size = 10, /* also known as "DVCPRO HD" */
.n_difchan = 2,
.time_base = { 1001, 60000 },
.ltc_divisor = 60,
.height = 720,
.width = 960,
.sar = {{1, 1}, {4, 3}},
.work_chunks = &work_chunks_dv100ntscp[0],
.idct_factor = &dv_idct_factor_hd720[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 8,
.block_sizes = block_sizes_dv100,
.audio_stride = 90,
.audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
.audio_shuffle = dv_audio_shuffle525,
},
{ .dsf = 1,
.video_stype = 0x18,
.frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
.difseg_size = 12, /* also known as "DVCPRO HD" */
.n_difchan = 2,
.time_base = { 1, 50 },
.ltc_divisor = 50,
.height = 720,
.width = 960,
.sar = {{1, 1}, {4, 3}},
.work_chunks = &work_chunks_dv100palp[0],
.idct_factor = &dv_idct_factor_hd720[0],
.pix_fmt = PIX_FMT_YUV422P,
.bpm = 8,
.block_sizes = block_sizes_dv100,
.audio_stride = 90,
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625,
},
{ .dsf = 1,
.video_stype = 0x1,
.frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
.difseg_size = 12,
.n_difchan = 1,
.time_base = { 1, 25 },
.ltc_divisor = 25,
.height = 576,
.width = 720,
.sar = {{59, 54}, {118, 81}},
.work_chunks = &work_chunks_dv25pal[0],
.idct_factor = &dv_idct_factor_sd[0],
.pix_fmt = PIX_FMT_YUV420P,
.bpm = 6,
.block_sizes = block_sizes_dv2550,
.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_shuffle625,
}
};
const DVprofile* ff_dv_frame_profile(const DVprofile *sys,
const uint8_t* frame, unsigned buf_size)
{
int i;
int dsf = (frame[3] & 0x80) >> 7;
int stype = frame[80*5 + 48 + 3] & 0x1f;
/* 576i50 25Mbps 4:1:1 is a special case */
if (dsf == 1 && stype == 0 && frame[5] & 0x07) {
return &dv_profiles[2];
}
for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
return &dv_profiles[i];
/* check if old sys matches and assumes corrupted input */
if (sys && buf_size == sys->frame_size)
return sys;
return NULL;
}
const DVprofile* ff_dv_codec_profile(AVCodecContext* codec)
{
int i;
for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
if (codec->height == dv_profiles[i].height &&
codec->pix_fmt == dv_profiles[i].pix_fmt &&
codec->width == dv_profiles[i].width)
return &dv_profiles[i];
return NULL;
}
| 123linslouis-android-video-cutter | jni/libavcodec/dvdata.c | C | asf20 | 9,927 |
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/../av.mk
LOCAL_SRC_FILES := $(FFFILES)
LOCAL_C_INCLUDES := \
$(LOCAL_PATH) \
$(LOCAL_PATH)/..
LOCAL_CFLAGS += $(FFCFLAGS)
LOCAL_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := $(FFLIBS)
LOCAL_MODULE := $(FFNAME)
include $(BUILD_STATIC_LIBRARY) | 123linslouis-android-video-cutter | jni/libavcodec/Android.mk | Makefile | asf20 | 312 |