Commit 75832019 authored by Loren Merritt's avatar Loren Merritt
Browse files

move checkasm to tools/

delete unused stuff in testing/
`make clean` deletes checkasm and avc2avi



git-svn-id: svn://svn.videolan.org/x264/trunk@339 df754926-b1dd-0310-bc7b-ec298dee348c
parent 63472638
......@@ -69,7 +69,7 @@ x264$(EXE): libx264.a x264.o matroska.o
x264vfw.dll: libx264.a $(wildcard vfw/*.c vfw/*.h)
make -C vfw/build/cygwin
checkasm: testing/checkasm.o libx264.a
checkasm: tools/checkasm.o libx264.a
$(CC) -o $@ $< libx264.a $(LDFLAGS)
common/amd64/*.o: common/amd64/amd64inc.asm
......@@ -91,6 +91,8 @@ endif
clean:
rm -f $(OBJS) $(OBJASM) config.h *.a x264.o matroska.o x264 x264.exe .depend TAGS
rm -f checkasm checkasm.exe tools/checkasm.o
rm -f tools/avc2avi tools/avc2avi.exe tools/avc2avi.o
rm -rf vfw/build/cygwin/bin
distclean: clean
......
/*****************************************************************************
* macroblock.c: h264 encoder library
*****************************************************************************
* Copyright (C) 2003 Laurent Aimar
* $Id: edge-detec.c,v 1.1 2004/06/03 19:27:08 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include "common.h"
#include "me.h"
#include "vlc.h"
static inline int x264_median( int a, int b, int c )
{
int min = a, max =a;
if( b < min )
{
min = b;
}
else
{
max = b; /* no need to do 'b > max' (more consuming than always doing affectation) */
}
if( c < min )
{
min = c;
}
else if( c > max )
{
max = c;
}
return a + b + c - min - max;
}
static const uint8_t intra4x4_cbp_to_golomb[48]=
{
3, 29, 30, 17, 31, 18, 37, 8, 32, 38, 19, 9, 20, 10, 11, 2,
16, 33, 34, 21, 35, 22, 39, 4, 36, 40, 23, 5, 24, 6, 7, 1,
41, 42, 43, 25, 44, 26, 46, 12, 45, 47, 27, 13, 28, 14, 15, 0
};
static const uint8_t inter_cbp_to_golomb[48]=
{
0, 2, 3, 7, 4, 8, 17, 13, 5, 18, 9, 14, 10, 15, 16, 11,
1, 32, 33, 36, 34, 37, 44, 40, 35, 45, 38, 41, 39, 42, 43, 19,
6, 24, 25, 20, 26, 21, 46, 28, 27, 47, 22, 29, 23, 30, 31, 12
};
static const uint8_t block_idx_x[16] =
{
0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3
};
static const uint8_t block_idx_y[16] =
{
0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3
};
static const uint8_t block_idx_xy[4][4] =
{
{ 0, 2, 8, 10},
{ 1, 3, 9, 11},
{ 4, 6, 12, 14},
{ 5, 7, 13, 15}
};
static const int quant_mf[6][4][4] =
{
{ { 13107, 8066, 13107, 8066}, { 8066, 5243, 8066, 5243},
{ 13107, 8066, 13107, 8066}, { 8066, 5243, 8066, 5243} },
{ { 11916, 7490, 11916, 7490}, { 7490, 4660, 7490, 4660},
{ 11916, 7490, 11916, 7490}, { 7490, 4660, 7490, 4660} },
{ { 10082, 6554, 10082, 6554}, { 6554, 4194, 6554, 4194},
{ 10082, 6554, 10082, 6554}, { 6554, 4194, 6554, 4194} },
{ { 9362, 5825, 9362, 5825}, { 5825, 3647, 5825, 3647},
{ 9362, 5825, 9362, 5825}, { 5825, 3647, 5825, 3647} },
{ { 8192, 5243, 8192, 5243}, { 5243, 3355, 5243, 3355},
{ 8192, 5243, 8192, 5243}, { 5243, 3355, 5243, 3355} },
{ { 7282, 4559, 7282, 4559}, { 4559, 2893, 4559, 2893},
{ 7282, 4559, 7282, 4559}, { 4559, 2893, 4559, 2893} }
};
static const int dequant_mf[6][4][4] =
{
{ {10, 13, 10, 13}, {13, 16, 13, 16}, {10, 13, 10, 13}, {13, 16, 13, 16} },
{ {11, 14, 11, 14}, {14, 18, 14, 18}, {11, 14, 11, 14}, {14, 18, 14, 18} },
{ {13, 16, 13, 16}, {16, 20, 16, 20}, {13, 16, 13, 16}, {16, 20, 16, 20} },
{ {14, 18, 14, 18}, {18, 23, 18, 23}, {14, 18, 14, 18}, {18, 23, 18, 23} },
{ {16, 20, 16, 20}, {20, 25, 20, 25}, {16, 20, 16, 20}, {20, 25, 20, 25} },
{ {18, 23, 18, 23}, {23, 29, 23, 29}, {18, 23, 18, 23}, {23, 29, 23, 29} }
};
static int predict_pred_intra4x4_mode( x264_t *h, x264_macroblock_t *mb, int idx )
{
x264_macroblock_t *mba = mb->context->block[idx].mba;
x264_macroblock_t *mbb = mb->context->block[idx].mbb;
int i_mode_a = I_PRED_4x4_DC;
int i_mode_b = I_PRED_4x4_DC;
if( !mba || !mbb )
{
return I_PRED_4x4_DC;
}
if( mba->i_type == I_4x4 )
{
i_mode_a = mb->context->block[idx].bka->i_intra4x4_pred_mode;
}
if( mbb->i_type == I_4x4 )
{
i_mode_b = mb->context->block[idx].bkb->i_intra4x4_pred_mode;
}
return X264_MIN( i_mode_a, i_mode_b );
}
static int predict_non_zero_code( x264_t *h, x264_macroblock_t *mb, int idx )
{
x264_macroblock_t *mba = mb->context->block[idx].mba;
x264_macroblock_t *mbb = mb->context->block[idx].mbb;
int i_z_a = 0x80, i_z_b = 0x80;
int i_ret;
/* none avail -> 0, one avail -> this one, both -> (a+b+1)>>1 */
if( mba )
{
i_z_a = mb->context->block[idx].bka->i_non_zero_count;
}
if( mbb )
{
i_z_b = mb->context->block[idx].bkb->i_non_zero_count;
}
i_ret = i_z_a+i_z_b;
if( i_ret < 0x80 )
{
i_ret = ( i_ret + 1 ) >> 1;
}
return i_ret & 0x7f;
}
/*
* Handle intra mb
*/
/* Max = 4 */
static void predict_16x16_mode_available( x264_macroblock_t *mb, int *mode, int *pi_count )
{
if( ( mb->i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) )
{
/* top and left avaible */
*mode++ = I_PRED_16x16_DC;
*mode++ = I_PRED_16x16_V;
*mode++ = I_PRED_16x16_H;
*mode++ = I_PRED_16x16_P;
*pi_count = 4;
}
else if( ( mb->i_neighbour & MB_LEFT ) )
{
/* left available*/
*mode++ = I_PRED_16x16_DC_LEFT;
*mode++ = I_PRED_16x16_H;
*pi_count = 2;
}
else if( ( mb->i_neighbour & MB_TOP ) )
{
/* top available*/
*mode++ = I_PRED_16x16_DC_TOP;
*mode++ = I_PRED_16x16_V;
*pi_count = 2;
}
else
{
/* none avaible */
*mode = I_PRED_16x16_DC_128;
*pi_count = 1;
}
}
/* Max = 4 */
static void predict_8x8_mode_available( x264_macroblock_t *mb, int *mode, int *pi_count )
{
if( ( mb->i_neighbour & (MB_LEFT|MB_TOP) ) == (MB_LEFT|MB_TOP) )
{
/* top and left avaible */
*mode++ = I_PRED_CHROMA_DC;
*mode++ = I_PRED_CHROMA_V;
*mode++ = I_PRED_CHROMA_H;
*mode++ = I_PRED_CHROMA_P;
*pi_count = 4;
}
else if( ( mb->i_neighbour & MB_LEFT ) )
{
/* left available*/
*mode++ = I_PRED_CHROMA_DC_LEFT;
*mode++ = I_PRED_CHROMA_H;
*pi_count = 2;
}
else if( ( mb->i_neighbour & MB_TOP ) )
{
/* top available*/
*mode++ = I_PRED_CHROMA_DC_TOP;
*mode++ = I_PRED_CHROMA_V;
*pi_count = 2;
}
else
{
/* none avaible */
*mode = I_PRED_CHROMA_DC_128;
*pi_count = 1;
}
}
/* MAX = 8 */
static void predict_4x4_mode_available( x264_macroblock_t *mb, int idx, int *mode, int *pi_count )
{
int b_a, b_b, b_c;
static const int needmb[16] =
{
MB_LEFT|MB_TOP, MB_TOP,
MB_LEFT, MB_PRIVATE,
MB_TOP, MB_TOP|MB_TOPRIGHT,
0, MB_PRIVATE,
MB_LEFT, 0,
MB_LEFT, MB_PRIVATE,
0, MB_PRIVATE,
0, MB_PRIVATE
};
/* FIXME even when b_c == 0 there is some case where missing pixels
* are emulated and thus more mode are available TODO
* analysis and encode should be fixed too */
b_a = (needmb[idx]&mb->i_neighbour&MB_LEFT) == (needmb[idx]&MB_LEFT);
b_b = (needmb[idx]&mb->i_neighbour&MB_TOP) == (needmb[idx]&MB_TOP);
b_c = (needmb[idx]&mb->i_neighbour&(MB_TOPRIGHT|MB_PRIVATE)) == (needmb[idx]&(MB_TOPRIGHT|MB_PRIVATE));
if( b_a && b_b )
{
*mode++ = I_PRED_4x4_DC;
*mode++ = I_PRED_4x4_H;
*mode++ = I_PRED_4x4_V;
*mode++ = I_PRED_4x4_DDR;
*mode++ = I_PRED_4x4_VR;
*mode++ = I_PRED_4x4_HD;
*mode++ = I_PRED_4x4_HU;
*pi_count = 7;
if( b_c )
{
*mode++ = I_PRED_4x4_DDL;
*mode++ = I_PRED_4x4_VL;
(*pi_count) += 2;
}
}
else if( b_a && !b_b )
{
*mode++ = I_PRED_4x4_DC_LEFT;
*mode++ = I_PRED_4x4_H;
*pi_count = 2;
}
else if( !b_a && b_b )
{
*mode++ = I_PRED_4x4_DC_TOP;
*mode++ = I_PRED_4x4_V;
*pi_count = 2;
}
else
{
*mode++ = I_PRED_4x4_DC_128;
*pi_count = 1;
}
}
/****************************************************************************
* Scan and Quant functions
****************************************************************************/
static const int scan_zigzag_x[16]={0, 1, 0, 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 3, 2, 3};
static const int scan_zigzag_y[16]={0, 0, 1, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 2, 3, 3};
static inline void scan_zigzag_4x4full( int level[16], int16_t dct[4][4] )
{
int i;
for( i = 0; i < 16; i++ )
{
level[i] = dct[scan_zigzag_y[i]][scan_zigzag_x[i]];
}
}
static inline void scan_zigzag_4x4( int level[15], int16_t dct[4][4] )
{
int i;
for( i = 1; i < 16; i++ )
{
level[i - 1] = dct[scan_zigzag_y[i]][scan_zigzag_x[i]];
}
}
static inline void scan_zigzag_2x2_dc( int level[4], int16_t dct[2][2] )
{
level[0] = dct[0][0];
level[1] = dct[0][1];
level[2] = dct[1][0];
level[3] = dct[1][1];
}
static void quant_4x4( int16_t dct[4][4], int i_qscale, int b_intra )
{
int i_qbits = 15 + i_qscale / 6;
int i_mf = i_qscale % 6;
int f = ( 1 << i_qbits ) / ( b_intra ? 3 : 6 );
int x,y;
for( y = 0; y < 4; y++ )
{
for( x = 0; x < 4; x++ )
{
if( dct[y][x] > 0 )
{
dct[y][x] =( f + (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][y][x] ) >> i_qbits;
}
else
{
dct[y][x] = - ( ( f - (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][y][x] ) >> i_qbits );
}
}
}
}
static void quant_4x4_dc( int16_t dct[4][4], int i_qscale, int b_intra )
{
int i_qbits = 15 + i_qscale / 6;
int i_mf = i_qscale % 6;
int f = ( 1 << i_qbits ) / ( b_intra ? 3 : 6 );
int x,y;
for( y = 0; y < 4; y++ )
{
for( x = 0; x < 4; x++ )
{
if( dct[y][x] > 0 )
{
dct[y][x] =( 2*f + (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][0][0] ) >> ( 1 + i_qbits );
}
else
{
dct[y][x] = - ( ( 2*f - (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][0][0] ) >> (1 + i_qbits ) );
}
}
}
}
static void quant_2x2_dc( int16_t dct[2][2], int i_qscale, int b_intra )
{
int i_qbits = 15 + i_qscale / 6;
int i_mf = i_qscale % 6;
int f = ( 1 << i_qbits ) / ( b_intra ? 3 : 6 );
int x,y;
for( y = 0; y < 2; y++ )
{
for( x = 0; x < 2; x++ )
{
/* XXX: is int64_t really needed ? */
if( dct[y][x] > 0 )
{
dct[y][x] =( 2*f + (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][0][0] ) >> ( 1 + i_qbits );
}
else
{
dct[y][x] = - ( ( 2*f - (int64_t)dct[y][x] * (int64_t)quant_mf[i_mf][0][0] ) >> (1 + i_qbits ) );
}
}
}
}
static void dequant_4x4_dc( int16_t dct[4][4], int i_qscale )
{
int i_mf = i_qscale%6;
int i_qbits = i_qscale/6;
int f;
int x,y;
if( i_qbits <= 1 )
{
f = 1 << ( 1 - i_qbits );
}
else
{
f = 0;
}
for( y = 0; y < 4; y++ )
{
for( x = 0; x < 4; x++ )
{
if( i_qbits >= 2 )
{
dct[y][x] = ( dct[y][x] * dequant_mf[i_mf][0][0] ) << (i_qbits - 2);
}
else
{
dct[y][x] = ( dct[y][x] * dequant_mf[i_mf][0][0] + f ) >> ( 2 -i_qbits );
}
}
}
}
static void dequant_2x2_dc( int16_t dct[2][2], int i_qscale )
{
int i_mf = i_qscale%6;
int i_qbits = i_qscale/6;
int x,y;
for( y = 0; y < 2; y++ )
{
for( x = 0; x < 2; x++ )
{
if( i_qbits >= 1 )
{
dct[y][x] = ( dct[y][x] * dequant_mf[i_mf][0][0] ) << (i_qbits - 1);
}
else
{
dct[y][x] = ( dct[y][x] * dequant_mf[i_mf][0][0] ) >> 1;
}
}
}
}
static void dequant_4x4( int16_t dct[4][4], int i_qscale )
{
int i_mf = i_qscale%6;
int i_qbits = i_qscale/6;
int x,y;
for( y = 0; y < 4; y++ )
{
for( x = 0; x < 4; x++ )
{
dct[y][x] = ( dct[y][x] * dequant_mf[i_mf][x][y] ) << i_qbits;
}
}
}
static inline int array_non_zero_count( int *v, int i_count )
{
int i;
int i_nz;
for( i = 0, i_nz = 0; i < i_count; i++ )
{
if( v[i] )
{
i_nz++;
}
}
return i_nz;
}
/* TODO : use a table instead */
static int mb_partition_count( int i_partition )
{
switch( i_partition )
{
case D_8x8:
return 4;
case D_16x8:
case D_8x16:
return 2;
case D_16x16:
return 1;
default:
/* should never occur */
return 0;
}
}
static int mb_sub_partition_count( int i_partition )
{
switch( i_partition )
{
case D_L0_4x4:
case D_L1_4x4:
case D_BI_4x4:
return 4;
case D_L0_4x8:
case D_L1_4x8:
case D_BI_4x8:
case D_L0_8x4:
case D_L1_8x4:
case D_BI_8x4:
return 2;
case D_L0_8x8:
case D_L1_8x8:
case D_BI_8x8:
case D_DIRECT_8x8:
return 1;
default:
/* should never occur */
return 0;
}
}
static inline void x264_macroblock_partition_getxy( x264_macroblock_t *mb, int i_part, int i_sub, int *x, int *y )
{
if( mb->i_partition == D_16x16 )
{
*x = 0;
*y = 0;
}
else if( mb->i_partition == D_16x8 )
{
*x = 0;
*y = 2*i_part;
}
else if( mb->i_partition == D_8x16 )
{
*x = 2*i_part;
*y = 0;
}
else if( mb->i_partition == D_8x8 )
{
*x = 2 * (i_part%2);
*y = 2 * (i_part/2);
if( IS_SUB4x4( mb->i_sub_partition[i_part] ) )
{
(*x) += i_sub%2;
(*y) += i_sub/2;
}
else if( IS_SUB4x8( mb->i_sub_partition[i_part] ) )
{
(*x) += i_sub;
}
else if( IS_SUB8x4( mb->i_sub_partition[i_part] ) )
{
(*y) += i_sub;
}
}
}
static inline void x264_macroblock_partition_size( x264_macroblock_t *mb, int i_part, int i_sub, int *w, int *h )
{
if( mb->i_partition == D_16x16 )
{
*w = 4;
*h = 4;
}
else if( mb->i_partition == D_16x8 )
{
*w = 4;
*h = 2;
}
else if( mb->i_partition == D_8x16 )
{
*w = 2;
*h = 4;
}
else if( mb->i_partition == D_8x8 )
{
if( IS_SUB4x4( mb->i_sub_partition[i_part] ) )
{
*w = 1;
*h = 1;
}
else if( IS_SUB4x8( mb->i_sub_partition[i_part] ) )
{
*w = 1;
*h = 2;
}
else if( IS_SUB8x4( mb->i_sub_partition[i_part] ) )
{